Skip to content

Commit 55ec9fe

Browse files
authored
replace export of isleaftype with a more simply-defined isconcrete (#23666)
fixes #17086
1 parent 957848b commit 55ec9fe

23 files changed

+94
-49
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ Deprecated or removed
438438
been deprecated due to inconsistency with linear algebra. Use `.+` and `.-` for these operations
439439
instead.
440440

441+
* `isleaftype` is deprecated in favor of a simpler predicate `isconcrete`. Concrete types are
442+
those that might equal `typeof(x)` for some `x`; `isleaftype` includes some types for which
443+
this is not true. If you are certain you need the old behavior, it is temporarily available
444+
as `Base._isleaftype` ([#17086]).
445+
441446
Command-line option changes
442447
---------------------------
443448

base/broadcast.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ _nullable_eltype(f, A, As...) =
309309
T = _broadcast_eltype(f, A, Bs...)
310310
shape = broadcast_indices(A, Bs...)
311311
iter = CartesianRange(shape)
312-
if isleaftype(T)
312+
if Base._isleaftype(T)
313313
return broadcast_t(f, T, shape, iter, A, Bs...)
314314
end
315315
if isempty(iter)
@@ -320,8 +320,8 @@ end
320320
@inline function broadcast_c(f, ::Type{Nullable}, a...)
321321
nonnull = all(hasvalue, a)
322322
S = _nullable_eltype(f, a...)
323-
if isleaftype(S) && null_safe_op(f, maptoTuple(_unsafe_get_eltype,
324-
a...).types...)
323+
if Base._isleaftype(S) && null_safe_op(f, maptoTuple(_unsafe_get_eltype,
324+
a...).types...)
325325
Nullable{S}(f(map(unsafe_get, a)...), nonnull)
326326
else
327327
if nonnull

base/complex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ big(z::Complex{T}) where {T<:Real} = Complex{big(T)}(z)
958958
complex(A::AbstractArray{<:Complex}) = A
959959

960960
function complex(A::AbstractArray{T}) where T
961-
if !isleaftype(T)
961+
if !isconcrete(T)
962962
error("`complex` not defined on abstractly-typed arrays; please convert to a more specific type")
963963
end
964964
convert(AbstractArray{typeof(complex(zero(T)))}, A)

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,9 @@ import .Iterators.enumerate
17661766
# issue #5794
17671767
@deprecate map(f, d::T) where {T<:Associative} T( f(p) for p in pairs(d) )
17681768

1769+
# issue #17086
1770+
@deprecate isleaftype isconcrete
1771+
17691772
# PR #22932
17701773
@deprecate +(a::Number, b::AbstractArray) broadcast(+, a, b)
17711774
@deprecate +(a::AbstractArray, b::Number) broadcast(+, a, b)

base/dict.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function show(io::IO, t::Associative{K,V}) where V where K
3434
if isempty(t)
3535
print(io, typeof(t), "()")
3636
else
37-
if isleaftype(K) && isleaftype(V)
37+
if _isleaftype(K) && _isleaftype(V)
3838
print(io, typeof(t).name)
3939
else
4040
print(io, typeof(t))
@@ -161,7 +161,7 @@ associative_with_eltype(DT_apply, ::Type) = DT_apply(Any, Any)()
161161
associative_with_eltype(DT_apply::F, kv, t) where {F} = grow_to!(associative_with_eltype(DT_apply, _default_eltype(typeof(kv))), kv)
162162
function associative_with_eltype(DT_apply::F, kv::Generator, t) where F
163163
T = _default_eltype(typeof(kv))
164-
if T <: Union{Pair, Tuple{Any, Any}} && isleaftype(T)
164+
if T <: Union{Pair, Tuple{Any, Any}} && _isleaftype(T)
165165
return associative_with_eltype(DT_apply, kv, T)
166166
end
167167
return grow_to!(associative_with_eltype(DT_apply, T), kv)

base/exports.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ export
931931
fieldname,
932932
fieldnames,
933933
fieldcount,
934-
isleaftype,
934+
isconcrete,
935935
oftype,
936936
promote,
937937
promote_rule,

base/float.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ Base.iszero(x::Float16) = reinterpret(UInt16, x) & ~sign_mask(Float16) == 0x0000
877877
float(A::AbstractArray{<:AbstractFloat}) = A
878878

879879
function float(A::AbstractArray{T}) where T
880-
if !isleaftype(T)
880+
if !isconcrete(T)
881881
error("`float` not defined on abstractly-typed arrays; please convert to a more specific type")
882882
end
883883
convert(AbstractArray{typeof(float(zero(T)))}, A)

base/inference.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const NF = NotFound()
6363
const LineNum = Int
6464
const VarTable = Array{Any,1}
6565

66+
const isleaftype = _isleaftype
67+
6668
# The type of a variable load is either a value or an UndefVarError
6769
mutable struct VarState
6870
typ

base/interactiveutil.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ Evaluates the arguments to the function or macro call, determines their types, a
555555
function type_close_enough(@nospecialize(x), @nospecialize(t))
556556
x == t && return true
557557
return (isa(x,DataType) && isa(t,DataType) && x.name === t.name &&
558-
!isleaftype(t) && x <: t) ||
558+
!_isleaftype(t) && x <: t) ||
559559
(isa(x,Union) && isa(t,DataType) && (type_close_enough(x.a, t) || type_close_enough(x.b, t)))
560560
end
561561

base/iterators.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -733,17 +733,14 @@ iteratoreltype(::Type{Flatten{I}}) where {I} = _flatteneltype(I, iteratoreltype(
733733
_flatteneltype(I, ::HasEltype) = iteratoreltype(eltype(I))
734734
_flatteneltype(I, et) = EltypeUnknown()
735735

736-
flatten_iteratorsize(::Union{HasShape, HasLength}, b::Type{<:Tuple}) = isleaftype(b) ? HasLength() : SizeUnknown()
737-
flatten_iteratorsize(::Union{HasShape, HasLength}, b::Type{<:Number}) = HasLength()
736+
flatten_iteratorsize(::Union{HasShape, HasLength}, ::Type{<:NTuple{N,Any}}) where {N} = HasLength()
737+
flatten_iteratorsize(::Union{HasShape, HasLength}, ::Type{<:Tuple}) = SizeUnknown()
738+
flatten_iteratorsize(::Union{HasShape, HasLength}, ::Type{<:Number}) = HasLength()
738739
flatten_iteratorsize(a, b) = SizeUnknown()
739740

740741
iteratorsize(::Type{Flatten{I}}) where {I} = flatten_iteratorsize(iteratorsize(I), eltype(I))
741742

742-
function flatten_length(f, ::Type{T}) where {T<:Tuple}
743-
if !isleaftype(T)
744-
throw(ArgumentError(
745-
"Cannot compute length of a tuple-type which is not a leaf-type"))
746-
end
743+
function flatten_length(f, T::Type{<:NTuple{N,Any}}) where {N}
747744
fieldcount(T)*length(f.it)
748745
end
749746
flatten_length(f, ::Type{<:Number}) = length(f.it)

0 commit comments

Comments
 (0)