Skip to content

Commit 2571882

Browse files
committed
Revert "implement Memory{T} as a new backend for Array{T} (JuliaLang#51319)"
This reverts commit 909bcea.
1 parent 1a49eea commit 2571882

File tree

128 files changed

+5354
-6006
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+5354
-6006
lines changed

base/Base.jl

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ using Core.Intrinsics, Core.IR
66

77
# to start, we're going to use a very simple definition of `include`
88
# that doesn't require any function (except what we can get from the `Core` top-module)
9-
# start this big so that we don't have to resize before we have defined how to grow an array
10-
const _included_files = Array{Tuple{Module,String},1}(Core.undef, 400)
11-
setfield!(_included_files, :size, (1,))
9+
const _included_files = Array{Tuple{Module,String},1}(Core.undef, 1)
1210
function include(mod::Module, path::String)
13-
len = getfield(_included_files.size, 1)
14-
memlen = _included_files.ref.mem.length
15-
lenp1 = Core.add_int(len, 1)
16-
if len === memlen # by the time this is true we hopefully will have defined _growend!
17-
_growend!(_included_files, UInt(1))
18-
else
19-
setfield!(_included_files, :size, (lenp1,))
20-
end
21-
Core.memoryrefset!(Core.memoryref(_included_files.ref, lenp1), (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)), :not_atomic, true)
11+
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), _included_files, UInt(1))
12+
Core.arrayset(true, _included_files, (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)), arraylen(_included_files))
2213
Core.println(path)
2314
ccall(:jl_uv_flush, Nothing, (Ptr{Nothing},), Core.io_pointer(Core.stdout))
2415
Core.include(mod, path)
@@ -40,7 +31,6 @@ macro noinline() Expr(:meta, :noinline) end
4031
getproperty(x::Module, f::Symbol) = (@inline; getglobal(x, f))
4132
getproperty(x::Type, f::Symbol) = (@inline; getfield(x, f))
4233
setproperty!(x::Type, f::Symbol, v) = error("setfield! fields of Types should not be changed")
43-
setproperty!(x::Array, f::Symbol, v) = error("setfield! fields of Array should not be changed")
4434
getproperty(x::Tuple, f::Int) = (@inline; getfield(x, f))
4535
setproperty!(x::Tuple, f::Int, v) = setfield!(x, f, v) # to get a decent error
4636

@@ -202,22 +192,23 @@ include("strings/lazy.jl")
202192

203193
# array structures
204194
include("indices.jl")
205-
include("genericmemory.jl")
206195
include("array.jl")
207196
include("abstractarray.jl")
208197
include("subarray.jl")
209198
include("views.jl")
210199
include("baseext.jl")
211200

212-
include("c.jl")
213201
include("ntuple.jl")
202+
214203
include("abstractdict.jl")
215204
include("iddict.jl")
216205
include("idset.jl")
206+
217207
include("iterators.jl")
218208
using .Iterators: zip, enumerate, only
219209
using .Iterators: Flatten, Filter, product # for generators
220210
using .Iterators: Stateful # compat (was formerly used in reinterpretarray.jl)
211+
221212
include("namedtuple.jl")
222213

