diff --git a/src/Static.jl b/src/Static.jl index 82ab248..4a79800 100644 --- a/src/Static.jl +++ b/src/Static.jl @@ -3,7 +3,7 @@ module Static import IfElse: ifelse export StaticInt, StaticFloat64, StaticSymbol, True, False, StaticBool, NDIndex -export dynamic, is_static, known, static, static_promote +export dynamic, is_static, known, static, static_promote, static_! """ StaticSymbol @@ -315,7 +315,6 @@ Base.inv(x::StaticNumber{N}) where {N} = one(x) / x @inline Base.iseven(@nospecialize x::StaticNumber) = iseven(known(x)) @inline Base.isodd(@nospecialize x::StaticNumber) = isodd(known(x)) - Base.AbstractFloat(x::StaticNumber) = StaticFloat64(x) Base.abs(::StaticNumber{N}) where {N} = static(abs(N)) @@ -423,8 +422,13 @@ Base.xor(::StaticInteger{X}, ::StaticInteger{Y}) where {X, Y} = static(xor(X, Y) Base.xor(::StaticInteger{X}, y::Union{Integer, Missing}) where {X} = xor(X, y) Base.xor(x::Union{Integer, Missing}, ::StaticInteger{Y}) where {Y} = xor(x, Y) -Base.:(!)(::True) = False() -Base.:(!)(::False) = True() +# These are heavily invalidating, leading to major compile time increases downstream +#Base.:(!)(::True) = False() +#Base.:(!)(::False) = True() +# Instead, use the not invalidating form +static_!(x::Bool) = !x +static_!(::True) = False() +static_!(::False) = True() Base.all(::Tuple{Vararg{True}}) = true Base.all(::Tuple{Vararg{Union{True, False}}}) = false @@ -745,7 +749,7 @@ end """ eq(x, y) -Equivalent to `!=` but if `x` and `y` are both static returns a `StaticBool. +Equivalent to `!=` but if `x` and `y` are both static returns a `StaticBool`. """ eq(x::X, y::Y) where {X, Y} = ifelse(is_static(X) & is_static(Y), static, identity)(x == y) eq(x) = Base.Fix2(eq, x) @@ -753,15 +757,15 @@ eq(x) = Base.Fix2(eq, x) """ ne(x, y) -Equivalent to `!=` but if `x` and `y` are both static returns a `StaticBool. +Equivalent to `!=` but if `x` and `y` are both static returns a `StaticBool`. """ -ne(x::X, y::Y) where {X, Y} = !eq(x, y) +ne(x::X, y::Y) where {X, Y} = ifelse(is_static(X) & is_static(Y), static, identity)(x != y) ne(x) = Base.Fix2(ne, x) """ gt(x, y) -Equivalent to `>` but if `x` and `y` are both static returns a `StaticBool. +Equivalent to `>` but if `x` and `y` are both static returns a `StaticBool`. """ gt(x::X, y::Y) where {X, Y} = ifelse(is_static(X) & is_static(Y), static, identity)(x > y) gt(x) = Base.Fix2(gt, x) @@ -769,7 +773,7 @@ gt(x) = Base.Fix2(gt, x) """ ge(x, y) -Equivalent to `>=` but if `x` and `y` are both static returns a `StaticBool. +Equivalent to `>=` but if `x` and `y` are both static returns a `StaticBool`. """ ge(x::X, y::Y) where {X, Y} = ifelse(is_static(X) & is_static(Y), static, identity)(x >= y) ge(x) = Base.Fix2(ge, x) @@ -777,7 +781,7 @@ ge(x) = Base.Fix2(ge, x) """ le(x, y) -Equivalent to `<=` but if `x` and `y` are both static returns a `StaticBool. +Equivalent to `<=` but if `x` and `y` are both static returns a `StaticBool`. """ le(x::X, y::Y) where {X, Y} = ifelse(is_static(X) & is_static(Y), static, identity)(x <= y) le(x) = Base.Fix2(le, x) @@ -785,7 +789,7 @@ le(x) = Base.Fix2(le, x) """ lt(x, y) -Equivalent to `<` but if `x` and `y` are both static returns a `StaticBool. +Equivalent to `<` but if `x` and `y` are both static returns a `StaticBool`. """ lt(x::X, y::Y) where {X, Y} = ifelse(is_static(X) & is_static(Y), static, identity)(x < y) lt(x) = Base.Fix2(lt, x) diff --git a/test/runtests.jl b/test/runtests.jl index 502ee35..4a52ced 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -117,8 +117,6 @@ end @test @inferred(~t) === f @test @inferred(~f) === t - @test @inferred(!t) === f - @test @inferred(!f) === t @test @inferred(+t) === StaticInt(1) @test @inferred(+f) === StaticInt(0) @test @inferred(-t) === StaticInt(-1)