Remove match check

This commit is contained in:
Tim Chevalier 2012-08-24 21:03:51 -07:00
parent c7a3d0eb58
commit 5e22fb9c7f
13 changed files with 23 additions and 39 deletions

View file

@ -348,7 +348,7 @@ enum expr_ {
Same semantics as while(true) { body }, but typestate knows that the
(implicit) condition is always true. */
expr_loop(blk, option<ident>),
expr_match(@expr, ~[arm], alt_mode),
expr_match(@expr, ~[arm]),
expr_fn(proto, fn_decl, blk, capture_clause),
expr_fn_block(fn_decl, blk, capture_clause),
// Inner expr is always an expr_fn_block. We need the wrapping node to

View file

@ -250,7 +250,7 @@ impl ext_ctxt: ext_ctxt_helpers {
self.stmt(
self.expr(
span,
ast::expr_match(v, arms, ast::alt_exhaustive)))
ast::expr_match(v, arms)))
}
fn lit_str(span: span, s: @~str) -> @ast::expr {
@ -944,7 +944,7 @@ fn deser_enum(cx: ext_ctxt, tps: deser_tps_map, e_name: ast::ident,
// Generate code like:
let e_name = cx.lit_str(e_span, @cx.str_of(e_name));
let alt_expr = cx.expr(e_span,
ast::expr_match(#ast{__i}, arms, ast::alt_exhaustive));
ast::expr_match(#ast{__i}, arms));
let var_lambda = #ast{ |__i| $(alt_expr) };
let read_var = #ast{ $(cx.clone(d)).read_enum_variant($(var_lambda)) };
let read_lambda = cx.lambda(cx.expr_blk(read_var));

View file

@ -456,9 +456,9 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
expr_loop(fld.fold_block(body),
option::map(opt_ident, |x| fld.fold_ident(x)))
}
expr_match(expr, arms, mode) => {
expr_match(expr, arms) => {
expr_match(fld.fold_expr(expr),
vec::map(arms, |x| fld.fold_arm(x)), mode)
vec::map(arms, |x| fld.fold_arm(x)))
}
expr_fn(proto, decl, body, captures) => {
expr_fn(proto, fold_fn_decl(decl, fld),

View file

@ -1668,8 +1668,6 @@ struct parser {
fn parse_alt_expr() -> @expr {
let lo = self.last_span.lo;
let mode = if self.eat_keyword(~"check") { alt_check }
else { alt_exhaustive };
let discriminant = self.parse_expr();
self.expect(token::LBRACE);
let mut arms: ~[arm] = ~[];
@ -1701,7 +1699,7 @@ struct parser {
}
let mut hi = self.span.hi;
self.bump();
return self.mk_expr(lo, hi, expr_match(discriminant, arms, mode));
return self.mk_expr(lo, hi, expr_match(discriminant, arms));
}
fn parse_expr() -> @expr {

View file

@ -1128,11 +1128,10 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
option::iter(opt_ident, |ident| {print_ident(s, ident); space(s.s)});
print_block(s, blk);
}
ast::expr_match(expr, arms, mode) => {
ast::expr_match(expr, arms) => {
cbox(s, alt_indent_unit);
ibox(s, 4u);
word_nbsp(s, ~"match");
if mode == ast::alt_check { word_nbsp(s, ~"check"); }
print_maybe_parens_discrim(s, expr);
space(s.s);
bopen(s);

View file

@ -430,7 +430,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
}
expr_while(x, b) => { v.visit_expr(x, e, v); v.visit_block(b, e, v); }
expr_loop(b, _) => v.visit_block(b, e, v),
expr_match(x, arms, _) => {
expr_match(x, arms) => {
v.visit_expr(x, e, v);
for arms.each |a| { v.visit_arm(a, e, v); }
}

View file

@ -171,7 +171,7 @@ fn req_loans_in_expr(ex: @ast::expr,
visit::visit_expr(ex, self, vt);
}
ast::expr_match(ex_v, arms, _) => {
ast::expr_match(ex_v, arms) => {
let cmt = self.bccx.cat_expr(ex_v);
for arms.each |arm| {
for arm.pats.each |pat| {

View file

@ -24,7 +24,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) {
fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
visit::visit_expr(ex, s, v);
match ex.node {
expr_match(scrut, arms, mode) => {
expr_match(scrut, arms) => {
check_arms(tcx, arms);
/* Check for exhaustiveness */
// Check for empty enum, because is_useful only works on inhabited
@ -48,13 +48,10 @@ fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
}
_ => { /* We assume only enum types can be uninhabited */ }
}
if mode == alt_exhaustive {
let arms = vec::concat(vec::filter_map(arms, unguarded_pat));
check_exhaustive(tcx, ex.span, arms);
}
}
_ => ()
let arms = vec::concat(vec::filter_map(arms, unguarded_pat));
check_exhaustive(tcx, ex.span, arms);
}
_ => ()
}
}

View file

@ -1048,7 +1048,7 @@ impl Liveness {
self.propagate_through_loop(expr, none, blk, succ)
}
expr_match(e, arms, _) => {
expr_match(e, arms) => {
//
// (e)
// |

View file

@ -259,7 +259,7 @@ fn resolve_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
cx.sess.intr()));
new_cx.parent = some(expr.id);
}
ast::expr_match(subexpr, _, _) => {
ast::expr_match(subexpr, _) => {
debug!("node %d: %s", expr.id, pprust::expr_to_str(expr,
cx.sess.intr()));
new_cx.parent = some(expr.id);

View file

@ -822,16 +822,15 @@ fn trans_alt(bcx: block,
alt_expr: @ast::expr,
expr: @ast::expr,
arms: ~[ast::arm],
mode: ast::alt_mode,
dest: dest) -> block {
let _icx = bcx.insn_ctxt("alt::trans_alt");
do with_scope(bcx, alt_expr.info(), ~"alt") |bcx| {
trans_alt_inner(bcx, expr, arms, mode, dest)
trans_alt_inner(bcx, expr, arms, dest)
}
}
fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: ~[ast::arm],
mode: ast::alt_mode, dest: dest) -> block {
dest: dest) -> block {
let _icx = scope_cx.insn_ctxt("alt::trans_alt_inner");
let bcx = scope_cx, tcx = bcx.tcx();
let mut bodies = ~[], matches = ~[];
@ -860,15 +859,7 @@ fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: ~[ast::arm],
return fail_cx.llbb;
}
let t = node_id_type(bcx, expr.id);
let mk_fail = match mode {
ast::alt_check => {
let fail_cx = @mut none;
// Cached fail-on-fallthrough block
some(|| mk_fail(scope_cx, expr.span, ~"non-exhaustive match failure",
fail_cx))
}
ast::alt_exhaustive => {
let fail_cx = @mut none;
let mk_fail = { let fail_cx = @mut none;
// special case for uninhabited type
if ty::type_is_empty(tcx, t) {
some(|| mk_fail(scope_cx, expr.span,
@ -877,7 +868,6 @@ fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: ~[ast::arm],
else {
none
}
}
};
let mut exit_map = ~[];
let spilled = spill_if_immediate(bcx, val, t);

View file

@ -3798,8 +3798,8 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
ast::expr_if(cond, thn, els) => {
return trans_if(bcx, cond, thn, els, dest);
}
ast::expr_match(expr, arms, mode) => {
return alt::trans_alt(bcx, e, expr, arms, mode, dest);
ast::expr_match(expr, arms) => {
return alt::trans_alt(bcx, e, expr, arms, dest);
}
ast::expr_block(blk) => {
return do with_scope(bcx, blk.info(), ~"block-expr body") |bcx| {
@ -4488,7 +4488,7 @@ fn trans_block_cleanups_(bcx: block,
}
}
}
}
}
return bcx;
}

View file

@ -1599,7 +1599,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
fcx.write_ty(id, ty::mk_nil(tcx));
bot = !may_break(body);
}
ast::expr_match(discrim, arms, mode) => {
ast::expr_match(discrim, arms) => {
bot = alt::check_alt(fcx, expr, discrim, arms);
}
ast::expr_fn(proto, decl, body, cap_clause) => {