Skip to content

Commit 1e24b6d

Browse files
committed
Rename isleaftype() to isconcrete()
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".
1 parent e21caee commit 1e24b6d

40 files changed

+233
-231
lines changed

base/broadcast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ _broadcast_eltype(f, A, Bs...) = Base._return_type(f, eltypestuple(A, Bs...))
289289
T = _broadcast_eltype(f, A, Bs...)
290290
shape = broadcast_indices(A, Bs...)
291291
iter = CartesianRange(shape)
292-
if isleaftype(T)
292+
if isconcrete(T)
293293
return broadcast_t(f, T, shape, iter, A, Bs...)
294294
end
295295
if isempty(iter)
@@ -305,7 +305,7 @@ end
305305
@inline function broadcast_c(f, ::Type{Nullable}, a...)
306306
nonnull = all(hasvalue, a)
307307
S = _broadcast_eltype(f, a...)
308-
if isleaftype(S) && null_safe_eltype_op(f, a...)
308+
if isconcrete(S) && null_safe_eltype_op(f, a...)
309309
Nullable{S}(f(map(unsafe_get, a)...), nonnull)
310310
else
311311
if nonnull

base/complex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ big(z::Complex{<:Integer}) = Complex{BigInt}(z)
885885
complex(A::AbstractArray{<:Complex}) = A
886886

887887
function complex{T}(A::AbstractArray{T})
888-
if !isleaftype(T)
888+
if !isconcrete(T)
889889
error("`complex` not defined on abstractly-typed arrays; please convert to a more specific type")
890890
end
891891
convert(AbstractArray{typeof(complex(zero(T)))}, A)

base/deprecated.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,8 @@ end
12781278
@deprecate_binding LinearSlow IndexCartesian false
12791279
@deprecate_binding linearindexing IndexStyle false
12801280

1281+
@deprecate isleaftype isconcrete
1282+
12811283
# END 0.6 deprecations
12821284

12831285
# BEGIN 1.0 deprecations

base/dict.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function show{K,V}(io::IO, t::Associative{K,V})
3434
if isempty(t)
3535
print(io, typeof(t), "()")
3636
else
37-
if isleaftype(K) && isleaftype(V)
37+
if isconcrete(K) && isconcrete(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{F}(DT_apply::F, kv, t) = grow_to!(associative_with_eltype(DT_apply, _default_eltype(typeof(kv))), kv)
162162
function associative_with_eltype{F}(DT_apply::F, kv::Generator, t)
163163
T = _default_eltype(typeof(kv))
164-
if T <: Union{Pair, Tuple{Any, Any}} && isleaftype(T)
164+
if T <: Union{Pair, Tuple{Any, Any}} && isconcrete(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
@@ -979,7 +979,7 @@ export
979979
fieldoffset,
980980
fieldname,
981981
fieldnames,
982-
isleaftype,
982+
isconcrete,
983983
oftype,
984984
promote,
985985
promote_rule,

base/float.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ truncmask(x, mask) = x
848848
float(A::AbstractArray{<:AbstractFloat}) = A
849849

850850
function float{T}(A::AbstractArray{T})
851-
if !isleaftype(T)
851+
if !isconcrete(T)
852852
error("`float` not defined on abstractly-typed arrays; please convert to a more specific type")
853853
end
854854
convert(AbstractArray{typeof(float(zero(T)))}, A)

base/inference.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ const _Type_name = Type.body.name
347347
isType(t::ANY) = isa(t, DataType) && (t::DataType).name === _Type_name
348348

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

352352
const IInf = typemax(Int) # integer infinity
353353
const n_ifunc = reinterpret(Int32,arraylen)+1
@@ -544,7 +544,7 @@ add_tfunc(nfields, 1, 1,
544544
isa(x,Const) && return Const(nfields(x.val))
545545
isa(x,Conditional) && return Const(nfields(Bool))
546546
if isType(x)
547-
isleaftype(x.parameters[1]) && return Const(nfields(x.parameters[1]))
547+
isconcrete(x.parameters[1]) && return Const(nfields(x.parameters[1]))
548548
elseif isa(x,DataType) && !x.abstract && !(x.name === Tuple.name && isvatuple(x))
549549
return Const(length(x.types))
550550
end
@@ -578,13 +578,13 @@ function typeof_tfunc(t::ANY)
578578
return Const(Bool)
579579
elseif isType(t)
580580
tp = t.parameters[1]
581-
if !isleaftype(tp)
581+
if !isconcrete(tp)
582582
return DataType # typeof(Kind::Type)::DataType
583583
else
584584
return Const(typeof(tp)) # XXX: this is not necessarily true
585585
end
586586
elseif isa(t, DataType)
587-
if isleaftype(t) || isvarargtype(t)
587+
if isconcrete(t) || isvarargtype(t)
588588
return Const(t)
589589
elseif t === Any
590590
return DataType
@@ -625,11 +625,11 @@ add_tfunc(isa, 2, 2,
625625
if t !== Any && !has_free_typevars(t)
626626
if v t
627627
return Const(true)
628-
elseif isa(v, Const) || isa(v, Conditional) || isleaftype(v)
628+
elseif isa(v, Const) || isa(v, Conditional) || isconcrete(v)
629629
return Const(false)
630630
end
631631
end
632-
# TODO: handle non-leaftype(t) by testing against lower and upper bounds
632+
# TODO: handle non-concrete t by testing against lower and upper bounds
633633
return Bool
634634
end)
635635
add_tfunc(issubtype, 2, 2,
@@ -739,7 +739,7 @@ function getfield_tfunc(s00::ANY, name)
739739
s = unwrap_unionall(s00)
740740
if isType(s)
741741
p1 = s.parameters[1]
742-
if !isleaftype(p1)
742+
if !isconcrete(p1)
743743
return Any
744744
end
745745
s = DataType # typeof(p1)
@@ -826,7 +826,7 @@ function getfield_tfunc(s00::ANY, name)
826826
if fld < 1 || fld > nf
827827
return Bottom
828828
end
829-
if isType(s00) && isleaftype(s00.parameters[1])
829+
if isType(s00) && isconcrete(s00.parameters[1])
830830
sp = s00.parameters[1]
831831
elseif isa(s00, Const) && isa(s00.val, DataType)
832832
sp = s00.val
@@ -926,7 +926,7 @@ has_free_typevars(t::ANY) = ccall(:jl_has_free_typevars, Cint, (Any,), t)!=0
926926
function apply_type_tfunc(headtypetype::ANY, args::ANY...)
927927
if isa(headtypetype, Const)
928928
headtype = headtypetype.val
929-
elseif isType(headtypetype) && isleaftype(headtypetype.parameters[1])
929+
elseif isType(headtypetype) && isconcrete(headtypetype.parameters[1])
930930
headtype = headtypetype.parameters[1]
931931
else
932932
return Any
@@ -949,7 +949,7 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...)
949949
ai = args[i]
950950
if isType(ai)
951951
aty = ai.parameters[1]
952-
isleaftype(aty) || (allconst = false)
952+
isconcrete(aty) || (allconst = false)
953953
else
954954
aty = (ai::Const).val
955955
end
@@ -970,7 +970,7 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...)
970970
ai = args[i]
971971
if isType(ai)
972972
aip1 = ai.parameters[1]
973-
canconst &= isleaftype(aip1)
973+
canconst &= isconcrete(aip1)
974974
push!(tparams, aip1)
975975
elseif isa(ai, Const) && (isa(ai.val, Type) || isa(ai.val, TypeVar) || valid_tparam(ai.val))
976976
push!(tparams, ai.val)
@@ -1045,7 +1045,7 @@ add_tfunc(apply_type, 1, IInf, apply_type_tfunc)
10451045
end
10461046

10471047
function invoke_tfunc(f::ANY, types::ANY, argtype::ANY, sv::InferenceState)
1048-
if !isleaftype(Type{types})
1048+
if !isconcrete(Type{types})
10491049
return Any
10501050
end
10511051
argtype = typeintersect(types,limit_tuple_type(argtype, sv.params))
@@ -1513,7 +1513,7 @@ function return_type_tfunc(argtypes::ANY, vtypes::VarTable, sv::InferenceState)
15131513
if isa(tt, Const) || (isType(tt) && !has_free_typevars(tt))
15141514
aft = argtypes[2]
15151515
if isa(aft, Const) || (isType(aft) && !has_free_typevars(aft)) ||
1516-
(isleaftype(aft) && !(aft <: Builtin) && !(aft <: IntrinsicFunction))
1516+
(isconcrete(aft) && !(aft <: Builtin) && !(aft <: IntrinsicFunction))
15171517
af_argtype = isa(tt, Const) ? tt.val : tt.parameters[1]
15181518
if isa(af_argtype, DataType) && af_argtype <: Tuple
15191519
argtypes_vec = Any[aft, af_argtype.parameters...]
@@ -1527,7 +1527,7 @@ function return_type_tfunc(argtypes::ANY, vtypes::VarTable, sv::InferenceState)
15271527
if isa(rt, Const)
15281528
# output was computed to be constant
15291529
return Const(typeof(rt.val))
1530-
elseif isleaftype(rt)
1530+
elseif isconcrete(rt)
15311531
# output type was known for certain
15321532
return Const(rt)
15331533
elseif (isa(tt, Const) || isconstType(tt)) &&
@@ -1614,9 +1614,9 @@ function abstract_call(f::ANY, fargs::Union{Tuple{},Vector{Any}}, argtypes::Vect
16141614
if isa(aft, Const)
16151615
af = aft.val
16161616
else
1617-
if isType(aft) && isleaftype(aft.parameters[1])
1617+
if isType(aft) && isconcrete(aft.parameters[1])
16181618
af = aft.parameters[1]
1619-
elseif isleaftype(aft) && isdefined(aft, :instance)
1619+
elseif isconcrete(aft) && isdefined(aft, :instance)
16201620
af = aft.instance
16211621
else
16221622
# TODO jb/functions: take advantage of case where non-constant `af`'s type is known
@@ -1847,9 +1847,9 @@ function abstract_eval_call(e::Expr, vtypes::VarTable, sv::InferenceState)
18471847
if isa(ft, Const)
18481848
f = ft.val
18491849
else
1850-
if isType(ft) && isleaftype(ft.parameters[1])
1850+
if isType(ft) && isconcrete(ft.parameters[1])
18511851
f = ft.parameters[1]
1852-
elseif isleaftype(ft) && isdefined(ft, :instance)
1852+
elseif isconcrete(ft) && isdefined(ft, :instance)
18531853
f = ft.instance
18541854
else
18551855
for i = 2:(length(argtypes)-1)
@@ -1858,7 +1858,7 @@ function abstract_eval_call(e::Expr, vtypes::VarTable, sv::InferenceState)
18581858
end
18591859
end
18601860
# non-constant function, but type is known
1861-
if (isleaftype(ft) || ft <: Type) && !(ft <: Builtin) && !(ft <: IntrinsicFunction)
1861+
if (isconcrete(ft) || ft <: Type) && !(ft <: Builtin) && !(ft <: IntrinsicFunction)
18621862
return abstract_call_gf_by_type(nothing, argtypes_to_type(argtypes), sv)
18631863
end
18641864
return Any
@@ -2370,7 +2370,7 @@ function code_for_method(method::Method, atypes::ANY, sparams::SimpleVector, wor
23702370
if world < min_world(method) || world > max_world(method)
23712371
return nothing
23722372
end
2373-
if method.isstaged && !isleaftype(atypes)
2373+
if method.isstaged && !isconcrete(atypes)
23742374
# don't call staged functions on abstract types.
23752375
# (see issues #8504, #10230)
23762376
# we can't guarantee that their type behavior is monotonic.
@@ -3397,7 +3397,7 @@ function effect_free(e::ANY, src::CodeInfo, mod::Module, allow_volatile::Bool)
33973397
return false
33983398
elseif is_known_call(e, getfield, src, mod)
33993399
et = exprtype(e, src, mod)
3400-
if !isa(et,Const) && !(isType(et) && isleaftype(et))
3400+
if !isa(et,Const) && !(isType(et) && isconcrete(et))
34013401
# first argument must be immutable to ensure e is affect_free
34023402
a = ea[2]
34033403
typ = widenconst(exprtype(a, src, mod))
@@ -3635,15 +3635,15 @@ end
36353635

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

36443644
if (f === typeassert || ft typeof(typeassert)) && length(atypes)==3
36453645
# typeassert(x::S, T) => x, when S<:T
3646-
if isType(atypes[3]) && isleaftype(atypes[3]) &&
3646+
if isType(atypes[3]) && isconcrete(atypes[3]) &&
36473647
atypes[2] atypes[3].parameters[1]
36483648
return (argexprs[2], ())
36493649
end
@@ -3667,7 +3667,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
36673667
if f === Core.invoke && length(atypes) >= 3
36683668
ft = widenconst(atypes[2])
36693669
invoke_tt = widenconst(atypes[3])
3670-
if !isleaftype(ft) || !isleaftype(invoke_tt) || !isType(invoke_tt)
3670+
if !isconcrete(ft) || !isconcrete(invoke_tt) || !isType(invoke_tt)
36713671
return NF
36723672
end
36733673
if !(isa(invoke_tt.parameters[1], Type) &&
@@ -4333,7 +4333,7 @@ function inlining_pass(e::Expr, sv::InferenceState)
43334333
ft = Bool
43344334
else
43354335
f = nothing
4336-
if !( isleaftype(ft) || ft<:Type )
4336+
if !( isconcrete(ft) || ft<:Type )
43374337
return (e, stmts)
43384338
end
43394339
end
@@ -4438,7 +4438,7 @@ function inlining_pass(e::Expr, sv::InferenceState)
44384438
ft = Bool
44394439
else
44404440
f = nothing
4441-
if !( isleaftype(ft) || ft<:Type )
4441+
if !( isconcrete(ft) || ft<:Type )
44424442
return (e,stmts)
44434443
end
44444444
end
@@ -4950,7 +4950,7 @@ function is_allocation(e::ANY, sv::InferenceState)
49504950
return (length(e.args)-1,())
49514951
elseif e.head === :new
49524952
typ = widenconst(exprtype(e, sv.src, sv.mod))
4953-
if isa(typ, DataType) && isleaftype(typ)
4953+
if isa(typ, DataType) && isconcrete(typ)
49544954
nf = length(e.args) - 1
49554955
names = fieldnames(typ)
49564956
@assert(nf <= nfields(typ))

base/interactiveutil.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ versioninfo(verbose::Bool) = versioninfo(STDOUT,verbose)
315315
316316
Prints lowered and type-inferred ASTs for the methods matching the given generic function
317317
and type signature to `io` which defaults to `STDOUT`. The ASTs are annotated in such a way
318-
as to cause "non-leaf" types to be emphasized (if color is available, displayed in red).
319-
This serves as a warning of potential type instability. Not all non-leaf types are particularly
318+
as to cause non-concrete types to be emphasized (if color is available, displayed in red).
319+
This serves as a warning of potential type instability. Not all non-concrete types are particularly
320320
problematic for performance, so the results need to be used judiciously.
321321
See [`@code_warntype`](@ref man-code-warntype) for more information.
322322
"""
@@ -502,7 +502,7 @@ Evaluates the arguments to the function or macro call, determines their types, a
502502
function type_close_enough(x::ANY, t::ANY)
503503
x == t && return true
504504
return (isa(x,DataType) && isa(t,DataType) && x.name === t.name &&
505-
!isleaftype(t) && x <: t) ||
505+
!isconcrete(t) && x <: t) ||
506506
(isa(x,Union) && isa(t,DataType) && (type_close_enough(x.a, t) || type_close_enough(x.b, t)))
507507
end
508508

base/methodshow.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function show(io::IO, m::Method; kwtype::Nullable{DataType}=Nullable{DataType}()
111111
# TODO: more accurate test? (tn.name === "#" name)
112112
ft == typeof(getfield(ft.name.module, ft.name.mt.name))
113113
print(io, ft.name.mt.name)
114-
elseif isa(ft, DataType) && ft.name === Type.body.name && isleaftype(ft)
114+
elseif isa(ft, DataType) && ft.name === Type.body.name && isconcrete(ft)
115115
f = ft.parameters[1]
116116
if isa(f, DataType) && isempty(f.parameters)
117117
print(io, f)
@@ -232,7 +232,7 @@ function show(io::IO, ::MIME"text/html", m::Method; kwtype::Nullable{DataType}=N
232232
isdefined(ft.name.module, ft.name.mt.name) &&
233233
ft == typeof(getfield(ft.name.module, ft.name.mt.name))
234234
print(io, ft.name.mt.name)
235-
elseif isa(ft, DataType) && ft.name === Type.body.name && isleaftype(ft)
235+
elseif isa(ft, DataType) && ft.name === Type.body.name && isconcrete(ft)
236236
f = ft.parameters[1]
237237
if isa(f, DataType) && isempty(f.parameters)
238238
print(io, f)

base/nullable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ end
271271
"""
272272
Return the given type if it is concrete, and `Union{}` otherwise.
273273
"""
274-
nullable_returntype{T}(::Type{T}) = isleaftype(T) ? T : Union{}
274+
nullable_returntype{T}(::Type{T}) = isconcrete(T) ? T : Union{}
275275

276276
"""
277277
map(f, x::Nullable)
@@ -285,7 +285,7 @@ type `Nullable{typeof(f(x))}`.
285285
"""
286286
function map{T}(f, x::Nullable{T})
287287
S = promote_op(f, T)
288-
if isleaftype(S) && null_safe_op(f, T)
288+
if isconcrete(S) && null_safe_op(f, T)
289289
Nullable(f(unsafe_get(x)), !isnull(x))
290290
else
291291
if isnull(x)

base/promotion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ promote_op(::Any...) = (@_pure_meta; Any)
314314
function promote_op{S}(f, ::Type{S})
315315
@_inline_meta
316316
T = _return_type(f, Tuple{_default_type(S)})
317-
isleaftype(S) && return isleaftype(T) ? T : Any
317+
isconcrete(S) && return isconcrete(T) ? T : Any
318318
return typejoin(S, T)
319319
end
320320
function promote_op{R,S}(f, ::Type{R}, ::Type{S})
321321
@_inline_meta
322322
T = _return_type(f, Tuple{_default_type(R), _default_type(S)})
323-
isleaftype(R) && isleaftype(S) && return isleaftype(T) ? T : Any
323+
isconcrete(R) && isconcrete(S) && return isconcrete(T) ? T : Any
324324
return typejoin(R, S, T)
325325
end
326326

0 commit comments

Comments
 (0)