Skip to content

Commit ff129ca

Browse files
authored
minor follow up on the tagged code instance change (#543)
1 parent e59b7fe commit ff129ca

4 files changed

Lines changed: 26 additions & 25 deletions

File tree

src/interpreter.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ end
6565
#=CC.=#get_inference_world(interp::CthulhuInterpreter) = get_inference_world(interp.native)
6666
CC.get_inference_cache(interp::CthulhuInterpreter) = get_inference_cache(interp.native)
6767

68-
# No need to do any locking since we're not putting our results into the runtime cache
69-
CC.lock_mi_inference(interp::CthulhuInterpreter, mi::MethodInstance) = nothing
70-
CC.unlock_mi_inference(interp::CthulhuInterpreter, mi::MethodInstance) = nothing
68+
CC.may_optimize(interp::CthulhuInterpreter) = true
69+
CC.may_compress(interp::CthulhuInterpreter) = false
70+
CC.may_discard_trees(interp::CthulhuInterpreter) = false
71+
CC.verbose_stmt_info(interp::CthulhuInterpreter) = true
72+
7173
CC.method_table(interp::CthulhuInterpreter) = method_table(interp.native)
7274

73-
if isdefined(CC, :cache_owner)
75+
@static if VERSION v"1.11.0-DEV.1552"
76+
# Since the cache for `CthulhuInterpreter` is volatile and does not involve with the
77+
# internal code cache, technically, there's no requirement to supply `cache_owner` as an
78+
# identifier for the internal code cache. However, the definition of `cache_owner` is
79+
# necessary for utilizing the default `CodeInstance` constructor, define the overload here.
7480
struct CthulhuCacheToken
7581
token
7682
end
@@ -80,17 +86,11 @@ end
8086
struct CthulhuCache
8187
cache::OptimizationDict
8288
end
83-
8489
CC.code_cache(interp::CthulhuInterpreter) = WorldView(CthulhuCache(interp.opt), WorldRange(get_inference_world(interp)))
8590
CC.get(wvc::WorldView{CthulhuCache}, mi::MethodInstance, default) = get(wvc.cache.cache, mi, default)
8691
CC.haskey(wvc::WorldView{CthulhuCache}, mi::MethodInstance) = haskey(wvc.cache.cache, mi)
8792
CC.setindex!(wvc::WorldView{CthulhuCache}, ci::CodeInstance, mi::MethodInstance) = setindex!(wvc.cache.cache, ci, mi)
8893

89-
CC.may_optimize(interp::CthulhuInterpreter) = true
90-
CC.may_compress(interp::CthulhuInterpreter) = false
91-
CC.may_discard_trees(interp::CthulhuInterpreter) = false
92-
CC.verbose_stmt_info(interp::CthulhuInterpreter) = true
93-
9494
function CC.add_remark!(interp::CthulhuInterpreter, sv::InferenceState, msg)
9595
key = CC.any(sv.result.overridden_by_const) ? sv.result : sv.linfo
9696
push!(get!(PC2Remarks, interp.remarks, key), sv.currpc=>msg)

test/setup.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ if isdefined(parentmodule(@__MODULE__), :VSCodeServer)
33
using ..VSCodeServer
44
end
55

6-
function cthulhu_info(@nospecialize(f), @nospecialize(TT=()); optimize=true)
7-
(interp, mi) = Cthulhu.mkinterp(Core.Compiler.NativeInterpreter(), f, TT)
8-
(; src, rt, exct, infos, slottypes, effects) = Cthulhu.lookup(interp, mi, optimize; allow_no_src=true)
6+
function cthulhu_info(@nospecialize(f), @nospecialize(tt=());
7+
optimize=true, interp=Core.Compiler.NativeInterpreter())
8+
(interp, mi) = Cthulhu.mkinterp(f, tt; interp)
9+
(; src, rt, exct, infos, slottypes, effects) =
10+
Cthulhu.lookup(interp, mi, optimize; allow_no_src=true)
911
if src !== nothing
10-
src = Cthulhu.preprocess_ci!(src, mi, optimize, Cthulhu.CthulhuConfig(dead_code_elimination=true))
12+
config = Cthulhu.CthulhuConfig(; dead_code_elimination=true)
13+
src = Cthulhu.preprocess_ci!(src, mi, optimize, config)
1114
end
12-
(; interp, src, infos, mi, rt, exct, slottypes, effects)
15+
return (; interp, src, infos, mi, rt, exct, slottypes, effects)
1316
end
1417

1518
function find_callsites_by_ftt(@nospecialize(f), @nospecialize(TT=Tuple{}); optimize=true)

test/test_AbstractInterpreter.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ end
77

88
const CC = Core.Compiler
99

10-
if isdefined(CC, :cache_owner)
10+
@static if VERSION v"1.11.0-DEV.1552"
1111
macro newinterp(InterpName)
1212
InterpCacheName = QuoteNode(Symbol(string(InterpName, "Cache")))
1313
InterpName = esc(InterpName)
@@ -77,7 +77,7 @@ macro newinterp(InterpName)
7777
$CC.setindex!(wvc::$CC.WorldView{$InterpCacheName}, ci::$C.CodeInstance, mi::$C.MethodInstance) = setindex!(wvc.cache.dict, ci, mi)
7878
end
7979
end
80-
end # isdefined(CC, :cache_owner)
80+
end # if VERSION ≥ v"1.11.0-DEV.1552"
8181

8282
@doc """
8383
@newinterp NewInterpreter

test/test_Cthulhu.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ end
268268
end
269269
t[1]
270270
end
271-
@test length(callsites) == 1 # getindex(::Union{Vector{Any}, Const(tuple(1,nothing))}, ::Const(1))
271+
@test length(callsites) == 1 # getindex(::Union{Vector{Any}, Const(tuple(1,nothing))}, ::Const(1))
272272
callinfo = callsites[1].info
273273
@test isa(callinfo, Cthulhu.MultiCallInfo)
274274
callinfos = callinfo.callinfos
275275
@test length(callinfos) == 2
276-
@test count(ci->isa(ci, Cthulhu.MICallInfo), callinfos) == 1 # getindex(::Vector{Any}, ::Const(1))
276+
@test count(ci->isa(ci, Cthulhu.MICallInfo), callinfos) == 1 # getindex(::Vector{Any}, ::Const(1))
277277
@test count(ci->isa(ci, Cthulhu.ConstPropCallInfo) || isa(ci, Cthulhu.SemiConcreteCallInfo), callinfos) == 1 # getindex(::Const(tuple(1,nothing)), ::Const(1))
278278
end
279279

@@ -1015,12 +1015,10 @@ end
10151015
let (interp, mi) = Cthulhu.mkinterp((Int,)) do var::Int
10161016
countvars50037(1, var)
10171017
end
1018-
key = nothing
1019-
for (mi, codeinst) in interp.opt
1020-
if mi.def.name === :countvars50037
1021-
key = mi
1022-
break
1023-
end
1018+
@static if VERSION v"1.10"
1019+
key = only(Base.specializations(only(methods(countvars50037))))
1020+
else
1021+
key = only(methods(countvars50037)).specializations[1]
10241022
end
10251023
codeinst = interp.opt[key]
10261024
inferred = @atomic :monotonic codeinst.inferred

0 commit comments

Comments
 (0)