@@ -7,15 +7,16 @@ Internally, each `MethodInstance` keep a unique global cache of code instances
77that have been created for the given method instance, stratified by world age
88ranges. This struct abstracts over access to this cache.
99"""
10- struct InternalCodeCache end
10+ struct InternalCodeCache
11+ owner:: Any # `jl_egal` is used for comparison
12+ end
1113
1214function setindex! (cache:: InternalCodeCache , ci:: CodeInstance , mi:: MethodInstance )
15+ @assert ci. owner === cache. owner
1316 ccall (:jl_mi_cache_insert , Cvoid, (Any, Any), mi, ci)
1417 return cache
1518end
1619
17- const GLOBAL_CI_CACHE = InternalCodeCache ()
18-
1920struct WorldRange
2021 min_world:: UInt
2122 max_world:: UInt
@@ -49,11 +50,11 @@ WorldView(wvc::WorldView, wr::WorldRange) = WorldView(wvc.cache, wr)
4950WorldView (wvc:: WorldView , args... ) = WorldView (wvc. cache, args... )
5051
5152function haskey (wvc:: WorldView{InternalCodeCache} , mi:: MethodInstance )
52- return ccall (:jl_rettype_inferred , Any, (Any, UInt, UInt), mi, first (wvc. worlds), last (wvc. worlds)) != = nothing
53+ return ccall (:jl_rettype_inferred , Any, (Any, Any, UInt, UInt), wvc . cache . owner , mi, first (wvc. worlds), last (wvc. worlds)) != = nothing
5354end
5455
5556function get (wvc:: WorldView{InternalCodeCache} , mi:: MethodInstance , default)
56- r = ccall (:jl_rettype_inferred , Any, (Any, UInt, UInt), mi, first (wvc. worlds), last (wvc. worlds))
57+ r = ccall (:jl_rettype_inferred , Any, (Any, Any, UInt, UInt), wvc . cache . owner , mi, first (wvc. worlds), last (wvc. worlds))
5758 if r === nothing
5859 return default
5960 end
@@ -70,3 +71,9 @@ function setindex!(wvc::WorldView{InternalCodeCache}, ci::CodeInstance, mi::Meth
7071 setindex! (wvc. cache, ci, mi)
7172 return wvc
7273end
74+
75+ function code_cache (interp:: AbstractInterpreter )
76+ cache = InternalCodeCache (cache_owner (interp))
77+ worlds = WorldRange (get_inference_world (interp))
78+ return WorldView (cache, worlds)
79+ end
0 commit comments