aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-14 20:37:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:53 -0700
commit6a9a918fbe4adc23dd7d7573c6f1e499f4be074e (patch)
treef94c3d80a82b04a905d725689740af1d8c90dc97 /src/type.zig
parentd18881de1be811c1dff52590223b92c916c4b773 (diff)
downloadzig-6a9a918fbe4adc23dd7d7573c6f1e499f4be074e.tar.gz
zig-6a9a918fbe4adc23dd7d7573c6f1e499f4be074e.zip
stage2: encode one-possible-value tuple specially
Anonymous structs and anonymous tuples can be stored via a only_possible_value tag because their type encodings, by definition, will have every value specified, which can be used to populate the fields slice in `Key.Aggregate`. Also fix `isTupleOrAnonStruct`.
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/type.zig b/src/type.zig
index ee9e7c8e17..32fa64a1ac 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -3583,8 +3583,8 @@ pub const Type = struct {
// TODO: this is incorrect for structs with comptime fields, I think
// we should use a temporary allocator to construct an aggregate that
// is populated with the comptime values and then intern that value here.
- // This TODO is repeated for anon_struct_type below, as well as in
- // the redundant implementation of one-possible-value logic in Sema.zig.
+ // This TODO is repeated in the redundant implementation of
+ // one-possible-value logic in Sema.zig.
const empty = try mod.intern(.{ .aggregate = .{
.ty = ty.ip_index,
.fields = &.{},
@@ -3593,22 +3593,15 @@ pub const Type = struct {
},
.anon_struct_type => |tuple| {
- for (tuple.types, tuple.values) |field_ty, val| {
- if (val != .none) continue; // comptime field
- if ((try field_ty.toType().onePossibleValue(mod)) != null) continue;
- return null;
+ for (tuple.values) |val| {
+ if (val == .none) return null;
}
-
- // TODO: this is incorrect for structs with comptime fields, I think
- // we should use a temporary allocator to construct an aggregate that
- // is populated with the comptime values and then intern that value here.
- // This TODO is repeated for struct_type above, as well as in
- // the redundant implementation of one-possible-value logic in Sema.zig.
- const empty = try mod.intern(.{ .aggregate = .{
+ // In this case the struct has all comptime-known fields and
+ // therefore has one possible value.
+ return (try mod.intern(.{ .aggregate = .{
.ty = ty.ip_index,
- .fields = &.{},
- } });
- return empty.toValue();
+ .fields = tuple.values,
+ } })).toValue();
},
.union_type => |union_type| {
@@ -4477,7 +4470,7 @@ pub const Type = struct {
const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return false;
return struct_obj.is_tuple;
},
- .anon_struct_type => |anon_struct_type| anon_struct_type.names.len == 0,
+ .anon_struct_type => true,
else => false,
};
}