Open JeffBezanson opened 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.
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...
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
)
I see, that's tricky.
I tried debugging code that uses
@spawn
just for fun, and inside the macro a line is annotated withtypeof(10)
. I have no idea why.