Skip to content

Commit

Permalink
Remove automatic inbounds stuff (#43)
Browse files Browse the repository at this point in the history
* remove automatic inbounds

* skip piracy tests and bump version

* remove stuff about inbounds from the docs
  • Loading branch information
MasonProtter authored Oct 9, 2023
1 parent 9c6dcb9 commit 0b174fb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StrideArraysCore"
uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da"
authors = ["Chris Elrod <[email protected]> and contributors"]
version = "0.4.17"
version = "0.5.0"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
[![Build Status](https://github.com/JuliaSIMD/StrideArraysCore.jl/workflows/CI/badge.svg)](https://github.com/JuliaSIMD/StrideArraysCore.jl/actions)
[![Coverage](https://codecov.io/gh/JuliaSIMD/StrideArraysCore.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaSIMD/StrideArraysCore.jl)

### Caution

`StrideArraysCore` (and `StrideArray`s) does not check bounds by default. To enable bounds checking (for both), define
```julia
StrideArraysCore.boundscheck() = true
```
Note, bounds checking is still disabled when using `@inbounds`, even if `boundscheck() == false`.
Starting Julia with `--check-bounds=yes` will automatically redefine `StrideArraysCore.boundscheck() = true`.


Defines the core `PtrArray` type so that some libraries can make use of it internally without the need for circular dependencies.
[StrideArrays](https://github.com/chriselrod/StrideArrays.jl) extends this type with many methods and functionality. It is
recommended you depend on and use `StrideArrays` instead.
Expand Down
11 changes: 0 additions & 11 deletions src/StrideArraysCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export PtrArray, StrideArray, StaticInt, static, @gc_preserve
(r::Returns)(args...) = r.x
end

const checkbounds_recompile = VERSION >= v"1.9.0" && Base.JLOptions().use_pkgimages == 1

@generated static_sizeof(::Type{T}) where {T} =
:(StaticInt{$(Base.allocatedinline(T) ? sizeof(T) : sizeof(Int))}())
include("ptr_array.jl")
Expand All @@ -68,14 +66,5 @@ if VERSION >= v"1.7.0" && hasfield(Method, :recursion_relation)
end
end

if !checkbounds_recompile
function __init__()
ccall(:jl_generating_output, Cint, ()) == 1 && return nothing
if Base.JLOptions().check_bounds == 1
@eval boundscheck() = true
end
# # @require LoopVectorization="bdcacae8-1622-11e9-2a5c-532679323890" @eval using StrideArrays
end
end

end
17 changes: 6 additions & 11 deletions src/ptr_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,6 @@ Base.@propagate_inbounds function Base.setindex!(
PtrArray(A)[i...] = v
end
end
if checkbounds_recompile
@eval boundscheck() = $(Base.JLOptions().check_bounds == 1)
else
boundscheck() = false
end

@inline _offset_dense(i::Tuple{}, s::Tuple{}) = Zero()
@inline _offset_dense(i::Tuple{I}, s::Tuple{S}) where {I,S} = i[1] * s[1]
Expand Down Expand Up @@ -937,32 +932,32 @@ end
end

@inline function Base.getindex(A::PtrArray, i::Vararg{Integer})
boundscheck() && @boundscheck checkbounds(A, i...)
@boundscheck checkbounds(A, i...)
pload(_offset_ptr(A, i))
end
@inline function Base.setindex!(A::PtrArray, v, i::Vararg{Integer,K}) where {K}
boundscheck() && @boundscheck checkbounds(A, i...)
@boundscheck checkbounds(A, i...)
pstore!(_offset_ptr(A, i), v)
v
end
@inline function Base.getindex(A::PtrArray{T}, i::Integer) where {T}
boundscheck() && @boundscheck checkbounds(A, i)
@boundscheck checkbounds(A, i)
pload(pointer(A) + (i - oneunit(i)) * static_sizeof(T))
end
@inline function Base.setindex!(A::PtrArray{T}, v, i::Integer) where {T}
boundscheck() && @boundscheck checkbounds(A, i)
@boundscheck checkbounds(A, i)
pstore!(pointer(A) + (i - oneunit(i)) * static_sizeof(T), v)
v
end
@inline function Base.getindex(A::PtrVector{T}, i::Integer) where {T}
boundscheck() && @boundscheck checkbounds(A, i)
@boundscheck checkbounds(A, i)
pload(
pointer(A) +
(i - ArrayInterface.offset1(A)) * only(LayoutPointers.bytestrides(A))
)
end
@inline function Base.setindex!(A::PtrVector{T}, v, i::Integer) where {T}
boundscheck() && @boundscheck checkbounds(A, i)
@boundscheck checkbounds(A, i)
pstore!(
pointer(A) +
(i - ArrayInterface.offset1(A)) * only(LayoutPointers.bytestrides(A)),
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ end
end

@testset "StrideArraysCore.jl" begin

Aqua.test_all(StrideArraysCore)
# Currently StrideArraysCore commits piracy with zero_offsets(A::AbstractArray) and preserve_buffer(A::MemoryBuffer)
Aqua.test_all(StrideArraysCore; piracy=false)

@testset "StrideArrays Basic" begin
@test (Base.JLOptions().check_bounds == 1) == StrideArraysCore.boundscheck()

Acomplex = StrideArray{Complex{Float64}}(undef, (StaticInt(4), StaticInt(5)))
@test @inferred(StrideArraysCore.ArrayInterface.known_size(Acomplex)) === (4, 5)
Expand Down

2 comments on commit 0b174fb

@chriselrod
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/93123

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 0b174fb3a1523d72e081a674ee836f83ffc59e35
git push origin v0.5.0

Please sign in to comment.