Skip to content

Commit 76fe03d

Browse files
committed
merge LambdaInfo and MethodList, but split off AstInfo
1 parent 1fed09e commit 76fe03d

21 files changed

+767
-756
lines changed

base/boot.jl

+16-9
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,26 @@
5959
# name::Symbol
6060
#end
6161

62-
#type LambdaInfo
62+
#type AstInfo
6363
# ast::Union{Expr, Vector{UInt8}}
64-
# rettype::Any
65-
# sparam_vals::SimpleVector
66-
# specTypes::Any
6764
# unspecialized_ducttape::LambdaInfo
6865
# def::Method
6966
# pure::Bool
67+
# called::Int32
68+
#end
69+
70+
#type LambdaInfo
71+
# next::Union{LambdaInfo,Void}
72+
# sig::Any
73+
# rettype::Any
74+
# va::Bool
75+
# sparam_vals::SimpleVector
76+
# func
77+
# ...
7078
#end
7179

7280
#type Method
81+
# ast::AstInfo
7382
# sig::Type
7483
# tvars::Expr
7584
# sparam_syms::SimpleVector
@@ -81,10 +90,7 @@
8190
# module::Module
8291
# file::Symbol
8392
# line::Int32
84-
# called::Int32
85-
# pure::Bool
8693
# isstaged::Bool
87-
# va::Bool
8894
# invokes::Union{MethodTable,Void}
8995
# next::Union{Method,Void}
9096
#end
@@ -143,7 +149,7 @@ export
143149
Tuple, Type, TypeConstructor, TypeName, TypeVar, Union, Void,
144150
SimpleVector, AbstractArray, DenseArray,
145151
# special objects
146-
Box, Function, Builtin, IntrinsicFunction, LambdaInfo, MethodList, Method, MethodTable,
152+
Box, Function, Builtin, IntrinsicFunction, LambdaInfo, AstInfo, Method, MethodTable,
147153
Module, Symbol, Task, Array, WeakRef,
148154
# numeric types
149155
Number, Real, Integer, Bool, Ref, Ptr,
@@ -316,7 +322,7 @@ TypeVar(n::Symbol, lb::ANY, ub::ANY, b::Bool) =
316322
ccall(:jl_new_typevar_, Any, (Any, Any, Any, Any), n, lb::Type, ub::Type, b)::TypeVar
317323

318324
TypeConstructor(p::ANY, t::ANY) = ccall(:jl_new_type_constructor, Any, (Any, Any), p::SimpleVector, t::Type)
319-
LambdaInfo(ast::Method, sparam_vals::SimpleVector, specTypes::DataType) = ccall(:jl_spec_lambda_info, Any, (Any, Any, Any), ast.unspecialized, sparam_vals, specTypes)
325+
LambdaInfo(m::Method, sparam_vals::SimpleVector, specTypes::DataType) = ccall(:jl_new_lambda_info, Any, (Any, Any, Any), m.ast, sparam_vals, specTypes)
320326

321327
Void() = nothing
322328

@@ -364,5 +370,6 @@ Array{T}(::Type{T}, d::Int...) = Array{T}(d)
364370
Array{T}(::Type{T}, m::Int) = Array{T,1}(m)
365371
Array{T}(::Type{T}, m::Int,n::Int) = Array{T,2}(m,n)
366372
Array{T}(::Type{T}, m::Int,n::Int,o::Int) = Array{T,3}(m,n,o)
373+
Array{T,N}(::Type{T}, d::NTuple{N,Int}) = Array{T,N}(d)
367374

368375
ccall(:jl_set_istopmod, Void, (Bool,), true)

base/inference.jl

+42-36
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ type VarInfo
2929
mod::Module
3030
end
3131

