@@ -2421,11 +2421,15 @@ function abstract_eval_getglobal(interp::AbstractInterpreter, sv::AbsIntState, s
24212421end
24222422
24232423function abstract_eval_getglobal (interp:: AbstractInterpreter , sv:: AbsIntState , saw_latestworld:: Bool , argtypes:: Vector{Any} )
2424- if length (argtypes) == 3
2425- return abstract_eval_getglobal (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ])
2426- elseif length (argtypes) == 4
2427- return abstract_eval_getglobal (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ])
2428- elseif ! isvarargtype (argtypes[end ]) || length (argtypes) > 5
2424+ if ! isvarargtype (argtypes[end ])
2425+ if length (argtypes) == 3
2426+ return abstract_eval_getglobal (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ])
2427+ elseif length (argtypes) == 4
2428+ return abstract_eval_getglobal (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ])
2429+ else
2430+ return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
2431+ end
2432+ elseif length (argtypes) > 5
24292433 return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
24302434 else
24312435 return CallMeta (Any, generic_getglobal_exct, generic_getglobal_effects, NoCallInfo ())
@@ -2466,12 +2470,17 @@ end
24662470end
24672471
24682472function abstract_eval_get_binding_type (interp:: AbstractInterpreter , sv:: AbsIntState , argtypes:: Vector{Any} )
2469- if length (argtypes) == 3
2470- return abstract_eval_get_binding_type (interp, sv, argtypes[2 ], argtypes[3 ])
2471- elseif ! isvarargtype (argtypes[end ]) || length (argtypes) > 4
2473+ if ! isvarargtype (argtypes[end ])
2474+ if length (argtypes) == 3
2475+ return abstract_eval_get_binding_type (interp, sv, argtypes[2 ], argtypes[3 ])
2476+ else
2477+ return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
2478+ end
2479+ elseif length (argtypes) > 4
24722480 return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
2481+ else
2482+ return CallMeta (Type, Union{TypeError, ArgumentError}, EFFECTS_THROWS, NoCallInfo ())
24732483 end
2474- return CallMeta (Type, Union{TypeError, ArgumentError}, EFFECTS_THROWS, NoCallInfo ())
24752484end
24762485
24772486const setglobal!_effects = Effects (EFFECTS_TOTAL; effect_free= ALWAYS_FALSE, nothrow= false , inaccessiblememonly= ALWAYS_FALSE)
@@ -2504,11 +2513,15 @@ end
25042513const generic_setglobal!_exct = Union{ArgumentError, TypeError, ErrorException, ConcurrencyViolationError}
25052514
25062515function abstract_eval_setglobal! (interp:: AbstractInterpreter , sv:: AbsIntState , saw_latestworld:: Bool , argtypes:: Vector{Any} )
2507- if length (argtypes) == 4
2508- return abstract_eval_setglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ])
2509- elseif length (argtypes) == 5
2510- return abstract_eval_setglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ], argtypes[5 ])
2511- elseif ! isvarargtype (argtypes[end ]) || length (argtypes) > 6
2516+ if ! isvarargtype (argtypes[end ])
2517+ if length (argtypes) == 4
2518+ return abstract_eval_setglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ])
2519+ elseif length (argtypes) == 5
2520+ return abstract_eval_setglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ], argtypes[5 ])
2521+ else
2522+ return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
2523+ end
2524+ elseif length (argtypes) > 6
25122525 return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
25132526 else
25142527 return CallMeta (Any, generic_setglobal!_exct, setglobal!_effects, NoCallInfo ())
@@ -2532,75 +2545,87 @@ function abstract_eval_swapglobal!(interp::AbstractInterpreter, sv::AbsIntState,
25322545end
25332546
25342547function abstract_eval_swapglobal! (interp:: AbstractInterpreter , sv:: AbsIntState , saw_latestworld:: Bool , argtypes:: Vector{Any} )
2535- if length (argtypes) == 4
2536- return abstract_eval_swapglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ])
2537- elseif length (argtypes) == 5
2538- return abstract_eval_swapglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ], argtypes[5 ])
2539- elseif ! isvarargtype (argtypes[end ]) || length (argtypes) > 6
2548+ if ! isvarargtype (argtypes[end ])
2549+ if length (argtypes) == 4
2550+ return abstract_eval_swapglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ])
2551+ elseif length (argtypes) == 5
2552+ return abstract_eval_swapglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ], argtypes[5 ])
2553+ else
2554+ return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
2555+ end
2556+ elseif length (argtypes) > 6
25402557 return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
25412558 else
25422559 return CallMeta (Any, Union{generic_getglobal_exct,generic_setglobal!_exct}, setglobal!_effects, NoCallInfo ())
25432560 end
25442561end
25452562
25462563function abstract_eval_setglobalonce! (interp:: AbstractInterpreter , sv:: AbsIntState , saw_latestworld:: Bool , argtypes:: Vector{Any} )
2547- if length (argtypes) in (4 , 5 , 6 )
2548- cm = abstract_eval_setglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ])
2549- if length (argtypes) >= 5
2550- goe = global_order_exct (argtypes[5 ], #= loading=# true , #= storing=# true )
2551- cm = merge_exct (cm, goe)
2552- end
2553- if length (argtypes) == 6
2554- goe = global_order_exct (argtypes[6 ], #= loading=# true , #= storing=# false )
2555- cm = merge_exct (cm, goe)
2556- end
2557- return CallMeta (Bool, cm. exct, cm. effects, cm. info)
2558- elseif ! isvarargtype (argtypes[end ]) || length (argtypes) > 6
2564+ if ! isvarargtype (argtypes[end ])
2565+ if length (argtypes) in (4 , 5 , 6 )
2566+ cm = abstract_eval_setglobal! (interp, sv, saw_latestworld, argtypes[2 ], argtypes[3 ], argtypes[4 ])
2567+ if length (argtypes) >= 5
2568+ goe = global_order_exct (argtypes[5 ], #= loading=# true , #= storing=# true )
2569+ cm = merge_exct (cm, goe)
2570+ end
2571+ if length (argtypes) == 6
2572+ goe = global_order_exct (argtypes[6 ], #= loading=# true , #= storing=# false )
2573+ cm = merge_exct (cm, goe)
2574+ end
2575+ return CallMeta (Bool, cm. exct, cm. effects, cm. info)
2576+ else
2577+ return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
2578+ end
2579+ elseif length (argtypes) > 7
25592580 return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
25602581 else
25612582 return CallMeta (Bool, generic_setglobal!_exct, setglobal!_effects, NoCallInfo ())
25622583 end
25632584end
25642585
25652586function abstract_eval_replaceglobal! (interp:: AbstractInterpreter , sv:: AbsIntState , saw_latestworld:: Bool , argtypes:: Vector{Any} )
2566- if length (argtypes) in (5 , 6 , 7 )
2567- (M, s, x, v) = argtypes[2 ], argtypes[3 ], argtypes[4 ], argtypes[5 ]
2568- T = nothing
2569- if isa (M, Const) && isa (s, Const)
2570- M, s = M. val, s. val
2571- M isa Module || return CallMeta (Union{}, TypeError, EFFECTS_THROWS, NoCallInfo ())
2572- s isa Symbol || return CallMeta (Union{}, TypeError, EFFECTS_THROWS, NoCallInfo ())
2573- gr = GlobalRef (M, s)
2574- v′ = RefValue {Any} (v)
2575- (valid_worlds, (rte, T)) = scan_leaf_partitions (interp, gr, sv. world) do interp:: AbstractInterpreter , binding:: Core.Binding , partition:: Core.BindingPartition
2576- partition_T = nothing
2577- partition_rte = abstract_eval_partition_load (interp, binding, partition)
2578- if binding_kind (partition) == PARTITION_KIND_GLOBAL
2579- partition_T = partition_restriction (partition)
2587+ if ! isvarargtype (argtypes[end ])
2588+ if length (argtypes) in (5 , 6 , 7 )
2589+ (M, s, x, v) = argtypes[2 ], argtypes[3 ], argtypes[4 ], argtypes[5 ]
2590+ T = nothing
2591+ if isa (M, Const) && isa (s, Const)
2592+ M, s = M. val, s. val
2593+ M isa Module || return CallMeta (Union{}, TypeError, EFFECTS_THROWS, NoCallInfo ())
2594+ s isa Symbol || return CallMeta (Union{}, TypeError, EFFECTS_THROWS, NoCallInfo ())
2595+ gr = GlobalRef (M, s)
2596+ v′ = RefValue {Any} (v)
2597+ (valid_worlds, (rte, T)) = scan_leaf_partitions (interp, gr, sv. world) do interp:: AbstractInterpreter , binding:: Core.Binding , partition:: Core.BindingPartition
2598+ partition_T = nothing
2599+ partition_rte = abstract_eval_partition_load (interp, binding, partition)
2600+ if binding_kind (partition) == PARTITION_KIND_GLOBAL
2601+ partition_T = partition_restriction (partition)
2602+ end
2603+ partition_exct = Union{partition_rte. exct, global_assignment_binding_rt_exct (interp, partition, v′[])[2 ]}
2604+ partition_rte = RTEffects (partition_rte. rt, partition_exct, partition_rte. effects)
2605+ Pair {RTEffects, Any} (partition_rte, partition_T)
25802606 end
2581- partition_exct = Union{partition_rte. exct, global_assignment_binding_rt_exct (interp, partition, v′[])[2 ]}
2582- partition_rte = RTEffects (partition_rte. rt, partition_exct, partition_rte. effects)
2583- Pair {RTEffects, Any} (partition_rte, partition_T)
2607+ update_valid_age! (sv, valid_worlds)
2608+ effects = merge_effects (rte. effects, Effects (setglobal!_effects, nothrow= rte. exct=== Bottom))
2609+ sg = CallMeta (Any, rte. exct, effects, GlobalAccessInfo (convert (Core. Binding, gr)))
2610+ else
2611+ sg = abstract_eval_setglobal! (interp, sv, saw_latestworld, M, s, v)
2612+ end
2613+ if length (argtypes) >= 6
2614+ goe = global_order_exct (argtypes[6 ], #= loading=# true , #= storing=# true )
2615+ sg = merge_exct (sg, goe)
25842616 end
2585- update_valid_age! (sv, valid_worlds)
2586- effects = merge_effects (rte. effects, Effects (setglobal!_effects, nothrow= rte. exct=== Bottom))
2587- sg = CallMeta (Any, rte. exct, effects, GlobalAccessInfo (convert (Core. Binding, gr)))
2617+ if length (argtypes) == 7
2618+ goe = global_order_exct (argtypes[7 ], #= loading=# true , #= storing=# false )
2619+ sg = merge_exct (sg, goe)
2620+ end
2621+ rt = T === nothing ?
2622+ ccall (:jl_apply_cmpswap_type , Any, (Any,), S) where S :
2623+ ccall (:jl_apply_cmpswap_type , Any, (Any,), T)
2624+ return CallMeta (rt, sg. exct, sg. effects, sg. info)
25882625 else
2589- sg = abstract_eval_setglobal! (interp, sv, saw_latestworld, M, s, v)
2590- end
2591- if length (argtypes) >= 6
2592- goe = global_order_exct (argtypes[6 ], #= loading=# true , #= storing=# true )
2593- sg = merge_exct (sg, goe)
2594- end
2595- if length (argtypes) == 7
2596- goe = global_order_exct (argtypes[7 ], #= loading=# true , #= storing=# false )
2597- sg = merge_exct (sg, goe)
2626+ return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
25982627 end
2599- rt = T === nothing ?
2600- ccall (:jl_apply_cmpswap_type , Any, (Any,), S) where S :
2601- ccall (:jl_apply_cmpswap_type , Any, (Any,), T)
2602- return CallMeta (rt, sg. exct, sg. effects, sg. info)
2603- elseif ! isvarargtype (argtypes[end ]) || length (argtypes) > 8
2628+ elseif length (argtypes) > 8
26042629 return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
26052630 else
26062631 return CallMeta (Any, Union{generic_getglobal_exct,generic_setglobal!_exct}, setglobal!_effects, NoCallInfo ())
@@ -2655,11 +2680,8 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
26552680 return Future (abstract_eval_isdefinedglobal (interp, argtypes[2 ], argtypes[3 ], Const (true ),
26562681 length (argtypes) == 4 ? argtypes[4 ] : Const (:unordered ),
26572682 si. saw_latestworld, sv))
2658- elseif f === Core. isdefinedglobal && 3 <= length (argtypes) <= 5
2659- return Future (abstract_eval_isdefinedglobal (interp, argtypes[2 ], argtypes[3 ],
2660- length (argtypes) >= 4 ? argtypes[4 ] : Const (true ),
2661- length (argtypes) >= 5 ? argtypes[5 ] : Const (:unordered ),
2662- si. saw_latestworld, sv))
2683+ elseif f === Core. isdefinedglobal
2684+ return Future (abstract_eval_isdefinedglobal (interp, sv, si. saw_latestworld, argtypes))
26632685 elseif f === Core. get_binding_type
26642686 return Future (abstract_eval_get_binding_type (interp, sv, argtypes))
26652687 end
@@ -3299,6 +3321,23 @@ function abstract_eval_isdefinedglobal(interp::AbstractInterpreter, @nospecializ
32993321 return CallMeta (Bool, Union{exct, TypeError, UndefVarError}, generic_isdefinedglobal_effects, NoCallInfo ())
33003322end
33013323
3324+ function abstract_eval_isdefinedglobal (interp:: AbstractInterpreter , sv:: AbsIntState , saw_latestworld:: Bool , argtypes:: Vector{Any} )
3325+ if ! isvarargtype (argtypes[end ])
3326+ if 3 <= length (argtypes) <= 5
3327+ return abstract_eval_isdefinedglobal (interp, argtypes[2 ], argtypes[3 ],
3328+ length (argtypes) >= 4 ? argtypes[4 ] : Const (true ),
3329+ length (argtypes) >= 5 ? argtypes[5 ] : Const (:unordered ),
3330+ saw_latestworld, sv)
3331+ else
3332+ return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
3333+ end
3334+ elseif length (argtypes) > 6
3335+ return CallMeta (Union{}, ArgumentError, EFFECTS_THROWS, NoCallInfo ())
3336+ else
3337+ return CallMeta (Bool, Union{ConcurrencyViolationError, TypeError, UndefVarError}, generic_isdefinedglobal_effects, NoCallInfo ())
3338+ end
3339+ end
3340+
33023341function abstract_eval_throw_undef_if_not (interp:: AbstractInterpreter , e:: Expr , sstate:: StatementState , sv:: AbsIntState )
33033342 condt = abstract_eval_value (interp, e. args[2 ], sstate, sv)
33043343 condval = maybe_extract_const_bool (condt)
@@ -3452,6 +3491,20 @@ function merge_override_effects!(interp::AbstractInterpreter, effects::Effects,
34523491 # It is possible for arguments (GlobalRef/:static_parameter) to throw,
34533492 # but these will be recomputed during SSA construction later.
34543493 override = decode_statement_effects_override (sv)
3494+ if override. consistent
3495+ m = sv. linfo. def
3496+ if isa (m, Method)
3497+ # N.B.: We'd like deleted_world here, but we can't add an appropriate edge at this point.
3498+ # However, in order to reach here in the first place, ordinary method lookup would have
3499+ # had to add an edge and appropriate invalidation trigger.
3500+ valid_worlds = WorldRange (m. primary_world, typemax (Int))
3501+ if sv. world. this in valid_worlds
3502+ update_valid_age! (sv, valid_worlds)
3503+ else
3504+ override = EffectsOverride (override, consistent= false )
3505+ end
3506+ end
3507+ end
34553508 effects = override_effects (effects, override)
34563509 set_curr_ssaflag! (sv, flags_for_effects (effects), IR_FLAGS_EFFECTS)
34573510 merge_effects! (interp, sv, effects)
0 commit comments