Skip to content

Commit dd610a1

Browse files
committed
rustc: Add node IDs to AST types so we can associate them with region environments
1 parent d608131 commit dd610a1

File tree

7 files changed

+84
-37
lines changed

7 files changed

+84
-37
lines changed

src/rustc/front/test.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,15 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
254254
types: []});
255255

256256
let test_desc_ty: ast::ty =
257-
nospan(ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()));
257+
{id: cx.sess.next_node_id(),
258+
node: ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()),
259+
span: dummy_sp()};
258260

259261
let vec_mt: ast::mt = {ty: @test_desc_ty, mutbl: ast::m_imm};
260262

261-
ret @nospan(ast::ty_vec(vec_mt));
263+
ret @{id: cx.sess.next_node_id(),
264+
node: ast::ty_vec(vec_mt),
265+
span: dummy_sp()};
262266
}
263267

264268
fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
@@ -346,7 +350,7 @@ fn mk_test_wrapper(cx: test_ctxt,
346350

347351
let wrapper_decl: ast::fn_decl = {
348352
inputs: [],
349-
output: @nospan(ast::ty_nil),
353+
output: @{id: cx.sess.next_node_id(), node: ast::ty_nil, span: span},
350354
purity: ast::impure_fn,
351355
cf: ast::return_val,
352356
constraints: []
@@ -377,17 +381,23 @@ fn mk_test_wrapper(cx: test_ctxt,
377381

378382
fn mk_main(cx: test_ctxt) -> @ast::item {
379383
let str_pt = @nospan({global: false, idents: ["str"], types: []});
380-
let str_ty = @nospan(ast::ty_path(str_pt, cx.sess.next_node_id()));
384+
let str_ty = @{id: cx.sess.next_node_id(),
385+
node: ast::ty_path(str_pt, cx.sess.next_node_id()),
386+
span: dummy_sp()};
381387
let args_mt: ast::mt = {ty: str_ty, mutbl: ast::m_imm};
382-
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
388+
let args_ty: ast::ty = {id: cx.sess.next_node_id(),
389+
node: ast::ty_vec(args_mt),
390+
span: dummy_sp()};
383391

384392
let args_arg: ast::arg =
385393
{mode: ast::expl(ast::by_val),
386394
ty: @args_ty,
387395
ident: "args",
388396
id: cx.sess.next_node_id()};
389397

390-
let ret_ty = nospan(ast::ty_nil);
398+
let ret_ty = {id: cx.sess.next_node_id(),
399+
node: ast::ty_nil,
400+
span: dummy_sp()};
391401

392402
let decl: ast::fn_decl =
393403
{inputs: [args_arg],

src/rustc/metadata/astencode_gen.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,12 +3463,15 @@ fn serialize_31<S: std::serialization::serializer>(s: S,
34633463
/*syntax::ast::ty*/
34643464
fn serialize_30<S: std::serialization::serializer>(s: S, v: syntax::ast::ty) {
34653465

3466-
s.emit_rec(/*syntax::ast::ty_*//*syntax::codemap::span*/
3466+
s.emit_rec(/*syntax::ast::node_id*//*syntax::ast::ty_*/
3467+
/*syntax::codemap::span*/
34673468
{||
34683469
{
3469-
s.emit_rec_field("node", 0u,
3470+
s.emit_rec_field("id", 0u,
3471+
{|| serialize_27(s, v.id) });
3472+
s.emit_rec_field("node", 1u,
34703473
{|| serialize_31(s, v.node) });
3471-
s.emit_rec_field("span", 1u,
3474+
s.emit_rec_field("span", 2u,
34723475
{|| serialize_19(s, v.span) })
34733476
}
34743477
});
@@ -7325,15 +7328,18 @@ fn deserialize_30<S: std::serialization::deserializer>(s: S) ->
73257328
s.read_rec(
73267329

73277330

7331+
/*syntax::ast::node_id*/
7332+
73287333
/*syntax::ast::ty_*/
73297334

73307335
/*syntax::codemap::span*/
73317336

73327337
{||
7333-
{node:
7334-
s.read_rec_field("node", 0u, {|| deserialize_31(s) }),
7338+
{id: s.read_rec_field("id", 0u, {|| deserialize_27(s) }),
7339+
node:
7340+
s.read_rec_field("node", 1u, {|| deserialize_31(s) }),
73357341
span:
7336-
s.read_rec_field("span", 1u,
7342+
s.read_rec_field("span", 2u,
73377343
{|| deserialize_19(s) }),}
73387344
})
73397345

src/rustc/middle/trans/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4419,7 +4419,8 @@ fn trans_item(ccx: crate_ctxt, item: ast::item) {
44194419
node: ast::pat_ident(rslt_path, none),
44204420
span: ctor.node.body.span};
44214421
// Set up obj's type
4422-
let rslt_ast_ty : @ast::ty = @{node: ast::ty_infer,
4422+
let rslt_ast_ty : @ast::ty = @{id: ccx.sess.next_node_id(),
4423+
node: ast::ty_infer,
44234424
span: ctor.node.body.span};
44244425
// kludgy
44254426
let ty_args = [], i = 0u;

src/rustc/syntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, }
334334

335335
enum float_ty { ty_f, ty_f32, ty_f64, }
336336

337-
type ty = spanned<ty_>;
337+
type ty = {id: node_id, node: ty_, span: span};
338338

339339
// Not represented directly in the AST, referred to by name through a ty_path.
340340
enum prim_ty {

src/rustc/syntax/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold {
699699
}
700700
fn f_ty(afp: ast_fold_precursor, f: ast_fold, &&x: @ty) -> @ty {
701701
let (n, s) = afp.fold_ty(x.node, x.span, f);
702-
ret @{node: n, span: afp.new_span(s)};
702+
ret @{id: x.id, node: n, span: afp.new_span(s)};
703703
}
704704
fn f_constr(afp: ast_fold_precursor, f: ast_fold, &&x: @ast::constr) ->
705705
@ast::constr {

src/rustc/syntax/parse/parser.rs

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,24 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool,
385385
expect(p, token::LT);
386386
} else if !colons_before_params && p.token == token::LT {
387387
p.bump();
388-
} else { ret @spanned(lo, p.last_span.hi, orig_t); }
388+
} else {
389+
ret @{id: p.get_id(),
390+
node: orig_t,
391+
span: ast_util::mk_sp(lo, p.last_span.hi)};
392+
}
389393

390394
// If we're here, we have explicit type parameter instantiation.
391395
let seq = parse_seq_to_gt(some(token::COMMA), {|p| parse_ty(p, false)},
392396
p);
393397

394398
alt orig_t {
395399
ast::ty_path(pth, ann) {
396-
ret @spanned(lo, p.last_span.hi,
397-
ast::ty_path(@spanned(lo, p.last_span.hi,
398-
{global: pth.node.global,
399-
idents: pth.node.idents,
400-
types: seq}), ann));
400+
ret @{id: p.get_id(),
401+
node: ast::ty_path(@spanned(lo, p.last_span.hi,
402+
{global: pth.node.global,
403+
idents: pth.node.idents,
404+
types: seq}), ann),
405+
span: ast_util::mk_sp(lo, p.last_span.hi)};
401406
}
402407
_ { p.fatal("type parameter instantiation only allowed for paths"); }
403408
}
@@ -407,11 +412,17 @@ fn parse_ret_ty(p: parser) -> (ast::ret_style, @ast::ty) {
407412
ret if eat(p, token::RARROW) {
408413
let lo = p.span.lo;
409414
if eat(p, token::NOT) {
410-
(ast::noreturn, @spanned(lo, p.last_span.hi, ast::ty_bot))
411-
} else { (ast::return_val, parse_ty(p, false)) }
415+
(ast::noreturn, @{id: p.get_id(),
416+
node: ast::ty_bot,
417+
span: ast_util::mk_sp(lo, p.last_span.hi)})
418+
} else {
419+
(ast::return_val, parse_ty(p, false))
420+
}
412421
} else {
413422
let pos = p.span.lo;
414-
(ast::return_val, @spanned(pos, pos, ast::ty_nil))
423+
(ast::return_val, @{id: p.get_id(),
424+
node: ast::ty_nil,
425+
span: ast_util::mk_sp(pos, pos)})
415426
}
416427
}
417428

@@ -435,8 +446,11 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
435446
let lo = p.span.lo;
436447

437448
alt have_dollar(p) {
438-
some(e) {ret @spanned(lo, p.span.hi,
439-
ast::ty_mac(spanned(lo, p.span.hi, e)))}
449+
some(e) {
450+
ret @{id: p.get_id(),
451+
node: ast::ty_mac(spanned(lo, p.span.hi, e)),
452+
span: ast_util::mk_sp(lo, p.span.hi)};
453+
}
440454
none {}
441455
}
442456

@@ -475,7 +489,10 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
475489
let t = ast::ty_rec(elems.node);
476490
if p.token == token::COLON {
477491
p.bump();
478-
ast::ty_constr(@spanned(lo, hi, t), parse_type_constraints(p))
492+
ast::ty_constr(@{id: p.get_id(),
493+
node: t,
494+
span: ast_util::mk_sp(lo, hi)},
495+
parse_type_constraints(p))
479496
} else { t }
480497
} else if p.token == token::LBRACKET {
481498
expect(p, token::LBRACKET);
@@ -534,7 +551,9 @@ fn parse_fn_block_arg(p: parser) -> ast::arg {
534551
let t = if eat(p, token::COLON) {
535552
parse_ty(p, false)
536553
} else {
537-
@spanned(p.span.lo, p.span.hi, ast::ty_infer)
554+
@{id: p.get_id(),
555+
node: ast::ty_infer,
556+
span: ast_util::mk_sp(p.span.lo, p.span.hi)}
538557
};
539558
ret {mode: m, ty: t, ident: i, id: p.get_id()};
540559
}
@@ -1606,7 +1625,9 @@ fn parse_local(p: parser, is_mutbl: bool,
16061625
allow_init: bool) -> @ast::local {
16071626
let lo = p.span.lo;
16081627
let pat = parse_pat(p);
1609-
let ty = @spanned(lo, lo, ast::ty_infer);
1628+
let ty = @{id: p.get_id(),
1629+
node: ast::ty_infer,
1630+
span: ast_util::mk_sp(lo, lo)};
16101631
if eat(p, token::COLON) { ty = parse_ty(p, false); }
16111632
let init = if allow_init { parse_initializer(p) } else { none };
16121633
ret @spanned(lo, p.last_span.hi,
@@ -1882,7 +1903,7 @@ fn parse_fn_block_decl(p: parser) -> ast::fn_decl {
18821903
let output = if eat(p, token::RARROW) {
18831904
parse_ty(p, false)
18841905
} else {
1885-
@spanned(p.span.lo, p.span.hi, ast::ty_infer)
1906+
@{id: p.get_id(), node: ast::ty_infer, span: p.span}
18861907
};
18871908
ret {inputs: inputs,
18881909
output: output,
@@ -1957,7 +1978,7 @@ fn parse_item_iface(p: parser, attrs: [ast::attribute]) -> @ast::item {
19571978
fn parse_item_impl(p: parser, attrs: [ast::attribute]) -> @ast::item {
19581979
let lo = p.last_span.lo;
19591980
fn wrap_path(p: parser, pt: @ast::path) -> @ast::ty {
1960-
@{node: ast::ty_path(pt, p.get_id()), span: pt.span}
1981+
@{id: p.get_id(), node: ast::ty_path(pt, p.get_id()), span: pt.span}
19611982
}
19621983
let (ident, tps) = if !is_word(p, "of") {
19631984
if p.token == token::LT { (none, parse_ty_params(p)) }
@@ -1996,7 +2017,9 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
19962017
{inputs:
19972018
[{mode: ast::expl(ast::by_ref), ty: t,
19982019
ident: arg_ident, id: p.get_id()}],
1999-
output: @spanned(lo, lo, ast::ty_nil),
2020+
output: @{id: p.get_id(),
2021+
node: ast::ty_nil,
2022+
span: ast_util::mk_sp(lo, lo)},
20002023
purity: ast::impure_fn,
20012024
cf: ast::return_val,
20022025
constraints: []};
@@ -2066,8 +2089,9 @@ enum class_contents { ctor_decl(ast::fn_decl, ast::blk, codemap::span),
20662089
// Can ctors have attrs?
20672090
// result type is always the type of the class
20682091
let decl_ = parse_fn_decl(p, ast::impure_fn);
2069-
let decl = {output: @{node: ast::ty_path(class_name, p.get_id()),
2070-
span: decl_.output.span}
2092+
let decl = {output: @{id: p.get_id(),
2093+
node: ast::ty_path(class_name, p.get_id()),
2094+
span: decl_.output.span}
20712095
with decl_};
20722096
let body = parse_block(p);
20732097
ret ctor_decl(decl, body, ast_util::mk_sp(lo, p.last_span.hi));

src/rustc/syntax/print/pprust.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ fn fun_to_str(decl: ast::fn_decl, name: ast::ident,
114114
fn test_fun_to_str() {
115115
let decl: ast::fn_decl = {
116116
inputs: [],
117-
output: @ast_util::respan(ast_util::dummy_sp(), ast::ty_nil),
117+
output: @{id: 0,
118+
node: ast::ty_nil,
119+
span: ast_util::dummy_sp()},
118120
purity: ast::impure_fn,
119121
cf: ast::return_val,
120122
constraints: []
@@ -138,11 +140,15 @@ fn test_res_to_str() {
138140
let decl: ast::fn_decl = {
139141
inputs: [{
140142
mode: ast::expl(ast::by_val),
141-
ty: @ast_util::respan(ast_util::dummy_sp(), ast::ty_nil),
143+
ty: @{id: 0,
144+
node: ast::ty_nil,
145+
span: ast_util::dummy_sp()},
142146
ident: "b",
143147
id: 0
144148
}],
145-
output: @ast_util::respan(ast_util::dummy_sp(), ast::ty_nil),
149+
output: @{id: 0,
150+
node: ast::ty_nil,
151+
span: ast_util::dummy_sp()},
146152
purity: ast::impure_fn,
147153
cf: ast::return_val,
148154
constraints: []

0 commit comments

Comments
 (0)