Skip to content

Commit 12c77cc

Browse files
authored
Merge pull request #643 from pszufe/psz/inboundscheck
Add support for @inbounds via Base.@BoundsCheck in abstract array types
2 parents 13ac291 + f81dad9 commit 12c77cc

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

lib/DaggerWebDash/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1717
TimespanLogging = "a526e669-04d3-4846-9525-c66122c55f63"
1818

1919
[compat]
20-
Dagger = "0.16, 0.17, 0.18"
20+
Dagger = "0.16, 0.17, 0.18, 0.19"
2121
HTTP = "1.7"
2222
JSON3 = "1"
2323
MemPool = "0.3, 0.4"

src/array/indexing.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ Base.getindex(c::ArrayOp, idx...) =
3636
const GETINDEX_CACHE = TaskLocalValue{Dict{Tuple,Any}}(()->Dict{Tuple,Any}())
3737
const GETINDEX_CACHE_SIZE = ScopedValue{Int}(0)
3838
with_index_caching(f, size::Integer=1) = with(f, GETINDEX_CACHE_SIZE=>size)
39-
function Base.getindex(A::DArray{T,N}, idx::NTuple{N,Int}) where {T,N}
39+
@inline function Base.getindex(A::DArray{T,N}, idx::NTuple{N,Int}) where {T,N}
4040
# Scalar indexing check
4141
assert_allowscalar()
4242

4343
# Boundscheck
44-
checkbounds(A, idx...)
44+
Base.@boundscheck checkbounds(A, idx...)
4545

4646
# Find the associated partition and offset within it
4747
part_idx, offset_idx = partition_for(A, idx)
@@ -108,12 +108,12 @@ end
108108

109109
### setindex!
110110

111-
function Base.setindex!(A::DArray{T,N}, value, idx::NTuple{N,Int}) where {T,N}
111+
@inline function Base.setindex!(A::DArray{T,N}, value, idx::NTuple{N,Int}) where {T,N}
112112
# Scalar indexing check
113113
assert_allowscalar()
114114

115115
# Boundscheck
116-
checkbounds(A, idx...)
116+
Base.@boundscheck checkbounds(A, idx...)
117117

118118
# Find the associated partition and offset within it
119119
part_idx, offset_idx = partition_for(A, idx)

src/utils/haloarray.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function Base.copy(tile::HaloArray{T,N,H}) where {T,N,H}
4444
end
4545

4646
# Define getindex for HaloArray
47-
function Base.getindex(tile::HaloArray{T,N}, I::Vararg{Int,N}) where {T,N}
48-
checkbounds(tile, I...)
47+
@inline function Base.getindex(tile::HaloArray{T,N}, I::Vararg{Int,N}) where {T,N}
48+
Base.@boundscheck checkbounds(tile, I...)
4949
if all(1 .<= I .<= size(tile.center))
5050
return tile.center[I...]
5151
elseif !any(1 .<= I .<= size(tile.center))
@@ -69,8 +69,8 @@ function Base.getindex(tile::HaloArray{T,N}, I::Vararg{Int,N}) where {T,N}
6969
end
7070

7171
# Define setindex! for HaloArray
72-
function Base.setindex!(tile::HaloArray{T,N}, value, I::Vararg{Int,N}) where {T,N}
73-
checkbounds(tile, I...)
72+
@inline function Base.setindex!(tile::HaloArray{T,N}, value, I::Vararg{Int,N}) where {T,N}
73+
Base.@boundscheck checkbounds(tile, I...)
7474
if all(1 .<= I .<= size(tile.center))
7575
# Center
7676
return tile.center[I...] = value

src/utils/reuse.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ mutable struct ReusableLinkedList{T} <: AbstractVector{T}
208208
end
209209
end
210210
Base.eltype(list::ReusableLinkedList{T}) where T = T
211-
function Base.getindex(list::ReusableLinkedList{T}, idx::Integer) where T
212-
checkbounds(list, idx)
211+
@inline function Base.getindex(list::ReusableLinkedList{T}, idx::Integer) where T
212+
Base.@boundscheck checkbounds(list, idx)
213213
node = list.head
214214
for _ in 1:(idx-1)
215215
node === nothing && throw(BoundsError(list, idx))
@@ -218,8 +218,8 @@ function Base.getindex(list::ReusableLinkedList{T}, idx::Integer) where T
218218
node === nothing && throw(BoundsError(list, idx))
219219
return node.value
220220
end
221-
function Base.setindex!(list::ReusableLinkedList{T}, value::T, idx::Integer) where T
222-
checkbounds(list, idx)
221+
@inline function Base.setindex!(list::ReusableLinkedList{T}, value::T, idx::Integer) where T
222+
Base.@boundscheck checkbounds(list, idx)
223223
node = list.head
224224
for _ in 1:(idx-1)
225225
node === nothing && throw(BoundsError(list, idx))
@@ -377,8 +377,8 @@ function Base.resize!(list::ReusableLinkedList, N::Integer)
377377
end
378378
return list
379379
end
380-
function Base.deleteat!(list::ReusableLinkedList, idx::Integer)
381-
checkbounds(list, idx)
380+
@inline function Base.deleteat!(list::ReusableLinkedList, idx::Integer)
381+
Base.@boundscheck checkbounds(list, idx)
382382
if idx == 1
383383
deleted = list.head
384384
list.head = list.head.next

0 commit comments

Comments
 (0)