diff --git a/src/interpreter.jl b/src/interpreter.jl index a09484b9..a8b5c98c 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -76,15 +76,28 @@ function Compiler.add_remark!(interp::CthulhuInterpreter, sv::InferenceState, ms end function Compiler.finish(state::InferenceState, interp::CthulhuInterpreter) - r = @invoke Compiler.finish(state::InferenceState, interp::AbstractInterpreter) - interp.unopt[Core.Compiler.any(state.result.overridden_by_const) ? state.result : state.linfo] = InferredSource( + res = @invoke Compiler.finish(state::InferenceState, interp::AbstractInterpreter) + key = Core.Compiler.any(state.result.overridden_by_const) ? state.result : state.linfo + interp.unopt[key] = InferredSource( copy(state.src), copy(state.stmt_info), isdefined(Core.Compiler, :Effects) ? state.ipo_effects : nothing, state.result.result) - return r + return res end +# branch on https://github.com/JuliaLang/julia/pull/43994 +const AFTER_43994 = isdefined(Compiler, :transform_optresult_for_cache) + +@static if AFTER_43994 +function Compiler.transform_result_for_cache(interp::CthulhuInterpreter, linfo::MethodInstance, + valid_worlds::WorldRange, result::InferenceResult) + inferred_result = result.src + return isa(inferred_result, OptimizedSource) ? inferred_result : + isa(inferred_result, Compiler.ConstAPI) ? inferred_result : + nothing +end +else # @static if AFTER_43994 function Compiler.transform_result_for_cache(interp::CthulhuInterpreter, linfo::MethodInstance, valid_worlds::WorldRange, @nospecialize(inferred_result), ipo_effects::Effects = Effects()) if isa(inferred_result, OptimizationState) @@ -96,6 +109,7 @@ function Compiler.transform_result_for_cache(interp::CthulhuInterpreter, linfo:: end return inferred_result end +end # @static if AFTER_43994 # branch on https://github.com/JuliaLang/julia/pull/41328 @static if isdefined(Compiler, :is_stmt_inline) @@ -124,6 +138,13 @@ function Compiler.inlining_policy(interp::CthulhuInterpreter) end end # @static if isdefined(Compiler, :is_stmt_inline) +@static if AFTER_43994 +function Compiler.transform_optresult_for_cache(interp::CthulhuInterpreter, + opt::OptimizationState, ir::IRCode, @nospecialize(newresult)) + isa(newresult, Compiler.ConstAPI) && return newresult + return OptimizedSource(ir, opt.src, opt.src.inlineable) +end +else # @static if AFTER_43994 function Compiler.finish!(interp::CthulhuInterpreter, caller::InferenceResult) src = caller.src if isa(src, OptimizationState) @@ -134,3 +155,4 @@ function Compiler.finish!(interp::CthulhuInterpreter, caller::InferenceResult) end end end +end # @static if AFTER_43994 diff --git a/test/utils.jl b/test/utils.jl index 17b6ddcb..8fa5299b 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -26,9 +26,10 @@ function strip_base_linenums(s) end function irshow_filename(optimize, debuginfo, iswarn, hide_type_stable, inline_cost, type_annotations) - return "test_output/foo-$(optimize ? :opt : :unopt)-$(debuginfo)-$(iswarn ? :warn : :nowarn)\ + p = "test_output/foo-$(optimize ? :opt : :unopt)-$(debuginfo)-$(iswarn ? :warn : :nowarn)\ -$(hide_type_stable ? :hide_type_stable : :show_type_stable)-$(inline_cost ? :inline_cost : :nocost)\ -$(type_annotations ? :types : :notypes)" + return normpath(@__DIR__, p) end # to generate test cases for IRShow tests