From 11cd8098714e7944fc899905114bdee404044f42 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Tue, 5 Nov 2024 18:30:35 +0900 Subject: [PATCH] inference: minor follow-ups to JuliaLang/julia#56299 (#56450) --- base/compiler/abstractinterpretation.jl | 16 ++++++++-------- base/compiler/tfuncs.jl | 4 ++-- test/compiler/effects.jl | 13 ++++++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 8b557b2105f1c..dbfe3bb9ccac4 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -2466,7 +2466,7 @@ function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntSta end end -function args_are_actually_getglobal(argtypes) +function argtypes_are_actually_getglobal(argtypes::Vector{Any}) length(argtypes) in (3, 4) || return false M = argtypes[2] s = argtypes[3] @@ -2506,21 +2506,21 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f), return Future(abstract_eval_setglobalonce!(interp, sv, argtypes)) elseif f === Core.replaceglobal! return Future(abstract_eval_replaceglobal!(interp, sv, argtypes)) - elseif f === Core.getfield && args_are_actually_getglobal(argtypes) + elseif f === Core.getfield && argtypes_are_actually_getglobal(argtypes) return Future(abstract_eval_getglobal(interp, sv, argtypes)) - elseif f === Core.isdefined && args_are_actually_getglobal(argtypes) + elseif f === Core.isdefined && argtypes_are_actually_getglobal(argtypes) exct = Bottom if length(argtypes) == 4 order = argtypes[4] - exct = global_order_exct(order, true, false) - if !(isa(order, Const) && get_atomic_order(order.val, true, false).x >= MEMORY_ORDER_UNORDERED.x) + exct = global_order_exct(order, #=loading=#true, #=storing=#false) + if !(isa(order, Const) && get_atomic_order(order.val, #=loading=#true, #=storing=#false).x >= MEMORY_ORDER_UNORDERED.x) exct = Union{exct, ConcurrencyViolationError} end end return Future(merge_exct(CallMeta(abstract_eval_isdefined( interp, - GlobalRef((argtypes[2]::Const).val, - (argtypes[3]::Const).val), + GlobalRef((argtypes[2]::Const).val::Module, + (argtypes[3]::Const).val::Symbol), sv), NoCallInfo()), exct)) elseif f === Core.get_binding_type @@ -3048,7 +3048,7 @@ function abstract_eval_copyast(interp::AbstractInterpreter, e::Expr, vtypes::Uni end function abstract_eval_isdefined_expr(interp::AbstractInterpreter, e::Expr, vtypes::Union{VarTable,Nothing}, - sv::AbsIntState) + sv::AbsIntState) sym = e.args[1] if isa(sym, SlotNumber) && vtypes !== nothing vtyp = vtypes[slot_id(sym)] diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index 64ec7054221e1..f0212f1082331 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -2497,11 +2497,11 @@ function builtin_effects(𝕃::AbstractLattice, @nospecialize(f::Builtin), argty elseif f === getglobal 2 ≤ length(argtypes) ≤ 3 || return EFFECTS_THROWS # Modeled more precisely in abstract_eval_getglobal - return Effects(EFFECTS_TOTAL; consistent=ALWAYS_FALSE, nothrow=false, inaccessiblememonly=ALWAYS_FALSE) + return generic_getglobal_effects elseif f === Core.get_binding_type length(argtypes) == 2 || return EFFECTS_THROWS # Modeled more precisely in abstract_eval_get_binding_type - return Effects(EFFECTS_TOTAL; effect_free=ALWAYS_FALSE, nothrow=get_binding_type_nothrow(𝕃, argtypes[1], argtypes[2])) + return Effects(EFFECTS_TOTAL; nothrow=get_binding_type_nothrow(𝕃, argtypes[1], argtypes[2])) elseif f === compilerbarrier length(argtypes) == 2 || return Effects(EFFECTS_THROWS; consistent=ALWAYS_FALSE) setting = argtypes[1] diff --git a/test/compiler/effects.jl b/test/compiler/effects.jl index cdc26cddc440d..4174aa3d01030 100644 --- a/test/compiler/effects.jl +++ b/test/compiler/effects.jl @@ -357,18 +357,21 @@ end @test !Core.Compiler.builtin_nothrow(Core.Compiler.fallback_lattice, Core.get_binding_type, Any[Rational{Int}, Core.Const(:foo)], Any) -# Nothrow for assignment to globals +# effects modeling for assignment to globals global glob_assign_int::Int = 0 -f_glob_assign_int() = global glob_assign_int += 1 -let effects = Base.infer_effects(f_glob_assign_int, ()) +f_glob_assign_int() = global glob_assign_int = 1 +let effects = Base.infer_effects(f_glob_assign_int, (); optimize=false) + @test Core.Compiler.is_consistent(effects) @test !Core.Compiler.is_effect_free(effects) @test Core.Compiler.is_nothrow(effects) end -# Nothrow for setglobal! +# effects modeling for for setglobal! global SETGLOBAL!_NOTHROW::Int = 0 -let effects = Base.infer_effects() do +let effects = Base.infer_effects(; optimize=false) do setglobal!(@__MODULE__, :SETGLOBAL!_NOTHROW, 42) end + @test Core.Compiler.is_consistent(effects) + @test !Core.Compiler.is_effect_free(effects) @test Core.Compiler.is_nothrow(effects) end