zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 6cee98eb3074fcb99297f23f30e3a230a14e8db7 (tree)
parent 4b7fa0fce90f05e13334bab5379d9e9ae8c5ae49
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Tue, 25 Jul 2023 10:46:49 -0700

frontend: forbid packed and extern tuples

Diffstat:
Msrc/AstGen.zig | 7+++++++
Msrc/Sema.zig | 6++++++
Msrc/codegen/llvm/Builder.zig | 4++--
Mtest/behavior/tuple_declarations.zig | 21---------------------
Mtest/cases/compile_errors/reify_struct.zig | 4++--
5 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/src/AstGen.zig b/src/AstGen.zig @@ -4687,6 +4687,13 @@ fn structDeclInner( const container_field = tree.fullContainerField(member_node) orelse continue; if (container_field.ast.tuple_like) break true; } else false; + + if (is_tuple) switch (layout) { + .Auto => {}, + .Extern => return astgen.failNode(node, "extern tuples are not supported", .{}), + .Packed => return astgen.failNode(node, "packed tuples are not supported", .{}), + }; + if (is_tuple) for (container_decl.ast.members) |member_node| { switch (node_tags[member_node]) { .container_field_init, diff --git a/src/Sema.zig b/src/Sema.zig @@ -20391,6 +20391,12 @@ fn reifyStruct( const gpa = sema.gpa; const ip = &mod.intern_pool; + if (is_tuple) switch (layout) { + .Extern => return sema.fail(block, src, "extern tuples are not supported", .{}), + .Packed => return sema.fail(block, src, "packed tuples are not supported", .{}), + .Auto => {}, + }; + // Because these three things each reference each other, `undefined` // placeholders are used before being set after the struct type gains an // InternPool index. diff --git a/src/codegen/llvm/Builder.zig b/src/codegen/llvm/Builder.zig @@ -4164,8 +4164,8 @@ pub const WipFunction = struct { @memcpy(extra.trail.nextMut(incoming_len, Block.Index, wip), blocks); if (wip.builder.useLibLlvm()) { const ExpectedContents = extern struct { - [expected_incoming_len]*llvm.Value, - [expected_incoming_len]*llvm.BasicBlock, + values: [expected_incoming_len]*llvm.Value, + blocks: [expected_incoming_len]*llvm.BasicBlock, }; var stack align(@alignOf(ExpectedContents)) = std.heap.stackFallback(@sizeOf(ExpectedContents), wip.builder.gpa); diff --git a/test/behavior/tuple_declarations.zig b/test/behavior/tuple_declarations.zig @@ -31,27 +31,6 @@ test "tuple declaration type info" { try expect(!info.fields[1].is_comptime); try expect(info.fields[1].alignment == @alignOf([]const u8)); } - { - const T = packed struct(u32) { u1, u30, u1 }; - const info = @typeInfo(T).Struct; - - try expect(std.mem.endsWith(u8, @typeName(T), "test.tuple declaration type info.T")); - - try expect(info.layout == .Packed); - try expect(info.backing_integer == u32); - try expect(info.fields.len == 3); - try expect(info.decls.len == 0); - try expect(info.is_tuple); - - try expectEqualStrings(info.fields[0].name, "0"); - try expect(info.fields[0].type == u1); - - try expectEqualStrings(info.fields[1].name, "1"); - try expect(info.fields[1].type == u30); - - try expectEqualStrings(info.fields[2].name, "2"); - try expect(info.fields[2].type == u1); - } } test "Tuple declaration usage" { diff --git a/test/cases/compile_errors/reify_struct.zig b/test/cases/compile_errors/reify_struct.zig @@ -51,7 +51,7 @@ comptime { .alignment = 4, }}, .decls = &.{}, - .is_tuple = true, + .is_tuple = false, } }); } comptime { @@ -65,7 +65,7 @@ comptime { .alignment = 4, }}, .decls = &.{}, - .is_tuple = true, + .is_tuple = false, } }); }