Skip to content

Commit 2ad0954

Browse files
committed
Merge remote branch 'upstream/master'
2 parents a355505 + 56eb986 commit 2ad0954

26 files changed

+1621
-1599
lines changed

src/comp/driver/rustc.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ fn time[T](bool do_it, str what, fn() -> T thunk) -> T {
7676
fn compile_input(session::session sess, eval::env env, str input,
7777
str output) {
7878
auto time_passes = sess.get_opts().time_passes;
79-
auto def = tup(ast::local_crate, 0);
80-
auto p = parser::new_parser(sess, env, def, input, 0u, 0u);
79+
auto p = parser::new_parser(sess, env, input, 0u, 0);
8180
auto crate =
8281
time(time_passes, "parsing", bind parse_input(sess, p, input));
8382
if (sess.get_opts().output_type == link::output_type_none) { ret; }
83+
auto ast_map = time(time_passes, "ast indexing",
84+
bind middle::ast_map::map_crate(*crate));
8485
auto d =
8586
time(time_passes, "resolution",
86-
bind resolve::resolve_crate(sess, crate));
87-
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1);
87+
bind resolve::resolve_crate(sess, ast_map, crate));
88+
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1, ast_map);
8889
time[()](time_passes, "typechecking",
8990
bind typeck::check_crate(ty_cx, crate));
9091
if (sess.get_opts().run_typestate) {
@@ -95,22 +96,22 @@ fn compile_input(session::session sess, eval::env env, str input,
9596
bind middle::alias::check_crate(@ty_cx, crate));
9697
auto llmod =
9798
time[llvm::llvm::ModuleRef](time_passes, "translation",
98-
bind trans::trans_crate(sess, crate,
99-
ty_cx, output));
99+
bind trans::trans_crate
100+
(sess, crate, ty_cx, output, ast_map));
100101
time[()](time_passes, "LLVM passes",
101102
bind link::write::run_passes(sess, llmod, output));
102103
}
103104

104105
fn pretty_print_input(session::session sess, eval::env env, str input,
105106
pp_mode ppm) {
106-
auto def = tup(ast::local_crate, 0);
107-
auto p = front::parser::new_parser(sess, env, def, input, 0u, 0u);
107+
auto p = front::parser::new_parser(sess, env, input, 0u, 0);
108108
auto crate = parse_input(sess, p, input);
109109
auto mode;
110110
alt (ppm) {
111111
case (ppm_typed) {
112-
auto d = resolve::resolve_crate(sess, crate);
113-
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1);
112+
auto amap = middle::ast_map::map_crate(*crate);
113+
auto d = resolve::resolve_crate(sess, amap, crate);
114+
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1, amap);
114115
typeck::check_crate(ty_cx, crate);
115116
mode = ppaux::mo_typed(ty_cx);
116117
}

src/comp/front/ast.rs

+78-84
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ type path = spanned[path_];
1616
fn path_name(&path p) -> str { ret str::connect(p.node.idents, "::"); }
1717

1818
type crate_num = int;
19+
type node_id = int;
20+
type def_id = tup(crate_num, node_id);
1921

2022
const crate_num local_crate = 0;
21-
22-
type def_num = int;
23-
24-
type def_id = tup(crate_num, def_num);
23+
fn local_def(node_id id) -> def_id {
24+
ret tup(local_crate, id);
25+
}
2526

2627
type ty_param = ident;
2728

