Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ function setindex!(A::Array{T}, x, i::Int) where {T}
end
function _setindex!(A::Array{T}, x::T, i::Int) where {T}
@_noub_if_noinbounds_meta
@boundscheck (i - 1)%UInt < length(A)%UInt || throw_boundserror(A, (i,))
@boundscheck checkbounds(Bool, A, i) || throw_boundserror(A, (i,))
memoryrefset!(memoryrefnew(A.ref, i, false), x, :not_atomic, false)
return A
end
Expand Down
13 changes: 7 additions & 6 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@ macro _nospecializeinfer_meta()
return Expr(:meta, :nospecializeinfer)
end

function _checkbounds_array(::Type{Bool}, A::Union{Array, GenericMemory}, i::Int)
# These special checkbounds methods are defined early for bootstrapping
function checkbounds(::Type{Bool}, A::Union{Array, Memory}, i::Int)
@inline
ult_int(bitcast(UInt, sub_int(i, 1)), bitcast(UInt, length(A)))
end
function _checkbounds_array(A::Union{Array, GenericMemory}, i::Int)
function checkbounds(A::Union{Array, GenericMemory}, i::Int)
@inline
_checkbounds_array(Bool, A, i) || throw_boundserror(A, (i,))
checkbounds(Bool, A, i) || throw_boundserror(A, (i,))
end

default_access_order(a::GenericMemory{:not_atomic}) = :not_atomic
Expand All @@ -393,7 +394,7 @@ default_access_order(a::GenericMemoryRef{:atomic}) = :monotonic

function getindex(A::GenericMemory, i::Int)
@_noub_if_noinbounds_meta
(@_boundscheck) && _checkbounds_array(A, i)
(@_boundscheck) && checkbounds(A, i)
memoryrefget(memoryrefnew(memoryrefnew(A), i, false), default_access_order(A), false)
end

Expand Down Expand Up @@ -962,13 +963,13 @@ end
# linear indexing
function getindex(A::Array, i::Int)
@_noub_if_noinbounds_meta
@boundscheck _checkbounds_array(A, i)
@boundscheck checkbounds(A, i)
memoryrefget(memoryrefnew(getfield(A, :ref), i, false), :not_atomic, false)
end
# simple Array{Any} operations needed for bootstrap
function setindex!(A::Array{Any}, @nospecialize(x), i::Int)
@_noub_if_noinbounds_meta
@boundscheck _checkbounds_array(A, i)
@boundscheck checkbounds(A, i)
memoryrefset!(memoryrefnew(getfield(A, :ref), i, false), x, :not_atomic, false)
return A
end
Expand Down
4 changes: 2 additions & 2 deletions base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ sizeof(a::GenericMemory) = Core.sizeof(a)
# multi arg case will be overwritten later. This is needed for bootstrapping
function isassigned(a::GenericMemory, i::Int)
@inline
@boundscheck (i - 1)%UInt < length(a)%UInt || return false
@boundscheck checkbounds(Bool, a, i) || return false
return @inbounds memoryref_isassigned(memoryref(a, i), default_access_order(a), false)
end

Expand Down Expand Up @@ -227,7 +227,7 @@ Memory{T}(x::AbstractArray{S,1}) where {T,S} = copyto_axcheck!(Memory{T}(undef,

function _iterate_array(A::Union{Memory, Array}, i::Int)
@inline
(i - 1)%UInt < length(A)%UInt ? (A[i], i + 1) : nothing
checkbounds(Bool, A, i) ? (A[i], i + 1) : nothing
end

iterate(A::Memory, i=1) = (@inline; _iterate_array(A, i))
Expand Down
2 changes: 1 addition & 1 deletion base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ size(s::CodeUnits) = (length(s),)
elsize(s::Type{<:CodeUnits{T}}) where {T} = sizeof(T)
@propagate_inbounds getindex(s::CodeUnits, i::Int) = codeunit(s.s, i)
IndexStyle(::Type{<:CodeUnits}) = IndexLinear()
@inline iterate(s::CodeUnits, i=1) = (i % UInt) - 1 < length(s) ? (@inbounds s[i], i + 1) : nothing
@inline iterate(s::CodeUnits, i=1) = checkbounds(Bool, s, i) ? (@inbounds s[i], i + 1) : nothing


write(io::IO, s::CodeUnits) = write(io, s.s)
Expand Down