@@ -368,6 +368,7 @@ function find_union_split_method_matches(interp::AbstractInterpreter, argtypes::
368368 for i in 1 : length (split_argtypes)
369369 arg_n = split_argtypes[i]:: Vector{Any}
370370 sig_n = argtypes_to_type (arg_n)
371+ sig_n === Bottom && continue
371372 mt = ccall (:jl_method_table_for , Any, (Any,), sig_n)
372373 mt === nothing && return FailedMethodMatch (" Could not identify method table for call" )
373374 mt = mt:: MethodTable
@@ -614,7 +615,7 @@ function abstract_call_method(interp::AbstractInterpreter,
614615 sigtuple = unwrap_unionall (sig)
615616 sigtuple isa DataType ||
616617 return Future (MethodCallResult (Any, Any, Effects (), nothing , false , false ))
617- all (@nospecialize (x) -> valid_as_lattice ( unwrapva (x) , true ), sigtuple. parameters) ||
618+ all (@nospecialize (x) -> isvarargtype (x) || valid_as_lattice (x , true ), sigtuple. parameters) ||
618619 return Future (MethodCallResult (Union{}, Any, EFFECTS_THROWS, nothing , false , false )) # catch bad type intersections early
619620
620621 if is_nospecializeinfer (method)
@@ -2840,6 +2841,7 @@ function abstract_call_unknown(interp::AbstractInterpreter, @nospecialize(ft),
28402841 end
28412842 # non-constant function, but the number of arguments is known and the `f` is not a builtin or intrinsic
28422843 atype = argtypes_to_type (arginfo. argtypes)
2844+ atype === Bottom && return Future (CallMeta (Union{}, Union{}, EFFECTS_THROWS, NoCallInfo ())) # accidentally unreachable
28432845 return abstract_call_gf_by_type (interp, nothing , arginfo, si, atype, sv, max_methods):: Future
28442846end
28452847
@@ -3454,10 +3456,10 @@ world_range(ir::IRCode) = ir.valid_worlds
34543456world_range (ci:: CodeInfo ) = WorldRange (ci. min_world, ci. max_world)
34553457world_range (compact:: IncrementalCompact ) = world_range (compact. ir)
34563458
3457- function force_binding_resolution! (g:: GlobalRef )
3459+ function force_binding_resolution! (g:: GlobalRef , world :: UInt )
34583460 # Force resolution of the binding
34593461 # TODO : This will go away once we switch over to fully partitioned semantics
3460- ccall (:jl_globalref_boundp , Cint , (Any,), g)
3462+ ccall (:jl_force_binding_resolution , Cvoid , (Any, Csize_t ), g, world )
34613463 return nothing
34623464end
34633465
@@ -3475,7 +3477,7 @@ function abstract_eval_globalref_type(g::GlobalRef, src::Union{CodeInfo, IRCode,
34753477 # This method is surprisingly hot. For performance, don't ask the runtime to resolve
34763478 # the binding unless necessary - doing so triggers an additional lookup, which though
34773479 # not super expensive is hot enough to show up in benchmarks.
3478- force_binding_resolution! (g)
3480+ force_binding_resolution! (g, min_world (worlds) )
34793481 return abstract_eval_globalref_type (g, src, false )
34803482 end
34813483 # return Union{}
@@ -3488,7 +3490,7 @@ function abstract_eval_globalref_type(g::GlobalRef, src::Union{CodeInfo, IRCode,
34883490end
34893491
34903492function lookup_binding_partition! (interp:: AbstractInterpreter , g:: GlobalRef , sv:: AbsIntState )
3491- force_binding_resolution! (g)
3493+ force_binding_resolution! (g, get_inference_world (interp) )
34923494 partition = lookup_binding_partition (get_inference_world (interp), g)
34933495 update_valid_age! (sv, WorldRange (partition. min_world, partition. max_world))
34943496 partition
@@ -3522,6 +3524,11 @@ function abstract_eval_partition_load(interp::AbstractInterpreter, partition::Co
35223524 end
35233525
35243526 if is_defined_const_binding (kind)
3527+ if kind == BINDING_KIND_BACKDATED_CONST
3528+ # Infer this as guard. We do not want a later const definition to retroactively improve
3529+ # inference results in an earlier world.
3530+ return RTEffects (Any, UndefVarError, generic_getglobal_effects)
3531+ end
35253532 rt = Const (partition_restriction (partition))
35263533 return RTEffects (rt, Union{}, Effects (EFFECTS_TOTAL, inaccessiblememonly= is_mutation_free_argtype (rt) ? ALWAYS_TRUE : ALWAYS_FALSE))
35273534 end
@@ -3537,7 +3544,8 @@ function abstract_eval_globalref(interp::AbstractInterpreter, g::GlobalRef, saw_
35373544 partition = abstract_eval_binding_partition! (interp, g, sv)
35383545 ret = abstract_eval_partition_load (interp, partition)
35393546 if ret. rt != = Union{} && ret. exct === UndefVarError && InferenceParams (interp). assume_bindings_static
3540- if isdefined (g, :binding ) && isdefined (g. binding, :value )
3547+ b = convert (Core. Binding, g)
3548+ if isdefined (b, :value )
35413549 ret = RTEffects (ret. rt, Union{}, Effects (generic_getglobal_effects, nothrow= true ))
35423550 end
35433551 # We do not assume in general that assigned global bindings remain assigned.
@@ -3785,14 +3793,23 @@ function update_bestguess!(interp::AbstractInterpreter, frame::InferenceState,
37853793 slottypes = frame. slottypes
37863794 rt = widenreturn (rt, BestguessInfo (interp, bestguess, nargs, slottypes, currstate))
37873795 # narrow representation of bestguess slightly to prepare for tmerge with rt
3788- if rt isa InterConditional && bestguess isa Const
3796+ if rt isa InterConditional && bestguess isa Const && bestguess . val isa Bool
37893797 slot_id = rt. slot
37903798 old_id_type = widenconditional (slottypes[slot_id])
37913799 if bestguess. val === true && rt. elsetype != = Bottom
37923800 bestguess = InterConditional (slot_id, old_id_type, Bottom)
37933801 elseif bestguess. val === false && rt. thentype != = Bottom
37943802 bestguess = InterConditional (slot_id, Bottom, old_id_type)
37953803 end
3804+ # or narrow representation of rt slightly to prepare for tmerge with bestguess
3805+ elseif bestguess isa InterConditional && rt isa Const && rt. val isa Bool
3806+ slot_id = bestguess. slot
3807+ old_id_type = widenconditional (slottypes[slot_id])
3808+ if rt. val === true && bestguess. elsetype != = Bottom
3809+ rt = InterConditional (slot_id, old_id_type, Bottom)
3810+ elseif rt. val === false && bestguess. thentype != = Bottom
3811+ rt = InterConditional (slot_id, Bottom, old_id_type)
3812+ end
37963813 end
37973814 # copy limitations to return value
37983815 if ! isempty (frame. pclimitations)
0 commit comments