Commit d77d0dc
Fix bug in
Use a tryfinally macro to ensure compile timer is closed, while maintaining scope.
This fixes a bug where an exception thrown _anywhere_, on any Task on
any thread, completely disables the compilation time measurement for any
concurrently executing `@time` blocks, without warning the user about
it.
Here are some examples of the current, broken behavior:
- Throwing (and catching) an exception disables compilation time
measurement, even though the exception didn't escape, without warning
the user - note 0 compilation time reported:
```julia
julia> @time begin
# The following exception disables compilation time measurement
try throw("ha HAH!") catch end
@eval module M ; f(x) = 2*x ; end
@eval M.f(2)
end
0.003950 seconds (2.17 k allocations: 170.093 KiB)
4
```
- Throwing an exception while the first task is sleeping disables
compilation time measurement, so this ends up incorrectly reporting 0
compilation time:
```julia
julia> f(n) = begin
# while we're sleeping, someone throws an exception somewhere else :'(
sleep(n)
@eval module M ; f(x) = 2*x ; end
@eval M.f(2)
end
f (generic function with 1 method)
julia> f(0) # warmup
WARNING: replacing module M.
4
julia> @async @time f(5)
Task (runnable) @0x000000010f2c0780
julia> throw("oh no sad")
ERROR: "oh no sad"
Stacktrace:
[1] top-level scope
@ REPL[9]:1
WARNING: replacing module M.
5.008401 seconds (1.92 k allocations: 120.515 KiB)
```
After this commit, both of those examples correctly report their
compilation time.@time compilation time measurement, using tryfinally macro. (JuliaLang#41923)1 parent b51d7e0 commit d77d0dc
2 files changed
+18
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
167 | 177 | | |
168 | 178 | | |
169 | 179 | | |
| |||
207 | 217 | | |
208 | 218 | | |
209 | 219 | | |
210 | | - | |
211 | | - | |
212 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
213 | 224 | | |
214 | 225 | | |
215 | 226 | | |
| |||
253 | 264 | | |
254 | 265 | | |
255 | 266 | | |
256 | | - | |
257 | | - | |
258 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
259 | 271 | | |
260 | 272 | | |
261 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
560 | 560 | | |
561 | 561 | | |
562 | 562 | | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | 563 | | |
570 | 564 | | |
571 | 565 | | |
| |||
0 commit comments