Skip to content

Commit 64e802b

Browse files
committed
split part of LambdaInfo into MethodInfo
eventually, MethodInfo should be able to merge with Method in the MethodTable->defs and LambdaInfo should be able to replace Method in the MethodTable->cache
1 parent 309593e commit 64e802b

19 files changed

+469
-358
lines changed

base/boot.jl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,28 @@
6060
#end
6161

6262
#type LambdaInfo
63+
# inferred_ast::Expr
64+
# rettype::Any
65+
# sparam_vals::SimpleVector
66+
# specTypes::Any
67+
# unspecialized::LambdaInfo
68+
# def::MethodInfo
69+
# pure::Bool
70+
#end
71+
72+
#type MethodInfo
6373
# ast::Expr
64-
# sparams::Tuple
74+
# sparam_syms::SimpleVector
6575
# tfunc
6676
# name::Symbol
77+
# roots::Vector{Any}
78+
# unspecialized::LambdaInfo
6779
# specializations
68-
# inferred
69-
# file::Symbol
70-
# line::Int
7180
# module::Module
81+
# file::Symbol
82+
# line::Int32
83+
# called::Int32
84+
# pure::Bool
7285
#end
7386

7487
#abstract Ref{T}
@@ -125,7 +138,7 @@ export
125138
Tuple, Type, TypeConstructor, TypeName, TypeVar, Union, Void,
126139
SimpleVector, AbstractArray, DenseArray,
127140
# special objects
128-
Box, Function, Builtin, IntrinsicFunction, LambdaInfo, Method, MethodTable,
141+
Box, Function, Builtin, IntrinsicFunction, LambdaInfo, MethodInfo, Method, MethodTable,
129142
Module, Symbol, Task, Array, WeakRef,
130143
# numeric types
131144
Number, Real, Integer, Bool, Ref, Ptr,
@@ -298,6 +311,7 @@ TypeVar(n::Symbol, lb::ANY, ub::ANY, b::Bool) =
298311
ccall(:jl_new_typevar_, Any, (Any, Any, Any, Any), n, lb::Type, ub::Type, b)::TypeVar
299312

300313
TypeConstructor(p::ANY, t::ANY) = ccall(:jl_new_type_constructor, Any, (Any, Any), p::SimpleVector, t::Type)
314+
LambdaInfo(ast::MethodInfo, sparam_vals::SimpleVector, specTypes::DataType) = ccall(:jl_new_lambda_info, Any, (Any, Any, Any), ast, sparam_vals, specTypes)
301315

302316
Void() = nothing
303317

base/inference.jl

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ type VarInfo
2929
mod::Module
3030
end
3131

32-
function VarInfo(linfo::LambdaInfo, ast=linfo.ast)
32+
function VarInfo(linfo::LambdaInfo, ast=linfo.inferred_ast)
3333
if !isa(ast,Expr)
34-
ast = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo, ast)
34+
ast = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo.def, ast)
3535
end
3636
vinflist = ast.args[2][1]::Array{Any,1}
3737
vars = map(vi->vi[1], vinflist)
@@ -43,17 +43,17 @@ function VarInfo(linfo::LambdaInfo, ast=linfo.ast)
4343
gensym_types = Any[ NF for i = 1:(ngs::Int) ]
4444
nl = label_counter(body)+1
4545
if length(linfo.sparam_vals) > 0
46-
n = length(linfo.sparam_syms)
46+
n = length(linfo.def.sparam_syms)
4747
sp = Array(Any, n*2)
4848
for i = 1:n
49-
sp[i*2-1] = linfo.sparam_syms[i]
49+
sp[i*2-1] = linfo.def.sparam_syms[i]
5050
sp[i*2 ] = linfo.sparam_vals[i]
5151
end
5252
sp = svec(sp...)
5353
else
5454
sp = svec()
5555
end
56-
VarInfo(sp, vars, gensym_types, vinflist, nl, ObjectIdDict(), linfo.module)
56+
VarInfo(sp, vars, gensym_types, vinflist, nl, ObjectIdDict(), linfo.def.module)
5757
end
5858

