Skip to content

Commit 14685e5

Browse files
Vexuandrewrk
authored andcommitted
stage2: use correct type (u29) for alignment
1 parent 32568db commit 14685e5

File tree

7 files changed

+49
-11
lines changed

7 files changed

+49
-11
lines changed

src/AstGen.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ pub const ResultLoc = union(enum) {
291291
}
292292
};
293293

294-
pub const align_rl: ResultLoc = .{ .ty = .u16_type };
295-
pub const coerced_align_rl: ResultLoc = .{ .coerced_ty = .u16_type };
294+
pub const align_rl: ResultLoc = .{ .ty = .u29_type };
295+
pub const coerced_align_rl: ResultLoc = .{ .coerced_ty = .u29_type };
296296
pub const bool_rl: ResultLoc = .{ .ty = .bool_type };
297297
pub const type_rl: ResultLoc = .{ .ty = .type_type };
298298
pub const coerced_type_rl: ResultLoc = .{ .coerced_ty = .type_type };
@@ -8077,6 +8077,7 @@ const primitives = std.ComptimeStringMap(Zir.Inst.Ref, .{
80778077
.{ "true", .bool_true },
80788078
.{ "type", .type_type },
80798079
.{ "u16", .u16_type },
8080+
.{ "u29", .u29_type },
80808081
.{ "u32", .u32_type },
80818082
.{ "u64", .u64_type },
80828083
.{ "u128", .u128_type },
@@ -8749,6 +8750,7 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
87498750
.isize_type,
87508751
.type_type,
87518752
.u16_type,
8753+
.u29_type,
87528754
.u32_type,
87538755
.u64_type,
87548756
.u128_type,
@@ -8988,6 +8990,7 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
89888990
.i8_type,
89898991
.isize_type,
89908992
.u16_type,
8993+
.u29_type,
89918994
.u32_type,
89928995
.u64_type,
89938996
.u128_type,
@@ -9063,6 +9066,7 @@ fn rvalue(
90639066
as_ty | @enumToInt(Zir.Inst.Ref.u8_type),
90649067
as_ty | @enumToInt(Zir.Inst.Ref.i8_type),
90659068
as_ty | @enumToInt(Zir.Inst.Ref.u16_type),
9069+
as_ty | @enumToInt(Zir.Inst.Ref.u29_type),
90669070
as_ty | @enumToInt(Zir.Inst.Ref.i16_type),
90679071
as_ty | @enumToInt(Zir.Inst.Ref.u32_type),
90689072
as_ty | @enumToInt(Zir.Inst.Ref.i32_type),

src/Module.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4016,7 +4016,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
40164016
try wip_captures.finalize();
40174017
const src: LazySrcLoc = .{ .node_offset = 0 };
40184018
const decl_tv = try sema.resolveInstValue(&block_scope, src, result_ref);
4019-
const decl_align: u16 = blk: {
4019+
const decl_align: u32 = blk: {
40204020
const align_ref = decl.zirAlignRef();
40214021
if (align_ref == .none) break :blk 0;
40224022
break :blk try sema.resolveAlign(&block_scope, src, align_ref);

src/Sema.zig

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,9 +1739,9 @@ pub fn resolveAlign(
17391739
block: *Block,
17401740
src: LazySrcLoc,
17411741
zir_ref: Zir.Inst.Ref,
1742-
) !u16 {
1743-
const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16));
1744-
const alignment = @intCast(u16, alignment_big); // We coerce to u16 in the prev line.
1742+
) !u32 {
1743+
const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u29));
1744+
const alignment = @intCast(u32, alignment_big); // We coerce to u16 in the prev line.
17451745
if (alignment == 0) return sema.fail(block, src, "alignment must be >= 1", .{});
17461746
if (!std.math.isPowerOfTwo(alignment)) {
17471747
return sema.fail(block, src, "alignment value {d} is not a power of two", .{
@@ -2663,7 +2663,7 @@ fn zirAllocExtended(
26632663
break :blk try sema.resolveType(block, ty_src, type_ref);
26642664
} else undefined;
26652665

2666-
const alignment: u16 = if (small.has_align) blk: {
2666+
const alignment: u32 = if (small.has_align) blk: {
26672667
const align_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
26682668
extra_index += 1;
26692669
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
1421014210
.size = ptr_size,
1421114211
.mutable = !is_const_val.toBool(),
1421214212
.@"volatile" = is_volatile_val.toBool(),
14213-
.@"align" = @intCast(u16, alignment_val.toUnsignedInt(target)), // TODO: Validate this value.
14213+
.@"align" = @intCast(u29, alignment_val.toUnsignedInt(target)), // TODO: Validate this value.
1421414214
.@"addrspace" = address_space_val.toEnum(std.builtin.AddressSpace),
1421514215
.pointee_type = try child_ty.copy(sema.arena),
1421614216
.@"allowzero" = is_allowzero_val.toBool(),
@@ -16984,7 +16984,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1698416984
const body = sema.code.extra[extra_index..][0..body_len];
1698516985
extra_index += body.len;
1698616986

16987-
const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u16);
16987+
const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29);
1698816988
if (val.tag() == .generic_poison) {
1698916989
break :blk null;
1699016990
}
@@ -23886,6 +23886,7 @@ pub fn typeHasOnePossibleValue(
2388623886
.i8,
2388723887
.u16,
2388823888
.i16,
23889+
.u29,
2388923890
.u32,
2389023891
.i32,
2389123892
.u64,
@@ -24179,6 +24180,7 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
2417924180
.u8 => return .u8_type,
2418024181
.i8 => return .i8_type,
2418124182
.u16 => return .u16_type,
24183+
.u29 => return .u29_type,
2418224184
.i16 => return .i16_type,
2418324185
.u32 => return .u32_type,
2418424186
.i32 => return .i32_type,
@@ -24549,6 +24551,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2454924551
.i8,
2455024552
.u16,
2455124553
.i16,
24554+
.u29,
2455224555
.u32,
2455324556
.i32,
2455424557
.u64,

src/TypedValue.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub fn print(
7979
.i8_type => return writer.writeAll("i8"),
8080
.u16_type => return writer.writeAll("u16"),
8181
.i16_type => return writer.writeAll("i16"),
82+
.u29_type => return writer.writeAll("u29"),
8283
.u32_type => return writer.writeAll("u32"),
8384
.i32_type => return writer.writeAll("i32"),
8485
.u64_type => return writer.writeAll("u64"),

src/Zir.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,7 @@ pub const Inst = struct {
19611961
i8_type,
19621962
u16_type,
19631963
i16_type,
1964+
u29_type,
19641965
u32_type,
19651966
i32_type,
19661967
u64_type,
@@ -2072,6 +2073,10 @@ pub const Inst = struct {
20722073
.ty = Type.initTag(.type),
20732074
.val = Value.initTag(.i16_type),
20742075
},
2076+
.u29_type = .{
2077+
.ty = Type.initTag(.type),
2078+
.val = Value.initTag(.u29_type),
2079+
},
20752080
.u32_type = .{
20762081
.ty = Type.initTag(.type),
20772082
.val = Value.initTag(.u32_type),

src/type.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub const Type = extern union {
3636
.i8,
3737
.u16,
3838
.i16,
39+
.u29,
3940
.u32,
4041
.i32,
4142
.u64,
@@ -568,6 +569,7 @@ pub const Type = extern union {
568569
.i8,
569570
.u16,
570571
.i16,
572+
.u29,
571573
.u32,
572574
.i32,
573575
.u64,
@@ -979,6 +981,7 @@ pub const Type = extern union {
979981
.i8,
980982
.u16,
981983
.i16,
984+
.u29,
982985
.u32,
983986
.i32,
984987
.u64,
@@ -1261,6 +1264,7 @@ pub const Type = extern union {
12611264
.i8,
12621265
.u16,
12631266
.i16,
1267+
.u29,
12641268
.u32,
12651269
.i32,
12661270
.u64,
@@ -1551,6 +1555,7 @@ pub const Type = extern union {
15511555
.i8,
15521556
.u16,
15531557
.i16,
1558+
.u29,
15541559
.u32,
15551560
.i32,
15561561
.u64,
@@ -1935,6 +1940,7 @@ pub const Type = extern union {
19351940
.i8,
19361941
.u16,
19371942
.i16,
1943+
.u29,
19381944
.u32,
19391945
.i32,
19401946
.u64,
@@ -2235,6 +2241,7 @@ pub const Type = extern union {
22352241
.u8 => return Value.initTag(.u8_type),
22362242
.i8 => return Value.initTag(.i8_type),
22372243
.u16 => return Value.initTag(.u16_type),
2244+
.u29 => return Value.initTag(.u29_type),
22382245
.i16 => return Value.initTag(.i16_type),
22392246
.u32 => return Value.initTag(.u32_type),
22402247
.i32 => return Value.initTag(.i32_type),
@@ -2312,6 +2319,7 @@ pub const Type = extern union {
23122319
.i8,
23132320
.u16,
23142321
.i16,
2322+
.u29,
23152323
.u32,
23162324
.i32,
23172325
.u64,
@@ -2560,6 +2568,7 @@ pub const Type = extern union {
25602568
.i8,
25612569
.u16,
25622570
.i16,
2571+
.u29,
25632572
.u32,
25642573
.i32,
25652574
.u64,
@@ -2953,6 +2962,7 @@ pub const Type = extern union {
29532962
.vector => return AbiAlignmentAdvanced{ .scalar = 16 },
29542963

29552964
.i16, .u16 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(16, target) },
2965+
.u29 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(29, target) },
29562966
.i32, .u32 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(32, target) },
29572967
.i64, .u64 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(64, target) },
29582968
.u128, .i128 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(128, target) },
@@ -3416,6 +3426,7 @@ pub const Type = extern union {
34163426
},
34173427

34183428
.i16, .u16 => return AbiSizeAdvanced{ .scalar = intAbiSize(16, target) },
3429+
.u29 => return AbiSizeAdvanced{ .scalar = intAbiSize(29, target) },
34193430
.i32, .u32 => return AbiSizeAdvanced{ .scalar = intAbiSize(32, target) },
34203431
.i64, .u64 => return AbiSizeAdvanced{ .scalar = intAbiSize(64, target) },
34213432
.u128, .i128 => return AbiSizeAdvanced{ .scalar = intAbiSize(128, target) },
@@ -3569,6 +3580,7 @@ pub const Type = extern union {
35693580
.bool, .u1 => 1,
35703581
.u8, .i8 => 8,
35713582
.i16, .u16, .f16 => 16,
3583+
.u29 => 29,
35723584
.i32, .u32, .f32 => 32,
35733585
.i64, .u64, .f64 => 64,
35743586
.f80 => 80,
@@ -4524,6 +4536,7 @@ pub const Type = extern union {
45244536
.u1,
45254537
.u8,
45264538
.u16,
4539+
.u29,
45274540
.u32,
45284541
.u64,
45294542
.u128,
@@ -4550,6 +4563,7 @@ pub const Type = extern union {
45504563
.i8 => return .{ .signedness = .signed, .bits = 8 },
45514564
.u16 => return .{ .signedness = .unsigned, .bits = 16 },
45524565
.i16 => return .{ .signedness = .signed, .bits = 16 },
4566+
.u29 => return .{ .signedness = .unsigned, .bits = 29 },
45534567
.u32 => return .{ .signedness = .unsigned, .bits = 32 },
45544568
.i32 => return .{ .signedness = .signed, .bits = 32 },
45554569
.u64 => return .{ .signedness = .unsigned, .bits = 64 },
@@ -4814,6 +4828,7 @@ pub const Type = extern union {
48144828
.i8,
48154829
.u16,
48164830
.i16,
4831+
.u29,
48174832
.u32,
48184833
.i32,
48194834
.u64,
@@ -4856,6 +4871,7 @@ pub const Type = extern union {
48564871
.i8,
48574872
.u16,
48584873
.i16,
4874+
.u29,
48594875
.u32,
48604876
.i32,
48614877
.u64,
@@ -5072,6 +5088,7 @@ pub const Type = extern union {
50725088
.i8,
50735089
.u16,
50745090
.i16,
5091+
.u29,
50755092
.u32,
50765093
.i32,
50775094
.u64,
@@ -5816,6 +5833,7 @@ pub const Type = extern union {
58165833
i8,
58175834
u16,
58185835
i16,
5836+
u29,
58195837
u32,
58205838
i32,
58215839
u64,
@@ -5939,6 +5957,7 @@ pub const Type = extern union {
59395957
.i8,
59405958
.u16,
59415959
.i16,
5960+
.u29,
59425961
.u32,
59435962
.i32,
59445963
.u64,
@@ -6302,6 +6321,7 @@ pub const Type = extern union {
63026321
pub const @"u1" = initTag(.u1);
63036322
pub const @"u8" = initTag(.u8);
63046323
pub const @"u16" = initTag(.u16);
6324+
pub const @"u29" = initTag(.u29);
63056325
pub const @"u32" = initTag(.u32);
63066326
pub const @"u64" = initTag(.u64);
63076327

src/value.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub const Value = extern union {
3030
i8_type,
3131
u16_type,
3232
i16_type,
33+
u29_type,
3334
u32_type,
3435
i32_type,
3536
u64_type,
@@ -196,6 +197,7 @@ pub const Value = extern union {
196197
.i8_type,
197198
.u16_type,
198199
.i16_type,
200+
.u29_type,
199201
.u32_type,
200202
.i32_type,
201203
.u64_type,
@@ -397,6 +399,7 @@ pub const Value = extern union {
397399
.i8_type,
398400
.u16_type,
399401
.i16_type,
402+
.u29_type,
400403
.u32_type,
401404
.i32_type,
402405
.u64_type,
@@ -660,6 +663,7 @@ pub const Value = extern union {
660663
.u8_type => return out_stream.writeAll("u8"),
661664
.i8_type => return out_stream.writeAll("i8"),
662665
.u16_type => return out_stream.writeAll("u16"),
666+
.u29_type => return out_stream.writeAll("u29"),
663667
.i16_type => return out_stream.writeAll("i16"),
664668
.u32_type => return out_stream.writeAll("u32"),
665669
.i32_type => return out_stream.writeAll("i32"),
@@ -900,6 +904,7 @@ pub const Value = extern union {
900904
.i8_type => Type.initTag(.i8),
901905
.u16_type => Type.initTag(.u16),
902906
.i16_type => Type.initTag(.i16),
907+
.u29_type => Type.initTag(.u29),
903908
.u32_type => Type.initTag(.u32),
904909
.i32_type => Type.initTag(.i32),
905910
.u64_type => Type.initTag(.u64),
@@ -4905,7 +4910,7 @@ pub const Value = extern union {
49054910
/// `Module.resolvePeerTypes`.
49064911
stored_inst_list: std.ArrayListUnmanaged(Air.Inst.Ref) = .{},
49074912
/// 0 means ABI-aligned.
4908-
alignment: u16,
4913+
alignment: u32,
49094914
},
49104915
};
49114916

@@ -4916,7 +4921,7 @@ pub const Value = extern union {
49164921
data: struct {
49174922
decl_index: Module.Decl.Index,
49184923
/// 0 means ABI-aligned.
4919-
alignment: u16,
4924+
alignment: u32,
49204925
},
49214926
};
49224927

0 commit comments

Comments
 (0)