From ed92217f94e2d70847bcf2b7716f47a410d52d25 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 27 Apr 2023 15:41:15 -0400 Subject: [PATCH] Mark typeintersect pure for Julia 1.9 (#1156) * 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 --- .github/workflows/ci.yml | 1 + Project.toml | 2 +- src/arraymath.jl | 4 ++-- src/convert.jl | 4 ++-- src/util.jl | 8 +++++++- test/check_bounds_no.jl | 16 ++++++++++++++++ test/runtests.jl | 7 +++++++ 7 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 test/check_bounds_no.jl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68f665bc..84450068 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,7 @@ jobs: matrix: version: - '1.6' + - '~1.9.0-0' - '1' - 'nightly' os: diff --git a/Project.toml b/Project.toml index f63c46ad..f94daf9e 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/arraymath.jl b/src/arraymath.jl index 4410e3d1..8d9d75a3 100644 --- a/src/arraymath.jl +++ b/src/arraymath.jl @@ -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) @@ -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) diff --git a/src/convert.jl b/src/convert.jl index c81361be..bcf5a817 100644 --- a/src/convert.jl +++ b/src/convert.jl @@ -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 @@ -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 diff --git a/src/util.jl b/src/util.jl index 725ac0cc..6079c36d 100644 --- a/src/util.jl +++ b/src/util.jl @@ -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} @@ -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) diff --git a/test/check_bounds_no.jl b/test/check_bounds_no.jl new file mode 100644 index 00000000..592fe10f --- /dev/null +++ b/test/check_bounds_no.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index a705cc5d..68aac8d6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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"]