authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-08 15:07:12-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-08 15:07:12-05:00
logd80db3546cf49b8af434005de0e74509d07b4855
treeba1c1340830ca852ad74eb4399528b4d311f485a
parent80ba21b83cd13849c1d1d9cdebfa070b03f334d3
signature Commit is signed but in an unrecognized format.

Revert "properly spill optional payload capture value"

This reverts commit 80ba21b83cd13849c1d1d9cdebfa070b03f334d3.

3 files changed, 3 insertions(+), 30 deletions(-)

src/analyze.cpp+1-2
......@@ -6104,12 +6104,11 @@ static void mark_suspension_point(Scope *scope) {
61046104 continue;
61056105 }
61066106 case ScopeIdExpr: {
6107 ScopeExpr *parent_expr_scope = reinterpret_cast<ScopeExpr *>(scope);
61086107 if (!looking_for_exprs) {
6109 parent_expr_scope->need_spill = MemoizedBoolTrue;
61106108 // Now we're only looking for a block, to see if it's in a loop (see the case ScopeIdBlock)
61116109 continue;
61126110 }
6111 ScopeExpr *parent_expr_scope = reinterpret_cast<ScopeExpr *>(scope);
61136112 if (child_expr_scope != nullptr) {
61146113 for (size_t i = 0; parent_expr_scope->children_ptr[i] != child_expr_scope; i += 1) {
61156114 assert(i < parent_expr_scope->children_len);
src/ir.cpp+2-4
......@@ -8874,9 +8874,7 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
88748874 AstNode *else_node = node->data.test_expr.else_node;
88758875 bool var_is_ptr = node->data.test_expr.var_is_ptr;
88768876
8877 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, expr_node, scope);
8878
8879 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, &spill_scope->base, LValPtr, nullptr);
8877 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
88808878 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
88818879 return maybe_val_ptr;
88828880
......@@ -8901,7 +8899,7 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
89018899
89028900 ir_set_cursor_at_end_and_append_block(irb, then_block);
89038901
8904 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, &spill_scope->base, is_comptime);
8902 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
89058903 Scope *var_scope;
89068904 if (var_symbol) {
89078905 bool is_shadowable = false;
test/stage1/behavior/async_fn.zig-24
......@@ -1416,27 +1416,3 @@ test "async function call resolves target fn frame, runtime func" {
14161416 resume S.global_frame;
14171417 expect(S.global_int == 10);
14181418}
1419
1420test "properly spill optional payload capture value" {
1421 const S = struct {
1422 var global_frame: anyframe = undefined;
1423 var global_int: usize = 2;
1424
1425 fn foo() void {
1426 var opt: ?usize = 1234;
1427 if (opt) |x| {
1428 bar();
1429 global_int += x;
1430 }
1431 }
1432
1433 fn bar() void {
1434 global_frame = @frame();
1435 suspend;
1436 global_int += 1;
1437 }
1438 };
1439 _ = async S.foo();
1440 resume S.global_frame;
1441 expect(S.global_int == 1237);
1442}