Skip to content
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

Fix some Base.@propagate_inbounds annotations #155

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
26 changes: 13 additions & 13 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ abstract type AbstractFill{T, N, Axes} <: AbstractArray{T, N} end

==(a::AbstractFill, b::AbstractFill) = axes(a) == axes(b) && getindex_value(a) == getindex_value(b)

Base.@propagate_inbounds @inline function _fill_getindex(F::AbstractFill, kj::Integer...)
Base.@propagate_inbounds function _fill_getindex(F::AbstractFill, kj::Integer...)
@boundscheck checkbounds(F, kj...)
getindex_value(F)
end
Comment on lines +37 to 40
Copy link
Contributor

@mcabbott mcabbott Aug 15, 2021

Choose a reason for hiding this comment

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

Should this just be @inbounds? I thought that a function which deals with checkbounds need not propagate anything further, and only functions like getindex(F::AbstractFill, k::Integer) = _fill_getindex(F, k) need to do so. Like the example here:

https://docs.julialang.org/en/v1/devdocs/boundscheck/#Eliding-bounds-checks

(But 5 mins of trying to @eval things to test didn't tell me anything, so I am not 100% sure.)


getindex(F::AbstractFill, k::Integer) = _fill_getindex(F, k)
getindex(F::AbstractFill{T, N}, kj::Vararg{<:Integer, N}) where {T, N} = _fill_getindex(F, kj...)
Base.@propagate_inbounds getindex(F::AbstractFill, k::Integer) = _fill_getindex(F, k)
Base.@propagate_inbounds getindex(F::AbstractFill{T, N}, kj::Vararg{<:Integer, N}) where {T, N} = _fill_getindex(F, kj...)

@inline function setindex!(F::AbstractFill, v, k::Integer)
Base.@propagate_inbounds function setindex!(F::AbstractFill, v, k::Integer)
@boundscheck checkbounds(F, k)
v == getindex_value(F) || throw(ArgumentError("Cannot setindex! to $v for an AbstractFill with value $(getindex_value(F))."))
F
end

@inline function setindex!(F::AbstractFill{T, N}, v, kj::Vararg{<:Integer, N}) where {T, N}
Base.@propagate_inbounds function setindex!(F::AbstractFill{T, N}, v, kj::Vararg{<:Integer, N}) where {T, N}
@boundscheck checkbounds(F, kj...)
v == getindex_value(F) || throw(ArgumentError("Cannot setindex! to $v for an AbstractFill with value $(getindex_value(F))."))
F
Expand Down Expand Up @@ -163,26 +163,26 @@ convert(::Type{T}, F::T) where T<:Fill = F



getindex(F::Fill{<:Any,0}) = getindex_value(F)
Base.@propagate_inbounds getindex(F::Fill{<:Any,0}) = getindex_value(F)

Base.@propagate_inbounds @inline function _fill_getindex(A::AbstractFill, I::Vararg{Union{Real, AbstractArray}, N}) where N
Base.@propagate_inbounds function _fill_getindex(A::AbstractFill, I::Vararg{Union{Real, AbstractArray}, N}) where N
@boundscheck checkbounds(A, I...)
shape = Base.index_shape(I...)
fillsimilar(A, shape)
end

Base.@propagate_inbounds @inline function _fill_getindex(A::AbstractFill, kr::AbstractArray{Bool})
Base.@propagate_inbounds function _fill_getindex(A::AbstractFill, kr::AbstractArray{Bool})
@boundscheck checkbounds(A, kr)
fillsimilar(A, count(kr))
end

Base.@propagate_inbounds @inline Base._unsafe_getindex(::IndexStyle, F::AbstractFill, I::Vararg{Union{Real, AbstractArray}, N}) where N =
Base._unsafe_getindex(::IndexStyle, F::AbstractFill, I::Vararg{Union{Real, AbstractArray}, N}) where N =
@inbounds(return _fill_getindex(F, I...))



getindex(A::AbstractFill, kr::AbstractVector{Bool}) = _fill_getindex(A, kr)
getindex(A::AbstractFill, kr::AbstractArray{Bool}) = _fill_getindex(A, kr)
Base.@propagate_inbounds getindex(A::AbstractFill, kr::AbstractVector{Bool}) = _fill_getindex(A, kr)
Base.@propagate_inbounds getindex(A::AbstractFill, kr::AbstractArray{Bool}) = _fill_getindex(A, kr)

sort(a::AbstractFill; kwds...) = a
sort!(a::AbstractFill; kwds...) = a
Expand Down Expand Up @@ -329,7 +329,7 @@ axes(T::AbstractTriangular{<:Any,<:AbstractFill}) = axes(parent(T))
axes(rd::RectDiagonal) = rd.axes
size(rd::RectDiagonal) = length.(rd.axes)

@inline function getindex(rd::RectDiagonal{T}, i::Integer, j::Integer) where T
Base.@propagate_inbounds function getindex(rd::RectDiagonal{T}, i::Integer, j::Integer) where T
@boundscheck checkbounds(rd, i, j)
if i == j
@inbounds r = rd.diag[i]
Expand All @@ -339,7 +339,7 @@ size(rd::RectDiagonal) = length.(rd.axes)
return r
end

function setindex!(rd::RectDiagonal, v, i::Integer, j::Integer)
Base.@propagate_inbounds function setindex!(rd::RectDiagonal, v, i::Integer, j::Integer)
@boundscheck checkbounds(rd, i, j)
if i == j
@inbounds rd.diag[i] = v
Expand Down