JunoLab / Juno.jl

MIT License
144 stars 23 forks source link

[BUG] `typeof(10)` output while debugging #599

Open JeffBezanson opened 4 years ago

JeffBezanson commented 4 years ago

typeof10

I tried debugging code that uses @spawn just for fun, and inside the macro a line is annotated with typeof(10). I have no idea why.

JeffBezanson commented 4 years ago

The argument to the enclosing function is in fact 10, I just don't see why it's showing up here or why it's printed like that.

pfitzseb commented 4 years ago

So the @spawn code seems to get expanded to

   1  2  1 ─       Core.NewvarNode(:(t))
   2* 2  │         a = (rand)(Bool)
   3  362  │  │ %3  = var"#20#22"
   4  362  │  │ %4  = (typeof)(a)
   5  362  │  │ %5  = (Core.apply_type)(%3, %4)
   6  362  │  │       #20 = %new(%5, a)
   7  362  │  │ %7  = #20
   8  362  │  │       task = (Task)(%7)
   9  363  └──│       goto #3 if not false
  10  364  2 ─│       (push!)(Main.:(var"##sync#33"), task)

So it makes sense that we step to typeof(a). It's definitely confusing though...

aviatesk commented 4 years ago

MRE:

julia> @code_lowered (()->let
           a = rand(Bool)
           t = Base.Threads.@spawn begin
               a ? sleep(0) : sleep(1)
               sin(a)
           end
           fetch(t)
       end)()
CodeInfo(
1 ─       Core.NewvarNode(
:(t))
│         a = Main.rand(Main.Bool)
│   %3  = Main.:(var"#56#58")
│   %4  = Core.typeof(a)
│   %5  = Core.apply_type(%3, %4)
│         #56 = %new(%5, a)
│   %7  = #56
│         task = Base.Threads.Task(%7)
│   %9  = false
│         Base.setproperty!(task, :sticky, %9)
└──       goto #3 if not false
2 ─       Base.Threads.put!(Main.:(var"##sync#33"), task)
3 ┄       Base.Threads.schedule(task)
│         t = task
│   %15 = Main.fetch(t)
└──       return %15
)
JeffBezanson commented 4 years ago

I see, that's tricky.