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)
This commit is contained in:
Veikka Tuominen
2022-08-27 18:48:01 +03:00
committed by Andrew Kelley
parent c97d64b677
commit e323cf1264
9 changed files with 261 additions and 148 deletions

View File

@@ -19,3 +19,4 @@ export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
// target=native
//
// :4:11: error: 'try' not allowed inside defer expression
// :4:5: note: defer expression here

View File

@@ -0,0 +1,25 @@
pub export fn complex() void {
var a: error{ Foo, Bar } = error.Foo;
switch (a) {
error.Foo => unreachable,
error.Bar => unreachable,
else => {
@compileError("<something complex here>");
},
}
}
pub export fn simple() void {
var a: error{ Foo, Bar } = error.Foo;
switch (a) {
error.Foo => unreachable,
error.Bar => unreachable,
else => |e| return e,
}
}
// error
// backend=llvm
// target=native
//
// :6:14: error: unreachable else prong; all cases already handled