oxinabox / MagneticReadHead.jl

A cassette-based debugger | The Other Debugger
MIT License
50 stars 6 forks source link

Debugging Plots.jl, TimerOutputs.jl and CSV.jl crashes #56

Closed KristofferC closed 5 years ago

KristofferC commented 5 years ago

Tried

julia> using Plots, MagneticReadHead

julia> @time @iron_debug plot(rand(5))
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Any, (597,)}[SSAValue(1), SSAValue(2), ....
rec_backtrace at /home/Administrator/buildbot/worker/package_win64/build/src\stackwalk.c:94
record_backtrace at /home/Administrator/buildbot/worker/package_win64/build/src\task.c:217 [inlined]
jl_throw at /home/Administrator/buildbot/worker/package_win64/build/src\task.c:417
jl_bounds_error_ints at /home/Administrator/buildbot/worker/package_win64/build/src\rtutils.c:183
getindex at .\array.jl:729 [inlined]
renumber_ssa at .\compiler/ssair\slot2ssa.jl:65 [inlined]
#241 at .\compiler/ssair\slot2ssa.jl:74 [inlined]
ssamap at .\compiler/ssair\ir.jl:429
renumber_ssa! at .\compiler/ssair\slot2ssa.jl:74 [inlined]
renumber_ssa! at .\compiler/ssair\slot2ssa.jl:73
jl_apply_generic at /home/Administrator/buildbot/worker/package_win64/build/src\gf.c:2219
construct_ssa! at .\compiler/ssair\slot2ssa.jl:859
just_construct_ssa at .\compiler/ssair\driver.jl:109
run_passes at .\compiler/ssair\driver.jl:114

on master of MRH.

See also #61 and #62

oxinabox commented 5 years ago

Thanks. This tends to be that I broke one of the unwritten rules of when you are allowed to run Expr(:isdefined, :foo) and hit the fallback SSAValue from https://github.com/JuliaLang/julia/pull/31786.

Something will need to be added to: https://github.com/oxinabox/MagneticReadHead.jl/blob/077943b3dac27f41c40e451a7341c25892ab98bd/src/pass.jl#L64 to handle whatever the cause of this is.

oxinabox commented 5 years ago

I am really struggling to make a MVE of this. I can reproduct this with Plots, but so far not with anything simpler.

oxinabox commented 5 years ago

I am pretty sure

61 and #62 are also the same issue.

I need to sit down with someone who understands the optimizer (pokes @keno) and dig into which of its assumptions I am violating.

oxinabox commented 5 years ago

I am going to close #61 and #62 just to keep the converstation in one place

oxinabox commented 5 years ago

Best MWE:

using MagneticReadHead, TimerOutputs
t = TimerOutput()
@run print_timer(t)
oxinabox commented 5 years ago

We are hitting this case https://github.com/JuliaLang/julia/blob/faefe2ae64fb9a12824832582e2ddd3bc554d372/base/compiler/ssair/slot2ssa.jl#L656

oxinabox commented 5 years ago

MWE:

using MagneticReadHead

function danger19()
    y=2
    function inner()
        h=y
        y=12
        return h
    end
    inner()
end 

@run danger19()
oxinabox commented 5 years ago

https://github.com/oxinabox/MagneticReadHead.jl/pull/57 solves the danger19 MWE, but not the others.

KristofferC commented 5 years ago

Don't think this should have been closed.

oxinabox commented 5 years ago

My latest MWE is

 @run TimerOutputs.print_header(stdout, 0.5, 0.1, 3, 3, 7, false, true, 11, true, "oio")

The extra confoudning thing is if I copy and paste the corresponding section of code directy into the REPL the call to

@run print_header(stdout, 0.5, 0.1, 3, 3, 7, false, true, 11, true, "oio")

works fine

KristofferC commented 5 years ago

I tried on the CSV.jl example and it doesn't crash but it never seems to finish running either (waited 6-7 min).

oxinabox commented 5 years ago

@KristofferC was this with #68? I am not particularly superised, there are some performance blackholes with compilation. I belive they are just the extreme case of the sprand one you commented in the CompiledFrames thread. A simple one is

julia> foo() = Complex.(rand(1,2), rand(1,2)) * rand(Int, 2,1);

julia> @btime foo();
  297.770 ns (9 allocations: 720 bytes)

julia> @btime Debugger.@run foo();
  15.472 ms (46982 allocations: 1.78 MiB)

julia> @time MagneticReadHead.@run foo()
  <Hangs for over 30 minutes before I stopped watching>

I think they are either bugs Cassette or in the compiler, At some point I will switch off Cassette and on to IRTools I think. IRTools, being a bit simpler, plays nicer with the compiler. See https://github.com/JuliaDiff/ChainRules.jl/pull/37

If you like you could try a few: set_uninstrumented!(Base); set_uninstrumented!(CSV.Parsers) etc. But that would throw off any benchmarks.

KristofferC commented 5 years ago

Sorry, yes with #68 (I meant to comment on that PR)

oxinabox commented 5 years ago

74 is the correct way to solve this,

and it does indeed solve it.