32-
function VarInfo(linfo::LambdaInfo, ast=linfo.def.unspecialized.ast)
32+
function VarInfo(linfo::LambdaInfo, astinfo::AstInfo=linfo.func)
33+
ast = astinfo.ast
3334
if !isa(ast,Expr)
34-
ast = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo.def, ast)
35+
ast = ccall(:jl_uncompress_ast, Any, (Any,Any), astinfo.def, ast)
3536
end
3637
vinflist = ast.args[2][1]::Array{Any,1}
3738
vars = map(vi->vi[1], vinflist)
@@ -43,17 +44,17 @@ function VarInfo(linfo::LambdaInfo, ast=linfo.def.unspecialized.ast)
4344
gensym_types = Any[ NF for i = 1:(ngs::Int) ]
4445
nl = label_counter(body)+1
4546
if length(linfo.sparam_vals) > 0
46-
n = length(linfo.def.sparam_syms)
47+
n = length(astinfo.def.sparam_syms)
4748
sp = Array(Any, n*2)
4849
for i = 1:n
49-
sp[i*2-1] = linfo.def.sparam_syms[i]
50+
sp[i*2-1] = astinfo.def.sparam_syms[i]
5051
sp[i*2 ] = linfo.sparam_vals[i]
5152
end
5253
sp = svec(sp...)
5354
else
5455
sp = svec()
5556
end
56-
VarInfo(sp, vars, gensym_types, vinflist, nl, ObjectIdDict(), linfo.def.module)
57+
VarInfo(sp, vars, gensym_types, vinflist, nl, ObjectIdDict(), astinfo.def.module)
5758
end
5859

5960
type VarState
@@ -733,6 +734,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
733734
break
734735
end
735736
linfo = linfo::LambdaInfo
737+
astinfo = linfo.func::AstInfo
736738
lsig = length(m[3].sig.parameters)
737739
# limit argument type tuple based on size of definition signature.
738740
# for example, given function f(T, Any...), limit to 3 arguments
@@ -741,7 +743,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
741743
limit = false
742744
# look at the stack to detect recursive calls with growing argument lists
743745
while sp !== EmptyCallStack()
744-
if linfo.def === sp.meth && length(argtypes) > length(sp.types.parameters)
746+
if astinfo.def === sp.meth && length(argtypes) > length(sp.types.parameters)
745747
limit = true; break
746748
end
747749
sp = sp.prev
@@ -766,7 +768,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
766768
end
767769
end
768770
#print(m,"\n")
769-
(_tree,rt) = typeinf(linfo, sig, m[2], linfo.def)
771+
(_tree,rt) = typeinf(linfo, sig, m[2], astinfo.def)
770772
rettype = tmerge(rettype, rt)
771773
if is(rettype,Any)
772774
break
@@ -799,7 +801,7 @@ function invoke_tfunc(f::ANY, types::ANY, argtype::ANY)
799801
if linfo === NF
800802
return Any
801803
end
802-
return typeinf(linfo::LambdaInfo, ti, env, linfo.def)[2]
804+
return typeinf(linfo::LambdaInfo, ti, env, (linfo.func::AstInfo).def)[2]
803805
end
804806

805807
# `types` is an array of inferred types for expressions in `args`.
@@ -919,9 +921,10 @@ function pure_eval_call(f::ANY, fargs, argtypes::ANY, sv, e)
919921
if linfo === NF
920922
return false
921923
end
922-
if !linfo.pure
923-
typeinf(linfo, meth[1], meth[2], linfo.def)
924-
if !linfo.pure
924+
astinfo = linfo.func::AstInfo
925+
if !astinfo.pure
926+
typeinf(linfo, meth[1], meth[2], astinfo.def)
927+
if !astinfo.pure
925928
return false
926929
end
927930
end
@@ -1393,7 +1396,7 @@ function typeinf_ext(linfo::LambdaInfo, atypes::ANY, def::Method)
13931396
return result
13941397
end
13951398

1396-
typeinf(linfo::LambdaInfo,atypes::ANY,sparams::ANY) = typeinf(linfo,atypes,sparams,linfo.def,true,false)
1399+
typeinf(linfo::LambdaInfo,atypes::ANY,sparams::ANY) = typeinf(linfo,atypes,sparams,(linfo.func::AstInfo).def,true,false)
13971400
typeinf(linfo::LambdaInfo,atypes::ANY,sparams::ANY,def::Method) = typeinf(linfo,atypes,sparams,def,true,false)
13981401

13991402
CYCLE_ID = 1
@@ -1433,19 +1436,19 @@ function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::Met
14331436
return (nothing, code)
14341437
end
14351438
else
1436-
return code # else code is a tuple (ast, type)
1439+
return code # else code is a tuple (astinfo, type)
14371440
end
14381441
end
14391442
end
14401443
end
14411444
# TODO: typeinf currently gets stuck without this
14421445
if def.name === :abstract_interpret || def.name === :tuple_elim_pass || def.name === :abstract_call_gf
1443-
return (def.unspecialized.ast, Any)
1446+
return (def.ast, Any)
14441447
end
14451448

1446-
(fulltree, result, rec) = typeinf_uncached(linfo, atypes, sparams, def, curtype, cop, true)
1447-
if fulltree === ()
1448-
return (fulltree, result::Type)
1449+
(astinfo, result, rec) = typeinf_uncached(linfo, atypes, sparams, def, curtype, cop, true)
1450+
if astinfo === ()
1451+
return (def.ast, result::Type)
14491452
end
14501453

14511454
if !redo
@@ -1467,18 +1470,18 @@ function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::Met
14671470
tfarr[idx] = atypes
14681471
# in the "rec" state this tree will not be used again, so store
14691472
# just the return type in place of it.
1470-
tfarr[idx+1] = rec ? result : (fulltree,result)
1473+
tfarr[idx+1] = rec ? result : (astinfo,result)
14711474
tfarr[idx+2] = rec
14721475
else
1473-
def.tfunc[tfunc_idx] = rec ? result : (fulltree,result)
1476+
def.tfunc[tfunc_idx] = rec ? result : (astinfo,result)
14741477
def.tfunc[tfunc_idx+1] = rec
14751478
end
14761479

1477-
return (fulltree, result::Type)
1480+
return (astinfo, result::Type)
14781481
end
14791482

14801483
typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::ANY; optimize=true) =
1481-
typeinf_uncached(linfo::LambdaInfo, atypes, sparams, linfo.def, Bottom, true, optimize)
1484+
typeinf_uncached(linfo::LambdaInfo, atypes, sparams, (linfo.func::AstInfo).def, Bottom, true, optimize)
14821485

14831486
# t[n:end]
14841487
tupletype_tail(t::ANY, n) = Tuple{t.parameters[n:end]...}
@@ -1539,7 +1542,7 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
15391542
# check for recursion
15401543
f = inference_stack
15411544
while !isa(f,EmptyCallStack)
1542-
if (is(f.meth, def) || f.meth.unspecialized.ast == def.unspecialized.ast) && typeseq(f.types, atypes)
1545+
if (is(f.meth, def) || f.meth.ast.ast == def.ast.ast) && typeseq(f.types, atypes)
15431546
# return best guess so far
15441547
(f::CallStack).recurred = true
15451548
(f::CallStack).cycleid = CYCLE_ID
@@ -1563,13 +1566,12 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
15631566

15641567
#if dbg print("typeinf ", def.name, " ", atypes, "\n") end
15651568

1569+
astinfo = linfo.func::AstInfo
15661570
if cop
1567-
ast = ccall(:jl_prepare_ast, Any, (Any,), def)::Expr
1568-
else
1569-
ast = linfo.ast
1571+
astinfo = ccall(:jl_copy_ast_info, Any, (Any,), astinfo)::AstInfo
15701572
end
1571-
1572-
sv = VarInfo(linfo, ast)
1573+
ast = astinfo.ast::Expr
1574+
sv = VarInfo(linfo, astinfo)
15731575