5959
type VarState
@@ -648,8 +648,10 @@ end
648648
let stagedcache=Dict{Any,Any}()
649649
global func_for_method
650650
function func_for_method(m::Method, tt, env)
651+
spvals = Any[env[i] for i = 2:2:length(env)]
652+
_any(sp -> isa(sp, TypeVar), spvals) && empty!(spvals)
651653
if !m.isstaged
652-
return m.func
654+
return LambdaInfo(m.func, svec(spvals...), tt)
653655
elseif haskey(stagedcache, (m, tt))
654656
return stagedcache[(m, tt)]
655657
else
@@ -660,6 +662,7 @@ let stagedcache=Dict{Any,Any}()
660662
return NF
661663
end
662664
f = ccall(:jl_instantiate_staged, Any, (Any, Any, Any), m.func, tt, env)
665+
f = LambdaInfo(f, svec(spvals...), tt)
663666
stagedcache[(m, tt)] = f
664667
return f
665668
end
@@ -738,7 +741,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
738741
limit = false
739742
# look at the stack to detect recursive calls with growing argument lists
740743
while sp !== EmptyCallStack()
741-
if linfo.ast === sp.ast && length(argtypes) > length(sp.types.parameters)
744+
if linfo.def.ast === sp.ast && length(argtypes) > length(sp.types.parameters)
742745
limit = true; break
743746
end
744747
sp = sp.prev
@@ -763,7 +766,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
763766
end
764767
end
765768
#print(m,"\n")
766-
(_tree,rt) = typeinf(linfo, sig, m[2], linfo)
769+
(_tree,rt) = typeinf(linfo, sig, m[2], linfo.def)
767770
rettype = tmerge(rettype, rt)
768771
if is(rettype,Any)
769772
break
@@ -796,7 +799,7 @@ function invoke_tfunc(f::ANY, types::ANY, argtype::ANY)
796799
if linfo === NF
797800
return Any
798801
end
799-
return typeinf(linfo::LambdaInfo, ti, env, linfo)[2]
802+
return typeinf(linfo::LambdaInfo, ti, env, linfo.def)[2]
800803
end
801804

802805
# `types` is an array of inferred types for expressions in `args`.
@@ -917,7 +920,7 @@ function pure_eval_call(f::ANY, fargs, argtypes::ANY, sv, e)
917920
return false
918921
end
919922
if !linfo.pure
920-
typeinf(linfo, meth[1], meth[2], linfo)
923+
typeinf(linfo, meth[1], meth[2], linfo.def)
921924
if !linfo.pure
922925
return false
923926
end
@@ -1381,7 +1384,7 @@ f_argnames(ast) =
13811384

13821385
is_rest_arg(arg::ANY) = (ccall(:jl_is_rest_arg,Int32,(Any,), arg) != 0)
13831386

1384-
function typeinf_ext(linfo, atypes::ANY, def)
1387+
function typeinf_ext(linfo::LambdaInfo, atypes::ANY, def::MethodInfo)
13851388
global inference_stack
13861389
last = inference_stack
13871390
inference_stack = EmptyCallStack()
@@ -1390,8 +1393,8 @@ function typeinf_ext(linfo, atypes::ANY, def)
13901393
return result
13911394
end
13921395

1393-
typeinf(linfo,atypes::ANY,sparams::ANY) = typeinf(linfo,atypes,sparams,linfo,true,false)
1394-
typeinf(linfo,atypes::ANY,sparams::ANY,def) = typeinf(linfo,atypes,sparams,def,true,false)
1396+
typeinf(linfo::LambdaInfo,atypes::ANY,sparams::ANY) = typeinf(linfo,atypes,sparams,linfo.def,true,false)
1397+
typeinf(linfo::LambdaInfo,atypes::ANY,sparams::ANY,def::MethodInfo) = typeinf(linfo,atypes,sparams,def,true,false)
13951398

