@@ -124,8 +124,8 @@ const DenseVecOrMat{T} = Union{DenseVector{T}, DenseMatrix{T}}
124124 @_safeindex
125125
126126This internal macro converts:
127- - `getindex(xs::Tuple, )` -> `__inbounds_getindex(args... )`
128- - `setindex!(xs::Vector, args... )` -> `__inbounds_setindex !(xs, args... )`
127+ - `getindex(xs::Tuple, i::Int )` -> `__safe_getindex(xs, i )`
128+ - `setindex!(xs::Vector{T}, x, i::Int )` -> `__safe_setindex !(xs, x, i )`
129129to tell the compiler that indexing operations within the applied expression are always
130130inbounds and do not need to taint `:consistent` and `:nothrow`.
131131"""
@@ -143,10 +143,10 @@ function _safeindex(__module__, ex)
143143 for i = 2 : length (lhs. args)
144144 args[i- 1 ] = _safeindex (__module__, lhs. args[i])
145145 end
146- return Expr (:call , GlobalRef (__module__, :__inbounds_setindex ! ), xs, _safeindex (__module__, rhs), args... )
146+ return Expr (:call , GlobalRef (__module__, :__safe_setindex ! ), xs, _safeindex (__module__, rhs), args... )
147147 end
148148 elseif ex. head === :ref # xs[i]
149- return Expr (:call , GlobalRef (__module__, :__inbounds_getindex ), ex. args... )
149+ return Expr (:call , GlobalRef (__module__, :__safe_getindex ), ex. args... )
150150 end
151151 args = Vector {Any} (undef, length (ex. args))
152152 for i = 1 : length (ex. args)
@@ -236,13 +236,15 @@ sizeof(a::Array) = length(a) * elsize(typeof(a)) # n.b. this ignores bitsunion b
236236
237237function isassigned (a:: Array , i:: Int... )
238238 @inline
239+ @_noub_if_noinbounds_meta
239240 @boundscheck checkbounds (Bool, a, i... ) || return false
240241 ii = _sub2ind (size (a), i... )
241242 return @inbounds isassigned (memoryref (a. ref, ii, false ))
242243end
243244
244245function isassigned (a:: Vector , i:: Int ) # slight compiler simplification for the most common case
245246 @inline
247+ @_noub_if_noinbounds_meta
246248 @boundscheck checkbounds (Bool, a, i) || return false
247249 return @inbounds isassigned (memoryref (a. ref, i, false ))
248250end
@@ -962,29 +964,23 @@ Dict{String, Int64} with 2 entries:
962964function setindex! end
963965
964966function setindex! (A:: Array{T} , x, i:: Int ) where {T}
967+ @_noub_if_noinbounds_meta
965968 @boundscheck (i - 1 )% UInt < length (A)% UInt || throw_boundserror (A, (i,))
966969 memoryrefset! (memoryref (A. ref, i, false ), x isa T ? x : convert (T,x):: T , :not_atomic , false )
967970 return A
968971end
969972function setindex! (A:: Array{T} , x, i1:: Int , i2:: Int , I:: Int... ) where {T}
970973 @inline
974+ @_noub_if_noinbounds_meta
971975 @boundscheck checkbounds (A, i1, i2, I... ) # generally _to_linear_index requires bounds checking
972976 memoryrefset! (memoryref (A. ref, _to_linear_index (A, i1, i2, I... ), false ), x isa T ? x : convert (T,x):: T , :not_atomic , false )
973977 return A
974978end
975979
976- function __inbounds_setindex! (A:: Array{T} , x, i:: Int ) where {T}
977- @inline
978- val = x isa T ? x : convert (T,x):: T
979- memoryrefset! (memoryref (A. ref, i, false ), val, :not_atomic , false )
980- return A
981- end
982- function __inbounds_setindex! (A:: Array{T} , x, i1:: Int , i2:: Int , I:: Int... ) where {T}
983- @inline
984- val = x isa T ? x : convert (T,x):: T
985- memoryrefset! (memoryref (A. ref, _to_linear_index (A, i1, i2, I... ), false ), val, :not_atomic , false )
986- return A
987- end
980+ __safe_setindex! (A:: Vector{T} , x:: T , i:: Int ) where {T} = (@inline ; @_nothrow_noub_meta ;
981+ memoryrefset! (memoryref (A. ref, i, false ), x, :not_atomic , false ); return A)
982+ __safe_setindex! (A:: Vector{T} , x, i:: Int ) where {T} = (@inline ;
983+ __safe_setindex! (A, convert (T, x):: T , i))
988984
989985# This is redundant with the abstract fallbacks but needed and helpful for bootstrap
990986function setindex! (A:: Array , X:: AbstractArray , I:: AbstractVector{Int} )
0 commit comments