Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace Array{...}(shape...)-like calls in base/[m-r]* #24760

Merged
merged 1 commit into from
Nov 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ elseif Sys.isapple()
path_basename = String(basename(path))
local casepreserved_basename
header_size = 12
buf = Vector{UInt8}(length(path_basename) + header_size + 1)
buf = Vector{UInt8}(uninitialized, length(path_basename) + header_size + 1)
while true
ret = ccall(:getattrlist, Cint,
(Cstring, Ptr{Void}, Ptr{Void}, Csize_t, Culong),
Expand Down
2 changes: 1 addition & 1 deletion base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function method_argnames(m::Method)
if !isdefined(m, :source) && isdefined(m, :generator)
return m.generator.argnames
end
argnames = Vector{Any}(m.nargs)
argnames = Vector{Any}(uninitialized, m.nargs)
ccall(:jl_fill_argnames, Void, (Any, Any), m.source, argnames)
return argnames
end
Expand Down
10 changes: 5 additions & 5 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ _countnz(x) = x != 0
@generated function findn(A::AbstractArray{T,N}) where {T,N}
quote
nnzA = count(_countnz, A)
@nexprs $N d->(I_d = Vector{Int}(nnzA))
@nexprs $N d->(I_d = Vector{Int}(uninitialized, nnzA))
k = 1
@nloops $N i A begin
@inbounds if (@nref $N A i) != zero(T)
Expand Down Expand Up @@ -1000,13 +1000,13 @@ julia> fill!(A, 2.)
2.0 2.0 2.0
2.0 2.0 2.0

julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(3), a); a[1] = 2; A
julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(uninitialized, 3), a); a[1] = 2; A
3-element Array{Array{Int64,1},1}:
[2, 1, 1]
[2, 1, 1]
[2, 1, 1]

julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(3), f())
julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(uninitialized, 3), f())
3-element Array{Int64,1}:
1
1
Expand Down Expand Up @@ -1430,7 +1430,7 @@ end
@generated function findn(B::BitArray{N}) where N
quote
nnzB = count(B)
I = ntuple(x->Vector{Int}(nnzB), Val($N))
I = ntuple(x->Vector{Int}(uninitialized, nnzB), Val($N))
if nnzB > 0
count = 1
@nloops $N i B begin
Expand Down Expand Up @@ -1667,7 +1667,7 @@ julia> extrema(A, (1,2))
function extrema(A::AbstractArray, dims)
sz = [size(A)...]
sz[[dims...]] = 1
B = Array{Tuple{eltype(A),eltype(A)}}(sz...)
B = Array{Tuple{eltype(A),eltype(A)}}(uninitialized, sz...)
return extrema!(B, A)
end