13961399
CYCLE_ID = 1
13971400

@@ -1400,8 +1403,8 @@ CYCLE_ID = 1
14001403

14011404
# def is the original unspecialized version of a method. we aggregate all
14021405
# saved type inference data there.
1403-
function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def, cop, needtree)
1404-
if linfo.module === Core && isempty(sparams) && isempty(linfo.sparam_vals)
1406+
function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::MethodInfo, cop, needtree)
1407+
if def.module === Core && isempty(sparams) && isempty(linfo.sparam_vals)
14051408
atypes = Tuple
14061409
end
14071410
#dbg =
@@ -1436,8 +1439,8 @@ function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def, cop
14361439
end
14371440
end
14381441
# TODO: typeinf currently gets stuck without this
1439-
if linfo.name === :abstract_interpret || linfo.name === :tuple_elim_pass || linfo.name === :abstract_call_gf
1440-
return (linfo.ast, Any)
1442+
if def.name === :abstract_interpret || def.name === :tuple_elim_pass || def.name === :abstract_call_gf
1443+
return (def.ast, Any)
14411444
end
14421445

14431446
(fulltree, result, rec) = typeinf_uncached(linfo, atypes, sparams, def, curtype, cop, true)
@@ -1474,21 +1477,21 @@ function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def, cop
14741477
return (fulltree, result::Type)
14751478
end
14761479

1477-
typeinf_uncached(linfo, atypes::ANY, sparams::ANY; optimize=true) =
1478-
typeinf_uncached(linfo, atypes, sparams, linfo, Bottom, true, optimize)
1480+
typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::ANY; optimize=true) =
1481+
typeinf_uncached(linfo::LambdaInfo, atypes, sparams, linfo, Bottom, true, optimize)
14791482

14801483
# t[n:end]
14811484
tupletype_tail(t::ANY, n) = Tuple{t.parameters[n:end]...}
14821485

14831486
# compute an inferred (optionally optimized) AST without global effects (i.e. updating the cache)
1484-
function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def, curtype, cop, optimize)
1487+
function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::MethodInfo, curtype, cop, optimize)
14851488
ast0 = def.ast
14861489
#if dbg
1487-
# print("typeinf ", linfo.name, " ", object_id(ast0), "\n")
1490+
# print("typeinf ", def.name, " ", object_id(ast0), "\n")
14881491
#end
14891492
# if isdefined(:STDOUT)
14901493
# write(STDOUT, "typeinf ")
1491-
# write(STDOUT, string(linfo.name))
1494+
# write(STDOUT, string(def.name))
14921495
# write(STDOUT, string(atypes))
14931496
# write(STDOUT, '\n')
14941497
# end
@@ -1556,15 +1559,15 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
15561559
end
15571560

15581561
#if trace_inf
1559-
# print("typeinf ", linfo.name, " ", atypes, " ", linfo.file,":",linfo.line,"\n")
1562+
# print("typeinf ", def.name, " ", atypes, " ", def.file,":",def.line,"\n")
15601563
#end
15611564

1562-
#if dbg print("typeinf ", linfo.name, " ", atypes, "\n") end
1565+
#if dbg print("typeinf ", def.name, " ", atypes, "\n") end
15631566

15641567
if cop
1565-
ast = ccall(:jl_prepare_ast, Any, (Any,), linfo)::Expr
1568+
ast = ccall(:jl_prepare_ast, Any, (Any,), def)::Expr
15661569
else
1567-
ast = linfo.ast
1570+
ast = linfo.inferred_ast
15681571
end
15691572

