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.
This commit is contained in:
Marijn Haverbeke 2011-05-12 10:51:13 +02:00
parent 079512494f
commit 2b36e40c58
6 changed files with 224 additions and 202 deletions

View File

@ -24,11 +24,19 @@ type ty_param = ident;
// Annotations added during successive passes.
tag ann {
ann_none(uint);
ann_type(middle.ty.t,
ann_type(uint,
middle.ty.t,
Option.t[vec[middle.ty.t]], /* ty param substs */
Option.t[@ts_ann]); /* pre- and postcondition for typestate */
}
fn ann_tag(&ann a) -> uint {
ret alt (a) {
case (ann_none(?t)) { t }
case (ann_type(?t, _, _, _)) { t }
};
}
tag def {
def_fn(def_id);
def_obj(def_id);

View File

@ -3127,7 +3127,7 @@ fn node_ann_ty_params(&ast.ann a) -> vec[ty.t] {
log_err "missing type annotation";
fail;
}
case (ast.ann_type(_, ?tps_opt, _)) {
case (ast.ann_type(_, _, ?tps_opt, _)) {
alt (tps_opt) {
case (none[vec[ty.t]]) {
log_err "type annotation has no ty params";
@ -4148,7 +4148,7 @@ fn lval_generic_fn(&@block_ctxt cx,
cx.fcx.lcx.ccx.sess.bug("no type annotation for path!");
fail;
}
case (ast.ann_type(?monoty_, ?tps, _)) {
case (ast.ann_type(_, ?monoty_, ?tps, _)) {
monoty = monoty_;
tys = Option.get[vec[ty.t]](tps);
}

View File

@ -1433,7 +1433,7 @@ fn ann_to_type(&ast.ann ann) -> t {
log_err "ann_to_type() called on node with no type";
fail;
}
case (ast.ann_type(?ty, _, _)) {
case (ast.ann_type(_, ?ty, _, _)) {
ret ty;
}
}
@ -1445,7 +1445,7 @@ fn ann_to_type_params(&ast.ann ann) -> vec[t] {
log_err "ann_to_type_params() called on node with no type params";
fail;
}
case (ast.ann_type(_, ?tps, _)) {
case (ast.ann_type(_, _, ?tps, _)) {
alt (tps) {
case (none[vec[t]]) {
let vec[t] result = vec();
@ -1467,7 +1467,7 @@ fn ann_to_monotype(ctxt cx, ast.ann a) -> t {
log_err "ann_to_monotype() called on expression with no type!";
fail;
}
case (ast.ann_type(?typ, ?tps_opt, _)) {
case (ast.ann_type(_, ?typ, ?tps_opt, _)) {
alt (tps_opt) {
case (none[vec[t]]) { ret typ; }
case (some[vec[t]](?tps)) {
@ -1479,8 +1479,8 @@ fn ann_to_monotype(ctxt cx, ast.ann a) -> t {
}
// Turns a type into an ann_type, using defaults for other fields.
fn triv_ann(t typ) -> ast.ann {
ret ast.ann_type(typ, none[vec[t]], none[@ts_ann]);
fn triv_ann(&ast.ann old, t typ) -> ast.ann {
ret ast.ann_type(ast.ann_tag(old), typ, none[vec[t]], none[@ts_ann]);
}
// Returns the number of distinct type parameters in the given type.
@ -1778,7 +1778,7 @@ fn expr_has_ty_params(&@ast.expr expr) -> bool {
// FIXME: Rewrite using complex patterns when they're trustworthy.
alt (expr_ann(expr)) {
case (ast.ann_none(_)) { fail; }
case (ast.ann_type(_, ?tps_opt, _)) {
case (ast.ann_type(_, _, ?tps_opt, _)) {
ret !Option.is_none[vec[t]](tps_opt);
}
}
@ -1794,28 +1794,31 @@ fn replace_expr_type(&@ast.expr expr,
new_tps = none[vec[t]];
}
auto ann = ast.ann_type(new_tyt._1, new_tps, none[@ts_ann]);
fn mkann_fn(t tyt, Option.t[vec[t]] tps, &ast.ann old_ann) -> ast.ann {
ret ast.ann_type(ast.ann_tag(old_ann), tyt, tps, none[@ts_ann]);
}
auto mkann = bind mkann_fn(new_tyt._1, new_tps, _);
alt (expr.node) {
case (ast.expr_call(?callee, ?args, _)) {
ret @fold.respan[ast.expr_](expr.span,
ast.expr_call(callee, args, ann));
case (ast.expr_call(?callee, ?args, ?a)) {
ret @fold.respan(expr.span,
ast.expr_call(callee, args, mkann(a)));
}
case (ast.expr_self_method(?ident, _)) {
ret @fold.respan[ast.expr_](expr.span,
ast.expr_self_method(ident, ann));
case (ast.expr_self_method(?ident, ?a)) {
ret @fold.respan(expr.span,
ast.expr_self_method(ident, mkann(a)));
}
case (ast.expr_bind(?callee, ?args, _)) {
ret @fold.respan[ast.expr_](expr.span,
ast.expr_bind(callee, args, ann));
case (ast.expr_bind(?callee, ?args, ?a)) {
ret @fold.respan(expr.span,
ast.expr_bind(callee, args, mkann(a)));
}
case (ast.expr_field(?e, ?i, _)) {
ret @fold.respan[ast.expr_](expr.span,
ast.expr_field(e, i, ann));
case (ast.expr_field(?e, ?i, ?a)) {
ret @fold.respan(expr.span,
ast.expr_field(e, i, mkann(a)));
}
case (ast.expr_path(?p, ?dopt, _)) {
ret @fold.respan[ast.expr_](expr.span,
ast.expr_path(p, dopt, ann));
case (ast.expr_path(?p, ?dopt, ?a)) {
ret @fold.respan(expr.span,
ast.expr_path(p, dopt, mkann(a)));
}
case (_) {
log_err "unhandled expr type in replace_expr_type(): " +

File diff suppressed because it is too large Load Diff

View File

@ -389,7 +389,7 @@ fn mk_f_to_fn_info(@ast.crate c) -> fn_info_map {
fn ann_to_ts_ann(ann a, uint nv) -> ts_ann {
alt (a) {
case (ann_none(_)) { ret empty_ann(nv); }
case (ann_type(_,_,?t)) {
case (ann_type(_,_,_,?t)) {
alt (t) {
/* Kind of inconsistent. empty_ann()s everywhere
or an option of a ts_ann? */
@ -406,7 +406,7 @@ fn ann_to_ts_ann_fail(ann a) -> Option.t[@ts_ann] {
log("ann_to_ts_ann_fail: didn't expect ann_none here");
fail;
}
case (ann_type(_,_,?t)) {
case (ann_type(_,_,_,?t)) {
ret t;
}
}
@ -418,7 +418,7 @@ fn ann_to_ts_ann_fail_more(ann a) -> @ts_ann {
log("ann_to_ts_ann_fail: didn't expect ann_none here");
fail;
}
case (ann_type(_,_,?t)) {
case (ann_type(_,_,_,?t)) {
assert (! is_none[@ts_ann](t));
ret get[@ts_ann](t);
}
@ -450,7 +450,7 @@ fn expr_states(@expr e) -> pre_and_post_state {
log_err "expr_pp: the impossible happened (no annotation)";
fail;
}
case (ann_type(_, _, ?maybe_pp)) {
case (ann_type(_, _, _, ?maybe_pp)) {
alt (maybe_pp) {
case (none[@ts_ann]) {
log_err "expr_pp: the impossible happened (no pre/post)";
@ -471,7 +471,7 @@ fn expr_pp(@expr e) -> pre_and_post {
log_err "expr_pp: the impossible happened (no annotation)";
fail;
}
case (ann_type(_, _, ?maybe_pp)) {
case (ann_type(_, _, _, ?maybe_pp)) {
alt (maybe_pp) {
case (none[@ts_ann]) {
log_err "expr_pp: the impossible happened (no pre/post)";
@ -505,7 +505,7 @@ fn block_pp(&block b) -> pre_and_post {
log_err "block_pp: the impossible happened (no ann)";
fail;
}
case (ann_type(_,_,?t)) {
case (ann_type(_, _,_,?t)) {
alt (t) {
case (none[@ts_ann]) {
log_err "block_pp: the impossible happened (no ty)";
@ -525,7 +525,7 @@ fn block_states(&block b) -> pre_and_post_state {
log_err "block_pp: the impossible happened (no ann)";
fail;
}
case (ann_type(_,_,?t)) {
case (ann_type(_, _,_,?t)) {
alt (t) {
case (none[@ts_ann]) {
log_err "block_states: the impossible happened (no ty)";
@ -605,8 +605,8 @@ fn with_pp(ann a, pre_and_post p) -> ann {
log("with_pp: the impossible happened");
fail; /* shouldn't happen b/c code is typechecked */
}
case (ann_type(?t, ?ps, _)) {
ret (ann_type(t, ps,
case (ann_type(?tg, ?t, ?ps, _)) {
ret (ann_type(tg, t, ps,
some[@ts_ann]
(@rec(conditions=p,
states=empty_states(pps_len(p))))));
@ -1292,7 +1292,7 @@ fn find_pre_post_state_item(fn_info_map fm, fn_info enclosing, @item i)
fn set_prestate_ann(@ann a, prestate pre) -> bool {
alt (*a) {
case (ann_type(_,_,?ts_a)) {
case (ann_type(_, _,_,?ts_a)) {
assert (! is_none[@ts_ann](ts_a));
ret set_prestate(get[@ts_ann](ts_a), pre);
}
@ -1306,7 +1306,7 @@ fn set_prestate_ann(@ann a, prestate pre) -> bool {
fn extend_prestate_ann(ann a, prestate pre) -> bool {
alt (a) {
case (ann_type(_,_,?ts_a)) {
case (ann_type(_,_,_,?ts_a)) {
assert (! is_none[@ts_ann](ts_a));
ret extend_prestate((get[@ts_ann](ts_a)).states.prestate, pre);
}
@ -1319,7 +1319,7 @@ fn extend_prestate_ann(ann a, prestate pre) -> bool {
fn set_poststate_ann(ann a, poststate post) -> bool {
alt (a) {
case (ann_type(_,_,?ts_a)) {
case (ann_type(_, _,_,?ts_a)) {
assert (! is_none[@ts_ann](ts_a));
ret set_poststate(get[@ts_ann](ts_a), post);
}
@ -1332,7 +1332,7 @@ fn set_poststate_ann(ann a, poststate post) -> bool {
fn extend_poststate_ann(ann a, poststate post) -> bool {
alt (a) {
case (ann_type(_,_,?ts_a)) {
case (ann_type(_, _,_,?ts_a)) {
assert (! is_none[@ts_ann](ts_a));
ret extend_poststate((*get[@ts_ann](ts_a)).states.poststate, post);
}
@ -1345,7 +1345,7 @@ fn extend_poststate_ann(ann a, poststate post) -> bool {
fn set_pre_and_post(&ann a, pre_and_post pp) -> () {
alt (a) {
case (ann_type(_,_,?ts_a)) {
case (ann_type(_, _,_,?ts_a)) {
assert (! is_none[@ts_ann](ts_a));
auto t = *get[@ts_ann](ts_a);
/* log("set_pre_and_post, old =");
@ -2046,8 +2046,9 @@ fn init_ann(&fn_info fi, &ann a) -> ann {
// result in an uninitialized ann -- but don't want to have to
// write code to handle native_mods properly
}
case (ann_type(?t,?ps,_)) {
ret ann_type(t, ps, some[@ts_ann](@empty_ann(num_locals(fi))));
case (ann_type(?tg, ?t,?ps,_)) {
ret ann_type(tg, t, ps,
some[@ts_ann](@empty_ann(num_locals(fi))));
}
}
}
@ -2060,8 +2061,8 @@ fn init_blank_ann(&() ignore, &ann a) -> ann {
log("warning: init_blank_ann: saw ann_none");
ret a;
}
case (ann_type(?t,?ps,_)) {
ret ann_type(t, ps, some[@ts_ann](@empty_ann(0u)));
case (ann_type(?tg, ?t,?ps,_)) {
ret ann_type(tg, t, ps, some[@ts_ann](@empty_ann(0u)));
}
}
}
@ -2074,7 +2075,7 @@ fn init_block(&fn_info fi, &span sp, &block_ b) -> block {
log("init_block: shouldn't see ann_none");
fail;
}
case (ann_type(?t,?ps,_)) {
case (ann_type(_, ?t,?ps,_)) {
auto fld0 = fold.new_identity_fold[fn_info]();
fld0 = @rec(fold_ann = bind init_ann(_,_) with *fld0);

View File

@ -117,8 +117,8 @@ fn field_exprs(vec[ast.field] fields) -> vec [@ast.expr] {
ret Vec.map[ast.field, @ast.expr](f, fields);
}
fn plain_ann(middle.ty.ctxt tcx) -> ast.ann {
ret ast.ann_type(middle.ty.mk_nil(tcx),
fn plain_ann(&ast.ann old, middle.ty.ctxt tcx) -> ast.ann {
ret ast.ann_type(ast.ann_tag(old), middle.ty.mk_nil(tcx),
none[vec[middle.ty.t]], none[@ts_ann]);
}
@ -164,7 +164,7 @@ fn log_ann(&ast.ann a) -> () {
case (ast.ann_none(_)) {
log("ann_none");
}
case (ast.ann_type(_,_,_)) {
case (ast.ann_type(_,_,_,_)) {
log("ann_type");
}
}