You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
replace @pure annotations in Base with effect settings
This commit replaces `@pure`/`@_pure_meta` annotations used in `Base`
with corresponding effect settings (`:total` or `:total_or_throw`).
The concrete evaluation mechanism based on the effect system (#43852)
has the following benefits over the `@pure`-based optimization:
- it can fold cases when consistent exception is thrown
- it can handle constant union-split situation as well
- effects can be propagated inter-procedurally
While revisiting the existing annotations, I removed some unnecessary ones
and also added some more hopefully new annotations (mostly for reflection utilities).
In theory this should give us some performance benefits, e.g. now we
can concrete-evaluate union-spit `typeintersect`:
```julia
@test Base.return_types((Union{Int,Nothing},)) do x
typeintersect(String, typeof(x))
end |> only === Type{Union{}}
```
Though this commit ends up bigger than I expected -- we should carefully
check a benchmark result so that it doesn't come with any regressions.
Complex{T}(x::AbstractIrrational) where {T<:Real} =Complex{T}(T(x))
50
50
51
-
@purefunctionRational{T}(x::AbstractIrrational) where T<:Integer
51
+
#XXX this may change `DEFAULT_PRECISION`, thus not effect free
52
+
@assume_effects:totalfunctionRational{T}(x::AbstractIrrational) where T<:Integer
52
53
o =precision(BigFloat)
53
54
p =256
54
55
whiletrue
@@ -64,7 +65,7 @@ Complex{T}(x::AbstractIrrational) where {T<:Real} = Complex{T}(T(x))
64
65
end
65
66
Rational{BigInt}(x::AbstractIrrational) =throw(ArgumentError("Cannot convert an AbstractIrrational to a Rational{BigInt}: use rationalize(BigInt, x) instead"))
66
67
67
-
@purefunction (t::Type{T})(x::AbstractIrrational, r::RoundingMode) where T<:Union{Float32,Float64}
68
+
@assume_effects:totalfunction (t::Type{T})(x::AbstractIrrational, r::RoundingMode) where T<:Union{Float32,Float64}
68
69
setprecision(BigFloat, 256) do
69
70
T(BigFloat(x)::BigFloat, r)
70
71
end
@@ -106,11 +107,11 @@ end
106
107
<=(x::AbstractFloat, y::AbstractIrrational) = x < y
107
108
108
109
# Irrational vs Rational
109
-
@purefunctionrationalize(::Type{T}, x::AbstractIrrational; tol::Real=0) where T
110
+
@assume_effects:totalfunctionrationalize(::Type{T}, x::AbstractIrrational; tol::Real=0) where T
0 commit comments