Skip to content

Commit 192f3bf

Browse files
committed
add new :total_or_throw utility setting for @assume_effects
This setting is particularly useful since it allows the compiler to evaluate a call of the applied method when all the call arguments are fully known, no matter if the call results in an error or not.
1 parent 4751165 commit 192f3bf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

base/expr.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,20 @@ and is a convenient shortcut.
517517
distinction that the `:consistent`-cy requirement applies world-age wise rather
518518
than globally as described above. However, in particular, a method annotated
519519
`@Base.pure` is always `:total`.
520+
521+
---
522+
# `:total_or_throw`
523+
524+
This `setting` combines the following other assertions:
525+
- `:consistent`
526+
- `:effect_free`
527+
- `:terminates_globally`
528+
and is a convenient shortcut.
529+
530+
!!! note
531+
This setting is particularly useful since it allows the compiler to evaluate a call of
532+
the applied method when all the call arguments are fully known, no matter if the call
533+
results in an error or not.
520534
"""
521535
macro assume_effects(args...)
522536
(consistent, effect_free, nothrow, terminates_globally, terminates_locally) =
@@ -537,12 +551,14 @@ macro assume_effects(args...)
537551
terminates_locally = true
538552
elseif setting === :total
539553
consistent = effect_free = nothrow = terminates_globally = true
554+
elseif setting === :total_or_throw
555+
consistent = effect_free = terminates_globally = true
540556
else
541557
throw(ArgumentError("@assume_effects $setting not supported"))
542558
end
543559
end
544560
ex = args[end]
545-
isa(ex, Expr) || throw(ArgumentError("Bad expression `$ex` in @constprop [settings] ex"))
561+
isa(ex, Expr) || throw(ArgumentError("Bad expression `$ex` in `@assume_effects [settings] ex`"))
546562
if ex.head === :macrocall && ex.args[1] == Symbol("@ccall")
547563
ex.args[1] = GlobalRef(Base, Symbol("@ccall_effects"))
548564
insert!(ex.args, 3, Core.Compiler.encode_effects_override(Core.Compiler.EffectsOverride(

test/compiler/inline.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ recur_termination22(x) = x * recur_termination21(x-1)
10891089
end
10901090

10911091
const ___CONST_DICT___ = Dict{Any,Any}(:a => 1, :b => 2)
1092-
Base.@assume_effects :consistent :effect_free :terminates_globally consteval(
1092+
Base.@assume_effects :total_or_throw consteval(
10931093
f, args...; kwargs...) = f(args...; kwargs...)
10941094
@test fully_eliminated() do
10951095
consteval(getindex, ___CONST_DICT___, :a)

0 commit comments

Comments
 (0)