Remove support for old-style for

Closes #1619
This commit is contained in:
Marijn Haverbeke 2012-04-06 20:36:43 +02:00
parent c902eafa14
commit fc202ca034
21 changed files with 37 additions and 164 deletions

View file

@ -103,10 +103,6 @@ fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt<scope>) {
visit_expr(cx, f, sc, v);
}
ast::expr_alt(input, arms, _) { check_alt(*cx, input, arms, sc, v); }
ast::expr_for(decl, seq, blk) {
visit_expr(cx, seq, sc, v);
check_loop(*cx, sc) {|| check_for(*cx, decl, seq, blk, sc, v); }
}
ast::expr_path(pt) {
check_var(*cx, ex, pt, ex.id, false, sc);
handled = false;

View file

@ -11,7 +11,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) {
},
visit_expr: {|e: @expr, cx: ctx, v: visit::vt<ctx>|
alt e.node {
expr_for(_, e, b) | expr_while(e, b) | expr_do_while(b, e) {
expr_while(e, b) | expr_do_while(b, e) {
v.visit_expr(e, cx, v);
v.visit_block(b, {in_loop: true with cx}, v);
}

View file

@ -106,10 +106,6 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
expr_while(_, _) | expr_do_while(_, _) | expr_loop(_) {
visit_block(lp, cx) {|| visit::visit_expr(ex, cx, v);}
}
expr_for(_, coll, blk) {
v.visit_expr(coll, cx, v);
visit_block(lp, cx) {|| visit::visit_block(blk, cx, v);}
}
expr_alt(input, arms, _) {
v.visit_expr(input, cx, v);
let before = cx.current;

View file

@ -408,7 +408,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
e.sess.abort_if_errors();
fn walk_expr(e: @env, exp: @ast::expr, sc: scopes, v: vt<scopes>) {
visit_expr_with_scope(exp, sc, v);
visit::visit_expr(exp, sc, v);
alt exp.node {
ast::expr_path(p) {
maybe_insert(e, exp.id,
@ -613,18 +613,6 @@ fn visit_arm_with_scope(a: ast::arm, sc: scopes, v: vt<scopes>) {
v.visit_block(a.body, sc_inner, v);
}
fn visit_expr_with_scope(x: @ast::expr, sc: scopes, v: vt<scopes>) {
alt x.node {
ast::expr_for(decl, coll, blk) {
let new_sc = cons(scope_loop(decl), @sc);
v.visit_expr(coll, sc, v);
v.visit_local(decl, new_sc, v);
v.visit_block(blk, new_sc, v);
}
_ { visit::visit_expr(x, sc, v); }
}
}
// This is only for irrefutable patterns (e.g. ones that appear in a let)
// So if x occurs, and x is already known to be a enum, that's always an error
fn visit_local_with_scope(e: @env, loc: @local, sc:scopes, v:vt<scopes>) {

View file

@ -1685,39 +1685,6 @@ fn trans_if(cx: block, cond: @ast::expr, thn: ast::blk,
ret join_returns(cx, [then_bcx, else_bcx], [then_dest, else_dest], dest);
}
fn trans_for(cx: block, local: @ast::local, seq: @ast::expr,
body: ast::blk) -> block {
let _icx = cx.insn_ctxt("trans_for");
fn inner(bcx: block, local: @ast::local, curr: ValueRef, t: ty::t,
body: ast::blk, outer_next_cx: block) -> block {
let next_cx = sub_block(bcx, "next");
let scope_cx = loop_scope_block(bcx, cont_other(next_cx),
outer_next_cx, "for loop scope",
body.span);
Br(bcx, scope_cx.llbb);
let curr = PointerCast(bcx, curr,
T_ptr(type_of(bcx.ccx(), t)));
let bcx = alt::bind_irrefutable_pat(scope_cx, local.node.pat,
curr, false);
let bcx = trans_block(bcx, body, ignore);
cleanup_and_Br(bcx, scope_cx, next_cx.llbb);
ret next_cx;
}
let ccx = cx.ccx();
let next_cx = sub_block(cx, "next");
let seq_ty = expr_ty(cx, seq);
let {bcx: bcx, val: seq} = trans_temp_expr(cx, seq);
let seq = PointerCast(bcx, seq, T_ptr(ccx.opaque_vec_type));
let mut fill = tvec::get_fill(bcx, seq);
if ty::type_is_str(seq_ty) {
fill = Sub(bcx, fill, C_int(ccx, 1));
}
let bcx = tvec::iter_vec_raw(bcx, seq, seq_ty, fill,
bind inner(_, local, _, _, body, next_cx));
Br(bcx, next_cx.llbb);
ret next_cx;
}
fn trans_while(cx: block, cond: @ast::expr, body: ast::blk)
-> block {
let _icx = cx.insn_ctxt("trans_while");
@ -3148,10 +3115,6 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
trans_check_expr(bcx, a, "Claim")
};
}
ast::expr_for(decl, seq, body) {
assert dest == ignore;
ret trans_for(bcx, decl, seq, body);
}
ast::expr_while(cond, body) {
assert dest == ignore;
ret trans_while(bcx, cond, body);

View file

@ -190,7 +190,7 @@ fn mark_for_expr(cx: ctx, e: @expr) {
}
}
}
expr_for(_, _, _) | expr_do_while(_, _) | expr_alt(_, _, _) |
expr_do_while(_, _) | expr_alt(_, _, _) |
expr_block(_) | expr_if(_, _, _) | expr_while(_, _) |
expr_fail(_) | expr_break | expr_cont | expr_unary(_, _) |
expr_lit(_) | expr_assert(_) | expr_check(_, _) |

View file

@ -453,9 +453,6 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
set_pre_and_post(fcx.ccx, e.id, block_precond(fcx.ccx, body),
loop_postcond);
}
expr_for(d, index, body) {
find_pre_post_loop(fcx, d, index, body, e.id);
}
expr_index(val, sub) { find_pre_post_exprs(fcx, [val, sub], e.id); }
expr_alt(ex, alts, _) {
find_pre_post_expr(fcx, ex);

View file

@ -561,9 +561,6 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
false_postcond(num_constrs));
}
}
expr_for(d, index, body) {
ret find_pre_post_state_loop(fcx, pres, d, index, body, e.id);
}
expr_index(val, sub) {
ret find_pre_post_state_two(fcx, pres, val, sub, e.id, oper_pure);
}

View file

@ -2955,21 +2955,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
check_expr_with(fcx, cond, ty::mk_bool(tcx)) |
check_then_else(fcx, thn, elsopt, id, expr.span);
}
ast::expr_for(decl, seq, body) {
bot = check_expr(fcx, seq);
let mut elt_ty;
let ety = fcx.expr_ty(seq);
alt structure_of(fcx, expr.span, ety) {
ty::ty_vec(vec_elt_ty) { elt_ty = vec_elt_ty.ty; }
ty::ty_str { elt_ty = ty::mk_mach_uint(tcx, ast::ty_u8); }
_ {
tcx.sess.span_fatal(expr.span,
"mismatched types: expected vector or string "
+ "but found `" + ty_to_str(tcx, ety) + "`");
}
}
bot |= check_for(fcx, decl, elt_ty, body, id);
}
ast::expr_while(cond, body) {
bot = check_expr_with(fcx, cond, ty::mk_bool(tcx));
check_block_no_value(fcx, body);