Skip to content

Commit 0bdaaa5

Browse files
committed
update with JuliaLang/#43994
1 parent de98e6a commit 0bdaaa5

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/interpreter.jl

+25-3
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,28 @@ function Compiler.add_remark!(interp::CthulhuInterpreter, sv::InferenceState, ms
7676
end
7777

7878
function Compiler.finish(state::InferenceState, interp::CthulhuInterpreter)
79-
r = @invoke Compiler.finish(state::InferenceState, interp::AbstractInterpreter)
80-
interp.unopt[Core.Compiler.any(state.result.overridden_by_const) ? state.result : state.linfo] = InferredSource(
79+
res = @invoke Compiler.finish(state::InferenceState, interp::AbstractInterpreter)
80+
key = Core.Compiler.any(state.result.overridden_by_const) ? state.result : state.linfo
81+
interp.unopt[key] = InferredSource(
8182
copy(state.src),
8283
copy(state.stmt_info),
8384
isdefined(Core.Compiler, :Effects) ? state.ipo_effects : nothing,
8485
state.result.result)
85-
return r
86+
return res
8687
end
8788

89+
# branch on https://github.com/JuliaLang/julia/pull/43994
90+
const AFTER_43994 = isdefined(Compiler, :transform_optresult_for_cache)
91+
92+
@static if AFTER_43994
93+
function Compiler.transform_result_for_cache(interp::CthulhuInterpreter, linfo::MethodInstance,
94+
valid_worlds::WorldRange, result::InferenceResult)
95+
inferred_result = result.src
96+
return isa(inferred_result, OptimizedSource) ? inferred_result :
97+
isa(inferred_result, Compiler.ConstAPI) ? inferred_result :
98+
nothing
99+
end
100+
else # @static if AFTER_43994
88101
function Compiler.transform_result_for_cache(interp::CthulhuInterpreter, linfo::MethodInstance,
89102
valid_worlds::WorldRange, @nospecialize(inferred_result))
90103
if isa(inferred_result, OptimizationState)
@@ -96,6 +109,7 @@ function Compiler.transform_result_for_cache(interp::CthulhuInterpreter, linfo::
96109
end
97110
return inferred_result
98111
end
112+
end # @static if AFTER_43994
99113

100114
# branch on https://github.com/JuliaLang/julia/pull/41328
101115
@static if isdefined(Compiler, :is_stmt_inline)
@@ -124,6 +138,13 @@ function Compiler.inlining_policy(interp::CthulhuInterpreter)
124138
end
125139
end # @static if isdefined(Compiler, :is_stmt_inline)
126140

141+
@static if AFTER_43994
142+
function Compiler.transform_optresult_for_cache(interp::CthulhuInterpreter,
143+
opt::OptimizationState, ir::IRCode, @nospecialize(newresult))
144+
isa(newresult, Compiler.ConstAPI) && return newresult
145+
return OptimizedSource(ir, opt.src, opt.src.inlineable)
146+
end
147+
else # @static if AFTER_43994
127148
function Compiler.finish!(interp::CthulhuInterpreter, caller::InferenceResult)
128149
src = caller.src
129150
if isa(src, OptimizationState)
@@ -134,3 +155,4 @@ function Compiler.finish!(interp::CthulhuInterpreter, caller::InferenceResult)
134155
end
135156
end
136157
end
158+
end # @static if AFTER_43994

test/utils.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ function strip_base_linenums(s)
2626
end
2727

2828
function irshow_filename(optimize, debuginfo, iswarn, hide_type_stable, inline_cost, type_annotations)
29-
return "test_output/foo-$(optimize ? :opt : :unopt)-$(debuginfo)-$(iswarn ? :warn : :nowarn)\
29+
p = "test_output/foo-$(optimize ? :opt : :unopt)-$(debuginfo)-$(iswarn ? :warn : :nowarn)\
3030
-$(hide_type_stable ? :hide_type_stable : :show_type_stable)-$(inline_cost ? :inline_cost : :nocost)\
3131
-$(type_annotations ? :types : :notypes)"
32+
return normpath(@__DIR__, p)
3233
end
3334

3435
# to generate test cases for IRShow tests

0 commit comments

Comments
 (0)