@@ -2570,9 +2570,9 @@ function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntSta
2570
2570
M isa Module || return CallMeta (Union{}, TypeError, EFFECTS_THROWS, NoCallInfo ())
2571
2571
s isa Symbol || return CallMeta (Union{}, TypeError, EFFECTS_THROWS, NoCallInfo ())
2572
2572
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
2574
2574
partition_T = nothing
2575
- partition_rte = abstract_eval_partition_load (interp, partition)
2575
+ partition_rte = abstract_eval_partition_load (interp, binding, partition)
2576
2576
if binding_kind (partition) == PARTITION_KIND_GLOBAL
2577
2577
partition_T = partition_restriction (partition)
2578
2578
end
@@ -3511,13 +3511,11 @@ function abstract_eval_binding_partition!(interp::AbstractInterpreter, g::Global
3511
3511
return partition
3512
3512
end
3513
3513
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 )
3517
3515
kind = binding_kind (partition)
3518
3516
isdepwarn = (partition. kind & PARTITION_FLAG_DEPWARN) != 0
3519
3517
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)
3521
3519
if interp != = nothing && InferenceParams (interp). assume_bindings_static
3522
3520
return RTEffects (Union{}, UndefVarError, EFFECTS_THROWS)
3523
3521
else
@@ -3543,12 +3541,23 @@ function abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing
3543
3541
# Could be replaced by a backdated const which has an effect, so we can't assume it won't.
3544
3542
# Besides, we would prefer not to merge the world range for this into the world range for
3545
3543
# _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)
3547
3545
rt = Any
3548
3546
else
3549
3547
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
3550
3559
end
3551
- return RTEffects (rt, UndefVarError, local_getglobal_effects )
3560
+ return RTEffects (rt, exct, effects )
3552
3561
end
3553
3562
3554
3563
function 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) =
3596
3605
abstract_load_all_consistent_leaf_partitions (interp, g:: GlobalRef , wwr:: WorldWithRange ) =
3597
3606
scan_leaf_partitions (abstract_eval_partition_load, interp, g, wwr)
3598
3607
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
-
3608
3608
function abstract_eval_globalref (interp, g:: GlobalRef , saw_latestworld:: Bool , sv:: AbsIntState )
3609
3609
if saw_latestworld
3610
3610
return RTEffects (Any, Any, generic_getglobal_effects)
3611
3611
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)
3613
3616
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
3621
3617
return ret
3622
3618
end
3623
3619
0 commit comments