Skip to content

Commit c97b051

Browse files
committed
rustc: Add write_type() wherever ann_types are written, except for triv_ann()
1 parent 7647b83 commit c97b051

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

src/comp/middle/ty.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ type type_store = rec(mutable vec[raw_t] others,
163163
hashmap[raw_t,uint] other_structural);
164164

165165
type ty_param_substs_opt_and_ty = tup(option::t[vec[ty::t]], ty::t);
166-
type node_type_table = vec[mutable option::t[ty::ty_param_substs_opt_and_ty]];
166+
type node_type_table =
167+
@mutable vec[mutable option::t[ty::ty_param_substs_opt_and_ty]];
167168

168169
fn mk_type_store() -> @type_store {
169170
let vec[raw_t] others = vec();
@@ -1469,6 +1470,18 @@ fn ann_to_type_params(&node_type_table ntt, &ast::ann ann) -> vec[t] {
14691470
}
14701471
}
14711472

1473+
fn ann_to_ty_param_substs_opt_and_ty(&node_type_table ntt, &ast::ann ann)
1474+
-> ty_param_substs_opt_and_ty {
1475+
alt (ann) {
1476+
case (ast::ann_none(_)) {
1477+
log_err "ann_to_ty_param_substs_opt_and_ty() called on a node " +
1478+
"with no type params";
1479+
fail;
1480+
}
1481+
case (ast::ann_type(_, ?t, ?tps, _)) { ret tup(tps, t); }
1482+
}
1483+
}
1484+
14721485
// Returns the type of an annotation, with type parameter substitutions
14731486
// performed if applicable.
14741487
fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t {

src/comp/middle/typeck.rs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type crate_ctxt = rec(session::session sess,
7272
mutable uint cache_hits,
7373
mutable uint cache_misses,
7474
ty::ctxt tcx,
75-
mutable node_type_table node_types);
75+
node_type_table node_types);
7676

7777
type fn_ctxt = rec(ty::t ret_ty,
7878
ast::purity purity,
@@ -372,12 +372,13 @@ fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast::ty ast_ty) -> ty::t {
372372
}
373373

374374
// 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,
376376
&ty_param_substs_opt_and_ty tpot) {
377-
_vec::grow_set[option::t[ty::ty_param_substs_opt_and_ty]](cx.node_types,
378-
0u,
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+
0u,
380+
none[ty_param_substs_opt_and_ty],
381+
some[ty_param_substs_opt_and_ty](tpot));
381382
}
382383

383384

@@ -396,7 +397,8 @@ mod Collect {
396397
type ctxt = rec(session::session sess,
397398
@ty_item_table id_to_ty_item,
398399
ty::type_cache type_cache,
399-
ty::ctxt tcx);
400+
ty::ctxt tcx,
401+
node_type_table node_types);
400402
type env = rec(@ctxt cx, ast::native_abi abi);
401403

402404
fn ty_of_fn_decl(&@ctxt cx,
@@ -824,16 +826,23 @@ mod Collect {
824826
ast::ann_type(ast::ann_tag(a), typ,
825827
none[vec[ty::t]],
826828
none[@ts_ann]));
829+
write_type(e.cx.node_types, ast::ann_tag(a),
830+
tup(none[vec[ty::t]], typ));
827831
ret @fold::respan[ast::item_](sp, item);
828832
}
829833

830834
fn collect_item_types(&session::session sess, &ty::ctxt tcx,
831835
&@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) {
833838
// First pass: collect all type item IDs:
834839
auto module = crate.node.module;
835840
auto id_to_ty_item = @common::new_def_hash[any_item]();
836841

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+
837846
auto fld_1 = fold::new_identity_fold[@ty_item_table]();
838847
fld_1 = @rec(update_env_for_item = bind collect(_, _),
839848
update_env_for_native_item = bind collect_native(_, _)
@@ -846,7 +855,8 @@ mod Collect {
846855
auto cx = @rec(sess=sess,
847856
id_to_ty_item=id_to_ty_item,
848857
type_cache=type_cache,
849-
tcx=tcx);
858+
tcx=tcx,
859+
node_types=ntt);
850860

851861
let @env e = @rec(cx=cx, abi=ast::native_abi_cdecl);
852862

@@ -863,7 +873,7 @@ mod Collect {
863873
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_,_)
864874
with *fld_2);
865875
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);
867877
}
868878
}
869879