15741576
if length(linfo.sparam_vals) > 0
15751577
# handled by VarInfo constructor
@@ -1580,7 +1582,7 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
15801582
push!(sp, sparams[i+1])
15811583
end
15821584
for i = 1:length(def.sparam_syms)
1583-
sym = linfo.def.sparam_syms[i]
1585+
sym = def.sparam_syms[i]
15841586
push!(sp, sym)
15851587
push!(sp, TypeVar(sym, Any, true))
15861588
end
@@ -1809,7 +1811,7 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
18091811
# for an example see test/libgit2.jl on 0.5-pre master
18101812
# around e.g. commit c072d1ce73345e153e4fddf656cda544013b1219
18111813
inference_stack = (inference_stack::CallStack).prev
1812-
return (def.unspecialized.ast, Any, false)
1814+
return (def.ast, Any, false)
18131815
end
18141816
end
18151817
handler_at[l] = cur_hand
@@ -1853,6 +1855,7 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
18531855
rec = false
18541856
end
18551857
fulltree = type_annotate(ast, s, sv, frame.result, args)
1858+
astinfo.inferred = true
18561859

18571860
if !rec
18581861
@assert fulltree.args[3].head === :body
@@ -1868,12 +1871,13 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
18681871
end
18691872
body = Expr(:block)
18701873
body.args = fulltree.args[3].args::Array{Any,1}
1871-
linfo.pure = popmeta!(body, :pure)[1]
1874+
astinfo.pure = popmeta!(body, :pure)[1]
18721875
fulltree = ccall(:jl_compress_ast, Any, (Any,Any), def, fulltree)
18731876
end
1877+
astinfo.ast = fulltree
18741878

18751879
inference_stack = (inference_stack::CallStack).prev
1876-
return (fulltree, frame.result, rec)
1880+
return (astinfo, frame.result, rec)
18771881
end
18781882

18791883
function record_var_type(e::Symbol, t::ANY, decls)
@@ -2308,8 +2312,9 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
23082312
end
23092313
end
23102314
linfo = linfo::LambdaInfo
2315+
astinfo = linfo.func::AstInfo
23112316

2312-
spnames = Any[s for s in linfo.def.sparam_syms]
2317+
spnames = Any[s for s in astinfo.def.sparam_syms]
23132318
if length(linfo.sparam_vals) > 0
23142319
spvals = Any[x for x in linfo.sparam_vals]
23152320
else
@@ -2338,7 +2343,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
23382343
# # check call stack to see if this argument list is growing
23392344
# st = inference_stack
23402345
# while !isa(st, EmptyCallStack)
2341-
# if st.meth === linfo.def && length(atypes) > length(st.types)
2346+
# if st.meth === astinfo.def && length(atypes) > length(st.types)
23422347
# atypes = limit_tuple_type(atypes)
23432348
# meth = _methods(f, atypes, 1)
23442349
# if meth === false || length(meth) != 1
@@ -2359,13 +2364,14 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
23592364
methargs = metharg.parameters
23602365
nm = length(methargs)
23612366

2362-
(ast, ty) = typeinf(linfo, metharg, methsp, linfo.def, true, true)
2363-
if is(ast,())
2367+
(astinfo, ty) = typeinf(linfo, metharg, methsp, astinfo.def, true, true)
2368+
if is(astinfo,())
23642369
return NF
23652370
end
23662371
needcopy = true
2372+
ast = astinfo.ast
23672373
if !isa(ast,Expr)
2368-
ast = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo.def, ast)
2374+
ast = ccall(:jl_uncompress_ast, Any, (Any,Any), astinfo.def, ast)
23692375
needcopy = false
23702376
end
23712377
ast = ast::Expr

base/interactiveutil.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -598,17 +598,20 @@ function summarysize(obj::MethodTable, seen, excl)
598598
return size
599599
end
600600

