authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-25 10:46:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-25 21:45:33-07:00
log6cee98eb3074fcb99297f23f30e3a230a14e8db7
treedba0265f7fe90862ac7c1dee3287eff5a69865c1
parent4b7fa0fce90f05e13334bab5379d9e9ae8c5ae49

frontend: forbid packed and extern tuples


5 files changed, 17 insertions(+), 25 deletions(-)

src/AstGen.zig+7
......@@ -4687,6 +4687,13 @@ fn structDeclInner(
46874687 const container_field = tree.fullContainerField(member_node) orelse continue;
46884688 if (container_field.ast.tuple_like) break true;
46894689 } else false;
4690
4691 if (is_tuple) switch (layout) {
4692 .Auto => {},
4693 .Extern => return astgen.failNode(node, "extern tuples are not supported", .{}),
4694 .Packed => return astgen.failNode(node, "packed tuples are not supported", .{}),
4695 };
4696
46904697 if (is_tuple) for (container_decl.ast.members) |member_node| {
46914698 switch (node_tags[member_node]) {
46924699 .container_field_init,
src/Sema.zig+6
......@@ -20391,6 +20391,12 @@ fn reifyStruct(
2039120391 const gpa = sema.gpa;
2039220392 const ip = &mod.intern_pool;
2039320393
20394 if (is_tuple) switch (layout) {
20395 .Extern => return sema.fail(block, src, "extern tuples are not supported", .{}),
20396 .Packed => return sema.fail(block, src, "packed tuples are not supported", .{}),
20397 .Auto => {},
20398 };
20399
2039420400 // Because these three things each reference each other, `undefined`
2039520401 // placeholders are used before being set after the struct type gains an
2039620402 // InternPool index.
src/codegen/llvm/Builder.zig+2-2
......@@ -4164,8 +4164,8 @@ pub const WipFunction = struct {
41644164 @memcpy(extra.trail.nextMut(incoming_len, Block.Index, wip), blocks);
41654165 if (wip.builder.useLibLlvm()) {
41664166 const ExpectedContents = extern struct {
4167 [expected_incoming_len]*llvm.Value,
4168 [expected_incoming_len]*llvm.BasicBlock,
4167 values: [expected_incoming_len]*llvm.Value,
4168 blocks: [expected_incoming_len]*llvm.BasicBlock,
41694169 };
41704170 var stack align(@alignOf(ExpectedContents)) =
41714171 std.heap.stackFallback(@sizeOf(ExpectedContents), wip.builder.gpa);
test/behavior/tuple_declarations.zig-21
......@@ -31,27 +31,6 @@ test "tuple declaration type info" {
3131 try expect(!info.fields[1].is_comptime);
3232 try expect(info.fields[1].alignment == @alignOf([]const u8));
3333 }
34 {
35 const T = packed struct(u32) { u1, u30, u1 };
36 const info = @typeInfo(T).Struct;
37
38 try expect(std.mem.endsWith(u8, @typeName(T), "test.tuple declaration type info.T"));
39
40 try expect(info.layout == .Packed);
41 try expect(info.backing_integer == u32);
42 try expect(info.fields.len == 3);
43 try expect(info.decls.len == 0);
44 try expect(info.is_tuple);
45
46 try expectEqualStrings(info.fields[0].name, "0");
47 try expect(info.fields[0].type == u1);
48
49 try expectEqualStrings(info.fields[1].name, "1");
50 try expect(info.fields[1].type == u30);
51
52 try expectEqualStrings(info.fields[2].name, "2");
53 try expect(info.fields[2].type == u1);
54 }
5534}
5635
5736test "Tuple declaration usage" {
test/cases/compile_errors/reify_struct.zig+2-2
......@@ -51,7 +51,7 @@ comptime {
5151 .alignment = 4,
5252 }},
5353 .decls = &.{},
54 .is_tuple = true,
54 .is_tuple = false,
5555 } });
5656}
5757comptime {
......@@ -65,7 +65,7 @@ comptime {
6565 .alignment = 4,
6666 }},
6767 .decls = &.{},
68 .is_tuple = true,
68 .is_tuple = false,
6969 } });
7070}
7171