authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-19 20:26:57-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-19 20:26:57-07:00
logbfff8544e1049fc7aa3310883f619efb3f394948
tree62ba7c3594d2d7e091b26525811f53d8e3d51e34
parent8841a71aa675f76c0ff7658339872a5faa5e4d5b

AstGen: emit break_inline for corresponding inline loops

Prior to this commit there would be a `break` ZIR instruction to break from a `block_inline` which is a mismatch.

1 files changed, 10 insertions(+), 4 deletions(-)

src/AstGen.zig+10-4
......@@ -1729,8 +1729,10 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
17291729 continue;
17301730 };
17311731
1732 const break_tag: Zir.Inst.Tag = if (block_gz.is_inline) .break_inline else .@"break";
1733
17321734 if (rhs == 0) {
1733 _ = try parent_gz.addBreak(.@"break", block_inst, .void_value);
1735 _ = try parent_gz.addBreak(break_tag, block_inst, .void_value);
17341736 return Zir.Inst.Ref.unreachable_value;
17351737 }
17361738 block_gz.break_count += 1;
......@@ -1746,7 +1748,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
17461748
17471749 switch (block_gz.break_result_loc) {
17481750 .block_ptr => {
1749 const br = try parent_gz.addBreak(.@"break", block_inst, operand);
1751 const br = try parent_gz.addBreak(break_tag, block_inst, operand);
17501752 try block_gz.labeled_breaks.append(astgen.gpa, br);
17511753
17521754 // if list grew as much as rvalue_rl_count, then a break
......@@ -1765,10 +1767,10 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
17651767 .ptr => {
17661768 // In this case we don't have any mechanism to intercept it;
17671769 // we assume the result location is written, and we break with void.
1768 _ = try parent_gz.addBreak(.@"break", block_inst, .void_value);
1770 _ = try parent_gz.addBreak(break_tag, block_inst, .void_value);
17691771 },
17701772 else => {
1771 _ = try parent_gz.addBreak(.@"break", block_inst, operand);
1773 _ = try parent_gz.addBreak(break_tag, block_inst, operand);
17721774 },
17731775 }
17741776 return Zir.Inst.Ref.unreachable_value;
......@@ -5300,6 +5302,7 @@ fn whileExpr(
53005302 try parent_gz.instructions.append(astgen.gpa, loop_block);
53015303
53025304 var loop_scope = parent_gz.makeSubBlock(scope);
5305 loop_scope.is_inline = is_inline;
53035306 loop_scope.setBreakResultLoc(rl);
53045307 defer loop_scope.unstack();
53055308 defer loop_scope.labeled_breaks.deinit(astgen.gpa);
......@@ -5550,6 +5553,7 @@ fn forExpr(
55505553 try parent_gz.instructions.append(astgen.gpa, loop_block);
55515554
55525555 var loop_scope = parent_gz.makeSubBlock(scope);
5556 loop_scope.is_inline = is_inline;
55535557 loop_scope.setBreakResultLoc(rl);
55545558 defer loop_scope.unstack();
55555559 defer loop_scope.labeled_breaks.deinit(astgen.gpa);
......@@ -9492,6 +9496,8 @@ const GenZir = struct {
94929496 const base_tag: Scope.Tag = .gen_zir;
94939497 base: Scope = Scope{ .tag = base_tag },
94949498 force_comptime: bool,
9499 /// This is set to true for inline loops; false otherwise.
9500 is_inline: bool = false,
94959501 in_defer: bool,
94969502 c_import: bool = false,
94979503 /// How decls created in this scope should be named.