Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

effects: add :removable convenient setting for Base.@assume_effects #47700

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
removable_call(getindex, ___CONST_DICT___, :a)
aviatesk marked this conversation as resolved.
Show resolved Hide resolved
nothing
end

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