Skip to content

Commit 7f126aa

Browse files
committed
Evaluate GlobalRef only if binding is defined
1 parent 4c2bca7 commit 7f126aa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/codegen/reverse.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,20 @@ function diffract_ir!(ir, ci, meth, sparams::Core.SimpleVector, nargs::Int, N::I
683683
end
684684

685685
eval_globalref(x) = x
686-
eval_globalref(x::GlobalRef) = getglobal(x.mod, x.name)
686+
function eval_globalref(ref::GlobalRef)
687+
isdefined(ref.mod, ref.name) || return nothing
688+
getproperty(ref.mod, ref.name)
689+
end
687690
ssa_def(ir, idx::SSAValue) = ssa_def(ir, ir[idx][:inst])
688691
ssa_def(ir, def) = def
689692

690693
function is_global_access(ir::Union{IRCode,IncrementalCompact}, stmt)
691694
isexpr(stmt, :call, 3) || return false
692-
f = eval_globalref(ssa_def(ir, stmt.args[1]))
695+
f = ssa_def(ir, stmt.args[1])
696+
if isa(f, GlobalRef)
697+
f.name === :getproperty || return false
698+
f = eval_globalref(f)
699+
end
693700
f === getproperty || return false
694701
from = eval_globalref(ssa_def(ir, stmt.args[2]))
695702
isa(from, Module) || return false

0 commit comments

Comments
 (0)