15701573
sv = VarInfo(linfo, ast)
@@ -1577,8 +1580,8 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
15771580
push!(sp, sparams[i].name)
15781581
push!(sp, sparams[i+1])
15791582
end
1580-
for i = 1:length(linfo.sparam_syms)
1581-
sym = linfo.sparam_syms[i]
1583+
for i = 1:length(def.sparam_syms)
1584+
sym = linfo.def.sparam_syms[i]
15821585
push!(sp, sym)
15831586
push!(sp, TypeVar(sym, Any, true))
15841587
end
@@ -1864,7 +1867,6 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
18641867
tuple_elim_pass(fulltree, sv)
18651868
getfield_elim_pass(fulltree.args[3], sv)
18661869
end
1867-
linfo.inferred = true
18681870
body = Expr(:block)
18691871
body.args = fulltree.args[3].args::Array{Any,1}
18701872
linfo.pure = popmeta!(body, :pure)[1]
@@ -2308,7 +2310,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
23082310
end
23092311
linfo = linfo::LambdaInfo
23102312

2311-
spnames = Any[s for s in linfo.sparam_syms]
2313+
spnames = Any[s for s in linfo.def.sparam_syms]
23122314
if length(linfo.sparam_vals) > 0
23132315
spvals = Any[x for x in linfo.sparam_vals]
23142316
else
@@ -2358,13 +2360,13 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
23582360
methargs = metharg.parameters
23592361
nm = length(methargs)
23602362

2361-
(ast, ty) = typeinf(linfo, metharg, methsp, linfo, true, true)
2363+
(ast, ty) = typeinf(linfo, metharg, methsp, linfo.def, true, true)
23622364
if is(ast,())
23632365
return NF
23642366
end
23652367
needcopy = true
23662368
if !isa(ast,Expr)
2367-
ast = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo, ast)
2369+
ast = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo.def, ast)
23682370
needcopy = false
23692371
end
23702372
ast = ast::Expr

base/reflection.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ done(mt::MethodTable, m::Method) = false
245245
done(mt::MethodTable, i::Void) = true
246246

247247
uncompressed_ast(l::LambdaInfo) =
248+
isa(l.inferred_ast,Expr) ? l.inferred_ast : ccall(:jl_uncompress_ast, Any, (Any,Any), l.def, l.inferred_ast)
249+
uncompressed_ast(l::MethodInfo) =
248250
isa(l.ast,Expr) ? l.ast : ccall(:jl_uncompress_ast, Any, (Any,Any), l, l.ast)
249251

250252
# Printing code representations in IR and assembly
@@ -291,14 +293,14 @@ function code_typed(f::ANY, types::ANY=Tuple; optimize=true)
291293
for x in _methods(f,types,-1)
292294
linfo = func_for_method_checked(x, types)
293295
if optimize
294-
(tree, ty) = Core.Inference.typeinf(linfo, x[1], x[2], linfo,
296+
(tree, ty) = Core.Inference.typeinf(linfo, x[1], x[2], linfo.def,
295297
true, true)
296298
else
297299
(tree, ty) = Core.Inference.typeinf_uncached(linfo, x[1], x[2],
298300
optimize=false)
299301
end
300302
if !isa(tree, Expr)
301-
tree = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo, tree)
303+
tree = ccall(:jl_uncompress_ast, Any, (Any,Any), linfo.def, tree)
302304
end
303305
push!(asts, tree)
304306
end

