Skip to content

rename Base.@assume_effects :total_may_throw setting to :foldable #45534

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

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ julia> code_typed() do
1 ─ return 479001600
) => Int64

julia> Base.@assume_effects :total_may_throw @ccall jl_type_intersection(Vector{Int}::Any, Vector{<:Integer}::Any)::Any
julia> Base.@assume_effects :foldable @ccall jl_type_intersection(Vector{Int}::Any, Vector{<:Integer}::Any)::Any
Vector{Int64} (alias for Array{Int64, 1})
```

Expand Down Expand Up @@ -541,7 +541,7 @@ This `setting` combines the following other assertions:
and is a convenient shortcut.

---
# `:total_may_throw`
# `:foldable`

This `setting` combines the following other assertions:
- `:consistent`
Expand All @@ -554,10 +554,10 @@ and is a convenient shortcut.
the applied method when all the call arguments are fully known to be constant, no matter
if the call results in an error or not.

`@assume_effects :total_may_throw` is similar to [`@pure`](@ref) with the primary
`@assume_effects :foldable` is similar to [`@pure`](@ref) with the primary
distinction that the `:consistent`-cy requirement applies world-age wise rather
than globally as described above. However, in particular, a method annotated
`@pure` should always be `:total` or `:total_may_throw`.
`@pure` should always be `:total` or `:foldable`.
Another advantage is that effects introduced by `@assume_effects` are propagated to
callers interprocedurally while a purity defined by `@pure` is not.
"""
Expand All @@ -580,7 +580,7 @@ macro assume_effects(args...)
terminates_locally = true
elseif setting === :total
consistent = effect_free = nothrow = terminates_globally = true
elseif setting === :total_may_throw
elseif setting === :foldable
consistent = effect_free = terminates_globally = true
else
throw(ArgumentError("@assume_effects $setting not supported"))
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4079,7 +4079,7 @@ const CONST_DICT = let d = Dict()
end
d
end
Base.@assume_effects :total_may_throw getcharid(c) = CONST_DICT[c]
Base.@assume_effects :foldable getcharid(c) = CONST_DICT[c]
@noinline callf(f, args...) = f(args...)
function entry_to_be_invalidated(c)
return callf(getcharid, c)
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ recur_termination22(x) = x * recur_termination21(x-1)
end

const ___CONST_DICT___ = Dict{Any,Any}(Symbol(c) => i for (i, c) in enumerate('a':'z'))
Base.@assume_effects :total_may_throw concrete_eval(
Base.@assume_effects :foldable concrete_eval(
f, args...; kwargs...) = f(args...; kwargs...)
@test fully_eliminated() do
concrete_eval(getindex, ___CONST_DICT___, :a)
Expand Down