| author | |
| committer | |
| log | a6f254ec3e106e6496a84c89375427e6adc9065f |
| tree | f892444e1f9a7af783b7fb0f4ebdbdef6be86d6c |
| parent | 3b8187072fc76966da9d9ab1a6a0ecd7aff4e090 |
7 files changed, 16 insertions(+), 14 deletions(-)
src/AstGen.zig+1-1| ... | ... | @@ -740,7 +740,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr |
| 740 | 740 | _ = try gz.addAsIndex(.{ |
| 741 | 741 | .tag = .@"unreachable", |
| 742 | 742 | .data = .{ .@"unreachable" = .{ |
| 743 | .safety = true, | |
| 743 | .force_comptime = gz.force_comptime, | |
| 744 | 744 | .src_node = gz.nodeIndexToRelative(node), |
| 745 | 745 | } }, |
| 746 | 746 | }); |
src/Sema.zig+5-4| ... | ... | @@ -12337,14 +12337,15 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi |
| 12337 | 12337 | } |
| 12338 | 12338 | |
| 12339 | 12339 | fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 12340 | const tracy = trace(@src()); | |
| 12341 | defer tracy.end(); | |
| 12342 | ||
| 12343 | 12340 | const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable"; |
| 12344 | 12341 | const src = inst_data.src(); |
| 12342 | ||
| 12343 | if (block.is_comptime or inst_data.force_comptime) { | |
| 12344 | return sema.fail(block, src, "reached unreachable code", .{}); | |
| 12345 | } | |
| 12345 | 12346 | try sema.requireRuntimeBlock(block, src); |
| 12346 | 12347 | // TODO Add compile error for @optimizeFor occurring too late in a scope. |
| 12347 | try block.addUnreachable(src, inst_data.safety); | |
| 12348 | try block.addUnreachable(src, true); | |
| 12348 | 12349 | return always_noreturn; |
| 12349 | 12350 | } |
| 12350 | 12351 |
src/Zir.zig+1-5| ... | ... | @@ -2502,11 +2502,7 @@ pub const Inst = struct { |
| 2502 | 2502 | /// Offset from Decl AST node index. |
| 2503 | 2503 | /// `Tag` determines which kind of AST node this points to. |
| 2504 | 2504 | src_node: i32, |
| 2505 | /// `false`: Not safety checked - the compiler will assume the | |
| 2506 | /// correctness of this instruction. | |
| 2507 | /// `true`: In safety-checked modes, this will generate a call | |
| 2508 | /// to the panic function unless it can be proven unreachable by the compiler. | |
| 2509 | safety: bool, | |
| 2505 | force_comptime: bool, | |
| 2510 | 2506 | |
| 2511 | 2507 | pub fn src(self: @This()) LazySrcLoc { |
| 2512 | 2508 | return .{ .node_offset = self.src_node }; |
src/print_zir.zig-2| ... | ... | @@ -2091,8 +2091,6 @@ const Writer = struct { |
| 2091 | 2091 | |
| 2092 | 2092 | fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| 2093 | 2093 | const inst_data = self.code.instructions.items(.data)[inst].@"unreachable"; |
| 2094 | const safety_str = if (inst_data.safety) "safe" else "unsafe"; | |
| 2095 | try stream.print("{s}) ", .{safety_str}); | |
| 2096 | 2094 | try self.writeSrc(stream, inst_data.src()); |
| 2097 | 2095 | } |
| 2098 | 2096 |
test/compile_errors/stage2/comptime_unreachable.zig created+7| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | pub export fn entry() void { | |
| 2 | comptime unreachable; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // | |
| 7 | // :2:14: error: reached unreachable code |
test/incremental/x86_64-linux/comptime_var.3.zig+1-1| ... | ... | @@ -7,4 +7,4 @@ pub fn main() void {} |
| 7 | 7 | |
| 8 | 8 | // error |
| 9 | 9 | // |
| 10 | // :4:17: error: unable to resolve comptime value | |
| 10 | // :4:17: error: reached unreachable code |
test/incremental/x86_64-macos/comptime_var.3.zig+1-1| ... | ... | @@ -7,4 +7,4 @@ pub fn main() void {} |
| 7 | 7 | |
| 8 | 8 | // error |
| 9 | 9 | // |
| 10 | // :4:17: error: unable to resolve comptime value | |
| 10 | // :4:17: error: reached unreachable code |