From 3b254fb3fef06a4ced3a523d593b4ef20528c4bb Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Tue, 18 Jun 2024 00:34:33 +0900 Subject: [PATCH] adjustments to the latest caching interface changes --- src/interpreter.jl | 60 +++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/interpreter.jl b/src/interpreter.jl index 49fd45f8..d25f9285 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -107,8 +107,8 @@ function InferredSource(state::InferenceState) exct) end -function CC.finish(state::InferenceState, interp::CthulhuInterpreter) - res = @invoke CC.finish(state::InferenceState, interp::AbstractInterpreter) +function cthulhu_finish(@specialize(finishfunc), state::InferenceState, interp::CthulhuInterpreter) + res = @invoke finishfunc(state::InferenceState, interp::AbstractInterpreter) key = (@static VERSION ≥ v"1.12.0-DEV.317" ? CC.is_constproped(state) : CC.any(state.result.overridden_by_const)) ? state.result : state.linfo interp.unopt[key] = InferredSource(state) return res @@ -126,18 +126,44 @@ function create_cthulhu_source(@nospecialize(opt), effects::Effects) return OptimizedSource(ir, opt.src, opt.src.inlineable, effects) end -@static if VERSION ≥ v"1.12.0-DEV.15" -function CC.transform_result_for_cache(interp::CthulhuInterpreter, - linfo::MethodInstance, valid_worlds::WorldRange, result::InferenceResult, can_discard_trees::Bool=false) - return create_cthulhu_source(result.src, result.ipo_effects) +@static if VERSION ≥ v"1.12.0-DEV.734" +CC.finishinfer!(state::InferenceState, interp::CthulhuInterpreter) = cthulhu_finish(CC.finishinfer!, state, interp) +function CC.finish!(interp::CthulhuInterpreter, caller::InferenceState; + can_discard_trees::Bool=false) + result = caller.result + result.src = create_cthulhu_source(result.src, result.ipo_effects) + return @invoke CC.finish!(interp::AbstractInterpreter, caller::InferenceState; + can_discard_trees) end -else -function CC.transform_result_for_cache(interp::CthulhuInterpreter, - linfo::MethodInstance, valid_worlds::WorldRange, result::InferenceResult) + +elseif VERSION ≥ v"1.11.0-DEV.737" +CC.finish(state::InferenceState, interp::CthulhuInterpreter) = cthulhu_finish(CC.finish, state, interp) +function CC.finish!(interp::CthulhuInterpreter, caller::InferenceState) + result = caller.result + opt = result.src + result.src = create_cthulhu_source(opt, result.ipo_effects) + if opt isa CC.OptimizationState + CC.ir_to_codeinf!(opt) + end + return nothing +end +function CC.transform_result_for_cache(::CthulhuInterpreter, ::MethodInstance, ::WorldRange, + result::InferenceResult) + return result.src +end + +else # VERSION < v"1.11.0-DEV.737" +CC.finish(state::InferenceState, interp::CthulhuInterpreter) = cthulhu_finish(CC.finish, state, interp) +function CC.transform_result_for_cache(::CthulhuInterpreter, ::MethodInstance, ::WorldRange, + result::InferenceResult) return create_cthulhu_source(result.src, result.ipo_effects) end +function CC.finish!(interp::CthulhuInterpreter, caller::InferenceResult) + caller.src = create_cthulhu_source(caller.src, caller.ipo_effects) end +end # @static if + @static if VERSION ≥ v"1.12.0-DEV.45" function CC.src_inlining_policy(interp::CthulhuInterpreter, @nospecialize(src), @nospecialize(info::CCCallInfo), stmt_flag::UInt32) @@ -210,22 +236,6 @@ function CC.IRInterpretationState(interp::CthulhuInterpreter, code.min_world, code.max_world) end -@static if VERSION ≥ v"1.11.0-DEV.737" -function CC.finish!(interp::CthulhuInterpreter, caller::InferenceState) - result = caller.result - opt = result.src - result.src = create_cthulhu_source(opt, result.ipo_effects) - if opt isa CC.OptimizationState - CC.ir_to_codeinf!(opt) - end - return nothing -end -else -function CC.finish!(interp::CthulhuInterpreter, caller::InferenceResult) - caller.src = create_cthulhu_source(caller.src, caller.ipo_effects) -end -end - @static if VERSION ≥ v"1.11.0-DEV.1127" function CC.update_exc_bestguess!(interp::CthulhuInterpreter, @nospecialize(exct), frame::InferenceState)