Skip to content

Commit ebc4df3

Browse files
brsongraydon
authored andcommitted
Implement local declarations with receive. Un-XFAIL decl-with-recv.rs.
1 parent 71f0584 commit ebc4df3

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

Makefile.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ TEST_XFAILS_STAGE0 := $(FLOAT_XFAILS) \
653653
clone-with-exterior.rs \
654654
comm.rs \
655655
constrained-type.rs \
656-
decl-with-recv.rs \
657656
destructor-ordering.rs \
658657
iter-ret.rs \
659658
lazychan.rs \

src/comp/front/parser.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,13 +1365,21 @@ impure fn parse_expr_inner(parser p) -> @ast.expr {
13651365
}
13661366

13671367
impure fn parse_initializer(parser p) -> option.t[ast.initializer] {
1368-
if (p.peek() == token.EQ) {
1369-
p.bump();
1370-
ret some(rec(op = ast.init_assign,
1371-
expr = parse_expr(p)));
1368+
alt (p.peek()) {
1369+
case (token.EQ) {
1370+
p.bump();
1371+
ret some(rec(op = ast.init_assign,
1372+
expr = parse_expr(p)));
1373+
}
1374+
case (token.LARROW) {
1375+
p.bump();
1376+
ret some(rec(op = ast.init_recv,
1377+
expr = parse_expr(p)));
1378+
}
1379+
case (_) {
1380+
ret none[ast.initializer];
1381+
}
13721382
}
1373-
1374-
ret none[ast.initializer];
13751383
}
13761384

13771385
impure fn parse_pat(parser p) -> @ast.pat {

src/comp/middle/fold.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
437437
alt (d.node) {
438438
case (ast.decl_local(?local)) {
439439
auto ty_ = none[@ast.ty];
440-
auto initopt = none[ast.initializer];
440+
auto init_ = none[ast.initializer];
441441
alt (local.ty) {
442442
case (some[@ast.ty](?t)) {
443443
ty_ = some[@ast.ty](fold_ty(env, fld, t));
@@ -446,13 +446,12 @@ fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
446446
}
447447
alt (local.init) {
448448
case (some[ast.initializer](?init)) {
449-
auto init_ = rec(expr = fold_expr(env, fld, init.expr)
450-
with init);
451-
initopt = some[ast.initializer](init_);
449+
auto e = fold_expr(env, fld, init.expr);
450+
init_ = some[ast.initializer](rec(expr = e with init));
452451
}
453452
case (_) { /* fall through */ }
454453
}
455-
let @ast.local local_ = @rec(ty=ty_, init=initopt with *local);
454+
let @ast.local local_ = @rec(ty=ty_, init=init_ with *local);
456455
ret fld.fold_decl_local(env_, d.span, local_);
457456
}
458457

src/comp/middle/trans.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4839,22 +4839,31 @@ fn trans_recv(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
48394839
auto data = trans_lval(bcx, lhs);
48404840
check (data.is_mem);
48414841
bcx = data.res.bcx;
4842+
auto unit_ty = node_ann_type(bcx.fcx.ccx, ann);
4843+
4844+
// FIXME: calculate copy init-ness in typestate.
4845+
ret recv_val(bcx, data.res.val, rhs, unit_ty, DROP_EXISTING);
4846+
}
4847+
4848+
fn recv_val(@block_ctxt cx, ValueRef lhs, @ast.expr rhs,
4849+
@ty.t unit_ty, copy_action action) -> result {
4850+
4851+
auto bcx = cx;
48424852
auto prt = trans_expr(bcx, rhs);
48434853
bcx = prt.bcx;
48444854

48454855
auto sub = trans_upcall(bcx, "upcall_recv",
4846-
vec(vp2i(bcx, data.res.val),
4856+
vec(vp2i(bcx, lhs),
48474857
vp2i(bcx, prt.val)));
48484858
bcx = sub.bcx;
48494859

4850-
auto unit_ty = node_ann_type(cx.fcx.ccx, ann);
4851-
auto data_load = load_scalar_or_boxed(bcx, data.res.val, unit_ty);
4852-
auto cp = copy_ty(bcx, DROP_EXISTING, data.res.val, data_load, unit_ty);
4860+
auto data_load = load_scalar_or_boxed(bcx, lhs, unit_ty);
4861+
auto cp = copy_ty(bcx, action, lhs, data_load, unit_ty);
48534862
bcx = cp.bcx;
48544863

48554864
// TODO: Any cleanup need to be done here?
48564865

4857-
ret res(bcx, data.res.val);
4866+
ret res(bcx, lhs);
48584867
}
48594868

48604869
fn init_local(@block_ctxt cx, @ast.local local) -> result {
@@ -4870,8 +4879,15 @@ fn init_local(@block_ctxt cx, @ast.local local) -> result {
48704879

48714880
alt (local.init) {
48724881
case (some[ast.initializer](?init)) {
4873-
auto sub = trans_expr(bcx, init.expr);
4874-
bcx = copy_ty(sub.bcx, INIT, llptr, sub.val, ty).bcx;
4882+
alt (init.op) {
4883+
case (ast.init_assign) {
4884+
auto sub = trans_expr(bcx, init.expr);
4885+
bcx = copy_ty(sub.bcx, INIT, llptr, sub.val, ty).bcx;
4886+
}
4887+
case (ast.init_recv) {
4888+
bcx = recv_val(bcx, llptr, init.expr, ty, INIT).bcx;
4889+
}
4890+
}
48754891
}
48764892
case (_) {
48774893
if (middle.ty.type_has_dynamic_size(ty)) {

src/comp/middle/typeck.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,16 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
24092409
case (some[ast.initializer](?init)) {
24102410
auto expr_0 = check_expr(fcx, init.expr);
24112411
auto lty = plain_ty(ty.ty_local(local.id));
2412-
auto expr_1 = demand_expr(fcx, lty, expr_0);
2412+
auto expr_1;
2413+
alt (init.op) {
2414+
case (ast.init_assign) {
2415+
expr_1 = demand_expr(fcx, lty, expr_0);
2416+
}
2417+
case (ast.init_recv) {
2418+
auto port_ty = plain_ty(ty.ty_port(lty));
2419+
expr_1 = demand_expr(fcx, port_ty, expr_0);
2420+
}
2421+
}
24132422
auto init_0 = rec(expr = expr_1 with init);
24142423
initopt = some[ast.initializer](init_0);
24152424
}

0 commit comments

Comments
 (0)