| author | |
| committer | |
| log | 0576086395774389a9f38d960f9ed5102a813bdb |
| tree | 43558a9b825a3312865ec76d2da7f6980d0b1a70 |
| parent | 3ef34feaeb3a18926bead1981e5ce577382da38e |
and make Decl alignment & linksection, and struct & union field alignment
be scalar values, not Value values.
YAGNI5 files changed, 79 insertions(+), 110 deletions(-)
src/Module.zig+37-33| ... | ... | @@ -349,12 +349,13 @@ pub const Decl = struct { |
| 349 | 349 | /// Populated when `has_tv`. |
| 350 | 350 | val: Value, |
| 351 | 351 | /// Populated when `has_tv`. |
| 352 | align_val: Value, | |
| 352 | /// Points to memory inside value_arena. | |
| 353 | @"linksection": ?[*:0]const u8, | |
| 353 | 354 | /// Populated when `has_tv`. |
| 354 | linksection_val: Value, | |
| 355 | @"align": u32, | |
| 355 | 356 | /// Populated when `has_tv`. |
| 356 | 357 | @"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. | |
| 358 | 359 | /// If this is `null` then there is no memory management needed. |
| 359 | 360 | value_arena: ?*std.heap.ArenaAllocator.State = null, |
| 360 | 361 | /// The direct parent namespace of the Decl. |
| ... | ... | @@ -423,7 +424,7 @@ pub const Decl = struct { |
| 423 | 424 | /// to require re-analysis. |
| 424 | 425 | outdated, |
| 425 | 426 | }, |
| 426 | /// Whether `typed_value`, `align_val`, `linksection_val` and `addrspace` are populated. | |
| 427 | /// Whether `typed_value`, `align`, `linksection` and `addrspace` are populated. | |
| 427 | 428 | has_tv: bool, |
| 428 | 429 | /// If `true` it means the `Decl` is the resource owner of the type/value associated |
| 429 | 430 | /// with it. That means when `Decl` is destroyed, the cleanup code should additionally |
| ... | ... | @@ -794,9 +795,9 @@ pub const Decl = struct { |
| 794 | 795 | |
| 795 | 796 | pub fn getAlignment(decl: Decl, target: Target) u32 { |
| 796 | 797 | assert(decl.has_tv); |
| 797 | if (decl.align_val.tag() != .null_value) { | |
| 798 | if (decl.@"align" != 0) { | |
| 798 | 799 | // Explicit alignment. |
| 799 | return @intCast(u32, decl.align_val.toUnsignedInt()); | |
| 800 | return decl.@"align"; | |
| 800 | 801 | } else { |
| 801 | 802 | // Natural alignment. |
| 802 | 803 | return decl.ty.abiAlignment(target); |
| ... | ... | @@ -893,9 +894,10 @@ pub const Struct = struct { |
| 893 | 894 | /// Uses `noreturn` to indicate `anytype`. |
| 894 | 895 | /// undefined until `status` is `have_field_types` or `have_layout`. |
| 895 | 896 | ty: Type, |
| 896 | abi_align: Value, | |
| 897 | 897 | /// Uses `unreachable_value` to indicate no default. |
| 898 | 898 | default_val: Value, |
| 899 | /// Zero means to use the ABI alignment of the type. | |
| 900 | abi_align: u32, | |
| 899 | 901 | /// undefined until `status` is `have_layout`. |
| 900 | 902 | offset: u32, |
| 901 | 903 | /// If true then `default_val` is the comptime field value. |
| ... | ... | @@ -903,10 +905,10 @@ pub const Struct = struct { |
| 903 | 905 | |
| 904 | 906 | /// Returns the field alignment, assuming the struct is not packed. |
| 905 | 907 | pub fn normalAlignment(field: Field, target: Target) u32 { |
| 906 | if (field.abi_align.tag() == .abi_align_default) { | |
| 908 | if (field.abi_align == 0) { | |
| 907 | 909 | return field.ty.abiAlignment(target); |
| 908 | 910 | } else { |
| 909 | return @intCast(u32, field.abi_align.toUnsignedInt()); | |
| 911 | return field.abi_align; | |
| 910 | 912 | } |
| 911 | 913 | } |
| 912 | 914 | }; |
| ... | ... | @@ -1139,16 +1141,17 @@ pub const Union = struct { |
| 1139 | 1141 | pub const Field = struct { |
| 1140 | 1142 | /// undefined until `status` is `have_field_types` or `have_layout`. |
| 1141 | 1143 | ty: Type, |
| 1142 | abi_align: Value, | |
| 1144 | /// 0 means the ABI alignment of the type. | |
| 1145 | abi_align: u32, | |
| 1143 | 1146 | |
| 1144 | 1147 | /// Returns the field alignment, assuming the union is not packed. |
| 1145 | 1148 | /// Keep implementation in sync with `Sema.unionFieldAlignment`. |
| 1146 | 1149 | /// Prefer to call that function instead of this one during Sema. |
| 1147 | 1150 | pub fn normalAlignment(field: Field, target: Target) u32 { |
| 1148 | if (field.abi_align.tag() == .abi_align_default) { | |
| 1151 | if (field.abi_align == 0) { | |
| 1149 | 1152 | return field.ty.abiAlignment(target); |
| 1150 | 1153 | } else { |
| 1151 | return @intCast(u32, field.abi_align.toUnsignedInt()); | |
| 1154 | return field.abi_align; | |
| 1152 | 1155 | } |
| 1153 | 1156 | } |
| 1154 | 1157 | }; |
| ... | ... | @@ -1224,7 +1227,7 @@ pub const Union = struct { |
| 1224 | 1227 | if (!field.ty.hasRuntimeBits()) continue; |
| 1225 | 1228 | |
| 1226 | 1229 | const field_align = a: { |
| 1227 | if (field.abi_align.tag() == .abi_align_default) { | |
| 1230 | if (field.abi_align == 0) { | |
| 1228 | 1231 | break :a field.ty.abiAlignment(target); |
| 1229 | 1232 | } else { |
| 1230 | 1233 | break :a @intCast(u32, field.abi_align.toUnsignedInt()); |
| ... | ... | @@ -1246,10 +1249,10 @@ pub const Union = struct { |
| 1246 | 1249 | if (!field.ty.hasRuntimeBits()) continue; |
| 1247 | 1250 | |
| 1248 | 1251 | const field_align = a: { |
| 1249 | if (field.abi_align.tag() == .abi_align_default) { | |
| 1252 | if (field.abi_align == 0) { | |
| 1250 | 1253 | break :a field.ty.abiAlignment(target); |
| 1251 | 1254 | } else { |
| 1252 | break :a @intCast(u32, field.abi_align.toUnsignedInt()); | |
| 1255 | break :a field.abi_align; | |
| 1253 | 1256 | } |
| 1254 | 1257 | }; |
| 1255 | 1258 | max_align = @maximum(max_align, field_align); |
| ... | ... | @@ -1300,10 +1303,10 @@ pub const Union = struct { |
| 1300 | 1303 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 1301 | 1304 | |
| 1302 | 1305 | const field_align = a: { |
| 1303 | if (field.abi_align.tag() == .abi_align_default) { | |
| 1306 | if (field.abi_align == 0) { | |
| 1304 | 1307 | break :a field.ty.abiAlignment(target); |
| 1305 | 1308 | } else { |
| 1306 | break :a @intCast(u32, field.abi_align.toUnsignedInt()); | |
| 1309 | break :a field.abi_align; | |
| 1307 | 1310 | } |
| 1308 | 1311 | }; |
| 1309 | 1312 | const field_size = field.ty.abiSize(target); |
| ... | ... | @@ -3863,15 +3866,16 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 3863 | 3866 | try wip_captures.finalize(); |
| 3864 | 3867 | const src: LazySrcLoc = .{ .node_offset = 0 }; |
| 3865 | 3868 | const decl_tv = try sema.resolveInstValue(&block_scope, src, result_ref); |
| 3866 | const align_val = blk: { | |
| 3869 | const decl_align: u16 = blk: { | |
| 3867 | 3870 | 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); | |
| 3870 | 3873 | }; |
| 3871 | const linksection_val = blk: { | |
| 3874 | const decl_linksection: ?[*:0]const u8 = blk: { | |
| 3872 | 3875 | 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; | |
| 3875 | 3879 | }; |
| 3876 | 3880 | const address_space = blk: { |
| 3877 | 3881 | const addrspace_ctx: Sema.AddressSpaceContext = switch (decl_tv.val.tag()) { |
| ... | ... | @@ -3911,8 +3915,8 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 3911 | 3915 | |
| 3912 | 3916 | decl.ty = ty_ty; |
| 3913 | 3917 | 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; | |
| 3916 | 3920 | decl.has_tv = true; |
| 3917 | 3921 | decl.owns_tv = false; |
| 3918 | 3922 | decl_arena_state.* = decl_arena.state; |
| ... | ... | @@ -3942,8 +3946,8 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 3942 | 3946 | |
| 3943 | 3947 | decl.ty = try decl_tv.ty.copy(decl_arena_allocator); |
| 3944 | 3948 | 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; | |
| 3947 | 3951 | decl.@"addrspace" = address_space; |
| 3948 | 3952 | decl.has_tv = true; |
| 3949 | 3953 | decl.owns_tv = owns_tv; |
| ... | ... | @@ -4022,8 +4026,8 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 4022 | 4026 | |
| 4023 | 4027 | decl.ty = try decl_tv.ty.copy(decl_arena_allocator); |
| 4024 | 4028 | 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; | |
| 4027 | 4031 | decl.@"addrspace" = address_space; |
| 4028 | 4032 | decl.has_tv = true; |
| 4029 | 4033 | decl_arena_state.* = decl_arena.state; |
| ... | ... | @@ -4889,8 +4893,8 @@ pub fn allocateNewDecl( |
| 4889 | 4893 | .owns_tv = false, |
| 4890 | 4894 | .ty = undefined, |
| 4891 | 4895 | .val = undefined, |
| 4892 | .align_val = undefined, | |
| 4893 | .linksection_val = undefined, | |
| 4896 | .@"align" = undefined, | |
| 4897 | .@"linksection" = undefined, | |
| 4894 | 4898 | .@"addrspace" = .generic, |
| 4895 | 4899 | .analysis = .unreferenced, |
| 4896 | 4900 | .deletion_flag = false, |
| ... | ... | @@ -4995,8 +4999,8 @@ pub fn createAnonymousDeclFromDeclNamed( |
| 4995 | 4999 | new_decl.src_line = src_decl.src_line; |
| 4996 | 5000 | new_decl.ty = typed_value.ty; |
| 4997 | 5001 | 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; | |
| 5000 | 5004 | new_decl.has_tv = true; |
| 5001 | 5005 | new_decl.analysis = .complete; |
| 5002 | 5006 | new_decl.generation = mod.generation; |
src/Sema.zig+21-36| ... | ... | @@ -486,19 +486,17 @@ pub const Block = struct { |
| 486 | 486 | wad.* = undefined; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | /// `alignment` value of 0 means to use ABI alignment. | |
| 489 | 490 | pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value, alignment: u32) !*Decl { |
| 490 | 491 | const sema = wad.block.sema; |
| 491 | 492 | // Do this ahead of time because `createAnonymousDecl` depends on calling |
| 492 | 493 | // `type.hasRuntimeBits()`. |
| 493 | 494 | _ = 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"; | |
| 497 | 495 | const new_decl = try sema.mod.createAnonymousDecl(wad.block, .{ |
| 498 | 496 | .ty = ty, |
| 499 | 497 | .val = val, |
| 500 | 498 | }); |
| 501 | new_decl.align_val = align_val; | |
| 499 | new_decl.@"align" = alignment; | |
| 502 | 500 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 503 | 501 | try new_decl.finalizeNewArena(&wad.new_decl_arena); |
| 504 | 502 | wad.finished = true; |
| ... | ... | @@ -1281,7 +1279,7 @@ fn resolveConstBool( |
| 1281 | 1279 | return val.toBool(); |
| 1282 | 1280 | } |
| 1283 | 1281 | |
| 1284 | fn resolveConstString( | |
| 1282 | pub fn resolveConstString( | |
| 1285 | 1283 | sema: *Sema, |
| 1286 | 1284 | block: *Block, |
| 1287 | 1285 | src: LazySrcLoc, |
| ... | ... | @@ -1539,7 +1537,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: *Block, err_msg: *Module.ErrorMsg) |
| 1539 | 1537 | return error.AnalysisFail; |
| 1540 | 1538 | } |
| 1541 | 1539 | |
| 1542 | fn resolveAlign( | |
| 1540 | pub fn resolveAlign( | |
| 1543 | 1541 | sema: *Sema, |
| 1544 | 1542 | block: *Block, |
| 1545 | 1543 | src: LazySrcLoc, |
| ... | ... | @@ -13061,7 +13059,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 13061 | 13059 | var buffer: Value.ToTypeBuffer = undefined; |
| 13062 | 13060 | gop.value_ptr.* = .{ |
| 13063 | 13061 | .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()), | |
| 13065 | 13063 | }; |
| 13066 | 13064 | } |
| 13067 | 13065 | } |
| ... | ... | @@ -13230,7 +13228,7 @@ fn reifyStruct( |
| 13230 | 13228 | var buffer: Value.ToTypeBuffer = undefined; |
| 13231 | 13229 | gop.value_ptr.* = .{ |
| 13232 | 13230 | .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()), | |
| 13234 | 13232 | .default_val = default_val, |
| 13235 | 13233 | .is_comptime = is_comptime_val.toBool(), |
| 13236 | 13234 | .offset = undefined, |
| ... | ... | @@ -14949,9 +14947,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 14949 | 14947 | }; |
| 14950 | 14948 | |
| 14951 | 14949 | 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; | |
| 14955 | 14953 | } |
| 14956 | 14954 | |
| 14957 | 14955 | const target = sema.mod.getTarget(); |
| ... | ... | @@ -15552,8 +15550,8 @@ fn zirBuiltinExtern( |
| 15552 | 15550 | new_decl.src_line = sema.owner_decl.src_line; |
| 15553 | 15551 | new_decl.ty = try ty.copy(new_decl_arena_allocator); |
| 15554 | 15552 | 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; | |
| 15557 | 15555 | new_decl.has_tv = true; |
| 15558 | 15556 | new_decl.analysis = .complete; |
| 15559 | 15557 | new_decl.generation = sema.mod.generation; |
| ... | ... | @@ -16543,9 +16541,7 @@ fn structFieldPtrByIndex( |
| 16543 | 16541 | ptr_ty_data.bit_offset += struct_ptr_ty_info.bit_offset; |
| 16544 | 16542 | } |
| 16545 | 16543 | } 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; | |
| 16549 | 16545 | } |
| 16550 | 16546 | |
| 16551 | 16547 | const target = sema.mod.getTarget(); |
| ... | ... | @@ -19168,15 +19164,11 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { |
| 19168 | 19164 | const decl_tv = try decl.typedValue(); |
| 19169 | 19165 | if (decl_tv.val.castTag(.variable)) |payload| { |
| 19170 | 19166 | 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()); | |
| 19175 | 19167 | const ty = try Type.ptr(sema.arena, target, .{ |
| 19176 | 19168 | .pointee_type = decl_tv.ty, |
| 19177 | 19169 | .mutable = variable.is_mutable, |
| 19178 | 19170 | .@"addrspace" = decl.@"addrspace", |
| 19179 | .@"align" = alignment, | |
| 19171 | .@"align" = decl.@"align", | |
| 19180 | 19172 | }); |
| 19181 | 19173 | return sema.addConstant(ty, try Value.Tag.decl_ref.create(sema.arena, decl)); |
| 19182 | 19174 | } |
| ... | ... | @@ -20848,7 +20840,7 @@ fn semaStructFields( |
| 20848 | 20840 | assert(!gop.found_existing); |
| 20849 | 20841 | gop.value_ptr.* = .{ |
| 20850 | 20842 | .ty = try field_ty.copy(decl_arena_allocator), |
| 20851 | .abi_align = Value.initTag(.abi_align_default), | |
| 20843 | .abi_align = 0, | |
| 20852 | 20844 | .default_val = Value.initTag(.unreachable_value), |
| 20853 | 20845 | .is_comptime = is_comptime, |
| 20854 | 20846 | .offset = undefined, |
| ... | ... | @@ -20860,8 +20852,7 @@ fn semaStructFields( |
| 20860 | 20852 | // TODO: if we need to report an error here, use a source location |
| 20861 | 20853 | // that points to this alignment expression rather than the struct. |
| 20862 | 20854 | // 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); | |
| 20865 | 20856 | } |
| 20866 | 20857 | if (has_default) { |
| 20867 | 20858 | 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 { |
| 21088 | 21079 | assert(!gop.found_existing); |
| 21089 | 21080 | gop.value_ptr.* = .{ |
| 21090 | 21081 | .ty = try field_ty.copy(decl_arena_allocator), |
| 21091 | .abi_align = Value.initTag(.abi_align_default), | |
| 21082 | .abi_align = 0, | |
| 21092 | 21083 | }; |
| 21093 | 21084 | |
| 21094 | 21085 | if (align_ref != .none) { |
| 21095 | 21086 | // TODO: if we need to report an error here, use a source location |
| 21096 | 21087 | // that points to this alignment expression rather than the struct. |
| 21097 | 21088 | // 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); | |
| 21100 | 21090 | } else { |
| 21101 | gop.value_ptr.abi_align = Value.initTag(.abi_align_default); | |
| 21091 | gop.value_ptr.abi_align = 0; | |
| 21102 | 21092 | } |
| 21103 | 21093 | } |
| 21104 | 21094 | } |
| ... | ... | @@ -21638,11 +21628,6 @@ fn analyzeComptimeAlloc( |
| 21638 | 21628 | var anon_decl = try block.startAnonDecl(src); |
| 21639 | 21629 | defer anon_decl.deinit(); |
| 21640 | 21630 | |
| 21641 | const align_val = if (alignment == 0) | |
| 21642 | Value.@"null" | |
| 21643 | else | |
| 21644 | try Value.Tag.int_u64.create(anon_decl.arena(), alignment); | |
| 21645 | ||
| 21646 | 21631 | const decl = try anon_decl.finish( |
| 21647 | 21632 | try var_type.copy(anon_decl.arena()), |
| 21648 | 21633 | // There will be stores before the first load, but they may be to sub-elements or |
| ... | ... | @@ -21651,7 +21636,7 @@ fn analyzeComptimeAlloc( |
| 21651 | 21636 | Value.undef, |
| 21652 | 21637 | alignment, |
| 21653 | 21638 | ); |
| 21654 | decl.align_val = align_val; | |
| 21639 | decl.@"align" = alignment; | |
| 21655 | 21640 | |
| 21656 | 21641 | try sema.mod.declareDeclDependency(sema.owner_decl, decl); |
| 21657 | 21642 | return sema.addConstant(ptr_type, try Value.Tag.decl_ref_mut.create(sema.arena, .{ |
| ... | ... | @@ -22066,10 +22051,10 @@ fn unionFieldAlignment( |
| 22066 | 22051 | src: LazySrcLoc, |
| 22067 | 22052 | field: Module.Union.Field, |
| 22068 | 22053 | ) !u32 { |
| 22069 | if (field.abi_align.tag() == .abi_align_default) { | |
| 22054 | if (field.abi_align == 0) { | |
| 22070 | 22055 | return sema.typeAbiAlignment(block, src, field.ty); |
| 22071 | 22056 | } else { |
| 22072 | return @intCast(u32, field.abi_align.toUnsignedInt()); | |
| 22057 | return field.abi_align; | |
| 22073 | 22058 | } |
| 22074 | 22059 | } |
| 22075 | 22060 |
src/arch/x86_64/abi.zig+4-6| ... | ... | @@ -179,9 +179,8 @@ pub fn classifySystemV(ty: Type, target: Target) [8]Class { |
| 179 | 179 | var byte_i: usize = 0; // out of 8 |
| 180 | 180 | const fields = ty.structFields(); |
| 181 | 181 | 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)) { | |
| 185 | 184 | return memory_class; |
| 186 | 185 | } |
| 187 | 186 | } |
| ... | ... | @@ -288,9 +287,8 @@ pub fn classifySystemV(ty: Type, target: Target) [8]Class { |
| 288 | 287 | |
| 289 | 288 | const fields = ty.unionFields(); |
| 290 | 289 | 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)) { | |
| 294 | 292 | return memory_class; |
| 295 | 293 | } |
| 296 | 294 | } |
src/codegen/c.zig+17-31| ... | ... | @@ -245,7 +245,7 @@ pub const Function = struct { |
| 245 | 245 | ty, |
| 246 | 246 | decl_c_value, |
| 247 | 247 | .Const, |
| 248 | Value.initTag(.abi_align_default), | |
| 248 | 0, | |
| 249 | 249 | ); |
| 250 | 250 | try writer.writeAll(" = "); |
| 251 | 251 | try f.object.dg.renderValue(writer, ty, val); |
| ... | ... | @@ -267,10 +267,10 @@ pub const Function = struct { |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | 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); | |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | fn allocAlignedLocal(f: *Function, ty: Type, mutability: Mutability, alignment: Value) !CValue { | |
| 273 | fn allocAlignedLocal(f: *Function, ty: Type, mutability: Mutability, alignment: u32) !CValue { | |
| 274 | 274 | const local_value = f.allocLocalValue(); |
| 275 | 275 | try f.object.dg.renderTypeAndName( |
| 276 | 276 | f.object.writer(), |
| ... | ... | @@ -854,8 +854,7 @@ pub const DeclGen = struct { |
| 854 | 854 | try w.writeAll(", "); |
| 855 | 855 | } |
| 856 | 856 | 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); | |
| 859 | 858 | params_written += 1; |
| 860 | 859 | } |
| 861 | 860 | |
| ... | ... | @@ -928,8 +927,7 @@ pub const DeclGen = struct { |
| 928 | 927 | var ptr_type_buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 929 | 928 | const ptr_type = t.slicePtrFieldType(&ptr_type_buf); |
| 930 | 929 | 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); | |
| 933 | 931 | |
| 934 | 932 | const ptr_sentinel = ptr_type.ptrInfo().data.sentinel; |
| 935 | 933 | const child_type = t.childType(); |
| ... | ... | @@ -1018,7 +1016,7 @@ pub const DeclGen = struct { |
| 1018 | 1016 | try name.writer().print("field_{d}", .{i}); |
| 1019 | 1017 | |
| 1020 | 1018 | 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); | |
| 1022 | 1020 | try buffer.appendSlice(";\n"); |
| 1023 | 1021 | } |
| 1024 | 1022 | } |
| ... | ... | @@ -1056,7 +1054,7 @@ pub const DeclGen = struct { |
| 1056 | 1054 | const name: CValue = .{ .bytes = "tag" }; |
| 1057 | 1055 | try buffer.appendSlice("struct {\n "); |
| 1058 | 1056 | 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); | |
| 1060 | 1058 | try buffer.appendSlice(";\n"); |
| 1061 | 1059 | } |
| 1062 | 1060 | } |
| ... | ... | @@ -1106,8 +1104,7 @@ pub const DeclGen = struct { |
| 1106 | 1104 | |
| 1107 | 1105 | try bw.writeAll("typedef struct { "); |
| 1108 | 1106 | 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); | |
| 1111 | 1108 | try bw.writeAll("; uint16_t error; } "); |
| 1112 | 1109 | const name_index = buffer.items.len; |
| 1113 | 1110 | if (err_set_type.castTag(.error_set_inferred)) |inf_err_set_payload| { |
| ... | ... | @@ -1172,8 +1169,7 @@ pub const DeclGen = struct { |
| 1172 | 1169 | |
| 1173 | 1170 | try bw.writeAll("typedef struct { "); |
| 1174 | 1171 | 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); | |
| 1177 | 1173 | try bw.writeAll("; bool is_null; } "); |
| 1178 | 1174 | const name_index = buffer.items.len; |
| 1179 | 1175 | try bw.print("zig_Q_{s};\n", .{typeToCIdentifier(child_type)}); |
| ... | ... | @@ -1375,12 +1371,9 @@ pub const DeclGen = struct { |
| 1375 | 1371 | dg: *DeclGen, |
| 1376 | 1372 | w: anytype, |
| 1377 | 1373 | ty: Type, |
| 1378 | //mutability: Mutability, | |
| 1379 | //alignment: Value, | |
| 1380 | 1374 | ) error{ OutOfMemory, AnalysisFail }!void { |
| 1381 | 1375 | 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); | |
| 1384 | 1377 | } |
| 1385 | 1378 | |
| 1386 | 1379 | /// Renders a type and name in field declaration/definition format. |
| ... | ... | @@ -1398,7 +1391,7 @@ pub const DeclGen = struct { |
| 1398 | 1391 | ty: Type, |
| 1399 | 1392 | name: CValue, |
| 1400 | 1393 | mutability: Mutability, |
| 1401 | alignment: Value, | |
| 1394 | alignment: u32, | |
| 1402 | 1395 | ) error{ OutOfMemory, AnalysisFail }!void { |
| 1403 | 1396 | var suffix = std.ArrayList(u8).init(dg.gpa); |
| 1404 | 1397 | defer suffix.deinit(); |
| ... | ... | @@ -1413,8 +1406,8 @@ pub const DeclGen = struct { |
| 1413 | 1406 | render_ty = render_ty.elemType(); |
| 1414 | 1407 | } |
| 1415 | 1408 | |
| 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}); | |
| 1418 | 1411 | try dg.renderType(w, render_ty); |
| 1419 | 1412 | |
| 1420 | 1413 | const const_prefix = switch (mutability) { |
| ... | ... | @@ -1570,7 +1563,7 @@ pub fn genDecl(o: *Object) !void { |
| 1570 | 1563 | |
| 1571 | 1564 | const decl_c_value: CValue = if (is_global) .{ .bytes = mem.span(o.dg.decl.name) } else .{ .decl = o.dg.decl }; |
| 1572 | 1565 | |
| 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"); | |
| 1574 | 1567 | try fwd_decl_writer.writeAll(";\n"); |
| 1575 | 1568 | |
| 1576 | 1569 | if (variable.init.isUndefDeep()) { |
| ... | ... | @@ -1579,7 +1572,7 @@ pub fn genDecl(o: *Object) !void { |
| 1579 | 1572 | |
| 1580 | 1573 | try o.indent_writer.insertNewline(); |
| 1581 | 1574 | 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"); | |
| 1583 | 1576 | try w.writeAll(" = "); |
| 1584 | 1577 | if (variable.init.tag() != .unreachable_value) { |
| 1585 | 1578 | try o.dg.renderValue(w, tv.ty, variable.init); |
| ... | ... | @@ -1594,7 +1587,7 @@ pub fn genDecl(o: *Object) !void { |
| 1594 | 1587 | // https://github.com/ziglang/zig/issues/7582 |
| 1595 | 1588 | |
| 1596 | 1589 | 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"); | |
| 1598 | 1591 | |
| 1599 | 1592 | try writer.writeAll(" = "); |
| 1600 | 1593 | try o.dg.renderValue(writer, tv.ty, tv.val); |
| ... | ... | @@ -1993,15 +1986,8 @@ fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue { |
| 1993 | 1986 | } |
| 1994 | 1987 | |
| 1995 | 1988 | 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 | ||
| 2003 | 1989 | // 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)); | |
| 2005 | 1991 | try writer.writeAll(";\n"); |
| 2006 | 1992 | |
| 2007 | 1993 | return CValue{ .local_ref = local.local }; |
src/value.zig-4| ... | ... | @@ -98,7 +98,6 @@ pub const Value = extern union { |
| 98 | 98 | bool_false, |
| 99 | 99 | generic_poison, |
| 100 | 100 | |
| 101 | abi_align_default, | |
| 102 | 101 | empty_struct_value, |
| 103 | 102 | empty_array, // See last_no_payload_tag below. |
| 104 | 103 | // After this, the tag requires a payload. |
| ... | ... | @@ -241,7 +240,6 @@ pub const Value = extern union { |
| 241 | 240 | .null_value, |
| 242 | 241 | .bool_true, |
| 243 | 242 | .bool_false, |
| 244 | .abi_align_default, | |
| 245 | 243 | .manyptr_u8_type, |
| 246 | 244 | .manyptr_const_u8_type, |
| 247 | 245 | .manyptr_const_u8_sentinel_0_type, |
| ... | ... | @@ -437,7 +435,6 @@ pub const Value = extern union { |
| 437 | 435 | .bool_true, |
| 438 | 436 | .bool_false, |
| 439 | 437 | .empty_struct_value, |
| 440 | .abi_align_default, | |
| 441 | 438 | .manyptr_u8_type, |
| 442 | 439 | .manyptr_const_u8_type, |
| 443 | 440 | .manyptr_const_u8_sentinel_0_type, |
| ... | ... | @@ -677,7 +674,6 @@ pub const Value = extern union { |
| 677 | 674 | .export_options_type => return out_stream.writeAll("std.builtin.ExportOptions"), |
| 678 | 675 | .extern_options_type => return out_stream.writeAll("std.builtin.ExternOptions"), |
| 679 | 676 | .type_info_type => return out_stream.writeAll("std.builtin.Type"), |
| 680 | .abi_align_default => return out_stream.writeAll("(default ABI alignment)"), | |
| 681 | 677 | |
| 682 | 678 | .empty_struct_value => return out_stream.writeAll("struct {}{}"), |
| 683 | 679 | .aggregate => { |