Skip to content

Commit b020ccb

Browse files
committed
Revert type inference fixes
1 parent f9b16dc commit b020ccb

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/dimensions.jl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,39 +146,37 @@ function to_parent_dims(::Type{T}, ::StaticInt{dim}) where {T,dim}
146146
throw_dim_error(T, dim)
147147
end
148148
end
149-
struct Returns{T}; x::T; end; @inline (r::Returns)(_::Vararg{Any,K}) where {K} = r.x
150-
_nunderscore(::Val{N}) where {N} = ntuple(Returns(nothing), Val(N))
149+
150+
_nunderscore(::Val{N}) where {N} = ntuple(Compat.Returns(:_), Val(N))
151151

152152
"""
153153
has_dimnames(::Type{T}) -> StaticBool
154154
155155
Returns `static(true)` if `x` has on or more named dimensions. If all dimensions correspond
156-
to `nothing`, then `static(false)` is returned.
156+
to `static(:_)`, then `static(false)` is returned.
157157
"""
158158
Compat.@constprop :aggressive has_dimnames(x) = static(_is_named(known_dimnames(x)))
159-
_is_named(x::Tuple{Nothing,Vararg}) = _is_named(Base.tail(x))
160-
_is_named(x::Tuple{Nothing}) = false
161-
_is_named(x::Tuple{Symbol,Vararg}) = true
162-
_is_named(x::Tuple{}) = true
159+
_is_named(x::NTuple{N,Symbol}) where {N} = x !== _nunderscore(Val(N))
160+
_is_named(::Any) = true
163161

164162
"""
165163
known_dimnames(::Type{T}) -> Tuple{Vararg{Union{Symbol,Nothing}}}
166164
known_dimnames(::Type{T}, dim::Union{Int,StaticInt}) -> Union{Symbol,Nothing}
167165
168-
Return the names of the dimensions for `x`. `nothing` is used to indicate a dimension does not
166+
Return the names of the dimensions for `x`. `:_` is used to indicate a dimension does not
169167
have a name.
170168
"""
171169
@inline known_dimnames(x, dim::Integer) = _known_dimname(known_dimnames(x), canonicalize(dim))
172170
known_dimnames(x) = known_dimnames(typeof(x))
173171
known_dimnames(::Type{T}) where {T} = _known_dimnames(T, parent_type(T))
174172
_known_dimnames(::Type{T}, ::Type{T}) where {T} = _unknown_dimnames(Base.IteratorSize(T))
175173
_unknown_dimnames(::Base.HasShape{N}) where {N} = _nunderscore(Val(N))
176-
_unknown_dimnames(::Any) = (nothing,)
174+
_unknown_dimnames(::Any) = (:_,)
177175
function _known_dimnames(::Type{C}, ::Type{P}) where {C,P}
178176
eachop(_inbounds_known_dimname, to_parent_dims(C), known_dimnames(P))
179177
end
180178
@inline function _known_dimname(x::Tuple{Vararg{Any,N}}, dim::CanonicalInt) where {N}
181-
(dim > N || dim < 1) && return nothing
179+
@boundscheck (dim > N || dim < 1) && return :_
182180
return @inbounds(x[dim])
183181
end
184182
@inline _inbounds_known_dimname(x, dim) = @inbounds(_known_dimname(x, dim))
@@ -187,17 +185,17 @@ end
187185
dimnames(x) -> Tuple{Vararg{Union{Symbol,StaticSymbol}}}
188186
dimnames(x, dim::Union{Int,StaticInt}) -> Union{Symbol,StaticSymbol}
189187
190-
Return the names of the dimensions for `x`. `nothing` is used to indicate a dimension does not
188+
Return the names of the dimensions for `x`. `:_` is used to indicate a dimension does not
191189
have a name.
192190
"""
193191
@inline dimnames(x, dim::Integer) = _dimname(dimnames(x), canonicalize(dim))
194192
@inline dimnames(x) = _dimnames(has_parent(x), x)
195193
@inline function _dimnames(::True, x)
196194
eachop(_inbounds_dimname, to_parent_dims(x), dimnames(parent(x)))
197195
end
198-
_dimnames(::False, x) = ntuple(_->nothing, Val(ndims(x)))
196+
_dimnames(::False, x) = ntuple(_->static(:_), Val(ndims(x)))
199197
@inline function _dimname(x::Tuple{Vararg{Any,N}}, dim::CanonicalInt) where {N}
200-
@boundscheck (dim > N || dim < 1) && return nothing
198+
@boundscheck (dim > N || dim < 1) && return static(:_)
201199
return @inbounds(x[dim])
202200
end
203201
@inline _inbounds_dimname(x, dim) = @inbounds(_dimname(x, dim))

test/dimensions.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ end
101101
@test @inferred(ArrayInterface.has_dimnames(typeof(view(x, :, 1, :)))) == true
102102
@test @inferred(dimnames(x)) === d
103103
@test @inferred(ArrayInterface.dimnames(z)) === (:x, static(:y))
104-
@test @inferred(dimnames(parent(x))) === (nothing, nothing)
104+
@test @inferred(dimnames(parent(x))) === (static(:_), static(:_))
105105
@test @inferred(dimnames(x')) === reverse(d)
106-
@test @inferred(dimnames(y')) === (nothing, static(:x))
106+
@test @inferred(dimnames(y')) === (static(:_), static(:x))
107107
@test @inferred(dimnames(PermutedDimsArray(x, (2, 1)))) === reverse(d)
108108
@test @inferred(dimnames(PermutedDimsArray(x', (2, 1)))) === d
109109
@test @inferred(dimnames(view(x, :, 1))) === (static(:x),)
110-
@test @inferred(dimnames(view(x, :, :, :))) === (static(:x),static(:y), nothing)
111-
@test @inferred(dimnames(view(x, :, 1, :))) === (static(:x), nothing)
110+
@test @inferred(dimnames(view(x, :, :, :))) === (static(:x),static(:y), static(:_))
111+
@test @inferred(dimnames(view(x, :, 1, :))) === (static(:x), static(:_))
112112
@test @inferred(dimnames(x, ArrayInterface.One())) === static(:x)
113-
@test @inferred(dimnames(parent(x), ArrayInterface.One())) === nothing
114-
@test @inferred(ArrayInterface.known_dimnames(Iterators.flatten(1:10))) === (nothing,)
115-
@test @inferred(ArrayInterface.known_dimnames(Iterators.flatten(1:10), static(1))) === nothing
113+
@test @inferred(dimnames(parent(x), ArrayInterface.One())) === static(:_)
114+
@test @inferred(ArrayInterface.known_dimnames(Iterators.flatten(1:10))) === (:_,)
115+
@test @inferred(ArrayInterface.known_dimnames(Iterators.flatten(1:10), static(1))) === :_
116116
@test @inferred(ArrayInterface.known_dimnames(z)) === (nothing, :y)
117117
end
118118

0 commit comments

Comments
 (0)