@@ -2570,9 +2570,9 @@ function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntSta
25702570 M isa Module || return CallMeta(Union{}, TypeError, EFFECTS_THROWS, NoCallInfo())
25712571 s isa Symbol || return CallMeta(Union{}, TypeError, EFFECTS_THROWS, NoCallInfo())
25722572 gr = GlobalRef(M, s)
2573- (valid_worlds, (rte, T)) = scan_leaf_partitions(interp, gr, sv.world) do interp, _ , partition
2573+ (valid_worlds, (rte, T)) = scan_leaf_partitions(interp, gr, sv.world) do interp, binding , partition
25742574 partition_T = nothing
2575- partition_rte = abstract_eval_partition_load(interp, partition)
2575+ partition_rte = abstract_eval_partition_load(interp, binding, partition)
25762576 if binding_kind(partition) == PARTITION_KIND_GLOBAL
25772577 partition_T = partition_restriction(partition)
25782578 end
@@ -3511,13 +3511,11 @@ function abstract_eval_binding_partition!(interp::AbstractInterpreter, g::Global
35113511 return partition
35123512end
35133513
3514- abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing}, ::Core.Binding, partition::Core.BindingPartition) =
3515- abstract_eval_partition_load(interp, partition)
3516- function abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing}, partition::Core.BindingPartition)
3514+ function abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing}, binding::Core.Binding, partition::Core.BindingPartition)
35173515 kind = binding_kind(partition)
35183516 isdepwarn = (partition.kind & PARTITION_FLAG_DEPWARN) != 0
35193517 local_getglobal_effects = Effects(generic_getglobal_effects, effect_free=isdepwarn ? ALWAYS_FALSE : ALWAYS_TRUE)
3520- if is_some_guard(kind) || kind == PARTITION_KIND_UNDEF_CONST
3518+ if is_some_guard(kind)
35213519 if interp !== nothing && InferenceParams(interp).assume_bindings_static
35223520 return RTEffects(Union{}, UndefVarError, EFFECTS_THROWS)
35233521 else
@@ -3543,12 +3541,23 @@ function abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing
35433541 # Could be replaced by a backdated const which has an effect, so we can't assume it won't.
35443542 # Besides, we would prefer not to merge the world range for this into the world range for
35453543 # _GLOBAL, because that would pessimize codegen.
3546- local_getglobal_effects = Effects(local_getglobal_effects, effect_free=ALWAYS_FALSE)
3544+ effects = Effects(local_getglobal_effects, effect_free=ALWAYS_FALSE)
35473545 rt = Any
35483546 else
35493547 rt = partition_restriction(partition)
3548+ effects = local_getglobal_effects
3549+ end
3550+ if (interp !== nothing && InferenceParams(interp).assume_bindings_static &&
3551+ kind in (PARTITION_KIND_GLOBAL, PARTITION_KIND_DECLARED) &&
3552+ isdefined(binding, :value))
3553+ exct = Union{}
3554+ effects = Effects(generic_getglobal_effects; nothrow=true)
3555+ else
3556+ # We do not assume in general that assigned global bindings remain assigned.
3557+ # The existence of pkgimages allows them to revert in practice.
3558+ exct = UndefVarError
35503559 end
3551- return RTEffects(rt, UndefVarError, local_getglobal_effects )
3560+ return RTEffects(rt, exct, effects )
35523561end
35533562
35543563function scan_specified_partitions(query::Function, walk_binding_partition::Function, interp, g::GlobalRef, wwr::WorldWithRange)
@@ -3596,28 +3605,15 @@ scan_partitions(query::Function, interp, g::GlobalRef, wwr::WorldWithRange) =
35963605abstract_load_all_consistent_leaf_partitions(interp, g::GlobalRef, wwr::WorldWithRange) =
35973606 scan_leaf_partitions(abstract_eval_partition_load, interp, g, wwr)
35983607
3599- function abstract_eval_globalref_partition(interp, binding::Core.Binding, partition::Core.BindingPartition)
3600- # For inference purposes, we don't particularly care which global binding we end up loading, we only
3601- # care about its type. However, we would still like to terminate the world range for the particular
3602- # binding we end up reaching such that codegen can emit a simpler pointer load.
3603- Pair{RTEffects, Union{Nothing, Core.Binding}}(
3604- abstract_eval_partition_load(interp, partition),
3605- binding_kind(partition) in (PARTITION_KIND_GLOBAL, PARTITION_KIND_DECLARED) ? binding : nothing)
3606- end
3607-
36083608function abstract_eval_globalref(interp, g::GlobalRef, saw_latestworld::Bool, sv::AbsIntState)
36093609 if saw_latestworld
36103610 return RTEffects(Any, Any, generic_getglobal_effects)
36113611 end
3612- (valid_worlds, (ret, binding_if_global)) = scan_leaf_partitions(abstract_eval_globalref_partition, interp, g, sv.world)
3612+ # For inference purposes, we don't particularly care which global binding we end up loading, we only
3613+ # care about its type. However, we would still like to terminate the world range for the particular
3614+ # binding we end up reaching such that codegen can emit a simpler pointer load.
3615+ (valid_worlds, ret) = scan_leaf_partitions(abstract_eval_partition_load, interp, g, sv.world)
36133616 update_valid_age!(sv, valid_worlds)
3614- if ret.rt !== Union{} && ret.exct === UndefVarError && binding_if_global !== nothing && InferenceParams(interp).assume_bindings_static
3615- if isdefined(binding_if_global, :value)
3616- ret = RTEffects(ret.rt, Union{}, Effects(generic_getglobal_effects, nothrow=true))
3617- end
3618- # We do not assume in general that assigned global bindings remain assigned.
3619- # The existence of pkgimages allows them to revert in practice.
3620- end
36213617 return ret
36223618end
36233619
0 commit comments