From 4e40962b4c4951e05033c2ee3722ef1647091c02 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sun, 14 Sep 2025 23:17:02 +0200 Subject: [PATCH] `ReadOnly`: slightly restrict the dispatch on the `setindex!` method Stricten up `Vararg{Any}` to `Vararg{Integer}`. The stricter dispatch still satisfies the `AbstractArray` interface, for both cases of `IndexStyle`. The benefit is that `Integer` excludes some common types, such as `CartesianIndex`. As a result, loading SparseArrays causes only $24$ invalidations in the sysimage after this change, as opposed to $26$ before this change. --- src/readonly.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/readonly.jl b/src/readonly.jl index 00eacc3c..8031b91a 100644 --- a/src/readonly.jl +++ b/src/readonly.jl @@ -22,7 +22,7 @@ end Base.unsafe_convert(x::Type{Ptr{T}}, A::ReadOnly) where T = Base.unsafe_convert(x, parent(A)) Base.elsize(::Type{ReadOnly{T,N,V}}) where {T,N,V} = Base.elsize(V) -Base.@propagate_inbounds @inline Base.setindex!(x::ReadOnly, v, ind...) = if v == getindex(parent(x), ind...) +Base.@propagate_inbounds @inline Base.setindex!(x::ReadOnly, v, ind::Vararg{Integer}) = if v == getindex(parent(x), ind...) v else error("Can't change $(typeof(x)).")