@@ -218,28 +218,28 @@ function typeinf(interp::NativeInterpreter, frame::InferenceState)
218218end 
219219typeinf (interp:: AbstractInterpreter , frame:: InferenceState ) =  _typeinf (interp, frame)
220220
221- function  finish! (interp:: AbstractInterpreter , caller:: InferenceResult )
222-     #  If we didn't transform the src for caching, we may have to transform
223-     #  it anyway for users like typeinf_ext. Do that here.
224-     opt =  caller. src
225-     if  opt isa  OptimizationState{typeof (interp)} #  implies `may_optimize(interp) === true`
226-         if  opt. ir != =  nothing 
227-             if  caller. must_be_codeinf
228-                 caller. src =  ir_to_codeinf! (opt)
229-             elseif  is_inlineable (opt. src)
230-                 #  TODO : If the CFG is too big, inlining becomes more expensive and if we're going to
231-                 #  use this IR over and over, it's worth simplifying it. Round trips through
232-                 #  CodeInstance do this implicitly, since they recompute the CFG, so try to
233-                 #  match that behavior here.
234-                 #  ir = cfg_simplify!(opt.ir)
235-                 caller. src =  opt. ir
236-             else 
237-                 #  Not cached and not inlineable - drop the ir
238-                 caller. src =  nothing 
239-             end 
240-         end 
221+ function  finish! (interp:: AbstractInterpreter , caller:: InferenceState )
222+     result =  caller. result
223+     valid_worlds =  result. valid_worlds
224+     if  last (valid_worlds) >=  get_world_counter ()
225+         #  if we aren't cached, we don't need this edge
226+         #  but our caller might, so let's just make it anyways
227+         store_backedges (result, caller. stmt_edges[1 ])
228+     end 
229+     opt =  result. src
230+     if  opt isa  OptimizationState &&  result. must_be_codeinf
231+         result. src =  opt =  ir_to_codeinf! (opt)
241232    end 
242-     return  caller. src
233+     if  opt isa  CodeInfo
234+         opt. min_world =  first (valid_worlds)
235+         opt. max_world =  last (valid_worlds)
236+         caller. src =  opt
237+     else 
238+         #  In this case caller.src is invalid for clients (such as typeinf_ext) to use
239+         #  but that is what !must_be_codeinf permits
240+         #  This is hopefully unreachable when must_be_codeinf is true
241+     end 
242+     return 
243243end 
244244
245245function  _typeinf (interp:: AbstractInterpreter , frame:: InferenceState )
@@ -266,17 +266,12 @@ function _typeinf(interp::AbstractInterpreter, frame::InferenceState)
266266        end 
267267    end 
268268    for  caller in  frames
269-         (; result ) =  caller
270-         valid_worlds =  result. valid_worlds
271-         if  last (valid_worlds) >=  get_world_counter ()
272-             #  if we aren't cached, we don't need this edge
273-             #  but our caller might, so let's just make it anyways
274-             store_backedges (result, caller. stmt_edges[1 ])
275-         end 
269+         finish! (caller. interp, caller)
276270        if  caller. cached
277-             cache_result! (caller. interp, result)
271+             cache_result! (caller. interp, caller . result)
278272        end 
279-         finish! (caller. interp, result)
273+         #  n.b. We do not drop result.src here, even though that wastes memory while it is still in the local cache
274+         #  since the user might have requested call-site inlining of it.
280275    end 
281276    empty! (frames)
282277    return  true 
367362function  transform_result_for_cache (interp:: AbstractInterpreter ,
368363    linfo:: MethodInstance , valid_worlds:: WorldRange , result:: InferenceResult )
369364    inferred_result =  result. src
370-     if  inferred_result isa  OptimizationState{typeof (interp)}
371-         #  TODO  respect must_be_codeinf setting here?
372-         result. src =  inferred_result =  ir_to_codeinf! (inferred_result)
373-     end 
374365    if  inferred_result isa  CodeInfo
375-         inferred_result. min_world =  first (valid_worlds)
376-         inferred_result. max_world =  last (valid_worlds)
377366        inferred_result =  maybe_compress_codeinfo (interp, linfo, inferred_result)
378367    end 
379368    #  The global cache can only handle objects that codegen understands
0 commit comments