Skip to content

Commit

Permalink
effects: add :removable convenient setting for `Base.@assume_effect…
Browse files Browse the repository at this point in the history
…s` (#47700)

This setting is similar to `:foldable` but for dead call elimination.
  • Loading branch information
aviatesk authored Nov 25, 2022
1 parent d0a211a commit 039d8fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ The following `setting`s are supported.
- `:notaskstate`
- `:inaccessiblememonly`
- `:foldable`
- `:removable`
- `:total`
# Extended help
Expand Down Expand Up @@ -596,7 +597,6 @@ global state or mutable memory pointed to by its arguments.
This setting is a convenient shortcut for the set of effects that the compiler
requires to be guaranteed to constant fold a call at compile time. It is
currently equivalent to the following `setting`s:
- `:consistent`
- `:effect_free`
- `:terminates_globally`
Expand All @@ -607,6 +607,16 @@ currently equivalent to the following `setting`s:
however, that by the `:consistent`-cy requirements, any such annotated call
must consistently throw given the same argument values.
---
## `:removable`
This setting is a convenient shortcut for the set of effects that the compiler
requires to be guaranteed to delete a call whose result is unused at compile time.
It is currently equivalent to the following `setting`s:
- `:effect_free`
- `:nothrow`
- `:terminates_globally`
---
## `:total`
Expand Down Expand Up @@ -666,6 +676,8 @@ macro assume_effects(args...)
inaccessiblememonly = val
elseif setting === :foldable
consistent = effect_free = terminates_globally = val
elseif setting === :removable
effect_free = nothrow = terminates_globally = val
elseif setting === :total
consistent = effect_free = nothrow = terminates_globally = notaskstate = inaccessiblememonly = val
else
Expand Down
8 changes: 8 additions & 0 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ Base.@assume_effects :foldable concrete_eval(
concrete_eval(getindex, ___CONST_DICT___, :a)
end

# :removable override
Base.@assume_effects :removable removable_call(
f, args...; kwargs...) = f(args...; kwargs...)
@test fully_eliminated() do
@noinline removable_call(getindex, ___CONST_DICT___, :a)
nothing
end

# terminates_globally override
# https://github.com/JuliaLang/julia/issues/41694
Base.@assume_effects :terminates_globally function issue41694(x)
Expand Down

0 comments on commit 039d8fd

Please sign in to comment.