Skip to content

Commit d33f30f

Browse files
committed
fix type-predicate queries
expand the set of them to be more "complete", and document them more fully
1 parent 7cfc29f commit d33f30f

39 files changed

+779
-825
lines changed

NEWS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,10 @@ Deprecated or removed
810810
been deprecated due to inconsistency with linear algebra. Use `.+` and `.-` for these operations
811811
instead ([#22880], [#22932]).
812812

813-
* `isleaftype` is deprecated in favor of a simpler predicate `isconcrete`. Concrete types are
814-
those that might equal `typeof(x)` for some `x`; `isleaftype` includes some types for which
815-
this is not true. If you are certain you need the old behavior, it is temporarily available
816-
as `Base._isleaftype` ([#17086]).
813+
* `isleaftype` is deprecated in favor of the simpler predicates `isconcretetype` and `isdispatchtuple`.
814+
Concrete types are those that might equal `typeof(x)` for some `x`;
815+
`isleaftype` included some types for which this is not true. Those are now categorized more precisely
816+
as "dispatch tuple types" and "!has_free_typevars" (not exported). ([#17086], [#25496])
817817

818818
* `contains(eq, itr, item)` is deprecated in favor of `any` with a predicate ([#23716]).
819819

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ function hash(a::AbstractArray{T}, h::UInt) where T
19851985
# to a range with more than two elements because more extreme values
19861986
# cannot be represented. We must still hash the two first values as a
19871987
# range since they can always be considered as such (in a wider type)
1988-
if isconcrete(T)
1988+
if isconcretetype(T)
19891989
try
19901990
step = x2 - x1
19911991
catch err

base/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ julia> string.(("one","two","three","four"), ": ", 1:4)
622622
const NonleafHandlingTypes = Union{DefaultArrayStyle,ArrayConflict,VectorStyle,MatrixStyle}
623623

624624
@inline function broadcast(f, s::NonleafHandlingTypes, ::Type{ElType}, inds::Indices, As...) where ElType
625-
if !Base._isleaftype(ElType)
625+
if !Base.isconcretetype(ElType)
626626
return broadcast_nonleaf(f, s, ElType, inds, As...)
627627
end
628628
dest = broadcast_similar(f, s, ElType, inds, As...)

base/complex.jl

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

978978
function complex(A::AbstractArray{T}) where T
979-
if !isconcrete(T)
979+
if !isconcretetype(T)
980980
error("`complex` not defined on abstractly-typed arrays; please convert to a more specific type")
981981
end
982982
convert(AbstractArray{typeof(complex(zero(T)))}, A)

base/deprecated.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ import .Iterators.enumerate
747747
@deprecate map(f, d::T) where {T<:AbstractDict} T( f(p) for p in pairs(d) )
748748

749749
# issue #17086
750-
@deprecate isleaftype isconcrete
750+
@deprecate isleaftype isconcretetype
751+
@deprecate isabstract isabstracttype
751752

752753
# PR #22932
753754
@deprecate +(a::Number, b::AbstractArray) 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::AbstractDict{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 isconcretetype(K) && isconcretetype(V)
3838
print(io, typeof(t).name)
3939
else
4040
print(io, typeof(t))
@@ -160,7 +160,7 @@ dict_with_eltype(DT_apply, ::Type) = DT_apply(Any, Any)()
160160
dict_with_eltype(DT_apply::F, kv, t) where {F} = grow_to!(dict_with_eltype(DT_apply, @default_eltype(typeof(kv))), kv)
161161
function dict_with_eltype(DT_apply::F, kv::Generator, t) where F
162162
T = @default_eltype(kv)
163-
if T <: Union{Pair, Tuple{Any, Any}} && _isleaftype(T)
163+
if T <: Union{Pair, Tuple{Any, Any}} && isconcretetype(T)
164164
return dict_with_eltype(DT_apply, kv, T)
165165
end
166166
return grow_to!(dict_with_eltype(DT_apply, T), kv)

base/exports.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,11 @@ export
851851
fieldname,
852852
fieldnames,
853853
fieldcount,
854-
isconcrete,
854+
isabstracttype,
855+
isprimitivetype,
856+
isstructtype,
857+
isconcretetype,
858+
isdispatchtuple,
855859
oftype,
856860
promote,
857861
promote_rule,

base/float.jl

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

865865
function float(A::AbstractArray{T}) where T
866-
if !isconcrete(T)
866+
if !isconcretetype(T)
867867
error("`float` not defined on abstractly-typed arrays; please convert to a more specific type")
868868
end
869869
convert(AbstractArray{typeof(float(zero(T)))}, A)

0 commit comments

Comments
 (0)