@@ -7,10 +7,13 @@ 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
- import Core. Compiler: MethodMatch, LimitedAccuracy, ignorelimited, specialize_method
12
+ import Core. Compiler: MethodMatch, specialize_method,
13
+ widenconst, ignorelimited,
14
+ LimitedAccuracy, Const, PartialStruct, InterConditional, PartialOpaque
13
15
import Base: unwrapva, isvarargtype
16
+
14
17
const mapany = Base. mapany
15
18
16
19
# branch on https://github.com/JuliaLang/julia/pull/42125
21
24
macro constprop (_, ex); esc (ex); end
22
25
end
23
26
27
+ const IS_OVERHAULED = isdefined (Core. Compiler, :LatticeElement )
28
+ @static if IS_OVERHAULED
29
+ import Core. Compiler: ⊤, ⊥, LatticeElement, NativeType, LatticeElement, isConst,
30
+ isLimitedAccuracy, Argtypes, SSAValueTypes
31
+ else
32
+ const Argtypes = Vector{Any}
33
+ const SSAValueTypes = Vector{Any}
34
+ end
35
+
24
36
Base. @kwdef mutable struct CthulhuConfig
25
37
enable_highlighter:: Bool = false
26
38
highlighter:: Cmd = ` pygmentize -l`
@@ -167,15 +179,36 @@ const descend = descend_code_typed
167
179
168
180
descend (interp:: CthulhuInterpreter , mi:: MethodInstance ; kwargs... ) = _descend (interp, mi; iswarn= false , interruptexc= false , kwargs... )
169
181
182
+ @static if IS_OVERHAULED
183
+ import Core. Compiler: ConditionalInfo
170
184
function codeinst_rt (code:: CodeInstance )
171
185
rettype = code. rettype
172
186
if isdefined (code, :rettype_const )
173
187
rettype_const = code. rettype_const
174
188
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
189
+ return PartialStruct (rettype, rettype_const)
190
+ elseif isa (rettype_const, PartialOpaque) && rettype <: OpaqueClosure
177
191
return rettype_const
178
- elseif isa (rettype_const, Core. InterConditional) && ! (Core. InterConditional <: rettype )
192
+ elseif isa (rettype_const, ConditionalInfo) && ! (ConditionalInfo <: rettype )
193
+ @assert rettype_const. inter
194
+ return InterConditional (rettype_const. slot_id, rettype_const. vtype, rettype_const. elsetype), mi
195
+ else
196
+ return Const (rettype_const)
197
+ end
198
+ else
199
+ return rettype
200
+ end
201
+ end
202
+ else # @static if IS_OVERHAULED
203
+ function codeinst_rt (code:: CodeInstance )
204
+ rettype = code. rettype
205
+ if isdefined (code, :rettype_const )
206
+ rettype_const = code. rettype_const
207
+ if isa (rettype_const, Vector{Any}) && ! (Vector{Any} <: rettype )
208
+ return PartialStruct (rettype, rettype_const)
209
+ elseif isa (rettype_const, PartialOpaque) && rettype <: OpaqueClosure
210
+ return rettype_const
211
+ elseif isa (rettype_const, InterConditional) && ! (InterConditional <: rettype )
179
212
return rettype_const
180
213
else
181
214
return Const (rettype_const)
@@ -184,6 +217,7 @@ function codeinst_rt(code::CodeInstance)
184
217
return rettype
185
218
end
186
219
end
220
+ end # @static if IS_OVERHAULED
187
221
188
222
# `@constprop :aggressive` here in order to make sure the constant propagation of `allow_no_codeinf`
189
223
@constprop :aggressive function lookup (interp:: CthulhuInterpreter , mi:: MethodInstance , optimize:: Bool ; allow_no_codeinf:: Bool = false )
193
227
infos = interp. unopt[mi]. stmt_infos
194
228
slottypes = codeinf. slottypes
195
229
if isnothing (slottypes)
196
- slottypes = Any[ Any for i = 1 : length (codeinf. slotflags) ]
230
+ @static if IS_OVERHAULED
231
+ slottypes = LatticeElement[ ⊤ for i = 1 : length (codeinf. slotflags) ]
232
+ else
233
+ slottypes = Any[ Any for i = 1 : length (codeinf. slotflags) ]
234
+ end
197
235
end
198
236
else
199
237
codeinst = interp. opt[mi]
209
247
# But with coverage on, the empty function body isn't empty due to :code_coverage_effect expressions.
210
248
codeinf = nothing
211
249
infos = []
212
- slottypes = Any[Base. unwrap_unionall (mi. specTypes). parameters... ]
250
+ @static if IS_OVERHAULED
251
+ slottypes = AbstractLatticce[NativeType (t) for t in Base. unwrap_unionall (mi. specTypes). parameters]
252
+ else
253
+ slottypes = Any[Base. unwrap_unionall (mi. specTypes). parameters... ]
254
+ end
213
255
else
214
256
Core. eval (Main, quote
215
257
interp = $ interp
219
261
error (" couldn't find the source; inspect `Main.interp` and `Main.mi`" )
220
262
end
221
263
end
222
- ( codeinf, rt, infos, slottypes:: Vector{Any} )
264
+ return codeinf, rt, infos, slottypes:: Argtypes
223
265
end
224
266
225
267
# #
0 commit comments