Expand Down
2 changes: 1 addition & 1 deletion base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Return the current user's home directory.
"""
function homedir()
path_max = 1024
buf = Vector{UInt8}(path_max)
buf = Vector{UInt8}(uninitialized, path_max)
sz = Ref{Csize_t}(path_max + 1)
while true
rc = ccall(:uv_os_homedir, Cint, (Ptr{UInt8}, Ptr{Csize_t}), buf, sz)
Expand Down
2 changes: 1 addition & 1 deletion base/pcre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ free_match_context(context) =
ccall((:pcre2_match_context_free_8, PCRE_LIB), Void, (Ptr{Void},), context)

function err_message(errno)
buffer = Vector{UInt8}(256)
buffer = Vector{UInt8}(uninitialized, 256)
ccall((:pcre2_get_error_message_8, PCRE_LIB), Void,
(Int32, Ptr{UInt8}, Csize_t), errno, buffer, sizeof(buffer))
Base.@gc_preserve buffer unsafe_string(pointer(buffer))
Expand Down
4 changes: 2 additions & 2 deletions base/pkg/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ end
const PackageState = Union{Void,VersionNumber}

function diff(have::Dict, want::Dict, avail::Dict, fixed::Dict)
change = Vector{Tuple{String,Tuple{PackageState,PackageState}}}(0)
remove = Vector{Tuple{String,Tuple{PackageState,PackageState}}}(0)
change = Vector{Tuple{String,Tuple{PackageState,PackageState}}}()
remove = Vector{Tuple{String,Tuple{PackageState,PackageState}}}()

for pkg in collect(union(keys(have),keys(want)))
h, w = haskey(have,pkg), haskey(want,pkg)
Expand Down
4 changes: 2 additions & 2 deletions base/pkg/resolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function sanity_check(deps::Dict{String,Dict{VersionNumber,Available}},
end
end

vers = Vector{Tuple{String,VersionNumber,VersionNumber}}(0)
vers = Vector{Tuple{String,VersionNumber,VersionNumber}}()
for (p,d) in deps, vn in keys(d)
lvns = VersionNumber[Iterators.filter(vn2->(vn2>vn), keys(d))...]
nvn = isempty(lvns) ? typemax(VersionNumber) : minimum(lvns)
Expand All @@ -88,7 +88,7 @@ function sanity_check(deps::Dict{String,Dict{VersionNumber,Available}},

checked = falses(nv)

problematic = Vector{Tuple{String,VersionNumber,String}}(0)
problematic = Vector{Tuple{String,VersionNumber,String}}()
i = 1
psl = 0
for (p,vn,nvn) in vers
Expand Down
6 changes: 3 additions & 3 deletions base/pkg/resolve/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mutable struct Interface
pdict = Dict{String,Int}(pkgs[i] => i for i = 1:np)

# generate spp and pvers
spp = Vector{Int}(np)
spp = Vector{Int}(uninitialized, np)

pvers = [VersionNumber[] for i = 1:np]

Expand Down Expand Up @@ -86,7 +86,7 @@ mutable struct Interface
for p0 = 1:np
pvers0 = pvers[p0]
spp0 = spp[p0]
vweight0 = vweight[p0] = Vector{VersionWeight}(spp0)
vweight0 = vweight[p0] = Vector{VersionWeight}(uninitialized, spp0)
for v0 = 1:spp0-1
vweight0[v0] = VersionWeight(pvers0[v0])
end
Expand Down Expand Up @@ -240,7 +240,7 @@ function enforce_optimality!(sol::Vector{Int}, interface::Interface)

# prepare some useful structures
# pdeps[p0][v0] has all dependencies of package p0 version v0
pdeps = [Vector{Requires}(spp[p0]-1) for p0 = 1:np]
pdeps = [Vector{Requires}(uninitialized, spp[p0]-1) for p0 = 1:np]
# prevdeps[p1][p0][v0] is the VersionSet of package p1 which package p0 version v0
# depends upon
prevdeps = [Dict{Int,Dict{Int,VersionSet}}() for p0 = 1:np]
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/resolve/maxsum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function getsolution(msgs::Messages)

fld = msgs.fld
np = length(fld)
sol = Vector{Int}(np)
sol = Vector{Int}(uninitialized, np)
for p0 = 1:np
fld0 = fld[p0]
s0 = indmax(fld0)
Expand Down
4 changes: 2 additions & 2 deletions base/pkg/resolve/versionweight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for f in (:-, :+)
l0 = min(la, lb)
l1 = max(la, lb)
ld = la - lb
rv = Vector{T}(l1)
rv = Vector{T}(uninitialized, l1)
rf = ($f)(a.rest, b.rest)
@inbounds for i = 1:l0
rv[i] = ($f)(av[i], bv[i])
Expand Down Expand Up @@ -109,7 +109,7 @@ function VWPreBuild(ispre::Bool, desc::Tuple{Vararg{Union{Integer,String}}})
isempty(desc) && return _vwprebuild_zero
desc == ("",) && return VWPreBuild(ispre ? -1 : 1, HierarchicalValue(VWPreBuildItem[]))
nonempty = ispre ? -1 : 0
w = Vector{VWPreBuildItem}(length(desc))
w = Vector{VWPreBuildItem}(uninitialized, length(desc))
i = 1
@inbounds for item in desc
w[i] = VWPreBuildItem(item)
Expand Down
12 changes: 6 additions & 6 deletions base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ function typejoin(@nospecialize(a), @nospecialize(b))
lbf, bfixed = full_va_len(bp)
if laf < lbf
if isvarargtype(ap[lar]) && !afixed
c = Vector{Any}(laf)
c = Vector{Any}(uninitialized, laf)
c[laf] = Vararg{typejoin(unwrapva(ap[lar]), tailjoin(bp,laf))}
n = laf-1
else
c = Vector{Any}(laf+1)
c = Vector{Any}(uninitialized, laf+1)
c[laf+1] = Vararg{tailjoin(bp,laf+1)}
n = laf
end
elseif lbf < laf
if isvarargtype(bp[lbr]) && !bfixed
c = Vector{Any}(lbf)
c = Vector{Any}(uninitialized, lbf)
c[lbf] = Vararg{typejoin(unwrapva(bp[lbr]), tailjoin(ap,lbf))}
n = lbf-1
else
c = Vector{Any}(lbf+1)
c = Vector{Any}(uninitialized, lbf+1)
c[lbf+1] = Vararg{tailjoin(ap,lbf+1)}
n = lbf
end
else
c = Vector{Any}(laf)
c = Vector{Any}(uninitialized, laf)
n = laf
end
for i = 1:n
Expand All @@ -86,7 +86,7 @@ function typejoin(@nospecialize(a), @nospecialize(b))
if n == 0
return aprimary
end
p = Vector{Any}(n)
p = Vector{Any}(uninitialized, n)
for i = 1:n
ai, bi = a.parameters[i], b.parameters[i]
if ai === bi || (isa(ai,Type) && isa(bi,Type) && typeseq(ai,bi))
Expand Down
2 changes: 1 addition & 1 deletion base/random/RNGs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if Sys.iswindows()
struct RandomDevice <: AbstractRNG
buffer::Vector{UInt128}

RandomDevice() = new(Vector{UInt128}(1))
RandomDevice() = new(Vector{UInt128}(uninitialized, 1))
end

function rand(rd::RandomDevice, T::BoolBitIntegerType)
Expand Down
2 changes: 1 addition & 1 deletion base/random/dSFMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function dsfmt_jump(s::DSFMT_state, jp::AbstractString)
index = val[nval - 1]
work = zeros(Int32, JN32)
rwork = reinterpret(UInt64, work)
dsfmt = Vector{UInt64}(nval >> 1)
dsfmt = Vector{UInt64}(uninitialized, nval >> 1)
ccall(:memcpy, Ptr{Void}, (Ptr{UInt64}, Ptr{Int32}, Csize_t),
dsfmt, val, (nval - 1) * sizeof(Int32))
dsfmt[end] = UInt64(N*2)
Expand Down
12 changes: 6 additions & 6 deletions base/random/generation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct BigFloatRandGenerator

function BigFloatRandGenerator(prec::Int=precision(BigFloat))
nlimbs = (prec-1) ÷ bits_in_Limb + 1
limbs = Vector{Limb}(nlimbs)
limbs = Vector{Limb}(uninitialized, nlimbs)
shift = nlimbs * bits_in_Limb - prec
new(prec, nlimbs, limbs, shift)
end
Expand Down Expand Up @@ -131,7 +131,7 @@ rand( dims::Dims) = rand(GLOBAL_RNG, dims)
rand(r::AbstractRNG, dims::Integer...) = rand(r, Dims(dims))
rand( dims::Integer...) = rand(Dims(dims))

rand(r::AbstractRNG, ::Type{T}, dims::Dims) where {T} = rand!(r, Array{T}(dims))
rand(r::AbstractRNG, ::Type{T}, dims::Dims) where {T} = rand!(r, Array{T}(uninitialized, dims))
rand( ::Type{T}, dims::Dims) where {T} = rand(GLOBAL_RNG, T, dims)

rand(r::AbstractRNG, ::Type{T}, d::Integer, dims::Integer...) where {T} =
Expand Down Expand Up @@ -317,7 +317,7 @@ end
rand!(A::AbstractArray, r::AbstractArray) = rand!(GLOBAL_RNG, A, r)

rand(rng::AbstractRNG, r::AbstractArray{T}, dims::Dims) where {T} =
rand!(rng, Array{T}(dims), r)
rand!(rng, Array{T}(uninitialized, dims), r)
rand( r::AbstractArray, dims::Dims) = rand(GLOBAL_RNG, r, dims)
rand(rng::AbstractRNG, r::AbstractArray, dims::Integer...) = rand(rng, r, Dims(dims))
rand( r::AbstractArray, dims::Integer...) = rand(GLOBAL_RNG, r, Dims(dims))
Expand Down Expand Up @@ -375,9 +375,9 @@ rand!(r::AbstractRNG, A::AbstractArray, s::Union{Associative,AbstractSet}) =
rand!(A::AbstractArray, s::Union{Associative,AbstractSet}) = rand!(GLOBAL_RNG, A, s)

rand(r::AbstractRNG, s::Associative{K,V}, dims::Dims) where {K,V} =
rand!(r, Array{Pair{K,V}}(dims), s)
rand!(r, Array{Pair{K,V}}(uninitialized, dims), s)

rand(r::AbstractRNG, s::AbstractSet{T}, dims::Dims) where {T} = rand!(r, Array{T}(dims), s)
rand(r::AbstractRNG, s::AbstractSet{T}, dims::Dims) where {T} = rand!(r, Array{T}(uninitialized, dims), s)
rand(r::AbstractRNG, s::Union{Associative,AbstractSet}, dims::Integer...) =
rand(r, s, Dims(dims))
rand(s::Union{Associative,AbstractSet}, dims::Integer...) = rand(GLOBAL_RNG, s, Dims(dims))
Expand Down Expand Up @@ -408,7 +408,7 @@ rand(s::AbstractString) = rand(GLOBAL_RNG, s)
rand!(rng::AbstractRNG, A::AbstractArray, str::AbstractString) = rand!(rng, A, collect(str))
rand!(A::AbstractArray, str::AbstractString) = rand!(GLOBAL_RNG, A, str)
rand(rng::AbstractRNG, str::AbstractString, dims::Dims) =
rand!(rng, Array{eltype(str)}(dims), str)
rand!(rng, Array{eltype(str)}(uninitialized, dims), str)

rand(rng::AbstractRNG, str::AbstractString, d::Integer, dims::Integer...) =
rand(rng, str, Dims((d, dims...)))
Expand Down
8 changes: 4 additions & 4 deletions base/random/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ julia> randperm(MersenneTwister(1234), 4)
3
```
"""
randperm(r::AbstractRNG, n::Integer) = randperm!(r, Vector{Int}(n))
randperm(r::AbstractRNG, n::Integer) = randperm!(r, Vector{Int}(uninitialized, n))
randperm(n::Integer) = randperm(GLOBAL_RNG, n)

