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

Teach the parser and typechecker to understand port[int](). Closes #588 #589

Closed
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion src/comp/front/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ tag expr_ {
/* FIXME Would be nice if expr_check desugared
to expr_if_check. */
expr_if_check(@expr, block, option::t[@expr]);
expr_port;
expr_port(option::t[@ty]);
expr_chan(@expr);
expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids);
}
Expand Down
7 changes: 6 additions & 1 deletion src/comp/front/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,12 @@ fn noop_fold_expr(&expr_ e, ast_fold fld) -> expr_ {
case (expr_log(?lv, ?e)) { expr_log(lv, fld.fold_expr(e)) }
case (expr_assert(?e)) { expr_assert(fld.fold_expr(e)) }
case (expr_check(?e)) { expr_check(fld.fold_expr(e)) }
case (expr_port()) { e }
case (expr_port(?ot)) {
expr_port(alt(ot) {
case (option::some(?t)) { option::some(fld.fold_ty(t)) }
case (option::none) { option::none }
})
}
case (expr_chan(?e)) { expr_chan(fld.fold_expr(e)) }
case (expr_anon_obj(?ao, ?typms, ?odis)) {
expr_anon_obj(fold_anon_obj(ao), typms, odis)
Expand Down
10 changes: 8 additions & 2 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,16 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
ex = ast::expr_be(e);
} else { p.fatal("Non-call expression in tail call"); }
} else if (eat_word(p, "port")) {
auto ty = none;
if(token::LBRACKET == p.peek()) {
expect(p, token::LBRACKET);
ty = some(parse_ty(p));
expect(p, token::RBRACKET);
}
expect(p, token::LPAREN);
expect(p, token::RPAREN);
hi = p.get_hi_pos();
ex = ast::expr_port;
ex = ast::expr_port(ty);
} else if (eat_word(p, "chan")) {
expect(p, token::LPAREN);
auto e = parse_expr(p);
Expand Down Expand Up @@ -1592,7 +1598,7 @@ fn stmt_ends_with_semi(&ast::stmt stmt) -> bool {
case (ast::expr_log(_, _)) { true }
case (ast::expr_check(_)) { true }
case (ast::expr_if_check(_, _, _)) { false }
case (ast::expr_port) { true }
case (ast::expr_port(_)) { true }
case (ast::expr_chan(_)) { true }
case (ast::expr_anon_obj(_,_,_)) { false }
case (ast::expr_assert(_)) { true }
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5996,7 +5996,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
case (ast::expr_ret(?ex)) { ret trans_ret(cx, ex); }
case (ast::expr_put(?ex)) { ret trans_put(cx, ex); }
case (ast::expr_be(?ex)) { ret trans_be(cx, ex); }
case (ast::expr_port) { ret trans_port(cx, e.id); }
case (ast::expr_port(_)) { ret trans_port(cx, e.id); }
case (ast::expr_chan(?ex)) { ret trans_chan(cx, ex, e.id); }
case (ast::expr_send(?lhs, ?rhs)) {
ret trans_send(cx, lhs, rhs, e.id);
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/tstate/pre_post_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
}
case (expr_break) { clear_pp(expr_pp(fcx.ccx, e)); }
case (expr_cont) { clear_pp(expr_pp(fcx.ccx, e)); }
case (expr_port) { clear_pp(expr_pp(fcx.ccx, e)); }
case (expr_port(_)) { clear_pp(expr_pp(fcx.ccx, e)); }
case (expr_ext(_, _, _, ?expanded)) {
find_pre_post_expr(fcx, expanded);
copy_pre_post(fcx.ccx, e.id, expanded);
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/tstate/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
}
case (expr_break) { ret pure_exp(fcx.ccx, e.id, pres); }
case (expr_cont) { ret pure_exp(fcx.ccx, e.id, pres); }
case (expr_port) { ret pure_exp(fcx.ccx, e.id, pres); }
case (expr_port(_)) { ret pure_exp(fcx.ccx, e.id, pres); }
case (expr_self_method(_)) { ret pure_exp(fcx.ccx, e.id, pres); }
case (expr_anon_obj(?anon_obj, _, _)) {
alt (anon_obj.with_obj) {
Expand Down
10 changes: 9 additions & 1 deletion src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2075,8 +2075,16 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
}
}
}
case (ast::expr_port) {
case (ast::expr_port(?typ)) {
auto t = next_ty_var(fcx);
alt(typ) {
case (some(?_t)) {
demand::simple(fcx, expr.span,
ast_ty_to_ty_crate(fcx.ccx, _t),
t);
}
case (none) {}
}
auto pt = ty::mk_port(fcx.ccx.tcx, t);
write::ty_only_fixup(fcx, id, pt);
}
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ fn visit_expr[E](&@expr ex, &E e, &vt[E] v) {
case (expr_log(_, ?x)) { vt(v).visit_expr(x, e, v); }
case (expr_check(?x)) { vt(v).visit_expr(x, e, v); }
case (expr_assert(?x)) { vt(v).visit_expr(x, e, v); }
case (expr_port) { }
case (expr_port(_)) { }
case (expr_chan(?x)) { vt(v).visit_expr(x, e, v); }
case (expr_anon_obj(?anon_obj, _, _)) {
alt (anon_obj.fields) {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
case (ast::expr_log(_, ?x)) { walk_expr(v, x); }
case (ast::expr_check(?x)) { walk_expr(v, x); }
case (ast::expr_assert(?x)) { walk_expr(v, x); }
case (ast::expr_port) { }
case (ast::expr_port(_)) { }
case (ast::expr_chan(?x)) { walk_expr(v, x); }
case (ast::expr_anon_obj(?anon_obj, _, _)) {
// Fields
Expand Down
13 changes: 12 additions & 1 deletion src/comp/pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,18 @@ fn print_expr(&ps s, &@ast::expr expr) {
// FIXME: extension 'body'

}
case (ast::expr_port) { word(s.s, "port"); popen(s); pclose(s); }
case (ast::expr_port(?ot)) {
word(s.s, "port");
alt(ot) {
case(some(?t)) {
word(s.s, "[");
print_type(s, *t);
word(s.s, "]");
}
case(none) {}
}
popen(s); pclose(s);
}
case (ast::expr_chan(?expr)) {
word(s.s, "chan");
popen(s);
Expand Down
44 changes: 44 additions & 0 deletions src/test/run-pass/task-compare.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// xfail-stage0
// xfail-stage1
// xfail-stage2

/**
A test case for issue #577, which also exposes #588
*/

use std;
import std::task::join;

fn child() {}

fn main() {
// tasks
auto t1; auto t2;

t1 = spawn child();
t2 = spawn child();

assert(t1 == t1);
assert(t1 != t2);

// ports
auto p1; auto p2;

p1 = port[int]();
p2 = port[int]();

assert(p1 == p1);
assert(p1 != p2);

// channels
auto c1; auto c2;

c1 = chan(p1);
c2 = chan(p2);

assert(c1 == c1);
assert(c1 != c2);

join(t1);
join(t2);
}