Skip to content

Commit 9984b8e

Browse files
authored
Add effect annotations (#41)
* Add effect annotations * Update Project.toml
1 parent cde03bb commit 9984b8e

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "IrrationalConstants"
22
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
33
authors = ["JuliaMath"]
4-
version = "0.2.3"
4+
version = "0.2.4"
55

66
[compat]
77
julia = "1"

src/macro.jl

+27
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,32 @@ function irrational(sym::Symbol, val::Union{Float64,Expr}, def::Union{Symbol,Exp
135135
@assert isa(big($esym), BigFloat)
136136
@assert Float64($esym) == Float64(big($esym))
137137
@assert Float32($esym) == Float32(big($esym))
138+
139+
# https://github.com/JuliaLang/julia/pull/55886 removed these effects for generic `AbstractIrrational` subtypes
140+
@static if isdefined(Base, :_throw_argument_error_irrational_to_rational_bigint)
141+
function Base.Rational{$BigInt}(::$eT)
142+
Base._throw_argument_error_irrational_to_rational_bigint()
143+
end
144+
end
145+
@static if isdefined(Base, :_irrational_to_rational)
146+
Base.@assume_effects :foldable function Base.Rational{T}(x::$eT) where {T<:Integer}
147+
Base._irrational_to_rational(T, x)
148+
end
149+
end
150+
@static if isdefined(Base, :_irrational_to_float)
151+
Base.@assume_effects :foldable function (::Type{T})(x::$eT, r::RoundingMode) where {T<:Union{Float32,Float64}}
152+
Base._irrational_to_float(T, x, r)
153+
end
154+
end
155+
@static if isdefined(Base, :_rationalize_irrational)
156+
Base.@assume_effects :foldable function Base.rationalize(::Type{T}, x::$eT; tol::Real=0) where {T<:Integer}
157+
Base._rationalize_irrational(T, x, tol)
158+
end
159+
end
160+
@static if isdefined(Base, :_lessrational)
161+
Base.@assume_effects :foldable function Base.lessrational(rx::Rational, x::$eT)
162+
Base._lessrational(rx, x)
163+
end
164+
end
138165
end
139166
end

test/runtests.jl

+5
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,8 @@ end
255255
)
256256
end
257257
end
258+
259+
# issues #37 and #40
260+
@testset "slow comparisons" begin
261+
@test iszero(@allocated(3.0 <= invsqrt2))
262+
end

0 commit comments

Comments
 (0)