-
Notifications
You must be signed in to change notification settings - Fork 2
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
Iterating over eachindex
doesn't remove out-of-bounds error
#65
Comments
eachindex
doesn't remove oit-of-bounds erroreachindex
doesn't remove out-of-bounds error
Based on the debuginfo shown in the LLVM IR above, I believe this happens because the method function setindex!(A::Array{T}, x, i::Int) where {T}
@_noub_if_noinbounds_meta
@boundscheck (i - 1)%UInt < length(A)%UInt || throw_boundserror(A, (i,))
memoryrefset!(memoryrefnew(A.ref, i, false), x isa T ? x : convert(T,x)::T, :not_atomic, false)
return A
end Changing our definition of function Base.setindex!(A::FixedSizeArray{T}, x, i::Int) where {T}
Base.@_noub_if_noinbounds_meta
@boundscheck (i - 1)%UInt < length(A)%UInt || Base.throw_boundserror(A, (i,))
@inbounds A.mem[i] = x
return A
end does seem to help quite a bit. I'm not sure what |
Pretty sure
|
I opened the PR before reading your message here, sorry! Do suggest improvements about the effect macros (I'm not particularly familiar with all their meanings), but as far as I can tell the proposed change is relatively safe, and I'm pretty sure the line memoryrefset!(memoryrefnew(A.ref, i, false), x isa T ? x : convert(T,x)::T, :not_atomic, false) in the @inbounds A.ref[i] = x (maybe not true when using Edit: on a closer inspection, I believe that for a Base.memoryrefset!(Base.memoryrefnew(Base.memoryrefnew(A.mem), i, false), x isa T ? x : convert(T,x)::T, :not_atomic, false) but when inbounds is propagated correctly then this should be pretty much the same as @inbounds A.ref[i] = x |
Maybe this is something deep in Julia internals, but iterating over
eachindex
of an array doesn't help removing bounds errors:LLVM IR
Details
The text was updated successfully, but these errors were encountered: