@@ -2574,9 +2574,9 @@ function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntSta
25742574 M isa Module || return CallMeta (Union{}, TypeError, EFFECTS_THROWS, NoCallInfo ())
25752575 s isa Symbol || return CallMeta (Union{}, TypeError, EFFECTS_THROWS, NoCallInfo ())
25762576 gr = GlobalRef (M, s)
2577- (valid_worlds, (rte, T)) = scan_leaf_partitions (interp, gr, sv. world) do interp, _ , partition
2577+ (valid_worlds, (rte, T)) = scan_leaf_partitions (interp, gr, sv. world) do interp, binding , partition
25782578 partition_T = nothing
2579- partition_rte = abstract_eval_partition_load (interp, partition)
2579+ partition_rte = abstract_eval_partition_load (interp, binding, partition)
25802580 if binding_kind (partition) == PARTITION_KIND_GLOBAL
25812581 partition_T = partition_restriction (partition)
25822582 end
@@ -3558,13 +3558,11 @@ function abstract_eval_binding_partition!(interp::AbstractInterpreter, g::Global
35583558 return partition
35593559end
35603560
3561- abstract_eval_partition_load (interp:: Union{AbstractInterpreter, Nothing} , :: Core.Binding , partition:: Core.BindingPartition ) =
3562- abstract_eval_partition_load (interp, partition)
3563- function abstract_eval_partition_load (interp:: Union{AbstractInterpreter, Nothing} , partition:: Core.BindingPartition )
3561+ function abstract_eval_partition_load (interp:: Union{AbstractInterpreter, Nothing} , binding:: Core.Binding , partition:: Core.BindingPartition )
35643562 kind = binding_kind (partition)
35653563 isdepwarn = (partition. kind & PARTITION_FLAG_DEPWARN) != 0
35663564 local_getglobal_effects = Effects (generic_getglobal_effects, effect_free= isdepwarn ? ALWAYS_FALSE : ALWAYS_TRUE)
3567- if is_some_guard (kind) || kind == PARTITION_KIND_UNDEF_CONST
3565+ if is_some_guard (kind)
35683566 if interp != = nothing && InferenceParams (interp). assume_bindings_static
35693567 return RTEffects (Union{}, UndefVarError, EFFECTS_THROWS)
35703568 else
@@ -3590,12 +3588,23 @@ function abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing
35903588 # Could be replaced by a backdated const which has an effect, so we can't assume it won't.
35913589 # Besides, we would prefer not to merge the world range for this into the world range for
35923590 # _GLOBAL, because that would pessimize codegen.
3593- local_getglobal_effects = Effects (local_getglobal_effects, effect_free= ALWAYS_FALSE)
3591+ effects = Effects (local_getglobal_effects, effect_free= ALWAYS_FALSE)
35943592 rt = Any
35953593 else
35963594 rt = partition_restriction (partition)
3595+ effects = local_getglobal_effects
3596+ end
3597+ if (interp != = nothing && InferenceParams (interp). assume_bindings_static &&
3598+ kind in (PARTITION_KIND_GLOBAL, PARTITION_KIND_DECLARED) &&
3599+ isdefined (binding, :value ))
3600+ exct = Union{}
3601+ effects = Effects (generic_getglobal_effects; nothrow= true )
3602+ else
3603+ # We do not assume in general that assigned global bindings remain assigned.
3604+ # The existence of pkgimages allows them to revert in practice.
3605+ exct = UndefVarError
35973606 end
3598- return RTEffects (rt, UndefVarError, local_getglobal_effects )
3607+ return RTEffects (rt, exct, effects )
35993608end
36003609
36013610function scan_specified_partitions (query:: Function , walk_binding_partition:: Function , interp, g:: GlobalRef , wwr:: WorldWithRange )
@@ -3643,28 +3652,15 @@ scan_partitions(query::Function, interp, g::GlobalRef, wwr::WorldWithRange) =
36433652abstract_load_all_consistent_leaf_partitions (interp, g:: GlobalRef , wwr:: WorldWithRange ) =
36443653 scan_leaf_partitions (abstract_eval_partition_load, interp, g, wwr)
36453654
3646- function abstract_eval_globalref_partition (interp, binding:: Core.Binding , partition:: Core.BindingPartition )
3647- # For inference purposes, we don't particularly care which global binding we end up loading, we only
3648- # care about its type. However, we would still like to terminate the world range for the particular
3649- # binding we end up reaching such that codegen can emit a simpler pointer load.
3650- Pair {RTEffects, Union{Nothing, Core.Binding}} (
3651- abstract_eval_partition_load (interp, partition),
3652- binding_kind (partition) in (PARTITION_KIND_GLOBAL, PARTITION_KIND_DECLARED) ? binding : nothing )
3653- end
3654-
36553655function abstract_eval_globalref (interp, g:: GlobalRef , saw_latestworld:: Bool , sv:: AbsIntState )
36563656 if saw_latestworld
36573657 return RTEffects (Any, Any, generic_getglobal_effects)
36583658 end
3659- (valid_worlds, (ret, binding_if_global)) = scan_leaf_partitions (abstract_eval_globalref_partition, interp, g, sv. world)
3659+ # For inference purposes, we don't particularly care which global binding we end up loading, we only
3660+ # care about its type. However, we would still like to terminate the world range for the particular
3661+ # binding we end up reaching such that codegen can emit a simpler pointer load.
3662+ (valid_worlds, ret) = scan_leaf_partitions (abstract_eval_partition_load, interp, g, sv. world)
36603663 update_valid_age! (sv, valid_worlds)
3661- if ret. rt != = Union{} && ret. exct === UndefVarError && binding_if_global != = nothing && InferenceParams (interp). assume_bindings_static
3662- if isdefined (binding_if_global, :value )
3663- ret = RTEffects (ret. rt, Union{}, Effects (generic_getglobal_effects, nothrow= true ))
3664- end
3665- # We do not assume in general that assigned global bindings remain assigned.
3666- # The existence of pkgimages allows them to revert in practice.
3667- end
36683664 return ret
36693665end
36703666
0 commit comments