Skip to content

Mark typeintersect pure for Julia 1.9 #1156

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

Merged
merged 7 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
version:
- '1.6'
- '~1.9.0-0'
- '1'
- 'nightly'
os:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StaticArrays"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.5.21"
version = "1.5.22"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
4 changes: 2 additions & 2 deletions src/arraymath.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inline zeros(::Type{SA}) where {SA <: StaticArray{<:Tuple}} = zeros(Base.typeintersect(SA, AbstractArray{Float64}))
@inline zeros(::Type{SA}) where {SA <: StaticArray{<:Tuple}} = zeros(typeintersect(SA, AbstractArray{Float64}))
@inline zeros(::Type{SA}) where {SA <: StaticArray{<:Tuple, T}} where T = _zeros(Size(SA), SA)
@generated function _zeros(::Size{s}, ::Type{SA}) where {s, SA <: StaticArray}
T = eltype(SA)
Expand All @@ -16,7 +16,7 @@
end
end

@inline ones(::Type{SA}) where {SA <: StaticArray{<:Tuple}} = ones(Base.typeintersect(SA, AbstractArray{Float64}))
@inline ones(::Type{SA}) where {SA <: StaticArray{<:Tuple}} = ones(typeintersect(SA, AbstractArray{Float64}))
@inline ones(::Type{SA}) where {SA <: StaticArray{<:Tuple, T}} where T = _ones(Size(SA), SA)
@generated function _ones(::Size{s}, ::Type{SA}) where {s, SA <: StaticArray}
T = eltype(SA)
Expand Down
4 changes: 2 additions & 2 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function adapt_size(::Type{SA}, x) where {SA<:StaticArray}
_no_precise_size(SA, x)
end
end
SA′ = Base.typeintersect(SA, StaticArrayNoEltype{SZ,tuple_length(SZ)})
SA′ = typeintersect(SA, StaticArrayNoEltype{SZ,tuple_length(SZ)})
SA′ === Union{} && _no_precise_size(SA, x)
return SA′
end
Expand All @@ -139,7 +139,7 @@ function adapt_eltype(::Type{SA}, x) where {SA<:StaticArray}
else
eltype(x)
end
return Base.typeintersect(SA, AbstractArray{T})
return typeintersect(SA, AbstractArray{T})
end

need_rewrap(::Type{<:StaticArray}, x) = false
Expand Down
8 changes: 7 additions & 1 deletion src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ else
const var"@_inline_meta" = Base.var"@inline"
end

# Julia 1.9 removed the `@pure` annotation in favor of Concrete-Eval
# This behaves unfavorable with `julia --check-bounds=no`
Base.@pure function typeintersect(@nospecialize(a),@nospecialize(b))
Base.typeintersect(a,b)
end

# For convenience
TupleN{T,N} = NTuple{N,T}

Expand All @@ -13,7 +19,7 @@ TupleN{T,N} = NTuple{N,T}

# Base gives up on tuples for promote_eltype... (TODO can we improve Base?)
_TupleOf{T} = Tuple{T,Vararg{T}}
promote_tuple_eltype(::Union{_TupleOf{T}, Type{<:_TupleOf{T}}}) where {T} = T
promote_tuple_eltype(::Union{_TupleOf{T}, Type{<:_TupleOf{T}}}) where {T} = T
@generated function promote_tuple_eltype(::Union{T,Type{T}}) where T <: Tuple
t = Union{}
for i = 1:length(T.parameters)
Expand Down
16 changes: 16 additions & 0 deletions test/check_bounds_no.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module TestCheckBoundsNo

using Test
using StaticArrays

# https://github.com/JuliaArrays/StaticArrays.jl/issues/1155
@testset "Issue #1155" begin
u = @inferred(SVector(1, 2))
v = @inferred(SVector(3.0, 4.0))
a = 1.0
b = 2
result = @inferred(a * u + b * v)
@test result ≈ @inferred(SVector(7, 10))
end

end # module
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ if TEST_GROUP ∈ ["", "all", "group-A"]
addtests("inv.jl")
addtests("pinv.jl")
addtests("solve.jl")

# special logic required since we need to start a new
# Julia process for these tests
if isempty(enabled_tests) || "check_bounds_no" in enabled_tests
Random.seed!(42)
run(`$(Base.julia_cmd()) --check-bounds=no $(abspath("check_bounds_no.jl"))`)
end
end

if TEST_GROUP ∈ ["", "all", "group-B"]
Expand Down