mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 03:03:40 +00:00
Teach the parser and typechecker to understand port[int](). Closes #588
This commit is contained in:
parent
1c6ae8cadf
commit
64596e6583
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
@ -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 }
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
44
src/test/run-pass/task-compare.rs
Normal file
44
src/test/run-pass/task-compare.rs
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user