Skip to content

Commit d107ae9

Browse files
committed
use package extensions
1 parent abe0ca6 commit d107ae9

8 files changed

+49
-26
lines changed

Project.toml

+11
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,15 @@ LinearAlgebra = "<0.0.1, 1.2"
1717
Random = "<0.0.1, 1.2"
1818
Requires = "0.5, 1"
1919
SparseArrays = "<0.0.1, 1.2"
20+
StaticArrays = "1"
2021
julia = "1.2"
22+
23+
[extensions]
24+
StaticArraysExt = "StaticArrays"
25+
26+
[extras]
27+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
28+
29+
[weakdeps]
30+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
31+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

ext/StaticArraysExt.jl

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module StaticArraysExt
2+
3+
using ReachabilityBase.Arrays
4+
5+
@static if isdefined(Base, :get_extension)
6+
import StaticArrays
7+
else
8+
import ..StaticArrays
9+
end
10+
11+
# represent the projection matrix with a static array
12+
function Arrays.projection_matrix(block::AbstractVector{Int}, n::Int,
13+
::Type{<:StaticArrays.SVector{L,N}}) where {L,N}
14+
mat = projection_matrix(block, n, N)
15+
m = size(mat, 1)
16+
return StaticArrays.SMatrix{m,n}(mat)
17+
end
18+
19+
Arrays.similar_type(x::StaticArrays.StaticArray) = StaticArrays.similar_type(x)
20+
21+
end # module

src/Arrays/Arrays.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This module provides machinery for vectors and matrices.
55
"""
66
module Arrays
77

8-
using LinearAlgebra, Requires, SparseArrays
8+
using LinearAlgebra, SparseArrays
99
import LinearAlgebra: rank
1010

1111
using Random: AbstractRNG, GLOBAL_RNG

src/Arrays/init.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
function __init__()
2-
@require StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" include("init_StaticArrays.jl")
1+
@static if !isdefined(Base, :get_extension)
2+
using Requires
3+
end
4+
5+
@static if !isdefined(Base, :get_extension)
6+
function __init__()
7+
@require StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" include("../../ext/StaticArraysExt.jl")
8+
end
39
end

src/Arrays/init_StaticArrays.jl

-4
This file was deleted.

src/Arrays/matrix_operations.jl

-12
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,6 @@ function projection_matrix(block::AbstractVector{Int}, n::Int,
279279
return projection_matrix(block, n, N)
280280
end
281281

282-
function load_projection_matrix_static()
283-
return quote
284-
# represent the projection matrix with a static array
285-
function projection_matrix(block::AbstractVector{Int}, n::Int,
286-
VN::Type{<:SVector{L,N}}) where {L,N}
287-
mat = projection_matrix(block, n, N)
288-
m = size(mat, 1)
289-
return SMatrix{m,n}(mat)
290-
end
291-
end # quote
292-
end # end load_projection_matrix_static
293-
294282
"""
295283
remove_zero_columns(A::AbstractMatrix)
296284

src/Arrays/matrix_vector_operations.jl

-6
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,3 @@ end
141141

142142
# no-op
143143
similar_type(x::AbstractVector) = typeof(x)
144-
145-
function load_copy_finalize_static()
146-
return quote
147-
similar_type(x::StaticArrays.StaticArray) = StaticArrays.similar_type(x)
148-
end # quote
149-
end # end load_copy_finalize_static

test/Aqua.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@ using ReachabilityBase, Test
22
import Aqua
33

44
@testset "Aqua tests" begin
5-
Aqua.test_all(ReachabilityBase)
5+
# Requires is only used in old versions
6+
@static if VERSION >= v"1.9"
7+
stale_deps = (ignore=[:Requires],)
8+
else
9+
stale_deps = true
10+
end
11+
12+
Aqua.test_all(ReachabilityBase; stale_deps=stale_deps)
613
end

0 commit comments

Comments
 (0)