Skip to content

Commit c6f2b5f

Browse files
authored
Merge pull request #564 from YingboMa/inbounds
Use `propagate_inbounds` to ensure bounds check elision
2 parents da4a1ed + cd6c2ea commit c6f2b5f

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

src/MArray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ end
122122
v.data[i]
123123
end
124124

125-
@inline function setindex!(v::MArray, val, i::Int)
125+
@propagate_inbounds function setindex!(v::MArray, val, i::Int)
126126
@boundscheck checkbounds(v,i)
127127
T = eltype(v)
128128

src/SOneTo.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ Base.axes(s::SOneTo) = (s,)
1919
Base.size(s::SOneTo) = (length(s),)
2020
Base.length(s::SOneTo{n}) where {n} = n
2121

22-
function Base.getindex(s::SOneTo, i::Int)
22+
@propagate_inbounds function Base.getindex(s::SOneTo, i::Int)
2323
@boundscheck checkbounds(s, i)
2424
return i
2525
end
26-
function Base.getindex(s::SOneTo, s2::SOneTo)
26+
@propagate_inbounds function Base.getindex(s::SOneTo, s2::SOneTo)
2727
@boundscheck checkbounds(s, s2)
2828
return s2
2929
end

src/Scalar.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ end
1515
@inline convert(::Type{SA}, sa::SA) where {SA <: Scalar} = sa
1616

1717
getindex(v::Scalar) = v.data[1]
18-
@inline function getindex(v::Scalar, i::Int)
18+
@propagate_inbounds function getindex(v::Scalar, i::Int)
1919
@boundscheck if i != 1
2020
error("Attempt to index Scalar at index $i")
2121
end

src/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ end
182182
end
183183

184184
return quote
185-
@_inline_meta
185+
@_propagate_inbounds_meta
186186
@boundscheck sizematch($(Size{newsize}()), dest) || throw(DimensionMismatch("array could not be broadcast to match destination"))
187187
@inbounds $(Expr(:block, exprs...))
188188
return dest

src/convert.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@inline (::Type{SA})(x...) where {SA <: StaticArray} = SA(x)
55
@inline (::Type{SA})(a::StaticArray) where {SA<:StaticArray} = SA(Tuple(a))
6-
@inline (::Type{SA})(a::AbstractArray) where {SA <: StaticArray} = convert(SA, a)
6+
@propagate_inbounds (::Type{SA})(a::AbstractArray) where {SA <: StaticArray} = convert(SA, a)
77

88
# this covers most conversions and "statically-sized reshapes"
99
@inline convert(::Type{SA}, sa::StaticArray) where {SA<:StaticArray} = SA(Tuple(sa))
@@ -17,7 +17,7 @@
1717
throw(DimensionMismatch("expected input array of length $(length(SA)), got length $(length(a))"))
1818
end
1919

20-
@inline function convert(::Type{SA}, a::AbstractArray) where {SA <: StaticArray}
20+
@propagate_inbounds function convert(::Type{SA}, a::AbstractArray) where {SA <: StaticArray}
2121
@boundscheck if length(a) != length(SA)
2222
dimension_mismatch_fail(SA, a)
2323
end

src/deque.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626
i == newlen ? :(ifelse($i == index, x, vec[$i-1])) :
2727
:(ifelse($i < index, vec[$i], ifelse($i == index, x, vec[$i-1])))) for i = 1:newlen]
2828
return quote
29-
@_inline_meta
29+
@_propagate_inbounds_meta
3030
@boundscheck if (index < 1 || index > $newlen)
3131
throw(BoundsError(vec, index))
3232
end
@@ -60,7 +60,7 @@ end
6060
newlen = s[1] - 1
6161
exprs = [:(ifelse($i < index, vec[$i], vec[$i+1])) for i = 1:newlen]
6262
return quote
63-
@_inline_meta
63+
@_propagate_inbounds_meta
6464
@boundscheck if (index < 1 || index > $(s[1]))
6565
throw(BoundsError(vec, index))
6666
end

src/indexing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ setindex!(a::StaticArray, value, i::Int) = error("setindex!(::$(typeof(a)), valu
99
# Note: all indexing behavior defaults to dense, linear indexing
1010

1111
@propagate_inbounds function getindex(a::StaticArray, inds::Int...)
12-
@boundscheck checkbounds(a, inds...)
12+
@boundscheck checkbounds(a, inds...)
1313
_getindex_scalar(Size(a), a, inds...)
1414
end
1515

@@ -31,7 +31,7 @@ end
3131
end
3232

3333
@propagate_inbounds function setindex!(a::StaticArray, value, inds::Int...)
34-
@boundscheck checkbounds(a, inds...)
34+
@boundscheck checkbounds(a, inds...)
3535
_setindex!_scalar(Size(a), a, value, inds...)
3636
end
3737

0 commit comments

Comments
 (0)