Skip to content

Commit e102413

Browse files
committed
rustc: Pass a "type context" around instead of directly passing the type store; prep for removing type annotations
1 parent b258060 commit e102413

File tree

7 files changed

+786
-833
lines changed

7 files changed

+786
-833
lines changed

src/comp/driver/rustc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ fn compile_input(session.session sess,
7373
crate = resolve.resolve_crate(sess, crate);
7474
capture.check_for_captures(sess, crate);
7575

76-
auto tystore = ty.mk_type_store();
77-
auto typeck_result = typeck.check_crate(sess, tystore, crate);
76+
auto ty_cx = ty.mk_ctxt();
77+
auto typeck_result = typeck.check_crate(sess, ty_cx, crate);
7878
crate = typeck_result._0;
7979
auto type_cache = typeck_result._1;
8080
// FIXME: uncomment once typestate_check works
8181
// crate = typestate_check.check_crate(crate);
82-
trans.trans_crate(sess, crate, tystore, type_cache, output, shared,
82+
trans.trans_crate(sess, crate, ty_cx, type_cache, output, shared,
8383
optimize, verify, ot);
8484
}
8585

src/comp/front/creader.rs

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ tag resolve_result {
4949
// Callback to translate defs to strs or back.
5050
type str_def = fn(str) -> ast.def_id;
5151

52-
type pstate = rec(str rep, mutable uint pos, uint len,
53-
@ty.type_store tystore);
52+
type pstate = rec(str rep, mutable uint pos, uint len, ty.ctxt tcx);
5453

5554
fn peek(@pstate st) -> u8 {
5655
if (st.pos < st.len) {ret st.rep.(st.pos) as u8;}
@@ -63,9 +62,9 @@ fn next(@pstate st) -> u8 {
6362
ret ch as u8;
6463
}
6564

66-
fn parse_ty_str(str rep, str_def sd, @ty.type_store tystore) -> ty.t {
65+
fn parse_ty_str(str rep, str_def sd, ty.ctxt tcx) -> ty.t {
6766
auto len = _str.byte_len(rep);
68-
auto st = @rec(rep=rep, mutable pos=0u, len=len, tystore=tystore);
67+
auto st = @rec(rep=rep, mutable pos=0u, len=len, tcx=tcx);
6968
auto result = parse_ty(st, sd);
7069
if (st.pos != len) {
7170
log_err "parse_ty_str: incomplete parse, stopped at byte "
@@ -77,27 +76,27 @@ fn parse_ty_str(str rep, str_def sd, @ty.type_store tystore) -> ty.t {
7776

7877
fn parse_ty(@pstate st, str_def sd) -> ty.t {
7978
alt (next(st) as char) {
80-
case ('n') { ret ty.mk_nil(st.tystore); }
81-
case ('b') { ret ty.mk_bool(st.tystore); }
82-
case ('i') { ret ty.mk_int(st.tystore); }
83-
case ('u') { ret ty.mk_uint(st.tystore); }
84-
case ('l') { ret ty.mk_float(st.tystore); }
79+
case ('n') { ret ty.mk_nil(st.tcx); }
80+
case ('b') { ret ty.mk_bool(st.tcx); }
81+
case ('i') { ret ty.mk_int(st.tcx); }
82+
case ('u') { ret ty.mk_uint(st.tcx); }
83+
case ('l') { ret ty.mk_float(st.tcx); }
8584
case ('M') {
8685
alt (next(st) as char) {
87-
case ('b') { ret ty.mk_mach(st.tystore, common.ty_u8); }
88-
case ('w') { ret ty.mk_mach(st.tystore, common.ty_u16); }
89-
case ('l') { ret ty.mk_mach(st.tystore, common.ty_u32); }
90-
case ('d') { ret ty.mk_mach(st.tystore, common.ty_u64); }
91-
case ('B') { ret ty.mk_mach(st.tystore, common.ty_i8); }
92-
case ('W') { ret ty.mk_mach(st.tystore, common.ty_i16); }
93-
case ('L') { ret ty.mk_mach(st.tystore, common.ty_i32); }
94-
case ('D') { ret ty.mk_mach(st.tystore, common.ty_i64); }
95-
case ('f') { ret ty.mk_mach(st.tystore, common.ty_f32); }
96-
case ('F') { ret ty.mk_mach(st.tystore, common.ty_f64); }
86+
case ('b') { ret ty.mk_mach(st.tcx, common.ty_u8); }
87+
case ('w') { ret ty.mk_mach(st.tcx, common.ty_u16); }
88+
case ('l') { ret ty.mk_mach(st.tcx, common.ty_u32); }
89+
case ('d') { ret ty.mk_mach(st.tcx, common.ty_u64); }
90+
case ('B') { ret ty.mk_mach(st.tcx, common.ty_i8); }
91+
case ('W') { ret ty.mk_mach(st.tcx, common.ty_i16); }
92+
case ('L') { ret ty.mk_mach(st.tcx, common.ty_i32); }
93+
case ('D') { ret ty.mk_mach(st.tcx, common.ty_i64); }
94+
case ('f') { ret ty.mk_mach(st.tcx, common.ty_f32); }
95+
case ('F') { ret ty.mk_mach(st.tcx, common.ty_f64); }
9796
}
9897
}
99-
case ('c') { ret ty.mk_char(st.tystore); }
100-
case ('s') { ret ty.mk_str(st.tystore); }
98+
case ('c') { ret ty.mk_char(st.tcx); }
99+
case ('s') { ret ty.mk_str(st.tcx); }
101100
case ('t') {
102101
check(next(st) as char == '[');
103102
auto def = parse_def(st, sd);
@@ -106,21 +105,21 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
106105
params += vec(parse_ty(st, sd));
107106
}
108107
st.pos = st.pos + 1u;
109-
ret ty.mk_tag(st.tystore, def, params);
108+
ret ty.mk_tag(st.tcx, def, params);
110109
}
111-
case ('p') { ret ty.mk_param(st.tystore, parse_int(st) as uint); }
112-
case ('@') { ret ty.mk_box(st.tystore, parse_mt(st, sd)); }
113-
case ('V') { ret ty.mk_vec(st.tystore, parse_mt(st, sd)); }
114-
case ('P') { ret ty.mk_port(st.tystore, parse_ty(st, sd)); }
115-
case ('C') { ret ty.mk_chan(st.tystore, parse_ty(st, sd)); }
110+
case ('p') { ret ty.mk_param(st.tcx, parse_int(st) as uint); }
111+
case ('@') { ret ty.mk_box(st.tcx, parse_mt(st, sd)); }
112+
case ('V') { ret ty.mk_vec(st.tcx, parse_mt(st, sd)); }
113+
case ('P') { ret ty.mk_port(st.tcx, parse_ty(st, sd)); }
114+
case ('C') { ret ty.mk_chan(st.tcx, parse_ty(st, sd)); }
116115
case ('T') {
117116
check(next(st) as char == '[');
118117
let vec[ty.mt] params = vec();
119118
while (peek(st) as char != ']') {
120119
params += vec(parse_mt(st, sd));
121120
}
122121
st.pos = st.pos + 1u;
123-
ret ty.mk_tup(st.tystore, params);
122+
ret ty.mk_tup(st.tcx, params);
124123
}
125124
case ('R') {
126125
check(next(st) as char == '[');
@@ -134,15 +133,15 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
134133
fields += vec(rec(ident=name, mt=parse_mt(st, sd)));
135134
}
136135
st.pos = st.pos + 1u;
137-
ret ty.mk_rec(st.tystore, fields);
136+
ret ty.mk_rec(st.tcx, fields);
138137
}
139138
case ('F') {
140139
auto func = parse_ty_fn(st, sd);
141-
ret ty.mk_fn(st.tystore, ast.proto_fn, func._0, func._1);
140+
ret ty.mk_fn(st.tcx, ast.proto_fn, func._0, func._1);
142141
}
143142
case ('W') {
144143
auto func = parse_ty_fn(st, sd);
145-
ret ty.mk_fn(st.tystore, ast.proto_iter, func._0, func._1);
144+
ret ty.mk_fn(st.tcx, ast.proto_iter, func._0, func._1);
146145
}
147146
case ('N') {
148147
auto abi;
@@ -152,7 +151,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
152151
case ('l') {abi = ast.native_abi_llvm;}
153152
}
154153
auto func = parse_ty_fn(st, sd);
155-
ret ty.mk_native_fn(st.tystore,abi,func._0,func._1);
154+
ret ty.mk_native_fn(st.tcx,abi,func._0,func._1);
156155
}
157156
case ('O') {
158157
check(next(st) as char == '[');
@@ -174,11 +173,11 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
174173
output=func._1));
175174
}
176175
st.pos += 1u;
177-
ret ty.mk_obj(st.tystore, methods);
176+
ret ty.mk_obj(st.tcx, methods);
178177
}
179-
case ('X') { ret ty.mk_var(st.tystore, parse_int(st)); }
180-
case ('E') { ret ty.mk_native(st.tystore); }
181-
case ('Y') { ret ty.mk_type(st.tystore); }
178+
case ('X') { ret ty.mk_var(st.tcx, parse_int(st)); }
179+
case ('E') { ret ty.mk_native(st.tcx); }
180+
case ('Y') { ret ty.mk_type(st.tcx); }
182181
}
183182
}
184183

@@ -331,7 +330,7 @@ fn variant_tag_id(&ebml.doc d) -> ast.def_id {
331330
ret parse_def_id(ebml.doc_data(tagdoc));
332331
}
333332

334-
fn item_type(&ebml.doc item, int this_cnum, @ty.type_store tystore) -> ty.t {
333+
fn item_type(&ebml.doc item, int this_cnum, ty.ctxt tcx) -> ty.t {
335334
fn parse_external_def_id(int this_cnum, str s) -> ast.def_id {
336335
// FIXME: This is completely wrong when linking against a crate
337336
// that, in turn, links against another crate. We need a mapping
@@ -344,7 +343,7 @@ fn item_type(&ebml.doc item, int this_cnum, @ty.type_store tystore) -> ty.t {
344343

345344
auto tp = ebml.get_doc(item, metadata.tag_items_data_item_type);
346345
auto s = _str.unsafe_from_bytes(ebml.doc_data(tp));
347-
ret parse_ty_str(s, bind parse_external_def_id(this_cnum, _), tystore);
346+
ret parse_ty_str(s, bind parse_external_def_id(this_cnum, _), tcx);
348347
}
349348

350349
fn item_ty_param_count(&ebml.doc item, int this_cnum) -> uint {
@@ -506,12 +505,12 @@ fn lookup_def(session.session sess, int cnum, vec[ast.ident] path)
506505
ret some[ast.def](def);
507506
}
508507

509-
fn get_type(session.session sess, @ty.type_store tystore, ast.def_id def)
508+
fn get_type(session.session sess, ty.ctxt tcx, ast.def_id def)
510509
-> ty.ty_param_count_and_ty {
511510
auto external_crate_id = def._0;
512511
auto data = sess.get_external_crate(external_crate_id).data;
513512
auto item = lookup_item(def._1, data);
514-
auto t = item_type(item, external_crate_id, tystore);
513+
auto t = item_type(item, external_crate_id, tcx);
515514

516515
auto tp_count;
517516
auto kind_ch = item_kind(item);
@@ -532,9 +531,8 @@ fn get_symbol(session.session sess, ast.def_id def) -> str {
532531
ret item_symbol(item);
533532
}
534533

535-
fn get_tag_variants(session.session sess,
536-
@ty.type_store tystore,
537-
ast.def_id def) -> vec[trans.variant_info] {
534+
fn get_tag_variants(session.session sess, ty.ctxt tcx, ast.def_id def)
535+
-> vec[trans.variant_info] {
538536
auto external_crate_id = def._0;
539537
auto data = sess.get_external_crate(external_crate_id).data;
540538
auto items = ebml.get_doc(ebml.new_doc(data), metadata.tag_items);
@@ -544,9 +542,9 @@ fn get_tag_variants(session.session sess,
544542
auto variant_ids = tag_variant_ids(item, external_crate_id);
545543
for (ast.def_id did in variant_ids) {
546544
auto item = find_item(did._1, items);
547-
auto ctor_ty = item_type(item, external_crate_id, tystore);
545+
auto ctor_ty = item_type(item, external_crate_id, tcx);
548546
let vec[ty.t] arg_tys = vec();
549-
alt (ty.struct(tystore, ctor_ty)) {
547+
alt (ty.struct(tcx, ctor_ty)) {
550548
case (ty.ty_fn(_, ?args, _)) {
551549
for (ty.arg a in args) {
552550
arg_tys += vec(a.ty);

src/comp/middle/metadata.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ mod Encode {
5353

5454
type ctxt = rec(
5555
fn(ast.def_id) -> str ds, // Callback to translate defs to strs.
56-
@ty.type_store tystore // The type store.
56+
ty.ctxt tcx // The type context.
5757
);
5858

5959
fn ty_str(@ctxt cx, ty.t t) -> str {
60-
ret sty_str(cx, ty.struct(cx.tystore, t));
60+
ret sty_str(cx, ty.struct(cx.tcx, t));
6161
}
6262

6363
fn mt_str(@ctxt cx, &ty.mt mt) -> str {
@@ -337,7 +337,7 @@ fn encode_type(@trans.crate_ctxt cx, &ebml.writer ebml_w, ty.t typ) {
337337
ebml.start_tag(ebml_w, tag_items_data_item_type);
338338

339339
auto f = def_to_str;
340-
auto ty_str_ctxt = @rec(ds=f, tystore=cx.tystore);
340+
auto ty_str_ctxt = @rec(ds=f, tcx=cx.tcx);
341341
ebml_w.writer.write(_str.bytes(Encode.ty_str(ty_str_ctxt, typ)));
342342

343343
ebml.end_tag(ebml_w);
@@ -457,7 +457,7 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
457457
encode_def_id(ebml_w, odid.ty);
458458
encode_kind(ebml_w, 'y' as u8);
459459
encode_type_param_count(ebml_w, tps);
460-
encode_type(cx, ebml_w, ty.ty_fn_ret(cx.tystore, fn_ty));
460+
encode_type(cx, ebml_w, ty.ty_fn_ret(cx.tcx, fn_ty));
461461
ebml.end_tag(ebml_w);
462462
}
463463
}
@@ -470,7 +470,7 @@ fn encode_info_for_native_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
470470
case (ast.native_item_ty(_, ?did)) {
471471
encode_def_id(ebml_w, did);
472472
encode_kind(ebml_w, 'T' as u8);
473-
encode_type(cx, ebml_w, ty.mk_native(cx.tystore));
473+
encode_type(cx, ebml_w, ty.mk_native(cx.tcx));
474474
}
475475
case (ast.native_item_fn(_, _, _, ?tps, ?did, ?ann)) {
476476
encode_def_id(ebml_w, did);

0 commit comments

Comments
 (0)