diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-27 18:48:01 +0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-09-12 01:52:44 -0400 |
| commit | e323cf1264f390911dcc2efea71d46be1d631d92 (patch) | |
| tree | ffe4c716e299e94ef1ed797f32aed8451e8090c9 /src/print_zir.zig | |
| parent | c97d64b677eb891144fb356e1f4b9011c60cc0e2 (diff) | |
| download | zig-e323cf1264f390911dcc2efea71d46be1d631d92.tar.gz zig-e323cf1264f390911dcc2efea71d46be1d631d92.zip | |
stage2: change how defers are stored in Zir
Storing defers this way has the benefits that the defer doesn't get
analyzed multiple times in AstGen, it takes up less space, and it
makes Sema aware of defers allowing for 'unreachable else prong'
error on error sets in generic code.
The disadvantage is that it is a bit more complex and errdefers with
payloads now emit a placeholder instruction (but those are rare).
Sema.zig before:
Total ZIR bytes: 3.7794370651245117MiB
Instructions: 238996 (2.051319122314453MiB)
String Table Bytes: 89.2802734375KiB
Extra Data Items: 430144 (1.640869140625MiB)
Sema.zig after:
Total ZIR bytes: 3.3344192504882812MiB
Instructions: 211829 (1.8181428909301758MiB)
String Table Bytes: 89.2802734375KiB
Extra Data Items: 374611 (1.4290275573730469MiB)
Diffstat (limited to 'src/print_zir.zig')
| -rw-r--r-- | src/print_zir.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/print_zir.zig b/src/print_zir.zig index 976d012138..fb1d2960c4 100644 --- a/src/print_zir.zig +++ b/src/print_zir.zig @@ -446,6 +446,9 @@ const Writer = struct { .closure_get => try self.writeInstNode(stream, inst), + .@"defer" => try self.writeDefer(stream, inst), + .defer_err_code => try self.writeDeferErrCode(stream, inst), + .extended => try self.writeExtended(stream, inst), } } @@ -2364,6 +2367,26 @@ const Writer = struct { try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 }); } + fn writeDefer(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { + const inst_data = self.code.instructions.items(.data)[inst].@"defer"; + const body = self.code.extra[inst_data.index..][0..inst_data.len]; + try self.writeBracedBody(stream, body); + try stream.writeByte(')'); + } + + fn writeDeferErrCode(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { + const inst_data = self.code.instructions.items(.data)[inst].defer_err_code; + const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data; + + try self.writeInstRef(stream, Zir.indexToRef(extra.remapped_err_code)); + try stream.writeAll(" = "); + try self.writeInstRef(stream, inst_data.err_code); + try stream.writeAll(", "); + const body = self.code.extra[extra.index..][0..extra.len]; + try self.writeBracedBody(stream, body); + try stream.writeByte(')'); + } + fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void { var i: usize = @enumToInt(ref); |
