Skip to content

Commit

Permalink
effects: fix :nothrow modeling of getglobal
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Aug 2, 2023
1 parent 18b0989 commit 29ab6d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
21 changes: 10 additions & 11 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2343,19 +2343,18 @@ function getfield_effects(𝕃::AbstractLattice, arginfo::ArgInfo, @nospecialize
end

function getglobal_effects(argtypes::Vector{Any}, @nospecialize(rt))
2 length(argtypes) 3 || return EFFECTS_THROWS
consistent = inaccessiblememonly = ALWAYS_FALSE
nothrow = false
if length(argtypes) 2
M, s = argtypes[1], argtypes[2]
if getglobal_nothrow(M, s)
nothrow = true
# typeasserts below are already checked in `getglobal_nothrow`
Mval, sval = (M::Const).val::Module, (s::Const).val::Symbol
if isconst(Mval, sval)
consistent = ALWAYS_TRUE
if is_mutation_free_argtype(rt)
inaccessiblememonly = ALWAYS_TRUE
end
M, s = argtypes[1], argtypes[2]
if (length(argtypes) == 3 ? getglobal_nothrow(M, s, argtypes[3]) : getglobal_nothrow(M, s))
nothrow = true
# typeasserts below are already checked in `getglobal_nothrow`
Mval, sval = (M::Const).val::Module, (s::Const).val::Symbol
if isconst(Mval, sval)
consistent = ALWAYS_TRUE
if is_mutation_free_argtype(rt)
inaccessiblememonly = ALWAYS_TRUE
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1011,3 +1011,15 @@ end
isinf(y) && return zero(y)
irinterp_nothrow_override(true, y)
end |> Core.Compiler.is_nothrow

# getglobal effects
const my_defined_var = 42
@test Base.infer_effects() do
getglobal(@__MODULE__, :my_defined_var, :monotonic)
end |> Core.Compiler.is_foldable_nothrow
@test Base.infer_effects() do
getglobal(@__MODULE__, :my_defined_var, :foo)
end |> !Core.Compiler.is_nothrow
@test Base.infer_effects() do
getglobal(@__MODULE__, :my_defined_var, :foo, nothing)
end |> !Core.Compiler.is_nothrow

0 comments on commit 29ab6d2

Please sign in to comment.