@@ -29,9 +29,10 @@ type VarInfo
29
29
mod:: Module
30
30
end
31
31
32
- function VarInfo (linfo:: LambdaInfo , ast= linfo. def. unspecialized. ast)
32
+ function VarInfo (linfo:: LambdaInfo , astinfo:: AstInfo = linfo. func)
33
+ ast = astinfo. ast
33
34
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)
35
36
end
36
37
vinflist = ast. args[2 ][1 ]:: Array{Any,1}
37
38
vars = map (vi-> vi[1 ], vinflist)
@@ -43,17 +44,17 @@ function VarInfo(linfo::LambdaInfo, ast=linfo.def.unspecialized.ast)
43
44
gensym_types = Any[ NF for i = 1 : (ngs:: Int ) ]
44
45
nl = label_counter (body)+ 1
45
46
if length (linfo. sparam_vals) > 0
46
- n = length (linfo . def. sparam_syms)
47
+ n = length (astinfo . def. sparam_syms)
47
48
sp = Array (Any, n* 2 )
48
49
for i = 1 : n
49
- sp[i* 2 - 1 ] = linfo . def. sparam_syms[i]
50
+ sp[i* 2 - 1 ] = astinfo . def. sparam_syms[i]
50
51
sp[i* 2 ] = linfo. sparam_vals[i]
51
52
end
52
53
sp = svec (sp... )
53
54
else
54
55
sp = svec ()
55
56
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)
57
58
end
58
59
59
60
type VarState
@@ -733,6 +734,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
733
734
break
734
735
end
735
736
linfo = linfo:: LambdaInfo
737
+ astinfo = linfo. func:: AstInfo
736
738
lsig = length (m[3 ]. sig. parameters)
737
739
# limit argument type tuple based on size of definition signature.
738
740
# 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)
741
743
limit = false
742
744
# look at the stack to detect recursive calls with growing argument lists
743
745
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)
745
747
limit = true ; break
746
748
end
747
749
sp = sp. prev
@@ -766,7 +768,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
766
768
end
767
769
end
768
770
# print(m,"\n")
769
- (_tree,rt) = typeinf (linfo, sig, m[2 ], linfo . def)
771
+ (_tree,rt) = typeinf (linfo, sig, m[2 ], astinfo . def)
770
772
rettype = tmerge (rettype, rt)
771
773
if is (rettype,Any)
772
774
break
@@ -799,7 +801,7 @@ function invoke_tfunc(f::ANY, types::ANY, argtype::ANY)
799
801
if linfo === NF
800
802
return Any
801
803
end
802
- return typeinf (linfo:: LambdaInfo , ti, env, linfo. def)[2 ]
804
+ return typeinf (linfo:: LambdaInfo , ti, env, ( linfo. func :: AstInfo ) . def)[2 ]
803
805
end
804
806
805
807
# `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)
919
921
if linfo === NF
920
922
return false
921
923
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
925
928
return false
926
929
end
927
930
end
@@ -1393,7 +1396,7 @@ function typeinf_ext(linfo::LambdaInfo, atypes::ANY, def::Method)
1393
1396
return result
1394
1397
end
1395
1398
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 )
1397
1400
typeinf (linfo:: LambdaInfo ,atypes:: ANY ,sparams:: ANY ,def:: Method ) = typeinf (linfo,atypes,sparams,def,true ,false )
1398
1401
1399
1402
CYCLE_ID = 1
@@ -1433,19 +1436,19 @@ function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::Met
1433
1436
return (nothing , code)
1434
1437
end
1435
1438
else
1436
- return code # else code is a tuple (ast , type)
1439
+ return code # else code is a tuple (astinfo , type)
1437
1440
end
1438
1441
end
1439
1442
end
1440
1443
end
1441
1444
# TODO : typeinf currently gets stuck without this
1442
1445
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)
1444
1447
end
1445
1448
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 )
1449
1452
end
1450
1453
1451
1454
if ! redo
@@ -1467,18 +1470,18 @@ function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::Met
1467
1470
tfarr[idx] = atypes
1468
1471
# in the "rec" state this tree will not be used again, so store
1469
1472
# just the return type in place of it.
1470
- tfarr[idx+ 1 ] = rec ? result : (fulltree ,result)
1473
+ tfarr[idx+ 1 ] = rec ? result : (astinfo ,result)
1471
1474
tfarr[idx+ 2 ] = rec
1472
1475
else
1473
- def. tfunc[tfunc_idx] = rec ? result : (fulltree ,result)
1476
+ def. tfunc[tfunc_idx] = rec ? result : (astinfo ,result)
1474
1477
def. tfunc[tfunc_idx+ 1 ] = rec
1475
1478
end
1476
1479
1477
- return (fulltree , result:: Type )
1480
+ return (astinfo , result:: Type )
1478
1481
end
1479
1482
1480
1483
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)
1482
1485
1483
1486
# t[n:end]
1484
1487
tupletype_tail (t:: ANY , n) = Tuple{t. parameters[n: end ]. .. }
@@ -1539,7 +1542,7 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1539
1542
# check for recursion
1540
1543
f = inference_stack
1541
1544
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)
1543
1546
# return best guess so far
1544
1547
(f:: CallStack ). recurred = true
1545
1548
(f:: CallStack ). cycleid = CYCLE_ID
@@ -1563,13 +1566,12 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1563
1566
1564
1567
# if dbg print("typeinf ", def.name, " ", atypes, "\n") end
1565
1568
1569
+ astinfo = linfo. func:: AstInfo
1566
1570
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
1570
1572
end
1571
-
1572
- sv = VarInfo (linfo, ast )
1573
+ ast = astinfo . ast :: Expr
1574
+ sv = VarInfo (linfo, astinfo )
1573
1575
1574
1576
if length (linfo. sparam_vals) > 0
1575
1577
# handled by VarInfo constructor
@@ -1580,7 +1582,7 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1580
1582
push! (sp, sparams[i+ 1 ])
1581
1583
end
1582
1584
for i = 1 : length (def. sparam_syms)
1583
- sym = linfo . def. sparam_syms[i]
1585
+ sym = def. sparam_syms[i]
1584
1586
push! (sp, sym)
1585
1587
push! (sp, TypeVar (sym, Any, true ))
1586
1588
end
@@ -1809,7 +1811,7 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1809
1811
# for an example see test/libgit2.jl on 0.5-pre master
1810
1812
# around e.g. commit c072d1ce73345e153e4fddf656cda544013b1219
1811
1813
inference_stack = (inference_stack:: CallStack ). prev
1812
- return (def. unspecialized . ast, Any, false )
1814
+ return (def. ast, Any, false )
1813
1815
end
1814
1816
end
1815
1817
handler_at[l] = cur_hand
@@ -1853,6 +1855,7 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1853
1855
rec = false
1854
1856
end
1855
1857
fulltree = type_annotate (ast, s, sv, frame. result, args)
1858
+ astinfo. inferred = true
1856
1859
1857
1860
if ! rec
1858
1861
@assert fulltree. args[3 ]. head === :body
@@ -1868,12 +1871,13 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1868
1871
end
1869
1872
body = Expr (:block )
1870
1873
body. args = fulltree. args[3 ]. args:: Array{Any,1}
1871
- linfo . pure = popmeta! (body, :pure )[1 ]
1874
+ astinfo . pure = popmeta! (body, :pure )[1 ]
1872
1875
fulltree = ccall (:jl_compress_ast , Any, (Any,Any), def, fulltree)
1873
1876
end
1877
+ astinfo. ast = fulltree
1874
1878
1875
1879
inference_stack = (inference_stack:: CallStack ). prev
1876
- return (fulltree , frame. result, rec)
1880
+ return (astinfo , frame. result, rec)
1877
1881
end
1878
1882
1879
1883
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
2308
2312
end
2309
2313
end
2310
2314
linfo = linfo:: LambdaInfo
2315
+ astinfo = linfo. func:: AstInfo
2311
2316
2312
- spnames = Any[s for s in linfo . def. sparam_syms]
2317
+ spnames = Any[s for s in astinfo . def. sparam_syms]
2313
2318
if length (linfo. sparam_vals) > 0
2314
2319
spvals = Any[x for x in linfo. sparam_vals]
2315
2320
else
@@ -2338,7 +2343,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
2338
2343
# # check call stack to see if this argument list is growing
2339
2344
# st = inference_stack
2340
2345
# 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)
2342
2347
# atypes = limit_tuple_type(atypes)
2343
2348
# meth = _methods(f, atypes, 1)
2344
2349
# if meth === false || length(meth) != 1
@@ -2359,13 +2364,14 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
2359
2364
methargs = metharg. parameters
2360
2365
nm = length (methargs)
2361
2366
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 ,())
2364
2369
return NF
2365
2370
end
2366
2371
needcopy = true
2372
+ ast = astinfo. ast
2367
2373
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)
2369
2375
needcopy = false
2370
2376
end
2371
2377
ast = ast:: Expr
0 commit comments