@@ -107,6 +107,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
107
107
val = pure_eval_call (interp, f, applicable, arginfo)
108
108
val != = nothing && return CallMeta (val, all_effects, MethodResultPure (info)) # TODO : add some sort of edge(s)
109
109
110
+ 𝕃ₚ = ipo_lattice (interp)
110
111
for i in 1 : napplicable
111
112
match = applicable[i]:: MethodMatch
112
113
method = match. method
@@ -179,8 +180,8 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
179
180
end
180
181
@assert ! (this_conditional isa Conditional) " invalid lattice element returned from inter-procedural context"
181
182
seen += 1
182
- rettype = tmerge (ipo_lattice (interp) , rettype, this_rt)
183
- if this_conditional != = Bottom && is_lattice_bool (ipo_lattice (interp) , rettype) && fargs != = nothing
183
+ rettype = tmerge (𝕃ₚ , rettype, this_rt)
184
+ if has_conditional (𝕃ₚ) && this_conditional != = Bottom && is_lattice_bool (𝕃ₚ , rettype) && fargs != = nothing
184
185
if conditionals === nothing
185
186
conditionals = Any[Bottom for _ in 1 : length (argtypes)],
186
187
Any[Bottom for _ in 1 : length (argtypes)]
@@ -211,7 +212,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
211
212
all_effects = Effects (all_effects; nothrow= false )
212
213
end
213
214
214
- rettype = from_interprocedural! (ipo_lattice (interp) , rettype, sv, arginfo, conditionals)
215
+ rettype = from_interprocedural! (𝕃ₚ , rettype, sv, arginfo, conditionals)
215
216
216
217
# Also considering inferring the compilation signature for this method, so
217
218
# it is available to the compiler in case it ends up needing it.
@@ -349,7 +350,7 @@ function find_matching_methods(argtypes::Vector{Any}, @nospecialize(atype), meth
349
350
end
350
351
351
352
"""
352
- from_interprocedural!(ipo_lattice ::AbstractLattice, rt, sv::InferenceState, arginfo::ArgInfo, maybecondinfo) -> newrt
353
+ from_interprocedural!(𝕃ₚ ::AbstractLattice, rt, sv::InferenceState, arginfo::ArgInfo, maybecondinfo) -> newrt
353
354
354
355
Converts inter-procedural return type `rt` into a local lattice element `newrt`,
355
356
that is appropriate in the context of current local analysis frame `sv`, especially:
@@ -368,13 +369,13 @@ In such cases `maybecondinfo` should be either of:
368
369
When we deal with multiple `MethodMatch`es, it's better to precompute `maybecondinfo` by
369
370
`tmerge`ing argument signature type of each method call.
370
371
"""
371
- function from_interprocedural! (ipo_lattice :: AbstractLattice , @nospecialize (rt), sv:: InferenceState , arginfo:: ArgInfo , @nospecialize (maybecondinfo))
372
+ function from_interprocedural! (𝕃ₚ :: AbstractLattice , @nospecialize (rt), sv:: InferenceState , arginfo:: ArgInfo , @nospecialize (maybecondinfo))
372
373
rt = collect_limitations! (rt, sv)
373
- if is_lattice_bool (ipo_lattice , rt)
374
+ if is_lattice_bool (𝕃ₚ , rt)
374
375
if maybecondinfo === nothing
375
376
rt = widenconditional (rt)
376
377
else
377
- rt = from_interconditional (ipo_lattice , rt, sv, arginfo, maybecondinfo)
378
+ rt = from_interconditional (𝕃ₚ , rt, sv, arginfo, maybecondinfo)
378
379
end
379
380
end
380
381
@assert ! (rt isa InterConditional) " invalid lattice element returned from inter-procedural context"
@@ -389,9 +390,10 @@ function collect_limitations!(@nospecialize(typ), sv::InferenceState)
389
390
return typ
390
391
end
391
392
392
- function from_interconditional (ipo_lattice :: AbstractLattice , @nospecialize (typ),
393
+ function from_interconditional (𝕃ₚ :: AbstractLattice , @nospecialize (typ),
393
394
sv:: InferenceState , (; fargs, argtypes):: ArgInfo , @nospecialize (maybecondinfo))
394
- lattice = widenlattice (ipo_lattice)
395
+ 𝕃 = widenlattice (𝕃ₚ)
396
+ has_conditional (𝕃ₚ) || return widenconditional (typ)
395
397
fargs === nothing && return widenconditional (typ)
396
398
slot = 0
397
399
thentype = elsetype = Any
@@ -417,21 +419,21 @@ function from_interconditional(ipo_lattice::AbstractLattice, @nospecialize(typ),
417
419
end
418
420
if condval === false
419
421
thentype = Bottom
420
- elseif ⊑ (lattice , new_thentype, thentype)
422
+ elseif ⊑ (𝕃 , new_thentype, thentype)
421
423
thentype = new_thentype
422
424
else
423
- thentype = tmeet (lattice , thentype, widenconst (new_thentype))
425
+ thentype = tmeet (𝕃 , thentype, widenconst (new_thentype))
424
426
end
425
427
if condval === true
426
428
elsetype = Bottom
427
- elseif ⊑ (lattice , new_elsetype, elsetype)
429
+ elseif ⊑ (𝕃 , new_elsetype, elsetype)
428
430
elsetype = new_elsetype
429
431
else
430
- elsetype = tmeet (lattice , elsetype, widenconst (new_elsetype))
432
+ elsetype = tmeet (𝕃 , elsetype, widenconst (new_elsetype))
431
433
end
432
- if (slot > 0 || condval != = false ) && ⋤ (lattice , thentype, old)
434
+ if (slot > 0 || condval != = false ) && ⋤ (𝕃 , thentype, old)
433
435
slot = id
434
- elseif (slot > 0 || condval != = true ) && ⋤ (lattice , elsetype, old)
436
+ elseif (slot > 0 || condval != = true ) && ⋤ (𝕃 , elsetype, old)
435
437
slot = id
436
438
else # reset: no new useful information for this slot
437
439
thentype = elsetype = Any
@@ -847,8 +849,8 @@ function concrete_eval_call(interp::AbstractInterpreter,
847
849
end
848
850
end
849
851
850
- has_conditional (argtypes:: Vector{Any} ) = any (@nospecialize (x)-> isa (x, Conditional), argtypes)
851
- has_conditional ((; argtypes) :: ArgInfo ) = has_conditional ( argtypes)
852
+ any_conditional (argtypes:: Vector{Any} ) = any (@nospecialize (x)-> isa (x, Conditional), argtypes)
853
+ any_conditional (arginfo :: ArgInfo ) = any_conditional (arginfo . argtypes)
852
854
853
855
function const_prop_enabled (interp:: AbstractInterpreter , sv:: InferenceState , match:: MethodMatch )
854
856
if ! InferenceParams (interp). ipo_constant_propagation
@@ -954,7 +956,7 @@ function abstract_call_method_with_const_args(interp::AbstractInterpreter,
954
956
mi = maybe_get_const_prop_profitable (interp, result, f, arginfo, si, match, sv)
955
957
mi === nothing && return nothing
956
958
# try semi-concrete evaluation
957
- if res:: Bool && ! has_conditional (arginfo)
959
+ if res:: Bool && ! any_conditional (arginfo)
958
960
mi_cache = WorldView (code_cache (interp), sv. world)
959
961
code = get (mi_cache, mi, nothing )
960
962
if code != = nothing
@@ -970,7 +972,8 @@ function abstract_call_method_with_const_args(interp::AbstractInterpreter,
970
972
end
971
973
# try constant prop'
972
974
inf_cache = get_inference_cache (interp)
973
- inf_result = cache_lookup (typeinf_lattice (interp), mi, arginfo. argtypes, inf_cache)
975
+ 𝕃ᵢ = typeinf_lattice (interp)
976
+ inf_result = cache_lookup (𝕃ᵢ, mi, arginfo. argtypes, inf_cache)
974
977
if inf_result === nothing
975
978
# if there might be a cycle, check to make sure we don't end up
976
979
# calling ourselves here.
@@ -983,7 +986,8 @@ function abstract_call_method_with_const_args(interp::AbstractInterpreter,
983
986
add_remark! (interp, sv, " [constprop] Edge cycle encountered" )
984
987
return nothing
985
988
end
986
- inf_result = InferenceResult (mi, ConditionalArgtypes (arginfo, sv))
989
+ argtypes = has_conditional (𝕃ᵢ) ? ConditionalArgtypes (arginfo, sv) : SimpleArgtypes (arginfo. argtypes)
990
+ inf_result = InferenceResult (mi, argtypes)
987
991
if ! any (inf_result. overridden_by_const)
988
992
add_remark! (interp, sv, " [constprop] Could not handle constant info in matching_cache_argtypes" )
989
993
return nothing
@@ -1572,9 +1576,9 @@ function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, (; fargs
1572
1576
sv:: Union{InferenceState, IRCode} , max_methods:: Int )
1573
1577
@nospecialize f
1574
1578
la = length (argtypes)
1575
- lattice = typeinf_lattice (interp)
1576
- ⊑ ᵢ = ⊑ (lattice )
1577
- if f === Core. ifelse && fargs isa Vector{Any} && la == 4
1579
+ 𝕃ᵢ = typeinf_lattice (interp)
1580
+ ⊑ ᵢ = ⊑ (𝕃ᵢ )
1581
+ if has_conditional (𝕃ᵢ) && f === Core. ifelse && fargs isa Vector{Any} && la == 4
1578
1582
cnd = argtypes[2 ]
1579
1583
if isa (cnd, Conditional)
1580
1584
newcnd = widenconditional (cnd)
@@ -1588,17 +1592,17 @@ function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, (; fargs
1588
1592
a = ssa_def_slot (fargs[3 ], sv)
1589
1593
b = ssa_def_slot (fargs[4 ], sv)
1590
1594
if isa (a, SlotNumber) && cnd. slot == slot_id (a)
1591
- tx = (cnd. thentype ⊑ ᵢ tx ? cnd. thentype : tmeet (lattice , tx, widenconst (cnd. thentype)))
1595
+ tx = (cnd. thentype ⊑ ᵢ tx ? cnd. thentype : tmeet (𝕃ᵢ , tx, widenconst (cnd. thentype)))
1592
1596
end
1593
1597
if isa (b, SlotNumber) && cnd. slot == slot_id (b)
1594
- ty = (cnd. elsetype ⊑ ᵢ ty ? cnd. elsetype : tmeet (lattice , ty, widenconst (cnd. elsetype)))
1598
+ ty = (cnd. elsetype ⊑ ᵢ ty ? cnd. elsetype : tmeet (𝕃ᵢ , ty, widenconst (cnd. elsetype)))
1595
1599
end
1596
- return tmerge (lattice , tx, ty)
1600
+ return tmerge (𝕃ᵢ , tx, ty)
1597
1601
end
1598
1602
end
1599
1603
end
1600
1604
rt = builtin_tfunction (interp, f, argtypes[2 : end ], sv)
1601
- if (rt === Bool || (isa (rt, Const) && isa (rt. val, Bool))) && isa (fargs, Vector{Any})
1605
+ if has_conditional (𝕃ᵢ) && (rt === Bool || (isa (rt, Const) && isa (rt. val, Bool))) && isa (fargs, Vector{Any})
1602
1606
# perform very limited back-propagation of type information for `is` and `isa`
1603
1607
if f === isa
1604
1608
a = ssa_def_slot (fargs[2 ], sv)
@@ -1816,6 +1820,7 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
1816
1820
(; fargs, argtypes) = arginfo
1817
1821
la = length (argtypes)
1818
1822
1823
+ 𝕃ᵢ = typeinf_lattice (interp)
1819
1824
if isa (f, Builtin)
1820
1825
if f === _apply_iterate
1821
1826
return abstract_apply (interp, argtypes, si, sv, max_methods)
@@ -1827,7 +1832,7 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
1827
1832
return abstract_finalizer (interp, argtypes, sv)
1828
1833
end
1829
1834
rt = abstract_call_builtin (interp, f, arginfo, sv, max_methods)
1830
- effects = builtin_effects (typeinf_lattice (interp) , f, argtypes[2 : end ], rt)
1835
+ effects = builtin_effects (𝕃ᵢ , f, argtypes[2 : end ], rt)
1831
1836
return CallMeta (rt, effects, NoCallInfo ())
1832
1837
elseif isa (f, Core. OpaqueClosure)
1833
1838
# calling an OpaqueClosure about which we have no information returns no information
0 commit comments