@@ -243,6 +243,7 @@ function find_matching_methods(𝕃::AbstractLattice,
243243 for i in 1 : length (split_argtypes)
244244 arg_n = split_argtypes[i]:: Vector{Any}
245245 sig_n = argtypes_to_type (arg_n)
246+ sig_n === Bottom && continue
246247 mt = ccall (:jl_method_table_for , Any, (Any,), sig_n)
247248 mt === nothing && return FailedMethodMatch (" Could not identify method table for call" )
248249 mt = mt:: MethodTable
@@ -506,7 +507,10 @@ function abstract_call_method(interp::AbstractInterpreter,
506507 return MethodCallResult (Any, false , false , nothing , Effects ())
507508 end
508509 sigtuple = unwrap_unionall (sig)
509- sigtuple isa DataType || return MethodCallResult (Any, false , false , nothing , Effects ())
510+ sigtuple isa DataType ||
511+ return MethodCallResult (Any, false , false , nothing , Effects ())
512+ all (@nospecialize (x) -> isvarargtype (x) || valid_as_lattice (x, true ), sigtuple. parameters) ||
513+ return MethodCallResult (Union{}, false , false , nothing , EFFECTS_THROWS) # catch bad type intersections early
510514
511515 if is_nospecializeinfer (method)
512516 sig = get_nospecializeinfer_sig (method, sig, sparams)
@@ -1385,25 +1389,35 @@ function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft)
13851389 end
13861390 if isa (tti, Union)
13871391 utis = uniontypes (tti)
1388- if any (@nospecialize (t) -> ! isa (t, DataType) || ! (t <: Tuple ) || ! isknownlength (t), utis)
1389- return AbstractIterationResult (Any[Vararg{Any}], nothing , Effects ())
1390- end
1391- ltp = length ((utis[1 ]:: DataType ). parameters)
1392- for t in utis
1393- if length ((t:: DataType ). parameters) != ltp
1394- return AbstractIterationResult (Any[Vararg{Any}], nothing )
1392+ # refine the Union to remove elements that are not valid tags for objects
1393+ filter! (@nospecialize (x) -> valid_as_lattice (x, true ), utis)
1394+ if length (utis) == 0
1395+ return AbstractIterationResult (Any[], nothing ) # oops, this statement was actually unreachable
1396+ elseif length (utis) == 1
1397+ tti = utis[1 ]
1398+ tti0 = rewrap_unionall (tti, tti0)
1399+ else
1400+ if any (@nospecialize (t) -> ! isa (t, DataType) || ! (t <: Tuple ) || ! isknownlength (t), utis)
1401+ return AbstractIterationResult (Any[Vararg{Any}], nothing , Effects ())
13951402 end
1396- end
1397- result = Any[ Union{} for _ in 1 : ltp ]
1398- for t in utis
1399- tps = (t:: DataType ). parameters
1400- _all (valid_as_lattice, tps) || continue
1401- for j in 1 : ltp
1402- result[j] = tmerge (result[j], rewrap_unionall (tps[j], tti0))
1403+ ltp = length ((utis[1 ]:: DataType ). parameters)
1404+ for t in utis
1405+ if length ((t:: DataType ). parameters) != ltp
1406+ return AbstractIterationResult (Any[Vararg{Any}], nothing )
1407+ end
1408+ end
1409+ result = Any[ Union{} for _ in 1 : ltp ]
1410+ for t in utis
1411+ tps = (t:: DataType ). parameters
1412+ for j in 1 : ltp
1413+ @assert valid_as_lattice (tps[j], true )
1414+ result[j] = tmerge (result[j], rewrap_unionall (tps[j], tti0))
1415+ end
14031416 end
1417+ return AbstractIterationResult (result, nothing )
14041418 end
1405- return AbstractIterationResult (result, nothing )
1406- elseif tti0 <: Tuple
1419+ end
1420+ if tti0 <: Tuple
14071421 if isa (tti0, DataType)
14081422 return AbstractIterationResult (Any[ p for p in tti0. parameters ], nothing )
14091423 elseif ! isa (tti, DataType)
@@ -1667,7 +1681,7 @@ end
16671681 return isa_condition (xt, ty, max_union_splitting)
16681682end
16691683@inline function isa_condition (@nospecialize (xt), @nospecialize (ty), max_union_splitting:: Int )
1670- tty_ub, isexact_tty = instanceof_tfunc (ty)
1684+ tty_ub, isexact_tty = instanceof_tfunc (ty, true )
16711685 tty = widenconst (xt)
16721686 if isexact_tty && ! isa (tty_ub, TypeVar)
16731687 tty_lb = tty_ub # TODO : this would be wrong if !isexact_tty, but instanceof_tfunc doesn't preserve this info
@@ -1677,7 +1691,7 @@ end
16771691 # `typeintersect` may be unable narrow down `Type`-type
16781692 thentype = tty_ub
16791693 end
1680- valid_as_lattice (thentype) || (thentype = Bottom)
1694+ valid_as_lattice (thentype, true ) || (thentype = Bottom)
16811695 elsetype = typesubtract (tty, tty_lb, max_union_splitting)
16821696 return ConditionalTypes (thentype, elsetype)
16831697 end
@@ -1923,7 +1937,7 @@ function abstract_invoke(interp::AbstractInterpreter, (; fargs, argtypes)::ArgIn
19231937 ft′ = argtype_by_index (argtypes, 2 )
19241938 ft = widenconst (ft′)
19251939 ft === Bottom && return CallMeta (Bottom, EFFECTS_THROWS, NoCallInfo ())
1926- (types, isexact, isconcrete, istype) = instanceof_tfunc (argtype_by_index (argtypes, 3 ))
1940+ (types, isexact, isconcrete, istype) = instanceof_tfunc (argtype_by_index (argtypes, 3 ), false )
19271941 isexact || return CallMeta (Any, Effects (), NoCallInfo ())
19281942 unwrapped = unwrap_unionall (types)
19291943 if types === Bottom || ! (unwrapped isa DataType) || unwrapped. name != = Tuple. name
@@ -2153,6 +2167,7 @@ function abstract_call_unknown(interp::AbstractInterpreter, @nospecialize(ft),
21532167 end
21542168 # non-constant function, but the number of arguments is known and the `f` is not a builtin or intrinsic
21552169 atype = argtypes_to_type (arginfo. argtypes)
2170+ atype === Bottom && return CallMeta (Union{}, Union{}, EFFECTS_THROWS, NoCallInfo ()) # accidentally unreachable
21562171 return abstract_call_gf_by_type (interp, nothing , arginfo, si, atype, sv, max_methods)
21572172end
21582173
@@ -2380,7 +2395,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
23802395 (; rt, effects) = abstract_eval_call (interp, e, vtypes, sv)
23812396 t = rt
23822397 elseif ehead === :new
2383- t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv))
2398+ t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv), true )
23842399 ut = unwrap_unionall (t)
23852400 consistent = ALWAYS_FALSE
23862401 nothrow = false
@@ -2444,7 +2459,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
24442459 end
24452460 effects = Effects (EFFECTS_TOTAL; consistent, nothrow)
24462461 elseif ehead === :splatnew
2447- t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv))
2462+ t, isexact = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv), true )
24482463 nothrow = false # TODO : More precision
24492464 if length (e. args) == 2 && isconcretedispatch (t) && ! ismutabletype (t)
24502465 at = abstract_eval_value (interp, e. args[2 ], vtypes, sv)
0 commit comments