Skip to content

Commit

Permalink
update with JuliaLang/#43994
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Mar 27, 2022
1 parent de98e6a commit 0bdaaa5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
if isa(inferred_result, OptimizationState)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -134,3 +155,4 @@ function Compiler.finish!(interp::CthulhuInterpreter, caller::InferenceResult)
end
end
end
end # @static if AFTER_43994
3 changes: 2 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bdaaa5

Please sign in to comment.