Skip to content

Commit 3e7282d

Browse files
committed
handle globalref inside args & const invoke
1 parent 1d46918 commit 3e7282d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/passes.jl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,19 @@ function inline_const!(ir::IRCode)
138138
t isa Const || continue
139139
ir.stmts[i][:inst] = quoted(t.val)
140140
ir.stmts[i][:type] = t
141-
@case Expr(:call, _...)
142-
sig = Core.Compiler.call_sig(ir, stmt)
141+
@case Expr(:call, f, args...)
142+
new_stmt = Expr(:call, f, map(eval_global, args)...)
143+
sig = Core.Compiler.call_sig(ir, new_stmt)
143144
if is_const_call_inlineable(sig)
144145
fargs = anymap(x::Const -> x.val, sig.atypes[2:end])
145146
val = sig.f(fargs...)
146147
ir.stmts[i][:inst] = quoted(val)
147148
ir.stmts[i][:type] = Const(val)
149+
else
150+
ir.stmts[i][:inst] = new_stmt
148151
end
152+
@case Expr(:invoke, mi, f, args...)
153+
ir.stmts[i][:inst] = Expr(:invoke, mi, f, map(eval_global, args)...)
149154
@case Expr(:new, t, args...)
150155
allconst = all(x->is_arg_allconst(ir, x), args)
151156
allconst && isconcretetype(t) && !t.mutable || continue
@@ -160,6 +165,17 @@ function inline_const!(ir::IRCode)
160165
return ir
161166
end
162167

168+
function eval_global(x)
169+
@switch x begin
170+
@case GlobalRef(mod, name)
171+
t = Core.Compiler.abstract_eval_global(mod, name)
172+
t isa Const || return x
173+
return quoted(t.val)
174+
@case _
175+
return x
176+
end
177+
end
178+
163179
"""
164180
const_invoke!(f, ir::IRCode, ref::GlobalRef)
165181
@@ -171,7 +187,7 @@ function const_invoke!(f, ir::IRCode, ref::GlobalRef)
171187
stmt = ir.stmts[i][:inst]
172188

173189
@switch stmt begin
174-
@case Expr(:invoke, _, ref, args...)
190+
@case Expr(:invoke, _, &ref, args...)
175191
if all(x->is_arg_allconst(ir, x), args)
176192
args = anymap(x->unwrap_arg(ir, x), args)
177193
val = f(args...)

0 commit comments

Comments
 (0)