diff --git a/src/Static.jl b/src/Static.jl index a71379b..b7dbbef 100644 --- a/src/Static.jl +++ b/src/Static.jl @@ -7,9 +7,9 @@ export StaticInt, StaticFloat64, StaticSymbol, True, False, StaticBool, NDIndex export dynamic, is_static, known, static @static if VERSION >= v"1.7.0-DEV.421" - using Base: @aggressive_constprop + using Base: @constprop else - macro aggressive_constprop(ex) + macro constprop(_, ex) ex end end @@ -30,7 +30,7 @@ Returns the known value corresponding to a static type `T`. If `T` is not a stat See also: [`static`](@ref), [`is_static`](@ref) """ known -@aggressive_constprop known(x) = known(typeof(x)) +@constprop :aggressive known(x) = known(typeof(x)) known(::Type{T}) where {T} = nothing known(::Type{StaticInt{N}}) where {N} = N::Int known(::Type{StaticFloat64{N}}) where {N} = N::Float64 @@ -67,19 +67,19 @@ static(:x) ``` """ static -@aggressive_constprop static(x::X) where {X} = ifelse(is_static(X), identity, _no_static_type)(x) -@aggressive_constprop static(x::Int) = StaticInt(x) -@aggressive_constprop static(x::Union{Int8,UInt8,Int16,UInt16}) = StaticInt(x % Int) +@constprop :aggressive static(x::X) where {X} = ifelse(is_static(X), identity, _no_static_type)(x) +@constprop :aggressive static(x::Int) = StaticInt(x) +@constprop :aggressive static(x::Union{Int8,UInt8,Int16,UInt16}) = StaticInt(x % Int) @static if sizeof(Int) == 8 - @aggressive_constprop static(x::Union{Int32,UInt32}) = StaticInt(x % Int) - @aggressive_constprop static(x::UInt64) = StaticInt(Int(x)) + @constprop :aggressive static(x::Union{Int32,UInt32}) = StaticInt(x % Int) + @constprop :aggressive static(x::UInt64) = StaticInt(Int(x)) else - @aggressive_constprop static(x::UInt32) = StaticInt(Int(x)) + @constprop :aggressive static(x::UInt32) = StaticInt(Int(x)) end -@aggressive_constprop static(x::Float64) = StaticFloat64(x) -@aggressive_constprop static(x::Bool) = StaticBool(x) -@aggressive_constprop static(x::Symbol) = StaticSymbol(x) -@aggressive_constprop static(x::Tuple{Vararg{Any}}) = map(static, x) +@constprop :aggressive static(x::Float64) = StaticFloat64(x) +@constprop :aggressive static(x::Bool) = StaticBool(x) +@constprop :aggressive static(x::Symbol) = StaticSymbol(x) +@constprop :aggressive static(x::Tuple{Vararg{Any}}) = map(static, x) @generated static(::Val{V}) where {V} = static(V) function _no_static_type(@nospecialize(x)) error("There is no static alternative for type $(typeof(x)).") @@ -102,7 +102,7 @@ is_static(@nospecialize(x::Type{<:Val})) = True() is_static(@nospecialize(x::Type{<:StaticFloat64})) = True() is_static(x::Type{T}) where {T} = False() -@aggressive_constprop _tuple_static(::Type{T}, i) where {T} = is_static(_get_tuple(T, i)) +@constprop :aggressive _tuple_static(::Type{T}, i) where {T} = is_static(_get_tuple(T, i)) function is_static(::Type{T}) where {N,T<:Tuple{Vararg{Any,N}}} if all(eachop(_tuple_static, nstatic(Val(N)), T)) return True() @@ -119,7 +119,7 @@ Returns the "dynamic" or non-static form of `x`. dynamic(x::X) where {X} = _dynamic(is_static(X), x) _dynamic(::True, x::X) where {X} = known(X) _dynamic(::False, x::X) where {X} = x -@aggressive_constprop dynamic(x::Tuple) = map(dynamic, x) +@constprop :aggressive dynamic(x::Tuple) = map(dynamic, x) dynamic(x::NDIndex) = CartesianIndex(dynamic(Tuple(x))) end