Skip to content

Commit 4c8bfe1

Browse files
committed
inference: minor follow-ups to #56299
- cosmetic changes (mostly) - added some new tests that have been fixed by the PR - remove the unnecessary `effect_free=ALWAYS_FALSE` taint for the fallback effects modeling of `Core.get_binding_type`
1 parent 8e0a171 commit 4c8bfe1

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,7 @@ function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntSta
24662466
end
24672467
end
24682468

2469-
function args_are_actually_getglobal(argtypes)
2469+
function argtypes_are_actually_getglobal(argtypes::Vector{Any})
24702470
length(argtypes) in (3, 4) || return false
24712471
M = argtypes[2]
24722472
s = argtypes[3]
@@ -2506,21 +2506,21 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
25062506
return Future(abstract_eval_setglobalonce!(interp, sv, argtypes))
25072507
elseif f === Core.replaceglobal!
25082508
return Future(abstract_eval_replaceglobal!(interp, sv, argtypes))
2509-
elseif f === Core.getfield && args_are_actually_getglobal(argtypes)
2509+
elseif f === Core.getfield && argtypes_are_actually_getglobal(argtypes)
25102510
return Future(abstract_eval_getglobal(interp, sv, argtypes))
2511-
elseif f === Core.isdefined && args_are_actually_getglobal(argtypes)
2511+
elseif f === Core.isdefined && argtypes_are_actually_getglobal(argtypes)
25122512
exct = Bottom
25132513
if length(argtypes) == 4
25142514
order = argtypes[4]
2515-
exct = global_order_exct(order, true, false)
2516-
if !(isa(order, Const) && get_atomic_order(order.val, true, false).x >= MEMORY_ORDER_UNORDERED.x)
2515+
exct = global_order_exct(order, #=loading=#true, #=storing=#false)
2516+
if !(isa(order, Const) && get_atomic_order(order.val, #=loading=#true, #=storing=#false).x >= MEMORY_ORDER_UNORDERED.x)
25172517
exct = Union{exct, ConcurrencyViolationError}
25182518
end
25192519
end
25202520
return Future(merge_exct(CallMeta(abstract_eval_isdefined(
25212521
interp,
2522-
GlobalRef((argtypes[2]::Const).val,
2523-
(argtypes[3]::Const).val),
2522+
GlobalRef((argtypes[2]::Const).val::Module,
2523+
(argtypes[3]::Const).val::Symbol),
25242524
sv),
25252525
NoCallInfo()), exct))
25262526
elseif f === Core.get_binding_type
@@ -3048,7 +3048,7 @@ function abstract_eval_copyast(interp::AbstractInterpreter, e::Expr, vtypes::Uni
30483048
end
30493049

30503050
function abstract_eval_isdefined_expr(interp::AbstractInterpreter, e::Expr, vtypes::Union{VarTable,Nothing},
3051-
sv::AbsIntState)
3051+
sv::AbsIntState)
30523052
sym = e.args[1]
30533053
if isa(sym, SlotNumber) && vtypes !== nothing
30543054
vtyp = vtypes[slot_id(sym)]

base/compiler/tfuncs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,11 +2497,11 @@ function builtin_effects(𝕃::AbstractLattice, @nospecialize(f::Builtin), argty
24972497
elseif f === getglobal
24982498
2 length(argtypes) 3 || return EFFECTS_THROWS
24992499
# Modeled more precisely in abstract_eval_getglobal
2500-
return Effects(EFFECTS_TOTAL; consistent=ALWAYS_FALSE, nothrow=false, inaccessiblememonly=ALWAYS_FALSE)
2500+
return generic_getglobal_effects
25012501
elseif f === Core.get_binding_type
25022502
length(argtypes) == 2 || return EFFECTS_THROWS
25032503
# Modeled more precisely in abstract_eval_get_binding_type
2504-
return Effects(EFFECTS_TOTAL; effect_free=ALWAYS_FALSE, nothrow=get_binding_type_nothrow(𝕃, argtypes[1], argtypes[2]))
2504+
return Effects(EFFECTS_TOTAL; nothrow=get_binding_type_nothrow(𝕃, argtypes[1], argtypes[2]))
25052505
elseif f === compilerbarrier
25062506
length(argtypes) == 2 || return Effects(EFFECTS_THROWS; consistent=ALWAYS_FALSE)
25072507
setting = argtypes[1]

test/compiler/effects.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,21 @@ end
357357

358358
@test !Core.Compiler.builtin_nothrow(Core.Compiler.fallback_lattice, Core.get_binding_type, Any[Rational{Int}, Core.Const(:foo)], Any)
359359

360-
# Nothrow for assignment to globals
360+
# effects modeling for assignment to globals
361361
global glob_assign_int::Int = 0
362-
f_glob_assign_int() = global glob_assign_int += 1
363-
let effects = Base.infer_effects(f_glob_assign_int, ())
362+
f_glob_assign_int() = global glob_assign_int = 1
363+
let effects = Base.infer_effects(f_glob_assign_int, (); optimize=false)
364+
@test Core.Compiler.is_consistent(effects)
364365
@test !Core.Compiler.is_effect_free(effects)
365366
@test Core.Compiler.is_nothrow(effects)
366367
end
367-
# Nothrow for setglobal!
368+
# effects modeling for for setglobal!
368369
global SETGLOBAL!_NOTHROW::Int = 0
369-
let effects = Base.infer_effects() do
370+
let effects = Base.infer_effects(; optimize=false) do
370371
setglobal!(@__MODULE__, :SETGLOBAL!_NOTHROW, 42)
371372
end
373+
@test Core.Compiler.is_consistent(effects)
374+
@test !Core.Compiler.is_effect_free(effects)
372375
@test Core.Compiler.is_nothrow(effects)
373376
end
374377

0 commit comments

Comments
 (0)