Skip to content

Commit ada0010

Browse files
committed
compiler: move unions into InternPool
There are a couple concepts here worth understanding: Key.UnionType - This type is available *before* resolving the union's fields. The enum tag type, number of fields, and field names, field types, and field alignments are not available with this. InternPool.UnionType - This one can be obtained from the above type with `InternPool.loadUnionType` which asserts that the union's enum tag type has been resolved. This one has all the information available. Additionally: * ZIR: Turn an unused bit into `any_aligned_fields` flag to help semantic analysis know whether a union has explicit alignment on any fields (usually not). * Sema: delete `resolveTypeRequiresComptime` which had the same type signature and near-duplicate logic to `typeRequiresComptime`. - Make opaque types not report comptime-only (this was inconsistent between the two implementations of this function). * Implement accepted proposal #12556 which is a breaking change.
1 parent 6a54639 commit ada0010

27 files changed

+1396
-1358
lines changed

lib/std/dwarf/call_frame.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,9 @@ pub const Instruction = union(Opcode) {
6969
register: u8,
7070
offset: u64,
7171
},
72-
offset_extended: struct {
73-
register: u8,
74-
offset: u64,
75-
},
7672
restore: struct {
7773
register: u8,
7874
},
79-
restore_extended: struct {
80-
register: u8,
81-
},
8275
nop: void,
8376
set_loc: struct {
8477
address: u64,
@@ -92,6 +85,13 @@ pub const Instruction = union(Opcode) {
9285
advance_loc4: struct {
9386
delta: u32,
9487
},
88+
offset_extended: struct {
89+
register: u8,
90+
offset: u64,
91+
},
92+
restore_extended: struct {
93+
register: u8,
94+
},
9595
undefined: struct {
9696
register: u8,
9797
},

lib/std/meta.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,9 @@ test "std.meta.FieldEnum" {
614614
const Tagged = union(enum) { a: u8, b: void, c: f32 };
615615
try testing.expectEqual(Tag(Tagged), FieldEnum(Tagged));
616616

617-
const Tag2 = enum { b, c, a };
617+
const Tag2 = enum { a, b, c };
618618
const Tagged2 = union(Tag2) { a: u8, b: void, c: f32 };
619-
try testing.expect(Tag(Tagged2) != FieldEnum(Tagged2));
619+
try testing.expect(Tag(Tagged2) == FieldEnum(Tagged2));
620620

621621
const Tag3 = enum(u8) { a, b, c = 7 };
622622
const Tagged3 = union(Tag3) { a: u8, b: void, c: f32 };

src/AstGen.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4696,6 +4696,7 @@ fn unionDeclInner(
46964696

46974697
const bits_per_field = 4;
46984698
const max_field_size = 5;
4699+
var any_aligned_fields = false;
46994700
var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, field_count, bits_per_field, max_field_size);
47004701
defer wip_members.deinit();
47014702

@@ -4733,6 +4734,7 @@ fn unionDeclInner(
47334734
if (have_align) {
47344735
const align_inst = try expr(&block_scope, &block_scope.base, .{ .rl = .{ .ty = .u32_type } }, member.ast.align_expr);
47354736
wip_members.appendToField(@intFromEnum(align_inst));
4737+
any_aligned_fields = true;
47364738
}
47374739
if (have_value) {
47384740
if (arg_inst == .none) {
@@ -4783,6 +4785,7 @@ fn unionDeclInner(
47834785
.fields_len = field_count,
47844786
.decls_len = decl_count,
47854787
.auto_enum_tag = auto_enum_tok != null,
4788+
.any_aligned_fields = any_aligned_fields,
47864789
});
47874790

47884791
wip_members.finishBits(bits_per_field);
@@ -11754,6 +11757,7 @@ const GenZir = struct {
1175411757
decls_len: u32,
1175511758
layout: std.builtin.Type.ContainerLayout,
1175611759
auto_enum_tag: bool,
11760+
any_aligned_fields: bool,
1175711761
}) !void {
1175811762
const astgen = gz.astgen;
1175911763
const gpa = astgen.gpa;
@@ -11790,6 +11794,7 @@ const GenZir = struct {
1179011794
.name_strategy = gz.anon_name_strategy,
1179111795
.layout = args.layout,
1179211796
.auto_enum_tag = args.auto_enum_tag,
11797+
.any_aligned_fields = args.any_aligned_fields,
1179311798
}),
1179411799
.operand = payload_index,
1179511800
} },

0 commit comments

Comments
 (0)