601-
function summarysize(m::MethodList, seen, excl)
601+
function summarysize(m::LambdaInfo, seen, excl)
602602
size::Int = 0
603603
while true
604604
haskey(seen, m) ? (return size) : (seen[m] = true)
605605
size += Core.sizeof(m)
606606
if isdefined(m, :func)
607607
size += summarysize(m.func, seen, excl)::Int
608608
end
609+
if isdefined(m, :sparam_vals)
610+
size += summarysize(m.sparam_vals, seen, excl)::Int
611+
end
609612
size += summarysize(m.sig, seen, excl)::Int
610613
m.next === nothing && break
611-
m = m.next::MethodList
614+
m = m.next::LambdaInfo
612615
end
613616
return size
614617
end

base/reflection.jl

+7-6
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ next(mt::MethodTable, m::Method) = (m, m.next)
244244
done(mt::MethodTable, m::Method) = false
245245
done(mt::MethodTable, i::Void) = true
246246

247-
uncompressed_ast(l::LambdaInfo) =
247+
uncompressed_ast(l::AstInfo) =
248248
isa(l.ast, Expr) ? l.ast : ccall(:jl_uncompress_ast, Any, (Any,Any), l.def, l.ast)
249-
uncompressed_ast(l::Method) = uncompressed_ast(l.unspecialized)
249+
uncompressed_ast(l::Method) = uncompressed_ast(l.ast)
250250

251251
# Printing code representations in IR and assembly
252252
function _dump_function(f, t::ANY, native, wrapper, strip_ir_metadata, dump_module)
@@ -292,14 +292,15 @@ function code_typed(f::ANY, types::ANY=Tuple; optimize=true)
292292
for x in _methods(f,types,-1)
293293
linfo = func_for_method_checked(x, types)
294294
if optimize
295-
(tree, ty) = Core.Inference.typeinf(linfo, x[1], x[2], linfo.def,
295+
(astinfo, ty) = Core.Inference.typeinf(linfo, x[1], x[2], (linfo.func::AstInfo).def,
296296
true, true)
297297
else
298-
(tree, ty) = Core.Inference.typeinf_uncached(linfo, x[1], x[2],
298+
(astinfo, ty) = Core.Inference.typeinf_uncached(linfo, x[1], x[2],
299299
optimize=false)
300300
end
301+
tree = astinfo.ast
301302
if !isa(tree, Expr)
302-
tree = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo.def, tree)
303+
tree = ccall(:jl_uncompress_ast, Any, (Any,Any), astinfo.def, tree)
303304
end
304305
push!(asts, tree)
305306
end
@@ -311,7 +312,7 @@ function return_types(f::ANY, types::ANY=Tuple)
311312
rt = []
312313
for x in _methods(f,types,-1)
313314
linfo = func_for_method_checked(x,types)
314-
(tree, ty) = Core.Inference.typeinf(linfo, x[1], x[2])
315+
(astinfo, ty) = Core.Inference.typeinf(linfo, x[1], x[2])
315316
push!(rt, ty)
316317
end
317318
rt

base/stacktraces.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function show_spec_linfo(io::IO, frame::StackFrame)
139139
print(io, frame.func !== empty_sym ? frame.func : "?")
140140
else
141141
linfo = get(frame.outer_linfo)
142-
params = linfo.specTypes.parameters
142+
params = linfo.sig.parameters
143143
ft = params[1]
144144
if ft <: Function && isempty(ft.parameters) &&
145145
isdefined(ft.name.module, ft.name.mt.name) &&

base/sysimg.jl

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ include("array.jl")
7373
(::Type{Matrix})() = Array{Any}(0, 0)
7474

7575
# TODO: possibly turn these into deprecations
76-
Array{T,N}(::Type{T}, d::NTuple{N,Int}) = Array{T}(d)
7776
Array{T}(::Type{T}, d::Integer...) = Array{T}(convert(Tuple{Vararg{Int}}, d))
7877
Array{T}(::Type{T}, m::Integer) = Array{T}(m)
7978
Array{T}(::Type{T}, m::Integer,n::Integer) = Array{T}(m,n)

0 commit comments

Comments
 (0)