Open
Description
Ran into this today:
julia> using CodeInfoTools
julia> x = 1 #global variable
1
julia> f(y) = x + y;
julia> code_info(f, Int)
CodeInfo(
1 ─ %1 = Main.x + y
└── return %1
)
julia> for (v, st) ∈ Builder(ans)
@show st
end
st = :((+)(1, _2))
st = :(return %1)
Here, we can see that the global variable x
's value got embedded directly into the IR from the Builder
, rather than a reference to it. This can cause subtle and hard to track down errors in code generated with Builder
.
IMO x
and +
should both be GlobalRef
s here.
julia> let b = Builder(code_info(f, Int))
for (v, st) ∈ b
b[v] = b[v]
end
finish(b)
end
CodeInfo(
@ REPL[8]:1 within `f`
1 ─ %1 = (+)(1, y)
└── return %1
)
Metadata
Metadata
Assignees
Labels
No labels