@@ -72,7 +72,7 @@ type crate_ctxt = rec(session::session sess,
72
72
mutable uint cache_hits ,
73
73
mutable uint cache_misses ,
74
74
ty:: ctxt tcx,
75
- mutable node_type_table node_types ) ;
75
+ node_type_table node_types) ;
76
76
77
77
type fn_ctxt = rec ( ty:: t ret_ty ,
78
78
ast:: purity purity,
@@ -372,12 +372,13 @@ fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast::ty ast_ty) -> ty::t {
372
372
}
373
373
374
374
// Writes a type parameter count and type pair into the node type table.
375
- fn write_type( & @crate_ctxt cx , uint node_id,
375
+ fn write_type( & node_type_table ntt , uint node_id,
376
376
& ty_param_substs_opt_and_ty tpot) {
377
- _vec:: grow_set[ option:: t[ ty:: ty_param_substs_opt_and_ty] ] ( cx. node_types,
378
- 0 u,
379
- none[ ty_param_substs_opt_and_ty] ,
380
- some[ ty_param_substs_opt_and_ty] ( tpot) ) ;
377
+ _vec:: grow_set[ option:: t[ ty:: ty_param_substs_opt_and_ty] ]
378
+ ( * ntt,
379
+ 0 u,
380
+ none[ ty_param_substs_opt_and_ty] ,
381
+ some[ ty_param_substs_opt_and_ty] ( tpot) ) ;
381
382
}
382
383
383
384
@@ -396,7 +397,8 @@ mod Collect {
396
397
type ctxt = rec( session:: session sess,
397
398
@ty_item_table id_to_ty_item,
398
399
ty:: type_cache type_cache,
399
- ty:: ctxt tcx) ;
400
+ ty:: ctxt tcx,
401
+ node_type_table node_types) ;
400
402
type env = rec( @ctxt cx, ast:: native_abi abi) ;
401
403
402
404
fn ty_of_fn_decl( & @ctxt cx,
@@ -824,16 +826,23 @@ mod Collect {
824
826
ast:: ann_type( ast:: ann_tag( a) , typ,
825
827
none[ vec[ ty:: t] ] ,
826
828
none[ @ts_ann] ) ) ;
829
+ write_type( e. cx. node_types, ast:: ann_tag( a) ,
830
+ tup( none[ vec[ ty:: t] ] , typ) ) ;
827
831
ret @fold:: respan[ ast:: item_] ( sp, item) ;
828
832
}
829
833
830
834
fn collect_item_types( & session:: session sess, & ty:: ctxt tcx,
831
835
& @ast:: crate crate)
832
- -> tup( @ast:: crate , ty:: type_cache, @ty_item_table) {
836
+ -> tup( @ast:: crate, ty:: type_cache, @ty_item_table,
837
+ node_type_table) {
833
838
// First pass: collect all type item IDs:
834
839
auto module = crate . node. module;
835
840
auto id_to_ty_item = @common:: new_def_hash[ any_item] ( ) ;
836
841
842
+ let vec[ mutable option:: t[ ty:: ty_param_substs_opt_and_ty] ] ntt_sub =
843
+ vec( mutable) ;
844
+ let node_type_table ntt = @mutable ntt_sub;
845
+
837
846
auto fld_1 = fold:: new_identity_fold[ @ty_item_table] ( ) ;
838
847
fld_1 = @rec( update_env_for_item = bind collect( _, _) ,
839
848
update_env_for_native_item = bind collect_native( _, _)
@@ -846,7 +855,8 @@ mod Collect {
846
855
auto cx = @rec( sess=sess,
847
856
id_to_ty_item=id_to_ty_item,
848
857
type_cache=type_cache,
849
- tcx=tcx) ;
858
+ tcx=tcx,
859
+ node_types=ntt) ;
850
860
851
861
let @env e = @rec( cx=cx, abi=ast:: native_abi_cdecl) ;
852
862
@@ -863,7 +873,7 @@ mod Collect {
863
873
fold_item_tag = bind fold_item_tag( _, _, _, _, _, _, _)
864
874
with * fld_2) ;
865
875
auto crate_ = fold:: fold_crate[ @env] ( e, fld_2, crate ) ;
866
- ret tup( crate_, type_cache, id_to_ty_item) ;
876
+ ret tup( crate_, type_cache, id_to_ty_item, ntt ) ;
867
877
}
868
878
}
869
879
@@ -1135,13 +1145,17 @@ mod Pushdown {
1135
1145
p_1 = ast:: pat_wild( ast:: ann_type( ast:: ann_tag( ann) , t,
1136
1146
none[ vec[ ty:: t] ] ,
1137
1147
none[ @ts_ann] ) ) ;
1148
+ write_type( fcx. ccx. node_types, ast:: ann_tag( ann) ,
1149
+ tup( none[ vec[ ty:: t] ] , t) ) ;
1138
1150
}
1139
1151
case ( ast:: pat_lit( ?lit, ?ann) ) {
1140
1152
auto t = Demand :: simple( fcx, pat. span, expected,
1141
1153
ann_to_type( fcx. ccx. node_types, ann) ) ;
1142
1154
p_1 = ast:: pat_lit( lit, ast:: ann_type( ast:: ann_tag( ann) , t,
1143
1155
none[ vec[ ty:: t] ] ,
1144
1156
none[ @ts_ann] ) ) ;
1157
+ write_type( fcx. ccx. node_types, ast:: ann_tag( ann) ,
1158
+ tup( none[ vec[ ty:: t] ] , t) ) ;
1145
1159
}
1146
1160
case ( ast:: pat_bind( ?id, ?did, ?ann) ) {
1147
1161
auto t = Demand :: simple( fcx, pat. span, expected,
@@ -1151,6 +1165,8 @@ mod Pushdown {
1151
1165
t,
1152
1166
none[ vec[ ty:: t] ] ,
1153
1167
none[ @ts_ann] ) ) ;
1168
+ write_type( fcx. ccx. node_types, ast:: ann_tag( ann) ,
1169
+ tup( none[ vec[ ty:: t] ] , t) ) ;
1154
1170
}
1155
1171
case ( ast:: pat_tag( ?id, ?subpats, ?ann) ) {
1156
1172
// Take the variant's type parameters out of the expected
@@ -1182,6 +1198,9 @@ mod Pushdown {
1182
1198
1183
1199
// TODO: push down type from "expected".
1184
1200
p_1 = ast:: pat_tag( id, subpats_1, ann) ;
1201
+ write_type( fcx. ccx. node_types, ast:: ann_tag( ann) ,
1202
+ ty:: ann_to_ty_param_substs_opt_and_ty( fcx. ccx. node_types,
1203
+ ann) ) ;
1185
1204
}
1186
1205
}
1187
1206
@@ -1438,8 +1457,10 @@ mod Pushdown {
1438
1457
1439
1458
e_1 = ast:: expr_path( pth,
1440
1459
ast:: ann_type( ast:: ann_tag( ann) , t,
1441
- ty_params_opt,
1442
- none[ @ts_ann] ) ) ;
1460
+ ty_params_opt,
1461
+ none[ @ts_ann] ) ) ;
1462
+ write_type( fcx. ccx. node_types, ast:: ann_tag( ann) ,
1463
+ tup( ty_params_opt, t) ) ;
1443
1464
}
1444
1465
case ( ast:: expr_ext( ?p, ?args, ?body, ?expanded, ?ann) ) {
1445
1466
auto t = Demand :: autoderef( fcx, e. span, expected,
@@ -1595,6 +1616,7 @@ fn resolve_local_types_in_annotation(&option::t[@fn_ctxt] env, &ast::ann ann)
1595
1616
auto f = bind resolver( fcx, _) ;
1596
1617
auto new_type = ty:: fold_ty( fcx. ccx. tcx, f,
1597
1618
ann_to_type( fcx. ccx. node_types, ann) ) ;
1619
+ write_type( fcx. ccx. node_types, tg, tup( tps, new_type) ) ;
1598
1620
ret ast:: ann_type( tg, new_type, tps, ts_info) ;
1599
1621
}
1600
1622
}
@@ -1689,6 +1711,8 @@ fn check_pat(&@fn_ctxt fcx, &@ast::pat pat) -> @ast::pat {
1689
1711
new_pat = ast:: pat_tag( p, new_subpats,
1690
1712
ast:: ann_type( ast:: ann_tag( old_ann) , path_tpot. _1,
1691
1713
path_tpot. _0, none[ @ts_ann] ) ) ;
1714
+ write_type( fcx. ccx. node_types, ast:: ann_tag( old_ann) ,
1715
+ path_tpot) ;
1692
1716
}
1693
1717
1694
1718
// Nullary variants have tag types.
@@ -1709,6 +1733,8 @@ fn check_pat(&@fn_ctxt fcx, &@ast::pat pat) -> @ast::pat {
1709
1733
new_pat = ast:: pat_tag( p, subpats,
1710
1734
ast:: ann_type( ast:: ann_tag( old_ann) , path_tpot. _1,
1711
1735
path_tpot. _0, none[ @ts_ann] ) ) ;
1736
+ write_type( fcx. ccx. node_types, ast:: ann_tag( old_ann) ,
1737
+ path_tpot) ;
1712
1738
}
1713
1739
}
1714
1740
}
@@ -1960,6 +1986,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) -> @ast::expr {
1960
1986
ast:: expr_path( pth,
1961
1987
ast:: ann_type( ast:: ann_tag( old_ann) , path_tpot. _1,
1962
1988
path_tpot. _0, none[ @ts_ann] ) ) ) ;
1989
+ write_type( fcx. ccx. node_types, ast:: ann_tag( old_ann) ,
1990
+ path_tpot) ;
1963
1991
}
1964
1992
1965
1993
// The definition doesn't take type parameters. If the programmer
@@ -3033,7 +3061,7 @@ fn check_crate(&ty::ctxt tcx, &@ast::crate crate) -> typecheck_result {
3033
3061
map:: mk_hashmap[ unify_cache_entry, ty:: Unify :: result] ( hasher, eqer) ;
3034
3062
auto fpt =
3035
3063
mk_fn_purity_table ( crate ) ; // use a variation on Collect
3036
- let node_type_table node_types = vec ( mutable ) ;
3064
+ let node_type_table node_types = result . _3 ;
3037
3065
3038
3066
auto ccx = @rec ( sess=sess,
3039
3067
type_cache=result. _1 ,
@@ -3046,7 +3074,7 @@ fn check_crate(&ty::ctxt tcx, &@ast::crate crate) -> typecheck_result {
3046
3074
mutable cache_hits=0 u,
3047
3075
mutable cache_misses=0 u,
3048
3076
tcx=tcx,
3049
- mutable node_types=node_types) ;
3077
+ node_types=node_types) ;
3050
3078
3051
3079
auto fld = fold:: new_identity_fold[ @crate_ctxt] ( ) ;
3052
3080
0 commit comments