diff --git a/src/interpreter.jl b/src/interpreter.jl index 84e97852..335b462b 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -65,12 +65,18 @@ end #=CC.=#get_inference_world(interp::CthulhuInterpreter) = get_inference_world(interp.native) CC.get_inference_cache(interp::CthulhuInterpreter) = get_inference_cache(interp.native) -# No need to do any locking since we're not putting our results into the runtime cache -CC.lock_mi_inference(interp::CthulhuInterpreter, mi::MethodInstance) = nothing -CC.unlock_mi_inference(interp::CthulhuInterpreter, mi::MethodInstance) = nothing +CC.may_optimize(interp::CthulhuInterpreter) = true +CC.may_compress(interp::CthulhuInterpreter) = false +CC.may_discard_trees(interp::CthulhuInterpreter) = false +CC.verbose_stmt_info(interp::CthulhuInterpreter) = true + CC.method_table(interp::CthulhuInterpreter) = method_table(interp.native) -if isdefined(CC, :cache_owner) +@static if VERSION ≥ v"1.11.0-DEV.1552" +# Since the cache for `CthulhuInterpreter` is volatile and does not involve with the +# internal code cache, technically, there's no requirement to supply `cache_owner` as an +# identifier for the internal code cache. However, the definition of `cache_owner` is +# necessary for utilizing the default `CodeInstance` constructor, define the overload here. struct CthulhuCacheToken token end @@ -80,17 +86,11 @@ end struct CthulhuCache cache::OptimizationDict end - CC.code_cache(interp::CthulhuInterpreter) = WorldView(CthulhuCache(interp.opt), WorldRange(get_inference_world(interp))) CC.get(wvc::WorldView{CthulhuCache}, mi::MethodInstance, default) = get(wvc.cache.cache, mi, default) CC.haskey(wvc::WorldView{CthulhuCache}, mi::MethodInstance) = haskey(wvc.cache.cache, mi) CC.setindex!(wvc::WorldView{CthulhuCache}, ci::CodeInstance, mi::MethodInstance) = setindex!(wvc.cache.cache, ci, mi) -CC.may_optimize(interp::CthulhuInterpreter) = true -CC.may_compress(interp::CthulhuInterpreter) = false -CC.may_discard_trees(interp::CthulhuInterpreter) = false -CC.verbose_stmt_info(interp::CthulhuInterpreter) = true - function CC.add_remark!(interp::CthulhuInterpreter, sv::InferenceState, msg) key = CC.any(sv.result.overridden_by_const) ? sv.result : sv.linfo push!(get!(PC2Remarks, interp.remarks, key), sv.currpc=>msg) diff --git a/test/setup.jl b/test/setup.jl index 8e0dfd87..ec54365b 100644 --- a/test/setup.jl +++ b/test/setup.jl @@ -3,13 +3,16 @@ if isdefined(parentmodule(@__MODULE__), :VSCodeServer) using ..VSCodeServer end -function cthulhu_info(@nospecialize(f), @nospecialize(TT=()); optimize=true) - (interp, mi) = Cthulhu.mkinterp(Core.Compiler.NativeInterpreter(), f, TT) - (; src, rt, exct, infos, slottypes, effects) = Cthulhu.lookup(interp, mi, optimize; allow_no_src=true) +function cthulhu_info(@nospecialize(f), @nospecialize(tt=()); + optimize=true, interp=Core.Compiler.NativeInterpreter()) + (interp, mi) = Cthulhu.mkinterp(f, tt; interp) + (; src, rt, exct, infos, slottypes, effects) = + Cthulhu.lookup(interp, mi, optimize; allow_no_src=true) if src !== nothing - src = Cthulhu.preprocess_ci!(src, mi, optimize, Cthulhu.CthulhuConfig(dead_code_elimination=true)) + config = Cthulhu.CthulhuConfig(; dead_code_elimination=true) + src = Cthulhu.preprocess_ci!(src, mi, optimize, config) end - (; interp, src, infos, mi, rt, exct, slottypes, effects) + return (; interp, src, infos, mi, rt, exct, slottypes, effects) end function find_callsites_by_ftt(@nospecialize(f), @nospecialize(TT=Tuple{}); optimize=true) diff --git a/test/test_AbstractInterpreter.jl b/test/test_AbstractInterpreter.jl index aa62c7f4..ece9669c 100644 --- a/test/test_AbstractInterpreter.jl +++ b/test/test_AbstractInterpreter.jl @@ -7,7 +7,7 @@ end const CC = Core.Compiler -if isdefined(CC, :cache_owner) +@static if VERSION ≥ v"1.11.0-DEV.1552" macro newinterp(InterpName) InterpCacheName = QuoteNode(Symbol(string(InterpName, "Cache"))) InterpName = esc(InterpName) @@ -77,7 +77,7 @@ macro newinterp(InterpName) $CC.setindex!(wvc::$CC.WorldView{$InterpCacheName}, ci::$C.CodeInstance, mi::$C.MethodInstance) = setindex!(wvc.cache.dict, ci, mi) end end -end # isdefined(CC, :cache_owner) +end # if VERSION ≥ v"1.11.0-DEV.1552" @doc """ @newinterp NewInterpreter diff --git a/test/test_Cthulhu.jl b/test/test_Cthulhu.jl index 2f902252..8d6b4fcd 100644 --- a/test/test_Cthulhu.jl +++ b/test/test_Cthulhu.jl @@ -268,12 +268,12 @@ end end t[1] end - @test length(callsites) == 1 # getindex(::Union{Vector{Any}, Const(tuple(1,nothing))}, ::Const(1)) + @test length(callsites) == 1 # getindex(::Union{Vector{Any}, Const(tuple(1,nothing))}, ::Const(1)) callinfo = callsites[1].info @test isa(callinfo, Cthulhu.MultiCallInfo) callinfos = callinfo.callinfos @test length(callinfos) == 2 - @test count(ci->isa(ci, Cthulhu.MICallInfo), callinfos) == 1 # getindex(::Vector{Any}, ::Const(1)) + @test count(ci->isa(ci, Cthulhu.MICallInfo), callinfos) == 1 # getindex(::Vector{Any}, ::Const(1)) @test count(ci->isa(ci, Cthulhu.ConstPropCallInfo) || isa(ci, Cthulhu.SemiConcreteCallInfo), callinfos) == 1 # getindex(::Const(tuple(1,nothing)), ::Const(1)) end @@ -1015,12 +1015,10 @@ end let (interp, mi) = Cthulhu.mkinterp((Int,)) do var::Int countvars50037(1, var) end - key = nothing - for (mi, codeinst) in interp.opt - if mi.def.name === :countvars50037 - key = mi - break - end + @static if VERSION ≥ v"1.10" + key = only(Base.specializations(only(methods(countvars50037)))) + else + key = only(methods(countvars50037)).specializations[1] end codeinst = interp.opt[key] inferred = @atomic :monotonic codeinst.inferred