Skip to content

Commit

Permalink
Rename isleaftype() to isconcrete()
Browse files Browse the repository at this point in the history
For consistency, also change the C function jl_is_leaf_type() to
jl_is_concrete_type(). Replace (almost) all uses of "leaf" which mean
"concrete".
  • Loading branch information
nalimilan committed Feb 22, 2017
1 parent e21caee commit 077420c
Show file tree
Hide file tree
Showing 40 changed files with 234 additions and 232 deletions.
4 changes: 2 additions & 2 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ _broadcast_eltype(f, A, Bs...) = Base._return_type(f, eltypestuple(A, Bs...))
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 @@ -305,7 +305,7 @@ end
@inline function broadcast_c(f, ::Type{Nullable}, a...)
nonnull = all(hasvalue, a)
S = _broadcast_eltype(f, a...)
if isleaftype(S) && null_safe_eltype_op(f, a...)
if isconcrete(S) && null_safe_eltype_op(f, a...)
Nullable{S}(f(map(unsafe_get, a)...), nonnull)
else
if nonnull
Expand Down
2 changes: 1 addition & 1 deletion base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ big(z::Complex{<:Integer}) = Complex{BigInt}(z)
complex(A::AbstractArray{<:Complex}) = A

function complex{T}(A::AbstractArray{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 @@ -1278,6 +1278,8 @@ end
@deprecate_binding LinearSlow IndexCartesian false
@deprecate_binding linearindexing IndexStyle false

@deprecate isleaftype isconcrete

# END 0.6 deprecations

# BEGIN 1.0 deprecations
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{K,V}(io::IO, t::Associative{K,V})
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{F}(DT_apply::F, kv, t) = grow_to!(associative_with_eltype(DT_apply, _default_eltype(typeof(kv))), kv)
function associative_with_eltype{F}(DT_apply::F, kv::Generator, t)
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 @@ -979,7 +979,7 @@ export
fieldoffset,
fieldname,
fieldnames,
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 @@ -848,7 +848,7 @@ truncmask(x, mask) = x
float(A::AbstractArray{<:AbstractFloat}) = A

function float{T}(A::AbstractArray{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
54 changes: 27 additions & 27 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const _Type_name = Type.body.name
isType(t::ANY) = isa(t, DataType) && (t::DataType).name === _Type_name

# true if Type is inlineable as constant (is a singleton)
isconstType(t::ANY) = isType(t) && (isleaftype(t.parameters[1]) || t.parameters[1] === Union{})
isconstType(t::ANY) = isType(t) && (isconcrete(t.parameters[1]) || t.parameters[1] === Union{})

const IInf = typemax(Int) # integer infinity
const n_ifunc = reinterpret(Int32,arraylen)+1
Expand Down Expand Up @@ -544,7 +544,7 @@ add_tfunc(nfields, 1, 1,
isa(x,Const) && return Const(nfields(x.val))
isa(x,Conditional) && return Const(nfields(Bool))
if isType(x)
isleaftype(x.parameters[1]) && return Const(nfields(x.parameters[1]))
isconcrete(x.parameters[1]) && return Const(nfields(x.parameters[1]))
elseif isa(x,DataType) && !x.abstract && !(x.name === Tuple.name && isvatuple(x))
return Const(length(x.types))
end
Expand Down Expand Up @@ -578,13 +578,13 @@ function typeof_tfunc(t::ANY)
return Const(Bool)
elseif isType(t)
tp = t.parameters[1]
if !isleaftype(tp)
if !isconcrete(tp)
return DataType # typeof(Kind::Type)::DataType
else
return Const(typeof(tp)) # XXX: this is not necessarily true
end
elseif isa(t, DataType)
if isleaftype(t) || isvarargtype(t)
if isconcrete(t) || isvarargtype(t)
return Const(t)
elseif t === Any
return DataType
Expand Down Expand Up @@ -625,11 +625,11 @@ add_tfunc(isa, 2, 2,
if t !== Any && !has_free_typevars(t)
if v t
return Const(true)
elseif isa(v, Const) || isa(v, Conditional) || isleaftype(v)
elseif isa(v, Const) || isa(v, Conditional) || isconcrete(v)
return Const(false)
end
end
# TODO: handle non-leaftype(t) by testing against lower and upper bounds
# TODO: handle non-concrete t by testing against lower and upper bounds
return Bool
end)
add_tfunc(issubtype, 2, 2,
Expand Down Expand Up @@ -739,7 +739,7 @@ function getfield_tfunc(s00::ANY, name)
s = unwrap_unionall(s00)
if isType(s)
p1 = s.parameters[1]
if !isleaftype(p1)
if !isconcrete(p1)
return Any
end
s = DataType # typeof(p1)
Expand Down Expand Up @@ -826,7 +826,7 @@ function getfield_tfunc(s00::ANY, name)
if fld < 1 || fld > nf
return Bottom
end
if isType(s00) && isleaftype(s00.parameters[1])
if isType(s00) && isconcrete(s00.parameters[1])
sp = s00.parameters[1]
elseif isa(s00, Const) && isa(s00.val, DataType)
sp = s00.val
Expand Down Expand Up @@ -926,7 +926,7 @@ has_free_typevars(t::ANY) = ccall(:jl_has_free_typevars, Cint, (Any,), t)!=0
function apply_type_tfunc(headtypetype::ANY, args::ANY...)
if isa(headtypetype, Const)
headtype = headtypetype.val
elseif isType(headtypetype) && isleaftype(headtypetype.parameters[1])
elseif isType(headtypetype) && isconcrete(headtypetype.parameters[1])
headtype = headtypetype.parameters[1]
else
return Any
Expand All @@ -949,7 +949,7 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...)
ai = args[i]
if isType(ai)
aty = ai.parameters[1]
isleaftype(aty) || (allconst = false)
isconcrete(aty) || (allconst = false)
else
aty = (ai::Const).val
end
Expand All @@ -970,7 +970,7 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...)
ai = args[i]
if isType(ai)
aip1 = ai.parameters[1]
canconst &= isleaftype(aip1)
canconst &= isconcrete(aip1)
push!(tparams, aip1)
elseif isa(ai, Const) && (isa(ai.val, Type) || isa(ai.val, TypeVar) || valid_tparam(ai.val))
push!(tparams, ai.val)
Expand Down Expand Up @@ -1045,7 +1045,7 @@ add_tfunc(apply_type, 1, IInf, apply_type_tfunc)
end

function invoke_tfunc(f::ANY, types::ANY, argtype::ANY, sv::InferenceState)
if !isleaftype(Type{types})
if !isconcrete(Type{types})
return Any
end
argtype = typeintersect(types,limit_tuple_type(argtype, sv.params))
Expand Down Expand Up @@ -1513,7 +1513,7 @@ function return_type_tfunc(argtypes::ANY, vtypes::VarTable, sv::InferenceState)
if isa(tt, Const) || (isType(tt) && !has_free_typevars(tt))
aft = argtypes[2]
if isa(aft, Const) || (isType(aft) && !has_free_typevars(aft)) ||
(isleaftype(aft) && !(aft <: Builtin) && !(aft <: IntrinsicFunction))
(isconcrete(aft) && !(aft <: Builtin) && !(aft <: IntrinsicFunction))
af_argtype = isa(tt, Const) ? tt.val : tt.parameters[1]
if isa(af_argtype, DataType) && af_argtype <: Tuple
argtypes_vec = Any[aft, af_argtype.parameters...]
Expand All @@ -1527,7 +1527,7 @@ function return_type_tfunc(argtypes::ANY, vtypes::VarTable, sv::InferenceState)
if isa(rt, Const)
# output was computed to be constant
return Const(typeof(rt.val))
elseif isleaftype(rt)
elseif isconcrete(rt)
# output type was known for certain
return Const(rt)
elseif (isa(tt, Const) || isconstType(tt)) &&
Expand Down Expand Up @@ -1614,9 +1614,9 @@ function abstract_call(f::ANY, fargs::Union{Tuple{},Vector{Any}}, argtypes::Vect
if isa(aft, Const)
af = aft.val
else
if isType(aft) && isleaftype(aft.parameters[1])
if isType(aft) && isconcrete(aft.parameters[1])
af = aft.parameters[1]
elseif isleaftype(aft) && isdefined(aft, :instance)
elseif isconcrete(aft) && isdefined(aft, :instance)
af = aft.instance
else
# TODO jb/functions: take advantage of case where non-constant `af`'s type is known
Expand Down Expand Up @@ -1847,9 +1847,9 @@ function abstract_eval_call(e::Expr, vtypes::VarTable, sv::InferenceState)
if isa(ft, Const)
f = ft.val
else
if isType(ft) && isleaftype(ft.parameters[1])
if isType(ft) && isconcrete(ft.parameters[1])
f = ft.parameters[1]
elseif isleaftype(ft) && isdefined(ft, :instance)
elseif isconcrete(ft) && isdefined(ft, :instance)
f = ft.instance
else
for i = 2:(length(argtypes)-1)
Expand All @@ -1858,7 +1858,7 @@ function abstract_eval_call(e::Expr, vtypes::VarTable, sv::InferenceState)
end
end
# non-constant function, but type is known
if (isleaftype(ft) || ft <: Type) && !(ft <: Builtin) && !(ft <: IntrinsicFunction)
if (isconcrete(ft) || ft <: Type) && !(ft <: Builtin) && !(ft <: IntrinsicFunction)
return abstract_call_gf_by_type(nothing, argtypes_to_type(argtypes), sv)
end
return Any
Expand Down Expand Up @@ -2370,7 +2370,7 @@ function code_for_method(method::Method, atypes::ANY, sparams::SimpleVector, wor
if world < min_world(method) || world > max_world(method)
return nothing
end
if method.isstaged && !isleaftype(atypes)
if method.isstaged && !isconcrete(atypes)
# don't call staged functions on abstract types.
# (see issues #8504, #10230)
# we can't guarantee that their type behavior is monotonic.
Expand Down Expand Up @@ -3397,7 +3397,7 @@ function effect_free(e::ANY, src::CodeInfo, mod::Module, allow_volatile::Bool)
return false
elseif is_known_call(e, getfield, src, mod)
et = exprtype(e, src, mod)
if !isa(et,Const) && !(isType(et) && isleaftype(et))
if !isa(et,Const) && !(isType(et) && isconcrete(et))
# first argument must be immutable to ensure e is affect_free
a = ea[2]
typ = widenconst(exprtype(a, src, mod))
Expand Down Expand Up @@ -3635,15 +3635,15 @@ end

# inline functions whose bodies are "inline_worthy"
# where the function body doesn't contain any argument more than once.
# static parameters are ok if all the static parameter values are leaf types,
# static parameters are ok if all the static parameter values are concrete types,
# meaning they are fully known.
# `ft` is the type of the function. `f` is the exact function if known, or else `nothing`.
function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::InferenceState)
argexprs = e.args

if (f === typeassert || ft typeof(typeassert)) && length(atypes)==3
# typeassert(x::S, T) => x, when S<:T
if isType(atypes[3]) && isleaftype(atypes[3]) &&
if isType(atypes[3]) && isconcrete(atypes[3]) &&
atypes[2] atypes[3].parameters[1]
return (argexprs[2], ())
end
Expand All @@ -3667,7 +3667,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
if f === Core.invoke && length(atypes) >= 3
ft = widenconst(atypes[2])
invoke_tt = widenconst(atypes[3])
if !isleaftype(ft) || !isleaftype(invoke_tt) || !isType(invoke_tt)
if !isconcrete(ft) || !isconcrete(invoke_tt) || !isType(invoke_tt)
return NF
end
if !(isa(invoke_tt.parameters[1], Type) &&
Expand Down Expand Up @@ -4333,7 +4333,7 @@ function inlining_pass(e::Expr, sv::InferenceState)
ft = Bool
else
f = nothing
if !( isleaftype(ft) || ft<:Type )
if !( isconcrete(ft) || ft<:Type )
return (e, stmts)
end
end
Expand Down Expand Up @@ -4438,7 +4438,7 @@ function inlining_pass(e::Expr, sv::InferenceState)
ft = Bool
else
f = nothing
if !( isleaftype(ft) || ft<:Type )
if !( isconcrete(ft) || ft<:Type )
return (e,stmts)
end
end
Expand Down Expand Up @@ -4950,7 +4950,7 @@ function is_allocation(e::ANY, sv::InferenceState)
return (length(e.args)-1,())
elseif e.head === :new
typ = widenconst(exprtype(e, sv.src, sv.mod))
if isa(typ, DataType) && isleaftype(typ)
if isa(typ, DataType) && isconcrete(typ)
nf = length(e.args) - 1
names = fieldnames(typ)
@assert(nf <= nfields(typ))
Expand Down
6 changes: 3 additions & 3 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ versioninfo(verbose::Bool) = versioninfo(STDOUT,verbose)
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 @@ -502,7 +502,7 @@ Evaluates the arguments to the function or macro call, determines their types, a
function type_close_enough(x::ANY, t::ANY)
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
4 changes: 2 additions & 2 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function show(io::IO, m::Method; kwtype::Nullable{DataType}=Nullable{DataType}()
# TODO: more accurate test? (tn.name === "#" name)
ft == 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 @@ -232,7 +232,7 @@ function show(io::IO, ::MIME"text/html", m::Method; kwtype::Nullable{DataType}=N
isdefined(ft.name.module, ft.name.mt.name) &&
ft == 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 @@ -271,7 +271,7 @@ end
"""
Return the given type if it is concrete, and `Union{}` otherwise.
"""
nullable_returntype{T}(::Type{T}) = isleaftype(T) ? T : Union{}
nullable_returntype{T}(::Type{T}) = isconcrete(T) ? T : Union{}

"""
map(f, x::Nullable)
Expand All @@ -285,7 +285,7 @@ type `Nullable{typeof(f(x))}`.
"""
function map{T}(f, x::Nullable{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 @@ -314,13 +314,13 @@ promote_op(::Any...) = (@_pure_meta; Any)
function promote_op{S}(f, ::Type{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{R,S}(f, ::Type{R}, ::Type{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
Loading

0 comments on commit 077420c

Please sign in to comment.