Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename isleaftype() to isconcrete() #20709

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ Deprecated or removed
* Calling `write` on non-isbits arrays is deprecated in favor of explicit loops or
`serialize` ([#6466]).

* The function `isleaftype` is deprecated in favor of `isconcrete` ([#20709]).

* The default `juliarc.jl` file on Windows has been removed. Now must explicitly include the
full path if you need access to executables or libraries in the `JULIA_HOME` directory, e.g.
`joinpath(JULIA_HOME, "7z.exe")` for `7z.exe` ([#21540]).
Expand Down
4 changes: 2 additions & 2 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ _nullable_eltype(f, A, As...) =
T = _broadcast_eltype(f, A, Bs...)
shape = broadcast_indices(A, Bs...)
iter = CartesianRange(shape)
if isleaftype(T)
if isconcrete(T)
return broadcast_t(f, T, shape, iter, A, Bs...)
end
if isempty(iter)
Expand All @@ -320,7 +320,7 @@ end
@inline function broadcast_c(f, ::Type{Nullable}, a...)
nonnull = all(hasvalue, a)
S = _nullable_eltype(f, a...)
if isleaftype(S) && null_safe_op(f, maptoTuple(_unsafe_get_eltype,
if isconcrete(S) && null_safe_op(f, maptoTuple(_unsafe_get_eltype,
a...).types...)
Nullable{S}(f(map(unsafe_get, a)...), nonnull)
else
Expand Down
2 changes: 1 addition & 1 deletion base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,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 !isleaftype(T)
if !isconcrete(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
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,8 @@ end
# issue #6466
# `write` on non-isbits arrays is deprecated in io.jl.

@deprecate isleaftype isconcrete

# PR #22925
# also uncomment constructor tests in test/linalg/bidiag.jl
function Bidiagonal(dv::AbstractVector{T}, ev::AbstractVector{S}, uplo::Symbol) where {T,S}
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::Associative{K,V}) where V where K
if isempty(t)
print(io, typeof(t), "()")
else
if isleaftype(K) && isleaftype(V)
if isconcrete(K) && isconcrete(V)
print(io, typeof(t).name)
else
print(io, typeof(t))
Expand Down Expand Up @@ -161,7 +161,7 @@ associative_with_eltype(DT_apply, ::Type) = DT_apply(Any, Any)()
associative_with_eltype(DT_apply::F, kv, t) where {F} = grow_to!(associative_with_eltype(DT_apply, _default_eltype(typeof(kv))), kv)
function associative_with_eltype(DT_apply::F, kv::Generator, t) where F
T = _default_eltype(typeof(kv))
if T <: Union{Pair, Tuple{Any, Any}} && isleaftype(T)
if T <: Union{Pair, Tuple{Any, Any}} && isconcrete(T)
return associative_with_eltype(DT_apply, kv, T)
end
return grow_to!(associative_with_eltype(DT_apply, T), kv)
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ export
fieldname,
fieldnames,
fieldcount,
isleaftype,
isconcrete,
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 @@ -853,7 +853,7 @@ truncmask(x, mask) = x
float(A::AbstractArray{<:AbstractFloat}) = A

function float(A::AbstractArray{T}) where T
if !isleaftype(T)
if !isconcrete(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
72 changes: 36 additions & 36 deletions base/inference.jl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ end

Prints lowered and type-inferred ASTs for the methods matching the given generic function
and type signature to `io` which defaults to `STDOUT`. The ASTs are annotated in such a way
as to cause "non-leaf" types to be emphasized (if color is available, displayed in red).
This serves as a warning of potential type instability. Not all non-leaf types are particularly
as to cause non-concrete types to be emphasized (if color is available, displayed in red).
This serves as a warning of potential type instability. Not all non-concrete types are particularly
problematic for performance, so the results need to be used judiciously.
See [`@code_warntype`](@ref man-code-warntype) for more information.
"""
Expand Down Expand Up @@ -531,7 +531,7 @@ Evaluates the arguments to the function or macro call, determines their types, a
function type_close_enough(@nospecialize(x), @nospecialize(t))
x == t && return true
return (isa(x,DataType) && isa(t,DataType) && x.name === t.name &&
!isleaftype(t) && x <: t) ||
!isconcrete(t) && x <: t) ||
(isa(x,Union) && isa(t,DataType) && (type_close_enough(x.a, t) || type_close_enough(x.b, t)))
end

Expand Down
6 changes: 3 additions & 3 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -735,16 +735,16 @@ iteratoreltype(::Type{Flatten{I}}) where {I} = _flatteneltype(I, iteratoreltype(
_flatteneltype(I, ::HasEltype) = iteratoreltype(eltype(I))
_flatteneltype(I, et) = EltypeUnknown()

flatten_iteratorsize(::Union{HasShape, HasLength}, b::Type{<:Tuple}) = isleaftype(b) ? HasLength() : SizeUnknown()
flatten_iteratorsize(::Union{HasShape, HasLength}, b::Type{<:Tuple}) = isconcrete(b) ? HasLength() : SizeUnknown()
flatten_iteratorsize(::Union{HasShape, HasLength}, b::Type{<:Number}) = HasLength()
flatten_iteratorsize(a, b) = SizeUnknown()

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

function flatten_length(f, ::Type{T}) where {T<:Tuple}
if !isleaftype(T)
if !isconcrete(T)
throw(ArgumentError(
"Cannot compute length of a tuple-type which is not a leaf-type"))
"Cannot compute length of a tuple-type which is not concrete"))
end
fieldcount(T)*length(f.it)
end
Expand Down
4 changes: 2 additions & 2 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function show(io::IO, m::Method; kwtype::Nullable{DataType}=Nullable{DataType}()
# TODO: more accurate test? (tn.name === "#" name)
ft0 === typeof(getfield(ft.name.module, ft.name.mt.name))
print(io, ft.name.mt.name)
elseif isa(ft, DataType) && ft.name === Type.body.name && isleaftype(ft)
elseif isa(ft, DataType) && ft.name === Type.body.name && isconcrete(ft)
f = ft.parameters[1]
if isa(f, DataType) && isempty(f.parameters)
print(io, f)
Expand Down Expand Up @@ -234,7 +234,7 @@ function show(io::IO, ::MIME"text/html", m::Method; kwtype::Nullable{DataType}=N
isdefined(ft.name.module, ft.name.mt.name) &&
ft0 === typeof(getfield(ft.name.module, ft.name.mt.name))
print(io, ft.name.mt.name)
elseif isa(ft, DataType) && ft.name === Type.body.name && isleaftype(ft)
elseif isa(ft, DataType) && ft.name === Type.body.name && isconcrete(ft)
f = ft.parameters[1]
if isa(f, DataType) && isempty(f.parameters)
print(io, f)
Expand Down
4 changes: 2 additions & 2 deletions base/nullable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ end
"""
Return the given type if it is concrete, and `Union{}` otherwise.
"""
nullable_returntype(::Type{T}) where {T} = isleaftype(T) ? T : Union{}
nullable_returntype(::Type{T}) where {T} = isconcrete(T) ? T : Union{}

"""
map(f, x::Nullable)
Expand All @@ -349,7 +349,7 @@ Nullable{Bool}()
"""
function map(f, x::Nullable{T}) where T
S = promote_op(f, T)
if isleaftype(S) && null_safe_op(f, T)
if isconcrete(S) && null_safe_op(f, T)
Nullable(f(unsafe_get(x)), !isnull(x))
else
if isnull(x)
Expand Down
4 changes: 2 additions & 2 deletions base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,13 @@ promote_op(::Any...) = (@_inline_meta; Any)
function promote_op(f, ::Type{S}) where S
@_inline_meta
T = _return_type(f, Tuple{_default_type(S)})
isleaftype(S) && return isleaftype(T) ? T : Any
isconcrete(S) && return isconcrete(T) ? T : Any
return typejoin(S, T)
end
function promote_op(f, ::Type{R}, ::Type{S}) where {R,S}
@_inline_meta
T = _return_type(f, Tuple{_default_type(R), _default_type(S)})
isleaftype(R) && isleaftype(S) && return isleaftype(T) ? T : Any
isconcrete(R) && isconcrete(S) && return isconcrete(T) ? T : Any
return typejoin(R, S, T)
end

Expand Down
22 changes: 11 additions & 11 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,27 +283,27 @@ isbits(t::Type) = (@_pure_meta; false)
isbits(x) = (@_pure_meta; isbits(typeof(x)))

"""
isleaftype(T)
isconcrete(T)

Determine whether `T`'s only subtypes are itself and `Union{}`. This means `T` is
a concrete type that can have instances.

# Examples
```jldoctest
julia> isleaftype(Complex)
julia> isconcrete(Complex)
false

julia> isleaftype(Complex{Float32})
julia> isconcrete(Complex{Float32})
true

julia> isleaftype(Vector{Complex})
julia> isconcrete(Vector{Complex})
true

julia> isleaftype(Vector{Complex{Float32}})
julia> isconcrete(Vector{Complex{Float32}})
true
```
"""
isleaftype(@nospecialize(t)) = (@_pure_meta; isa(t, DataType) && t.isleaftype)
isconcrete(@nospecialize(t)) = (@_pure_meta; isa(t, DataType) && t.isconcrete)

"""
Base.isabstract(T)
Expand Down Expand Up @@ -767,8 +767,8 @@ function _dump_function_linfo(linfo::Core.MethodInstance, world::UInt, native::B
(Ptr{Void}, Bool, Bool), llvmf, strip_ir_metadata, dump_module)
end

# TODO: use jl_is_cacheable_sig instead of isleaftype
isleaftype(linfo.specTypes) || (str = "; WARNING: This code may not match what actually runs.\n" * str)
# TODO: use jl_is_cacheable_sig instead of isconcrete
isconcrete(linfo.specTypes) || (str = "; WARNING: This code may not match what actually runs.\n" * str)
return str
end

Expand Down Expand Up @@ -797,9 +797,9 @@ code_native(io::IO, @nospecialize(f), @nospecialize(types=Tuple), syntax::Symbol
code_native(@nospecialize(f), @nospecialize(types=Tuple), syntax::Symbol=:att) = code_native(STDOUT, f, types, syntax)
code_native(::IO, ::Any, ::Symbol) = error("illegal code_native call") # resolve ambiguous call

# give a decent error message if we try to instantiate a staged function on non-leaf types
# give a decent error message if we try to instantiate a staged function on non-concrete types
function func_for_method_checked(m::Method, @nospecialize types)
if isdefined(m,:generator) && !isdefined(m,:source) && !isleaftype(types)
if isdefined(m,:generator) && !isdefined(m,:source) && !isconcrete(types)
error("cannot call @generated function `", m, "` ",
"with abstract argument types: ", types)
end
Expand Down Expand Up @@ -861,7 +861,7 @@ function which(@nospecialize(f), @nospecialize(t))
throw(ArgumentError("argument is not a generic function"))
end
t = to_tuple_type(t)
if isleaftype(t)
if isconcrete(t)
ms = methods(f, t)
isempty(ms) && error("no method found for the specified argument types")
length(ms)!=1 && error("no unique matching method for the specified argument types")
Expand Down
4 changes: 2 additions & 2 deletions base/refpointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ convert(::Type{Ref{T}}, x) where {T} = RefValue{T}(x)
function unsafe_convert(P::Type{Ptr{T}}, b::RefValue{T}) where T
if isbits(T)
return convert(P, pointer_from_objref(b))
elseif isleaftype(T)
elseif isconcrete(T)
return convert(P, pointer_from_objref(b.x))
else
# If the slot is not leaf type, it could be either isbits or not.
# If the slot is not a concrete type, it could be either isbits or not.
# If it is actually an isbits type and the type inference can infer that
# it can rebox the `b.x` if we simply call `pointer_from_objref(b.x)` on it.
# Instead, explicitly load the pointer from the `RefValue` so that the pointer
Expand Down
2 changes: 1 addition & 1 deletion base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ function show_method_candidates(io::IO, ex::MethodError, kwargs::Vector=Any[])
# pool MethodErrors for these two functions.
if f === convert && !isempty(arg_types_param)
at1 = arg_types_param[1]
if isa(at1,DataType) && (at1::DataType).name === Type.body.name && isleaftype(at1)
if isa(at1,DataType) && (at1::DataType).name === Type.body.name && isconcrete(at1)
push!(funcs, (at1.parameters[1], arg_types_param[2:end]))
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for sets of arbitrary objects.
Set(itr) = Set{eltype(itr)}(itr)
function Set(g::Generator)
T = _default_eltype(typeof(g))
(isleaftype(T) || T === Union{}) || return grow_to!(Set{T}(), g)
(isconcrete(T) || T === Union{}) || return grow_to!(Set{T}(), g)
return Set{T}(g)
end

Expand Down Expand Up @@ -209,7 +209,7 @@ function unique(itr)
return out
end
x, i = next(itr, i)
if !isleaftype(T)
if !isconcrete(T)
S = typeof(x)
return _unique_from(itr, S[x], Set{S}((x,)), i)
end
Expand Down
6 changes: 3 additions & 3 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ function show_expr_type(io::IO, @nospecialize(ty), emph::Bool)
elseif ty === Core.IntrinsicFunction
print(io, "::I")
else
if emph && (!isleaftype(ty) || ty == Core.Box)
if emph && (!isconcrete(ty) || ty == Core.Box)
emphasize(io, "::$ty")
else
print(io, "::$ty")
Expand Down Expand Up @@ -1090,7 +1090,7 @@ function show_tuple_as_call(io::IO, name::Symbol, sig::Type)
isdefined(uw.name.module, uw.name.mt.name) &&
ft == typeof(getfield(uw.name.module, uw.name.mt.name))
print(io, uw.name.mt.name)
elseif isa(ft, DataType) && ft.name === Type.body.name && isleaftype(ft)
elseif isa(ft, DataType) && ft.name === Type.body.name && isconcrete(ft)
f = ft.parameters[1]
print(io, f)
else
Expand Down Expand Up @@ -1813,7 +1813,7 @@ function array_eltype_show_how(X)
str = string(e)
end
# Types hard-coded here are those which are created by default for a given syntax
isleaftype(e), (!isempty(X) && (e===Float64 || e===Int || e===Char) ? "" : str)
isconcrete(e), (!isempty(X) && (e===Float64 || e===Int || e===Char) ? "" : str)
end

function show_vector(io::IO, v, opn, cls)
Expand Down
4 changes: 2 additions & 2 deletions doc/images/jltypes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/src/devdocs/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ input and output types were inferred in advance) is assigned a fixed
cost (currently 20 cycles). In contrast, a `:call` expression, for
functions other than intrinsics/builtins, indicates that the call will
require dynamic dispatch, in which case we assign a cost set by
`InferenceParams.inline_nonleaf_penalty` (currently set at 1000). Note
`InferenceParams.inline_nonconcrete_penalty` (currently set at 1000). Note
that this is not a "first-principles" estimate of the raw cost of
dynamic dispatch, but a mere heuristic indicating that dynamic
dispatch is extremely expensive.
Expand Down
2 changes: 1 addition & 1 deletion doc/src/devdocs/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef struct {
} jl_typetag_t;
```

The type of any Julia object is an instance of a leaf `jl_datatype_t` object. The `jl_typeof()`
The type of any Julia object is an instance of a concrete `jl_datatype_t` object. The `jl_typeof()`
function can be used to query for it:

```c
Expand Down
4 changes: 2 additions & 2 deletions doc/src/devdocs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ For example, in the problem `Tuple{Int,String} <: Tuple{T,T} where T`, we derive
this would be true if `T` were a supertype of `Union{Int,String}`.
However, `Union{Int,String}` is an abstract type, so the relation does not hold.

This concreteness test is done by the function `is_leaf_bound`.
Note that this test is slightly different from `jl_is_leaf_type`, since it also returns
This concreteness test is done by the function `is_concrete_bound`.
Note that this test is slightly different from `jl_is_concrete_type`, since it also returns
`true` for `Bottom`.
Currently this function is heuristic, and does not catch all possible concrete types.
The difficulty is that whether a lower bound is concrete might depend on the values
Expand Down
Loading