@@ -1135,13 +1145,17 @@ mod Pushdown {
11351145
p_1 = ast::pat_wild(ast::ann_type(ast::ann_tag(ann), t,
11361146
none[vec[ty::t]],
11371147
none[@ts_ann]));
1148+
write_type(fcx.ccx.node_types, ast::ann_tag(ann),
1149+
tup(none[vec[ty::t]], t));
11381150
}
11391151
case (ast::pat_lit(?lit, ?ann)) {
11401152
auto t = Demand::simple(fcx, pat.span, expected,
11411153
ann_to_type(fcx.ccx.node_types, ann));
11421154
p_1 = ast::pat_lit(lit, ast::ann_type(ast::ann_tag(ann), t,
11431155
none[vec[ty::t]],
11441156
none[@ts_ann]));
1157+
write_type(fcx.ccx.node_types, ast::ann_tag(ann),
1158+
tup(none[vec[ty::t]], t));
11451159
}
11461160
case (ast::pat_bind(?id, ?did, ?ann)) {
11471161
auto t = Demand::simple(fcx, pat.span, expected,
@@ -1151,6 +1165,8 @@ mod Pushdown {
11511165
t,
11521166
none[vec[ty::t]],
11531167
none[@ts_ann]));
1168+
write_type(fcx.ccx.node_types, ast::ann_tag(ann),
1169+
tup(none[vec[ty::t]], t));
11541170
}
11551171
case (ast::pat_tag(?id, ?subpats, ?ann)) {
11561172
// Take the variant's type parameters out of the expected
@@ -1182,6 +1198,9 @@ mod Pushdown {
11821198

11831199
// TODO: push down type from "expected".
11841200
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));
11851204
}
11861205
}
11871206

@@ -1438,8 +1457,10 @@ mod Pushdown {
14381457

14391458
e_1 = ast::expr_path(pth,
14401459
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));
14431464
}
14441465
case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?ann)) {
14451466
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)
15951616
auto f = bind resolver(fcx, _);
15961617
auto new_type = ty::fold_ty(fcx.ccx.tcx, f,
15971618
ann_to_type(fcx.ccx.node_types, ann));
1619+
write_type(fcx.ccx.node_types, tg, tup(tps, new_type));
15981620
ret ast::ann_type(tg, new_type, tps, ts_info);
15991621
}
16001622
}
@@ -1689,6 +1711,8 @@ fn check_pat(&@fn_ctxt fcx, &@ast::pat pat) -> @ast::pat {
16891711
new_pat = ast::pat_tag(p, new_subpats,
16901712
ast::ann_type(ast::ann_tag(old_ann), path_tpot._1,
16911713
path_tpot._0, none[@ts_ann]));
1714+
write_type(fcx.ccx.node_types, ast::ann_tag(old_ann),
1715+
path_tpot);
16921716
}
16931717

16941718
// Nullary variants have tag types.
@@ -1709,6 +1733,8 @@ fn check_pat(&@fn_ctxt fcx, &@ast::pat pat) -> @ast::pat {
17091733
new_pat = ast::pat_tag(p, subpats,
17101734
ast::ann_type(ast::ann_tag(old_ann), path_tpot._1,
17111735
path_tpot._0, none[@ts_ann]));
1736+
write_type(fcx.ccx.node_types, ast::ann_tag(old_ann),
1737+
path_tpot);
17121738
}
17131739
}
17141740
}
@@ -1960,6 +1986,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) -> @ast::expr {
19601986
ast::expr_path(pth,
19611987
ast::ann_type(ast::ann_tag(old_ann), path_tpot._1,
19621988
path_tpot._0, none[@ts_ann])));
1989+
write_type(fcx.ccx.node_types, ast::ann_tag(old_ann),
1990+
path_tpot);
19631991
}
19641992

19651993
// 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 {
30333061
map::mk_hashmap[unify_cache_entry,ty::Unify::result](hasher, eqer);
30343062
auto fpt =
30353063
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;
30373065

30383066
auto ccx = @rec(sess=sess,
30393067
type_cache=result._1,
@@ -3046,7 +3074,7 @@ fn check_crate(&ty::ctxt tcx, &@ast::crate crate) -> typecheck_result {
30463074
mutable cache_hits=0u,
30473075
mutable cache_misses=0u,
30483076
tcx=tcx,
3049-
mutable node_types=node_types);
3077+
node_types=node_types);
30503078

30513079
auto fld = fold::new_identity_fold[@crate_ctxt]();
30523080

0 commit comments

Comments
 (0)