"""
Expand All @@ -263,7 +263,7 @@ optional `rng` argument specifies a random number generator (see

# Examples
```jldoctest
julia> randperm!(MersenneTwister(1234), Vector{Int}(4))
julia> randperm!(MersenneTwister(1234), Vector{Int}(uninitialized, 4))
4-element Array{Int64,1}:
2
1
Expand Down Expand Up @@ -311,7 +311,7 @@ julia> randcycle(MersenneTwister(1234), 6)
2
```
"""
randcycle(r::AbstractRNG, n::Integer) = randcycle!(r, Vector{Int}(n))
randcycle(r::AbstractRNG, n::Integer) = randcycle!(r, Vector{Int}(uninitialized, n))
randcycle(n::Integer) = randcycle(GLOBAL_RNG, n)

"""
Expand All @@ -323,7 +323,7 @@ The optional `rng` argument specifies a random number generator, see

# Examples
```jldoctest
julia> randcycle!(MersenneTwister(1234), Vector{Int}(6))
julia> randcycle!(MersenneTwister(1234), Vector{Int}(uninitialized, 6))
6-element Array{Int64,1}:
3
5
Expand Down
4 changes: 2 additions & 2 deletions base/random/normal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ for randfun in [:randn, :randexp]
$randfun!(A::AbstractArray) = $randfun!(GLOBAL_RNG, A)

# generating arrays
$randfun(rng::AbstractRNG, ::Type{T}, dims::Dims ) where {T} = $randfun!(rng, Array{T}(dims))
$randfun(rng::AbstractRNG, ::Type{T}, dims::Dims ) where {T} = $randfun!(rng, Array{T}(uninitialized, dims))
# Note that this method explicitly does not define $randfun(rng, T),
# in order to prevent an infinite recursion.
$randfun(rng::AbstractRNG, ::Type{T}, dim1::Integer, dims::Integer...) where {T} = $randfun!(rng, Array{T}(dim1, dims...))
$randfun(rng::AbstractRNG, ::Type{T}, dim1::Integer, dims::Integer...) where {T} = $randfun!(rng, Array{T}(uninitialized, dim1, dims...))
$randfun( ::Type{T}, dims::Dims ) where {T} = $randfun(GLOBAL_RNG, T, dims)
$randfun( ::Type{T}, dims::Integer... ) where {T} = $randfun(GLOBAL_RNG, T, dims...)
$randfun(rng::AbstractRNG, dims::Dims ) = $randfun(rng, Float64, dims)
Expand Down
2 changes: 1 addition & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ function vcat(rs::AbstractRange{T}...) where T
for ra in rs
n += length(ra)
end
a = Vector{T}(n)
a = Vector{T}(uninitialized, n)
i = 1
for ra in rs, x in ra
@inbounds a[i] = x
Expand Down
4 changes: 2 additions & 2 deletions base/refpointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ function Ref{P}(a::Array{T}) where P<:Union{Ptr,Cwstring,Cstring} where T
# this Array already has the right memory layout for the requested Ref
return RefArray(a,1,false) # root something, so that this function is type-stable
else
ptrs = Vector{P}(length(a)+1)
roots = Vector{Any}(length(a))
ptrs = Vector{P}(uninitialized, length(a)+1)
roots = Vector{Any}(uninitialized, length(a))
for i = 1:length(a)
root = cconvert(P, a[i])
ptrs[i] = unsafe_convert(P, root)::P
Expand Down
2 changes: 1 addition & 1 deletion base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ function keymap_merge(target,source)
for key in setdiff(keys(source), keys(direct_keys))
# We first resolve redirects in the source
value = source[key]
visited = Vector{Any}(0)
visited = Vector{Any}()
while isa(value, Union{Char,AbstractString})
value = normalize_key(value)
if value in visited
Expand Down
4 changes: 2 additions & 2 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function show(io::IO, ::MIME"text/plain", t::Associative{K,V}) where {K,V}
rows -= 1 # Subtract the summary

# determine max key width to align the output, caching the strings
ks = Vector{AbstractString}(min(rows, length(t)))
vs = Vector{AbstractString}(min(rows, length(t)))
ks = Vector{AbstractString}(uninitialized, min(rows, length(t)))
vs = Vector{AbstractString}(uninitialized, min(rows, length(t)))
keylen = 0
vallen = 0
for (i, (k, v)) in enumerate(t)
Expand Down
2 changes: 1 addition & 1 deletion base/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Rounding

let fenv_consts = Vector{Cint}(9)
let fenv_consts = Vector{Cint}(uninitialized, 9)
ccall(:jl_get_fenv_consts, Void, (Ptr{Cint},), fenv_consts)
global const JL_FE_INEXACT = fenv_consts[1]
global const JL_FE_UNDERFLOW = fenv_consts[2]
Expand Down