@@ -29,9 +29,9 @@ type VarInfo
29
29
mod:: Module
30
30
end
31
31
32
- function VarInfo (linfo:: LambdaInfo , ast= linfo. ast )
32
+ function VarInfo (linfo:: LambdaInfo , ast= linfo. inferred_ast )
33
33
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)
35
35
end
36
36
vinflist = ast. args[2 ][1 ]:: Array{Any,1}
37
37
vars = map (vi-> vi[1 ], vinflist)
@@ -43,17 +43,17 @@ function VarInfo(linfo::LambdaInfo, ast=linfo.ast)
43
43
gensym_types = Any[ NF for i = 1 : (ngs:: Int ) ]
44
44
nl = label_counter (body)+ 1
45
45
if length (linfo. sparam_vals) > 0
46
- n = length (linfo. sparam_syms)
46
+ n = length (linfo. def . sparam_syms)
47
47
sp = Array (Any, n* 2 )
48
48
for i = 1 : n
49
- sp[i* 2 - 1 ] = linfo. sparam_syms[i]
49
+ sp[i* 2 - 1 ] = linfo. def . sparam_syms[i]
50
50
sp[i* 2 ] = linfo. sparam_vals[i]
51
51
end
52
52
sp = svec (sp... )
53
53
else
54
54
sp = svec ()
55
55
end
56
- VarInfo (sp, vars, gensym_types, vinflist, nl, ObjectIdDict (), linfo. module)
56
+ VarInfo (sp, vars, gensym_types, vinflist, nl, ObjectIdDict (), linfo. def . module)
57
57
end
58
58
59
59
type VarState
648
648
let stagedcache= Dict {Any,Any} ()
649
649
global func_for_method
650
650
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)
651
653
if ! m. isstaged
652
- return m. func
654
+ return LambdaInfo ( m. func, svec (spvals ... ), tt)
653
655
elseif haskey (stagedcache, (m, tt))
654
656
return stagedcache[(m, tt)]
655
657
else
@@ -660,6 +662,7 @@ let stagedcache=Dict{Any,Any}()
660
662
return NF
661
663
end
662
664
f = ccall (:jl_instantiate_staged , Any, (Any, Any, Any), m. func, tt, env)
665
+ f = LambdaInfo (f, svec (spvals... ), tt)
663
666
stagedcache[(m, tt)] = f
664
667
return f
665
668
end
@@ -738,7 +741,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
738
741
limit = false
739
742
# look at the stack to detect recursive calls with growing argument lists
740
743
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)
742
745
limit = true ; break
743
746
end
744
747
sp = sp. prev
@@ -763,7 +766,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, e)
763
766
end
764
767
end
765
768
# print(m,"\n")
766
- (_tree,rt) = typeinf (linfo, sig, m[2 ], linfo)
769
+ (_tree,rt) = typeinf (linfo, sig, m[2 ], linfo. def )
767
770
rettype = tmerge (rettype, rt)
768
771
if is (rettype,Any)
769
772
break
@@ -796,7 +799,7 @@ function invoke_tfunc(f::ANY, types::ANY, argtype::ANY)
796
799
if linfo === NF
797
800
return Any
798
801
end
799
- return typeinf (linfo:: LambdaInfo , ti, env, linfo)[2 ]
802
+ return typeinf (linfo:: LambdaInfo , ti, env, linfo. def )[2 ]
800
803
end
801
804
802
805
# `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)
917
920
return false
918
921
end
919
922
if ! linfo. pure
920
- typeinf (linfo, meth[1 ], meth[2 ], linfo)
923
+ typeinf (linfo, meth[1 ], meth[2 ], linfo. def )
921
924
if ! linfo. pure
922
925
return false
923
926
end
@@ -1381,7 +1384,7 @@ f_argnames(ast) =
1381
1384
1382
1385
is_rest_arg (arg:: ANY ) = (ccall (:jl_is_rest_arg ,Int32,(Any,), arg) != 0 )
1383
1386
1384
- function typeinf_ext (linfo, atypes:: ANY , def)
1387
+ function typeinf_ext (linfo:: LambdaInfo , atypes:: ANY , def:: MethodInfo )
1385
1388
global inference_stack
1386
1389
last = inference_stack
1387
1390
inference_stack = EmptyCallStack ()
@@ -1390,8 +1393,8 @@ function typeinf_ext(linfo, atypes::ANY, def)
1390
1393
return result
1391
1394
end
1392
1395
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 )
1395
1398
1396
1399
CYCLE_ID = 1
1397
1400
@@ -1400,8 +1403,8 @@ CYCLE_ID = 1
1400
1403
1401
1404
# def is the original unspecialized version of a method. we aggregate all
1402
1405
# 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)
1405
1408
atypes = Tuple
1406
1409
end
1407
1410
# dbg =
@@ -1436,8 +1439,8 @@ function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def, cop
1436
1439
end
1437
1440
end
1438
1441
# 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)
1441
1444
end
1442
1445
1443
1446
(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
1474
1477
return (fulltree, result:: Type )
1475
1478
end
1476
1479
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)
1479
1482
1480
1483
# t[n:end]
1481
1484
tupletype_tail (t:: ANY , n) = Tuple{t. parameters[n: end ]. .. }
1482
1485
1483
1486
# 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)
1485
1488
ast0 = def. ast
1486
1489
# if dbg
1487
- # print("typeinf ", linfo .name, " ", object_id(ast0), "\n")
1490
+ # print("typeinf ", def .name, " ", object_id(ast0), "\n")
1488
1491
# end
1489
1492
# if isdefined(:STDOUT)
1490
1493
# write(STDOUT, "typeinf ")
1491
- # write(STDOUT, string(linfo .name))
1494
+ # write(STDOUT, string(def .name))
1492
1495
# write(STDOUT, string(atypes))
1493
1496
# write(STDOUT, '\n')
1494
1497
# end
@@ -1556,15 +1559,15 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1556
1559
end
1557
1560
1558
1561
# 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")
1560
1563
# end
1561
1564
1562
- # if dbg print("typeinf ", linfo .name, " ", atypes, "\n") end
1565
+ # if dbg print("typeinf ", def .name, " ", atypes, "\n") end
1563
1566
1564
1567
if cop
1565
- ast = ccall (:jl_prepare_ast , Any, (Any,), linfo ):: Expr
1568
+ ast = ccall (:jl_prepare_ast , Any, (Any,), def ):: Expr
1566
1569
else
1567
- ast = linfo. ast
1570
+ ast = linfo. inferred_ast
1568
1571
end
1569
1572
1570
1573
sv = VarInfo (linfo, ast)
@@ -1577,8 +1580,8 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1577
1580
push! (sp, sparams[i]. name)
1578
1581
push! (sp, sparams[i+ 1 ])
1579
1582
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]
1582
1585
push! (sp, sym)
1583
1586
push! (sp, TypeVar (sym, Any, true ))
1584
1587
end
@@ -1864,7 +1867,6 @@ function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector,
1864
1867
tuple_elim_pass (fulltree, sv)
1865
1868
getfield_elim_pass (fulltree. args[3 ], sv)
1866
1869
end
1867
- linfo. inferred = true
1868
1870
body = Expr (:block )
1869
1871
body. args = fulltree. args[3 ]. args:: Array{Any,1}
1870
1872
linfo. pure = popmeta! (body, :pure )[1 ]
@@ -2308,7 +2310,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
2308
2310
end
2309
2311
linfo = linfo:: LambdaInfo
2310
2312
2311
- spnames = Any[s for s in linfo. sparam_syms]
2313
+ spnames = Any[s for s in linfo. def . sparam_syms]
2312
2314
if length (linfo. sparam_vals) > 0
2313
2315
spvals = Any[x for x in linfo. sparam_vals]
2314
2316
else
@@ -2358,13 +2360,13 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
2358
2360
methargs = metharg. parameters
2359
2361
nm = length (methargs)
2360
2362
2361
- (ast, ty) = typeinf (linfo, metharg, methsp, linfo, true , true )
2363
+ (ast, ty) = typeinf (linfo, metharg, methsp, linfo. def , true , true )
2362
2364
if is (ast,())
2363
2365
return NF
2364
2366
end
2365
2367
needcopy = true
2366
2368
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)
2368
2370
needcopy = false
2369
2371
end
2370
2372
ast = ast:: Expr
0 commit comments