From d39da6f97819becd9ea41c194b5f0daa178814fe Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Mar 2011 13:56:38 -0500 Subject: [PATCH] Remove typestate workarounds --- src/comp/driver/rustc.rs | 2 -- src/comp/front/extfmt.rs | 17 ++-------------- src/comp/front/parser.rs | 18 ++++++++--------- src/comp/middle/trans.rs | 10 +++++----- src/comp/middle/ty.rs | 42 ++++++++++++--------------------------- src/comp/middle/typeck.rs | 16 ++++++++------- 6 files changed, 37 insertions(+), 68 deletions(-) diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 67275b9b76b..90fe0e0c4e7 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -137,8 +137,6 @@ impure fn main(vec[str] args) { input_file = some[str](arg); } } - // FIXME: dummy node to work around typestate mis-wiring bug. - i = i; } i += 1u; } diff --git a/src/comp/front/extfmt.rs b/src/comp/front/extfmt.rs index 7201a17c6f6..255614d0f07 100644 --- a/src/comp/front/extfmt.rs +++ b/src/comp/front/extfmt.rs @@ -244,9 +244,7 @@ fn parse_count(str s, uint i, uint lim) -> tup(count, uint) { ret tup(count_implied, i); } - // FIXME: These inner functions are just to avoid a rustboot - // "Unsatisfied precondition constraint" bug with alts nested in ifs - fn parse_star_count(str s, uint i, uint lim) -> tup(count, uint) { + if (s.(i) == ('*' as u8)) { auto param = parse_parameter(s, i + 1u, lim); auto j = param._1; alt (param._0) { @@ -257,9 +255,7 @@ fn parse_count(str s, uint i, uint lim) -> tup(count, uint) { ret tup(count_is_param(n), j); } } - } - - fn parse_count_(str s, uint i, uint lim) -> tup(count, uint) { + } else { auto num = peek_num(s, i, lim); alt (num) { case (none[tup(uint, uint)]) { @@ -270,12 +266,6 @@ fn parse_count(str s, uint i, uint lim) -> tup(count, uint) { } } } - - if (s.(i) == ('*' as u8)) { - ret parse_star_count(s, i, lim); - } else { - ret parse_count_(s, i, lim); - } } fn parse_precision(str s, uint i, uint lim) -> tup(count, uint) { @@ -318,9 +308,6 @@ fn parse_type(str s, uint i, uint lim) -> tup(ty, uint) { } else if (_str.eq(tstr, "t")) { t = ty_bits; } else { - // FIXME: This is a hack to avoid 'unsatisfied precondition - // constraint' on uninitialized variable t below - t = ty_bool; log "unknown type in conversion"; fail; } diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 934764e6d57..8665a425e89 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1365,7 +1365,7 @@ impure fn parse_initializer(parser p) -> option.t[@ast.expr] { impure fn parse_pat(parser p) -> @ast.pat { auto lo = p.get_span(); auto hi = lo; - auto pat = ast.pat_wild(ast.ann_none); // FIXME: typestate bug + auto pat; alt (p.peek()) { case (token.UNDERSCORE) { @@ -1541,31 +1541,28 @@ fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ { auto index = new_str_hash[uint](); auto u = 0u; for (@ast.stmt s in stmts) { - // FIXME: typestate bug requires we do this up top, not - // down below loop. Sigh. - u += 1u; alt (s.node) { case (ast.stmt_decl(?d)) { alt (d.node) { case (ast.decl_local(?loc)) { - index.insert(loc.ident, u-1u); + index.insert(loc.ident, u); } case (ast.decl_item(?it)) { alt (it.node) { case (ast.item_fn(?i, _, _, _, _)) { - index.insert(i, u-1u); + index.insert(i, u); } case (ast.item_mod(?i, _, _)) { - index.insert(i, u-1u); + index.insert(i, u); } case (ast.item_ty(?i, _, _, _, _)) { - index.insert(i, u-1u); + index.insert(i, u); } case (ast.item_tag(?i, _, _, _)) { - index.insert(i, u-1u); + index.insert(i, u); } case (ast.item_obj(?i, _, _, _, _)) { - index.insert(i, u-1u); + index.insert(i, u); } } } @@ -1573,6 +1570,7 @@ fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ { } case (_) { /* fall through */ } } + u += 1u; } ret rec(stmts=stmts, expr=expr, index=index); } diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index dde5aa60ac9..e00d5a92c79 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -929,8 +929,8 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint { ret cx.tag_sizes.get(t); } - auto tid = tup(0, 0); // FIXME (#250): typestate botch - let vec[@ty.t] subtys = vec(); // FIXME (#250): typestate botch + auto tid; + let vec[@ty.t] subtys; alt (t.struct) { case (ty.ty_tag(?tid_, ?subtys_)) { tid = tid_; @@ -3419,12 +3419,12 @@ fn trans_bind(@block_ctxt cx, @ast.expr f, } // Figure out which tydescs we need to pass, if any. - // FIXME: typestate botch - let @ty.t outgoing_fty = ty.plain_ty(ty.ty_nil); - let vec[ValueRef] lltydescs = vec(); + let @ty.t outgoing_fty; + let vec[ValueRef] lltydescs; alt (f_res.generic) { case (none[generic_info]) { outgoing_fty = ty.expr_ty(f); + lltydescs = vec(); } case (some[generic_info](?ginfo)) { outgoing_fty = ginfo.item_type; diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 0b6ef53bf6d..3f209d3c7ae 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -1018,32 +1018,6 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler) ret ures_err(terr_meth_count, expected, actual); } - // FIXME: work around buggy typestate logic for 'alt', sigh. - fn is_ok(&unify_result r) -> bool { - alt (r) { - case (ures_ok(?tfn)) { - ret true; - } - case (_) {} - } - ret false; - } - - fn append_if_ok(&method e_meth, - &unify_result r, &mutable vec[method] result_meths) { - alt (r) { - case (ures_ok(?tfn)) { - alt (tfn.struct) { - case (ty_fn(?proto, ?ins, ?out)) { - result_meths += vec(rec(inputs = ins, - output = out - with e_meth)); - } - } - } - } - } - while (i < expected_len) { auto e_meth = expected_meths.(i); auto a_meth = actual_meths.(i); @@ -1056,10 +1030,20 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler) expected, actual, handler, e_meth.inputs, e_meth.output, a_meth.inputs, a_meth.output); - if (!is_ok(r)) { - ret r; + alt (r) { + case (ures_ok(?tfn)) { + alt (tfn.struct) { + case (ty_fn(?proto, ?ins, ?out)) { + result_meths += vec(rec(inputs = ins, + output = out + with e_meth)); + } + } + } + case (_) { + ret r; + } } - append_if_ok(e_meth, r, result_meths); i += 1u; } auto t = plain_ty(ty_obj(result_meths)); diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index f8f7fc72719..c257a1677f7 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -890,7 +890,7 @@ fn are_compatible(&@fn_ctxt fcx, @ty.t expected, @ty.t actual) -> bool { // TODO: enforce this via a predicate. fn demand_pat(&@fn_ctxt fcx, @ty.t expected, @ast.pat pat) -> @ast.pat { - auto p_1 = ast.pat_wild(ast.ann_none); // FIXME: typestate botch + auto p_1; alt (pat.node) { case (ast.pat_wild(?ann)) { @@ -960,9 +960,7 @@ fn demand_expr(&@fn_ctxt fcx, @ty.t expected, @ast.expr e) -> @ast.expr { fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e, autoderef_kind adk) -> @ast.expr { - // FIXME: botch to work around typestate bug in rustboot - let vec[@ast.expr] v = vec(); - auto e_1 = ast.expr_vec(v, ast.ann_none); + auto e_1; alt (e.node) { case (ast.expr_vec(?es_0, ?ann)) { @@ -1167,6 +1165,10 @@ fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e, case (ast.expr_put(_)) { e_1 = e.node; } case (ast.expr_be(_)) { e_1 = e.node; } case (ast.expr_check_expr(_)) { e_1 = e.node; } + case (_) { + fcx.ccx.sess.unimpl("type unification for expression variant"); + fail; + } } ret @fold.respan[ast.expr_](e.span, e_1); @@ -1331,7 +1333,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr { } auto rt_0 = next_ty_var(fcx.ccx); - auto t_0 = plain_ty(ty.ty_uint); // FIXME: typestate botch + auto t_0; alt (expr_ty(f_0).struct) { case (ty.ty_fn(?proto, _, _)) { t_0 = plain_ty(ty.ty_fn(proto, arg_tys_0, rt_0)); @@ -1777,9 +1779,9 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr { auto result = check_call_or_bind(fcx, f, args); // Pull the argument and return types out. - auto proto_1 = ast.proto_fn; // FIXME: typestate botch + auto proto_1; let vec[ty.arg] arg_tys_1 = vec(); - auto rt_1 = plain_ty(ty.ty_nil); // FIXME: typestate botch + auto rt_1; alt (expr_ty(result._0).struct) { case (ty.ty_fn(?proto, ?arg_tys, ?rt)) { proto_1 = proto;