authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-26 13:58:04+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-27 18:05:08+03:00
logcccc4c38273eb3e937c3572952b5609b51010baa
treeeb202efed413f4d7be467c5e14a8ee44bda9b24d
parent07a7c2f7c86d72bd15e980d098aa2b46f236412f

AstGen: analyze inline switch cases


6 files changed, 63 insertions(+), 31 deletions(-)

src/AstGen.zig+10-4
...@@ -6312,6 +6312,9 @@ fn switchExpr(...@@ -6312,6 +6312,9 @@ fn switchExpr(
6312 },6312 },
6313 );6313 );
6314 }6314 }
6315 if (case.inline_token != null) {
6316 return astgen.failTok(case_src, "cannot inline '_' prong", .{});
6317 }
6315 special_node = case_node;6318 special_node = case_node;
6316 special_prong = .under;6319 special_prong = .under;
6317 underscore_src = case_src;6320 underscore_src = case_src;
...@@ -6365,8 +6368,8 @@ fn switchExpr(...@@ -6365,8 +6368,8 @@ fn switchExpr(
6365 var scalar_case_index: u32 = 0;6368 var scalar_case_index: u32 = 0;
6366 for (case_nodes) |case_node| {6369 for (case_nodes) |case_node| {
6367 const case = switch (node_tags[case_node]) {6370 const case = switch (node_tags[case_node]) {
6368 .switch_case_one => tree.switchCaseOne(case_node),6371 .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
6369 .switch_case => tree.switchCase(case_node),6372 .switch_case, .switch_case_inline => tree.switchCase(case_node),
6370 else => unreachable,6373 else => unreachable,
6371 };6374 };
63726375
...@@ -6506,7 +6509,8 @@ fn switchExpr(...@@ -6506,7 +6509,8 @@ fn switchExpr(
6506 const case_slice = case_scope.instructionsSlice();6509 const case_slice = case_scope.instructionsSlice();
6507 const body_len = astgen.countBodyLenAfterFixups(case_slice);6510 const body_len = astgen.countBodyLenAfterFixups(case_slice);
6508 try payloads.ensureUnusedCapacity(gpa, body_len);6511 try payloads.ensureUnusedCapacity(gpa, body_len);
6509 payloads.items[body_len_index] = body_len;6512 const inline_bit = @as(u32, @boolToInt(case.inline_token != null)) << 31;
6513 payloads.items[body_len_index] = body_len | inline_bit;
6510 appendBodyWithFixupsArrayList(astgen, payloads, case_slice);6514 appendBodyWithFixupsArrayList(astgen, payloads, case_slice);
6511 }6515 }
6512 }6516 }
...@@ -6553,7 +6557,7 @@ fn switchExpr(...@@ -6553,7 +6557,7 @@ fn switchExpr(
6553 end_index += 3 + items_len + 2 * ranges_len;6557 end_index += 3 + items_len + 2 * ranges_len;
6554 }6558 }
65556559
6556 const body_len = payloads.items[body_len_index];6560 const body_len = @truncate(u31, payloads.items[body_len_index]);
6557 end_index += body_len;6561 end_index += body_len;
65586562
6559 switch (strat.tag) {6563 switch (strat.tag) {
...@@ -9134,7 +9138,9 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {...@@ -9134,7 +9138,9 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
9134 .@"usingnamespace",9138 .@"usingnamespace",
9135 .test_decl,9139 .test_decl,
9136 .switch_case,9140 .switch_case,
9141 .switch_case_inline,
9137 .switch_case_one,9142 .switch_case_one,
9143 .switch_case_inline_one,
9138 .container_field_init,9144 .container_field_init,
9139 .container_field_align,9145 .container_field_align,
9140 .container_field,9146 .container_field,
src/Sema.zig+15-15
...@@ -9237,7 +9237,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9237,7 +9237,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9237 const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) {9237 const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) {
9238 .none => .{ .body = &.{}, .end = header_extra_index },9238 .none => .{ .body = &.{}, .end = header_extra_index },
9239 .under, .@"else" => blk: {9239 .under, .@"else" => blk: {
9240 const body_len = sema.code.extra[header_extra_index];9240 const body_len = @truncate(u31, sema.code.extra[header_extra_index]);
9241 const extra_body_start = header_extra_index + 1;9241 const extra_body_start = header_extra_index + 1;
9242 break :blk .{9242 break :blk .{
9243 .body = sema.code.extra[extra_body_start..][0..body_len],9243 .body = sema.code.extra[extra_body_start..][0..body_len],
...@@ -9307,7 +9307,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9307,7 +9307,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9307 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {9307 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
9308 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);9308 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
9309 extra_index += 1;9309 extra_index += 1;
9310 const body_len = sema.code.extra[extra_index];9310 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9311 extra_index += 1;9311 extra_index += 1;
9312 extra_index += body_len;9312 extra_index += body_len;
93139313
...@@ -9328,7 +9328,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9328,7 +9328,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9328 extra_index += 1;9328 extra_index += 1;
9329 const ranges_len = sema.code.extra[extra_index];9329 const ranges_len = sema.code.extra[extra_index];
9330 extra_index += 1;9330 extra_index += 1;
9331 const body_len = sema.code.extra[extra_index];9331 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9332 extra_index += 1;9332 extra_index += 1;
9333 const items = sema.code.refSlice(extra_index, items_len);9333 const items = sema.code.refSlice(extra_index, items_len);
9334 extra_index += items_len + body_len;9334 extra_index += items_len + body_len;
...@@ -9407,7 +9407,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9407,7 +9407,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9407 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {9407 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
9408 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);9408 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
9409 extra_index += 1;9409 extra_index += 1;
9410 const body_len = sema.code.extra[extra_index];9410 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9411 extra_index += 1;9411 extra_index += 1;
9412 extra_index += body_len;9412 extra_index += body_len;
94139413
...@@ -9427,7 +9427,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9427,7 +9427,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9427 extra_index += 1;9427 extra_index += 1;
9428 const ranges_len = sema.code.extra[extra_index];9428 const ranges_len = sema.code.extra[extra_index];
9429 extra_index += 1;9429 extra_index += 1;
9430 const body_len = sema.code.extra[extra_index];9430 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9431 extra_index += 1;9431 extra_index += 1;
9432 const items = sema.code.refSlice(extra_index, items_len);9432 const items = sema.code.refSlice(extra_index, items_len);
9433 extra_index += items_len + body_len;9433 extra_index += items_len + body_len;
...@@ -9549,7 +9549,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9549,7 +9549,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9549 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {9549 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
9550 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);9550 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
9551 extra_index += 1;9551 extra_index += 1;
9552 const body_len = sema.code.extra[extra_index];9552 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9553 extra_index += 1;9553 extra_index += 1;
9554 extra_index += body_len;9554 extra_index += body_len;
95559555
...@@ -9570,7 +9570,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9570,7 +9570,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9570 extra_index += 1;9570 extra_index += 1;
9571 const ranges_len = sema.code.extra[extra_index];9571 const ranges_len = sema.code.extra[extra_index];
9572 extra_index += 1;9572 extra_index += 1;
9573 const body_len = sema.code.extra[extra_index];9573 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9574 extra_index += 1;9574 extra_index += 1;
9575 const items = sema.code.refSlice(extra_index, items_len);9575 const items = sema.code.refSlice(extra_index, items_len);
9576 extra_index += items_len;9576 extra_index += items_len;
...@@ -9647,7 +9647,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9647,7 +9647,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9647 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {9647 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
9648 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);9648 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
9649 extra_index += 1;9649 extra_index += 1;
9650 const body_len = sema.code.extra[extra_index];9650 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9651 extra_index += 1;9651 extra_index += 1;
9652 extra_index += body_len;9652 extra_index += body_len;
96539653
...@@ -9668,7 +9668,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9668,7 +9668,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9668 extra_index += 1;9668 extra_index += 1;
9669 const ranges_len = sema.code.extra[extra_index];9669 const ranges_len = sema.code.extra[extra_index];
9670 extra_index += 1;9670 extra_index += 1;
9671 const body_len = sema.code.extra[extra_index];9671 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9672 extra_index += 1;9672 extra_index += 1;
9673 const items = sema.code.refSlice(extra_index, items_len);9673 const items = sema.code.refSlice(extra_index, items_len);
9674 extra_index += items_len + body_len;9674 extra_index += items_len + body_len;
...@@ -9732,7 +9732,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9732,7 +9732,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9732 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {9732 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
9733 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);9733 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
9734 extra_index += 1;9734 extra_index += 1;
9735 const body_len = sema.code.extra[extra_index];9735 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9736 extra_index += 1;9736 extra_index += 1;
9737 extra_index += body_len;9737 extra_index += body_len;
97389738
...@@ -9752,7 +9752,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9752,7 +9752,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9752 extra_index += 1;9752 extra_index += 1;
9753 const ranges_len = sema.code.extra[extra_index];9753 const ranges_len = sema.code.extra[extra_index];
9754 extra_index += 1;9754 extra_index += 1;
9755 const body_len = sema.code.extra[extra_index];9755 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9756 extra_index += 1;9756 extra_index += 1;
9757 const items = sema.code.refSlice(extra_index, items_len);9757 const items = sema.code.refSlice(extra_index, items_len);
9758 extra_index += items_len + body_len;9758 extra_index += items_len + body_len;
...@@ -9832,7 +9832,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9832,7 +9832,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9832 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {9832 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
9833 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);9833 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
9834 extra_index += 1;9834 extra_index += 1;
9835 const body_len = sema.code.extra[extra_index];9835 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9836 extra_index += 1;9836 extra_index += 1;
9837 const body = sema.code.extra[extra_index..][0..body_len];9837 const body = sema.code.extra[extra_index..][0..body_len];
9838 extra_index += body_len;9838 extra_index += body_len;
...@@ -9853,7 +9853,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9853,7 +9853,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9853 extra_index += 1;9853 extra_index += 1;
9854 const ranges_len = sema.code.extra[extra_index];9854 const ranges_len = sema.code.extra[extra_index];
9855 extra_index += 1;9855 extra_index += 1;
9856 const body_len = sema.code.extra[extra_index];9856 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9857 extra_index += 1;9857 extra_index += 1;
9858 const items = sema.code.refSlice(extra_index, items_len);9858 const items = sema.code.refSlice(extra_index, items_len);
9859 extra_index += items_len;9859 extra_index += items_len;
...@@ -9926,7 +9926,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9926,7 +9926,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9926 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {9926 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
9927 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);9927 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
9928 extra_index += 1;9928 extra_index += 1;
9929 const body_len = sema.code.extra[extra_index];9929 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9930 extra_index += 1;9930 extra_index += 1;
9931 const body = sema.code.extra[extra_index..][0..body_len];9931 const body = sema.code.extra[extra_index..][0..body_len];
9932 extra_index += body_len;9932 extra_index += body_len;
...@@ -9988,7 +9988,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9988,7 +9988,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9988 extra_index += 1;9988 extra_index += 1;
9989 const ranges_len = sema.code.extra[extra_index];9989 const ranges_len = sema.code.extra[extra_index];
9990 extra_index += 1;9990 extra_index += 1;
9991 const body_len = sema.code.extra[extra_index];9991 const body_len = @truncate(u31, sema.code.extra[extra_index]);
9992 extra_index += 1;9992 extra_index += 1;
9993 const items = sema.code.refSlice(extra_index, items_len);9993 const items = sema.code.refSlice(extra_index, items_len);
9994 extra_index += items_len;9994 extra_index += items_len;
src/Zir.zig+8-8
...@@ -2990,7 +2990,7 @@ pub const Inst = struct {...@@ -2990,7 +2990,7 @@ pub const Inst = struct {
2990 }2990 }
29912991
2992 if (self.bits.specialProng() != .none) {2992 if (self.bits.specialProng() != .none) {
2993 const body_len = zir.extra[extra_index];2993 const body_len = @truncate(u31, zir.extra[extra_index]);
2994 extra_index += 1;2994 extra_index += 1;
2995 const body = zir.extra[extra_index..][0..body_len];2995 const body = zir.extra[extra_index..][0..body_len];
2996 extra_index += body.len;2996 extra_index += body.len;
...@@ -3000,7 +3000,7 @@ pub const Inst = struct {...@@ -3000,7 +3000,7 @@ pub const Inst = struct {
3000 while (true) : (scalar_i += 1) {3000 while (true) : (scalar_i += 1) {
3001 const item = @intToEnum(Ref, zir.extra[extra_index]);3001 const item = @intToEnum(Ref, zir.extra[extra_index]);
3002 extra_index += 1;3002 extra_index += 1;
3003 const body_len = zir.extra[extra_index];3003 const body_len = @truncate(u31, zir.extra[extra_index]);
3004 extra_index += 1;3004 extra_index += 1;
3005 const body = zir.extra[extra_index..][0..body_len];3005 const body = zir.extra[extra_index..][0..body_len];
3006 extra_index += body.len;3006 extra_index += body.len;
...@@ -3029,7 +3029,7 @@ pub const Inst = struct {...@@ -3029,7 +3029,7 @@ pub const Inst = struct {
3029 var extra_index: usize = extra_end + 1;3029 var extra_index: usize = extra_end + 1;
30303030
3031 if (self.bits.specialProng() != .none) {3031 if (self.bits.specialProng() != .none) {
3032 const body_len = zir.extra[extra_index];3032 const body_len = @truncate(u31, zir.extra[extra_index]);
3033 extra_index += 1;3033 extra_index += 1;
3034 const body = zir.extra[extra_index..][0..body_len];3034 const body = zir.extra[extra_index..][0..body_len];
3035 extra_index += body.len;3035 extra_index += body.len;
...@@ -3038,7 +3038,7 @@ pub const Inst = struct {...@@ -3038,7 +3038,7 @@ pub const Inst = struct {
3038 var scalar_i: usize = 0;3038 var scalar_i: usize = 0;
3039 while (scalar_i < self.bits.scalar_cases_len) : (scalar_i += 1) {3039 while (scalar_i < self.bits.scalar_cases_len) : (scalar_i += 1) {
3040 extra_index += 1;3040 extra_index += 1;
3041 const body_len = zir.extra[extra_index];3041 const body_len = @truncate(u31, zir.extra[extra_index]);
3042 extra_index += 1;3042 extra_index += 1;
3043 extra_index += body_len;3043 extra_index += body_len;
3044 }3044 }
...@@ -3046,7 +3046,7 @@ pub const Inst = struct {...@@ -3046,7 +3046,7 @@ pub const Inst = struct {
3046 while (true) : (multi_i += 1) {3046 while (true) : (multi_i += 1) {
3047 const items_len = zir.extra[extra_index];3047 const items_len = zir.extra[extra_index];
3048 extra_index += 2;3048 extra_index += 2;
3049 const body_len = zir.extra[extra_index];3049 const body_len = @truncate(u31, zir.extra[extra_index]);
3050 extra_index += 1;3050 extra_index += 1;
3051 const items = zir.refSlice(extra_index, items_len);3051 const items = zir.refSlice(extra_index, items_len);
3052 extra_index += items_len;3052 extra_index += items_len;
...@@ -3858,7 +3858,7 @@ fn findDeclsSwitch(...@@ -3858,7 +3858,7 @@ fn findDeclsSwitch(
38583858
3859 const special_prong = extra.data.bits.specialProng();3859 const special_prong = extra.data.bits.specialProng();
3860 if (special_prong != .none) {3860 if (special_prong != .none) {
3861 const body_len = zir.extra[extra_index];3861 const body_len = @truncate(u31, zir.extra[extra_index]);
3862 extra_index += 1;3862 extra_index += 1;
3863 const body = zir.extra[extra_index..][0..body_len];3863 const body = zir.extra[extra_index..][0..body_len];
3864 extra_index += body.len;3864 extra_index += body.len;
...@@ -3871,7 +3871,7 @@ fn findDeclsSwitch(...@@ -3871,7 +3871,7 @@ fn findDeclsSwitch(
3871 var scalar_i: usize = 0;3871 var scalar_i: usize = 0;
3872 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3872 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3873 extra_index += 1;3873 extra_index += 1;
3874 const body_len = zir.extra[extra_index];3874 const body_len = @truncate(u31, zir.extra[extra_index]);
3875 extra_index += 1;3875 extra_index += 1;
3876 const body = zir.extra[extra_index..][0..body_len];3876 const body = zir.extra[extra_index..][0..body_len];
3877 extra_index += body_len;3877 extra_index += body_len;
...@@ -3886,7 +3886,7 @@ fn findDeclsSwitch(...@@ -3886,7 +3886,7 @@ fn findDeclsSwitch(
3886 extra_index += 1;3886 extra_index += 1;
3887 const ranges_len = zir.extra[extra_index];3887 const ranges_len = zir.extra[extra_index];
3888 extra_index += 1;3888 extra_index += 1;
3889 const body_len = zir.extra[extra_index];3889 const body_len = @truncate(u31, zir.extra[extra_index]);
3890 extra_index += 1;3890 extra_index += 1;
3891 const items = zir.refSlice(extra_index, items_len);3891 const items = zir.refSlice(extra_index, items_len);
3892 extra_index += items_len;3892 extra_index += items_len;
src/print_zir.zig+9-4
...@@ -1868,14 +1868,15 @@ const Writer = struct {...@@ -1868,14 +1868,15 @@ const Writer = struct {
1868 else => break :else_prong,1868 else => break :else_prong,
1869 };1869 };
18701870
1871 const body_len = self.code.extra[extra_index];1871 const body_len = @truncate(u31, self.code.extra[extra_index]);
1872 const inline_text = if (self.code.extra[extra_index] >> 31 != 0) "inline " else "";
1872 extra_index += 1;1873 extra_index += 1;
1873 const body = self.code.extra[extra_index..][0..body_len];1874 const body = self.code.extra[extra_index..][0..body_len];
1874 extra_index += body.len;1875 extra_index += body.len;
18751876
1876 try stream.writeAll(",\n");1877 try stream.writeAll(",\n");
1877 try stream.writeByteNTimes(' ', self.indent);1878 try stream.writeByteNTimes(' ', self.indent);
1878 try stream.print("{s} => ", .{prong_name});1879 try stream.print("{s}{s} => ", .{ inline_text, prong_name });
1879 try self.writeBracedBody(stream, body);1880 try self.writeBracedBody(stream, body);
1880 }1881 }
18811882
...@@ -1885,13 +1886,15 @@ const Writer = struct {...@@ -1885,13 +1886,15 @@ const Writer = struct {
1885 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {1886 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
1886 const item_ref = @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index]);1887 const item_ref = @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index]);
1887 extra_index += 1;1888 extra_index += 1;
1888 const body_len = self.code.extra[extra_index];1889 const body_len = @truncate(u31, self.code.extra[extra_index]);
1890 const is_inline = self.code.extra[extra_index] >> 31 != 0;
1889 extra_index += 1;1891 extra_index += 1;
1890 const body = self.code.extra[extra_index..][0..body_len];1892 const body = self.code.extra[extra_index..][0..body_len];
1891 extra_index += body_len;1893 extra_index += body_len;
18921894
1893 try stream.writeAll(",\n");1895 try stream.writeAll(",\n");
1894 try stream.writeByteNTimes(' ', self.indent);1896 try stream.writeByteNTimes(' ', self.indent);
1897 if (is_inline) try stream.writeAll("inline ");
1895 try self.writeInstRef(stream, item_ref);1898 try self.writeInstRef(stream, item_ref);
1896 try stream.writeAll(" => ");1899 try stream.writeAll(" => ");
1897 try self.writeBracedBody(stream, body);1900 try self.writeBracedBody(stream, body);
...@@ -1904,13 +1907,15 @@ const Writer = struct {...@@ -1904,13 +1907,15 @@ const Writer = struct {
1904 extra_index += 1;1907 extra_index += 1;
1905 const ranges_len = self.code.extra[extra_index];1908 const ranges_len = self.code.extra[extra_index];
1906 extra_index += 1;1909 extra_index += 1;
1907 const body_len = self.code.extra[extra_index];1910 const body_len = @truncate(u31, self.code.extra[extra_index]);
1911 const is_inline = self.code.extra[extra_index] >> 31 != 0;
1908 extra_index += 1;1912 extra_index += 1;
1909 const items = self.code.refSlice(extra_index, items_len);1913 const items = self.code.refSlice(extra_index, items_len);
1910 extra_index += items_len;1914 extra_index += items_len;
19111915
1912 try stream.writeAll(",\n");1916 try stream.writeAll(",\n");
1913 try stream.writeByteNTimes(' ', self.indent);1917 try stream.writeByteNTimes(' ', self.indent);
1918 if (is_inline) try stream.writeAll("inline ");
19141919
1915 for (items) |item_ref, item_i| {1920 for (items) |item_ref, item_i| {
1916 if (item_i != 0) try stream.writeAll(", ");1921 if (item_i != 0) try stream.writeAll(", ");
src/stage1/astgen.cpp+6
...@@ -6987,6 +6987,12 @@ static bool astgen_switch_prong_expr(Stage1AstGen *ag, Scope *scope, AstNode *sw...@@ -6987,6 +6987,12 @@ static bool astgen_switch_prong_expr(Stage1AstGen *ag, Scope *scope, AstNode *sw
6987 assert(switch_node->type == NodeTypeSwitchExpr);6987 assert(switch_node->type == NodeTypeSwitchExpr);
6988 assert(prong_node->type == NodeTypeSwitchProng);6988 assert(prong_node->type == NodeTypeSwitchProng);
69896989
6990 if (prong_node->data.switch_prong.is_inline) {
6991 exec_add_error_node(ag->codegen, ag->exec, prong_node,
6992 buf_sprintf("inline switch cases not supported by stage1"));
6993 return ag->codegen->invalid_inst_src;
6994 }
6995
6990 AstNode *expr_node = prong_node->data.switch_prong.expr;6996 AstNode *expr_node = prong_node->data.switch_prong.expr;
6991 AstNode *var_symbol_node = prong_node->data.switch_prong.var_symbol;6997 AstNode *var_symbol_node = prong_node->data.switch_prong.var_symbol;
6992 Scope *child_scope;6998 Scope *child_scope;
test/cases/compile_errors/inline_underscore_prong.zig created+15
...@@ -0,0 +1,15 @@
1const E = enum(u8) { a, b, c, d, _ };
2pub export fn entry() void {
3 var x: E = .a;
4 switch (x) {
5 inline .a, .b => |aorb| @compileLog(aorb),
6 .c, .d => |cord| @compileLog(cord),
7 inline _ => {},
8 }
9}
10
11// error
12// backend=stage2
13// target=native
14//
15// :7:16: error: cannot inline '_' prong