From d11bbde5f9c64ef58405604601d55f88bb5d5f3a Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 26 Oct 2024 23:13:58 +0100 Subject: compiler: remove anonymous struct types, unify all tuples This commit reworks how anonymous struct literals and tuples work. Previously, an untyped anonymous struct literal (e.g. `const x = .{ .a = 123 }`) was given an "anonymous struct type", which is a special kind of struct which coerces using structural equivalence. This mechanism was a holdover from before we used RLS / result types as the primary mechanism of type inference. This commit changes the language so that the type assigned here is a "normal" struct type. It uses a form of equivalence based on the AST node and the type's structure, much like a reified (`@Type`) type. Additionally, tuples have been simplified. The distinction between "simple" and "complex" tuple types is eliminated. All tuples, even those explicitly declared using `struct { ... }` syntax, use structural equivalence, and do not undergo staged type resolution. Tuples are very restricted: they cannot have non-`auto` layouts, cannot have aligned fields, and cannot have default values with the exception of `comptime` fields. Tuples currently do not have optimized layout, but this can be changed in the future. This change simplifies the language, and fixes some problematic coercions through pointers which led to unintuitive behavior. Resolves: #16865 --- src/Value.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Value.zig') diff --git a/src/Value.zig b/src/Value.zig index be2f7dc07f..dd27aaced2 100644 --- a/src/Value.zig +++ b/src/Value.zig @@ -3704,7 +3704,7 @@ pub const @"unreachable": Value = .{ .ip_index = .unreachable_value }; pub const generic_poison: Value = .{ .ip_index = .generic_poison }; pub const generic_poison_type: Value = .{ .ip_index = .generic_poison_type }; -pub const empty_struct: Value = .{ .ip_index = .empty_struct }; +pub const empty_tuple: Value = .{ .ip_index = .empty_tuple }; pub fn makeBool(x: bool) Value { return if (x) Value.true else Value.false; -- cgit v1.2.3