@@ -7,9 +7,10 @@ using InteractiveUtils
77using UUIDs
88using REPL: REPL, AbstractTerminal
99
10- using Core: MethodInstance
10+ import Core: MethodInstance, OpaqueClosure
1111const Compiler = Core. Compiler
12- using Core. Compiler: MethodMatch, LimitedAccuracy, ignorelimited
12+ import Core. Compiler: MethodMatch, LimitedAccuracy, widenconst, ignorelimited, Const,
13+ PartialStruct, InterConditional, PartialOpaque
1314
1415const mapany = Base. mapany
1516
2122 macro constprop (_, ex); esc (ex); end
2223end
2324
25+ const IS_OVERHAULED = isdefined (Core. Compiler, :TypeLattice )
26+ @static if IS_OVERHAULED
27+ import Core. Compiler: ⊤, ⊥, TypeLattice, NativeType, TypeLattice, isConst,
28+ isLimitedAccuracy, Lattices, SSAValueTypes
29+ else
30+ const Lattices = Vector{Any}
31+ const SSAValueTypes = Vector{Any}
32+ end
33+
2434Base. @kwdef mutable struct CthulhuConfig
2535 enable_highlighter:: Bool = false
2636 highlighter:: Cmd = ` pygmentize -l`
@@ -167,15 +177,35 @@ const descend = descend_code_typed
167177
168178descend (interp:: CthulhuInterpreter , mi:: MethodInstance ; kwargs... ) = _descend (interp, mi; iswarn= false , interruptexc= false , kwargs... )
169179
180+ @static if IS_OVERHAULED
181+ import Core. Compiler: InterConditionalInfo
182+ function codeinst_rt (code:: CodeInstance )
183+ rettype = code. rettype
184+ if isdefined (code, :rettype_const )
185+ rettype_const = code. rettype_const
186+ if isa (rettype_const, Vector{Any}) && ! (Vector{Any} <: rettype )
187+ return PartialStruct (rettype, rettype_const)
188+ elseif isa (rettype_const, PartialOpaque) && rettype <: OpaqueClosure
189+ return rettype_const
190+ elseif isa (rettype_const, InterConditionalInfo) && ! (InterConditionalInfo <: rettype )
191+ return InterConditional (rettype_const. slot, rettype_const. vtype, rettype_const. elsetype)
192+ else
193+ return Const (rettype_const)
194+ end
195+ else
196+ return rettype
197+ end
198+ end
199+ else # @static if IS_OVERHAULED
170200function codeinst_rt (code:: CodeInstance )
171201 rettype = code. rettype
172202 if isdefined (code, :rettype_const )
173203 rettype_const = code. rettype_const
174204 if isa (rettype_const, Vector{Any}) && ! (Vector{Any} <: rettype )
175- return Core . PartialStruct (rettype, rettype_const)
176- elseif isa (rettype_const, Core . PartialOpaque) && rettype <: Core. OpaqueClosure
205+ return PartialStruct (rettype, rettype_const)
206+ elseif isa (rettype_const, PartialOpaque) && rettype <: OpaqueClosure
177207 return rettype_const
178- elseif isa (rettype_const, Core . InterConditional) && ! (Core . InterConditional <: rettype )
208+ elseif isa (rettype_const, InterConditional) && ! (InterConditional <: rettype )
179209 return rettype_const
180210 else
181211 return Const (rettype_const)
@@ -184,6 +214,7 @@ function codeinst_rt(code::CodeInstance)
184214 return rettype
185215 end
186216end
217+ end # @static if IS_OVERHAULED
187218
188219# `@constprop :aggressive` here in order to make sure the constant propagation of `allow_no_codeinf`
189220@constprop :aggressive function lookup (interp:: CthulhuInterpreter , mi:: MethodInstance , optimize:: Bool ; allow_no_codeinf:: Bool = false )
193224 infos = interp. unopt[mi]. stmt_infos
194225 slottypes = codeinf. slottypes
195226 if isnothing (slottypes)
196- slottypes = Any[ Any for i = 1 : length (codeinf. slotflags) ]
227+ @static if IS_OVERHAULED
228+ slottypes = TypeLattice[ ⊤ for i = 1 : length (codeinf. slotflags) ]
229+ else
230+ slottypes = Any[ Any for i = 1 : length (codeinf. slotflags) ]
231+ end
197232 end
198233 else
199234 codeinst = interp. opt[mi]
209244 # But with coverage on, the empty function body isn't empty due to :code_coverage_effect expressions.
210245 codeinf = nothing
211246 infos = []
212- slottypes = Any[Base. unwrap_unionall (mi. specTypes). parameters... ]
247+ @static if IS_OVERHAULED
248+ slottypes = AbstractLatticce[NativeType (t) for t in Base. unwrap_unionall (mi. specTypes). parameters]
249+ else
250+ slottypes = Any[Base. unwrap_unionall (mi. specTypes). parameters... ]
251+ end
213252 else
214253 Core. eval (Main, quote
215254 interp = $ interp
219258 error (" couldn't find the source; inspect `Main.interp` and `Main.mi`" )
220259 end
221260 end
222- ( codeinf, rt, infos, slottypes:: Vector{Any} )
261+ return codeinf, rt, infos, slottypes:: Lattices
223262end
224263
225264# #
0 commit comments