From 440d59d3de52bd625eea5b4e5fa876ba4ac5318d Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Mon, 6 Sep 2021 22:20:04 +0900 Subject: [PATCH] update to https://github.com/JuliaLang/julia/pull/42082 --- .github/workflows/CI.yml | 1 + src/Cthulhu.jl | 5 +++- src/interpreter.jl | 9 +++++++- test/runtests.jl | 49 +++++++++++++++++++++------------------- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index daf17463..fea659c6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,6 +14,7 @@ jobs: matrix: version: - 'nightly' + - '1.7-nightly' os: - ubuntu-latest - macOS-latest diff --git a/src/Cthulhu.jl b/src/Cthulhu.jl index e9612e86..4a385d72 100644 --- a/src/Cthulhu.jl +++ b/src/Cthulhu.jl @@ -430,7 +430,10 @@ function do_typeinf!(interp::CthulhuInterpreter, mi::MethodInstance) # we may want to handle the case when `InferenceState(...)` returns `nothing`, # which indicates code generation of a `@generated` has been failed, # and show it in the UI in some way ? - frame = InferenceState(result, true, interp)::InferenceState + # branch on https://github.com/JuliaLang/julia/pull/42082 + frame = @static hasmethod(InferenceState, (InferenceResult,Symbol,AbstractInterpreter)) ? + InferenceState(result, #=cache=# :global, interp)::InferenceState : + InferenceState(result, #=cached=# true, interp)::InferenceState Core.Compiler.typeinf(interp, frame) return nothing end diff --git a/src/interpreter.jl b/src/interpreter.jl index 53845375..591979e8 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -84,12 +84,19 @@ end # branch on https://github.com/JuliaLang/julia/pull/41328 @static if isdefined(Compiler, :is_stmt_inline) -function Compiler.inlining_policy(interp::CthulhuInterpreter, @nospecialize(src), stmt_flag::UInt8) +function Compiler.inlining_policy( + interp::CthulhuInterpreter, @nospecialize(src), stmt_flag::UInt8, + mi::MethodInstance, argtypes::Vector{Any}) @assert isa(src, OptimizedSource) || isnothing(src) if isa(src, OptimizedSource) if Compiler.is_stmt_inline(stmt_flag) || src.isinlineable return src.ir end + else + # the default inlining policy may try additional effor to find the source in a local cache + return Base.@invoke Compiler.inlining_policy( + interp::AbstractInterpreter, nothing, stmt_flag::UInt8, + mi::MethodInstance, argtypes::Vector{Any}) end return nothing end diff --git a/test/runtests.jl b/test/runtests.jl index 725a7547..3bda5819 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -99,29 +99,32 @@ let callsites = find_callsites_by_ftt(call_by_apply, Tuple{Tuple{Int}}; optimize @test length(callsites) == 1 end -if Base.JLOptions().check_bounds ∈ (0, 2) - @testset "DCE & boundscheck" begin - Base.@propagate_inbounds function f(x) - @boundscheck error() - end - g(x) = @inbounds f(x) - h(x) = f(x) - - (_,CI, _, _, _, _) = process(g, Tuple{Vector{Float64}}) - @test all(CI.stmts.inst) do stmt - isa(stmt, Core.GotoNode) || (isa(stmt, Core.ReturnNode) && isdefined(stmt, :val)) || Base.Meta.isexpr(stmt, :code_coverage_effect, 0) - end - - (_,CI, _, _, _, _) = process(h, Tuple{Vector{Float64}}) - i = 1 - while CI.stmts.inst[i] === nothing || Base.Meta.isexpr(CI.stmts.inst[i], :code_coverage_effect, 0) - i += 1 - end - @test length(CI.stmts) - i + 1 == 2 - stmt = CI.stmts.inst[end] - @test isa(stmt, Core.ReturnNode) && !isdefined(stmt, :val) - end -end +# # TODO run this testset in a separate process +# # julia --check-bounds=auto --code-coverage=none +# @testset "DCE & boundscheck" begin +# M = Module() +# @eval M begin +# Base.@propagate_inbounds function f(x) +# @boundscheck error() +# end +# g(x) = @inbounds f(x) +# h(x) = f(x) +# end +# +# let +# (_,CI, _, _, _, _) = process(M.g, Tuple{Vector{Float64}}) +# @test all(CI.stmts.inst) do stmt +# isa(stmt, Core.GotoNode) || (isa(stmt, Core.ReturnNode) && isdefined(stmt, :val)) +# end +# end +# +# let +# (_,CI, _, _, _, _) = process(M.h, Tuple{Vector{Float64}}) +# @test count(!isnothing, CI.stmts.inst) == 2 +# stmt = CI.stmts.inst[end] +# @test isa(stmt, Core.ReturnNode) && !isdefined(stmt, :val) +# end +# end # Something with many methods, but enough to be under the match limit g_matches(a::Int, b::Int) = a+b