@@ -5,34 +5,65 @@ if isdefined(parentmodule(@__MODULE__), :VSCodeServer)
55 using .. VSCodeServer
66end
77
8- const CC = Core. Compiler
8+ @doc """
9+ @newinterp NewInterpreter [ephemeral_cache::Bool=false]
10+
11+ Defines new `NewInterpreter <: AbstractInterpreter` whose cache is separated
12+ from the native code cache, satisfying the minimum interface requirements.
913
14+ When the `ephemeral_cache=true` option is specified, `NewInterpreter` will hold
15+ `CodeInstance` in an ephemeral non-integrated cache, rather than in the integrated
16+ `Core.Compiler.InternalCodeCache`.
17+ Keep in mind that ephemeral cache lacks support for invalidation and doesn't persist across
18+ sessions. However it is an usual Julia object of the type `code_cache::IdDict{MethodInstance,CodeInstance}`,
19+ making it easier for debugging and inspecting the compiler behavior.
20+ """
1021@static if VERSION ≥ v" 1.11.0-DEV.1552"
11- macro newinterp(InterpName)
12- InterpCacheName = QuoteNode(Symbol(string(InterpName, " Cache" )))
22+ macro newinterp(InterpName, ephemeral_cache:: Bool = false )
23+ cache_token = QuoteNode(gensym(string(InterpName, " CacheToken" )))
24+ InterpCacheName = esc(Symbol(string(InterpName, " Cache" )))
1325 InterpName = esc(InterpName)
1426 C = Core
15- CC = Core . Compiler
27+ CC = Cthulhu . CC
1628 quote
29+ $ (ephemeral_cache && quote
30+ struct $ InterpCacheName
31+ dict:: IdDict{$C.MethodInstance,$C.CodeInstance}
32+ end
33+ $ InterpCacheName() = $ InterpCacheName(IdDict{$ C. MethodInstance,$ C. CodeInstance}())
34+ end )
1735 struct $ InterpName <: $CC.AbstractInterpreter
1836 meta # additional information
1937 world:: UInt
2038 inf_params:: $CC.InferenceParams
2139 opt_params:: $CC.OptimizationParams
2240 inf_cache:: Vector{$CC.InferenceResult}
41+ $ (ephemeral_cache && :(code_cache:: $InterpCacheName ))
2342 function $ InterpName(meta = nothing ;
24- world:: UInt = Base. get_world_counter(),
25- inf_params:: $CC.InferenceParams = $ CC. InferenceParams(),
26- opt_params:: $CC.OptimizationParams = $ CC. OptimizationParams(),
27- inf_cache:: Vector{$CC.InferenceResult} = $ CC. InferenceResult[])
28- return new(meta, world, inf_params, opt_params, inf_cache)
43+ world:: UInt = Base. get_world_counter(),
44+ inf_params:: $CC.InferenceParams = $ CC. InferenceParams(),
45+ opt_params:: $CC.OptimizationParams = $ CC. OptimizationParams(),
46+ inf_cache:: Vector{$CC.InferenceResult} = $ CC. InferenceResult[],
47+ $ (ephemeral_cache ?
48+ Expr(:kw, :(code_cache:: $InterpCacheName ), :($ InterpCacheName())) :
49+ Expr(:kw, :_, :nothing )))
50+ return $ (ephemeral_cache ?
51+ :(new(meta, world, inf_params, opt_params, inf_cache, code_cache)) :
52+ :(new(meta, world, inf_params, opt_params, inf_cache)))
2953 end
3054 end
3155 $ CC. InferenceParams(interp:: $InterpName ) = interp. inf_params
3256 $ CC. OptimizationParams(interp:: $InterpName ) = interp. opt_params
3357 $ CC. get_inference_world(interp:: $InterpName ) = interp. world
3458 $ CC. get_inference_cache(interp:: $InterpName ) = interp. inf_cache
35- $ CC. cache_owner(:: $InterpName ) = $ InterpCacheName
59+ $ CC. cache_owner(:: $InterpName ) = $ cache_token
60+ $ (ephemeral_cache && quote
61+ $ CC. code_cache(interp:: $InterpName ) = $ CC. WorldView(interp. code_cache, $ CC. WorldRange(interp. world))
62+ $ CC. get(wvc:: $CC.WorldView{$InterpCacheName} , mi:: $C.MethodInstance , default) = get(wvc. cache. dict, mi, default)
63+ $ CC. getindex(wvc:: $CC.WorldView{$InterpCacheName} , mi:: $C.MethodInstance ) = getindex(wvc. cache. dict, mi)
64+ $ CC. haskey(wvc:: $CC.WorldView{$InterpCacheName} , mi:: $C.MethodInstance ) = haskey(wvc. cache. dict, mi)
65+ $ CC. setindex!(wvc:: $CC.WorldView{$InterpCacheName} , ci:: $C.CodeInstance , mi:: $C.MethodInstance ) = setindex!(wvc. cache. dict, ci, mi)
66+ end )
3667 end
3768end
3869else
@@ -79,16 +110,11 @@ macro newinterp(InterpName)
79110end
80111end # if VERSION ≥ v"1.11.0-DEV.1552"
81112
82- @doc """
83- @newinterp NewInterpreter
84-
85- Defines new `NewInterpreter <: AbstractInterpreter` whose cache is separated
86- from the native code cache, satisfying the minimum interface requirements.
87- """ var"@newinterp"
113+ const CC = Cthulhu. CC
88114
89115# `OverlayMethodTable`
90116# --------------------
91- import Base. Experimental: @MethodTable, @overlay
117+ using Base. Experimental: @MethodTable, @overlay
92118
93119@newinterp MTOverlayInterp
94120@MethodTable OverlayedMT
0 commit comments