Skip to content

Commit 2b36e40

Browse files
committed
Ensure ann tags are actually kept around during typechecking
This way, the tag assigned by the parser stays with the node. I realize ann replacing is probably going away real soon, but I needed this now for moving the resolve defs out of the AST.
1 parent 0795124 commit 2b36e40

File tree

6 files changed

+224
-202
lines changed

6 files changed

+224
-202
lines changed

src/comp/front/ast.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ type ty_param = ident;
2424
// Annotations added during successive passes.
2525
tag ann {
2626
ann_none(uint);
27-
ann_type(middle.ty.t,
27+
ann_type(uint,
28+
middle.ty.t,
2829
Option.t[vec[middle.ty.t]], /* ty param substs */
2930
Option.t[@ts_ann]); /* pre- and postcondition for typestate */
3031
}
3132

33+
fn ann_tag(&ann a) -> uint {
34+
ret alt (a) {
35+
case (ann_none(?t)) { t }
36+
case (ann_type(?t, _, _, _)) { t }
37+
};
38+
}
39+
3240
tag def {
3341
def_fn(def_id);
3442
def_obj(def_id);

src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,7 @@ fn node_ann_ty_params(&ast.ann a) -> vec[ty.t] {
31273127
log_err "missing type annotation";
31283128
fail;
31293129
}
3130-
case (ast.ann_type(_, ?tps_opt, _)) {
3130+
case (ast.ann_type(_, _, ?tps_opt, _)) {
31313131
alt (tps_opt) {
31323132
case (none[vec[ty.t]]) {
31333133
log_err "type annotation has no ty params";
@@ -4148,7 +4148,7 @@ fn lval_generic_fn(&@block_ctxt cx,
41484148
cx.fcx.lcx.ccx.sess.bug("no type annotation for path!");
41494149
fail;
41504150
}
4151-
case (ast.ann_type(?monoty_, ?tps, _)) {
4151+
case (ast.ann_type(_, ?monoty_, ?tps, _)) {
41524152
monoty = monoty_;
41534153
tys = Option.get[vec[ty.t]](tps);
41544154
}

src/comp/middle/ty.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ fn ann_to_type(&ast.ann ann) -> t {
14331433
log_err "ann_to_type() called on node with no type";
14341434
fail;
14351435
}
1436-
case (ast.ann_type(?ty, _, _)) {
1436+
case (ast.ann_type(_, ?ty, _, _)) {
14371437
ret ty;
14381438
}
14391439
}
@@ -1445,7 +1445,7 @@ fn ann_to_type_params(&ast.ann ann) -> vec[t] {
14451445
log_err "ann_to_type_params() called on node with no type params";
14461446
fail;
14471447
}
1448-
case (ast.ann_type(_, ?tps, _)) {
1448+
case (ast.ann_type(_, _, ?tps, _)) {
14491449
alt (tps) {
14501450
case (none[vec[t]]) {
14511451
let vec[t] result = vec();
@@ -1467,7 +1467,7 @@ fn ann_to_monotype(ctxt cx, ast.ann a) -> t {
14671467
log_err "ann_to_monotype() called on expression with no type!";
14681468
fail;
14691469
}
1470-
case (ast.ann_type(?typ, ?tps_opt, _)) {
1470+
case (ast.ann_type(_, ?typ, ?tps_opt, _)) {
14711471
alt (tps_opt) {
14721472
case (none[vec[t]]) { ret typ; }
14731473
case (some[vec[t]](?tps)) {
@@ -1479,8 +1479,8 @@ fn ann_to_monotype(ctxt cx, ast.ann a) -> t {
14791479
}
14801480

14811481
// Turns a type into an ann_type, using defaults for other fields.
1482-
fn triv_ann(t typ) -> ast.ann {
1483-
ret ast.ann_type(typ, none[vec[t]], none[@ts_ann]);
1482+
fn triv_ann(&ast.ann old, t typ) -> ast.ann {
1483+
ret ast.ann_type(ast.ann_tag(old), typ, none[vec[t]], none[@ts_ann]);
14841484
}
14851485

14861486
// Returns the number of distinct type parameters in the given type.
@@ -1778,7 +1778,7 @@ fn expr_has_ty_params(&@ast.expr expr) -> bool {
17781778
// FIXME: Rewrite using complex patterns when they're trustworthy.
17791779
alt (expr_ann(expr)) {
17801780
case (ast.ann_none(_)) { fail; }
1781-
case (ast.ann_type(_, ?tps_opt, _)) {
1781+
case (ast.ann_type(_, _, ?tps_opt, _)) {
17821782
ret !Option.is_none[vec[t]](tps_opt);
17831783
}
17841784
}
@@ -1794,28 +1794,31 @@ fn replace_expr_type(&@ast.expr expr,
17941794
new_tps = none[vec[t]];
17951795
}
17961796

1797-
auto ann = ast.ann_type(new_tyt._1, new_tps, none[@ts_ann]);
1797+
fn mkann_fn(t tyt, Option.t[vec[t]] tps, &ast.ann old_ann) -> ast.ann {
1798+
ret ast.ann_type(ast.ann_tag(old_ann), tyt, tps, none[@ts_ann]);
1799+
}
1800+
auto mkann = bind mkann_fn(new_tyt._1, new_tps, _);
17981801

17991802
alt (expr.node) {
1800-
case (ast.expr_call(?callee, ?args, _)) {
1801-
ret @fold.respan[ast.expr_](expr.span,
1802-
ast.expr_call(callee, args, ann));
1803+
case (ast.expr_call(?callee, ?args, ?a)) {
1804+
ret @fold.respan(expr.span,
1805+
ast.expr_call(callee, args, mkann(a)));
18031806
}
1804-
case (ast.expr_self_method(?ident, _)) {
1805-
ret @fold.respan[ast.expr_](expr.span,
1806-
ast.expr_self_method(ident, ann));
1807+
case (ast.expr_self_method(?ident, ?a)) {
1808+
ret @fold.respan(expr.span,
1809+
ast.expr_self_method(ident, mkann(a)));
18071810
}
1808-
case (ast.expr_bind(?callee, ?args, _)) {
1809-
ret @fold.respan[ast.expr_](expr.span,
1810-
ast.expr_bind(callee, args, ann));
1811+
case (ast.expr_bind(?callee, ?args, ?a)) {
1812+
ret @fold.respan(expr.span,
1813+
ast.expr_bind(callee, args, mkann(a)));
18111814
}
1812-
case (ast.expr_field(?e, ?i, _)) {
1813-
ret @fold.respan[ast.expr_](expr.span,
1814-
ast.expr_field(e, i, ann));
1815+
case (ast.expr_field(?e, ?i, ?a)) {
1816+
ret @fold.respan(expr.span,
1817+
ast.expr_field(e, i, mkann(a)));
18151818
}
1816-
case (ast.expr_path(?p, ?dopt, _)) {
1817-
ret @fold.respan[ast.expr_](expr.span,
1818-
ast.expr_path(p, dopt, ann));
1819+
case (ast.expr_path(?p, ?dopt, ?a)) {
1820+
ret @fold.respan(expr.span,
1821+
ast.expr_path(p, dopt, mkann(a)));
18191822
}
18201823
case (_) {
18211824
log_err "unhandled expr type in replace_expr_type(): " +

0 commit comments

Comments
 (0)