KristofferC / TimerOutputs.jl

Formatted output of timed sections in Julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compilation errors in timed function calls yield "broken" stacktraces

sloede opened this issue · comments

When there is an error within a function call timed with @timeit, sometimes the stacktraces do not report correct file names and line numbers anymore.

mwe.jl

using TimerOutputs

function foo(::Float64) end

@timeit "foo" foo(1)

Running juila mwe.jl yields

ERROR: LoadError: MethodError: no method matching foo(::Int64)
Closest candidates are:
  foo(::Float64) at /path/to/mwe.jl:3
Stacktrace:
 [1] top-level scope at /home/user/.julia/packages/TimerOutputs/7Id5J/src/TimerOutput.jl:214
 [2] include at ./boot.jl:328 [inlined]
 [3] include_relative(::Module, ::String) at ./loading.jl:1105
 [4] include(::Module, ::String) at ./Base.jl:31
 [5] exec_options(::Base.JLOptions) at ./client.jl:287
 [6] _start() at ./client.jl:460
in expression starting at /path/to/mwe.jl:5

Some initial testing suggests that this is only a problem if the error occurs at the "function selection/argument evaluation level", i.e., if there is an error during the argument evaluation or if (as in this case) no matching method could be found. I was not able to reproduce this behavior if there are compilation errors from within the timed function.

I don't know if it's the same as this, but

julia> @timeit to "test" begin error() end
Stacktrace:
 [1] error()
   @ Base ./error.jl:44
 [2] macro expansion
   @ REPL[6]:1 [inlined]
 [3] top-level scope
   @ ~/.julia/packages/TimerOutputs/jgSVI/src/TimerOutput.jl:236
 [4] top-level scope
   @ ~/.julia/packages/Infiltrator/R8I9c/src/Infiltrator.jl:632

There is no such thing with a @views for instance.

This seems to be because TimerOutput wraps the code inside a tryfinally block, as seen from @macroexpand. Not sure how to fix.