Skip to content

Commit

Permalink
fix type-predicate queries
Browse files Browse the repository at this point in the history
expand the set of them to be more "complete",
and document them more fully
  • Loading branch information
vtjnash committed Jan 16, 2018
1 parent 27e5ae6 commit c9d254d
Show file tree
Hide file tree
Showing 39 changed files with 780 additions and 826 deletions.
8 changes: 4 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,10 @@ Deprecated or removed
been deprecated due to inconsistency with linear algebra. Use `.+` and `.-` for these operations
instead ([#22880], [#22932]).

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

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

Expand Down
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ function hash(a::AbstractArray{T}, h::UInt) where T
# to a range with more than two elements because more extreme values
# cannot be represented. We must still hash the two first values as a
# range since they can always be considered as such (in a wider type)
if isconcrete(T)
if isconcretetype(T)
try
step = x2 - x1
catch err
Expand Down
2 changes: 1 addition & 1 deletion base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ julia> string.(("one","two","three","four"), ": ", 1:4)
const NonleafHandlingTypes = Union{DefaultArrayStyle,ArrayConflict,VectorStyle,MatrixStyle}

@inline function broadcast(f, s::NonleafHandlingTypes, ::Type{ElType}, inds::Indices, As...) where ElType
if !Base._isleaftype(ElType)
if !Base.isconcretetype(ElType)
return broadcast_nonleaf(f, s, ElType, inds, As...)
end
dest = broadcast_similar(f, s, ElType, inds, As...)
Expand Down
2 changes: 1 addition & 1 deletion base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ big(z::Complex{T}) where {T<:Real} = Complex{big(T)}(z)
complex(A::AbstractArray{<:Complex}) = A

function complex(A::AbstractArray{T}) where T
if !isconcrete(T)
if !isconcretetype(T)
error("`complex` not defined on abstractly-typed arrays; please convert to a more specific type")
end
convert(AbstractArray{typeof(complex(zero(T)))}, A)
Expand Down
3 changes: 2 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ import .Iterators.enumerate
@deprecate map(f, d::T) where {T<:AbstractDict} T( f(p) for p in pairs(d) )

# issue #17086
@deprecate isleaftype isconcrete
@deprecate isleaftype isconcretetype
@deprecate isabstract isabstracttype

# PR #22932
@deprecate +(a::Number, b::AbstractArray) broadcast(+, a, b)
Expand Down
4 changes: 2 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function show(io::IO, t::AbstractDict{K,V}) where V where K
if isempty(t)
print(io, typeof(t), "()")
else
if _isleaftype(K) && _isleaftype(V)
if isconcretetype(K) && isconcretetype(V)
print(io, typeof(t).name)
else
print(io, typeof(t))
Expand Down Expand Up @@ -160,7 +160,7 @@ dict_with_eltype(DT_apply, ::Type) = DT_apply(Any, Any)()
dict_with_eltype(DT_apply::F, kv, t) where {F} = grow_to!(dict_with_eltype(DT_apply, @default_eltype(typeof(kv))), kv)
function dict_with_eltype(DT_apply::F, kv::Generator, t) where F
T = @default_eltype(kv)
if T <: Union{Pair, Tuple{Any, Any}} && _isleaftype(T)
if T <: Union{Pair, Tuple{Any, Any}} && isconcretetype(T)
return dict_with_eltype(DT_apply, kv, T)
end
return grow_to!(dict_with_eltype(DT_apply, T), kv)
Expand Down
6 changes: 5 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,11 @@ export
fieldname,
fieldnames,
fieldcount,
isconcrete,
isabstracttype,
isprimitivetype,
isstructtype,
isconcretetype,
isdispatchtuple,
oftype,
promote,
promote_rule,
Expand Down
2 changes: 1 addition & 1 deletion base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ Base.iszero(x::Float16) = reinterpret(UInt16, x) & ~sign_mask(Float16) == 0x0000
float(A::AbstractArray{<:AbstractFloat}) = A

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

0 comments on commit c9d254d

Please sign in to comment.