From dfb3231959bb340d260ddbec2b8eabfb5063c1bf Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 19 Oct 2021 20:14:10 -0700 Subject: stage2: implement switching on unions * AstGen: Move `refToIndex` and `indexToRef` to Zir * ZIR: the switch_block_*_* instruction tags are collapsed into one switch_block tag which uses 4 bits for flags, and reduces the scalar_cases_len field from 32 to 28 bits. This freed up more ZIR tags, 2 of which are now used for `switch_cond` and `switch_cond_ref` for producing the switch condition value. For example, for union values it returns the corresponding enum value. * switching with multiple cases and ranges is not yet supported because I want to change the ZIR encoding to store index pointers into the extra array rather than storing prong indexes. This will avoid O(N^2) iteration over prongs. * AstGen now adds a `switch_cond` on the operand and then passes the result of that to the `switch_block` instruction. * Sema: partially implement `switch_capture_*` instructions. * Sema: `unionToTag` notices if the enum type has only one possible value. --- test/stage2/cbe.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/stage2') diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig index 54ff136512..cfb9831e40 100644 --- a/test/stage2/cbe.zig +++ b/test/stage2/cbe.zig @@ -852,7 +852,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ _ = E.d; \\} , &.{ - ":3:10: error: enum 'tmp.E' has no member named 'd'", + ":3:11: error: enum 'tmp.E' has no member named 'd'", ":1:11: note: enum declared here", }); -- cgit v1.2.3