Skip to content

Commit b1f53ec

Browse files
authored
Base: eliminate unused variables (#59727)
Some more unused variables I found while working on #59202 by JETLS.
1 parent 47908c8 commit b1f53ec

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
lines changed

base/abstractarray.jl

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,8 @@ typed_hcat(::Type{T}) where {T} = Vector{T}()
16841684
## cat: special cases
16851685
vcat(X::T...) where {T} = T[ X[i] for i=eachindex(X) ]
16861686
vcat(X::T...) where {T<:Number} = T[ X[i] for i=eachindex(X) ]
1687-
hcat(X::T...) where {T} = T[ X[j] for i=1:1, j=eachindex(X) ]
1688-
hcat(X::T...) where {T<:Number} = T[ X[j] for i=1:1, j=eachindex(X) ]
1687+
hcat(X::T...) where {T} = T[ X[j] for _=1:1, j=eachindex(X) ]
1688+
hcat(X::T...) where {T<:Number} = T[ X[j] for _=1:1, j=eachindex(X) ]
16891689

16901690
vcat(X::Number...) = hvcat_fill!(Vector{promote_typeof(X...)}(undef, length(X)), X)
16911691
hcat(X::Number...) = hvcat_fill!(Matrix{promote_typeof(X...)}(undef, 1,length(X)), X)
@@ -1827,7 +1827,7 @@ function cat_shape(dims, shapes::Tuple)
18271827
return out_shape
18281828
end
18291829
# The new way to compute the shape (more inferable than combining cat_size & cat_shape, due to Varargs + issue#36454)
1830-
cat_size_shape(dims) = ntuple(zero, Val(length(dims)))
1830+
cat_size_shape(dims) = ntuple(Returns(0), Val(length(dims)))
18311831
@inline cat_size_shape(dims, X, tail...) = _cat_size_shape(dims, _cshp(1, dims, (), cat_size(X)), tail...)
18321832
_cat_size_shape(dims, shape) = shape
18331833
@inline _cat_size_shape(dims, shape, X, tail...) = _cat_size_shape(dims, _cshp(1, dims, shape, cat_size(X)), tail...)
@@ -1881,7 +1881,7 @@ end
18811881
@inline cat_t(::Type{T}, X...; dims) where {T} = _cat_t(dims, T, X...)
18821882

18831883
# Why isn't this called `__cat!`?
1884-
__cat(A, shape, catdims, X...) = __cat_offset!(A, shape, catdims, ntuple(zero, length(shape)), X...)
1884+
__cat(A, shape, catdims, X...) = __cat_offset!(A, shape, catdims, ntuple(Returns(0), length(shape)), X...)
18851885

18861886
function __cat_offset!(A, shape, catdims, offsets, x, X...)
18871887
# splitting the "work" on x from X... may reduce latency (fewer costly specializations)
@@ -2388,13 +2388,13 @@ _typed_hvncat_0d_only_one() =
23882388
function _typed_hvncat(::Type{T}, ::Val{N}) where {T, N}
23892389
N < 0 &&
23902390
throw(ArgumentError("concatenation dimension must be non-negative"))
2391-
return Array{T, N}(undef, ntuple(x -> 0, Val(N)))
2391+
return Array{T, N}(undef, ntuple(Returns(0), Val(N)))
23922392
end
23932393

23942394
function _typed_hvncat(T::Type, ::Val{N}, xs::Number...) where N
23952395
N < 0 &&
23962396
throw(ArgumentError("concatenation dimension must be non-negative"))
2397-
A = cat_similar(xs[1], T, (ntuple(x -> 1, Val(N - 1))..., length(xs)))
2397+
A = cat_similar(xs[1], T, (ntuple(Returns(1), Val(N - 1))..., length(xs)))
23982398
hvncat_fill!(A, false, xs)
23992399
return A
24002400
end
@@ -2408,7 +2408,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
24082408
throw(ArgumentError("concatenation dimension must be non-negative"))
24092409
for a as
24102410
ndims(a) <= N || all(x -> size(a, x) == 1, (N + 1):ndims(a)) ||
2411-
return _typed_hvncat(T, (ntuple(x -> 1, Val(N - 1))..., length(as), 1), false, as...)
2411+
return _typed_hvncat(T, (ntuple(Returns(1), Val(N - 1))..., length(as), 1), false, as...)
24122412
# the extra 1 is to avoid an infinite cycle
24132413
end
24142414

@@ -2423,7 +2423,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
24232423
end
24242424
end
24252425

2426-
A = cat_similar(as[1], T, (ntuple(d -> size(as[1], d), N - 1)..., Ndim, ntuple(x -> 1, nd - N)...))
2426+
A = cat_similar(as[1], T, (ntuple(d -> size(as[1], d), N - 1)..., Ndim, ntuple(Returns(1), nd - N)...))
24272427
k = 1
24282428
for a as
24292429
for i eachindex(a)
@@ -2450,7 +2450,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
24502450
end
24512451
end
24522452

2453-
A = Array{T, nd}(undef, ntuple(x -> 1, Val(N - 1))..., Ndim, ntuple(x -> 1, nd - N)...)
2453+
A = Array{T, nd}(undef, ntuple(Returns(1), Val(N - 1))..., Ndim, ntuple(Returns(1), nd - N)...)
24542454

24552455
k = 1
24562456
for a as
@@ -2518,7 +2518,7 @@ function hvncat_fill!(A::Array, row_first::Bool, xs::Tuple)
25182518
dd = nrc * (d - 1)
25192519
for i 1:nr
25202520
Ai = dd + i
2521-
for j 1:nc
2521+
for _ 1:nc
25222522
@inbounds A[Ai] = xs[k]
25232523
k += 1
25242524
Ai += nr
@@ -2535,7 +2535,7 @@ end
25352535
function _typed_hvncat(T::Type, dims::NTuple{N, Int}, row_first::Bool, as...) where {N}
25362536
# function barrier after calculating the max is necessary for high performance
25372537
nd = max(maximum(cat_ndims(a) for a as), N)
2538-
return _typed_hvncat_dims(T, (dims..., ntuple(x -> 1, nd - N)...), row_first, as)
2538+
return _typed_hvncat_dims(T, (dims..., ntuple(Returns(1), nd - N)...), row_first, as)
25392539
end
25402540

25412541
function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as::Tuple) where {T, N}
@@ -2644,7 +2644,7 @@ end
26442644
function _typed_hvncat(T::Type, shape::NTuple{N, Tuple}, row_first::Bool, as...) where {N}
26452645
# function barrier after calculating the max is necessary for high performance
26462646
nd = max(maximum(cat_ndims(a) for a as), N)
2647-
return _typed_hvncat_shape(T, (shape..., ntuple(x -> shape[end], nd - N)...), row_first, as)
2647+
return _typed_hvncat_shape(T, (shape..., ntuple(Returns(shape[end]), nd - N)...), row_first, as)
26482648
end
26492649

