Skip to content

Use @assume_effects instead of @pure for Julia >v1.8 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/StaticArraysCore.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module StaticArraysCore

macro assume_foldable(ex)
if VERSION ≥ v"1.8.0-rc2" # cf. https://github.com/JuliaLang/julia/pull/45534
return :(Base.@assume_effects :foldable $ex)
else
return :(Base.@pure $ex)
end
end

"""
abstract type StaticArray{S, T, N} <: AbstractArray{T, N} end
Expand Down Expand Up @@ -39,19 +46,19 @@ const StaticVecOrMat{T} = Union{StaticVector{<:Any, T}, StaticMatrix{<:Any, <:An
# The ::Tuple variants exist to make sure that anything that calls with a tuple
# instead of a Tuple gets through to the constructor, so the user gets a nice
# error message
Base.@pure tuple_length(T::Type{<:Tuple}) = length(T.parameters)
Base.@pure tuple_length(T::Tuple) = length(T)
Base.@pure tuple_prod(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 1 : *(T.parameters...)
Base.@pure tuple_prod(T::Tuple) = prod(T)
Base.@pure tuple_minimum(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 0 : minimum(tuple(T.parameters...))
Base.@pure tuple_minimum(T::Tuple) = minimum(T)
@assume_foldable tuple_length(T::Type{<:Tuple}) = length(T.parameters)
@assume_foldable tuple_length(T::Tuple) = length(T)
@assume_foldable tuple_prod(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 1 : *(T.parameters...)
@assume_foldable tuple_prod(T::Tuple) = prod(T)
@assume_foldable tuple_minimum(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 0 : minimum(tuple(T.parameters...))
@assume_foldable tuple_minimum(T::Tuple) = minimum(T)

"""
size_to_tuple(::Type{S}) where S<:Tuple

Converts a size given by `Tuple{N, M, ...}` into a tuple `(N, M, ...)`.
"""
Base.@pure function size_to_tuple(::Type{S}) where S<:Tuple
@assume_foldable function size_to_tuple(::Type{S}) where S<:Tuple
return tuple(S.parameters...)
end

Expand Down