Skip to content

Commit d39da6f

Browse files
brsongraydon
authored andcommitted
Remove typestate workarounds
1 parent b893bec commit d39da6f

File tree

6 files changed

+37
-68
lines changed

6 files changed

+37
-68
lines changed

src/comp/driver/rustc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ impure fn main(vec[str] args) {
137137
input_file = some[str](arg);
138138
}
139139
}
140-
// FIXME: dummy node to work around typestate mis-wiring bug.
141-
i = i;
142140
}
143141
i += 1u;
144142
}

src/comp/front/extfmt.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,7 @@ fn parse_count(str s, uint i, uint lim) -> tup(count, uint) {
244244
ret tup(count_implied, i);
245245
}
246246

247-
// FIXME: These inner functions are just to avoid a rustboot
248-
// "Unsatisfied precondition constraint" bug with alts nested in ifs
249-
fn parse_star_count(str s, uint i, uint lim) -> tup(count, uint) {
247+
if (s.(i) == ('*' as u8)) {
250248
auto param = parse_parameter(s, i + 1u, lim);
251249
auto j = param._1;
252250
alt (param._0) {
@@ -257,9 +255,7 @@ fn parse_count(str s, uint i, uint lim) -> tup(count, uint) {
257255
ret tup(count_is_param(n), j);
258256
}
259257
}
260-
}
261-
262-
fn parse_count_(str s, uint i, uint lim) -> tup(count, uint) {
258+
} else {
263259
auto num = peek_num(s, i, lim);
264260
alt (num) {
265261
case (none[tup(uint, uint)]) {
@@ -270,12 +266,6 @@ fn parse_count(str s, uint i, uint lim) -> tup(count, uint) {
270266
}
271267
}
272268
}
273-
274-
if (s.(i) == ('*' as u8)) {
275-
ret parse_star_count(s, i, lim);
276-
} else {
277-
ret parse_count_(s, i, lim);
278-
}
279269
}
280270

281271
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) {
318308
} else if (_str.eq(tstr, "t")) {
319309
t = ty_bits;
320310
} else {
321-
// FIXME: This is a hack to avoid 'unsatisfied precondition
322-
// constraint' on uninitialized variable t below
323-
t = ty_bool;
324311
log "unknown type in conversion";
325312
fail;
326313
}

src/comp/front/parser.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ impure fn parse_initializer(parser p) -> option.t[@ast.expr] {
13651365
impure fn parse_pat(parser p) -> @ast.pat {
13661366
auto lo = p.get_span();
13671367
auto hi = lo;
1368-
auto pat = ast.pat_wild(ast.ann_none); // FIXME: typestate bug
1368+
auto pat;
13691369

13701370
alt (p.peek()) {
13711371
case (token.UNDERSCORE) {
@@ -1541,38 +1541,36 @@ fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ {
15411541
auto index = new_str_hash[uint]();
15421542
auto u = 0u;
15431543
for (@ast.stmt s in stmts) {
1544-
// FIXME: typestate bug requires we do this up top, not
1545-
// down below loop. Sigh.
1546-
u += 1u;
15471544
alt (s.node) {
15481545
case (ast.stmt_decl(?d)) {
15491546
alt (d.node) {
15501547
case (ast.decl_local(?loc)) {
1551-
index.insert(loc.ident, u-1u);
1548+
index.insert(loc.ident, u);
15521549
}
15531550
case (ast.decl_item(?it)) {
15541551
alt (it.node) {
15551552
case (ast.item_fn(?i, _, _, _, _)) {
1556-
index.insert(i, u-1u);
1553+
index.insert(i, u);
15571554
}
15581555
case (ast.item_mod(?i, _, _)) {
1559-
index.insert(i, u-1u);
1556+
index.insert(i, u);
15601557
}
15611558
case (ast.item_ty(?i, _, _, _, _)) {
1562-
index.insert(i, u-1u);
1559+
index.insert(i, u);
15631560
}
15641561
case (ast.item_tag(?i, _, _, _)) {
1565-
index.insert(i, u-1u);
1562+
index.insert(i, u);
15661563
}
15671564
case (ast.item_obj(?i, _, _, _, _)) {
1568-
index.insert(i, u-1u);
1565+
index.insert(i, u);
15691566
}
15701567
}
15711568
}
15721569
}
15731570
}
15741571
case (_) { /* fall through */ }
15751572
}
1573+
u += 1u;
15761574
}
15771575
ret rec(stmts=stmts, expr=expr, index=index);
15781576
}

src/comp/middle/trans.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,8 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint {
929929
ret cx.tag_sizes.get(t);
930930
}
931931

932-
auto tid = tup(0, 0); // FIXME (#250): typestate botch
933-
let vec[@ty.t] subtys = vec(); // FIXME (#250): typestate botch
932+
auto tid;
933+
let vec[@ty.t] subtys;
934934
alt (t.struct) {
935935
case (ty.ty_tag(?tid_, ?subtys_)) {
936936
tid = tid_;
@@ -3419,12 +3419,12 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
34193419
}
34203420

34213421
// Figure out which tydescs we need to pass, if any.
3422-
// FIXME: typestate botch
3423-
let @ty.t outgoing_fty = ty.plain_ty(ty.ty_nil);
3424-
let vec[ValueRef] lltydescs = vec();
3422+
let @ty.t outgoing_fty;
3423+
let vec[ValueRef] lltydescs;
34253424
alt (f_res.generic) {
34263425
case (none[generic_info]) {
34273426
outgoing_fty = ty.expr_ty(f);
3427+
lltydescs = vec();
34283428
}
34293429
case (some[generic_info](?ginfo)) {
34303430
outgoing_fty = ginfo.item_type;

src/comp/middle/ty.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,32 +1018,6 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
10181018
ret ures_err(terr_meth_count, expected, actual);
10191019
}
10201020

1021-
// FIXME: work around buggy typestate logic for 'alt', sigh.
1022-
fn is_ok(&unify_result r) -> bool {
1023-
alt (r) {
1024-
case (ures_ok(?tfn)) {
1025-
ret true;
1026-
}
1027-
case (_) {}
1028-
}
1029-
ret false;
1030-
}
1031-
1032-
fn append_if_ok(&method e_meth,
1033-
&unify_result r, &mutable vec[method] result_meths) {
1034-
alt (r) {
1035-
case (ures_ok(?tfn)) {
1036-
alt (tfn.struct) {
1037-
case (ty_fn(?proto, ?ins, ?out)) {
1038-
result_meths += vec(rec(inputs = ins,
1039-
output = out
1040-
with e_meth));
1041-
}
1042-
}
1043-
}
1044-
}
1045-
}
1046-
10471021
while (i < expected_len) {
10481022
auto e_meth = expected_meths.(i);
10491023
auto a_meth = actual_meths.(i);
@@ -1056,10 +1030,20 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
10561030
expected, actual, handler,
10571031
e_meth.inputs, e_meth.output,
10581032
a_meth.inputs, a_meth.output);
1059-
if (!is_ok(r)) {
1060-
ret r;
1033+
alt (r) {
1034+
case (ures_ok(?tfn)) {
1035+
alt (tfn.struct) {
1036+
case (ty_fn(?proto, ?ins, ?out)) {
1037+
result_meths += vec(rec(inputs = ins,
1038+
output = out
1039+
with e_meth));
1040+
}
1041+
}
1042+
}
1043+
case (_) {
1044+
ret r;
1045+
}
10611046
}
1062-
append_if_ok(e_meth, r, result_meths);
10631047
i += 1u;
10641048
}
10651049
auto t = plain_ty(ty_obj(result_meths));

src/comp/middle/typeck.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ fn are_compatible(&@fn_ctxt fcx, @ty.t expected, @ty.t actual) -> bool {
890890
// TODO: enforce this via a predicate.
891891

892892
fn demand_pat(&@fn_ctxt fcx, @ty.t expected, @ast.pat pat) -> @ast.pat {
893-
auto p_1 = ast.pat_wild(ast.ann_none); // FIXME: typestate botch
893+
auto p_1;
894894

895895
alt (pat.node) {
896896
case (ast.pat_wild(?ann)) {
@@ -960,9 +960,7 @@ fn demand_expr(&@fn_ctxt fcx, @ty.t expected, @ast.expr e) -> @ast.expr {
960960

961961
fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e,
962962
autoderef_kind adk) -> @ast.expr {
963-
// FIXME: botch to work around typestate bug in rustboot
964-
let vec[@ast.expr] v = vec();
965-
auto e_1 = ast.expr_vec(v, ast.ann_none);
963+
auto e_1;
966964

967965
alt (e.node) {
968966
case (ast.expr_vec(?es_0, ?ann)) {
@@ -1167,6 +1165,10 @@ fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e,
11671165
case (ast.expr_put(_)) { e_1 = e.node; }
11681166
case (ast.expr_be(_)) { e_1 = e.node; }
11691167
case (ast.expr_check_expr(_)) { e_1 = e.node; }
1168+
case (_) {
1169+
fcx.ccx.sess.unimpl("type unification for expression variant");
1170+
fail;
1171+
}
11701172
}
11711173

11721174
ret @fold.respan[ast.expr_](e.span, e_1);
@@ -1331,7 +1333,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
13311333
}
13321334

13331335
auto rt_0 = next_ty_var(fcx.ccx);
1334-
auto t_0 = plain_ty(ty.ty_uint); // FIXME: typestate botch
1336+
auto t_0;
13351337
alt (expr_ty(f_0).struct) {
13361338
case (ty.ty_fn(?proto, _, _)) {
13371339
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 {
17771779
auto result = check_call_or_bind(fcx, f, args);
17781780

17791781
// Pull the argument and return types out.
1780-
auto proto_1 = ast.proto_fn; // FIXME: typestate botch
1782+
auto proto_1;
17811783
let vec[ty.arg] arg_tys_1 = vec();
1782-
auto rt_1 = plain_ty(ty.ty_nil); // FIXME: typestate botch
1784+
auto rt_1;
17831785
alt (expr_ty(result._0).struct) {
17841786
case (ty.ty_fn(?proto, ?arg_tys, ?rt)) {
17851787
proto_1 = proto;

0 commit comments

Comments
 (0)