base/serialize.jl

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const TAGS = Any[
1919
#LongSymbol, LongTuple, LongExpr,
2020
Symbol, Tuple, Expr, # dummy entries, intentionally shadowed by earlier ones
2121
LineNumberNode, SymbolNode, LabelNode, GotoNode,
22-
QuoteNode, TopNode, TypeVar, Box, LambdaInfo,
22+
QuoteNode, TopNode, TypeVar, Box, MethodInfo,
2323
Module, #=UndefRefTag=#Symbol, Task, ASCIIString, UTF8String,
2424
UTF16String, UTF32String, Float16,
2525
SimpleVector, #=BackrefTag=#Symbol, :reserved11, :reserved12,
@@ -72,7 +72,7 @@ const BACKREF_TAG = Int32(sertag(SimpleVector)+1)
7272
const EXPR_TAG = sertag(Expr)
7373
const LONGEXPR_TAG = Int32(sertag(Expr)+3)
7474
const MODULE_TAG = sertag(Module)
75-
const LAMBDASTATICDATA_TAG = sertag(LambdaInfo)
75+
const METHODDATA_TAG = sertag(MethodInfo)
7676
const TASK_TAG = sertag(Task)
7777
const DATATYPE_TAG = sertag(DataType)
7878
const TYPENAME_TAG = sertag(TypeName)
@@ -307,19 +307,17 @@ function object_number(l::ANY)
307307
return ln
308308
end
309309

310-
function serialize(s::SerializationState, linfo::LambdaInfo)
310+
function serialize(s::SerializationState, linfo::MethodInfo)
311311
serialize_cycle(s, linfo) && return
312-
writetag(s.io, LAMBDASTATICDATA_TAG)
312+
writetag(s.io, METHODDATA_TAG)
313313
serialize(s, object_number(linfo))
314-
serialize(s, uncompressed_ast(linfo))
315-
if isdefined(linfo.def, :roots)
316-
serialize(s, linfo.def.roots::Vector{Any})
314+
serialize(s, linfo.ast)
315+
if isdefined(linfo, :roots)
316+
serialize(s, linfo.roots::Vector{Any})
317317
else
318318
serialize(s, Any[])
319319
end
320320
serialize(s, linfo.sparam_syms)
321-
serialize(s, linfo.sparam_vals)
322-
serialize(s, linfo.inferred)
323321
serialize(s, linfo.module)
324322
serialize(s, linfo.name)
325323
serialize(s, linfo.file)
@@ -543,21 +541,19 @@ end
543541

544542
const known_object_data = Dict()
545543

546-
function deserialize(s::SerializationState, ::Type{LambdaInfo})
544+
function deserialize(s::SerializationState, ::Type{MethodInfo})
547545
lnumber = deserialize(s)
548546
if haskey(known_object_data, lnumber)
549-
linfo = known_object_data[lnumber]::LambdaInfo
547+
linfo = known_object_data[lnumber]::MethodInfo
550548
makenew = false
551549
else
552-
linfo = ccall(:jl_new_lambda_info, Any, (Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}), C_NULL, C_NULL, C_NULL, C_NULL)::LambdaInfo
550+
linfo = ccall(:jl_new_method_info, Any, (Ptr{Void}, Ptr{Void}, Ptr{Void}), C_NULL, C_NULL, C_NULL)::MethodInfo
553551
makenew = true
554552
end
555553
deserialize_cycle(s, linfo)
556-
ast = deserialize(s)::Expr
554+
ast = deserialize(s)
557555
roots = deserialize(s)::Vector{Any}
558556
sparam_syms = deserialize(s)::SimpleVector
559-
sparam_vals = deserialize(s)::SimpleVector
560-
infr = deserialize(s)::Bool
561557
mod = deserialize(s)::Module
562558
name = deserialize(s)
563559
file = deserialize(s)
@@ -566,8 +562,6 @@ function deserialize(s::SerializationState, ::Type{LambdaInfo})
566562
if makenew
567563
linfo.ast = ast
568564
linfo.sparam_syms = sparam_syms
569-
linfo.sparam_vals = sparam_vals
570-
linfo.inferred = infr
571565
linfo.module = mod
572566
linfo.roots = roots
573567
linfo.name = name

base/stacktraces.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@ 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-
print(io, linfo.name)
143-
if isdefined(linfo, 8)
144-
Base.show_delim_array(io, linfo.(#=specTypes=#8).parameters, "(", ", ", ")", false)
145-
end
142+
print(io, linfo.def.name)
143+
Base.show_delim_array(io, linfo.specTypes.parameters, "(", ", ", ")", false)
146144
end
147145
end
148146

0 commit comments

Comments
 (0)