@@ -138,14 +138,19 @@ function inline_const!(ir::IRCode)
138
138
t isa Const || continue
139
139
ir. stmts[i][:inst ] = quoted (t. val)
140
140
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)
143
144
if is_const_call_inlineable (sig)
144
145
fargs = anymap (x:: Const -> x. val, sig. atypes[2 : end ])
145
146
val = sig. f (fargs... )
146
147
ir. stmts[i][:inst ] = quoted (val)
147
148
ir. stmts[i][:type ] = Const (val)
149
+ else
150
+ ir. stmts[i][:inst ] = new_stmt
148
151
end
152
+ @case Expr (:invoke , mi, f, args... )
153
+ ir. stmts[i][:inst ] = Expr (:invoke , mi, f, map (eval_global, args)... )
149
154
@case Expr (:new , t, args... )
150
155
allconst = all (x-> is_arg_allconst (ir, x), args)
151
156
allconst && isconcretetype (t) && ! t. mutable || continue
@@ -160,6 +165,17 @@ function inline_const!(ir::IRCode)
160
165
return ir
161
166
end
162
167
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
+
163
179
"""
164
180
const_invoke!(f, ir::IRCode, ref::GlobalRef)
165
181
@@ -171,7 +187,7 @@ function const_invoke!(f, ir::IRCode, ref::GlobalRef)
171
187
stmt = ir. stmts[i][:inst ]
172
188
173
189
@switch stmt begin
174
- @case Expr (:invoke , _, ref, args... )
190
+ @case Expr (:invoke , _, & ref, args... )
175
191
if all (x-> is_arg_allconst (ir, x), args)
176
192
args = anymap (x-> unwrap_arg (ir, x), args)
177
193
val = f (args... )
0 commit comments