11# # interpreter
22
33using Core. Compiler:
4- AbstractInterpreter, InferenceResult, InferenceParams, InferenceState, MethodInstance, OptimizationParams, WorldView, get_world_counter
4+ AbstractInterpreter, InferenceResult, InferenceParams, InferenceState, MethodInstance, OptimizationParams, WorldView
55using GPUCompiler:
6- @safe_debug , AbstractCompilerParams, CodeCache, CompilerJob, methodinstance
6+ @safe_debug , AbstractCompilerParams, CompilerJob, methodinstance, CodeInstance, inference_params, optimization_params, get_inference_world
77using CodeInfoTools
88using CodeInfoTools: resolve
99
10+
1011struct StaticInterpreter <: AbstractInterpreter
11- global_cache:: CodeCache
12+ # The world age we're working inside of
13+ world:: UInt
1214 method_table:: Union{Nothing,Core.MethodTable}
1315
16+ token:: Any
17+
1418 # Cache of inference results for this particular interpreter
1519 local_cache:: Vector{InferenceResult}
16- # The world age we're working inside of
17- world:: UInt
1820
1921 # Parameters for inference and optimization
2022 inf_params:: InferenceParams
2123 opt_params:: OptimizationParams
22-
23- function StaticInterpreter (cache:: CodeCache , mt:: Union{Nothing,Core.MethodTable} , world:: UInt , ip:: InferenceParams , op:: OptimizationParams )
24+ function StaticInterpreter (world:: UInt , mt:: Union{Nothing,Core.MethodTable} , token_or_cache, ip:: InferenceParams , op:: OptimizationParams )
2425 @assert world <= Base. get_world_counter ()
25-
26- return new (
27- cache,
28- mt,
29-
30- # Initially empty cache
31- Vector {InferenceResult} (),
32-
33- # world age counter
34- world,
35-
36- # parameters for inference and optimization
37- ip,
38- op
39- )
26+ local_cache = Vector {Core.Compiler.InferenceResult} () # Initially empty cache
27+ return new (world, mt, token_or_cache, local_cache, ip, op)
4028 end
4129end
4230
43-
4431Core. Compiler. InferenceParams (interp:: StaticInterpreter ) = interp. inf_params
4532Core. Compiler. OptimizationParams (interp:: StaticInterpreter ) = interp. opt_params
46- Core . Compiler . get_world_counter (interp:: StaticInterpreter ) = interp. world
33+ GPUCompiler . get_inference_world (interp:: StaticInterpreter ) = interp. world
4734Core. Compiler. get_inference_cache (interp:: StaticInterpreter ) = interp. local_cache
48- Core. Compiler. code_cache (interp:: StaticInterpreter ) = WorldView ( interp. global_cache, interp . world)
35+ Core. Compiler. cache_owner (interp:: StaticInterpreter ) = interp. token
4936
5037# No need to do any locking since we're not putting our results into the runtime cache
5138Core. Compiler. lock_mi_inference (interp:: StaticInterpreter , mi:: MethodInstance ) = nothing
5239Core. Compiler. unlock_mi_inference (interp:: StaticInterpreter , mi:: MethodInstance ) = nothing
5340
5441function Core. Compiler. add_remark! (interp:: StaticInterpreter , sv:: InferenceState , msg)
55- @safe_debug " Inference remark during static compilation of $(sv. linfo) : $msg "
42+ @safe_debug " Inference remark during static compilation of $(sv. linfo) : $msg "
5643end
5744
58-
5945# ####
6046# #### Pre-inference
6147# ####
@@ -77,58 +63,46 @@ function custom_pass!(interp::StaticInterpreter, result::InferenceResult, mi::Co
7763end
7864
7965function Core. Compiler. InferenceState (result:: InferenceResult , cache:: Symbol , interp:: StaticInterpreter )
80- world = get_world_counter (interp)
81- src = @static if VERSION >= v " 1.10.0-DEV.873"
82- Core. Compiler. retrieve_code_info (result. linfo, world)
83- else
84- Core. Compiler. retrieve_code_info (result. linfo)
85- end
66+ world = get_inference_world (interp)
67+ src = Core. Compiler. retrieve_code_info (result. linfo, world)
8668 mi = result. linfo
8769 src = custom_pass! (interp, result, mi, src)
88- src === nothing && return nothing
89- Core. Compiler. validate_code_in_debug_mode (result. linfo, src, " lowered" )
70+ src === nothing && return Core. Compiler. maybe_validate_code (result. linfo, src, " lowered" )
9071 return InferenceState (result, src, cache, interp)
9172end
9273
9374Core. Compiler. may_optimize (interp:: StaticInterpreter ) = true
9475Core. Compiler. may_compress (interp:: StaticInterpreter ) = true
9576Core. Compiler. may_discard_trees (interp:: StaticInterpreter ) = true
96- Core. Compiler. verbose_stmt_info (interp:: StaticInterpreter ) = false
97-
77+ if isdefined (Core. Compiler, :verbose_stmt_inf )
78+ Core. Compiler. verbose_stmt_info (interp:: StaticInterpreter ) = false
79+ end
9880
9981if isdefined (Base. Experimental, Symbol (" @overlay" ))
10082 using Core. Compiler: OverlayMethodTable
101- if v " 1.8-beta2" <= VERSION < v " 1.9-" || VERSION >= v " 1.9.0-DEV.120"
102- Core. Compiler. method_table (interp:: StaticInterpreter ) =
103- OverlayMethodTable (interp. world, interp. method_table)
104- else
105- Core. Compiler. method_table (interp:: StaticInterpreter , sv:: InferenceState ) =
83+ Core. Compiler. method_table (interp:: StaticInterpreter ) =
10684 OverlayMethodTable (interp. world, interp. method_table)
107- end
10885else
10986 Core. Compiler. method_table (interp:: StaticInterpreter , sv:: InferenceState ) =
11087 WorldOverlayMethodTable (interp. world)
11188end
11289
11390# semi-concrete interepretation is broken with overlays (JuliaLang/julia#47349)
114- @static if VERSION >= v " 1.9.0-DEV.1248"
11591function Core. Compiler. concrete_eval_eligible (interp:: StaticInterpreter ,
11692 @nospecialize (f), result:: Core.Compiler.MethodCallResult , arginfo:: Core.Compiler.ArgInfo )
11793 ret = @invoke Core. Compiler. concrete_eval_eligible (interp:: AbstractInterpreter ,
11894 f:: Any , result:: Core.Compiler.MethodCallResult , arginfo:: Core.Compiler.ArgInfo )
11995 ret === false && return nothing
12096 return ret
12197end
122- end
12398
12499struct StaticCompilerParams <: AbstractCompilerParams
125100 opt:: Bool
126101 optlevel:: Int
127- cache:: CodeCache
128102end
129103
130- function StaticCompilerParams (; opt = false ,
131- optlevel = Base. JLOptions (). opt_level,
132- cache = CodeCache () )
133- return StaticCompilerParams (opt, optlevel, cache )
104+ function StaticCompilerParams (; opt= false ,
105+ optlevel= Base. JLOptions (). opt_level
106+ )
107+ return StaticCompilerParams (opt, optlevel)
134108end
0 commit comments