Repository: JuliaDebug/Cthulhu.jl
Pull request #539 (2024-02-08 13:11:22)

adjust to JuliaLang/julia#53088

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug) Report
Attention: `6 lines` in your changes are missing coverage. Please review.
> Comparison is base [(`5411430`)](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/commit/54114302c9ab0403009d762cf11a73a439b670d3?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug) 0.00% compared to head [(`16e55e2`)](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug) 0.00%.

| [Files](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug) | Patch % | Lines |
|---|---|---|
| [src/interpreter.jl](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug#diff-c3JjL2ludGVycHJldGVyLmps) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug) |
| [src/reflection.jl](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug#diff-c3JjL3JlZmxlY3Rpb24uamw=) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug) |
| [src/Cthulhu.jl](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug#diff-c3JjL0N0aHVsaHUuamw=) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug) |
| [src/codeview.jl](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug#diff-c3JjL2NvZGV2aWV3Lmps) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug) |

<details><summary>Additional details and impacted files</summary>


```diff
@@          Coverage Diff           @@
##           master    #539   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files           9       9           
  Lines        1552    1552           
======================================
  Misses       1552    1552           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/JuliaDebug/Cthulhu.jl/pull/539?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaDebug).


Patch:
diff --git a/src/Cthulhu.jl b/src/Cthulhu.jl
index 46b98bd..5954af9 100644
--- a/src/Cthulhu.jl
+++ b/src/Cthulhu.jl
@@ -20,6 +20,13 @@ const mapany = Base.mapany
 
 const ArgTypes = Vector{Any}
 
+@static if VERSION ≥ v"1.11.0-DEV.1498"
+    import .CC: get_inference_world
+    using Base: get_world_counter
+else
+    import .CC: get_world_counter, get_world_counter as get_inference_world
+end
+
 Base.@kwdef mutable struct CthulhuConfig
     enable_highlighter::Bool = false
     highlighter::Cmd = `pygmentize -l`
@@ -728,7 +735,7 @@ function _descend(term::AbstractTerminal, interp::AbstractInterpreter, curs::Abs
             display_CI = true
         elseif toggle === :ast || toggle === :llvm || toggle === :native
             view_cmd = CODEVIEWS[toggle]
-            world = get_world_counter(interp)
+            world = get_inference_world(interp)
             println(iostream)
             view_cmd(iostream, mi, optimize, debuginfo, world, CONFIG)
             display_CI = false
diff --git a/src/codeview.jl b/src/codeview.jl
index a1ccd4d..b7c987a 100644
--- a/src/codeview.jl
+++ b/src/codeview.jl
@@ -447,7 +447,7 @@ const BOOKMARKS = Bookmark[]
 function Base.show(
     io::IO, ::MIME"text/plain", b::Bookmark;
     optimize::Bool=false, debuginfo::AnyDebugInfo=:none, iswarn::Bool=false, hide_type_stable::Bool=false)
-    world = get_world_counter(b.interp)
+    world = get_inference_world(b.interp)
     CI, rt = InteractiveUtils.code_typed(b; optimize)
     (; interp, mi) = b
     (; effects) = lookup(interp, mi, optimize)
@@ -505,7 +505,7 @@ InteractiveUtils.code_llvm(
     b.mi,
     optimize,
     debuginfo === :source,
-    get_world_counter(b.interp),
+    get_inference_world(b.interp),
     config,
     dump_module,
     raw,
@@ -526,7 +526,7 @@ InteractiveUtils.code_native(
     b.mi,
     optimize,
     debuginfo === :source,
-    get_world_counter(b.interp),
+    get_inference_world(b.interp),
     config,
     dump_module,
     raw,
diff --git a/src/interpreter.jl b/src/interpreter.jl
index 620fb61..8e93250 100644
--- a/src/interpreter.jl
+++ b/src/interpreter.jl
@@ -50,7 +50,7 @@ function CthulhuInterpreter(interp::AbstractInterpreter=NativeInterpreter())
         InferenceDict{PC2Excts}())
 end
 
-import .CC: InferenceParams, OptimizationParams, get_world_counter,
+import .CC: InferenceParams, OptimizationParams, #=get_inference_world,=#
     get_inference_cache, code_cache, lock_mi_inference, unlock_mi_inference, method_table,
     inlining_policy
 using Base: @invoke
@@ -62,7 +62,7 @@ CC.OptimizationParams(interp::CthulhuInterpreter) =
 else
 CC.OptimizationParams(interp::CthulhuInterpreter) = OptimizationParams(interp.native)
 end
-CC.get_world_counter(interp::CthulhuInterpreter) = get_world_counter(interp.native)
+#=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
@@ -73,7 +73,7 @@ struct CthulhuCache
     cache::OptimizationDict
 end
 
-CC.code_cache(interp::CthulhuInterpreter) = WorldView(CthulhuCache(interp.opt), WorldRange(get_world_counter(interp)))
+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)
diff --git a/src/reflection.jl b/src/reflection.jl
index eee0400..b498b54 100644
--- a/src/reflection.jl
+++ b/src/reflection.jl
@@ -87,7 +87,7 @@ function find_callsites(interp::AbstractInterpreter, CI::Union{Core.CodeInfo, IR
                         func = args[6]
                         ftype = widenconst(argextype(func, CI, sptypes, slottypes))
                         sig = Tuple{ftype}
-                        callsite = Callsite(id, TaskCallInfo(callinfo(sig, nothing; world=get_world_counter(interp))), head)
+                        callsite = Callsite(id, TaskCallInfo(callinfo(sig, nothing; world=get_inference_world(interp))), head)
                     end
                 end
             end
@@ -99,7 +99,7 @@ function find_callsites(interp::AbstractInterpreter, CI::Union{Core.CodeInfo, IR
                 mi = get_mi(info)
                 meth = mi.def
                 if isa(meth, Method) && nameof(meth.module) === :CUDAnative && meth.name === :cufunction
-                    callsite = transform(Val(:CuFunction), callsite, c, CI, mi, slottypes; world=get_world_counter(interp))
+                    callsite = transform(Val(:CuFunction), callsite, c, CI, mi, slottypes; world=get_inference_world(interp))
                 end
             end
 


Test patch:
diff --git a/test/test_AbstractInterpreter.jl b/test/test_AbstractInterpreter.jl
index 0402494..fcee792 100644
--- a/test/test_AbstractInterpreter.jl
+++ b/test/test_AbstractInterpreter.jl
@@ -6,35 +6,52 @@ if isdefined(parentmodule(@__MODULE__), :VSCodeServer)
 end
 
 const CC = Core.Compiler
-import Core: MethodInstance, CodeInstance
-import .CC: WorldRange, WorldView, NativeInterpreter
-
-# define new `AbstractInterpreter` that satisfies the minimum interface requirements
-# while managing its cache independently
-macro newinterp(name)
-    cachename = gensym(string(name, "Cache"))
-    name = esc(name)
+
+"""
+    @newinterp NewInterpreter
+
+Defines new `NewInterpreter <: AbstractInterpreter` whose cache is separated
+from the native code cache, satisfying the minimum interface requirements.
+"""
+macro newinterp(InterpName)
+    InterpCacheName = esc(Symbol(string(InterpName, "Cache")))
+    InterpName = esc(InterpName)
+    C = Core
+    CC = Core.Compiler
     quote
-        struct $cachename
-            dict::IdDict{MethodInstance,CodeInstance}
+        struct $InterpCacheName
+            dict::IdDict{$C.MethodInstance,$C.CodeInstance}
+        end
+        $InterpCacheName() = $InterpCacheName(IdDict{$C.MethodInstance,$C.CodeInstance}())
+        struct $InterpName <: $CC.AbstractInterpreter
+            meta # additional information
+            world::UInt
+            inf_params::$CC.InferenceParams
+            opt_params::$CC.OptimizationParams
+            inf_cache::Vector{$CC.InferenceResult}
+            code_cache::$InterpCacheName
+            function $InterpName(meta = nothing;
+                                 world::UInt = Base.get_world_counter(),
+                                 inf_params::$CC.InferenceParams = $CC.InferenceParams(),
+                                 opt_params::$CC.OptimizationParams = $CC.OptimizationParams(),
+                                 inf_cache::Vector{$CC.InferenceResult} = $CC.InferenceResult[],
+                                 code_cache::$InterpCacheName = $InterpCacheName())
+                return new(meta, world, inf_params, opt_params, inf_cache, code_cache)
+            end
         end
-        struct $name <: CC.AbstractInterpreter
-            interp::CC.NativeInterpreter
-            cache::$cachename
-            $name(world = Base.get_world_counter();
-                interp = CC.NativeInterpreter(world),
-                cache = $cachename(IdDict{MethodInstance,CodeInstance}())
-                ) = new(interp, cache)
+        $CC.InferenceParams(interp::$InterpName) = interp.inf_params
+        $CC.OptimizationParams(interp::$InterpName) = interp.opt_params
+        @static if VERSION ≥ v"1.11.0-DEV.1498"
+        CC.get_inference_world(interp::$InterpName) = interp.world
+        else
+        CC.get_world_counter(interp::$InterpName) = interp.world
         end
-        CC.InferenceParams(interp::$name) = CC.InferenceParams(interp.interp)
-        CC.OptimizationParams(interp::$name) = CC.OptimizationParams(interp.interp)
-        CC.get_world_counter(interp::$name) = CC.get_world_counter(interp.interp)
-        CC.get_inference_cache(interp::$name) = CC.get_inference_cache(interp.interp)
-        CC.code_cache(interp::$name) = WorldView(interp.cache, WorldRange(CC.get_world_counter(interp)))
-        CC.get(wvc::WorldView{<:$cachename}, mi::MethodInstance, default) = get(wvc.cache.dict, mi, default)
-        CC.getindex(wvc::WorldView{<:$cachename}, mi::MethodInstance) = getindex(wvc.cache.dict, mi)
-        CC.haskey(wvc::WorldView{<:$cachename}, mi::MethodInstance) = haskey(wvc.cache.dict, mi)
-        CC.setindex!(wvc::WorldView{<:$cachename}, ci::CodeInstance, mi::MethodInstance) = setindex!(wvc.cache.dict, ci, mi)
+        $CC.get_inference_cache(interp::$InterpName) = interp.inf_cache
+        $CC.code_cache(interp::$InterpName) = $CC.WorldView(interp.code_cache, $CC.WorldRange(interp.world))
+        $CC.get(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance, default) = get(wvc.cache.dict, mi, default)
+        $CC.getindex(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance) = getindex(wvc.cache.dict, mi)
+        $CC.haskey(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance) = haskey(wvc.cache.dict, mi)
+        $CC.setindex!(wvc::$CC.WorldView{$InterpCacheName}, ci::$C.CodeInstance, mi::$C.MethodInstance) = setindex!(wvc.cache.dict, ci, mi)
     end
 end
 
@@ -43,8 +60,9 @@ end
 import Base.Experimental: @MethodTable, @overlay
 
 @newinterp MTOverlayInterp
-@MethodTable(OverlayedMT)
-CC.method_table(interp::MTOverlayInterp) = CC.OverlayMethodTable(CC.get_world_counter(interp), OverlayedMT)
+@MethodTable OverlayedMT
+CC.method_table(interp::MTOverlayInterp) =
+    CC.OverlayMethodTable(Cthulhu.get_inference_world(interp), OverlayedMT)
 @overlay OverlayedMT sin(x::Float64) = 1
 
 @testset "OverlayMethodTable integration" begin
diff --git a/test/test_codeview.jl b/test/test_codeview.jl
index 8e53101..1c95b63 100644
--- a/test/test_codeview.jl
+++ b/test/test_codeview.jl
@@ -22,7 +22,7 @@ Revise.track(TestCodeViewSandbox, normpath(@__DIR__, "TestCodeViewSandbox.jl"))
                 config = Cthulhu.CONFIG
 
                 io = IOBuffer()
-                codeview(io, mi, optimize, debuginfo, Cthulhu.get_world_counter(interp), config)
+                codeview(io, mi, optimize, debuginfo, Cthulhu.get_inference_world(interp), config)
                 @test !isempty(String(take!(io))) # just check it works
             end
         end