Skip to content

Commit df1b38d

Browse files
authored
cleanup MemoryRef (#54647)
While writing docs in #54642, I became dis-satisfied with how `MemoryRef` currently works and since we are approaching the deadline for changing things around here, made this. Previously, we had the builtin `memoryref` which constructed a `GenericMemoryRef` from a `GenericMemory` or from a `GenericMemoryRef` and an offset. and then we defined constructors `GenericMemoryRef`, `MemoryRef` etc that provided a nicish interface around the intrinsic. The problem with this is that people who want to make a `GenericMemoryRef` don't care what kind of `GenericMemoryRef` they are making. That choice is defined by the `GemericMemory`. As such, I have switched it around so that now the intrinsic is named `memoryrefnew` which frees up `memoryref` to be the function that constructs the appropriate type of `GenericMemoryRef`. This could have been done purely on the Base side, but renaming the intrinsic seems worth it to me since Base/Core use the (new) `memoryref` a lot and it seems like we should make the experience the same for internal and external users rather than making `Base` have to work around a bad name. (cherry picked from commit fa038d9)
1 parent 0211c83 commit df1b38d

File tree

18 files changed

+89
-93
lines changed

18 files changed

+89
-93
lines changed

base/array.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ isbitsunion(u::Type) = u isa Union && allocatedinline(u)
216216
function _unsetindex!(A::Array, i::Int)
217217
@inline
218218
@boundscheck checkbounds(A, i)
219-
@inbounds _unsetindex!(GenericMemoryRef(A.ref, i))
219+
@inbounds _unsetindex!(memoryref(A.ref, i))
220220
return A
221221
end
222222

@@ -239,14 +239,14 @@ function isassigned(a::Array, i::Int...)
239239
@_noub_if_noinbounds_meta
240240
@boundscheck checkbounds(Bool, a, i...) || return false
241241
ii = _sub2ind(size(a), i...)
242-
return @inbounds isassigned(memoryref(a.ref, ii, false))
242+
return @inbounds isassigned(memoryrefnew(a.ref, ii, false))
243243
end
244244

245245
function isassigned(a::Vector, i::Int) # slight compiler simplification for the most common case
246246
@inline
247247
@_noub_if_noinbounds_meta
248248
@boundscheck checkbounds(Bool, a, i) || return false
249-
return @inbounds isassigned(memoryref(a.ref, i, false))
249+
return @inbounds isassigned(memoryrefnew(a.ref, i, false))
250250
end
251251

252252

@@ -281,7 +281,7 @@ the same manner as C.
281281
"""
282282
function unsafe_copyto!(dest::Array, doffs, src::Array, soffs, n)
283283
n == 0 && return dest
284-
unsafe_copyto!(GenericMemoryRef(dest.ref, doffs), GenericMemoryRef(src.ref, soffs), n)
284+
unsafe_copyto!(memoryref(dest.ref, doffs), memoryref(src.ref, soffs), n)
285285
return dest
286286
end
287287

@@ -303,8 +303,8 @@ function _copyto_impl!(dest::Union{Array,Memory}, doffs::Integer, src::Union{Arr
303303
n > 0 || _throw_argerror("Number of elements to copy must be non-negative.")
304304
@boundscheck checkbounds(dest, doffs:doffs+n-1)
305305
@boundscheck checkbounds(src, soffs:soffs+n-1)
306-
@inbounds let dest = GenericMemoryRef(dest isa Array ? getfield(dest, :ref) : dest, doffs)
307-
src = GenericMemoryRef(src isa Array ? getfield(src, :ref) : src, soffs)
306+
@inbounds let dest = memoryref(dest isa Array ? getfield(dest, :ref) : dest, doffs)
307+
src = memoryref(src isa Array ? getfield(src, :ref) : src, soffs)
308308
unsafe_copyto!(dest, src, n)
309309
end
310310
return dest
@@ -348,7 +348,7 @@ copy
348348
@_nothrow_meta
349349
ref = a.ref
350350
newmem = ccall(:jl_genericmemory_copy_slice, Ref{Memory{T}}, (Any, Ptr{Cvoid}, Int), ref.mem, ref.ptr_or_offset, length(a))
351-
return $(Expr(:new, :(typeof(a)), :(Core.memoryref(newmem)), :(a.size)))
351+
return $(Expr(:new, :(typeof(a)), :(memoryref(newmem)), :(a.size)))
352352
end
353353

354354
## Constructors ##
@@ -973,21 +973,21 @@ function setindex! end
973973
function setindex!(A::Array{T}, x, i::Int) where {T}
974974
@_noub_if_noinbounds_meta
975975
@boundscheck (i - 1)%UInt < length(A)%UInt || throw_boundserror(A, (i,))
976-
memoryrefset!(memoryref(A.ref, i, false), x isa T ? x : convert(T,x)::T, :not_atomic, false)
976+
memoryrefset!(memoryrefnew(A.ref, i, false), x isa T ? x : convert(T,x)::T, :not_atomic, false)
977977
return A
978978
end
979979
function setindex!(A::Array{T}, x, i1::Int, i2::Int, I::Int...) where {T}
980980
@inline
981981
@_noub_if_noinbounds_meta
982982
@boundscheck checkbounds(A, i1, i2, I...) # generally _to_linear_index requires bounds checking
983-
memoryrefset!(memoryref(A.ref, _to_linear_index(A, i1, i2, I...), false), x isa T ? x : convert(T,x)::T, :not_atomic, false)
983+
memoryrefset!(memoryrefnew(A.ref, _to_linear_index(A, i1, i2, I...), false), x isa T ? x : convert(T,x)::T, :not_atomic, false)
984984
return A
985985
end
986986

987987
__safe_setindex!(A::Vector{Any}, @nospecialize(x), i::Int) = (@inline; @_nothrow_noub_meta;
988-
memoryrefset!(memoryref(A.ref, i, false), x, :not_atomic, false); return A)
988+
memoryrefset!(memoryrefnew(A.ref, i, false), x, :not_atomic, false); return A)
989989
__safe_setindex!(A::Vector{T}, x::T, i::Int) where {T} = (@inline; @_nothrow_noub_meta;
990-
memoryrefset!(memoryref(A.ref, i, false), x, :not_atomic, false); return A)
990+
memoryrefset!(memoryrefnew(A.ref, i, false), x, :not_atomic, false); return A)
991991
__safe_setindex!(A::Vector{T}, x, i::Int) where {T} = (@inline;
992992
__safe_setindex!(A, convert(T, x)::T, i))
993993

@@ -1059,7 +1059,7 @@ function _growbeg!(a::Vector, delta::Integer)
10591059
setfield!(a, :size, (newlen,))
10601060
# if offset is far enough advanced to fit data in existing memory without copying
10611061
if delta <= offset - 1
1062-
setfield!(a, :ref, @inbounds GenericMemoryRef(ref, 1 - delta))
1062+
setfield!(a, :ref, @inbounds memoryref(ref, 1 - delta))
10631063
else
10641064
@noinline (function()
10651065
memlen = length(mem)
@@ -1078,7 +1078,7 @@ function _growbeg!(a::Vector, delta::Integer)
10781078
newmem = array_new_memory(mem, newmemlen)
10791079
end
10801080
unsafe_copyto!(newmem, newoffset + delta, mem, offset, len)
1081-
setfield!(a, :ref, @inbounds GenericMemoryRef(newmem, newoffset))
1081+
setfield!(a, :ref, @inbounds memoryref(newmem, newoffset))
10821082
end)()
10831083
end
10841084
return
@@ -1113,7 +1113,7 @@ function _growend!(a::Vector, delta::Integer)
11131113
newmem = array_new_memory(mem, newmemlen2)
11141114
newoffset = offset
11151115
end
1116-
newref = @inbounds GenericMemoryRef(newmem, newoffset)
1116+
newref = @inbounds memoryref(newmem, newoffset)
11171117
unsafe_copyto!(newref, ref, len)
11181118
setfield!(a, :ref, newref)
11191119
end)()
@@ -1142,7 +1142,7 @@ function _growat!(a::Vector, i::Integer, delta::Integer)
11421142
prefer_start = i <= div(len, 2)
11431143
# if offset is far enough advanced to fit data in beginning of the memory
11441144
if prefer_start && delta <= offset - 1
1145-
newref = @inbounds GenericMemoryRef(mem, offset - delta)
1145+
newref = @inbounds memoryref(mem, offset - delta)
11461146
unsafe_copyto!(newref, ref, i)
11471147
setfield!(a, :ref, newref)
11481148
for j in i:i+delta-1
@@ -1159,7 +1159,7 @@ function _growat!(a::Vector, i::Integer, delta::Integer)
11591159
newmemlen = max(overallocation(memlen), len+2*delta+1)
11601160
newoffset = (newmemlen - newlen) ÷ 2 + 1
11611161
newmem = array_new_memory(mem, newmemlen)
1162-
newref = @inbounds GenericMemoryRef(newmem, newoffset)
1162+
newref = @inbounds memoryref(newmem, newoffset)
11631163
unsafe_copyto!(newref, ref, i-1)
11641164
unsafe_copyto!(newmem, newoffset + delta + i - 1, mem, offset + i - 1, len - i + 1)
11651165
setfield!(a, :ref, newref)
@@ -1176,7 +1176,7 @@ function _deletebeg!(a::Vector, delta::Integer)
11761176
end
11771177
newlen = len - delta
11781178
if newlen != 0 # if newlen==0 we could accidentally index past the memory
1179-
newref = @inbounds GenericMemoryRef(a.ref, delta + 1)
1179+
newref = @inbounds memoryref(a.ref, delta + 1)
11801180
setfield!(a, :ref, newref)
11811181
end
11821182
setfield!(a, :size, (newlen,))
@@ -1491,16 +1491,16 @@ function sizehint!(a::Vector, sz::Integer; first::Bool=false, shrink::Bool=true)
14911491
end
14921492
newmem = array_new_memory(mem, sz)
14931493
if first
1494-
newref = GenericMemoryRef(newmem, inc + 1)
1494+
newref = memoryref(newmem, inc + 1)
14951495
else
1496-
newref = GenericMemoryRef(newmem)
1496+
newref = memoryref(newmem)
14971497
end
14981498
unsafe_copyto!(newref, ref, len)
14991499
setfield!(a, :ref, newref)
15001500
elseif first
15011501
_growbeg!(a, inc)
15021502
newref = getfield(a, :ref)
1503-
newref = GenericMemoryRef(newref, inc + 1)
1503+
newref = memoryref(newref, inc + 1)
15041504
setfield!(a, :size, (len,)) # undo the size change from _growbeg!
15051505
setfield!(a, :ref, newref) # undo the offset change from _growbeg!
15061506
else # last

base/boot.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,12 @@ const undef = UndefInitializer()
517517
# empty vector constructor
518518
(self::Type{GenericMemory{kind,T,addrspace}})() where {T,kind,addrspace} = self(undef, 0)
519519

520+
memoryref(mem::GenericMemory) = memoryrefnew(mem)
521+
memoryref(mem::GenericMemory, i::Integer) = memoryrefnew(memoryrefnew(mem), Int(i), @_boundscheck)
522+
memoryref(ref::GenericMemoryRef, i::Integer) = memoryrefnew(ref, Int(i), @_boundscheck)
520523
GenericMemoryRef(mem::GenericMemory) = memoryref(mem)
521-
GenericMemoryRef(ref::GenericMemoryRef, i::Integer) = memoryref(ref, Int(i), @_boundscheck)
522-
GenericMemoryRef(mem::GenericMemory, i::Integer) = memoryref(memoryref(mem), Int(i), @_boundscheck)
523-
GenericMemoryRef{kind,<:Any,AS}(mem::GenericMemory{kind,<:Any,AS}) where {kind,AS} = memoryref(mem)
524-
GenericMemoryRef{kind,<:Any,AS}(ref::GenericMemoryRef{kind,<:Any,AS}, i::Integer) where {kind,AS} = memoryref(ref, Int(i), @_boundscheck)
525-
GenericMemoryRef{kind,<:Any,AS}(mem::GenericMemory{kind,<:Any,AS}, i::Integer) where {kind,AS} = memoryref(memoryref(mem), Int(i), @_boundscheck)
526-
GenericMemoryRef{kind,T,AS}(mem::GenericMemory{kind,T,AS}) where {kind,T,AS} = memoryref(mem)
527-
GenericMemoryRef{kind,T,AS}(ref::GenericMemoryRef{kind,T,AS}, i::Integer) where {kind,T,AS} = memoryref(ref, Int(i), @_boundscheck)
528-
GenericMemoryRef{kind,T,AS}(mem::GenericMemory{kind,T,AS}, i::Integer) where {kind,T,AS} = memoryref(memoryref(mem), Int(i), @_boundscheck)
524+
GenericMemoryRef(mem::GenericMemory, i::Integer) = memoryref(mem, i)
525+
GenericMemoryRef(mem::GenericMemoryRef, i::Integer) = memoryref(mem, i)
529526

530527
const Memory{T} = GenericMemory{:not_atomic, T, CPU}
531528
const MemoryRef{T} = GenericMemoryRef{:not_atomic, T, CPU}
@@ -633,12 +630,12 @@ module IR
633630
export CodeInfo, MethodInstance, CodeInstance, GotoNode, GotoIfNot, ReturnNode,
634631
NewvarNode, SSAValue, SlotNumber, Argument,
635632
PiNode, PhiNode, PhiCNode, UpsilonNode, LineInfoNode,
636-
Const, PartialStruct, InterConditional, EnterNode
633+
Const, PartialStruct, InterConditional, EnterNode, memoryref
637634

638635
using Core: CodeInfo, MethodInstance, CodeInstance, GotoNode, GotoIfNot, ReturnNode,
639636
NewvarNode, SSAValue, SlotNumber, Argument,
640637
PiNode, PhiNode, PhiCNode, UpsilonNode, LineInfoNode,
641-
Const, PartialStruct, InterConditional, EnterNode
638+
Const, PartialStruct, InterConditional, EnterNode, memoryref
642639

643640
end # module IR
644641

base/compiler/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ function iscall_with_boundscheck(@nospecialize(stmt), sv::PostOptAnalysisState)
677677
f === nothing && return false
678678
if f === getfield
679679
nargs = 4
680-
elseif f === memoryref || f === memoryrefget || f === memoryref_isassigned
680+
elseif f === memoryrefnew || f === memoryrefget || f === memoryref_isassigned
681681
nargs = 4
682682
elseif f === memoryrefset!
683683
nargs = 5

base/compiler/tfuncs.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ end
20742074
hasintersect(widenconst(idx), Int) || return Bottom
20752075
return ref
20762076
end
2077-
add_tfunc(memoryref, 1, 3, memoryref_tfunc, 1)
2077+
add_tfunc(memoryrefnew, 1, 3, memoryref_tfunc, 1)
20782078

20792079
@nospecs function memoryrefoffset_tfunc(𝕃::AbstractLattice, mem)
20802080
hasintersect(widenconst(mem), GenericMemoryRef) || return Bottom
@@ -2224,7 +2224,7 @@ end
22242224
# Query whether the given builtin is guaranteed not to throw given the argtypes
22252225
@nospecs function _builtin_nothrow(𝕃::AbstractLattice, f, argtypes::Vector{Any}, rt)
22262226
= partialorder(𝕃)
2227-
if f === memoryref
2227+
if f === memoryrefnew
22282228
return memoryref_builtin_common_nothrow(argtypes)
22292229
elseif f === memoryrefoffset
22302230
length(argtypes) == 1 || return false
@@ -2348,7 +2348,7 @@ const _EFFECT_FREE_BUILTINS = [
23482348
isa,
23492349
UnionAll,
23502350
getfield,
2351-
memoryref,
2351+
memoryrefnew,
23522352
memoryrefoffset,
23532353
memoryrefget,
23542354
memoryref_isassigned,
@@ -2383,7 +2383,7 @@ const _INACCESSIBLEMEM_BUILTINS = Any[
23832383
]
23842384

23852385
const _ARGMEM_BUILTINS = Any[
2386-
memoryref,
2386+
memoryrefnew,
23872387
memoryrefoffset,
23882388
memoryrefget,
23892389
memoryref_isassigned,
@@ -2565,7 +2565,7 @@ function builtin_effects(𝕃::AbstractLattice, @nospecialize(f::Builtin), argty
25652565
else
25662566
if contains_is(_CONSISTENT_BUILTINS, f)
25672567
consistent = ALWAYS_TRUE
2568-
elseif f === memoryref || f === memoryrefoffset
2568+
elseif f === memoryrefnew || f === memoryrefoffset
25692569
consistent = ALWAYS_TRUE
25702570
elseif f === memoryrefget || f === memoryrefset! || f === memoryref_isassigned
25712571
consistent = CONSISTENT_IF_INACCESSIBLEMEMONLY
@@ -2589,7 +2589,7 @@ function builtin_effects(𝕃::AbstractLattice, @nospecialize(f::Builtin), argty
25892589
else
25902590
inaccessiblememonly = ALWAYS_FALSE
25912591
end
2592-
if f === memoryref || f === memoryrefget || f === memoryrefset! || f === memoryref_isassigned
2592+
if f === memoryrefnew || f === memoryrefget || f === memoryrefset! || f === memoryref_isassigned
25932593
noub = memoryop_noub(f, argtypes) ? ALWAYS_TRUE : ALWAYS_FALSE
25942594
else
25952595
noub = ALWAYS_TRUE
@@ -2604,7 +2604,7 @@ function memoryop_noub(@nospecialize(f), argtypes::Vector{Any})
26042604
nargs == 0 && return true # must throw and noub
26052605
lastargtype = argtypes[end]
26062606
isva = isvarargtype(lastargtype)
2607-
if f === memoryref
2607+
if f === memoryrefnew
26082608
if nargs == 1 && !isva
26092609
return true
26102610
elseif nargs == 2 && !isva

base/deepcopy.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ function _deepcopy_memory_t(@nospecialize(x::Memory), T, stackdict::IdDict)
105105
end
106106
dest = typeof(x)(undef, length(x))
107107
stackdict[x] = dest
108-
xr = Core.memoryref(x)
109-
dr = Core.memoryref(dest)
108+
xr = memoryref(x)
109+
dr = memoryref(dest)
110110
for i = 1:length(x)
111-
xi = Core.memoryref(xr, i, false)
111+
xi = Core.memoryrefnew(xr, i, false)
112112
if Core.memoryref_isassigned(xi, :not_atomic, false)
113113
xi = Core.memoryrefget(xi, :not_atomic, false)
114114
if !isbits(xi)
115115
xi = deepcopy_internal(xi, stackdict)::typeof(xi)
116116
end
117-
di = Core.memoryref(dr, i, false)
117+
di = Core.memoryrefnew(dr, i, false)
118118
Core.memoryrefset!(di, xi, :not_atomic, false)
119119
end
120120
end
@@ -131,9 +131,9 @@ function deepcopy_internal(x::GenericMemoryRef, stackdict::IdDict)
131131
return stackdict[x]::typeof(x)
132132
end
133133
mem = getfield(x, :mem)
134-
dest = GenericMemoryRef(deepcopy_internal(mem, stackdict)::typeof(mem))
134+
dest = memoryref(deepcopy_internal(mem, stackdict)::typeof(mem))
135135
i = memoryrefoffset(x)
136-
i == 1 || (dest = Core.memoryref(dest, i, true))
136+
i == 1 || (dest = Core.memoryrefnew(dest, i, true))
137137
return dest
138138
end
139139

base/docs/basedocs.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,23 +2668,21 @@ julia> Memory{Float64}(undef, 3)
26682668
Memory{T}(::UndefInitializer, n)
26692669

26702670
"""
2671-
MemoryRef(memory)
2672-
2673-
Construct a MemoryRef from a memory object. This does not fail, but the
2674-
resulting memory may point out-of-bounds if the memory is empty.
2671+
`memoryref(::GenericMemory)`
2672+
Construct a `GenericMemoryRef` from a memory object. This does not fail, but the
2673+
resulting memory will point out-of-bounds if and only if the memory is empty.
26752674
"""
2676-
MemoryRef(::Memory)
2675+
memoryref(::GenericMemory)
26772676

26782677
"""
2679-
MemoryRef(::Memory, index::Integer)
2680-
MemoryRef(::MemoryRef, index::Integer)
2681-
2682-
Construct a MemoryRef from a memory object and an offset index (1-based) which
2678+
memoryref(::GenericMemory, index::Integer)
2679+
memoryref(::GenericMemoryRef, index::Integer)
2680+
Construct a `GenericMemoryRef` from a memory object and an offset index (1-based) which
26832681
can also be negative. This always returns an inbounds object, and will throw an
26842682
error if that is not possible (because the index would result in a shift
26852683
out-of-bounds of the underlying memory).
26862684
"""
2687-
MemoryRef(::Union{Memory,MemoryRef}, ::Integer)
2685+
memoryref(::Union{GenericMemory,GenericMemoryRef}, ::Integer)
26882686

26892687
"""
26902688
Vector{T}(undef, n)

base/docs/intrinsicsdocs.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ The `Core.Intrinsics` module holds the `Core.IntrinsicFunction` objects.
2323
Core.Intrinsics
2424

2525
"""
26-
Core.memoryref(::GenericMemory)
27-
Core.memoryref(::GenericMemoryRef, index::Int, [boundscheck::Bool])
26+
Core.memoryrefnew(::GenericMemory)
27+
Core.memoryrefnew(::GenericMemoryRef, index::Int, [boundscheck::Bool])
2828
29-
Return a `GenericMemoryRef` for a `GenericMemory`. See [`MemoryRef`](@ref).
29+
Return a `GenericMemoryRef` for a `GenericMemory`. See [`memoryref`](@ref).
3030
3131
!!! compat "Julia 1.11"
3232
This function requires Julia 1.11 or later.
3333
"""
34-
Core.memoryref
34+
Core.memoryrefnew
3535

3636
"""
3737
Core..memoryrefoffset(::GenericMemoryRef)
3838
39-
Return the offset index that was used to construct the `MemoryRef`. See [`Core.memoryref`](@ref).
39+
Return the offset index that was used to construct the `MemoryRef`. See [`memoryref`](@ref).
4040
4141
!!! compat "Julia 1.11"
4242
This function requires Julia 1.11 or later.

base/essentials.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Core: CodeInfo, SimpleVector, donotdelete, compilerbarrier, memoryref, memoryrefget, memoryrefset!
3+
using Core: CodeInfo, SimpleVector, donotdelete, compilerbarrier, memoryrefnew, memoryrefget, memoryrefset!
44

55
const Callable = Union{Function,Type}
66

@@ -372,7 +372,7 @@ default_access_order(a::GenericMemoryRef{:not_atomic}) = :not_atomic
372372
default_access_order(a::GenericMemoryRef{:atomic}) = :monotonic
373373

374374
getindex(A::GenericMemory, i::Int) = (@_noub_if_noinbounds_meta;
375-
memoryrefget(memoryref(memoryref(A), i, @_boundscheck), default_access_order(A), false))
375+
memoryrefget(memoryrefnew(memoryrefnew(A), i, @_boundscheck), default_access_order(A), false))
376376
getindex(A::GenericMemoryRef) = memoryrefget(A, default_access_order(A), @_boundscheck)
377377

378378
function iterate end
@@ -890,16 +890,16 @@ end
890890
function getindex(A::Array, i::Int)
891891
@_noub_if_noinbounds_meta
892892
@boundscheck ult_int(bitcast(UInt, sub_int(i, 1)), bitcast(UInt, length(A))) || throw_boundserror(A, (i,))
893-
memoryrefget(memoryref(getfield(A, :ref), i, false), :not_atomic, false)
893+
memoryrefget(memoryrefnew(getfield(A, :ref), i, false), :not_atomic, false)
894894
end
895895
# simple Array{Any} operations needed for bootstrap
896896
function setindex!(A::Array{Any}, @nospecialize(x), i::Int)
897897
@_noub_if_noinbounds_meta
898898
@boundscheck ult_int(bitcast(UInt, sub_int(i, 1)), bitcast(UInt, length(A))) || throw_boundserror(A, (i,))
899-
memoryrefset!(memoryref(getfield(A, :ref), i, false), x, :not_atomic, false)
899+
memoryrefset!(memoryrefnew(getfield(A, :ref), i, false), x, :not_atomic, false)
900900
return A
901901
end
902-
setindex!(A::Memory{Any}, @nospecialize(x), i::Int) = (memoryrefset!(memoryref(memoryref(A), i, @_boundscheck), x, :not_atomic, @_boundscheck); A)
902+
setindex!(A::Memory{Any}, @nospecialize(x), i::Int) = (memoryrefset!(memoryrefnew(memoryrefnew(A), i, @_boundscheck), x, :not_atomic, @_boundscheck); A)
903903
setindex!(A::MemoryRef{T}, x) where {T} = (memoryrefset!(A, convert(T, x), :not_atomic, @_boundscheck); A)
904904
setindex!(A::MemoryRef{Any}, @nospecialize(x)) = (memoryrefset!(A, x, :not_atomic, @_boundscheck); A)
905905

base/exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ export
549549
mapfoldl,
550550
mapfoldr,
551551
mapreduce,
552+
memoryref,
552553
merge!,
553554
mergewith!,
554555
merge,

0 commit comments

Comments
 (0)