384384
385385"""
386386 finish(interp::AbstractInterpreter, opt::OptimizationState,
387- params::OptimizationParams, ir::IRCode, result ) -> analyzed::Union{Nothing,ConstAPI}
387+ params::OptimizationParams, ir::IRCode, caller::InferenceResult ) -> analyzed::Union{Nothing,ConstAPI}
388388
389389Post process information derived by Julia-level optimizations for later uses:
390390- computes "purity", i.e. side-effect-freeness
@@ -394,16 +394,18 @@ In a case when the purity is proven, `finish` can return `ConstAPI` object wrapp
394394value so that the runtime system will use the constant calling convention for the method calls.
395395"""
396396function finish (interp:: AbstractInterpreter , opt:: OptimizationState ,
397- params:: OptimizationParams , ir:: IRCode , @nospecialize (result) )
397+ params:: OptimizationParams , ir:: IRCode , caller :: InferenceResult )
398398 (; src, linfo) = opt
399399 (; def, specTypes) = linfo
400400
401401 analyzed = nothing # `ConstAPI` if this call can use constant calling convention
402402 force_noinline = _any (@nospecialize (x) -> isexpr (x, :meta ) && x. args[1 ] === :noinline , ir. meta)
403403
404404 # compute inlining and other related optimizations
405- wresult = isa (result, InterConditional) ? widenconditional (result) : result
406- if (isa (wresult, Const) || isconstType (wresult))
405+ result = caller. result
406+ @assert ! (result isa LimitedAccuracy)
407+ result = isa (result, InterConditional) ? widenconditional (result) : result
408+ if (isa (result, Const) || isconstType (result))
407409 proven_pure = false
408410 # must be proven pure to use constant calling convention;
409411 # otherwise we might skip throwing errors (issue #20704)
@@ -437,14 +439,14 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
437439 # Still set pure flag to make sure `inference` tests pass
438440 # and to possibly enable more optimization in the future
439441 src. pure = true
440- if isa (wresult , Const)
441- val = wresult . val
442+ if isa (result , Const)
443+ val = result . val
442444 if is_inlineable_constant (val)
443445 analyzed = ConstAPI (val)
444446 end
445447 else
446- @assert isconstType (wresult )
447- analyzed = ConstAPI (wresult . parameters[1 ])
448+ @assert isconstType (result )
449+ analyzed = ConstAPI (result . parameters[1 ])
448450 end
449451 force_noinline || (src. inlineable = true )
450452 end
@@ -501,9 +503,10 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
501503end
502504
503505# run the optimization work
504- function optimize (interp:: AbstractInterpreter , opt:: OptimizationState , params:: OptimizationParams , @nospecialize (result))
506+ function optimize (interp:: AbstractInterpreter , opt:: OptimizationState ,
507+ params:: OptimizationParams , caller:: InferenceResult )
505508 @timeit " optimizer" ir = run_passes (opt. src, opt)
506- return finish (interp, opt, params, ir, result )
509+ return finish (interp, opt, params, ir, caller )
507510end
508511
509512function run_passes (ci:: CodeInfo , sv:: OptimizationState )
0 commit comments