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(...@@ -4687,6 +4687,13 @@ fn structDeclInner(
4687 const container_field = tree.fullContainerField(member_node) orelse continue;4687 const container_field = tree.fullContainerField(member_node) orelse continue;
4688 if (container_field.ast.tuple_like) break true;4688 if (container_field.ast.tuple_like) break true;
4689 } else false;4689 } 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
4690 if (is_tuple) for (container_decl.ast.members) |member_node| {4697 if (is_tuple) for (container_decl.ast.members) |member_node| {
4691 switch (node_tags[member_node]) {4698 switch (node_tags[member_node]) {
4692 .container_field_init,4699 .container_field_init,
src/Sema.zig+6
...@@ -20391,6 +20391,12 @@ fn reifyStruct(...@@ -20391,6 +20391,12 @@ fn reifyStruct(
20391 const gpa = sema.gpa;20391 const gpa = sema.gpa;
20392 const ip = &mod.intern_pool;20392 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
20394 // Because these three things each reference each other, `undefined`20400 // Because these three things each reference each other, `undefined`
20395 // placeholders are used before being set after the struct type gains an20401 // placeholders are used before being set after the struct type gains an
20396 // InternPool index.20402 // InternPool index.
src/codegen/llvm/Builder.zig+2-2
...@@ -4164,8 +4164,8 @@ pub const WipFunction = struct {...@@ -4164,8 +4164,8 @@ pub const WipFunction = struct {
4164 @memcpy(extra.trail.nextMut(incoming_len, Block.Index, wip), blocks);4164 @memcpy(extra.trail.nextMut(incoming_len, Block.Index, wip), blocks);
4165 if (wip.builder.useLibLlvm()) {4165 if (wip.builder.useLibLlvm()) {
4166 const ExpectedContents = extern struct {4166 const ExpectedContents = extern struct {
4167 [expected_incoming_len]*llvm.Value,4167 values: [expected_incoming_len]*llvm.Value,
4168 [expected_incoming_len]*llvm.BasicBlock,4168 blocks: [expected_incoming_len]*llvm.BasicBlock,
4169 };4169 };
4170 var stack align(@alignOf(ExpectedContents)) =4170 var stack align(@alignOf(ExpectedContents)) =
4171 std.heap.stackFallback(@sizeOf(ExpectedContents), wip.builder.gpa);4171 std.heap.stackFallback(@sizeOf(ExpectedContents), wip.builder.gpa);
test/behavior/tuple_declarations.zig-21
...@@ -31,27 +31,6 @@ test "tuple declaration type info" {...@@ -31,27 +31,6 @@ test "tuple declaration type info" {
31 try expect(!info.fields[1].is_comptime);31 try expect(!info.fields[1].is_comptime);
32 try expect(info.fields[1].alignment == @alignOf([]const u8));32 try expect(info.fields[1].alignment == @alignOf([]const u8));
33 }33 }
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 }
55}34}
5635
57test "Tuple declaration usage" {36test "Tuple declaration usage" {
test/cases/compile_errors/reify_struct.zig+2-2
...@@ -51,7 +51,7 @@ comptime {...@@ -51,7 +51,7 @@ comptime {
51 .alignment = 4,51 .alignment = 4,
52 }},52 }},
53 .decls = &.{},53 .decls = &.{},
54 .is_tuple = true,54 .is_tuple = false,
55 } });55 } });
56}56}
57comptime {57comptime {
...@@ -65,7 +65,7 @@ comptime {...@@ -65,7 +65,7 @@ comptime {
65 .alignment = 4,65 .alignment = 4,
66 }},66 }},
67 .decls = &.{},67 .decls = &.{},
68 .is_tuple = true,68 .is_tuple = false,
69 } });69 } });
70}70}
7171