Skip to content

Commit

Permalink
Mark typeintersect pure for Julia 1.9 (#1156)
Browse files Browse the repository at this point in the history
* Mark typeintersect pure for Julia 1.9+

* add tests

* fix typo

* bump version

* run CI on Julia v1.9 (including pre-releases)

---------

Co-authored-by: Hendrik Ranocha <[email protected]>
  • Loading branch information
vchuravy and ranocha committed Apr 27, 2023
1 parent 2f50491 commit ed92217
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
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

2 comments on commit ed92217

@mateuszbaran
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/82472

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.5.22 -m "<description of version>" ed92217f94e2d70847bcf2b7716f47a410d52d25
git push origin v1.5.22

Please sign in to comment.