26502650
function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::Tuple) where {T, N}
@@ -2976,8 +2976,8 @@ _vec_axis(A, ax=_iterator_axes(A)) = length(ax) == 1 ? only(ax) : OneTo(prod(len
29762976
end
29772977

29782978
function _dim_stack!(::Val{dims}, B::AbstractArray, x1, xrest) where {dims}
2979-
before = ntuple(d -> Colon(), dims - 1)
2980-
after = ntuple(d -> Colon(), ndims(B) - dims)
2979+
before = ntuple(Returns(Colon()), dims - 1)
2980+
after = ntuple(Returns(Colon()), ndims(B) - dims)
29812981

29822982
i = firstindex(B, dims)
29832983
copyto!(view(B, before..., i, after...), x1)
@@ -3165,8 +3165,7 @@ _sub2ind_vec(i, I1, I...) = (@inline; (I1[i], _sub2ind_vec(i, I...)...))
31653165
_sub2ind_vec(i) = ()
31663166

31673167
function _ind2sub(inds::Union{DimsInteger{N},Indices{N}}, ind::AbstractVector{<:Integer}) where N
3168-
M = length(ind)
3169-
t = ntuple(n->similar(ind),Val(N))
3168+
t = ntuple(_->similar(ind),Val(N))
31703169
for (i,idx) in pairs(IndexLinear(), ind)
31713170
sub = _ind2sub(inds, idx)
31723171
for j = 1:N

base/array.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ function _growbeg!(a::Vector, delta::Integer)
11411141
delta == 0 && return # avoid attempting to index off the end
11421142
delta >= 0 || throw(ArgumentError("grow requires delta >= 0"))
11431143
ref = a.ref
1144-
mem = ref.mem
11451144
len = length(a)
11461145
offset = memoryrefoffset(ref)
11471146
newlen = len + delta
@@ -1420,7 +1419,6 @@ append!(a::AbstractVector, iter...) = (foreach(v -> append!(a, v), iter); a)
14201419

14211420
function _append!(a::AbstractVector, ::Union{HasLength,HasShape}, iter)
14221421
n = Int(length(iter))::Int
1423-
i = lastindex(a)
14241422
sizehint!(a, length(a) + n; shrink=false)
14251423
for item in iter
14261424
push!(a, item)
@@ -1764,7 +1762,6 @@ function pushfirst!(a::Vector{Any}, @nospecialize x)
17641762
end
17651763
function pushfirst!(a::Vector{Any}, @nospecialize x...)
17661764
@_terminates_locally_meta
1767-
na = length(a)
17681765
nx = length(x)
17691766
_growbeg!(a, nx)
17701767
@_safeindex for i = 1:nx
@@ -1878,7 +1875,6 @@ function deleteat!(a::Vector, r::AbstractUnitRange{<:Integer})
18781875
if eltype(r) === Bool
18791876
return invoke(deleteat!, Tuple{Vector, AbstractVector{Bool}}, a, r)
18801877
else
1881-
n = length(a)
18821878
f = first(r)
18831879
f isa Bool && depwarn("passing Bool as an index is deprecated", :deleteat!)
18841880
isempty(r) || _deleteat!(a, f, length(r))

base/dict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ end
166166
@inbounds if (olds[i] & 0x80) != 0
167167
k = oldk[i]
168168
v = oldv[i]
169-
index, sh = hashindex(k, newsz)
169+
index, _ = hashindex(k, newsz)
170170
index0 = index
171171
while slots[index] != 0
172172
index = (index & (newsz-1)) + 1

base/essentials.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ function checkbounds(A::Union{Array, GenericMemory}, i::Int)
385385
checkbounds(Bool, A, i) || throw_boundserror(A, (i,))
386386
end
387387

388-
default_access_order(a::GenericMemory{:not_atomic}) = :not_atomic
389-
default_access_order(a::GenericMemory{:atomic}) = :monotonic
390-
default_access_order(a::GenericMemoryRef{:not_atomic}) = :not_atomic
391-
default_access_order(a::GenericMemoryRef{:atomic}) = :monotonic
388+
default_access_order(::GenericMemory{:not_atomic}) = :not_atomic
389+
default_access_order(::GenericMemory{:atomic}) = :monotonic
390+
default_access_order(::GenericMemoryRef{:not_atomic}) = :not_atomic
391+
default_access_order(::GenericMemoryRef{:atomic}) = :monotonic
392392

393393
function getindex(A::GenericMemory, i::Int)
394394
@_noub_if_noinbounds_meta
@@ -464,7 +464,7 @@ See also: [`round`](@ref), [`trunc`](@ref), [`oftype`](@ref), [`reinterpret`](@r
464464
function convert end
465465

466466
# ensure this is never ambiguous, and therefore fast for lookup
467-
convert(T::Type{Union{}}, x...) = throw(ArgumentError("cannot convert a value to Union{} for assignment"))
467+
convert(::Type{Union{}}, _...) = throw(ArgumentError("cannot convert a value to Union{} for assignment"))
468468

469469
convert(::Type{Type}, x::Type) = x # the ssair optimizer is strongly dependent on this method existing to avoid over-specialization
470470
# in the absence of inlining-enabled
@@ -513,7 +513,7 @@ Modifying the key-space of the underlying data may invalidate this object.
513513
"""
514514
Pairs
515515

516-
argtail(x, rest...) = rest
516+
argtail(_, rest...) = rest
517517

518518
"""
519519
tail(x::Tuple)::Tuple
@@ -576,7 +576,7 @@ end
576576

577577
# remove concrete constraint on diagonal TypeVar if it comes from troot
578578
function widen_diagonal(@nospecialize(t), troot::UnionAll)
579-
body = ccall(:jl_widen_diagonal, Any, (Any, Any), t, troot)
579+
return ccall(:jl_widen_diagonal, Any, (Any, Any), t, troot)
580580
end
581581

582582
function isvarargtype(@nospecialize(t))
@@ -981,7 +981,7 @@ getindex(v::SimpleVector, i::Int) = (@_foldable_meta; Core._svec_ref(v, i))
981981
function length(v::SimpleVector)
982982
Core._svec_len(v)
983983
end
984-
firstindex(v::SimpleVector) = 1
984+
firstindex(::SimpleVector) = 1
985985
lastindex(v::SimpleVector) = length(v)
986986
iterate(v::SimpleVector, i=1) = (length(v) < i ? nothing : (v[i], i + 1))
987987
eltype(::Type{SimpleVector}) = Any
@@ -1229,7 +1229,7 @@ to obtain a definitive answer.
12291229
12301230
See also [`iterate`](@ref), [`isempty`](@ref)
12311231
"""
1232-
isdone(itr, state...) = missing
1232+
isdone(_, _...) = missing
12331233

12341234
"""
12351235
iterate(iter [, state])::Union{Nothing, Tuple{Any, Any}}

base/operators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ orderings such as [`isless`](@ref).
288288
!!! compat "Julia 1.7"
289289
This function requires Julia 1.7 or later.
290290
"""
291-
isunordered(x) = false
291+
isunordered(_) = false
292292
isunordered(x::AbstractFloat) = isnan(x)
293-
isunordered(x::Missing) = true
293+
isunordered(::Missing) = true
294294

295295
==(T::Type, S::Type) = (@_total_meta; ccall(:jl_types_equal, Cint, (Any, Any), T, S) != 0)
296296
==(T::TypeVar, S::Type) = false

0 commit comments

Comments
 (0)