Skip to content

Commit 4c33d8a

Browse files
committed
---
yaml --- r: 2653 b: refs/heads/master c: a4dd577 h: refs/heads/master i: 2651: 6b501d7 v: v3
1 parent cb104ea commit 4c33d8a

File tree

8 files changed

+271
-368
lines changed

8 files changed

+271
-368
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8a7b5449959b44fcc98d9fd0d5f81d86b44fd399
2+
refs/heads/master: a4dd57705c7b203ad0efed4ddcc0e3959e65d627

trunk/src/comp/driver/rustc.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,18 @@ fn compile_input(session::session sess,
9797
bind resolve::resolve_crate(sess, crate));
9898

9999
auto ty_cx = ty::mk_ctxt(sess, def_map);
100-
auto typeck_result =
101-
time[typeck::typecheck_result](time_passes, "typechecking",
102-
bind typeck::check_crate(ty_cx, crate));
103-
auto node_type_table = typeck_result._0;
104-
auto type_cache = typeck_result._1;
100+
time[()](time_passes, "typechecking",
101+
bind typeck::check_crate(ty_cx, crate));
105102

106103
if (sess.get_opts().run_typestate) {
107104
time(time_passes, "typestate checking",
108-
bind middle::tstate::ck::check_crate(node_type_table,
109-
ty_cx, crate));
105+
bind middle::tstate::ck::check_crate(ty_cx, crate));
110106
}
111107

112-
auto llmod = time[llvm::ModuleRef](time_passes, "translation",
113-
bind trans::trans_crate(sess, crate, ty_cx, node_type_table,
114-
type_cache, output));
108+
auto llmod =
109+
time[llvm::ModuleRef](time_passes, "translation",
110+
bind trans::trans_crate(sess, crate,
111+
ty_cx, output));
115112

116113
time[()](time_passes, "LLVM passes",
117114
bind link::write::run_passes(sess, llmod, output));
@@ -128,8 +125,8 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
128125
crate = creader::read_crates(sess, crate);
129126
auto def_map = resolve::resolve_crate(sess, crate);
130127
auto ty_cx = ty::mk_ctxt(sess, def_map);
131-
auto typeck_result = typeck::check_crate(ty_cx, crate);
132-
mode = pprust::mo_typed(ty_cx, typeck_result._0, typeck_result._1);
128+
typeck::check_crate(ty_cx, crate);
129+
mode = pprust::mo_typed(ty_cx);
133130
} else {
134131
mode = pprust::mo_untyped;
135132
}

trunk/src/comp/middle/trans.rs

Lines changed: 47 additions & 82 deletions
Large diffs are not rendered by default.

trunk/src/comp/middle/tstate/auxiliary.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ type fn_ctxt = rec(fn_info enclosing,
167167
crate_ctxt ccx);
168168

169169
type crate_ctxt = rec(ty::ctxt tcx,
170-
ty::node_type_table node_types,
171170
node_ann_table node_anns,
172171
fn_info_map fm);
173172

@@ -370,9 +369,8 @@ fn num_locals(fn_info m) -> uint {
370369
ret m.vars.size();
371370
}
372371

373-
fn new_crate_ctxt(ty::node_type_table nt, ty::ctxt cx) -> crate_ctxt {
374-
ret rec(tcx=cx, node_types=nt,
375-
node_anns=@new_uint_hash[ts_ann](),
372+
fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt {
373+
ret rec(tcx=cx, node_anns=@new_uint_hash[ts_ann](),
376374
fm=@new_def_hash[fn_info]());
377375
}
378376

trunk/src/comp/middle/tstate/ck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a) -> () {
128128
if (f.proto == ast::proto_fn
129129
&& ! promises(*post, fcx.id, enclosing)
130130
&& ! type_is_nil(fcx.ccx.tcx,
131-
ret_ty_of_fn(fcx.ccx.node_types, fcx.ccx.tcx, a)) ) {
131+
ret_ty_of_fn(fcx.ccx.tcx, a)) ) {
132132
/* FIXME: call span_err, not span_warn, once I finish implementing
133133
! annotations */
134134
fcx.ccx.tcx.sess.span_warn(f.body.span, "In function " + fcx.name +
@@ -159,8 +159,8 @@ fn fn_states(&crate_ctxt ccx, &_fn f, &ident i, &def_id id, &ann a) -> () {
159159
check_fn_states(fcx, f, a);
160160
}
161161

162-
fn check_crate(ty::node_type_table nt, ty::ctxt cx, @crate crate) -> () {
163-
let crate_ctxt ccx = new_crate_ctxt(nt, cx);
162+
fn check_crate(ty::ctxt cx, @crate crate) -> () {
163+
let crate_ctxt ccx = new_crate_ctxt(cx);
164164

165165
/* Build the global map from function id to var-to-bit-num-map */
166166
mk_f_to_fn_info(ccx, crate);

trunk/src/comp/middle/ty.rs

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ type creader_cache = hashmap[tup(int,uint,uint),ty::t];
5858
type ctxt = rec(@type_store ts,
5959
session::session sess,
6060
resolve::def_map def_map,
61+
node_type_table node_types,
62+
type_cache tcache,
6163
creader_cache rcache,
6264
hashmap[t,str] short_names_cache);
6365
type ty_ctxt = ctxt; // Needed for disambiguation from unify::ctxt.
6466

6567
// Convert from method type to function type. Pretty easy; we just drop
6668
// 'ident'.
67-
fn method_ty_to_fn_ty(ctxt cx, method m) -> t {
69+
fn method_ty_to_fn_ty(&ctxt cx, method m) -> t {
6870
ret mk_fn(cx, m.proto, m.inputs, m.output);
6971
}
7072

@@ -215,9 +217,19 @@ fn mk_rcache() -> creader_cache {
215217
}
216218

217219
fn mk_ctxt(session::session s, resolve::def_map dm) -> ctxt {
220+
221+
let vec[mutable option::t[ty::ty_param_substs_opt_and_ty]] ntt_sub =
222+
[mutable];
223+
let node_type_table ntt = @mutable ntt_sub;
224+
225+
auto tcache =
226+
common::new_def_hash[ty::ty_param_count_and_ty]();
227+
218228
ret rec(ts = mk_type_store(),
219229
sess = s,
220230
def_map = dm,
231+
node_types = ntt,
232+
tcache = tcache,
221233
rcache = mk_rcache(),
222234
short_names_cache =
223235
map::mk_hashmap[ty::t,str](ty::hash_ty, ty::eq_ty));
@@ -489,9 +501,9 @@ fn path_to_str(&ast::path pth) -> str {
489501
ret result;
490502
}
491503

492-
fn ty_to_str(ctxt cx, &t typ) -> str {
504+
fn ty_to_str(&ctxt cx, &t typ) -> str {
493505

494-
fn fn_input_to_str(ctxt cx, &rec(mode mode, t ty) input) -> str {
506+
fn fn_input_to_str(&ctxt cx, &rec(mode mode, t ty) input) -> str {
495507
auto s;
496508
alt (input.mode) {
497509
case (mo_val) { s = ""; }
@@ -502,7 +514,7 @@ fn ty_to_str(ctxt cx, &t typ) -> str {
502514
ret s + ty_to_str(cx, input.ty);
503515
}
504516

505-
fn fn_to_str(ctxt cx,
517+
fn fn_to_str(&ctxt cx,
506518
ast::proto proto,
507519
option::t[ast::ident] ident,
508520
vec[arg] inputs, t output) -> str {
@@ -536,16 +548,16 @@ fn ty_to_str(ctxt cx, &t typ) -> str {
536548
ret s;
537549
}
538550

539-
fn method_to_str(ctxt cx, &method m) -> str {
551+
fn method_to_str(&ctxt cx, &method m) -> str {
540552
ret fn_to_str(cx, m.proto, some[ast::ident](m.ident),
541553
m.inputs, m.output) + ";";
542554
}
543555

544-
fn field_to_str(ctxt cx, &field f) -> str {
556+
fn field_to_str(&ctxt cx, &field f) -> str {
545557
ret mt_to_str(cx, f.mt) + " " + f.ident;
546558
}
547559

548-
fn mt_to_str(ctxt cx, &mt m) -> str {
560+
fn mt_to_str(&ctxt cx, &mt m) -> str {
549561
auto mstr;
550562
alt (m.mut) {
551563
case (ast::mut) { mstr = "mutable "; }
@@ -648,7 +660,7 @@ fn ty_to_str(ctxt cx, &t typ) -> str {
648660
ret s;
649661
}
650662

651-
fn ty_to_short_str(ctxt cx, t typ) -> str {
663+
fn ty_to_short_str(&ctxt cx, t typ) -> str {
652664
auto f = def_to_str;
653665
auto ecx = @rec(ds=f, tcx=cx, abbrevs=metadata::ac_no_abbrevs);
654666
auto s = metadata::Encode::ty_str(ecx, typ);
@@ -660,7 +672,7 @@ fn ty_to_short_str(ctxt cx, t typ) -> str {
660672

661673
type ty_walk = fn(t);
662674

663-
fn walk_ty(ctxt cx, ty_walk walker, t ty) {
675+
fn walk_ty(&ctxt cx, ty_walk walker, t ty) {
664676
alt (struct(cx, ty)) {
665677
case (ty_nil) { /* no-op */ }
666678
case (ty_bot) { /* no-op */ }
@@ -724,7 +736,7 @@ fn walk_ty(ctxt cx, ty_walk walker, t ty) {
724736

725737
type ty_fold = fn(t) -> t;
726738

727-
fn fold_ty(ctxt cx, ty_fold fld, t ty_0) -> t {
739+
fn fold_ty(&ctxt cx, ty_fold fld, t ty_0) -> t {
728740
auto ty = ty_0;
729741
alt (struct(cx, ty)) {
730742
case (ty_nil) { /* no-op */ }
@@ -819,13 +831,13 @@ fn fold_ty(ctxt cx, ty_fold fld, t ty_0) -> t {
819831

820832
// Type utilities
821833

822-
fn rename(ctxt cx, t typ, str new_cname) -> t {
834+
fn rename(&ctxt cx, t typ, str new_cname) -> t {
823835
ret gen_ty_full(cx, struct(cx, typ), some[str](new_cname));
824836
}
825837

826838
// Returns a type with the structural part taken from `struct_ty` and the
827839
// canonical name from `cname_ty`.
828-
fn copy_cname(ctxt cx, t struct_ty, t cname_ty) -> t {
840+
fn copy_cname(&ctxt cx, t struct_ty, t cname_ty) -> t {
829841
ret gen_ty_full(cx, struct(cx, struct_ty), cname(cx, cname_ty));
830842
}
831843

@@ -1484,8 +1496,8 @@ fn ann_has_type_params(&node_type_table ntt, &ast::ann ann) -> bool {
14841496

14851497
// Returns the type of an annotation, with type parameter substitutions
14861498
// performed if applicable.
1487-
fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t {
1488-
auto tpot = ann_to_ty_param_substs_opt_and_ty(ntt, a);
1499+
fn ann_to_monotype(&ctxt cx, ast::ann a) -> t {
1500+
auto tpot = ann_to_ty_param_substs_opt_and_ty(cx.node_types, a);
14891501
alt (tpot._0) {
14901502
case (none[vec[t]]) { ret tpot._1; }
14911503
case (some[vec[t]](?tps)) {
@@ -1518,8 +1530,8 @@ fn bot_ann(uint node_id, ctxt tcx) -> ast::ann {
15181530

15191531

15201532
// Returns the number of distinct type parameters in the given type.
1521-
fn count_ty_params(ctxt cx, t ty) -> uint {
1522-
fn counter(ctxt cx, @mutable vec[uint] param_indices, t ty) {
1533+
fn count_ty_params(&ctxt cx, t ty) -> uint {
1534+
fn counter(&ctxt cx, @mutable vec[uint] param_indices, t ty) {
15231535
alt (struct(cx, ty)) {
15241536
case (ty_param(?param_idx)) {
15251537
auto seen = false;
@@ -1650,28 +1662,28 @@ fn item_ty(&node_type_table ntt, &@ast::item it) -> ty_param_count_and_ty {
16501662
ret tup(ty_param_count, result_ty);
16511663
}
16521664

1653-
fn stmt_ty(&ctxt cx, &node_type_table ntt, &@ast::stmt s) -> t {
1665+
fn stmt_ty(&ctxt cx, &@ast::stmt s) -> t {
16541666
alt (s.node) {
16551667
case (ast::stmt_expr(?e,_)) {
1656-
ret expr_ty(cx, ntt, e);
1668+
ret expr_ty(cx, e);
16571669
}
16581670
case (_) {
16591671
ret mk_nil(cx);
16601672
}
16611673
}
16621674
}
16631675

1664-
fn block_ty(&ctxt cx, &node_type_table ntt, &ast::block b) -> t {
1676+
fn block_ty(&ctxt cx, &ast::block b) -> t {
16651677
alt (b.node.expr) {
1666-
case (some[@ast::expr](?e)) { ret expr_ty(cx, ntt, e); }
1678+
case (some[@ast::expr](?e)) { ret expr_ty(cx, e); }
16671679
case (none[@ast::expr]) { ret mk_nil(cx); }
16681680
}
16691681
}
16701682

16711683
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
16721684
// doesn't provide type parameter substitutions.
1673-
fn pat_ty(&ctxt cx, &node_type_table ntt, &@ast::pat pat) -> t {
1674-
ret ann_to_monotype(cx, ntt, pat_ann(pat));
1685+
fn pat_ty(&ctxt cx, &@ast::pat pat) -> t {
1686+
ret ann_to_monotype(cx, pat_ann(pat));
16751687
}
16761688

16771689
fn item_ann(&@ast::item it) -> ast::ann {
@@ -1743,15 +1755,16 @@ fn expr_ann(&@ast::expr e) -> ast::ann {
17431755
// ask for the type of "id" in "id(3)", it will return "fn(&int) -> int"
17441756
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see
17451757
// expr_ty_params_and_ty() below.
1746-
fn expr_ty(&ctxt cx, &node_type_table ntt, &@ast::expr expr) -> t {
1747-
ret ann_to_monotype(cx, ntt, expr_ann(expr));
1758+
fn expr_ty(&ctxt cx, &@ast::expr expr) -> t {
1759+
ret ann_to_monotype(cx, expr_ann(expr));
17481760
}
17491761

1750-
fn expr_ty_params_and_ty(&ctxt cx, &node_type_table ntt, &@ast::expr expr)
1762+
fn expr_ty_params_and_ty(&ctxt cx, &@ast::expr expr)
17511763
-> tup(vec[t], t) {
17521764
auto a = expr_ann(expr);
17531765

1754-
ret tup(ann_to_type_params(ntt, a), ann_to_type(ntt, a));
1766+
ret tup(ann_to_type_params(cx.node_types, a),
1767+
ann_to_type(cx.node_types, a));
17551768
}
17561769

17571770
fn expr_has_ty_params(&node_type_table ntt, &@ast::expr expr) -> bool {
@@ -2644,7 +2657,7 @@ fn substitute_type_params(&ctxt cx, &vec[t] bindings, &t typ) -> t {
26442657
if (!type_contains_bound_params(cx, typ)) {
26452658
ret typ;
26462659
}
2647-
fn replacer(ctxt cx, vec[t] bindings, t typ) -> t {
2660+
fn replacer(&ctxt cx, vec[t] bindings, t typ) -> t {
26482661
alt (struct(cx, typ)) {
26492662
case (ty_bound_param(?param_index)) {
26502663
ret bindings.(param_index);
@@ -2662,7 +2675,7 @@ fn bind_params_in_type(&ctxt cx, &t typ) -> t {
26622675
if (!type_contains_params(cx, typ)) {
26632676
ret typ;
26642677
}
2665-
fn binder(ctxt cx, t typ) -> t {
2678+
fn binder(&ctxt cx, t typ) -> t {
26662679
alt (struct(cx, typ)) {
26672680
case (ty_bound_param(?index)) {
26682681
log_err "bind_params_in_type() called on type that already " +
@@ -2701,20 +2714,18 @@ fn def_has_ty_params(&ast::def def) -> bool {
27012714
// If the given item is in an external crate, looks up its type and adds it to
27022715
// the type cache. Returns the type parameters and type.
27032716
fn lookup_item_type(session::session sess,
2704-
ctxt cx,
2705-
&type_cache cache,
2706-
ast::def_id did) -> ty_param_count_and_ty {
2717+
ctxt cx, ast::def_id did) -> ty_param_count_and_ty {
27072718
if (did._0 == sess.get_targ_crate_num()) {
27082719
// The item is in this crate. The caller should have added it to the
27092720
// type cache already; we simply return it.
2710-
ret cache.get(did);
2721+
ret cx.tcache.get(did);
27112722
}
27122723

2713-
alt (cache.find(did)) {
2724+
alt (cx.tcache.find(did)) {
27142725
case (some[ty_param_count_and_ty](?tpt)) { ret tpt; }
27152726
case (none[ty_param_count_and_ty]) {
27162727
auto tyt = creader::get_type(sess, cx, did);
2717-
cache.insert(did, tyt);
2728+
cx.tcache.insert(did, tyt);
27182729
ret tyt;
27192730
}
27202731
}
@@ -2731,8 +2742,8 @@ fn ret_ty_of_fn_ty(ty_ctxt tcx, t a_ty) -> t {
27312742
}
27322743
}
27332744

2734-
fn ret_ty_of_fn(node_type_table ntt, ty_ctxt tcx, ast::ann ann) -> t {
2735-
ret ret_ty_of_fn_ty(tcx, ann_to_type(ntt, ann));
2745+
fn ret_ty_of_fn(ty_ctxt tcx, ast::ann ann) -> t {
2746+
ret ret_ty_of_fn_ty(tcx, ann_to_type(tcx.node_types, ann));
27362747
}
27372748

27382749
// Local Variables:

0 commit comments

Comments
 (0)