Revert "properly spill optional payload capture value"

This reverts commit 80ba21b83c.
master
Andrew Kelley 2020-02-08 15:07:12 -05:00
parent 80ba21b83c
commit d80db3546c
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
3 changed files with 3 additions and 30 deletions

View File

@ -6104,12 +6104,11 @@ static void mark_suspension_point(Scope *scope) {
continue;
}
case ScopeIdExpr: {
ScopeExpr *parent_expr_scope = reinterpret_cast<ScopeExpr *>(scope);
if (!looking_for_exprs) {
parent_expr_scope->need_spill = MemoizedBoolTrue;
// Now we're only looking for a block, to see if it's in a loop (see the case ScopeIdBlock)
continue;
}
ScopeExpr *parent_expr_scope = reinterpret_cast<ScopeExpr *>(scope);
if (child_expr_scope != nullptr) {
for (size_t i = 0; parent_expr_scope->children_ptr[i] != child_expr_scope; i += 1) {
assert(i < parent_expr_scope->children_len);

View File

@ -8874,9 +8874,7 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
AstNode *else_node = node->data.test_expr.else_node;
bool var_is_ptr = node->data.test_expr.var_is_ptr;
ScopeExpr *spill_scope = create_expr_scope(irb->codegen, expr_node, scope);
IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, &spill_scope->base, LValPtr, nullptr);
IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
if (maybe_val_ptr == irb->codegen->invalid_inst_src)
return maybe_val_ptr;
@ -8901,7 +8899,7 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
ir_set_cursor_at_end_and_append_block(irb, then_block);
Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, &spill_scope->base, is_comptime);
Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
Scope *var_scope;
if (var_symbol) {
bool is_shadowable = false;

View File

@ -1416,27 +1416,3 @@ test "async function call resolves target fn frame, runtime func" {
resume S.global_frame;
expect(S.global_int == 10);
}
test "properly spill optional payload capture value" {
const S = struct {
var global_frame: anyframe = undefined;
var global_int: usize = 2;
fn foo() void {
var opt: ?usize = 1234;
if (opt) |x| {
bar();
global_int += x;
}
}
fn bar() void {
global_frame = @frame();
suspend;
global_int += 1;
}
};
_ = async S.foo();
resume S.global_frame;
expect(S.global_int == 1237);
}