Commit 14685e59b2

Veikka Tuominen <git@vexu.eu>
2022-06-05 20:48:22
stage2: use correct type (u29) for alignment
1 parent 32568db
src/AstGen.zig
@@ -291,8 +291,8 @@ pub const ResultLoc = union(enum) {
     }
 };
 
-pub const align_rl: ResultLoc = .{ .ty = .u16_type };
-pub const coerced_align_rl: ResultLoc = .{ .coerced_ty = .u16_type };
+pub const align_rl: ResultLoc = .{ .ty = .u29_type };
+pub const coerced_align_rl: ResultLoc = .{ .coerced_ty = .u29_type };
 pub const bool_rl: ResultLoc = .{ .ty = .bool_type };
 pub const type_rl: ResultLoc = .{ .ty = .type_type };
 pub const coerced_type_rl: ResultLoc = .{ .coerced_ty = .type_type };
@@ -8077,6 +8077,7 @@ const primitives = std.ComptimeStringMap(Zir.Inst.Ref, .{
     .{ "true", .bool_true },
     .{ "type", .type_type },
     .{ "u16", .u16_type },
+    .{ "u29", .u29_type },
     .{ "u32", .u32_type },
     .{ "u64", .u64_type },
     .{ "u128", .u128_type },
@@ -8749,6 +8750,7 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
                     .isize_type,
                     .type_type,
                     .u16_type,
+                    .u29_type,
                     .u32_type,
                     .u64_type,
                     .u128_type,
@@ -8988,6 +8990,7 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
                     .i8_type,
                     .isize_type,
                     .u16_type,
+                    .u29_type,
                     .u32_type,
                     .u64_type,
                     .u128_type,
@@ -9063,6 +9066,7 @@ fn rvalue(
                 as_ty | @enumToInt(Zir.Inst.Ref.u8_type),
                 as_ty | @enumToInt(Zir.Inst.Ref.i8_type),
                 as_ty | @enumToInt(Zir.Inst.Ref.u16_type),
+                as_ty | @enumToInt(Zir.Inst.Ref.u29_type),
                 as_ty | @enumToInt(Zir.Inst.Ref.i16_type),
                 as_ty | @enumToInt(Zir.Inst.Ref.u32_type),
                 as_ty | @enumToInt(Zir.Inst.Ref.i32_type),
src/Module.zig
@@ -4016,7 +4016,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
     try wip_captures.finalize();
     const src: LazySrcLoc = .{ .node_offset = 0 };
     const decl_tv = try sema.resolveInstValue(&block_scope, src, result_ref);
-    const decl_align: u16 = blk: {
+    const decl_align: u32 = blk: {
         const align_ref = decl.zirAlignRef();
         if (align_ref == .none) break :blk 0;
         break :blk try sema.resolveAlign(&block_scope, src, align_ref);
src/Sema.zig
@@ -1739,9 +1739,9 @@ pub fn resolveAlign(
     block: *Block,
     src: LazySrcLoc,
     zir_ref: Zir.Inst.Ref,
-) !u16 {
-    const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16));
-    const alignment = @intCast(u16, alignment_big); // We coerce to u16 in the prev line.
+) !u32 {
+    const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u29));
+    const alignment = @intCast(u32, alignment_big); // We coerce to u16 in the prev line.
     if (alignment == 0) return sema.fail(block, src, "alignment must be >= 1", .{});
     if (!std.math.isPowerOfTwo(alignment)) {
         return sema.fail(block, src, "alignment value {d} is not a power of two", .{
@@ -2663,7 +2663,7 @@ fn zirAllocExtended(
         break :blk try sema.resolveType(block, ty_src, type_ref);
     } else undefined;
 
-    const alignment: u16 = if (small.has_align) blk: {
+    const alignment: u32 = if (small.has_align) blk: {
         const align_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
         extra_index += 1;
         const alignment = try sema.resolveAlign(block, align_src, align_ref);
@@ -14210,7 +14210,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
                 .size = ptr_size,
                 .mutable = !is_const_val.toBool(),
                 .@"volatile" = is_volatile_val.toBool(),
-                .@"align" = @intCast(u16, alignment_val.toUnsignedInt(target)), // TODO: Validate this value.
+                .@"align" = @intCast(u29, alignment_val.toUnsignedInt(target)), // TODO: Validate this value.
                 .@"addrspace" = address_space_val.toEnum(std.builtin.AddressSpace),
                 .pointee_type = try child_ty.copy(sema.arena),
                 .@"allowzero" = is_allowzero_val.toBool(),
@@ -16984,7 +16984,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
         const body = sema.code.extra[extra_index..][0..body_len];
         extra_index += body.len;
 
-        const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u16);
+        const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29);
         if (val.tag() == .generic_poison) {
             break :blk null;
         }
@@ -23886,6 +23886,7 @@ pub fn typeHasOnePossibleValue(
         .i8,
         .u16,
         .i16,
+        .u29,
         .u32,
         .i32,
         .u64,
@@ -24179,6 +24180,7 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
         .u8 => return .u8_type,
         .i8 => return .i8_type,
         .u16 => return .u16_type,
+        .u29 => return .u29_type,
         .i16 => return .i16_type,
         .u32 => return .u32_type,
         .i32 => return .i32_type,
@@ -24549,6 +24551,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
         .i8,
         .u16,
         .i16,
+        .u29,
         .u32,
         .i32,
         .u64,
src/type.zig
@@ -36,6 +36,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -568,6 +569,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -979,6 +981,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -1261,6 +1264,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -1551,6 +1555,7 @@ pub const Type = extern union {
                 .i8,
                 .u16,
                 .i16,
+                .u29,
                 .u32,
                 .i32,
                 .u64,
@@ -1935,6 +1940,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -2235,6 +2241,7 @@ pub const Type = extern union {
             .u8 => return Value.initTag(.u8_type),
             .i8 => return Value.initTag(.i8_type),
             .u16 => return Value.initTag(.u16_type),
+            .u29 => return Value.initTag(.u29_type),
             .i16 => return Value.initTag(.i16_type),
             .u32 => return Value.initTag(.u32_type),
             .i32 => return Value.initTag(.i32_type),
@@ -2312,6 +2319,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -2560,6 +2568,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -2953,6 +2962,7 @@ pub const Type = extern union {
             .vector => return AbiAlignmentAdvanced{ .scalar = 16 },
 
             .i16, .u16 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(16, target) },
+            .u29 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(29, target) },
             .i32, .u32 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(32, target) },
             .i64, .u64 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(64, target) },
             .u128, .i128 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(128, target) },
@@ -3416,6 +3426,7 @@ pub const Type = extern union {
             },
 
             .i16, .u16 => return AbiSizeAdvanced{ .scalar = intAbiSize(16, target) },
+            .u29 => return AbiSizeAdvanced{ .scalar = intAbiSize(29, target) },
             .i32, .u32 => return AbiSizeAdvanced{ .scalar = intAbiSize(32, target) },
             .i64, .u64 => return AbiSizeAdvanced{ .scalar = intAbiSize(64, target) },
             .u128, .i128 => return AbiSizeAdvanced{ .scalar = intAbiSize(128, target) },
@@ -3569,6 +3580,7 @@ pub const Type = extern union {
             .bool, .u1 => 1,
             .u8, .i8 => 8,
             .i16, .u16, .f16 => 16,
+            .u29 => 29,
             .i32, .u32, .f32 => 32,
             .i64, .u64, .f64 => 64,
             .f80 => 80,
@@ -4524,6 +4536,7 @@ pub const Type = extern union {
             .u1,
             .u8,
             .u16,
+            .u29,
             .u32,
             .u64,
             .u128,
@@ -4550,6 +4563,7 @@ pub const Type = extern union {
             .i8 => return .{ .signedness = .signed, .bits = 8 },
             .u16 => return .{ .signedness = .unsigned, .bits = 16 },
             .i16 => return .{ .signedness = .signed, .bits = 16 },
+            .u29 => return .{ .signedness = .unsigned, .bits = 29 },
             .u32 => return .{ .signedness = .unsigned, .bits = 32 },
             .i32 => return .{ .signedness = .signed, .bits = 32 },
             .u64 => return .{ .signedness = .unsigned, .bits = 64 },
@@ -4814,6 +4828,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -4856,6 +4871,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -5072,6 +5088,7 @@ pub const Type = extern union {
             .i8,
             .u16,
             .i16,
+            .u29,
             .u32,
             .i32,
             .u64,
@@ -5816,6 +5833,7 @@ pub const Type = extern union {
         i8,
         u16,
         i16,
+        u29,
         u32,
         i32,
         u64,
@@ -5939,6 +5957,7 @@ pub const Type = extern union {
                 .i8,
                 .u16,
                 .i16,
+                .u29,
                 .u32,
                 .i32,
                 .u64,
@@ -6302,6 +6321,7 @@ pub const Type = extern union {
     pub const @"u1" = initTag(.u1);
     pub const @"u8" = initTag(.u8);
     pub const @"u16" = initTag(.u16);
+    pub const @"u29" = initTag(.u29);
     pub const @"u32" = initTag(.u32);
     pub const @"u64" = initTag(.u64);
 
src/TypedValue.zig
@@ -79,6 +79,7 @@ pub fn print(
         .i8_type => return writer.writeAll("i8"),
         .u16_type => return writer.writeAll("u16"),
         .i16_type => return writer.writeAll("i16"),
+        .u29_type => return writer.writeAll("u29"),
         .u32_type => return writer.writeAll("u32"),
         .i32_type => return writer.writeAll("i32"),
         .u64_type => return writer.writeAll("u64"),
src/value.zig
@@ -30,6 +30,7 @@ pub const Value = extern union {
         i8_type,
         u16_type,
         i16_type,
+        u29_type,
         u32_type,
         i32_type,
         u64_type,
@@ -196,6 +197,7 @@ pub const Value = extern union {
                 .i8_type,
                 .u16_type,
                 .i16_type,
+                .u29_type,
                 .u32_type,
                 .i32_type,
                 .u64_type,
@@ -397,6 +399,7 @@ pub const Value = extern union {
             .i8_type,
             .u16_type,
             .i16_type,
+            .u29_type,
             .u32_type,
             .i32_type,
             .u64_type,
@@ -660,6 +663,7 @@ pub const Value = extern union {
             .u8_type => return out_stream.writeAll("u8"),
             .i8_type => return out_stream.writeAll("i8"),
             .u16_type => return out_stream.writeAll("u16"),
+            .u29_type => return out_stream.writeAll("u29"),
             .i16_type => return out_stream.writeAll("i16"),
             .u32_type => return out_stream.writeAll("u32"),
             .i32_type => return out_stream.writeAll("i32"),
@@ -900,6 +904,7 @@ pub const Value = extern union {
             .i8_type => Type.initTag(.i8),
             .u16_type => Type.initTag(.u16),
             .i16_type => Type.initTag(.i16),
+            .u29_type => Type.initTag(.u29),
             .u32_type => Type.initTag(.u32),
             .i32_type => Type.initTag(.i32),
             .u64_type => Type.initTag(.u64),
@@ -4905,7 +4910,7 @@ pub const Value = extern union {
                 /// `Module.resolvePeerTypes`.
                 stored_inst_list: std.ArrayListUnmanaged(Air.Inst.Ref) = .{},
                 /// 0 means ABI-aligned.
-                alignment: u16,
+                alignment: u32,
             },
         };
 
@@ -4916,7 +4921,7 @@ pub const Value = extern union {
             data: struct {
                 decl_index: Module.Decl.Index,
                 /// 0 means ABI-aligned.
-                alignment: u16,
+                alignment: u32,
             },
         };
 
src/Zir.zig
@@ -1961,6 +1961,7 @@ pub const Inst = struct {
         i8_type,
         u16_type,
         i16_type,
+        u29_type,
         u32_type,
         i32_type,
         u64_type,
@@ -2072,6 +2073,10 @@ pub const Inst = struct {
                 .ty = Type.initTag(.type),
                 .val = Value.initTag(.i16_type),
             },
+            .u29_type = .{
+                .ty = Type.initTag(.type),
+                .val = Value.initTag(.u29_type),
+            },
             .u32_type = .{
                 .ty = Type.initTag(.type),
                 .val = Value.initTag(.u32_type),