@@ -165,7 +165,7 @@ function typesubtract(@nospecialize(a), @nospecialize(b), max_union_splitting::I
165165 if ub isa DataType
166166 if a. name === ub. name === Tuple. name &&
167167 length (a. parameters) == length (ub. parameters)
168- if 1 < unionsplitcost (a. parameters) <= max_union_splitting
168+ if 1 < unionsplitcost (JLTypeLattice (), a. parameters) <= max_union_splitting
169169 ta = switchtupleunion (a)
170170 return typesubtract (Union{ta... }, b, 0 )
171171 elseif b isa DataType
@@ -227,12 +227,11 @@ end
227227# or outside of the Tuple/Union nesting, though somewhat more expensive to be
228228# outside than inside because the representation is larger (because and it
229229# informs the callee whether any splitting is possible).
230- function unionsplitcost (argtypes:: Union{SimpleVector,Vector{Any}} )
230+ function unionsplitcost (𝕃 :: AbstractLattice , argtypes:: Union{SimpleVector,Vector{Any}} )
231231 nu = 1
232232 max = 2
233233 for ti in argtypes
234- # TODO remove this to implement callsite refinement of MustAlias
235- if isa (ti, MustAlias) && isa (widenconst (ti), Union)
234+ if has_extended_unionsplit (𝕃) && ! isvarargtype (ti)
236235 ti = widenconst (ti)
237236 end
238237 if isa (ti, Union)
@@ -252,12 +251,12 @@ end
252251# and `Union{return...} == ty`
253252function switchtupleunion (@nospecialize (ty))
254253 tparams = (unwrap_unionall (ty):: DataType ). parameters
255- return _switchtupleunion (Any[tparams... ], length (tparams), [], ty)
254+ return _switchtupleunion (JLTypeLattice (), Any[tparams... ], length (tparams), [], ty)
256255end
257256
258- switchtupleunion (argtypes:: Vector{Any} ) = _switchtupleunion (argtypes, length (argtypes), [], nothing )
257+ switchtupleunion (𝕃 :: AbstractLattice , argtypes:: Vector{Any} ) = _switchtupleunion (𝕃, argtypes, length (argtypes), [], nothing )
259258
260- function _switchtupleunion (t:: Vector{Any} , i:: Int , tunion:: Vector{Any} , @nospecialize (origt))
259+ function _switchtupleunion (𝕃 :: AbstractLattice , t:: Vector{Any} , i:: Int , tunion:: Vector{Any} , @nospecialize (origt))
261260 if i == 0
262261 if origt === nothing
263262 push! (tunion, copy (t))
@@ -268,17 +267,20 @@ function _switchtupleunion(t::Vector{Any}, i::Int, tunion::Vector{Any}, @nospeci
268267 else
269268 origti = ti = t[i]
270269 # TODO remove this to implement callsite refinement of MustAlias
271- if isa (ti, MustAlias) && isa (widenconst (ti), Union)
272- ti = widenconst (ti)
273- end
274270 if isa (ti, Union)
275- for ty in uniontypes (ti:: Union )
271+ for ty in uniontypes (ti)
272+ t[i] = ty
273+ _switchtupleunion (𝕃, t, i - 1 , tunion, origt)
274+ end
275+ t[i] = origti
276+ elseif has_extended_unionsplit (𝕃) && ! isa (ti, Const) && ! isvarargtype (ti) && isa (widenconst (ti), Union)
277+ for ty in uniontypes (ti)
276278 t[i] = ty
277- _switchtupleunion (t, i - 1 , tunion, origt)
279+ _switchtupleunion (𝕃, t, i - 1 , tunion, origt)
278280 end
279281 t[i] = origti
280282 else
281- _switchtupleunion (t, i - 1 , tunion, origt)
283+ _switchtupleunion (𝕃, t, i - 1 , tunion, origt)
282284 end
283285 end
284286 return tunion
0 commit comments