223214
# For OS specific stuff
@@ -233,17 +224,6 @@ function strcat(x::String, y::String)
233224
end
234225
include(strcat((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "build_h.jl")) # include($BUILDROOT/base/build_h.jl)
235226
include(strcat((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "version_git.jl")) # include($BUILDROOT/base/version_git.jl)
236-
# Initialize DL_LOAD_PATH as early as possible. We are defining things here in
237-
# a slightly more verbose fashion than usual, because we're running so early.
238-
const DL_LOAD_PATH = String[]
239-
let os = ccall(:jl_get_UNAME, Any, ())
240-
if os === :Darwin || os === :Apple
241-
if Base.DARWIN_FRAMEWORK
242-
push!(DL_LOAD_PATH, "@loader_path/Frameworks")
243-
end
244-
push!(DL_LOAD_PATH, "@loader_path")
245-
end
246-
end
247227

248228
# numeric operations
249229
include("hashing.jl")
@@ -291,24 +271,24 @@ include("set.jl")
291271

292272
# Strings
293273
include("char.jl")
294-
function array_new_memory(mem::Memory{UInt8}, newlen::Int)
295-
# add an optimization to array_new_memory for StringVector
296-
if (@assume_effects :total @ccall jl_genericmemory_owner(mem::Any,)::Any) isa String
297-
# If data is in a String, keep it that way.
298-
# When implemented, this could use jl_gc_expand_string(oldstr, newlen) as an optimization
299-
str = _string_n(newlen)
300-
return (@assume_effects :total !:consistent @ccall jl_string_to_genericmemory(str::Any,)::Memory{UInt8})
301-
else
302-
# TODO: when implemented, this should use a memory growing call
303-
return typeof(mem)(undef, newlen)
304-
end
305-
end
306274
include("strings/basic.jl")
307275
include("strings/string.jl")
308276
include("strings/substring.jl")
309-
include("strings/cstring.jl")
277+
278+
# Initialize DL_LOAD_PATH as early as possible. We are defining things here in
279+
# a slightly more verbose fashion than usual, because we're running so early.
280+
const DL_LOAD_PATH = String[]
281+
let os = ccall(:jl_get_UNAME, Any, ())
282+
if os === :Darwin || os === :Apple
283+
if Base.DARWIN_FRAMEWORK
284+
push!(DL_LOAD_PATH, "@loader_path/Frameworks")
285+
end
286+
push!(DL_LOAD_PATH, "@loader_path")
287+
end
288+
end
310289

311290
include("osutils.jl")
291+
include("c.jl")
312292

313293
# Core I/O
314294
include("io.jl")

base/abstractarray.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ julia> ndims(A)
268268
3
269269
```
270270
"""
271-
ndims(::AbstractArray{T,N}) where {T,N} = N::Int
272-
ndims(::Type{<:AbstractArray{<:Any,N}}) where {N} = N::Int
271+
ndims(::AbstractArray{T,N}) where {T,N} = N
272+
ndims(::Type{<:AbstractArray{<:Any,N}}) where {N} = N
273273
ndims(::Type{Union{}}, slurp...) = throw(ArgumentError("Union{} does not have elements"))
274274

275275
"""
@@ -731,6 +731,8 @@ end
731731
checkbounds_indices(::Type{Bool}, IA::Tuple, ::Tuple{}) = (@inline; all(x->length(x)==1, IA))
732732
checkbounds_indices(::Type{Bool}, ::Tuple{}, ::Tuple{}) = true
733733

734+
throw_boundserror(A, I) = (@noinline; throw(BoundsError(A, I)))
735+
734736
# check along a single dimension
735737
"""
736738
checkindex(Bool, inds::AbstractUnitRange, index)
@@ -1449,8 +1451,6 @@ function _setindex!(::IndexCartesian, A::AbstractArray, v, I::Vararg{Int,M}) whe
14491451
r
14501452
end
14511453

1452-
_unsetindex!(A::AbstractArray, i::Integer) = _unsetindex!(A, to_index(i))
1453-
14541454
"""
14551455
parent(A)
14561456
@@ -1556,8 +1556,7 @@ their component parts. A typical definition for an array that wraps a parent is
15561556
`Base.dataids(C::CustomArray) = dataids(C.parent)`.
15571557
"""
15581558
dataids(A::AbstractArray) = (UInt(objectid(A)),)
1559-
dataids(A::Memory) = (B = ccall(:jl_genericmemory_owner, Any, (Any,), A); (UInt(pointer(B isa typeof(A) ? B : A)),))
1560-
dataids(A::Array) = dataids(A.ref.mem)
1559+
dataids(A::Array) = (UInt(pointer(A)),)
15611560
dataids(::AbstractRange) = ()
15621561
dataids(x) = ()
15631562

0 commit comments

Comments
 (0)