Skip to content

Commit ee6203d

Browse files
committed
uninit is dead, long live undef
1 parent 6e0c299 commit ee6203d

File tree

162 files changed

+987
-984
lines changed

Some content is hidden

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

162 files changed

+987
-984
lines changed

NEWS.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ Language changes
120120
* `global const` declarations may no longer appear inside functions ([#12010]).
121121

122122
* Uninitialized `BitArray` constructors of the form `BitArray[{N}](shape...)` have been
123-
deprecated in favor of equivalents accepting `uninitialized` (an alias for
123+
deprecated in favor of equivalents accepting `undef` (an alias for
124124
`Uninitialized()`) as their first argument, as in
125-
`BitArray[{N}](uninitialized, shape...)`. For example, `BitVector(3)` is now
126-
`BitVector(uninitialized, 3)`, `BitMatrix((2, 4))` is now
127-
`BitMatrix(uninitialized, (2, 4))`, and `BitArray{3}(11, 13, 17)` is now
128-
`BitArray{3}(uninitialized, 11, 14, 17)` ([#24785]).
125+
`BitArray[{N}](undef, shape...)`. For example, `BitVector(3)` is now
126+
`BitVector(undef, 3)`, `BitMatrix((2, 4))` is now
127+
`BitMatrix(undef, (2, 4))`, and `BitArray{3}(11, 13, 17)` is now
128+
`BitArray{3}(undef, 11, 14, 17)` ([#24785]).
129129

130130
* Dispatch rules have been simplified:
131131
method matching is now determined exclusively by subtyping;
@@ -659,11 +659,11 @@ Deprecated or removed
659659

660660
* Uninitialized `Array` constructors of the form
661661
`Array[{T,N}](shape...)` have been deprecated in favor of equivalents
662-
accepting `uninitialized` (an alias for `Uninitialized()`) as their first argument,
663-
as in `Array[{T,N}](uninitialized, shape...)`. For example,
664-
`Vector(3)` is now `Vector(uninitialized, 3)`, `Matrix{Int}((2, 4))` is now,
665-
`Matrix{Int}(uninitialized, (2, 4))`, and `Array{Float32,3}(11, 13, 17)` is now
666-
`Array{Float32,3}(uninitialized, 11, 13, 17)` ([#24781]).
662+
accepting `uninit` (an alias for `Uninitialized()`) as their first argument,
663+
as in `Array[{T,N}](undef, shape...)`. For example,
664+
`Vector(3)` is now `Vector(undef, 3)`, `Matrix{Int}((2, 4))` is now,
665+
`Matrix{Int}(undef, (2, 4))`, and `Array{Float32,3}(11, 13, 17)` is now
666+
`Array{Float32,3}(undef, 11, 13, 17)` ([#24781]).
667667

668668
* `LinAlg.fillslots!` has been renamed `LinAlg.fillstored!` ([#25030]).
669669

@@ -689,11 +689,11 @@ Deprecated or removed
689689
output ([#12131]).
690690

691691
* Uninitialized `RowVector` constructors of the form `RowVector{T}(shape...)` have been
692-
deprecated in favor of equivalents accepting `uninitialized` (an alias for
692+
deprecated in favor of equivalents accepting `uninit` (an alias for
693693
`Uninitialized()`) as their first argument, as in
694-
`RowVector{T}(uninitialized, shape...)`. For example, `RowVector{Int}(3)` is now
695-
`RowVector{Int}(uninitialized, 3)`, and `RowVector{Float32}((1, 4))` is now
696-
`RowVector{Float32}(uninitialized, (1, 4))` ([#24786]).
694+
`RowVector{T}(undef, shape...)`. For example, `RowVector{Int}(3)` is now
695+
`RowVector{Int}(undef, 3)`, and `RowVector{Float32}((1, 4))` is now
696+
`RowVector{Float32}(undef, (1, 4))` ([#24786]).
697697

698698
* `writecsv(io, a; opts...)` has been deprecated in favor of
699699
`writedlm(io, a, ','; opts...)` ([#23529]).
@@ -756,7 +756,7 @@ Deprecated or removed
756756
in favor of `replace(s::AbstractString, pat => r; [count])` ([#25165]).
757757
Moreover, `count` cannot be negative anymore (use `typemax(Int)` instead ([#22325]).
758758

759-
* `read(io, type, dims)` is deprecated to `read!(io, Array{type}(uninitialized, dims))` ([#21450]).
759+
* `read(io, type, dims)` is deprecated to `read!(io, Array{type}(undef, dims))` ([#21450]).
760760

761761
* `read(::IO, ::Ref)` is now a method of `read!`, since it mutates its `Ref` argument ([#21592]).
762762

base/abstractarray.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ argument or as a series of integer arguments.
507507
508508
Custom AbstractArray subtypes may choose which specific array type is best-suited to return
509509
for the given element type and dimensionality. If they do not specialize this method, the
510-
default is an `Array{element_type}(uninitialized, dims...)`.
510+
default is an `Array{element_type}(undef, dims...)`.
511511
512512
For example, `similar(1:10, 1, 4)` returns an uninitialized `Array{Int,2}` since ranges are
513513
neither mutable nor support 2 dimensions:
@@ -546,7 +546,7 @@ similar(a::AbstractArray{T}, dims::DimOrInd...) where {T} = similar(a,
546546
similar(a::AbstractArray, ::Type{T}, dims::DimOrInd...) where {T} = similar(a, T, to_shape(dims))
547547
similar(a::AbstractArray, ::Type{T}, dims::NeedsShaping) where {T} = similar(a, T, to_shape(dims))
548548
# similar creates an Array by default
549-
similar(a::AbstractArray, ::Type{T}, dims::Dims{N}) where {T,N} = Array{T,N}(uninitialized, dims)
549+
similar(a::AbstractArray, ::Type{T}, dims::Dims{N}) where {T,N} = Array{T,N}(undef, dims)
550550

551551
to_shape(::Tuple{}) = ()
552552
to_shape(dims::Dims) = dims
@@ -571,7 +571,7 @@ argument. `storagetype` might be a type or a function.
571571
creates an array that "acts like" an `Array{Int}` (and might indeed be
572572
backed by one), but which is indexed identically to `A`. If `A` has
573573
conventional indexing, this will be identical to
574-
`Array{Int}(uninitialized, size(A))`, but if `A` has unconventional indexing then the
574+
`Array{Int}(undef, size(A))`, but if `A` has unconventional indexing then the
575575
indices of the result will match `A`.
576576
577577
similar(BitArray, (axes(A, 2),))
@@ -1221,10 +1221,10 @@ vcat(X::T...) where {T<:Number} = T[ X[i] for i=1:length(X) ]
12211221
hcat(X::T...) where {T} = T[ X[j] for i=1:1, j=1:length(X) ]
12221222
hcat(X::T...) where {T<:Number} = T[ X[j] for i=1:1, j=1:length(X) ]
12231223

1224-
vcat(X::Number...) = hvcat_fill(Vector{promote_typeof(X...)}(uninitialized, length(X)), X)
1225-
hcat(X::Number...) = hvcat_fill(Matrix{promote_typeof(X...)}(uninitialized, 1,length(X)), X)
1226-
typed_vcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Vector{T}(uninitialized, length(X)), X)
1227-
typed_hcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Matrix{T}(uninitialized, 1,length(X)), X)
1224+
vcat(X::Number...) = hvcat_fill(Vector{promote_typeof(X...)}(undef, length(X)), X)
1225+
hcat(X::Number...) = hvcat_fill(Matrix{promote_typeof(X...)}(undef, 1,length(X)), X)
1226+
typed_vcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Vector{T}(undef, length(X)), X)
1227+
typed_hcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Matrix{T}(undef, 1,length(X)), X)
12281228

12291229
vcat(V::AbstractVector...) = typed_vcat(promote_eltype(V...), V...)
12301230
vcat(V::AbstractVector{T}...) where {T} = typed_vcat(T, V...)
@@ -1316,7 +1316,7 @@ cat_size(A::AbstractArray, d) = size(A, d)
13161316
cat_indices(A, d) = OneTo(1)
13171317
cat_indices(A::AbstractArray, d) = axes(A, d)
13181318

1319-
cat_similar(A, T, shape) = Array{T}(uninitialized, shape)
1319+
cat_similar(A, T, shape) = Array{T}(undef, shape)
13201320
cat_similar(A::AbstractArray, T, shape) = similar(A, T, shape)
13211321

13221322
cat_shape(dims, shape::Tuple) = shape
@@ -1365,7 +1365,7 @@ end
13651365

13661366
function _cat(A, shape::NTuple{N}, catdims, X...) where N
13671367
offsets = zeros(Int, N)
1368-
inds = Vector{UnitRange{Int}}(uninitialized, N)
1368+
inds = Vector{UnitRange{Int}}(undef, N)
13691369
concat = copyto!(zeros(Bool, N), catdims)
13701370
for x in X
13711371
for i = 1:N
@@ -1595,7 +1595,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, xs::T...) where T<:Number
15951595
nr = length(rows)
15961596
nc = rows[1]
15971597

1598-
a = Matrix{T}(uninitialized, nr, nc)
1598+
a = Matrix{T}(undef, nr, nc)
15991599
if length(a) != length(xs)
16001600
throw(ArgumentError("argument count does not match specified shape (expected $(length(a)), got $(length(xs)))"))
16011601
end
@@ -1639,12 +1639,12 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...) where T
16391639
if nr*nc != len
16401640
throw(ArgumentError("argument count $(len) does not match specified shape $((nr,nc))"))
16411641
end
1642-
hvcat_fill(Matrix{T}(uninitialized, nr, nc), xs)
1642+
hvcat_fill(Matrix{T}(undef, nr, nc), xs)
16431643
end
16441644

16451645
function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as...) where T
16461646
nbr = length(rows) # number of block rows
1647-
rs = Vector{Any}(uninitialized, nbr)
1647+
rs = Vector{Any}(undef, nbr)
16481648
a = 1
16491649
for i = 1:nbr
16501650
rs[i] = typed_hcat(T, as[a:a-1+rows[i]]...)

base/abstractdict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ mutable struct IdDict{K,V} <: AbstractDict{K,V}
543543
ht::Vector{Any}
544544
count::Int
545545
ndel::Int
546-
IdDict{K,V}() where {K, V} = new{K,V}(Vector{Any}(uninitialized, 32), 0, 0)
546+
IdDict{K,V}() where {K, V} = new{K,V}(Vector{Any}(undef, 32), 0, 0)
547547

548548
function IdDict{K,V}(itr) where {K, V}
549549
d = IdDict{K,V}()

base/array.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function vect(X...)
104104
T = promote_typeof(X...)
105105
#T[ X[i] for i=1:length(X) ]
106106
# TODO: this is currently much faster. should figure out why. not clear.
107-
return copyto!(Vector{T}(uninitialized, length(X)), X)
107+
return copyto!(Vector{T}(undef, length(X)), X)
108108
end
109109

110110
size(a::Array, d) = arraysize(a, d)
@@ -259,14 +259,14 @@ end
259259

260260
## Constructors ##
261261

262-
similar(a::Array{T,1}) where {T} = Vector{T}(uninitialized, size(a,1))
263-
similar(a::Array{T,2}) where {T} = Matrix{T}(uninitialized, size(a,1), size(a,2))
264-
similar(a::Array{T,1}, S::Type) where {T} = Vector{S}(uninitialized, size(a,1))
265-
similar(a::Array{T,2}, S::Type) where {T} = Matrix{S}(uninitialized, size(a,1), size(a,2))
266-
similar(a::Array{T}, m::Int) where {T} = Vector{T}(uninitialized, m)
267-
similar(a::Array, T::Type, dims::Dims{N}) where {N} = Array{T,N}(uninitialized, dims)
268-
similar(a::Array{T}, dims::Dims{N}) where {T,N} = Array{T,N}(uninitialized, dims)
269-
similar(::Type{T}, shape::Tuple) where {T<:Array} = T(uninitialized, to_shape(shape))
262+
similar(a::Array{T,1}) where {T} = Vector{T}(undef, size(a,1))
263+
similar(a::Array{T,2}) where {T} = Matrix{T}(undef, size(a,1), size(a,2))
264+
similar(a::Array{T,1}, S::Type) where {T} = Vector{S}(undef, size(a,1))
265+
similar(a::Array{T,2}, S::Type) where {T} = Matrix{S}(undef, size(a,1), size(a,2))
266+
similar(a::Array{T}, m::Int) where {T} = Vector{T}(undef, m)
267+
similar(a::Array, T::Type, dims::Dims{N}) where {N} = Array{T,N}(undef, dims)
268+
similar(a::Array{T}, dims::Dims{N}) where {T,N} = Array{T,N}(undef, dims)
269+
similar(::Type{T}, shape::Tuple) where {T<:Array} = T(undef, to_shape(shape))
270270

271271
# T[x...] constructs Array{T,1}
272272
"""
@@ -291,20 +291,20 @@ julia> getindex(Int8, 1, 2, 3)
291291
```
292292
"""
293293
function getindex(::Type{T}, vals...) where T
294-
a = Vector{T}(uninitialized, length(vals))
294+
a = Vector{T}(undef, length(vals))
295295
@inbounds for i = 1:length(vals)
296296
a[i] = vals[i]
297297
end
298298
return a
299299
end
300300

301301
getindex(::Type{T}) where {T} = (@_inline_meta; Vector{T}())
302-
getindex(::Type{T}, x) where {T} = (@_inline_meta; a = Vector{T}(uninitialized, 1); @inbounds a[1] = x; a)
303-
getindex(::Type{T}, x, y) where {T} = (@_inline_meta; a = Vector{T}(uninitialized, 2); @inbounds (a[1] = x; a[2] = y); a)
304-
getindex(::Type{T}, x, y, z) where {T} = (@_inline_meta; a = Vector{T}(uninitialized, 3); @inbounds (a[1] = x; a[2] = y; a[3] = z); a)
302+
getindex(::Type{T}, x) where {T} = (@_inline_meta; a = Vector{T}(undef, 1); @inbounds a[1] = x; a)
303+
getindex(::Type{T}, x, y) where {T} = (@_inline_meta; a = Vector{T}(undef, 2); @inbounds (a[1] = x; a[2] = y); a)
304+
getindex(::Type{T}, x, y, z) where {T} = (@_inline_meta; a = Vector{T}(undef, 3); @inbounds (a[1] = x; a[2] = y; a[3] = z); a)
305305

306306
function getindex(::Type{Any}, @nospecialize vals...)
307-
a = Vector{Any}(uninitialized, length(vals))
307+
a = Vector{Any}(undef, length(vals))
308308
@inbounds for i = 1:length(vals)
309309
a[i] = vals[i]
310310
end
@@ -345,8 +345,8 @@ julia> fill(1.0, (5,5))
345345
If `x` is an object reference, all elements will refer to the same object. `fill(Foo(),
346346
dims)` will return an array filled with the result of evaluating `Foo()` once.
347347
"""
348-
fill(v, dims::Dims) = fill!(Array{typeof(v)}(uninitialized, dims), v)
349-
fill(v, dims::Integer...) = fill!(Array{typeof(v)}(uninitialized, dims...), v)
348+
fill(v, dims::Dims) = fill!(Array{typeof(v)}(undef, dims), v)
349+
fill(v, dims::Integer...) = fill!(Array{typeof(v)}(undef, dims...), v)
350350

351351
"""
352352
zeros([T=Float64,] dims...)
@@ -390,7 +390,7 @@ function ones end
390390

391391
for (fname, felt) in ((:zeros, :zero), (:ones, :one))
392392
@eval begin
393-
$fname(::Type{T}, dims::NTuple{N, Any}) where {T, N} = fill!(Array{T,N}(uninitialized, convert(Dims, dims)::Dims), $felt(T))
393+
$fname(::Type{T}, dims::NTuple{N, Any}) where {T, N} = fill!(Array{T,N}(undef, convert(Dims, dims)::Dims), $felt(T))
394394
$fname(dims::Tuple) = ($fname)(Float64, dims)
395395
$fname(::Type{T}, dims...) where {T} = $fname(T, dims)
396396
$fname(dims...) = $fname(dims)
@@ -422,7 +422,7 @@ promote_rule(a::Type{Array{T,n}}, b::Type{Array{S,n}}) where {T,n,S} = el_same(p
422422

423423
if nameof(@__MODULE__) === :Base # avoid method overwrite
424424
# constructors should make copies
425-
Array{T,N}(x::AbstractArray{S,N}) where {T,N,S} = copyto!(Array{T,N}(uninitialized, size(x)), x)
425+
Array{T,N}(x::AbstractArray{S,N}) where {T,N,S} = copyto!(Array{T,N}(undef, size(x)), x)
426426
AbstractArray{T,N}(A::AbstractArray{S,N}) where {T,N,S} = copyto!(similar(A,T), A)
427427
end
428428

@@ -445,7 +445,7 @@ julia> collect(Float64, 1:2:5)
445445
"""
446446
collect(::Type{T}, itr) where {T} = _collect(T, itr, IteratorSize(itr))
447447

448-
_collect(::Type{T}, itr, isz::HasLength) where {T} = copyto!(Vector{T}(uninitialized, Int(length(itr)::Integer)), itr)
448+
_collect(::Type{T}, itr, isz::HasLength) where {T} = copyto!(Vector{T}(undef, Int(length(itr)::Integer)), itr)
449449
_collect(::Type{T}, itr, isz::HasShape) where {T} = copyto!(similar(Array{T}, axes(itr)), itr)
450450
function _collect(::Type{T}, itr, isz::SizeUnknown) where T
451451
a = Vector{T}()
@@ -499,11 +499,11 @@ function _collect(cont, itr, ::HasEltype, isz::SizeUnknown)
499499
return a
500500
end
501501

502-
_collect_indices(::Tuple{}, A) = copyto!(Array{eltype(A),0}(uninitialized), A)
502+
_collect_indices(::Tuple{}, A) = copyto!(Array{eltype(A),0}(undef), A)
503503
_collect_indices(indsA::Tuple{Vararg{OneTo}}, A) =
504-
copyto!(Array{eltype(A)}(uninitialized, length.(indsA)), A)
504+
copyto!(Array{eltype(A)}(undef, length.(indsA)), A)
505505
function _collect_indices(indsA, A)
506-
B = Array{eltype(A)}(uninitialized, length.(indsA))
506+
B = Array{eltype(A)}(undef, length.(indsA))
507507
copyto!(B, CartesianIndices(axes(B)), A, CartesianIndices(indsA))
508508
end
509509

@@ -535,7 +535,7 @@ else
535535
end
536536
end
537537

538-
_array_for(::Type{T}, itr, ::HasLength) where {T} = Vector{T}(uninitialized, Int(length(itr)::Integer))
538+
_array_for(::Type{T}, itr, ::HasLength) where {T} = Vector{T}(undef, Int(length(itr)::Integer))
539539
_array_for(::Type{T}, itr, ::HasShape) where {T} = similar(Array{T}, axes(itr))::Array{T}
540540

541541
function collect(itr::Generator)
@@ -1464,7 +1464,7 @@ function vcat(arrays::Vector{T}...) where T
14641464
for a in arrays
14651465
n += length(a)
14661466
end
1467-
arr = Vector{T}(uninitialized, n)
1467+
arr = Vector{T}(undef, n)
14681468
ptr = pointer(arr)
14691469
if isbits(T)
14701470
elsz = Core.sizeof(T)
@@ -1966,7 +1966,7 @@ end
19661966
# Allocating result upfront is faster (possible only when collection can be iterated twice)
19671967
function findall(A::AbstractArray{Bool})
19681968
n = count(A)
1969-
I = Vector{eltype(keys(A))}(uninitialized, n)
1969+
I = Vector{eltype(keys(A))}(undef, n)
19701970
cnt = 1
19711971
for (i,a) in pairs(A)
19721972
if a

base/asyncmap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ end
246246

247247
# Special handling for some types.
248248
function asyncmap(f, s::AbstractString; kwargs...)
249-
s2 = Vector{Char}(uninitialized, length(s))
249+
s2 = Vector{Char}(undef, length(s))
250250
asyncmap!(f, s2, s; kwargs...)
251251
return String(s2)
252252
end

0 commit comments

Comments
 (0)