Skip to content

Commit 78ec6fe

Browse files
committed
Obliterate the callee_id hack
Exprs that could be applications of overloaded operators (expr_unary, expr_binary, expr_index) relied on the previous node ID being "reserved" to carry extra typechecking info. This was incredibly error-prone. Fixed it; now all exprs have two node IDs (which will be wasted in some cases; future work could make this an option instead if the extra int field ends up being a performance problem). Closes #2804
1 parent fec8059 commit 78ec6fe

File tree

21 files changed

+148
-57
lines changed

21 files changed

+148
-57
lines changed

src/fuzzer/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn find_rust_files(&files: ~[str], path: str) {
3434

3535
fn common_exprs() -> ~[ast::expr] {
3636
fn dse(e: ast::expr_) -> ast::expr {
37-
{ id: 0, node: e, span: ast_util::dummy_sp() }
37+
{ id: 0, callee_id: -1, node: e, span: ast_util::dummy_sp() }
3838
}
3939

4040
fn dsl(l: ast::lit_) -> ast::lit {

src/libsyntax/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ enum blk_check_mode { default_blk, unchecked_blk, unsafe_blk, }
288288
enum expr_check_mode { claimed_expr, checked_expr, }
289289

290290
#[auto_serialize]
291-
type expr = {id: node_id, node: expr_, span: span};
291+
type expr = {id: node_id, callee_id: node_id, node: expr_, span: span};
292+
// Extra node ID is only used for index, assign_op, unary, binary
292293

293294
#[auto_serialize]
294295
enum alt_mode { alt_check, alt_exhaustive, }

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ pure fn unguarded_pat(a: arm) -> option<~[@pat]> {
272272
if is_unguarded(a) { some(/* FIXME (#2543) */ copy a.pats) } else { none }
273273
}
274274

275-
// Provides an extra node_id to hang callee information on, in case the
276-
// operator is deferred to a user-supplied method. The parser is responsible
277-
// for reserving this id.
278-
fn op_expr_callee_id(e: @expr) -> node_id { e.id - 1 }
279-
280275
pure fn class_item_ident(ci: @class_member) -> ident {
281276
alt ci.node {
282277
instance_var(i,_,_,_,_) { /* FIXME (#2543) */ copy i }
@@ -455,14 +450,8 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
455450
},
456451

457452
visit_expr: fn@(e: @expr) {
453+
vfn(e.callee_id);
458454
vfn(e.id);
459-
alt e.node {
460-
expr_index(*) | expr_assign_op(*) |
461-
expr_unary(*) | expr_binary(*) {
462-
vfn(ast_util::op_expr_callee_id(e));
463-
}
464-
_ { /* fallthrough */ }
465-
}
466455
},
467456

468457
visit_ty: fn@(t: @ty) {

src/libsyntax/ext/auto_serialize.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ impl helpers for ext_ctxt {
172172
}
173173

174174
fn expr(span: span, node: ast::expr_) -> @ast::expr {
175-
@{id: self.next_id(), node: node, span: span}
175+
@{id: self.next_id(), callee_id: self.next_id(),
176+
node: node, span: span}
176177
}
177178

178179
fn var_ref(span: span, name: ast::ident) -> @ast::expr {

src/libsyntax/ext/build.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import base::ext_ctxt;
33

44
fn mk_expr(cx: ext_ctxt, sp: codemap::span, expr: ast::expr_) ->
55
@ast::expr {
6-
ret @{id: cx.next_id(), node: expr, span: sp};
6+
ret @{id: cx.next_id(), callee_id: cx.next_id(),
7+
node: expr, span: sp};
78
}
89

910
fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
1011
let sp_lit = @{node: lit, span: sp};
11-
ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp};
12+
mk_expr(cx, sp, ast::expr_lit(sp_lit))
1213
}
1314
fn mk_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
1415
let lit = ast::lit_str(@s);
@@ -62,7 +63,7 @@ fn mk_call(cx: ext_ctxt, sp: span, fn_path: ~[ast::ident],
6263
fn mk_base_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
6364
@ast::expr {
6465
let vecexpr = ast::expr_vec(exprs, ast::m_imm);
65-
ret @{id: cx.next_id(), node: vecexpr, span: sp};
66+
mk_expr(cx, sp, vecexpr)
6667
}
6768
fn mk_vstore_e(cx: ext_ctxt, sp: span, expr: @ast::expr, vst: ast::vstore) ->
6869
@ast::expr {

src/libsyntax/ext/concat_idents.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
99
}
1010

1111
ret @{id: cx.next_id(),
12+
callee_id: cx.next_id(),
1213
node: ast::expr_path(@{span: sp, global: false, idents: ~[@res],
1314
rp: none, types: ~[]}),
1415
span: sp};

src/libsyntax/ext/log_syntax.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
1111
);
1212

1313
//trivial expression
14-
ret @{id: cx.next_id(), node: ast::expr_rec(~[], option::none),
15-
span: sp};
14+
ret @{id: cx.next_id(), callee_id: cx.next_id(),
15+
node: ast::expr_rec(~[], option::none), span: sp};
1616
}

src/libsyntax/ext/simplext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import base::*;
77
import fold::*;
88
import ast_util::respan;
99
import ast::{ident, path, ty, blk_, expr, expr_path,
10-
expr_vec, expr_mac, mac_invoc, node_id};
10+
expr_vec, expr_mac, mac_invoc, node_id, expr_index};
1111

1212
export add_new_extension;
1313

src/libsyntax/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ impl of ast_fold for ast_fold_precursor {
688688
fn fold_expr(&&x: @expr) -> @expr {
689689
let (n, s) = self.fold_expr(x.node, x.span, self as ast_fold);
690690
ret @{id: self.new_id(x.id),
691+
callee_id: self.new_id(x.callee_id),
691692
node: n,
692693
span: self.new_span(s)};
693694
}

src/libsyntax/parse/parser.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import print::pprust::expr_to_str;
2+
13
import result::result;
24
import either::{either, left, right};
35
import std::map::{hashmap, str_hash};
@@ -758,11 +760,13 @@ class parser {
758760
}
759761

760762
fn mk_expr(lo: uint, hi: uint, +node: expr_) -> @expr {
761-
ret @{id: self.get_id(), node: node, span: mk_sp(lo, hi)};
763+
ret @{id: self.get_id(), callee_id: self.get_id(),
764+
node: node, span: mk_sp(lo, hi)};
762765
}
763766

764767
fn mk_mac_expr(lo: uint, hi: uint, m: mac_) -> @expr {
765768
ret @{id: self.get_id(),
769+
callee_id: self.get_id(),
766770
node: expr_mac({node: m, span: mk_sp(lo, hi)}),
767771
span: mk_sp(lo, hi)};
768772
}
@@ -772,7 +776,8 @@ class parser {
772776
let lv_lit = @{node: lit_uint(i as u64, ty_u32),
773777
span: span};
774778

775-
ret @{id: self.get_id(), node: expr_lit(lv_lit), span: span};
779+
ret @{id: self.get_id(), callee_id: self.get_id(),
780+
node: expr_lit(lv_lit), span: span};
776781
}
777782

778783
fn mk_pexpr(lo: uint, hi: uint, node: expr_) -> pexpr {
@@ -1112,7 +1117,6 @@ class parser {
11121117
let ix = self.parse_expr();
11131118
hi = ix.span.hi;
11141119
self.expect(token::RBRACKET);
1115-
self.get_id(); // see ast_util::op_expr_callee_id
11161120
e = self.mk_pexpr(lo, hi, expr_index(self.to_expr(e), ix));
11171121
}
11181122

0 commit comments

Comments
 (0)