authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-20 00:35:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-20 00:36:44-07:00
log0576086395774389a9f38d960f9ed5102a813bdb
tree43558a9b825a3312865ec76d2da7f6980d0b1a70
parent3ef34feaeb3a18926bead1981e5ce577382da38e

stage2: remove Value.Tag.abi_align_default

and make Decl alignment & linksection, and struct & union field alignment be scalar values, not Value values. YAGNI

5 files changed, 79 insertions(+), 110 deletions(-)

src/Module.zig+37-33
......@@ -349,12 +349,13 @@ pub const Decl = struct {
349349 /// Populated when `has_tv`.
350350 val: Value,
351351 /// Populated when `has_tv`.
352 align_val: Value,
352 /// Points to memory inside value_arena.
353 @"linksection": ?[*:0]const u8,
353354 /// Populated when `has_tv`.
354 linksection_val: Value,
355 @"align": u32,
355356 /// Populated when `has_tv`.
356357 @"addrspace": std.builtin.AddressSpace,
357 /// The memory for ty, val, align_val, linksection_val, and captures.
358 /// The memory for ty, val, align, linksection, and captures.
358359 /// If this is `null` then there is no memory management needed.
359360 value_arena: ?*std.heap.ArenaAllocator.State = null,
360361 /// The direct parent namespace of the Decl.
......@@ -423,7 +424,7 @@ pub const Decl = struct {
423424 /// to require re-analysis.
424425 outdated,
425426 },
426 /// Whether `typed_value`, `align_val`, `linksection_val` and `addrspace` are populated.
427 /// Whether `typed_value`, `align`, `linksection` and `addrspace` are populated.
427428 has_tv: bool,
428429 /// If `true` it means the `Decl` is the resource owner of the type/value associated
429430 /// with it. That means when `Decl` is destroyed, the cleanup code should additionally
......@@ -794,9 +795,9 @@ pub const Decl = struct {
794795
795796 pub fn getAlignment(decl: Decl, target: Target) u32 {
796797 assert(decl.has_tv);
797 if (decl.align_val.tag() != .null_value) {
798 if (decl.@"align" != 0) {
798799 // Explicit alignment.
799 return @intCast(u32, decl.align_val.toUnsignedInt());
800 return decl.@"align";
800801 } else {
801802 // Natural alignment.
802803 return decl.ty.abiAlignment(target);
......@@ -893,9 +894,10 @@ pub const Struct = struct {
893894 /// Uses `noreturn` to indicate `anytype`.
894895 /// undefined until `status` is `have_field_types` or `have_layout`.
895896 ty: Type,
896 abi_align: Value,
897897 /// Uses `unreachable_value` to indicate no default.
898898 default_val: Value,
899 /// Zero means to use the ABI alignment of the type.
900 abi_align: u32,
899901 /// undefined until `status` is `have_layout`.
900902 offset: u32,
901903 /// If true then `default_val` is the comptime field value.
......@@ -903,10 +905,10 @@ pub const Struct = struct {
903905
904906 /// Returns the field alignment, assuming the struct is not packed.
905907 pub fn normalAlignment(field: Field, target: Target) u32 {
906 if (field.abi_align.tag() == .abi_align_default) {
908 if (field.abi_align == 0) {
907909 return field.ty.abiAlignment(target);
908910 } else {
909 return @intCast(u32, field.abi_align.toUnsignedInt());
911 return field.abi_align;
910912 }
911913 }
912914 };
......@@ -1139,16 +1141,17 @@ pub const Union = struct {
11391141 pub const Field = struct {
11401142 /// undefined until `status` is `have_field_types` or `have_layout`.
11411143 ty: Type,
1142 abi_align: Value,
1144 /// 0 means the ABI alignment of the type.
1145 abi_align: u32,
11431146
11441147 /// Returns the field alignment, assuming the union is not packed.
11451148 /// Keep implementation in sync with `Sema.unionFieldAlignment`.
11461149 /// Prefer to call that function instead of this one during Sema.
11471150 pub fn normalAlignment(field: Field, target: Target) u32 {
1148 if (field.abi_align.tag() == .abi_align_default) {
1151 if (field.abi_align == 0) {
11491152 return field.ty.abiAlignment(target);
11501153 } else {
1151 return @intCast(u32, field.abi_align.toUnsignedInt());
1154 return field.abi_align;
11521155 }
11531156 }
11541157 };
......@@ -1224,7 +1227,7 @@ pub const Union = struct {
12241227 if (!field.ty.hasRuntimeBits()) continue;
12251228
12261229 const field_align = a: {
1227 if (field.abi_align.tag() == .abi_align_default) {
1230 if (field.abi_align == 0) {
12281231 break :a field.ty.abiAlignment(target);
12291232 } else {
12301233 break :a @intCast(u32, field.abi_align.toUnsignedInt());
......@@ -1246,10 +1249,10 @@ pub const Union = struct {
12461249 if (!field.ty.hasRuntimeBits()) continue;
12471250
12481251 const field_align = a: {
1249 if (field.abi_align.tag() == .abi_align_default) {
1252 if (field.abi_align == 0) {
12501253 break :a field.ty.abiAlignment(target);
12511254 } else {
1252 break :a @intCast(u32, field.abi_align.toUnsignedInt());
1255 break :a field.abi_align;
12531256 }
12541257 };
12551258 max_align = @maximum(max_align, field_align);
......@@ -1300,10 +1303,10 @@ pub const Union = struct {
13001303 if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue;
13011304
13021305 const field_align = a: {
1303 if (field.abi_align.tag() == .abi_align_default) {
1306 if (field.abi_align == 0) {
13041307 break :a field.ty.abiAlignment(target);
13051308 } else {
1306 break :a @intCast(u32, field.abi_align.toUnsignedInt());
1309 break :a field.abi_align;
13071310 }
13081311 };
13091312 const field_size = field.ty.abiSize(target);
......@@ -3863,15 +3866,16 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
38633866 try wip_captures.finalize();
38643867 const src: LazySrcLoc = .{ .node_offset = 0 };
38653868 const decl_tv = try sema.resolveInstValue(&block_scope, src, result_ref);
3866 const align_val = blk: {
3869 const decl_align: u16 = blk: {
38673870 const align_ref = decl.zirAlignRef();
3868 if (align_ref == .none) break :blk Value.initTag(.null_value);
3869 break :blk (try sema.resolveInstConst(&block_scope, src, align_ref)).val;
3871 if (align_ref == .none) break :blk 0;
3872 break :blk try sema.resolveAlign(&block_scope, src, align_ref);
38703873 };
3871 const linksection_val = blk: {
3874 const decl_linksection: ?[*:0]const u8 = blk: {
38723875 const linksection_ref = decl.zirLinksectionRef();
3873 if (linksection_ref == .none) break :blk Value.initTag(.null_value);
3874 break :blk (try sema.resolveInstConst(&block_scope, src, linksection_ref)).val;
3876 if (linksection_ref == .none) break :blk null;
3877 const bytes = try sema.resolveConstString(&block_scope, src, linksection_ref);
3878 break :blk (try decl_arena_allocator.dupeZ(u8, bytes)).ptr;
38753879 };
38763880 const address_space = blk: {
38773881 const addrspace_ctx: Sema.AddressSpaceContext = switch (decl_tv.val.tag()) {
......@@ -3911,8 +3915,8 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
39113915
39123916 decl.ty = ty_ty;
39133917 decl.val = try Value.Tag.ty.create(decl_arena_allocator, ty);
3914 decl.align_val = Value.initTag(.null_value);
3915 decl.linksection_val = Value.initTag(.null_value);
3918 decl.@"align" = 0;
3919 decl.@"linksection" = null;
39163920 decl.has_tv = true;
39173921 decl.owns_tv = false;
39183922 decl_arena_state.* = decl_arena.state;
......@@ -3942,8 +3946,8 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
39423946
39433947 decl.ty = try decl_tv.ty.copy(decl_arena_allocator);
39443948 decl.val = try decl_tv.val.copy(decl_arena_allocator);
3945 decl.align_val = try align_val.copy(decl_arena_allocator);
3946 decl.linksection_val = try linksection_val.copy(decl_arena_allocator);
3949 decl.@"align" = decl_align;
3950 decl.@"linksection" = decl_linksection;
39473951 decl.@"addrspace" = address_space;
39483952 decl.has_tv = true;
39493953 decl.owns_tv = owns_tv;
......@@ -4022,8 +4026,8 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
40224026
40234027 decl.ty = try decl_tv.ty.copy(decl_arena_allocator);
40244028 decl.val = try decl_tv.val.copy(decl_arena_allocator);
4025 decl.align_val = try align_val.copy(decl_arena_allocator);
4026 decl.linksection_val = try linksection_val.copy(decl_arena_allocator);
4029 decl.@"align" = decl_align;
4030 decl.@"linksection" = decl_linksection;
40274031 decl.@"addrspace" = address_space;
40284032 decl.has_tv = true;
40294033 decl_arena_state.* = decl_arena.state;
......@@ -4889,8 +4893,8 @@ pub fn allocateNewDecl(
48894893 .owns_tv = false,
48904894 .ty = undefined,
48914895 .val = undefined,
4892 .align_val = undefined,
4893 .linksection_val = undefined,
4896 .@"align" = undefined,
4897 .@"linksection" = undefined,
48944898 .@"addrspace" = .generic,
48954899 .analysis = .unreferenced,
48964900 .deletion_flag = false,
......@@ -4995,8 +4999,8 @@ pub fn createAnonymousDeclFromDeclNamed(
49954999 new_decl.src_line = src_decl.src_line;
49965000 new_decl.ty = typed_value.ty;
49975001 new_decl.val = typed_value.val;
4998 new_decl.align_val = Value.@"null";
4999 new_decl.linksection_val = Value.@"null";
5002 new_decl.@"align" = 0;
5003 new_decl.@"linksection" = null;
50005004 new_decl.has_tv = true;
50015005 new_decl.analysis = .complete;
50025006 new_decl.generation = mod.generation;
src/Sema.zig+21-36
......@@ -486,19 +486,17 @@ pub const Block = struct {
486486 wad.* = undefined;
487487 }
488488
489 /// `alignment` value of 0 means to use ABI alignment.
489490 pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value, alignment: u32) !*Decl {
490491 const sema = wad.block.sema;
491492 // Do this ahead of time because `createAnonymousDecl` depends on calling
492493 // `type.hasRuntimeBits()`.
493494 _ = try sema.typeHasRuntimeBits(wad.block, wad.src, ty);
494 const align_val = if (alignment != 0) blk: {
495 break :blk try Value.Tag.int_u64.create(wad.arena(), alignment);
496 } else Value.@"null";
497495 const new_decl = try sema.mod.createAnonymousDecl(wad.block, .{
498496 .ty = ty,
499497 .val = val,
500498 });
501 new_decl.align_val = align_val;
499 new_decl.@"align" = alignment;
502500 errdefer sema.mod.abortAnonDecl(new_decl);
503501 try new_decl.finalizeNewArena(&wad.new_decl_arena);
504502 wad.finished = true;
......@@ -1281,7 +1279,7 @@ fn resolveConstBool(
12811279 return val.toBool();
12821280}
12831281
1284fn resolveConstString(
1282pub fn resolveConstString(
12851283 sema: *Sema,
12861284 block: *Block,
12871285 src: LazySrcLoc,
......@@ -1539,7 +1537,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: *Block, err_msg: *Module.ErrorMsg)
15391537 return error.AnalysisFail;
15401538}
15411539
1542fn resolveAlign(
1540pub fn resolveAlign(
15431541 sema: *Sema,
15441542 block: *Block,
15451543 src: LazySrcLoc,
......@@ -13061,7 +13059,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
1306113059 var buffer: Value.ToTypeBuffer = undefined;
1306213060 gop.value_ptr.* = .{
1306313061 .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator),
13064 .abi_align = try alignment_val.copy(new_decl_arena_allocator),
13062 .abi_align = @intCast(u32, alignment_val.toUnsignedInt()),
1306513063 };
1306613064 }
1306713065 }
......@@ -13230,7 +13228,7 @@ fn reifyStruct(
1323013228 var buffer: Value.ToTypeBuffer = undefined;
1323113229 gop.value_ptr.* = .{
1323213230 .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator),
13233 .abi_align = try alignment_val.copy(new_decl_arena_allocator),
13231 .abi_align = @intCast(u32, alignment_val.toUnsignedInt()),
1323413232 .default_val = default_val,
1323513233 .is_comptime = is_comptime_val.toBool(),
1323613234 .offset = undefined,
......@@ -14949,9 +14947,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1494914947 };
1495014948
1495114949 if (struct_obj.layout == .Packed) {
14952 // TODO handle packed structs
14953 } else if (field.abi_align.tag() != .abi_align_default) {
14954 ptr_ty_data.@"align" = @intCast(u32, field.abi_align.toUnsignedInt());
14950 return sema.fail(block, src, "TODO handle packed structs with @fieldParentPtr", .{});
14951 } else {
14952 ptr_ty_data.@"align" = field.abi_align;
1495514953 }
1495614954
1495714955 const target = sema.mod.getTarget();
......@@ -15552,8 +15550,8 @@ fn zirBuiltinExtern(
1555215550 new_decl.src_line = sema.owner_decl.src_line;
1555315551 new_decl.ty = try ty.copy(new_decl_arena_allocator);
1555415552 new_decl.val = try Value.Tag.variable.create(new_decl_arena_allocator, new_var);
15555 new_decl.align_val = Value.@"null";
15556 new_decl.linksection_val = Value.@"null";
15553 new_decl.@"align" = 0;
15554 new_decl.@"linksection" = null;
1555715555 new_decl.has_tv = true;
1555815556 new_decl.analysis = .complete;
1555915557 new_decl.generation = sema.mod.generation;
......@@ -16543,9 +16541,7 @@ fn structFieldPtrByIndex(
1654316541 ptr_ty_data.bit_offset += struct_ptr_ty_info.bit_offset;
1654416542 }
1654516543 } else {
16546 if (field.abi_align.tag() != .abi_align_default) {
16547 ptr_ty_data.@"align" = @intCast(u32, field.abi_align.toUnsignedInt());
16548 }
16544 ptr_ty_data.@"align" = field.abi_align;
1654916545 }
1655016546
1655116547 const target = sema.mod.getTarget();
......@@ -19168,15 +19164,11 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref {
1916819164 const decl_tv = try decl.typedValue();
1916919165 if (decl_tv.val.castTag(.variable)) |payload| {
1917019166 const variable = payload.data;
19171 const alignment: u32 = if (decl.align_val.tag() == .null_value)
19172 0
19173 else
19174 @intCast(u32, decl.align_val.toUnsignedInt());
1917519167 const ty = try Type.ptr(sema.arena, target, .{
1917619168 .pointee_type = decl_tv.ty,
1917719169 .mutable = variable.is_mutable,
1917819170 .@"addrspace" = decl.@"addrspace",
19179 .@"align" = alignment,
19171 .@"align" = decl.@"align",
1918019172 });
1918119173 return sema.addConstant(ty, try Value.Tag.decl_ref.create(sema.arena, decl));
1918219174 }
......@@ -20848,7 +20840,7 @@ fn semaStructFields(
2084820840 assert(!gop.found_existing);
2084920841 gop.value_ptr.* = .{
2085020842 .ty = try field_ty.copy(decl_arena_allocator),
20851 .abi_align = Value.initTag(.abi_align_default),
20843 .abi_align = 0,
2085220844 .default_val = Value.initTag(.unreachable_value),
2085320845 .is_comptime = is_comptime,
2085420846 .offset = undefined,
......@@ -20860,8 +20852,7 @@ fn semaStructFields(
2086020852 // TODO: if we need to report an error here, use a source location
2086120853 // that points to this alignment expression rather than the struct.
2086220854 // But only resolve the source location if we need to emit a compile error.
20863 const abi_align_val = (try sema.resolveInstConst(&block_scope, src, align_ref)).val;
20864 gop.value_ptr.abi_align = try abi_align_val.copy(decl_arena_allocator);
20855 gop.value_ptr.abi_align = try sema.resolveAlign(&block_scope, src, align_ref);
2086520856 }
2086620857 if (has_default) {
2086720858 const default_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
......@@ -21088,17 +21079,16 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
2108821079 assert(!gop.found_existing);
2108921080 gop.value_ptr.* = .{
2109021081 .ty = try field_ty.copy(decl_arena_allocator),
21091 .abi_align = Value.initTag(.abi_align_default),
21082 .abi_align = 0,
2109221083 };
2109321084
2109421085 if (align_ref != .none) {
2109521086 // TODO: if we need to report an error here, use a source location
2109621087 // that points to this alignment expression rather than the struct.
2109721088 // But only resolve the source location if we need to emit a compile error.
21098 const abi_align_val = (try sema.resolveInstConst(&block_scope, src, align_ref)).val;
21099 gop.value_ptr.abi_align = try abi_align_val.copy(decl_arena_allocator);
21089 gop.value_ptr.abi_align = try sema.resolveAlign(&block_scope, src, align_ref);
2110021090 } else {
21101 gop.value_ptr.abi_align = Value.initTag(.abi_align_default);
21091 gop.value_ptr.abi_align = 0;
2110221092 }
2110321093 }
2110421094}
......@@ -21638,11 +21628,6 @@ fn analyzeComptimeAlloc(
2163821628 var anon_decl = try block.startAnonDecl(src);
2163921629 defer anon_decl.deinit();
2164021630
21641 const align_val = if (alignment == 0)
21642 Value.@"null"
21643 else
21644 try Value.Tag.int_u64.create(anon_decl.arena(), alignment);
21645
2164621631 const decl = try anon_decl.finish(
2164721632 try var_type.copy(anon_decl.arena()),
2164821633 // There will be stores before the first load, but they may be to sub-elements or
......@@ -21651,7 +21636,7 @@ fn analyzeComptimeAlloc(
2165121636 Value.undef,
2165221637 alignment,
2165321638 );
21654 decl.align_val = align_val;
21639 decl.@"align" = alignment;
2165521640
2165621641 try sema.mod.declareDeclDependency(sema.owner_decl, decl);
2165721642 return sema.addConstant(ptr_type, try Value.Tag.decl_ref_mut.create(sema.arena, .{
......@@ -22066,10 +22051,10 @@ fn unionFieldAlignment(
2206622051 src: LazySrcLoc,
2206722052 field: Module.Union.Field,
2206822053) !u32 {
22069 if (field.abi_align.tag() == .abi_align_default) {
22054 if (field.abi_align == 0) {
2207022055 return sema.typeAbiAlignment(block, src, field.ty);
2207122056 } else {
22072 return @intCast(u32, field.abi_align.toUnsignedInt());
22057 return field.abi_align;
2207322058 }
2207422059}
2207522060
src/arch/x86_64/abi.zig+4-6
......@@ -179,9 +179,8 @@ pub fn classifySystemV(ty: Type, target: Target) [8]Class {
179179 var byte_i: usize = 0; // out of 8
180180 const fields = ty.structFields();
181181 for (fields.values()) |field| {
182 if (field.abi_align.tag() != .abi_align_default) {
183 const field_alignment = field.abi_align.toUnsignedInt();
184 if (field_alignment < field.ty.abiAlignment(target)) {
182 if (field.abi_align != 0) {
183 if (field.abi_align < field.ty.abiAlignment(target)) {
185184 return memory_class;
186185 }
187186 }
......@@ -288,9 +287,8 @@ pub fn classifySystemV(ty: Type, target: Target) [8]Class {
288287
289288 const fields = ty.unionFields();
290289 for (fields.values()) |field| {
291 if (field.abi_align.tag() != .abi_align_default) {
292 const field_alignment = field.abi_align.toUnsignedInt();
293 if (field_alignment < field.ty.abiAlignment(target)) {
290 if (field.abi_align != 0) {
291 if (field.abi_align < field.ty.abiAlignment(target)) {
294292 return memory_class;
295293 }
296294 }
src/codegen/c.zig+17-31
......@@ -245,7 +245,7 @@ pub const Function = struct {
245245 ty,
246246 decl_c_value,
247247 .Const,
248 Value.initTag(.abi_align_default),
248 0,
249249 );
250250 try writer.writeAll(" = ");
251251 try f.object.dg.renderValue(writer, ty, val);
......@@ -267,10 +267,10 @@ pub const Function = struct {
267267 }
268268
269269 fn allocLocal(f: *Function, ty: Type, mutability: Mutability) !CValue {
270 return f.allocAlignedLocal(ty, mutability, Value.initTag(.abi_align_default));
270 return f.allocAlignedLocal(ty, mutability, 0);
271271 }
272272
273 fn allocAlignedLocal(f: *Function, ty: Type, mutability: Mutability, alignment: Value) !CValue {
273 fn allocAlignedLocal(f: *Function, ty: Type, mutability: Mutability, alignment: u32) !CValue {
274274 const local_value = f.allocLocalValue();
275275 try f.object.dg.renderTypeAndName(
276276 f.object.writer(),
......@@ -854,8 +854,7 @@ pub const DeclGen = struct {
854854 try w.writeAll(", ");
855855 }
856856 const name = CValue{ .arg = index };
857 const alignment = Value.initTag(.abi_align_default);
858 try dg.renderTypeAndName(w, dg.decl.ty.fnParamType(index), name, .Mut, alignment);
857 try dg.renderTypeAndName(w, dg.decl.ty.fnParamType(index), name, .Mut, 0);
859858 params_written += 1;
860859 }
861860
......@@ -928,8 +927,7 @@ pub const DeclGen = struct {
928927 var ptr_type_buf: Type.SlicePtrFieldTypeBuffer = undefined;
929928 const ptr_type = t.slicePtrFieldType(&ptr_type_buf);
930929 const ptr_name = CValue{ .bytes = "ptr" };
931 const ptr_alignment = Value.initTag(.abi_align_default);
932 try dg.renderTypeAndName(bw, ptr_type, ptr_name, .Mut, ptr_alignment);
930 try dg.renderTypeAndName(bw, ptr_type, ptr_name, .Mut, 0);
933931
934932 const ptr_sentinel = ptr_type.ptrInfo().data.sentinel;
935933 const child_type = t.childType();
......@@ -1018,7 +1016,7 @@ pub const DeclGen = struct {
10181016 try name.writer().print("field_{d}", .{i});
10191017
10201018 try buffer.append(' ');
1021 try dg.renderTypeAndName(writer, field_ty, .{ .bytes = name.items }, .Mut, Value.initTag(.abi_align_default));
1019 try dg.renderTypeAndName(writer, field_ty, .{ .bytes = name.items }, .Mut, 0);
10221020 try buffer.appendSlice(";\n");
10231021 }
10241022 }
......@@ -1056,7 +1054,7 @@ pub const DeclGen = struct {
10561054 const name: CValue = .{ .bytes = "tag" };
10571055 try buffer.appendSlice("struct {\n ");
10581056 if (layout.tag_size != 0) {
1059 try dg.renderTypeAndName(buffer.writer(), tag_ty, name, .Mut, Value.initTag(.abi_align_default));
1057 try dg.renderTypeAndName(buffer.writer(), tag_ty, name, .Mut, 0);
10601058 try buffer.appendSlice(";\n");
10611059 }
10621060 }
......@@ -1106,8 +1104,7 @@ pub const DeclGen = struct {
11061104
11071105 try bw.writeAll("typedef struct { ");
11081106 const payload_name = CValue{ .bytes = "payload" };
1109 const alignment = Value.initTag(.abi_align_default);
1110 try dg.renderTypeAndName(bw, child_type, payload_name, .Mut, alignment);
1107 try dg.renderTypeAndName(bw, child_type, payload_name, .Mut, 0);
11111108 try bw.writeAll("; uint16_t error; } ");
11121109 const name_index = buffer.items.len;
11131110 if (err_set_type.castTag(.error_set_inferred)) |inf_err_set_payload| {
......@@ -1172,8 +1169,7 @@ pub const DeclGen = struct {
11721169
11731170 try bw.writeAll("typedef struct { ");
11741171 const payload_name = CValue{ .bytes = "payload" };
1175 const alignment = Value.initTag(.abi_align_default);
1176 try dg.renderTypeAndName(bw, child_type, payload_name, .Mut, alignment);
1172 try dg.renderTypeAndName(bw, child_type, payload_name, .Mut, 0);
11771173 try bw.writeAll("; bool is_null; } ");
11781174 const name_index = buffer.items.len;
11791175 try bw.print("zig_Q_{s};\n", .{typeToCIdentifier(child_type)});
......@@ -1375,12 +1371,9 @@ pub const DeclGen = struct {
13751371 dg: *DeclGen,
13761372 w: anytype,
13771373 ty: Type,
1378 //mutability: Mutability,
1379 //alignment: Value,
13801374 ) error{ OutOfMemory, AnalysisFail }!void {
13811375 const name = CValue{ .bytes = "" };
1382 const alignment = Value.initTag(.abi_align_default);
1383 return renderTypeAndName(dg, w, ty, name, .Mut, alignment);
1376 return renderTypeAndName(dg, w, ty, name, .Mut, 0);
13841377 }
13851378
13861379 /// Renders a type and name in field declaration/definition format.
......@@ -1398,7 +1391,7 @@ pub const DeclGen = struct {
13981391 ty: Type,
13991392 name: CValue,
14001393 mutability: Mutability,
1401 alignment: Value,
1394 alignment: u32,
14021395 ) error{ OutOfMemory, AnalysisFail }!void {
14031396 var suffix = std.ArrayList(u8).init(dg.gpa);
14041397 defer suffix.deinit();
......@@ -1413,8 +1406,8 @@ pub const DeclGen = struct {
14131406 render_ty = render_ty.elemType();
14141407 }
14151408
1416 if (alignment.tag() != .abi_align_default and alignment.tag() != .null_value)
1417 try w.print("ZIG_ALIGN({}) ", .{alignment.toUnsignedInt()});
1409 if (alignment != 0)
1410 try w.print("ZIG_ALIGN({}) ", .{alignment});
14181411 try dg.renderType(w, render_ty);
14191412
14201413 const const_prefix = switch (mutability) {
......@@ -1570,7 +1563,7 @@ pub fn genDecl(o: *Object) !void {
15701563
15711564 const decl_c_value: CValue = if (is_global) .{ .bytes = mem.span(o.dg.decl.name) } else .{ .decl = o.dg.decl };
15721565
1573 try o.dg.renderTypeAndName(fwd_decl_writer, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.align_val);
1566 try o.dg.renderTypeAndName(fwd_decl_writer, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.@"align");
15741567 try fwd_decl_writer.writeAll(";\n");
15751568
15761569 if (variable.init.isUndefDeep()) {
......@@ -1579,7 +1572,7 @@ pub fn genDecl(o: *Object) !void {
15791572
15801573 try o.indent_writer.insertNewline();
15811574 const w = o.writer();
1582 try o.dg.renderTypeAndName(w, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.align_val);
1575 try o.dg.renderTypeAndName(w, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.@"align");
15831576 try w.writeAll(" = ");
15841577 if (variable.init.tag() != .unreachable_value) {
15851578 try o.dg.renderValue(w, tv.ty, variable.init);
......@@ -1594,7 +1587,7 @@ pub fn genDecl(o: *Object) !void {
15941587 // https://github.com/ziglang/zig/issues/7582
15951588
15961589 const decl_c_value: CValue = .{ .decl = o.dg.decl };
1597 try o.dg.renderTypeAndName(writer, tv.ty, decl_c_value, .Mut, o.dg.decl.align_val);
1590 try o.dg.renderTypeAndName(writer, tv.ty, decl_c_value, .Mut, o.dg.decl.@"align");
15981591
15991592 try writer.writeAll(" = ");
16001593 try o.dg.renderValue(writer, tv.ty, tv.val);
......@@ -1993,15 +1986,8 @@ fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue {
19931986 }
19941987
19951988 const target = f.object.dg.module.getTarget();
1996 const alignment = inst_ty.ptrAlignment(target);
1997 var payload = Value.Payload.U64{
1998 .base = .{ .tag = .int_u64 },
1999 .data = alignment,
2000 };
2001 const alignment_value = Value.initPayload(&payload.base);
2002
20031989 // First line: the variable used as data storage.
2004 const local = try f.allocAlignedLocal(elem_type, mutability, alignment_value);
1990 const local = try f.allocAlignedLocal(elem_type, mutability, inst_ty.ptrAlignment(target));
20051991 try writer.writeAll(";\n");
20061992
20071993 return CValue{ .local_ref = local.local };
src/value.zig-4
......@@ -98,7 +98,6 @@ pub const Value = extern union {
9898 bool_false,
9999 generic_poison,
100100
101 abi_align_default,
102101 empty_struct_value,
103102 empty_array, // See last_no_payload_tag below.
104103 // After this, the tag requires a payload.
......@@ -241,7 +240,6 @@ pub const Value = extern union {
241240 .null_value,
242241 .bool_true,
243242 .bool_false,
244 .abi_align_default,
245243 .manyptr_u8_type,
246244 .manyptr_const_u8_type,
247245 .manyptr_const_u8_sentinel_0_type,
......@@ -437,7 +435,6 @@ pub const Value = extern union {
437435 .bool_true,
438436 .bool_false,
439437 .empty_struct_value,
440 .abi_align_default,
441438 .manyptr_u8_type,
442439 .manyptr_const_u8_type,
443440 .manyptr_const_u8_sentinel_0_type,
......@@ -677,7 +674,6 @@ pub const Value = extern union {
677674 .export_options_type => return out_stream.writeAll("std.builtin.ExportOptions"),
678675 .extern_options_type => return out_stream.writeAll("std.builtin.ExternOptions"),
679676 .type_info_type => return out_stream.writeAll("std.builtin.Type"),
680 .abi_align_default => return out_stream.writeAll("(default ABI alignment)"),
681677
682678 .empty_struct_value => return out_stream.writeAll("struct {}{}"),
683679 .aggregate => {