Implement local declarations with receive. Un-XFAIL decl-with-recv.rs.
This commit is contained in:
parent
71f058499a
commit
ebc4df3c7a
|
@ -653,7 +653,6 @@ TEST_XFAILS_STAGE0 := $(FLOAT_XFAILS) \
|
|||
clone-with-exterior.rs \
|
||||
comm.rs \
|
||||
constrained-type.rs \
|
||||
decl-with-recv.rs \
|
||||
destructor-ordering.rs \
|
||||
iter-ret.rs \
|
||||
lazychan.rs \
|
||||
|
|
|
@ -1365,13 +1365,21 @@ impure fn parse_expr_inner(parser p) -> @ast.expr {
|
|||
}
|
||||
|
||||
impure fn parse_initializer(parser p) -> option.t[ast.initializer] {
|
||||
if (p.peek() == token.EQ) {
|
||||
p.bump();
|
||||
ret some(rec(op = ast.init_assign,
|
||||
expr = parse_expr(p)));
|
||||
alt (p.peek()) {
|
||||
case (token.EQ) {
|
||||
p.bump();
|
||||
ret some(rec(op = ast.init_assign,
|
||||
expr = parse_expr(p)));
|
||||
}
|
||||
case (token.LARROW) {
|
||||
p.bump();
|
||||
ret some(rec(op = ast.init_recv,
|
||||
expr = parse_expr(p)));
|
||||
}
|
||||
case (_) {
|
||||
ret none[ast.initializer];
|
||||
}
|
||||
}
|
||||
|
||||
ret none[ast.initializer];
|
||||
}
|
||||
|
||||
impure fn parse_pat(parser p) -> @ast.pat {
|
||||
|
|
|
@ -437,7 +437,7 @@ fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
|
|||
alt (d.node) {
|
||||
case (ast.decl_local(?local)) {
|
||||
auto ty_ = none[@ast.ty];
|
||||
auto initopt = none[ast.initializer];
|
||||
auto init_ = none[ast.initializer];
|
||||
alt (local.ty) {
|
||||
case (some[@ast.ty](?t)) {
|
||||
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 {
|
|||
}
|
||||
alt (local.init) {
|
||||
case (some[ast.initializer](?init)) {
|
||||
auto init_ = rec(expr = fold_expr(env, fld, init.expr)
|
||||
with init);
|
||||
initopt = some[ast.initializer](init_);
|
||||
auto e = fold_expr(env, fld, init.expr);
|
||||
init_ = some[ast.initializer](rec(expr = e with init));
|
||||
}
|
||||
case (_) { /* fall through */ }
|
||||
}
|
||||
let @ast.local local_ = @rec(ty=ty_, init=initopt with *local);
|
||||
let @ast.local local_ = @rec(ty=ty_, init=init_ with *local);
|
||||
ret fld.fold_decl_local(env_, d.span, local_);
|
||||
}
|
||||
|
||||
|
|
|
@ -4839,22 +4839,31 @@ fn trans_recv(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
|
|||
auto data = trans_lval(bcx, lhs);
|
||||
check (data.is_mem);
|
||||
bcx = data.res.bcx;
|
||||
auto unit_ty = node_ann_type(bcx.fcx.ccx, ann);
|
||||
|
||||
// FIXME: calculate copy init-ness in typestate.
|
||||
ret recv_val(bcx, data.res.val, rhs, unit_ty, DROP_EXISTING);
|
||||
}
|
||||
|
||||
fn recv_val(@block_ctxt cx, ValueRef lhs, @ast.expr rhs,
|
||||
@ty.t unit_ty, copy_action action) -> result {
|
||||
|
||||
auto bcx = cx;
|
||||
auto prt = trans_expr(bcx, rhs);
|
||||
bcx = prt.bcx;
|
||||
|
||||
auto sub = trans_upcall(bcx, "upcall_recv",
|
||||
vec(vp2i(bcx, data.res.val),
|
||||
vec(vp2i(bcx, lhs),
|
||||
vp2i(bcx, prt.val)));
|
||||
bcx = sub.bcx;
|
||||
|
||||
auto unit_ty = node_ann_type(cx.fcx.ccx, ann);
|
||||
auto data_load = load_scalar_or_boxed(bcx, data.res.val, unit_ty);
|
||||
auto cp = copy_ty(bcx, DROP_EXISTING, data.res.val, data_load, unit_ty);
|
||||
auto data_load = load_scalar_or_boxed(bcx, lhs, unit_ty);
|
||||
auto cp = copy_ty(bcx, action, lhs, data_load, unit_ty);
|
||||
bcx = cp.bcx;
|
||||
|
||||
// TODO: Any cleanup need to be done here?
|
||||
|
||||
ret res(bcx, data.res.val);
|
||||
ret res(bcx, lhs);
|
||||
}
|
||||
|
||||
fn init_local(@block_ctxt cx, @ast.local local) -> result {
|
||||
|
@ -4870,8 +4879,15 @@ fn init_local(@block_ctxt cx, @ast.local local) -> result {
|
|||
|
||||
alt (local.init) {
|
||||
case (some[ast.initializer](?init)) {
|
||||
auto sub = trans_expr(bcx, init.expr);
|
||||
bcx = copy_ty(sub.bcx, INIT, llptr, sub.val, ty).bcx;
|
||||
alt (init.op) {
|
||||
case (ast.init_assign) {
|
||||
auto sub = trans_expr(bcx, init.expr);
|
||||
bcx = copy_ty(sub.bcx, INIT, llptr, sub.val, ty).bcx;
|
||||
}
|
||||
case (ast.init_recv) {
|
||||
bcx = recv_val(bcx, llptr, init.expr, ty, INIT).bcx;
|
||||
}
|
||||
}
|
||||
}
|
||||
case (_) {
|
||||
if (middle.ty.type_has_dynamic_size(ty)) {
|
||||
|
|
|
@ -2409,7 +2409,16 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
|
|||
case (some[ast.initializer](?init)) {
|
||||
auto expr_0 = check_expr(fcx, init.expr);
|
||||
auto lty = plain_ty(ty.ty_local(local.id));
|
||||
auto expr_1 = demand_expr(fcx, lty, expr_0);
|
||||
auto expr_1;
|
||||
alt (init.op) {
|
||||
case (ast.init_assign) {
|
||||
expr_1 = demand_expr(fcx, lty, expr_0);
|
||||
}
|
||||
case (ast.init_recv) {
|
||||
auto port_ty = plain_ty(ty.ty_port(lty));
|
||||
expr_1 = demand_expr(fcx, port_ty, expr_0);
|
||||
}
|
||||
}
|
||||
auto init_0 = rec(expr = expr_1 with init);
|
||||
initopt = some[ast.initializer](init_0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue