|
1 | 1 | module StaticArraysCore |
2 | 2 |
|
| 3 | +macro assume_foldable(ex) |
| 4 | + if VERSION ≥ v"1.8.0-rc2" # cf. https://github.com/JuliaLang/julia/pull/45534 |
| 5 | + return :(Base.@assume_effects :foldable $ex) |
| 6 | + else |
| 7 | + return :(Base.@pure $ex) |
| 8 | + end |
| 9 | +end |
3 | 10 |
|
4 | 11 | """ |
5 | 12 | abstract type StaticArray{S, T, N} <: AbstractArray{T, N} end |
@@ -39,19 +46,19 @@ const StaticVecOrMat{T} = Union{StaticVector{<:Any, T}, StaticMatrix{<:Any, <:An |
39 | 46 | # The ::Tuple variants exist to make sure that anything that calls with a tuple |
40 | 47 | # instead of a Tuple gets through to the constructor, so the user gets a nice |
41 | 48 | # error message |
42 | | -Base.@pure tuple_length(T::Type{<:Tuple}) = length(T.parameters) |
43 | | -Base.@pure tuple_length(T::Tuple) = length(T) |
44 | | -Base.@pure tuple_prod(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 1 : *(T.parameters...) |
45 | | -Base.@pure tuple_prod(T::Tuple) = prod(T) |
46 | | -Base.@pure tuple_minimum(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 0 : minimum(tuple(T.parameters...)) |
47 | | -Base.@pure tuple_minimum(T::Tuple) = minimum(T) |
| 49 | +@assume_foldable tuple_length(T::Type{<:Tuple}) = length(T.parameters) |
| 50 | +@assume_foldable tuple_length(T::Tuple) = length(T) |
| 51 | +@assume_foldable tuple_prod(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 1 : *(T.parameters...) |
| 52 | +@assume_foldable tuple_prod(T::Tuple) = prod(T) |
| 53 | +@assume_foldable tuple_minimum(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 0 : minimum(tuple(T.parameters...)) |
| 54 | +@assume_foldable tuple_minimum(T::Tuple) = minimum(T) |
48 | 55 |
|
49 | 56 | """ |
50 | 57 | size_to_tuple(::Type{S}) where S<:Tuple |
51 | 58 |
|
52 | 59 | Converts a size given by `Tuple{N, M, ...}` into a tuple `(N, M, ...)`. |
53 | 60 | """ |
54 | | -Base.@pure function size_to_tuple(::Type{S}) where S<:Tuple |
| 61 | +@assume_foldable function size_to_tuple(::Type{S}) where S<:Tuple |
55 | 62 | return tuple(S.parameters...) |
56 | 63 | end |
57 | 64 |
|
|
0 commit comments