Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor follow up on the tagged code instance change #543

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions test/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/test_AbstractInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions test/test_Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading