Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #251

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,19 @@ impure fn main(vec[str] args) {
do_warn = false;
} else if (_str.eq(arg, "-shared")) {
shared = true;
} else {
// FIXME: rust could use an elif construct.
if (_str.eq(arg, "-o")) {
if (i+1u < len) {
output_file = some(args.(i+1u));
i += 1u;
} else {
usage(sess, args.(0));
sess.err("-o requires an argument");
}
} else if (_str.eq(arg, "-o")) {
if (i+1u < len) {
output_file = some(args.(i+1u));
i += 1u;
} else {
if (_str.eq(arg, "-h")) {
usage(sess, args.(0));
} else {
usage(sess, args.(0));
sess.err("unrecognized option: " + arg);
}
usage(sess, args.(0));
sess.err("-o requires an argument");
}
} else if (_str.eq(arg, "-h")) {
usage(sess, args.(0));
} else {
usage(sess, args.(0));
sess.err("unrecognized option: " + arg);
}
} else {
alt (input_file) {
Expand All @@ -142,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;
}
Expand Down
17 changes: 2 additions & 15 deletions src/comp/front/extfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)]) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 8 additions & 10 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1541,38 +1541,36 @@ 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);
}
}
}
}
}
case (_) { /* fall through */ }
}
u += 1u;
}
ret rec(stmts=stmts, expr=expr, index=index);
}
Expand Down
10 changes: 5 additions & 5 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -3418,12 +3418,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;
Expand Down
42 changes: 13 additions & 29 deletions src/comp/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand Down
16 changes: 9 additions & 7 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 3 additions & 18 deletions src/lib/_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,10 @@ fn buf(str s) -> sbuf {
}

fn bytes(str s) -> vec[u8] {
/* FIXME (issue #58):
* Should be...
*
* fn ith(str s, uint i) -> u8 {
* ret s.(i);
* }
* ret _vec.init_fn[u8](bind ith(s, _), byte_len(s));
*
* but we do not correctly decrement refcount of s when
* the binding dies, so we have to do this manually.
*/
let uint n = _str.byte_len(s);
let vec[u8] v = _vec.alloc[u8](n);
let uint i = 0u;
while (i < n) {
v += vec(s.(i));
i += 1u;
fn ith(str s, uint i) -> u8 {
ret s.(i);
}
ret v;
ret _vec.init_fn[u8](bind ith(s, _), byte_len(s));
}

fn from_bytes(vec[u8] v) : is_utf8(v) -> str {
Expand Down
27 changes: 8 additions & 19 deletions src/lib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,11 @@ fn new_buf_reader(str path) -> buf_reader {
ret fd_buf_reader(fd, new_buf());
}

/**
* FIXME (issue #150): This should be
*
* type fileflag = tag(append(), create(), truncate());
*
* but then the tag value ctors are not found from crate-importers of std, so
* we manually simulate the enum below.
*/
type fileflag = uint;
fn append() -> uint { ret 0u; }
fn create() -> uint { ret 1u; }
fn truncate() -> uint { ret 2u; }
tag fileflag {
append;
create;
truncate;
}

fn new_buf_writer(str path, vec[fileflag] flags) -> buf_writer {

Expand Down Expand Up @@ -129,13 +122,9 @@ fn new_buf_writer(str path, vec[fileflag] flags) -> buf_writer {

for (fileflag f in flags) {
alt (f) {
// FIXME (issue #150): cf comment above defn of fileflag type
//case (append()) { fflags |= os.libc_constants.O_APPEND(); }
//case (create()) { fflags |= os.libc_constants.O_CREAT(); }
//case (truncate()) { fflags |= os.libc_constants.O_TRUNC(); }
case (0u) { fflags |= os.libc_constants.O_APPEND(); }
case (1u) { fflags |= os.libc_constants.O_CREAT(); }
case (2u) { fflags |= os.libc_constants.O_TRUNC(); }
case (append) { fflags |= os.libc_constants.O_APPEND(); }
case (create) { fflags |= os.libc_constants.O_CREAT(); }
case (truncate) { fflags |= os.libc_constants.O_TRUNC(); }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/lib-io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test_simple(str tmpfilebase) {
log frood;

{
let io.buf_writer out = io.new_buf_writer(tmpfile, vec(io.create()));
let io.buf_writer out = io.new_buf_writer(tmpfile, vec(io.create));
out.write(_str.bytes(frood));
}

Expand Down