@@ -7,9 +7,10 @@ using InteractiveUtils
7
7
using UUIDs
8
8
using REPL: REPL, AbstractTerminal
9
9
10
- using Core: MethodInstance
10
+ import Core: MethodInstance, OpaqueClosure
11
11
const Compiler = Core. Compiler
12
- using Core. Compiler: MethodMatch, LimitedAccuracy, ignorelimited
12
+ import Core. Compiler: MethodMatch, LimitedAccuracy, widenconst, ignorelimited, Const,
13
+ PartialStruct, InterConditional, PartialOpaque
13
14
14
15
const mapany = Base. mapany
15
16
21
22
macro constprop (_, ex); esc (ex); end
22
23
end
23
24
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
+
24
34
Base. @kwdef mutable struct CthulhuConfig
25
35
enable_highlighter:: Bool = false
26
36
highlighter:: Cmd = ` pygmentize -l`
@@ -167,15 +177,35 @@ const descend = descend_code_typed
167
177
168
178
descend (interp:: CthulhuInterpreter , mi:: MethodInstance ; kwargs... ) = _descend (interp, mi; iswarn= false , interruptexc= false , kwargs... )
169
179
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
170
200
function codeinst_rt (code:: CodeInstance )
171
201
rettype = code. rettype
172
202
if isdefined (code, :rettype_const )
173
203
rettype_const = code. rettype_const
174
204
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
177
207
return rettype_const
178
- elseif isa (rettype_const, Core . InterConditional) && ! (Core . InterConditional <: rettype )
208
+ elseif isa (rettype_const, InterConditional) && ! (InterConditional <: rettype )
179
209
return rettype_const
180
210
else
181
211
return Const (rettype_const)
@@ -184,6 +214,7 @@ function codeinst_rt(code::CodeInstance)
184
214
return rettype
185
215
end
186
216
end
217
+ end # @static if IS_OVERHAULED
187
218
188
219
# `@constprop :aggressive` here in order to make sure the constant propagation of `allow_no_codeinf`
189
220
@constprop :aggressive function lookup (interp:: CthulhuInterpreter , mi:: MethodInstance , optimize:: Bool ; allow_no_codeinf:: Bool = false )
193
224
infos = interp. unopt[mi]. stmt_infos
194
225
slottypes = codeinf. slottypes
195
226
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
197
232
end
198
233
else
199
234
codeinst = interp. opt[mi]
209
244
# But with coverage on, the empty function body isn't empty due to :code_coverage_effect expressions.
210
245
codeinf = nothing
211
246
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
213
252
else
214
253
Core. eval (Main, quote
215
254
interp = $ interp
219
258
error (" couldn't find the source; inspect `Main.interp` and `Main.mi`" )
220
259
end
221
260
end
222
- ( codeinf, rt, infos, slottypes:: Vector{Any} )
261
+ return codeinf, rt, infos, slottypes:: Lattices
223
262
end
224
263
225
264
# #
0 commit comments