@@ -63,13 +63,13 @@ function rewrite_inst(inst, ir)
6363 ft = Core. Compiler. widenconst (maybe_argextype (inst. args[1 ], ir))
6464 if ! (ft <: Core.IntrinsicFunction ) && ! (ft <: Core.Builtin )
6565 rep = Expr (:call , call_with_reactant, inst. args... )
66- return rep
66+ return true , rep
6767 end
6868 end
6969 if Meta. isexpr (inst, :invoke )
70- return Expr (:call , inst. args[2 : end ]. .. )
70+ return false , Expr (:call , inst. args[2 : end ]. .. )
7171 end
72- return inst
72+ return false , inst
7373end
7474
7575const REDUB_ARGUMENTS_NAME = gensym (" redub_arguments" )
@@ -120,10 +120,14 @@ function _arg_partially_inline!(@nospecialize(x), slot_replacements::Vector{Any}
120120 return x
121121 end
122122 if isa (x, Core. ReturnNode)
123- return Core. ReturnNode (
123+ if ! isdefined (x, :val )
124+ return Core. ReturnNode (:nothing )
125+ else
126+ return Core. ReturnNode (
124127 _arg_partially_inline! (x. val, slot_replacements, type_signature, static_param_values,
125128 slot_offset, arg_offset, statement_offset, boundscheck),
126- )
129+ )
130+ end
127131 end
128132 if isa (x, Core. GotoIfNot)
129133 return Core. GotoIfNot (
@@ -257,12 +261,19 @@ function call_with_reactant_generator(world::UInt, source::LineNumberNode, self,
257261 Core. Compiler. typeinf (interp, frame)
258262 @assert Core. Compiler. is_inferred (frame)
259263
264+ method = match. method
265+ @show mi
266+ @show method
267+
260268 # if Core.Compiler.result_is_constabi(interp, frame.result)
261269 # rt = frame.result.result::Core.Compiler.Const
262270 # src = Core.Compiler.codeinfo_for_const(interp, frame.linfo, rt.val)
263271 # else
264272 opt = Core. Compiler. OptimizationState (frame, interp)
265273
274+ @show Core. Compiler. retrieve_code_info (mi, world)
275+ @show opt. src
276+
266277 caller = frame. result
267278 @static if VERSION < v " 1.11-"
268279 ir = Core. Compiler. run_passes (opt. src, opt, caller)
@@ -271,21 +282,35 @@ function call_with_reactant_generator(world::UInt, source::LineNumberNode, self,
271282 Core. Compiler. ipo_dataflow_analysis! (interp, opt, ir, caller)
272283 end
273284
274- for (i, inst) in enumerate (ir. stmts)
285+ @show ir
286+ any_changed = false
287+ for (i, inst) in enumerate (ir. stmts)
275288
289+
276290 @static if VERSION < v " 1.11"
277- Core. Compiler. setindex! (ir. stmts[i], rewrite_inst (inst[:inst ], ir), :inst )
291+ changed, next = rewrite_inst (inst[:inst ], ir)
292+ Core. Compiler. setindex! (ir. stmts[i], next, :inst )
278293 else
279- Core. Compiler. setindex! (ir. stmts[i], rewrite_inst (inst[:stmt ], ir), :stmt )
294+ changed, next = rewrite_inst (inst[:stmt ], ir)
295+ Core. Compiler. setindex! (ir. stmts[i], next, :stmt )
280296 end
281- Core. Compiler. setindex! (ir. stmts[i], Any, :type )
297+ if changed
298+ any_changed = true
299+ Core. Compiler. setindex! (ir. stmts[i], Any, :type )
300+ end
282301 end
283302 Core. Compiler. finish (interp, opt, ir, caller)
303+ @show " post" , ir
284304 src = Core. Compiler. ir_to_codeinf! (opt)
305+
306+ @show any_changed, src
307+ if ! any_changed
308+ src = Core. Compiler. retrieve_code_info (mi, world)
309+ @show " post non change" , src
310+ end
285311
286312 # prepare a new code info
287313 code_info = copy (src)
288- method = match. method
289314 static_params = match. sparams
290315 signature = sig
291316 is_invoke = args[1 ] === typeof (Core. invoke)
@@ -352,6 +377,7 @@ function call_with_reactant_generator(world::UInt, source::LineNumberNode, self,
352377 push! (fn_args, Core. SSAValue (length (overdubbed_code)))
353378 end
354379
380+ @show code_info. code
355381 #= == finish initialization of `overdubbed_code`/`overdubbed_codelocs` ===#
356382
357383 # substitute static parameters, offset slot numbers by number of added slots, and
@@ -383,6 +409,8 @@ function call_with_reactant_generator(world::UInt, source::LineNumberNode, self,
383409 code_info. ssavaluetypes = length (overdubbed_code)
384410 code_info. ssaflags = [0x00 for _ in 1 : length (overdubbed_code)] # XXX we need to copy flags that are set for the original code
385411
412+ @show code_info
413+
386414 return code_info
387415end
388416
0 commit comments