Juno.jl icon indicating copy to clipboard operation
Juno.jl copied to clipboard

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

Open JeffBezanson opened this issue 5 years ago • 4 comments

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 avatar Jul 29 '20 03:07 JeffBezanson

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.

JeffBezanson avatar Jul 29 '20 03:07 JeffBezanson

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...

pfitzseb avatar Jul 29 '20 13:07 pfitzseb

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
)

aviatesk avatar Jul 29 '20 13:07 aviatesk

I see, that's tricky.

JeffBezanson avatar Jul 29 '20 14:07 JeffBezanson