diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-12-29 16:24:07 +0000 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-12-31 09:55:03 +0000 |
| commit | 6026a5f217398b202b92a4ecc2e129691bbb3a69 (patch) | |
| tree | ee077302bdb0c28d620eb6233d23cd02360a5684 /src/Compilation.zig | |
| parent | 6d67658965bc298a697dc756a4e06bda144427de (diff) | |
| download | zig-6026a5f217398b202b92a4ecc2e129691bbb3a69.tar.gz zig-6026a5f217398b202b92a4ecc2e129691bbb3a69.zip | |
compiler: ensure result of `block_comptime` is comptime-known
To avoid this PR regressing error messages, most of the work here has
gone towards improving error notes for why code was comptime-evaluated.
ZIR `block_comptime` now stores a "comptime reason", the enum for which
is also used by Sema. There are two types in Sema:
* `ComptimeReason` represents the reason we started evaluating something
at comptime.
* `BlockComptimeReason` represents the reason a given block is evaluated
at comptime; it's either a `ComptimeReason` with an attached source
location, or it's because we're in a function which was called at
comptime (and that function's `Block` should be consulted for the
"parent" reason).
Every `Block` stores a `?BlockComptimeReason`. The old `is_comptime`
field is replaced with a trivial `isComptime()` method which returns
whether that reason is non-`null`.
Lastly, the handling for `block_comptime` has been simplified. It was
previously going through an unnecessary runtime-handling path; now, it
is a trivial sub block exited through a `break_inline` instruction.
Resolves: #22296
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 28c5efab6c..cee9513ac5 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -3435,6 +3435,7 @@ pub fn addModuleErrorMsg( var notes: std.ArrayHashMapUnmanaged(ErrorBundle.ErrorMessage, void, ErrorNoteHashContext, true) = .empty; defer notes.deinit(gpa); + var last_note_loc: ?std.zig.Loc = null; for (module_err_msg.notes) |module_note| { const note_src_loc = module_note.src_loc.upgrade(zcu); const source = try note_src_loc.file_scope.getSource(gpa); @@ -3443,6 +3444,9 @@ pub fn addModuleErrorMsg( const note_file_path = try note_src_loc.file_scope.fullPath(gpa); defer gpa.free(note_file_path); + const omit_source_line = loc.eql(err_loc) or (last_note_loc != null and loc.eql(last_note_loc.?)); + last_note_loc = loc; + const gop = try notes.getOrPutContext(gpa, .{ .msg = try eb.addString(module_note.msg), .src_loc = try eb.addSourceLocation(.{ @@ -3452,7 +3456,7 @@ pub fn addModuleErrorMsg( .span_end = span.end, .line = @intCast(loc.line), .column = @intCast(loc.column), - .source_line = if (err_loc.eql(loc)) 0 else try eb.addString(loc.source_line), + .source_line = if (omit_source_line) 0 else try eb.addString(loc.source_line), }), }, .{ .eb = eb }); if (gop.found_existing) { |
