aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-17 15:21:58 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-17 15:23:50 -0700
commitf4e051e35d8019c9a8d99ccae8f2e9d8f032629a (patch)
treecbeebf38b85f5aaaaff50ea7f9f875c02ac63667 /src/Module.zig
parent79628d48a4429818bddef2e86e2d7073d1955302 (diff)
downloadzig-f4e051e35d8019c9a8d99ccae8f2e9d8f032629a.tar.gz
zig-f4e051e35d8019c9a8d99ccae8f2e9d8f032629a.zip
Sema: fix comptime break semantics
Previously, breaking from an outer block at comptime would result in incorrect control flow. Now there is a mechanism, `error.ComptimeBreak`, similar to `error.ComptimeReturn`, to send comptime control flow further up the stack, to its matching block. This commit also introduces a new log scope. To use it, pass `--debug-log sema_zir` and you will see 1 line per ZIR instruction semantically analyzed. This is useful when you want to understand what comptime control flow is doing while debugging the compiler. One more `switch` test case is passing.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index a464ac83de..c66509f33a 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -2486,6 +2486,9 @@ pub const CompileError = error{
/// In a comptime scope, a return instruction was encountered. This error is only seen when
/// doing a comptime function call.
ComptimeReturn,
+ /// In a comptime scope, a break instruction was encountered. This error is only seen when
+ /// evaluating a comptime block.
+ ComptimeBreak,
};
pub fn deinit(mod: *Module) void {
@@ -4446,6 +4449,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
error.NeededSourceLocation => unreachable,
error.GenericPoison => unreachable,
error.ComptimeReturn => unreachable,
+ error.ComptimeBreak => unreachable,
else => |e| return e,
};
if (opt_opv) |opv| {
@@ -4478,6 +4482,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
+ error.ComptimeBreak => @panic("zig compiler bug: ComptimeBreak"),
else => |e| return e,
};