| ... | ... | @@ -526,8 +526,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 526 | 526 | mod, |
| 527 | 527 | scope, |
| 528 | 528 | rl, |
| 529 | node, |
| 529 | 530 | node_datas[node].lhs, |
| 530 | | main_tokens[node], |
| 531 | 531 | .is_err_ptr, |
| 532 | 532 | .err_union_payload_unsafe_ptr, |
| 533 | 533 | .err_union_code_ptr, |
| ... | ... | @@ -538,8 +538,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 538 | 538 | mod, |
| 539 | 539 | scope, |
| 540 | 540 | rl, |
| 541 | node, |
| 541 | 542 | node_datas[node].lhs, |
| 542 | | main_tokens[node], |
| 543 | 543 | .is_err, |
| 544 | 544 | .err_union_payload_unsafe, |
| 545 | 545 | .err_union_code, |
| ... | ... | @@ -555,7 +555,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 555 | 555 | rl, |
| 556 | 556 | node, |
| 557 | 557 | node_datas[node].lhs, |
| 558 | | main_tokens[node], |
| 559 | 558 | .is_null_ptr, |
| 560 | 559 | .optional_payload_unsafe_ptr, |
| 561 | 560 | undefined, |
| ... | ... | @@ -568,7 +567,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 568 | 567 | rl, |
| 569 | 568 | node, |
| 570 | 569 | node_datas[node].lhs, |
| 571 | | main_tokens[node], |
| 572 | 570 | .is_null, |
| 573 | 571 | .optional_payload_unsafe, |
| 574 | 572 | undefined, |
| ... | ... | @@ -1637,7 +1635,6 @@ fn orelseCatchExpr( |
| 1637 | 1635 | rl: ResultLoc, |
| 1638 | 1636 | node: ast.Node.Index, |
| 1639 | 1637 | lhs: ast.Node.Index, |
| 1640 | | op_token: ast.TokenIndex, |
| 1641 | 1638 | cond_op: zir.Inst.Tag, |
| 1642 | 1639 | unwrap_op: zir.Inst.Tag, |
| 1643 | 1640 | unwrap_code_op: zir.Inst.Tag, |
| ... | ... | @@ -1645,6 +1642,8 @@ fn orelseCatchExpr( |
| 1645 | 1642 | payload_token: ?ast.TokenIndex, |
| 1646 | 1643 | ) InnerError!zir.Inst.Ref { |
| 1647 | 1644 | const parent_gz = scope.getGenZir(); |
| 1645 | const tree = parent_gz.tree(); |
| 1646 | |
| 1648 | 1647 | var block_scope: Scope.GenZir = .{ |
| 1649 | 1648 | .parent = scope, |
| 1650 | 1649 | .zir_code = parent_gz.zir_code, |
| ... | ... | @@ -1674,8 +1673,7 @@ fn orelseCatchExpr( |
| 1674 | 1673 | }, |
| 1675 | 1674 | }; |
| 1676 | 1675 | const operand = try expr(mod, &block_scope.base, operand_rl, lhs); |
| 1677 | | const cond = try block_scope.addUnTok(cond_op, operand, op_token); |
| 1678 | | |
| 1676 | const cond = try block_scope.addUnNode(cond_op, operand, node); |
| 1679 | 1677 | const condbr = try block_scope.addCondBr(node); |
| 1680 | 1678 | |
| 1681 | 1679 | const block = try parent_gz.addBlock(.block, node); |
| ... | ... | @@ -1690,25 +1688,25 @@ fn orelseCatchExpr( |
| 1690 | 1688 | }; |
| 1691 | 1689 | defer then_scope.instructions.deinit(mod.gpa); |
| 1692 | 1690 | |
| 1693 | | if (payload_token != null) @panic("TODO handle catch"); |
| 1694 | | // var err_val_scope: Scope.LocalVal = undefined; |
| 1695 | | // const then_sub_scope = blk: { |
| 1696 | | // const payload = payload_token orelse break :blk &then_scope.base; |
| 1697 | | // if (mem.eql(u8, tree.tokenSlice(payload), "_")) { |
| 1698 | | // return mod.failTok(&then_scope.base, payload, "discard of error capture; omit it instead", .{}); |
| 1699 | | // } |
| 1700 | | // const err_name = try mod.identifierTokenString(scope, payload); |
| 1701 | | // err_val_scope = .{ |
| 1702 | | // .parent = &then_scope.base, |
| 1703 | | // .gen_zir = &then_scope, |
| 1704 | | // .name = err_name, |
| 1705 | | // .inst = try addZIRUnOp(mod, &then_scope.base, src, unwrap_code_op, operand), |
| 1706 | | // }; |
| 1707 | | // break :blk &err_val_scope.base; |
| 1708 | | // }; |
| 1691 | var err_val_scope: Scope.LocalVal = undefined; |
| 1692 | const then_sub_scope = blk: { |
| 1693 | const payload = payload_token orelse break :blk &then_scope.base; |
| 1694 | if (mem.eql(u8, tree.tokenSlice(payload), "_")) { |
| 1695 | return mod.failTok(&then_scope.base, payload, "discard of error capture; omit it instead", .{}); |
| 1696 | } |
| 1697 | const err_name = try mod.identifierTokenString(scope, payload); |
| 1698 | err_val_scope = .{ |
| 1699 | .parent = &then_scope.base, |
| 1700 | .gen_zir = &then_scope, |
| 1701 | .name = err_name, |
| 1702 | .inst = try then_scope.addUnNode(unwrap_code_op, operand, node), |
| 1703 | .src = parent_gz.tokSrcLoc(payload), |
| 1704 | }; |
| 1705 | break :blk &err_val_scope.base; |
| 1706 | }; |
| 1709 | 1707 | |
| 1710 | 1708 | block_scope.break_count += 1; |
| 1711 | | const then_result = try expr(mod, &then_scope.base, block_scope.break_result_loc, rhs); |
| 1709 | const then_result = try expr(mod, then_sub_scope, block_scope.break_result_loc, rhs); |
| 1712 | 1710 | // We hold off on the break instructions as well as copying the then/else |
| 1713 | 1711 | // instructions into place until we know whether to keep store_to_block_ptr |
| 1714 | 1712 | // instructions or not. |
| ... | ... | @@ -3861,25 +3859,6 @@ fn rlStrategy(rl: ResultLoc, block_scope: *Scope.GenZir) ResultLoc.Strategy { |
| 3861 | 3859 | } |
| 3862 | 3860 | } |
| 3863 | 3861 | |
| 3864 | | /// If the input ResultLoc is ref, returns ResultLoc.ref. Otherwise: |
| 3865 | | /// Returns ResultLoc.ty, where the type is determined by the input |
| 3866 | | /// ResultLoc type, wrapped in an optional type. If the input ResultLoc |
| 3867 | | /// has no type, .none is returned. |
| 3868 | | fn makeOptionalTypeResultLoc(mod: *Module, scope: *Scope, src: usize, rl: ResultLoc) !ResultLoc { |
| 3869 | | switch (rl) { |
| 3870 | | .ref => return ResultLoc.ref, |
| 3871 | | .discard, .none, .block_ptr, .inferred_ptr, .bitcasted_ptr => return ResultLoc.none, |
| 3872 | | .ty => |elem_ty| { |
| 3873 | | const wrapped_ty = try addZIRUnOp(mod, scope, src, .optional_type, elem_ty); |
| 3874 | | return ResultLoc{ .ty = wrapped_ty }; |
| 3875 | | }, |
| 3876 | | .ptr => |ptr_ty| { |
| 3877 | | const wrapped_ty = try addZIRUnOp(mod, scope, src, .optional_type_from_ptr_elem, ptr_ty); |
| 3878 | | return ResultLoc{ .ty = wrapped_ty }; |
| 3879 | | }, |
| 3880 | | } |
| 3881 | | } |
| 3882 | | |
| 3883 | 3862 | fn setBlockResultLoc(block_scope: *Scope.GenZir, parent_rl: ResultLoc) void { |
| 3884 | 3863 | // Depending on whether the result location is a pointer or value, different |
| 3885 | 3864 | // ZIR needs to be generated. In the former case we rely on storing to the |