28-
type ann = rec(uint id);
29-
3029
tag def {
3130
def_fn(def_id);
3231
def_obj(def_id);
@@ -102,15 +101,15 @@ type meta_item_ = rec(ident key, str value);
102101

103102
type block = spanned[block_];
104103

105-
type block_ = rec(vec[@stmt] stmts, option::t[@expr] expr, ann a);
104+
type block_ = rec(vec[@stmt] stmts, option::t[@expr] expr, node_id id);
106105

107106
type pat = spanned[pat_];
108107

109108
tag pat_ {
110-
pat_wild(ann);
111-
pat_bind(ident, def_id, ann);
112-
pat_lit(@lit, ann);
113-
pat_tag(path, vec[@pat], ann);
109+
pat_wild(node_id);
110+
pat_bind(ident, node_id);
111+
pat_lit(@lit, node_id);
112+
pat_tag(path, vec[@pat], node_id);
114113
}
115114

116115
tag mutability { mut; imm; maybe_mut; }
@@ -183,8 +182,8 @@ tag mode { val; alias(bool); }
183182
type stmt = spanned[stmt_];
184183
185184
tag stmt_ {
186-
stmt_decl(@decl, ann);
187-
stmt_expr(@expr, ann);
185+
stmt_decl(@decl, node_id);
186+
stmt_expr(@expr, node_id);
188187
189188
// These only exist in crate-level blocks.
190189
stmt_crate_directive(@crate_directive);
@@ -199,8 +198,7 @@ type local_ =
199198
bool infer,
200199
ident ident,
201200
option::t[initializer] init,
202-
def_id id,
203-
ann ann);
201+
node_id id);
204202
205203
type local = spanned[local_];
206204
@@ -225,58 +223,58 @@ tag seq_kind { sk_unique; sk_rc; }
225223
type expr = spanned[expr_];
226224
227225
tag expr_ {
228-
expr_vec(vec[@expr], mutability, seq_kind, ann);
229-
expr_tup(vec[elt], ann);
230-
expr_rec(vec[field], option::t[@expr], ann);
231-
expr_call(@expr, vec[@expr], ann);
232-
expr_self_method(ident, ann);
233-
expr_bind(@expr, vec[option::t[@expr]], ann);
234-
expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], ann);
235-
expr_binary(binop, @expr, @expr, ann);
236-
expr_unary(unop, @expr, ann);
237-
expr_lit(@lit, ann);
238-
expr_cast(@expr, @ty, ann);
239-
expr_if(@expr, block, option::t[@expr], ann);
240-
expr_while(@expr, block, ann);
241-
expr_for(@local, @expr, block, ann);
242-
expr_for_each(@local, @expr, block, ann);
243-
expr_do_while(block, @expr, ann);
244-
expr_alt(@expr, vec[arm], ann);
245-
expr_fn(_fn, ann);
246-
expr_block(block, ann);
226+
expr_vec(vec[@expr], mutability, seq_kind, node_id);
227+
expr_tup(vec[elt], node_id);
228+
expr_rec(vec[field], option::t[@expr], node_id);
229+
expr_call(@expr, vec[@expr], node_id);
230+
expr_self_method(ident, node_id);
231+
expr_bind(@expr, vec[option::t[@expr]], node_id);
232+
expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], node_id);
233+
expr_binary(binop, @expr, @expr, node_id);
234+
expr_unary(unop, @expr, node_id);
235+
expr_lit(@lit, node_id);
236+
expr_cast(@expr, @ty, node_id);
237+
expr_if(@expr, block, option::t[@expr], node_id);
238+
expr_while(@expr, block, node_id);
239+
expr_for(@local, @expr, block, node_id);
240+
expr_for_each(@local, @expr, block, node_id);
241+
expr_do_while(block, @expr, node_id);
242+
expr_alt(@expr, vec[arm], node_id);
243+
expr_fn(_fn, node_id);
244+
expr_block(block, node_id);
247245
/*
248246
* FIXME: many of these @exprs should be constrained with
249247
* is_lval once we have constrained types working.
250248
*/
251-
expr_move(@expr, @expr, ann);
252-
expr_assign(@expr,@expr, ann);
253-
expr_swap(@expr, @expr, ann);
254-
expr_assign_op(binop, @expr, @expr, ann);
255-
expr_send(@expr, @expr, ann);
256-
expr_recv(@expr, @expr, ann);
257-
expr_field(@expr, ident, ann);
258-
expr_index(@expr, @expr, ann);
259-
expr_path(path, ann);
260-
expr_ext(path, vec[@expr], option::t[str], @expr, ann);
261-
expr_fail(ann, option::t[str]);
262-
expr_break(ann);
263-
expr_cont(ann);
264-
expr_ret(option::t[@expr], ann);
265-
expr_put(option::t[@expr], ann);
266-
expr_be(@expr, ann);
267-
expr_log(int, @expr, ann);
249+
expr_move(@expr, @expr, node_id);
250+
expr_assign(@expr,@expr, node_id);
251+
expr_swap(@expr, @expr, node_id);
252+
expr_assign_op(binop, @expr, @expr, node_id);
253+
expr_send(@expr, @expr, node_id);
254+
expr_recv(@expr, @expr, node_id);
255+
expr_field(@expr, ident, node_id);
256+
expr_index(@expr, @expr, node_id);
257+
expr_path(path, node_id);
258+
expr_ext(path, vec[@expr], option::t[str], @expr, node_id);
259+
expr_fail(node_id, option::t[str]);
260+
expr_break(node_id);
261+
expr_cont(node_id);
262+
expr_ret(option::t[@expr], node_id);
263+
expr_put(option::t[@expr], node_id);
264+
expr_be(@expr, node_id);
265+
expr_log(int, @expr, node_id);
268266
269267
/* just an assert, no significance to typestate */
270-
expr_assert(@expr, ann);
268+
expr_assert(@expr, node_id);
271269
272270
/* preds that typestate is aware of */
273-
expr_check(@expr, ann);
271+
expr_check(@expr, node_id);
274272
/* FIXME Would be nice if expr_check desugared
275273
to expr_if_check. */
276-
expr_if_check(@expr, block, option::t[@expr], ann);
277-
expr_port(ann);
278-
expr_chan(@expr, ann);
279-
expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids, ann);
274+
expr_if_check(@expr, block, option::t[@expr], node_id);
275+
expr_port(node_id);
276+
expr_chan(@expr, node_id);
277+
expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids, node_id);
280278
}
281279
282280
type lit = spanned[lit_];
@@ -348,7 +346,7 @@ tag ty_ {
348346
ty_rec(vec[ty_field]);
349347
ty_fn(proto, vec[ty_arg], @ty, controlflow, vec[@constr]);
350348
ty_obj(vec[ty_method]);
351-
ty_path(path, ann);
349+
ty_path(path, node_id);
352350
ty_type;
353351
ty_constr(@ty, vec[@constr]);
354352
}
@@ -368,15 +366,17 @@ type constr_arg = constr_arg_general[uint];
368366
369367
type constr_arg_general[T] = spanned[constr_arg_general_[T]];
370368
371-
type constr_ = rec(path path, vec[@constr_arg_general[uint]] args, ann ann);
369+
type constr_ = rec(path path,
370+
vec[@constr_arg_general[uint]] args,
371+
node_id id);
372372
373373
type constr = spanned[constr_];
374374
375375
376376
/* The parser generates ast::constrs; resolve generates
377377
a mapping from each function to a list of ty::constr_defs,
378378
corresponding to these. */
379-
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
379+
type arg = rec(mode mode, @ty ty, ident ident, node_id id);
380380
381381
type fn_decl =
382382
rec(vec[arg] inputs,
@@ -402,11 +402,11 @@ tag controlflow {
402402

403403
type _fn = rec(fn_decl decl, proto proto, block body);
404404

405-
type method_ = rec(ident ident, _fn meth, def_id id, ann ann);
405+
type method_ = rec(ident ident, _fn meth, node_id id);
406406

407407
type method = spanned[method_];
408408

409-
type obj_field = rec(mutability mut, @ty ty, ident ident, def_id id, ann ann);
409+
type obj_field = rec(mutability mut, @ty ty, ident ident, node_id id);
410410

411411
type _obj =
412412
rec(vec[obj_field] fields, vec[@method] methods, option::t[@method] dtor);
@@ -435,22 +435,22 @@ type native_mod =
435435
vec[@view_item] view_items,
436436
vec[@native_item] items);
437437

438-
type variant_arg = rec(@ty ty, def_id id);
438+
type variant_arg = rec(@ty ty, node_id id);
439439

440-
type variant_ = rec(str name, vec[variant_arg] args, def_id id, ann ann);
440+
type variant_ = rec(str name, vec[variant_arg] args, node_id id);
441441

442442
type variant = spanned[variant_];
443443

444444
type view_item = spanned[view_item_];
445445

446446
tag view_item_ {
447-
view_item_use(ident, vec[@meta_item], def_id, ann);
448-
view_item_import(ident, vec[ident], def_id);
449-
view_item_import_glob(vec[ident], def_id);
450-
view_item_export(ident);
447+
view_item_use(ident, vec[@meta_item], node_id);
448+
view_item_import(ident, vec[ident], node_id);
449+
view_item_import_glob(vec[ident], node_id);
450+
view_item_export(ident, node_id);
451451
}
452452

453-
type obj_def_ids = rec(def_id ty, def_id ctor);
453+
type obj_def_ids = rec(node_id ty, node_id ctor);
454454

455455

456456
// Meta-data associated with an item
@@ -464,14 +464,11 @@ tag attr_style { attr_outer; attr_inner; }
464464

465465
type attribute_ = rec(attr_style style, meta_item value);
466466

467-
type item =
468-
rec(ident ident,
469-
vec[attribute] attrs,
470-
def_id id, // For objs, this is the type def_id
471-
472-
ann ann,
473-
item_ node,
474-
span span);
467+
type item = rec(ident ident,
468+
vec[attribute] attrs,
469+
node_id id, // For objs, this is the type's def_id
470+
item_ node,
471+
span span);
475472

476473
tag item_ {
477474
item_const(@ty, @expr);
@@ -480,21 +477,18 @@ tag item_ {
480477
item_native_mod(native_mod);
481478
item_ty(@ty, vec[ty_param]);
482479
item_tag(vec[variant], vec[ty_param]);
483-
item_obj(_obj, vec[ty_param], def_id);
484-
/* constructor id */
485-
480+
item_obj(_obj, vec[ty_param], node_id /* constructor id */);
486481
}
487482

488483
type native_item = spanned[native_item_];
489484

490485
tag native_item_ {
491-
native_item_ty(ident, def_id);
486+
native_item_ty(ident, node_id);
492487
native_item_fn(ident,
493488
option::t[str],
494489
fn_decl,
495490
vec[ty_param],
496-
def_id,
497-
ann);
491+
node_id);
498492
}
499493

500494
fn is_exported(ident i, _mod m) -> bool {
@@ -514,7 +508,7 @@ fn is_exported(ident i, _mod m) -> bool {
514508
auto count = 0u;
515509
for (@ast::view_item vi in m.view_items) {
516510
alt (vi.node) {
517-
case (ast::view_item_export(?id)) {
511+
case (ast::view_item_export(?id, _)) {
518512
if (str::eq(i, id)) {
519513
// even if it's nonlocal (since it's explicit)
520514

src/comp/front/creader.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ fn parse_def_id(vec[u8] buf) -> ast::def_id {
359359
auto crate_part = vec::slice[u8](buf, 0u, colon_idx);
360360
auto def_part = vec::slice[u8](buf, colon_idx + 1u, len);
361361
auto crate_num = uint::parse_buf(crate_part, 10u) as int;
362-
auto def_num = uint::parse_buf(def_part, 10u) as int;
363-
ret tup(crate_num, def_num);
362+
auto def_id = uint::parse_buf(def_part, 10u) as int;
363+
ret tup(crate_num, def_id);
364364
}
365365

366366
fn lookup_hash(&ebml::doc d, fn(vec[u8]) -> bool eq_fn, uint hash) ->
@@ -407,7 +407,7 @@ fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] {
407407
ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id;
408408
}
409409
auto eqer = bind eq_item(_, item_id);
410-
auto found = lookup_hash(items, eqer, metadata::hash_def_num(item_id));
410+
auto found = lookup_hash(items, eqer, metadata::hash_def_id(item_id));
411411
if (vec::len(found) == 0u) {
412412
ret option::none[ebml::doc];
413413
} else { ret option::some[ebml::doc](found.(0)); }
@@ -606,7 +606,7 @@ type env =
606606

607607
fn visit_view_item(env e, &@ast::view_item i) {
608608
alt (i.node) {
609-
case (ast::view_item_use(?ident, ?meta_items, ?id, ?ann)) {
609+
case (ast::view_item_use(?ident, ?meta_items, ?id)) {
610610
auto cnum;
611611
if (!e.crate_cache.contains_key(ident)) {
612612
cnum = e.next_crate_num;
@@ -615,7 +615,7 @@ fn visit_view_item(env e, &@ast::view_item i) {
615615
e.crate_cache.insert(ident, e.next_crate_num);
616616
e.next_crate_num += 1;
617617
} else { cnum = e.crate_cache.get(ident); }
618-
e.crate_map.insert(ann.id, cnum);
618+
e.crate_map.insert(id, cnum);
619619
}
620620
case (_) { }
621621
}

0 commit comments

Comments
 (0)