| 
1 | 1 | # This file is a part of Julia. License is MIT: https://julialang.org/license  | 
2 | 2 | 
 
  | 
3 |  | -using Core: CodeInfo, SimpleVector, donotdelete, compilerbarrier, memoryrefnew, memoryrefget, memoryrefset!  | 
 | 3 | +using Core: CodeInfo, SimpleVector, donotdelete, compilerbarrier, memoryref, memoryrefnew, memoryrefget, memoryrefset!  | 
4 | 4 | 
 
  | 
5 | 5 | const Callable = Union{Function,Type}  | 
6 | 6 | 
 
  | 
@@ -377,13 +377,26 @@ macro _nospecializeinfer_meta()  | 
377 | 377 |     return Expr(:meta, :nospecializeinfer)  | 
378 | 378 | end  | 
379 | 379 | 
 
  | 
 | 380 | +function _checkbounds_array(::Type{Bool}, A::Union{Array, GenericMemory}, i::Int)  | 
 | 381 | +    @inline  | 
 | 382 | +    ult_int(bitcast(UInt, sub_int(i, 1)), bitcast(UInt, length(A)))  | 
 | 383 | +end  | 
 | 384 | +function _checkbounds_array(A::Union{Array, GenericMemory}, i::Int)  | 
 | 385 | +    @inline  | 
 | 386 | +    _checkbounds_array(Bool, A, i) || throw_boundserror(A, (i,))  | 
 | 387 | +end  | 
 | 388 | + | 
380 | 389 | default_access_order(a::GenericMemory{:not_atomic}) = :not_atomic  | 
381 | 390 | default_access_order(a::GenericMemory{:atomic}) = :monotonic  | 
382 | 391 | default_access_order(a::GenericMemoryRef{:not_atomic}) = :not_atomic  | 
383 | 392 | default_access_order(a::GenericMemoryRef{:atomic}) = :monotonic  | 
384 | 393 | 
 
  | 
385 |  | -getindex(A::GenericMemory, i::Int) = (@_noub_if_noinbounds_meta;  | 
386 |  | -    memoryrefget(memoryrefnew(memoryrefnew(A), i, @_boundscheck), default_access_order(A), false))  | 
 | 394 | +function getindex(A::GenericMemory, i::Int)  | 
 | 395 | +    @_noub_if_noinbounds_meta  | 
 | 396 | +    (@_boundscheck) && _checkbounds_array(A, i)  | 
 | 397 | +    memoryrefget(memoryrefnew(memoryrefnew(A), i, false), default_access_order(A), false)  | 
 | 398 | +end  | 
 | 399 | + | 
387 | 400 | getindex(A::GenericMemoryRef) = memoryrefget(A, default_access_order(A), @_boundscheck)  | 
388 | 401 | 
 
  | 
389 | 402 | """  | 
@@ -949,13 +962,13 @@ end  | 
949 | 962 | # linear indexing  | 
950 | 963 | function getindex(A::Array, i::Int)  | 
951 | 964 |     @_noub_if_noinbounds_meta  | 
952 |  | -    @boundscheck ult_int(bitcast(UInt, sub_int(i, 1)), bitcast(UInt, length(A))) || throw_boundserror(A, (i,))  | 
 | 965 | +    @boundscheck _checkbounds_array(A, i)  | 
953 | 966 |     memoryrefget(memoryrefnew(getfield(A, :ref), i, false), :not_atomic, false)  | 
954 | 967 | end  | 
955 | 968 | # simple Array{Any} operations needed for bootstrap  | 
956 | 969 | function setindex!(A::Array{Any}, @nospecialize(x), i::Int)  | 
957 | 970 |     @_noub_if_noinbounds_meta  | 
958 |  | -    @boundscheck ult_int(bitcast(UInt, sub_int(i, 1)), bitcast(UInt, length(A))) || throw_boundserror(A, (i,))  | 
 | 971 | +    @boundscheck _checkbounds_array(A, i)  | 
959 | 972 |     memoryrefset!(memoryrefnew(getfield(A, :ref), i, false), x, :not_atomic, false)  | 
960 | 973 |     return A  | 
961 | 974 | end  | 
 | 
0 commit comments