authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-12 12:30:21+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:12+00:00
logb27c56fe5087872800f6b340ec3d1fc219d0d77b
treeba7183c61999deedacd513dd52c1c6f1072505fc
parentf7a1ccfc56ed2d5605aa6ee25ac8d609f4c0d2a5
signaturelock-open Commit is signed but in an unrecognized format.

compiler: get everything building

Several backends are crashing right now. I'll need to fix at least the C backend before this branch is ready to PR.

14 files changed, 300 insertions(+), 429 deletions(-)

lib/std/zig/target.zig+7-4
......@@ -519,10 +519,13 @@ pub fn intAlignment(target: *const std.Target, bits: u16) u16 {
519519 33...64 => 8,
520520 else => 16,
521521 },
522 else => return @min(
523 std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))),
524 target.cMaxIntAlignment(),
525 ),
522 else => switch (bits) {
523 0 => 1,
524 else => @min(
525 std.math.ceilPowerOfTwoPromote(u16, @intCast((@as(u17, bits) + 7) / 8)),
526 target.cMaxIntAlignment(),
527 ),
528 },
526529 };
527530}
528531
src/codegen/aarch64/Select.zig+37-52
......@@ -2791,9 +2791,9 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
27912791 } else return isel.fail("invalid constraint: '{s}'", .{constraint});
27922792 }
27932793
2794 const clobbers_val: Value = .fromInterned(unwrapped_asm.clobbers);
2794 const clobbers_val: Constant = .fromInterned(unwrapped_asm.clobbers);
27952795 const clobbers_ty = clobbers_val.typeOf(zcu);
2796 var clobbers_bigint_buf: Value.BigIntSpace = undefined;
2796 var clobbers_bigint_buf: Constant.BigIntSpace = undefined;
27972797 const clobbers_bigint = clobbers_val.toBigInt(&clobbers_bigint_buf, zcu);
27982798 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {
27992799 assert(clobbers_ty.fieldType(field_index, zcu).toIntern() == .bool_type);
......@@ -2818,7 +2818,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
28182818 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {
28192819 const limb_bits = @bitSizeOf(std.math.big.Limb);
28202820 if (field_index / limb_bits >= clobbers_bigint.limbs.len) continue; // field is false
2821 switch (@as(u1, @truncate(clobbers_bigint.limbs[field_index / limb_bits] >> field_index % limb_bits))) {
2821 switch (@as(u1, @truncate(clobbers_bigint.limbs[field_index / limb_bits] >> @intCast(field_index % limb_bits)))) {
28222822 0 => continue, // field is false
28232823 1 => {}, // field is true
28242824 }
......@@ -2871,7 +2871,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
28712871 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {
28722872 const limb_bits = @bitSizeOf(std.math.big.Limb);
28732873 if (field_index / limb_bits >= clobbers_bigint.limbs.len) continue; // field is false
2874 switch (@as(u1, @truncate(clobbers_bigint.limbs[field_index / limb_bits] >> field_index % limb_bits))) {
2874 switch (@as(u1, @truncate(clobbers_bigint.limbs[field_index / limb_bits] >> @intCast(field_index % limb_bits)))) {
28752875 0 => continue, // field is false
28762876 1 => {}, // field is true
28772877 }
......@@ -3283,8 +3283,8 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
32833283 } else if (dst_ty.isSliceAtRuntime(zcu) and src_ty.isSliceAtRuntime(zcu)) {
32843284 try dst_vi.value.move(isel, ty_op.operand);
32853285 } else if (dst_tag == .error_union and src_tag == .error_union) {
3286 assert(dst_ty.errorUnionSet(zcu).hasRuntimeBitsIgnoreComptime(zcu) ==
3287 src_ty.errorUnionSet(zcu).hasRuntimeBitsIgnoreComptime(zcu));
3286 assert(dst_ty.errorUnionSet(zcu).hasRuntimeBits(zcu) ==
3287 src_ty.errorUnionSet(zcu).hasRuntimeBits(zcu));
32883288 if (dst_ty.errorUnionPayload(zcu).toIntern() == src_ty.errorUnionPayload(zcu).toIntern()) {
32893289 try dst_vi.value.move(isel, ty_op.operand);
32903290 } else return isel.fail("bad {t} {f} {f}", .{ air_tag, isel.fmtType(dst_ty), isel.fmtType(src_ty) });
......@@ -4562,7 +4562,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
45624562 }
45634563 if (case.ranges.len == 0 and case.items.len == 1 and Constant.fromInterned(
45644564 case.items[0].toInterned().?,
4565 ).orderAgainstZero(zcu).compare(.eq)) {
4565 ).compareHetero(.eq, .zero_comptime_int, zcu)) {
45664566 try isel.emit(.cbnz(
45674567 cond_reg,
45684568 @intCast((isel.instructions.items.len + 1 - next_label) << 2),
......@@ -6893,11 +6893,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
68936893 var field_it = loaded_struct.iterateRuntimeOrder(ip);
68946894 while (field_it.next()) |field_index| {
68956895 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
6896 field_offset = field_ty.structFieldAlignment(
6897 loaded_struct.fieldAlign(ip, field_index),
6898 loaded_struct.layout,
6899 zcu,
6900 ).forward(field_offset);
6896 field_offset = loaded_struct.field_offsets.get(ip)[field_index];
69016897 const field_size = field_ty.abiSize(zcu);
69026898 if (field_size == 0) continue;
69036899 var agg_part_it = agg_vi.value.field(agg_ty, field_offset, field_size);
......@@ -6905,7 +6901,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
69056901 try agg_part_vi.?.move(isel, elems[field_index]);
69066902 field_offset += field_size;
69076903 }
6908 assert(loaded_struct.flagsUnordered(ip).alignment.forward(field_offset) == agg_vi.value.size(isel));
6904 assert(loaded_struct.alignment.forward(field_offset) == agg_vi.value.size(isel));
69096905 },
69106906 .tuple_type => |tuple_type| {
69116907 const elems: []const Air.Inst.Ref =
......@@ -6947,23 +6943,23 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
69476943 const union_layout = ZigType.getUnionLayout(loaded_union, zcu);
69486944
69496945 if (union_layout.tag_size > 0) unused_tag: {
6950 const loaded_tag = loaded_union.loadTagType(ip);
6946 const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type);
69516947 var tag_it = union_vi.value.field(union_ty, union_layout.tagOffset(), union_layout.tag_size);
69526948 const tag_vi = try tag_it.only(isel);
69536949 const tag_ra = try tag_vi.?.defReg(isel) orelse break :unused_tag;
69546950 switch (union_layout.tag_size) {
69556951 0 => unreachable,
6956 1...4 => try isel.movImmediate(tag_ra.w(), @as(u32, switch (loaded_tag.values.len) {
6952 1...4 => try isel.movImmediate(tag_ra.w(), @as(u32, switch (loaded_tag.field_values.len) {
69576953 0 => extra.field_index,
6958 else => switch (ip.indexToKey(loaded_tag.values.get(ip)[extra.field_index]).int.storage) {
6954 else => switch (ip.indexToKey(loaded_tag.field_values.get(ip)[extra.field_index]).int.storage) {
69596955 .u64 => |imm| @intCast(imm),
69606956 .i64 => |imm| @bitCast(@as(i32, @intCast(imm))),
69616957 else => unreachable,
69626958 },
69636959 })),
6964 5...8 => try isel.movImmediate(tag_ra.x(), switch (loaded_tag.values.len) {
6960 5...8 => try isel.movImmediate(tag_ra.x(), switch (loaded_tag.field_values.len) {
69656961 0 => extra.field_index,
6966 else => switch (ip.indexToKey(loaded_tag.values.get(ip)[extra.field_index]).int.storage) {
6962 else => switch (ip.indexToKey(loaded_tag.field_values.get(ip)[extra.field_index]).int.storage) {
69676963 .u64 => |imm| imm,
69686964 .i64 => |imm| @bitCast(imm),
69696965 else => unreachable,
......@@ -10391,7 +10387,7 @@ pub const Value = struct {
1039110387 switch (loaded_struct.layout) {
1039210388 .auto, .@"extern" => {},
1039310389 .@"packed" => continue :type_key .{
10394 .int_type = ip.indexToKey(loaded_struct.backingIntTypeUnordered(ip)).int_type,
10390 .int_type = ip.indexToKey(loaded_struct.packed_backing_int_type).int_type,
1039510391 },
1039610392 }
1039710393 const min_part_log2_stride: u5 = if (size > 16) 4 else if (size > 8) 3 else 0;
......@@ -10406,7 +10402,7 @@ pub const Value = struct {
1040610402 var field_it = loaded_struct.iterateRuntimeOrder(ip);
1040710403 while (field_it.next()) |field_index| {
1040810404 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
10409 const field_begin = switch (loaded_struct.fieldAlign(ip, field_index)) {
10405 const field_begin = switch (loaded_struct.field_aligns.getOrNone(ip, field_index)) {
1041010406 .none => field_ty.abiAlignment(zcu),
1041110407 else => |field_align| field_align,
1041210408 }.forward(field_end);
......@@ -10504,7 +10500,7 @@ pub const Value = struct {
1050410500 },
1050510501 .union_type => {
1050610502 const loaded_union = ip.loadUnionType(ty.toIntern());
10507 switch (loaded_union.flagsUnordered(ip).layout) {
10503 switch (loaded_union.layout) {
1050810504 .auto, .@"extern" => {},
1050910505 .@"packed" => continue :type_key .{ .int_type = .{
1051010506 .signedness = .unsigned,
......@@ -10539,12 +10535,13 @@ pub const Value = struct {
1053910535 const field_signedness = field_signedness: switch (field) {
1054010536 .tag => {
1054110537 if (offset >= field_begin and offset + size <= field_begin + field_size) {
10542 ty = .fromInterned(loaded_union.enum_tag_ty);
10538 ty = .fromInterned(loaded_union.enum_tag_type);
1054310539 ty_size = field_size;
1054410540 offset -= field_begin;
10545 continue :type_key ip.indexToKey(loaded_union.enum_tag_ty);
10541 continue :type_key ip.indexToKey(loaded_union.enum_tag_type);
1054610542 }
10547 break :field_signedness ip.indexToKey(loaded_union.loadTagType(ip).tag_ty).int_type.signedness;
10543 const loaded_enum = ip.loadEnumType(loaded_union.enum_tag_type);
10544 break :field_signedness ip.indexToKey(loaded_enum.int_tag_type).int_type.signedness;
1054810545 },
1054910546 .payload => null,
1055010547 };
......@@ -10574,7 +10571,7 @@ pub const Value = struct {
1057410571 }
1057510572 },
1057610573 .opaque_type, .func_type => continue :type_key .{ .simple_type = .anyopaque },
10577 .enum_type => continue :type_key ip.indexToKey(ip.loadEnumType(ty.toIntern()).tag_ty),
10574 .enum_type => continue :type_key ip.indexToKey(ip.loadEnumType(ty.toIntern()).int_tag_type),
1057810575 .error_set_type,
1057910576 .inferred_error_set_type,
1058010577 => continue :type_key .{ .simple_type = .anyerror },
......@@ -10740,7 +10737,7 @@ pub const Value = struct {
1074010737 .storage = .{ .u64 = 0 },
1074110738 } },
1074210739 },
10743 .int => |int| break :free storage: switch (int.storage) {
10740 .int => |int| break :free switch (int.storage) {
1074410741 .u64 => |imm| try isel.movImmediate(switch (size) {
1074510742 else => unreachable,
1074610743 1...4 => mat.ra.w(),
......@@ -10772,12 +10769,6 @@ pub const Value = struct {
1077210769 }
1077310770 try isel.movImmediate(mat.ra.x(), imm);
1077410771 },
10775 .lazy_align => |ty| continue :storage .{
10776 .u64 = ZigType.fromInterned(ty).abiAlignment(zcu).toByteUnits().?,
10777 },
10778 .lazy_size => |ty| continue :storage .{
10779 .u64 = ZigType.fromInterned(ty).abiSize(zcu),
10780 },
1078110772 },
1078210773 .err => |err| continue :constant_key .{ .int = .{
1078310774 .ty = err.ty,
......@@ -11084,13 +11075,9 @@ pub const Value = struct {
1108411075 var field_offset: u64 = 0;
1108511076 var field_it = loaded_struct.iterateRuntimeOrder(ip);
1108611077 while (field_it.next()) |field_index| {
11087 if (loaded_struct.fieldIsComptime(ip, field_index)) continue;
11078 if (loaded_struct.field_is_comptime_bits.get(ip, field_index)) continue;
1108811079 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
11089 field_offset = field_ty.structFieldAlignment(
11090 loaded_struct.fieldAlign(ip, field_index),
11091 loaded_struct.layout,
11092 zcu,
11093 ).forward(field_offset);
11080 field_offset = loaded_struct.field_offsets.get(ip)[field_index];
1109411081 const field_size = field_ty.abiSize(zcu);
1109511082 if (offset >= field_offset and offset + size <= field_offset + field_size) {
1109611083 offset -= field_offset;
......@@ -11132,7 +11119,7 @@ pub const Value = struct {
1113211119 .un => |un| {
1113311120 const loaded_union = ip.loadUnionType(un.ty);
1113411121 const union_layout = ZigType.getUnionLayout(loaded_union, zcu);
11135 if (loaded_union.hasTag(ip)) {
11122 if (loaded_union.has_runtime_tag) {
1113611123 const tag_offset = union_layout.tagOffset();
1113711124 if (offset >= tag_offset and offset + size <= tag_offset + union_layout.tag_size) {
1113811125 offset -= tag_offset;
......@@ -11477,13 +11464,9 @@ fn writeKeyToMemory(isel: *Select, constant_key: InternPool.Key, buffer: []u8) e
1147711464 var field_offset: u64 = 0;
1147811465 var field_it = loaded_struct.iterateRuntimeOrder(ip);
1147911466 while (field_it.next()) |field_index| {
11480 if (loaded_struct.fieldIsComptime(ip, field_index)) continue;
11467 if (loaded_struct.field_is_comptime_bits.get(ip, field_index)) continue;
1148111468 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
11482 field_offset = field_ty.structFieldAlignment(
11483 loaded_struct.fieldAlign(ip, field_index),
11484 loaded_struct.layout,
11485 zcu,
11486 ).forward(field_offset);
11469 field_offset = loaded_struct.field_offsets.get(ip)[field_index];
1148711470 const field_size = field_ty.abiSize(zcu);
1148811471 if (!try isel.writeToMemory(.fromInterned(switch (aggregate.storage) {
1148911472 .bytes => unreachable,
......@@ -12082,7 +12065,7 @@ pub const CallAbiIterator = struct {
1208212065 const zcu = isel.pt.zcu;
1208312066 const ip = &zcu.intern_pool;
1208412067
12085 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return null;
12068 if (!ty.hasRuntimeBits(zcu)) return null;
1208612069 try isel.values.ensureUnusedCapacity(zcu.gpa, Value.max_parts);
1208712070 const wip_vi = isel.initValue(ty);
1208812071 type_key: switch (ip.indexToKey(ty.toIntern())) {
......@@ -12186,7 +12169,7 @@ pub const CallAbiIterator = struct {
1218612169 switch (loaded_struct.layout) {
1218712170 .auto, .@"extern" => {},
1218812171 .@"packed" => continue :type_key .{
12189 .int_type = ip.indexToKey(loaded_struct.backingIntTypeUnordered(ip)).int_type,
12172 .int_type = ip.indexToKey(loaded_struct.packed_backing_int_type).int_type,
1219012173 },
1219112174 }
1219212175 const size = wip_vi.size(isel);
......@@ -12210,7 +12193,7 @@ pub const CallAbiIterator = struct {
1221012193 const field_end = next_field_end;
1221112194 const next_field_begin = if (field_it.next()) |field_index| next_field_begin: {
1221212195 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
12213 const next_field_begin = switch (loaded_struct.fieldAlign(ip, field_index)) {
12196 const next_field_begin = switch (loaded_struct.field_aligns.getOrNone(ip, field_index)) {
1221412197 .none => field_ty.abiAlignment(zcu),
1221512198 else => |field_align| field_align,
1221612199 }.forward(field_end);
......@@ -12276,7 +12259,7 @@ pub const CallAbiIterator = struct {
1227612259 },
1227712260 .union_type => {
1227812261 const loaded_union = ip.loadUnionType(ty.toIntern());
12279 switch (loaded_union.flagsUnordered(ip).layout) {
12262 switch (loaded_union.layout) {
1228012263 .auto, .@"extern" => {},
1228112264 .@"packed" => continue :type_key .{ .int_type = .{
1228212265 .signedness = .unsigned,
......@@ -12309,7 +12292,9 @@ pub const CallAbiIterator = struct {
1230912292 }
1231012293 },
1231112294 .opaque_type, .func_type => continue :type_key .{ .simple_type = .anyopaque },
12312 .enum_type => continue :type_key ip.indexToKey(ip.loadEnumType(ty.toIntern()).tag_ty),
12295 .enum_type => continue :type_key .{
12296 .int_type = ip.indexToKey(ip.loadEnumType(ty.toIntern()).int_tag_type).int_type,
12297 },
1231312298 .error_set_type,
1231412299 .inferred_error_set_type,
1231512300 => continue :type_key .{ .simple_type = .anyerror },
......@@ -12414,8 +12399,8 @@ pub const CallAbiIterator = struct {
1241412399 const ip = &zcu.intern_pool;
1241512400 var common_fdt: ?FundamentalDataType = null;
1241612401 for (0.., loaded_struct.field_types.get(ip)) |field_index, field_ty| {
12417 if (loaded_struct.fieldIsComptime(ip, field_index)) continue;
12418 if (loaded_struct.fieldAlign(ip, field_index) != .none) return null;
12402 if (loaded_struct.field_is_comptime_bits.get(ip, field_index)) continue;
12403 if (loaded_struct.field_aligns.getOrNone(ip, field_index) != .none) return null;
1241912404 if (!ZigType.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
1242012405 const fdt = homogeneousAggregateBaseType(zcu, field_ty);
1242112406 if (common_fdt == null) common_fdt = fdt else if (fdt != common_fdt) return null;
src/codegen/c.zig+56-87
......@@ -1052,17 +1052,7 @@ pub const DeclGen = struct {
10521052 .func,
10531053 .enum_literal,
10541054 => unreachable, // non-runtime values
1055 .int => |int| switch (int.storage) {
1056 .u64, .i64, .big_int => try w.print("{f}", .{try dg.fmtIntLiteralDec(val, location)}),
1057 .lazy_align, .lazy_size => {
1058 try w.writeAll("((");
1059 try dg.renderCType(w, ctype);
1060 try w.print("){f})", .{try dg.fmtIntLiteralHex(
1061 try pt.intValue(.usize, val.toUnsignedInt(zcu)),
1062 .Other,
1063 )});
1064 },
1065 },
1055 .int => try w.print("{f}", .{try dg.fmtIntLiteralDec(val, location)}),
10661056 .err => |err| try dg.renderErrorName(w, err.name),
10671057 .error_union => |error_union| switch (ctype.info(ctype_pool)) {
10681058 .basic => switch (error_union.val) {
......@@ -1338,7 +1328,7 @@ pub const DeclGen = struct {
13381328 const comptime_val = tuple.values.get(ip)[field_index];
13391329 if (comptime_val != .none) continue;
13401330 const field_ty: Type = .fromInterned(tuple.types.get(ip)[field_index]);
1341 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1331 if (!field_ty.hasRuntimeBits(zcu)) continue;
13421332
13431333 if (!empty) try w.writeByte(',');
13441334
......@@ -1373,7 +1363,7 @@ pub const DeclGen = struct {
13731363 var need_comma = false;
13741364 while (field_it.next()) |field_index| {
13751365 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
1376 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1366 if (!field_ty.hasRuntimeBits(zcu)) continue;
13771367
13781368 if (need_comma) try w.writeByte(',');
13791369 need_comma = true;
......@@ -1396,7 +1386,7 @@ pub const DeclGen = struct {
13961386 const loaded_union = ip.loadUnionType(ty.toIntern());
13971387 if (un.tag == .none) {
13981388 const backing_ty = try ty.externUnionBackingType(pt);
1399 assert(loaded_union.flagsUnordered(ip).layout == .@"extern");
1389 assert(loaded_union.layout == .@"extern");
14001390 if (location == .StaticInitializer) {
14011391 return dg.fail("TODO: C backend: implement extern union backing type rendering in static initializers", .{});
14021392 }
......@@ -1418,9 +1408,9 @@ pub const DeclGen = struct {
14181408
14191409 const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;
14201410 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
1421 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
1411 const field_name = ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[field_index];
14221412
1423 const has_tag = loaded_union.hasTag(ip);
1413 const has_tag = loaded_union.has_runtime_tag;
14241414 if (has_tag) try w.writeByte('{');
14251415 const aggregate = ctype.info(ctype_pool).aggregate;
14261416 for (0..if (has_tag) aggregate.fields.len else 1) |outer_field_index| {
......@@ -1597,7 +1587,7 @@ pub const DeclGen = struct {
15971587 var need_comma = false;
15981588 while (field_it.next()) |field_index| {
15991589 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
1600 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1590 if (!field_ty.hasRuntimeBits(zcu)) continue;
16011591
16021592 if (need_comma) try w.writeByte(',');
16031593 need_comma = true;
......@@ -1620,7 +1610,7 @@ pub const DeclGen = struct {
16201610 for (0..tuple_info.types.len) |field_index| {
16211611 if (tuple_info.values.get(ip)[field_index] != .none) continue;
16221612 const field_ty: Type = .fromInterned(tuple_info.types.get(ip)[field_index]);
1623 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1613 if (!field_ty.hasRuntimeBits(zcu)) continue;
16241614
16251615 if (need_comma) try w.writeByte(',');
16261616 need_comma = true;
......@@ -1630,7 +1620,7 @@ pub const DeclGen = struct {
16301620 },
16311621 .union_type => {
16321622 const loaded_union = ip.loadUnionType(ty.toIntern());
1633 switch (loaded_union.flagsUnordered(ip).layout) {
1623 switch (loaded_union.layout) {
16341624 .auto, .@"extern" => {
16351625 if (!location.isInitializer()) {
16361626 try w.writeByte('(');
......@@ -1638,7 +1628,7 @@ pub const DeclGen = struct {
16381628 try w.writeByte(')');
16391629 }
16401630
1641 const has_tag = loaded_union.hasTag(ip);
1631 const has_tag = loaded_union.has_runtime_tag;
16421632 if (has_tag) try w.writeByte('{');
16431633 const aggregate = ctype.info(ctype_pool).aggregate;
16441634 for (0..if (has_tag) aggregate.fields.len else 1) |outer_field_index| {
......@@ -1649,7 +1639,7 @@ pub const DeclGen = struct {
16491639 .payload) {
16501640 .tag => try dg.renderUndefValue(
16511641 w,
1652 .fromInterned(loaded_union.enum_tag_ty),
1642 .fromInterned(loaded_union.enum_tag_type),
16531643 initializer_type,
16541644 ),
16551645 .payload => {
......@@ -1760,6 +1750,7 @@ pub const DeclGen = struct {
17601750 .opt,
17611751 .aggregate,
17621752 .un,
1753 .bitpack,
17631754 .memoized_call,
17641755 => unreachable, // values, not types
17651756 },
......@@ -2797,7 +2788,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
27972788 } });
27982789
27992790 try w.print("case {f}: {{", .{
2800 try o.dg.fmtIntLiteralDec(try tag_val.intFromEnum(enum_ty, pt), .Other),
2791 try o.dg.fmtIntLiteralDec(tag_val.intFromEnum(zcu), .Other),
28012792 });
28022793 o.indent();
28032794 try o.newline();
......@@ -3599,10 +3590,7 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
35993590 const zcu = f.object.dg.pt.zcu;
36003591 const inst_ty = f.typeOfIndex(inst);
36013592 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3602 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3603 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3604 return .none;
3605 }
3593 assert(inst_ty.hasRuntimeBits(zcu));
36063594
36073595 const ptr = try f.resolveInst(bin_op.lhs);
36083596 const index = try f.resolveInst(bin_op.rhs);
......@@ -3629,7 +3617,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
36293617
36303618 const inst_ty = f.typeOfIndex(inst);
36313619 const ptr_ty = f.typeOf(bin_op.lhs);
3632 const elem_has_bits = ptr_ty.indexableElem(zcu).hasRuntimeBitsIgnoreComptime(zcu);
3620 assert(ptr_ty.indexableElem(zcu).hasRuntimeBits(zcu));
36333621
36343622 const ptr = try f.resolveInst(bin_op.lhs);
36353623 const index = try f.resolveInst(bin_op.rhs);
......@@ -3643,16 +3631,14 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
36433631 try w.writeByte('(');
36443632 try f.renderType(w, inst_ty);
36453633 try w.writeByte(')');
3646 if (elem_has_bits) try w.writeByte('&');
3647 if (elem_has_bits and ptr_ty.ptrSize(zcu) == .one) {
3634 try w.writeByte('&');
3635 if (ptr_ty.ptrSize(zcu) == .one) {
36483636 // It's a pointer to an array, so we need to de-reference.
36493637 try f.writeCValueDeref(w, ptr);
36503638 } else try f.writeCValue(w, ptr, .Other);
3651 if (elem_has_bits) {
3652 try w.writeByte('[');
3653 try f.writeCValue(w, index, .Other);
3654 try w.writeByte(']');
3655 }
3639 try w.writeByte('[');
3640 try f.writeCValue(w, index, .Other);
3641 try w.writeByte(']');
36563642 try a.end(f, w);
36573643 return local;
36583644}
......@@ -3661,10 +3647,7 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
36613647 const zcu = f.object.dg.pt.zcu;
36623648 const inst_ty = f.typeOfIndex(inst);
36633649 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3664 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3665 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3666 return .none;
3667 }
3650 assert(inst_ty.hasRuntimeBits(zcu));
36683651
36693652 const slice = try f.resolveInst(bin_op.lhs);
36703653 const index = try f.resolveInst(bin_op.rhs);
......@@ -3692,7 +3675,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
36923675 const inst_ty = f.typeOfIndex(inst);
36933676 const slice_ty = f.typeOf(bin_op.lhs);
36943677 const elem_ty = slice_ty.childType(zcu);
3695 const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(zcu);
3678 assert(elem_ty.hasRuntimeBits(zcu));
36963679
36973680 const slice = try f.resolveInst(bin_op.lhs);
36983681 const index = try f.resolveInst(bin_op.rhs);
......@@ -3703,13 +3686,11 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
37033686 const a = try Assignment.start(f, w, try f.ctypeFromType(inst_ty, .complete));
37043687 try f.writeCValue(w, local, .Other);
37053688 try a.assign(f, w);
3706 if (elem_has_bits) try w.writeByte('&');
3689 try w.writeByte('&');
37073690 try f.writeCValueMember(w, slice, .{ .identifier = "ptr" });
3708 if (elem_has_bits) {
3709 try w.writeByte('[');
3710 try f.writeCValue(w, index, .Other);
3711 try w.writeByte(']');
3712 }
3691 try w.writeByte('[');
3692 try f.writeCValue(w, index, .Other);
3693 try w.writeByte(']');
37133694 try a.end(f, w);
37143695 return local;
37153696}
......@@ -3718,10 +3699,7 @@ fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
37183699 const zcu = f.object.dg.pt.zcu;
37193700 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
37203701 const inst_ty = f.typeOfIndex(inst);
3721 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3722 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3723 return .none;
3724 }
3702 assert(inst_ty.hasRuntimeBits(zcu));
37253703
37263704 const array = try f.resolveInst(bin_op.lhs);
37273705 const index = try f.resolveInst(bin_op.rhs);
......@@ -3853,10 +3831,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
38533831 // bit-pointers we see here are vector element pointers.
38543832 assert(ptr_info.packed_offset.host_size == 0 or ptr_info.flags.vector_index != .none);
38553833
3856 if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3857 try reap(f, inst, &.{ty_op.operand});
3858 return .none;
3859 }
3834 assert(src_ty.hasRuntimeBits(zcu));
38603835
38613836 const operand = try f.resolveInst(ty_op.operand);
38623837
......@@ -4456,7 +4431,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
44564431 const inst_ty = f.typeOfIndex(inst);
44574432 const inst_scalar_ty = inst_ty.scalarType(zcu);
44584433 const elem_ty = inst_scalar_ty.indexableElem(zcu);
4459 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return f.moveCValue(inst, inst_ty, lhs);
4434 assert(elem_ty.hasRuntimeBits(zcu));
44604435 const inst_scalar_ctype = try f.ctypeFromType(inst_scalar_ty, .complete);
44614436
44624437 const local = try f.allocLocal(inst, inst_ty);
......@@ -4787,7 +4762,7 @@ fn lowerBlock(f: *Function, inst: Air.Inst.Index, body: []const Air.Inst.Index)
47874762 const w = &f.object.code.writer;
47884763
47894764 const inst_ty = f.typeOfIndex(inst);
4790 const result = if (inst_ty.hasRuntimeBitsIgnoreComptime(zcu) and !f.liveness.isUnused(inst))
4765 const result = if (inst_ty.hasRuntimeBits(zcu) and !f.liveness.isUnused(inst))
47914766 try f.allocLocal(inst, inst_ty)
47924767 else
47934768 .none;
......@@ -4853,7 +4828,7 @@ fn lowerTry(
48534828 const liveness_condbr = f.liveness.getCondBr(inst);
48544829 const w = &f.object.code.writer;
48554830 const payload_ty = err_union_ty.errorUnionPayload(zcu);
4856 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
4831 const payload_has_bits = payload_ty.hasRuntimeBits(zcu);
48574832
48584833 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
48594834 try w.writeAll("if (");
......@@ -5393,7 +5368,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
53935368 const result = result: {
53945369 const w = &f.object.code.writer;
53955370 const inst_ty = f.typeOfIndex(inst);
5396 const inst_local = if (inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) local: {
5371 const inst_local = if (inst_ty.hasRuntimeBits(zcu)) local: {
53975372 const inst_local = try f.allocLocalValue(.{
53985373 .ctype = try f.ctypeFromType(inst_ty, .complete),
53995374 .alignas = CType.AlignAs.fromAbiAlignment(inst_ty.abiAlignment(zcu)),
......@@ -5820,12 +5795,12 @@ fn fieldLocation(
58205795 .struct_type => {
58215796 const loaded_struct = ip.loadStructType(container_ty.toIntern());
58225797 return switch (loaded_struct.layout) {
5823 .auto, .@"extern" => if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu))
5798 .auto, .@"extern" => if (!container_ty.hasRuntimeBits(zcu))
58245799 .begin
5825 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu))
5826 .{ .byte_offset = loaded_struct.offsets.get(ip)[field_index] }
5800 else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu))
5801 .{ .byte_offset = loaded_struct.field_offsets.get(ip)[field_index] }
58275802 else
5828 .{ .field = .{ .identifier = loaded_struct.fieldName(ip, field_index).toSlice(ip) } },
5803 .{ .field = .{ .identifier = loaded_struct.field_names.get(ip)[field_index].toSlice(ip) } },
58295804 .@"packed" => if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0)
58305805 .{ .byte_offset = @divExact(zcu.structPackedFieldBitOffset(loaded_struct, field_index) +
58315806 container_ptr_ty.ptrInfo(zcu).packed_offset.bit_offset, 8) }
......@@ -5833,24 +5808,24 @@ fn fieldLocation(
58335808 .begin,
58345809 };
58355810 },
5836 .tuple_type => return if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu))
5811 .tuple_type => return if (!container_ty.hasRuntimeBits(zcu))
58375812 .begin
5838 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu))
5813 else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu))
58395814 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }
58405815 else
58415816 .{ .field = .{ .field = field_index } },
58425817 .union_type => {
58435818 const loaded_union = ip.loadUnionType(container_ty.toIntern());
5844 switch (loaded_union.flagsUnordered(ip).layout) {
5819 switch (loaded_union.layout) {
58455820 .auto, .@"extern" => {
58465821 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
5847 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu))
5822 if (!field_ty.hasRuntimeBits(zcu))
58485823 return if (loaded_union.has_runtime_tag and !container_ty.unionHasAllZeroBitFieldTypes(zcu))
58495824 .{ .field = .{ .identifier = "payload" } }
58505825 else
58515826 .begin;
5852 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
5853 return .{ .field = if (loaded_union.hasTag(ip))
5827 const field_name = ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[field_index];
5828 return .{ .field = if (loaded_union.has_runtime_tag)
58545829 .{ .payload_identifier = field_name.toSlice(ip) }
58555830 else
58565831 .{ .identifier = field_name.toSlice(ip) } };
......@@ -5996,10 +5971,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
59965971 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
59975972
59985973 const inst_ty = f.typeOfIndex(inst);
5999 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
6000 try reap(f, inst, &.{extra.struct_operand});
6001 return .none;
6002 }
5974 assert(inst_ty.hasRuntimeBits(zcu));
60035975
60045976 const struct_byval = try f.resolveInst(extra.struct_operand);
60055977 try reap(f, inst, &.{extra.struct_operand});
......@@ -6014,9 +5986,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
60145986 .struct_type => .{ .identifier = struct_ty.structFieldName(extra.field_index, zcu).unwrap().?.toSlice(ip) },
60155987 .union_type => name: {
60165988 const union_type = ip.loadUnionType(struct_ty.toIntern());
6017 const enum_tag_ty: Type = .fromInterned(union_type.enum_tag_ty);
5989 const enum_tag_ty: Type = .fromInterned(union_type.enum_tag_type);
60185990 const field_name_str = enum_tag_ty.enumFieldName(extra.field_index, zcu).toSlice(ip);
6019 if (union_type.hasTag(ip)) {
5991 if (union_type.has_runtime_tag) {
60205992 break :name .{ .payload_identifier = field_name_str };
60215993 } else {
60225994 break :name .{ .identifier = field_name_str };
......@@ -6161,7 +6133,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
61616133
61626134 const inst_ty = f.typeOfIndex(inst);
61636135 const payload_ty = inst_ty.errorUnionPayload(zcu);
6164 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
6136 const repr_is_err = !payload_ty.hasRuntimeBits(zcu);
61656137 const err_ty = inst_ty.errorUnionSet(zcu);
61666138 const err = try f.resolveInst(ty_op.operand);
61676139 try reap(f, inst, &.{ty_op.operand});
......@@ -6210,7 +6182,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
62106182 try reap(f, inst, &.{ty_op.operand});
62116183
62126184 // First, set the non-error value.
6213 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
6185 if (!payload_ty.hasRuntimeBits(zcu)) {
62146186 const a = try Assignment.start(f, w, try f.ctypeFromType(operand_ty, .complete));
62156187 try f.writeCValueDeref(w, operand);
62166188 try a.assign(f, w);
......@@ -6262,13 +6234,13 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
62626234 const inst_ty = f.typeOfIndex(inst);
62636235 const payload_ty = inst_ty.errorUnionPayload(zcu);
62646236 const payload = try f.resolveInst(ty_op.operand);
6265 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
6237 assert(payload_ty.hasRuntimeBits(zcu));
62666238 const err_ty = inst_ty.errorUnionSet(zcu);
62676239 try reap(f, inst, &.{ty_op.operand});
62686240
62696241 const w = &f.object.code.writer;
62706242 const local = try f.allocLocal(inst, inst_ty);
6271 if (!repr_is_err) {
6243 {
62726244 const a = try Assignment.start(f, w, try f.ctypeFromType(payload_ty, .complete));
62736245 try f.writeCValueMember(w, local, .{ .identifier = "payload" });
62746246 try a.assign(f, w);
......@@ -6277,10 +6249,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
62776249 }
62786250 {
62796251 const a = try Assignment.start(f, w, try f.ctypeFromType(err_ty, .complete));
6280 if (repr_is_err)
6281 try f.writeCValue(w, local, .Other)
6282 else
6283 try f.writeCValueMember(w, local, .{ .identifier = "error" });
6252 try f.writeCValueMember(w, local, .{ .identifier = "error" });
62846253 try a.assign(f, w);
62856254 try f.object.dg.renderValue(w, try pt.intValue(try pt.errorIntType(), 0), .Other);
62866255 try a.end(f, w);
......@@ -7411,10 +7380,10 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
74117380 var field_it = loaded_struct.iterateRuntimeOrder(ip);
74127381 while (field_it.next()) |field_index| {
74137382 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
7414 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
7383 if (!field_ty.hasRuntimeBits(zcu)) continue;
74157384
74167385 const a = try Assignment.start(f, w, try f.ctypeFromType(field_ty, .complete));
7417 try f.writeCValueMember(w, local, .{ .identifier = loaded_struct.fieldName(ip, field_index).toSlice(ip) });
7386 try f.writeCValueMember(w, local, .{ .identifier = loaded_struct.field_names.get(ip)[field_index].toSlice(ip) });
74187387 try a.assign(f, w);
74197388 try f.writeCValue(w, resolved_elements[field_index], .Other);
74207389 try a.end(f, w);
......@@ -7426,7 +7395,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
74267395 .tuple_type => |tuple_info| for (0..tuple_info.types.len) |field_index| {
74277396 if (tuple_info.values.get(ip)[field_index] != .none) continue;
74287397 const field_ty: Type = .fromInterned(tuple_info.types.get(ip)[field_index]);
7429 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
7398 if (!field_ty.hasRuntimeBits(zcu)) continue;
74307399
74317400 const a = try Assignment.start(f, w, try f.ctypeFromType(field_ty, .complete));
74327401 try f.writeCValueMember(w, local, .{ .field = field_index });
......@@ -7449,13 +7418,13 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
74497418
74507419 const union_ty = f.typeOfIndex(inst);
74517420 const loaded_union = ip.loadUnionType(union_ty.toIntern());
7452 const field_name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index];
7421 const field_name = ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[extra.field_index];
74537422 const payload_ty = f.typeOf(extra.init);
74547423 const payload = try f.resolveInst(extra.init);
74557424 try reap(f, inst, &.{extra.init});
74567425
74577426 const w = &f.object.code.writer;
7458 if (loaded_union.flagsUnordered(ip).layout == .@"packed") return f.moveCValue(inst, union_ty, payload);
7427 if (loaded_union.layout == .@"packed") return f.moveCValue(inst, union_ty, payload);
74597428
74607429 const local = try f.allocLocal(inst, union_ty);
74617430
......@@ -7466,7 +7435,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
74667435 const a = try Assignment.start(f, w, try f.ctypeFromType(tag_ty, .complete));
74677436 try f.writeCValueMember(w, local, .{ .identifier = "tag" });
74687437 try a.assign(f, w);
7469 try w.print("{f}", .{try f.fmtIntLiteralDec(try tag_val.intFromEnum(tag_ty, pt))});
7438 try w.print("{f}", .{try f.fmtIntLiteralDec(tag_val.intFromEnum(zcu))});
74707439 try a.end(f, w);
74717440 break :field .{ .payload_identifier = field_name.toSlice(ip) };
74727441 } else .{ .identifier = field_name.toSlice(ip) };
src/codegen/c/Type.zig+30-29
......@@ -2558,7 +2558,7 @@ pub const Pool = struct {
25582558 .tag = .@"struct",
25592559 .name = .{ .index = ip_index },
25602560 });
2561 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))
2561 if (kind.isForward()) return if (ty.hasRuntimeBits(zcu))
25622562 fwd_decl
25632563 else
25642564 .void;
......@@ -2584,9 +2584,9 @@ pub const Pool = struct {
25842584 kind.noParameter(),
25852585 );
25862586 if (field_ctype.index == .void) continue;
2587 const field_name = try pool.string(allocator, loaded_struct.fieldName(ip, field_index).toSlice(ip));
2587 const field_name = try pool.string(allocator, loaded_struct.field_names.get(ip)[field_index].toSlice(ip));
25882588 const field_alignas = AlignAs.fromAlignment(.{
2589 .@"align" = loaded_struct.fieldAlign(ip, field_index),
2589 .@"align" = loaded_struct.field_aligns.getOrNone(ip, field_index),
25902590 .abi = field_type.abiAlignment(zcu),
25912591 });
25922592 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
......@@ -2613,7 +2613,7 @@ pub const Pool = struct {
26132613 .@"packed" => return pool.fromType(
26142614 allocator,
26152615 scratch,
2616 Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)),
2616 .fromInterned(loaded_struct.packed_backing_int_type),
26172617 pt,
26182618 mod,
26192619 kind,
......@@ -2682,17 +2682,17 @@ pub const Pool = struct {
26822682 },
26832683 .union_type => {
26842684 const loaded_union = ip.loadUnionType(ip_index);
2685 switch (loaded_union.flagsUnordered(ip).layout) {
2685 switch (loaded_union.layout) {
26862686 .auto, .@"extern" => {
26872687 const fwd_decl = try pool.getFwdDecl(allocator, .{
26882688 .tag = if (loaded_union.has_runtime_tag) .@"struct" else .@"union",
26892689 .name = .{ .index = ip_index },
26902690 });
2691 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))
2691 if (kind.isForward()) return if (ty.hasRuntimeBits(zcu))
26922692 fwd_decl
26932693 else
26942694 .void;
2695 const loaded_tag = loaded_union.loadTagType(ip);
2695 const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type);
26962696 const scratch_top = scratch.items.len;
26972697 defer scratch.shrinkRetainingCapacity(scratch_top);
26982698 try scratch.ensureUnusedCapacity(
......@@ -2718,10 +2718,10 @@ pub const Pool = struct {
27182718 if (field_ctype.index == .void) continue;
27192719 const field_name = try pool.string(
27202720 allocator,
2721 loaded_tag.names.get(ip)[field_index].toSlice(ip),
2721 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
27222722 );
27232723 const field_alignas = AlignAs.fromAlignment(.{
2724 .@"align" = loaded_union.fieldAlign(ip, field_index),
2724 .@"align" = loaded_union.field_aligns.getOrNone(ip, field_index),
27252725 .abi = field_type.abiAlignment(zcu),
27262726 });
27272727 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
......@@ -2753,24 +2753,22 @@ pub const Pool = struct {
27532753 try pool.ensureUnusedCapacity(allocator, 2);
27542754 var struct_fields: [2]Info.Field = undefined;
27552755 var struct_fields_len: usize = 0;
2756 if (loaded_tag.tag_ty != .comptime_int_type) {
2757 const tag_type = Type.fromInterned(loaded_tag.tag_ty);
2758 const tag_ctype: CType = try pool.fromType(
2759 allocator,
2760 scratch,
2761 tag_type,
2762 pt,
2763 mod,
2764 kind.noParameter(),
2765 );
2766 if (tag_ctype.index != .void) {
2767 struct_fields[struct_fields_len] = .{
2768 .name = .{ .index = .tag },
2769 .ctype = tag_ctype,
2770 .alignas = AlignAs.fromAbiAlignment(tag_type.abiAlignment(zcu)),
2771 };
2772 struct_fields_len += 1;
2773 }
2756 const tag_type = Type.fromInterned(loaded_tag.int_tag_type);
2757 const tag_ctype: CType = try pool.fromType(
2758 allocator,
2759 scratch,
2760 tag_type,
2761 pt,
2762 mod,
2763 kind.noParameter(),
2764 );
2765 if (tag_ctype.index != .void) {
2766 struct_fields[struct_fields_len] = .{
2767 .name = .{ .index = .tag },
2768 .ctype = tag_ctype,
2769 .alignas = AlignAs.fromAbiAlignment(tag_type.abiAlignment(zcu)),
2770 };
2771 struct_fields_len += 1;
27742772 }
27752773 if (fields_len > 0) {
27762774 const payload_ctype = payload_ctype: {
......@@ -2823,12 +2821,14 @@ pub const Pool = struct {
28232821 .enum_type => return pool.fromType(
28242822 allocator,
28252823 scratch,
2826 Type.fromInterned(ip.loadEnumType(ip_index).tag_ty),
2824 .fromInterned(ip.loadEnumType(ip_index).int_tag_type),
28272825 pt,
28282826 mod,
28292827 kind,
28302828 ),
2831 .func_type => |func_info| if (func_info.is_generic) return .void else {
2829 .func_type => |func_info| {
2830 if (!ty.fnHasRuntimeBits(zcu)) return .void;
2831
28322832 const scratch_top = scratch.items.len;
28332833 defer scratch.shrinkRetainingCapacity(scratch_top);
28342834 try scratch.ensureUnusedCapacity(allocator, func_info.param_types.len);
......@@ -2894,6 +2894,7 @@ pub const Pool = struct {
28942894 .opt,
28952895 .aggregate,
28962896 .un,
2897 .bitpack,
28972898 .memoized_call,
28982899 => unreachable, // values, not types
28992900 },
src/codegen/riscv64/CodeGen.zig+23-30
......@@ -3257,7 +3257,7 @@ fn airOptionalPayload(func: *Func, inst: Air.Inst.Index) !void {
32573257 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
32583258 const result: MCValue = result: {
32593259 const pl_ty = func.typeOfIndex(inst);
3260 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
3260 if (!pl_ty.hasRuntimeBits(zcu)) break :result .none;
32613261
32623262 const opt_mcv = try func.resolveInst(ty_op.operand);
32633263 if (func.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {
......@@ -3331,7 +3331,7 @@ fn airUnwrapErrErr(func: *Func, inst: Air.Inst.Index) !void {
33313331 break :result .{ .immediate = 0 };
33323332 }
33333333
3334 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3334 if (!payload_ty.hasRuntimeBits(zcu)) {
33353335 break :result operand;
33363336 }
33373337
......@@ -3384,7 +3384,7 @@ fn genUnwrapErrUnionPayloadMir(
33843384 const payload_ty = err_union_ty.errorUnionPayload(zcu);
33853385
33863386 const result: MCValue = result: {
3387 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
3387 if (!payload_ty.hasRuntimeBits(zcu)) break :result .none;
33883388
33893389 const payload_off: u31 = @intCast(errUnionPayloadOffset(payload_ty, zcu));
33903390 switch (err_union) {
......@@ -3547,7 +3547,7 @@ fn airWrapErrUnionPayload(func: *Func, inst: Air.Inst.Index) !void {
35473547 const operand = try func.resolveInst(ty_op.operand);
35483548
35493549 const result: MCValue = result: {
3550 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .{ .immediate = 0 };
3550 if (!pl_ty.hasRuntimeBits(zcu)) break :result .{ .immediate = 0 };
35513551
35523552 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
35533553 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
......@@ -3571,7 +3571,7 @@ fn airWrapErrUnionErr(func: *Func, inst: Air.Inst.Index) !void {
35713571 const err_ty = eu_ty.errorUnionSet(zcu);
35723572
35733573 const result: MCValue = result: {
3574 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result try func.resolveInst(ty_op.operand);
3574 if (!pl_ty.hasRuntimeBits(zcu)) break :result try func.resolveInst(ty_op.operand);
35753575
35763576 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
35773577 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
......@@ -3761,7 +3761,7 @@ fn airSliceElemVal(func: *Func, inst: Air.Inst.Index) !void {
37613761
37623762 const result: MCValue = result: {
37633763 const elem_ty = func.typeOfIndex(inst);
3764 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
3764 assert(elem_ty.hasRuntimeBits(zcu));
37653765
37663766 const slice_ty = func.typeOf(bin_op.lhs);
37673767 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);
......@@ -3914,7 +3914,7 @@ fn airPtrElemVal(func: *Func, inst: Air.Inst.Index) !void {
39143914
39153915 const result: MCValue = if (!is_volatile and func.liveness.isUnused(inst)) .unreach else result: {
39163916 const elem_ty = base_ptr_ty.indexableElem(zcu);
3917 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
3917 assert(elem_ty.hasRuntimeBits(zcu));
39183918 const base_ptr_mcv = try func.resolveInst(bin_op.lhs);
39193919 const base_ptr_lock: ?RegisterLock = switch (base_ptr_mcv) {
39203920 .register => |reg| func.register_manager.lockRegAssumeUnused(reg),
......@@ -4617,7 +4617,7 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
46174617 const src_mcv = try func.resolveInst(operand);
46184618 const struct_ty = func.typeOf(operand);
46194619 const field_ty = struct_ty.fieldType(index, zcu);
4620 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
4620 assert(field_ty.hasRuntimeBits(zcu));
46214621
46224622 const field_off: u32 = switch (struct_ty.containerLayout(zcu)) {
46234623 .auto, .@"extern" => @intCast(struct_ty.structFieldOffset(index, zcu) * 8),
......@@ -5126,7 +5126,6 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
51265126 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
51275127 const pt = func.pt;
51285128 const zcu = pt.zcu;
5129 const ip = &zcu.intern_pool;
51305129
51315130 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
51325131 const lhs_ty = func.typeOf(bin_op.lhs);
......@@ -5140,28 +5139,23 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
51405139 .optional,
51415140 .@"struct",
51425141 => {
5143 const int_ty = switch (lhs_ty.zigTypeTag(zcu)) {
5142 const int_ty: Type = switch (lhs_ty.zigTypeTag(zcu)) {
51445143 .@"enum" => lhs_ty.intTagType(zcu),
51455144 .int => lhs_ty,
5146 .bool => Type.u1,
5147 .pointer => Type.u64,
5148 .error_set => Type.anyerror,
5145 .bool => .u1,
5146 .pointer => .u64,
5147 .error_set => .anyerror,
51495148 .optional => blk: {
51505149 const payload_ty = lhs_ty.optionalChild(zcu);
5151 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5152 break :blk Type.u1;
5150 if (!payload_ty.hasRuntimeBits(zcu)) {
5151 break :blk .u1;
51535152 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
5154 break :blk Type.u64;
5153 break :blk .u64;
51555154 } else {
51565155 return func.fail("TODO riscv cmp non-pointer optionals", .{});
51575156 }
51585157 },
5159 .@"struct" => blk: {
5160 const struct_obj = ip.loadStructType(lhs_ty.toIntern());
5161 assert(struct_obj.layout == .@"packed");
5162 const backing_index = struct_obj.backingIntTypeUnordered(ip);
5163 break :blk Type.fromInterned(backing_index);
5164 },
5158 .@"struct", .@"union" => lhs_ty.bitpackBackingInt(zcu),
51655159 else => unreachable,
51665160 };
51675161
......@@ -5925,8 +5919,7 @@ fn airBr(func: *Func, inst: Air.Inst.Index) !void {
59255919 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;
59265920
59275921 const block_ty = func.typeOfIndex(br.block_inst);
5928 const block_unused =
5929 !block_ty.hasRuntimeBitsIgnoreComptime(zcu) or func.liveness.isUnused(br.block_inst);
5922 const block_unused = !block_ty.hasRuntimeBits(zcu) or func.liveness.isUnused(br.block_inst);
59305923 const block_tracking = func.inst_tracking.getPtr(br.block_inst).?;
59315924 const block_data = func.blocks.getPtr(br.block_inst).?;
59325925 const first_br = block_data.relocs.items.len == 0;
......@@ -8249,7 +8242,7 @@ fn resolveCallingConventionValues(
82498242 // Return values
82508243 if (ret_ty.zigTypeTag(zcu) == .noreturn) {
82518244 result.return_value = InstTracking.init(.unreach);
8252 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8245 } else if (!ret_ty.hasRuntimeBits(zcu)) {
82538246 result.return_value = InstTracking.init(.none);
82548247 } else {
82558248 var ret_tracking: [2]InstTracking = undefined;
......@@ -8300,7 +8293,7 @@ fn resolveCallingConventionValues(
83008293 var param_float_reg_i: usize = 0;
83018294
83028295 for (param_types, result.args) |ty, *arg| {
8303 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8296 if (!ty.hasRuntimeBits(zcu)) {
83048297 assert(cc == .auto);
83058298 arg.* = .none;
83068299 continue;
......@@ -8415,10 +8408,10 @@ fn hasFeature(func: *Func, feature: Target.riscv.Feature) bool {
84158408}
84168409
84178410pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {
8418 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
8411 if (!payload_ty.hasRuntimeBits(zcu)) return 0;
84198412 const payload_align = payload_ty.abiAlignment(zcu);
84208413 const error_align = Type.anyerror.abiAlignment(zcu);
8421 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8414 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBits(zcu)) {
84228415 return 0;
84238416 } else {
84248417 return payload_align.forward(Type.anyerror.abiSize(zcu));
......@@ -8426,10 +8419,10 @@ pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {
84268419}
84278420
84288421pub fn errUnionErrorOffset(payload_ty: Type, zcu: *Zcu) u64 {
8429 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
8422 if (!payload_ty.hasRuntimeBits(zcu)) return 0;
84308423 const payload_align = payload_ty.abiAlignment(zcu);
84318424 const error_align = Type.anyerror.abiAlignment(zcu);
8432 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8425 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBits(zcu)) {
84338426 return error_align.forward(payload_ty.abiSize(zcu));
84348427 } else {
84358428 return 0;
src/codegen/sparc64/CodeGen.zig+11-11
......@@ -1102,7 +1102,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
11021102fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !void {
11031103 try self.blocks.putNoClobber(self.gpa, inst, .{
11041104 // A block is a setup to be able to jump to the end.
1105 .relocs = .{},
1105 .relocs = .empty,
11061106 // It also acts as a receptacle for break operands.
11071107 // Here we use `MCValue.none` to represent a null value so that the first
11081108 // break instruction will choose a MCValue for the block result and overwrite
......@@ -1376,19 +1376,19 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
13761376 const rhs = try self.resolveInst(bin_op.rhs);
13771377 const lhs_ty = self.typeOf(bin_op.lhs);
13781378
1379 const int_ty = switch (lhs_ty.zigTypeTag(zcu)) {
1379 const int_ty: Type = switch (lhs_ty.zigTypeTag(zcu)) {
13801380 .vector => unreachable, // Handled by cmp_vector.
13811381 .@"enum" => lhs_ty.intTagType(zcu),
13821382 .int => lhs_ty,
1383 .bool => Type.u1,
1384 .pointer => Type.usize,
1385 .error_set => Type.u16,
1383 .bool => .u1,
1384 .pointer => .usize,
1385 .error_set => .u16,
13861386 .optional => blk: {
13871387 const payload_ty = lhs_ty.optionalChild(zcu);
1388 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1389 break :blk Type.u1;
1388 if (!payload_ty.hasRuntimeBits(zcu)) {
1389 break :blk .u1;
13901390 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
1391 break :blk Type.usize;
1391 break :blk .usize;
13921392 } else {
13931393 return self.fail("TODO SPARCv9 cmp non-pointer optionals", .{});
13941394 }
......@@ -3452,8 +3452,8 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
34523452 if (err_ty.errorSetIsEmpty(zcu)) {
34533453 return error_union_mcv;
34543454 }
3455 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3456 return MCValue.none;
3455 if (!payload_ty.hasRuntimeBits(zcu)) {
3456 return .none;
34573457 }
34583458
34593459 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, zcu));
......@@ -4481,7 +4481,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
44814481 const ty = self.typeOf(ref);
44824482
44834483 // If the type has no codegen bits, no need to store it.
4484 if (!ty.hasRuntimeBitsIgnoreComptime(pt.zcu)) return .none;
4484 if (!ty.hasRuntimeBits(pt.zcu)) return .none;
44854485
44864486 if (ref.toIndex()) |inst| {
44874487 return self.getResolvedInstValue(inst);
src/codegen/spirv/CodeGen.zig+50-65
......@@ -208,7 +208,7 @@ pub fn genNav(cg: *CodeGen, do_codegen: bool) Error!void {
208208 try cg.args.ensureUnusedCapacity(gpa, fn_info.param_types.len);
209209 for (fn_info.param_types.get(ip)) |param_ty_index| {
210210 const param_ty: Type = .fromInterned(param_ty_index);
211 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
211 if (!param_ty.hasRuntimeBits(zcu)) continue;
212212
213213 const param_type_id = try cg.resolveType(param_ty, .direct);
214214 const arg_result_id = cg.module.allocId();
......@@ -884,7 +884,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
884884 return try cg.constructComposite(comp_ty_id, &constituents);
885885 },
886886 .enum_tag => {
887 const int_val = try val.intFromEnum(ty, pt);
887 const int_val = val.intFromEnum(zcu);
888888 const int_ty = ty.intTagType(zcu);
889889 break :cache try cg.constant(int_ty, int_val, repr);
890890 },
......@@ -959,18 +959,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
959959 },
960960 .struct_type => {
961961 const struct_type = zcu.typeToStruct(ty).?;
962
963 if (struct_type.layout == .@"packed") {
964 // TODO: composite int
965 // TODO: endianness
966 const bits: u16 = @intCast(ty.bitSize(zcu));
967 const bytes = std.mem.alignForward(u16, cg.module.backingIntBits(bits).@"0", 8) / 8;
968 var limbs: [8]u8 = undefined;
969 @memset(&limbs, 0);
970 val.writeToPackedMemory(pt, limbs[0..bytes], 0) catch unreachable;
971 const backing_ty: Type = .fromInterned(struct_type.backingIntTypeUnordered(ip));
972 return try cg.constInt(backing_ty, @as(u64, @bitCast(limbs)));
973 }
962 assert(struct_type.layout != .@"packed"); // packed structs use `bitpack`
974963
975964 var types = std.array_list.Managed(Type).init(gpa);
976965 defer types.deinit();
......@@ -981,7 +970,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
981970 var it = struct_type.iterateRuntimeOrder(ip);
982971 while (it.next()) |field_index| {
983972 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
984 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
973 if (!field_ty.hasRuntimeBits(zcu)) {
985974 // This is a zero-bit field - we only needed it for the alignment.
986975 continue;
987976 }
......@@ -1001,20 +990,24 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
1001990 else => unreachable,
1002991 },
1003992 .un => |un| {
993 assert(ty.containerLayout(zcu) != .@"packed"); // packed unions use `bitpack`
1004994 if (un.tag == .none) {
1005 assert(ty.containerLayout(zcu) == .@"packed"); // TODO
1006 const int_ty = try pt.intType(.unsigned, @intCast(ty.bitSize(zcu)));
1007 return try cg.constInt(int_ty, Value.toUnsignedInt(.fromInterned(un.val), zcu));
995 @panic("TODO");
1008996 }
1009997 const active_field = ty.unionTagFieldIndex(.fromInterned(un.tag), zcu).?;
1010998 const union_obj = zcu.typeToUnion(ty).?;
1011999 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[active_field]);
1012 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(zcu))
1000 const payload = if (field_ty.hasRuntimeBits(zcu))
10131001 try cg.constant(field_ty, .fromInterned(un.val), .direct)
10141002 else
10151003 null;
10161004 return try cg.unionInit(ty, active_field, payload);
10171005 },
1006 .bitpack => |bitpack| {
1007 const int_val: Value = .fromInterned(bitpack.backing_int_val);
1008 break :cache try cg.constant(int_val.typeOf(zcu), int_val, repr);
1009 },
1010
10181011 .memoized_call => unreachable,
10191012 }
10201013 };
......@@ -1255,17 +1248,16 @@ fn resolveTypeName(cg: *CodeGen, ty: Type) ![]const u8 {
12551248fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {
12561249 const gpa = cg.module.gpa;
12571250 const zcu = cg.module.zcu;
1258 const ip = &zcu.intern_pool;
12591251 const union_obj = zcu.typeToUnion(ty).?;
12601252
1261 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1253 if (union_obj.layout == .@"packed") {
12621254 return try cg.module.intType(.unsigned, @intCast(ty.bitSize(zcu)));
12631255 }
12641256
12651257 const layout = cg.unionLayout(ty);
12661258 if (!layout.has_payload) {
12671259 // No payload, so represent this as just the tag type.
1268 return try cg.resolveType(.fromInterned(union_obj.enum_tag_ty), .indirect);
1260 return try cg.resolveType(.fromInterned(union_obj.enum_tag_type), .indirect);
12691261 }
12701262
12711263 var member_types: [4]Id = undefined;
......@@ -1274,7 +1266,7 @@ fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {
12741266 const u8_ty_id = try cg.resolveType(.u8, .direct);
12751267
12761268 if (layout.tag_size != 0) {
1277 const tag_ty_id = try cg.resolveType(.fromInterned(union_obj.enum_tag_ty), .indirect);
1269 const tag_ty_id = try cg.resolveType(.fromInterned(union_obj.enum_tag_type), .indirect);
12781270 member_types[layout.tag_index] = tag_ty_id;
12791271 member_names[layout.tag_index] = "(tag)";
12801272 }
......@@ -1315,7 +1307,7 @@ fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {
13151307
13161308fn resolveFnReturnType(cg: *CodeGen, ret_ty: Type) !Id {
13171309 const zcu = cg.module.zcu;
1318 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1310 if (!ret_ty.hasRuntimeBits(zcu)) {
13191311 // If the return type is an error set or an error union, then we make this
13201312 // anyerror return type instead, so that it can be coerced into a function
13211313 // pointer type which has anyerror as the return type.
......@@ -1389,7 +1381,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
13891381 return cg.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(zcu)});
13901382 };
13911383
1392 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1384 if (!elem_ty.hasRuntimeBits(zcu)) {
13931385 assert(repr == .indirect);
13941386 if (target.os.tag != .opencl) return cg.fail("cannot generate opaque type", .{});
13951387 return try cg.module.opaqueType("zero-sized-array");
......@@ -1453,7 +1445,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
14531445 var param_index: usize = 0;
14541446 for (fn_info.param_types.get(ip)) |param_ty_index| {
14551447 const param_ty: Type = .fromInterned(param_ty_index);
1456 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1448 if (!param_ty.hasRuntimeBits(zcu)) continue;
14571449
14581450 param_ty_ids[param_index] = try cg.resolveType(param_ty, .direct);
14591451 param_index += 1;
......@@ -1518,7 +1510,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
15181510 };
15191511
15201512 if (struct_type.layout == .@"packed") {
1521 return try cg.resolveType(.fromInterned(struct_type.backingIntTypeUnordered(ip)), .direct);
1513 return try cg.resolveType(.fromInterned(struct_type.packed_backing_int_type), .direct);
15221514 }
15231515
15241516 var member_types = std.array_list.Managed(Id).init(gpa);
......@@ -1533,9 +1525,9 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
15331525 var it = struct_type.iterateRuntimeOrder(ip);
15341526 while (it.next()) |field_index| {
15351527 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
1536 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1528 if (!field_ty.hasRuntimeBits(zcu)) continue;
15371529
1538 const field_name = struct_type.fieldName(ip, field_index);
1530 const field_name = struct_type.field_names.get(ip)[field_index];
15391531 try member_types.append(try cg.resolveType(field_ty, .indirect));
15401532 try member_names.append(field_name.toSlice(ip));
15411533 try member_offsets.append(@intCast(ty.structFieldOffset(field_index, zcu)));
......@@ -1556,7 +1548,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
15561548 },
15571549 .optional => {
15581550 const payload_ty = ty.optionalChild(zcu);
1559 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1551 if (!payload_ty.hasRuntimeBits(zcu)) {
15601552 // Just use a bool.
15611553 // Note: Always generate the bool with indirect format, to save on some sanity
15621554 // Perform the conversion to a direct bool when the field is extracted.
......@@ -1653,7 +1645,7 @@ fn errorUnionLayout(cg: *CodeGen, payload_ty: Type) ErrorUnionLayout {
16531645
16541646 const error_first = error_align.compare(.gt, payload_align);
16551647 return .{
1656 .payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu),
1648 .payload_has_bits = payload_ty.hasRuntimeBits(zcu),
16571649 .error_first = error_first,
16581650 };
16591651}
......@@ -3724,7 +3716,6 @@ fn cmp(
37243716 const gpa = cg.module.gpa;
37253717 const pt = cg.pt;
37263718 const zcu = cg.module.zcu;
3727 const ip = &zcu.intern_pool;
37283719 const scalar_ty = lhs.ty.scalarType(zcu);
37293720 const is_vector = lhs.ty.isVector(zcu);
37303721
......@@ -3737,7 +3728,7 @@ fn cmp(
37373728 },
37383729 .@"struct" => {
37393730 const struct_ty = zcu.typeToPackedStruct(scalar_ty).?;
3740 const ty: Type = .fromInterned(struct_ty.backingIntTypeUnordered(ip));
3731 const ty: Type = .fromInterned(struct_ty.packed_backing_int_type);
37413732 return try cg.cmp(op, lhs.pun(ty), rhs.pun(ty));
37423733 },
37433734 .error_set => {
......@@ -3778,7 +3769,7 @@ fn cmp(
37783769
37793770 const payload_ty = ty.optionalChild(zcu);
37803771 if (ty.optionalReprIsPayload(zcu)) {
3781 assert(payload_ty.hasRuntimeBitsIgnoreComptime(zcu));
3772 assert(payload_ty.hasRuntimeBits(zcu));
37823773 assert(!payload_ty.isSlice(zcu));
37833774
37843775 return try cg.cmp(op, lhs.pun(payload_ty), rhs.pun(payload_ty));
......@@ -3787,12 +3778,12 @@ fn cmp(
37873778 const lhs_id = try lhs.materialize(cg);
37883779 const rhs_id = try rhs.materialize(cg);
37893780
3790 const lhs_valid_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
3781 const lhs_valid_id = if (payload_ty.hasRuntimeBits(zcu))
37913782 try cg.extractField(.bool, lhs_id, 1)
37923783 else
37933784 try cg.convertToDirect(.bool, lhs_id);
37943785
3795 const rhs_valid_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
3786 const rhs_valid_id = if (payload_ty.hasRuntimeBits(zcu))
37963787 try cg.extractField(.bool, rhs_id, 1)
37973788 else
37983789 try cg.convertToDirect(.bool, rhs_id);
......@@ -3800,7 +3791,7 @@ fn cmp(
38003791 const lhs_valid: Temporary = .init(.bool, lhs_valid_id);
38013792 const rhs_valid: Temporary = .init(.bool, rhs_valid_id);
38023793
3803 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3794 if (!payload_ty.hasRuntimeBits(zcu)) {
38043795 return try cg.cmp(op, lhs_valid, rhs_valid);
38053796 }
38063797
......@@ -4138,7 +4129,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
41384129 const array_ptr_id = try cg.resolve(ty_op.operand);
41394130 const len_id = try cg.constInt(.usize, array_ty.arrayLen(zcu));
41404131
4141 const elem_ptr_id = if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))
4132 const elem_ptr_id = if (!array_ty.hasRuntimeBits(zcu))
41424133 // Note: The pointer is something like *opaque{}, so we need to bitcast it to the element type.
41434134 try cg.bitCast(elem_ptr_ty, array_ptr_ty, array_ptr_id)
41444135 else
......@@ -4174,12 +4165,12 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
41744165 .@"struct" => {
41754166 if (zcu.typeToPackedStruct(result_ty)) |struct_type| {
41764167 comptime assert(Type.packed_struct_layout_version == 2);
4177 const backing_int_ty: Type = .fromInterned(struct_type.backingIntTypeUnordered(ip));
4168 const backing_int_ty: Type = .fromInterned(struct_type.packed_backing_int_type);
41784169 var running_int_id = try cg.constInt(backing_int_ty, 0);
41794170 var running_bits: u16 = 0;
41804171 for (struct_type.field_types.get(ip), elements) |field_ty_ip, element| {
41814172 const field_ty: Type = .fromInterned(field_ty_ip);
4182 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
4173 if (!field_ty.hasRuntimeBits(zcu)) continue;
41834174 const field_id = try cg.resolve(element);
41844175 const ty_bit_size: u16 = @intCast(field_ty.bitSize(zcu));
41854176 const field_int_ty = try cg.pt.intType(.unsigned, ty_bit_size);
......@@ -4239,7 +4230,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
42394230 const field_index = it.next().?;
42404231 if ((try result_ty.structFieldValueComptime(pt, i)) != null) continue;
42414232 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
4242 assert(field_ty.hasRuntimeBitsIgnoreComptime(zcu));
4233 assert(field_ty.hasRuntimeBits(zcu));
42434234
42444235 const id = try cg.resolve(element);
42454236 types[index] = field_ty;
......@@ -4399,10 +4390,7 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
43994390 const elem_ty = src_ptr_ty.childType(zcu);
44004391 const ptr_id = try cg.resolve(bin_op.lhs);
44014392
4402 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4403 const dst_ptr_ty = cg.typeOfIndex(inst);
4404 return try cg.bitCast(dst_ptr_ty, src_ptr_ty, ptr_id);
4405 }
4393 assert(elem_ty.hasRuntimeBits(zcu));
44064394
44074395 const index_id = try cg.resolve(bin_op.rhs);
44084396 return try cg.ptrElemPtr(src_ptr_ty, ptr_id, index_id);
......@@ -4526,13 +4514,13 @@ fn unionInit(
45264514 const zcu = cg.module.zcu;
45274515 const ip = &zcu.intern_pool;
45284516 const union_ty = zcu.typeToUnion(ty).?;
4529 const tag_ty: Type = .fromInterned(union_ty.enum_tag_ty);
4517 const tag_ty: Type = .fromInterned(union_ty.enum_tag_type);
45304518
45314519 const layout = cg.unionLayout(ty);
45324520 const payload_ty: Type = .fromInterned(union_ty.field_types.get(ip)[active_field]);
45334521
4534 if (union_ty.flagsUnordered(ip).layout == .@"packed") {
4535 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4522 if (union_ty.layout == .@"packed") {
4523 if (!payload_ty.hasRuntimeBits(zcu)) {
45364524 const int_ty = try pt.intType(.unsigned, @intCast(ty.bitSize(zcu)));
45374525 return cg.constInt(int_ty, 0);
45384526 }
......@@ -4558,7 +4546,7 @@ fn unionInit(
45584546
45594547 const tag_int = if (layout.tag_size != 0) blk: {
45604548 const tag_val = try pt.enumValueFieldIndex(tag_ty, active_field);
4561 const tag_int_val = try tag_val.intFromEnum(tag_ty, pt);
4549 const tag_int_val = tag_val.intFromEnum(zcu);
45624550 break :blk tag_int_val.toUnsignedInt(zcu);
45634551 } else 0;
45644552
......@@ -4577,7 +4565,7 @@ fn unionInit(
45774565 try cg.store(tag_ty, ptr_id, tag_id, .{});
45784566 }
45794567
4580 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4568 if (payload_ty.hasRuntimeBits(zcu)) {
45814569 const layout_payload_ty_id = try cg.resolveType(layout.payload_ty, .indirect);
45824570 const pl_ptr_ty_id = try cg.module.ptrType(layout_payload_ty_id, .function);
45834571 const pl_ptr_id = try cg.accessChain(pl_ptr_ty_id, tmp_id, &.{layout.payload_index});
......@@ -4613,7 +4601,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
46134601
46144602 const union_obj = zcu.typeToUnion(ty).?;
46154603 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
4616 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(zcu))
4604 const payload = if (field_ty.hasRuntimeBits(zcu))
46174605 try cg.resolve(extra.init)
46184606 else
46194607 null;
......@@ -4631,7 +4619,7 @@ fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
46314619 const field_index = struct_field.field_index;
46324620 const field_ty = object_ty.fieldType(field_index, zcu);
46334621
4634 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) return null;
4622 assert(field_ty.hasRuntimeBits(zcu));
46354623
46364624 switch (object_ty.zigTypeTag(zcu)) {
46374625 .@"struct" => switch (object_ty.containerLayout(zcu)) {
......@@ -5332,7 +5320,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) !void {
53325320 const zcu = cg.module.zcu;
53335321 const operand = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
53345322 const ret_ty = cg.typeOf(operand);
5335 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5323 if (!ret_ty.hasRuntimeBits(zcu)) {
53365324 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;
53375325 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
53385326 // Functions with an empty error set are emitted with an error code
......@@ -5356,7 +5344,7 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void {
53565344 const ptr_ty = cg.typeOf(un_op);
53575345 const ret_ty = ptr_ty.childType(zcu);
53585346
5359 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5347 if (!ret_ty.hasRuntimeBits(zcu)) {
53605348 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;
53615349 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
53625350 // Functions with an empty error set are emitted with an error code
......@@ -5573,7 +5561,7 @@ fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum {
55735561
55745562 const is_non_null_id = blk: {
55755563 if (is_pointer) {
5576 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5564 if (payload_ty.hasRuntimeBits(zcu)) {
55775565 const storage_class = cg.module.storageClass(operand_ty.ptrAddressSpace(zcu));
55785566 const bool_indirect_ty_id = try cg.resolveType(.bool, .indirect);
55795567 const bool_ptr_ty_id = try cg.module.ptrType(bool_indirect_ty_id, storage_class);
......@@ -5584,7 +5572,7 @@ fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum {
55845572 break :blk try cg.load(.bool, operand_id, .{});
55855573 }
55865574
5587 break :blk if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
5575 break :blk if (payload_ty.hasRuntimeBits(zcu))
55885576 try cg.extractField(.bool, operand_id, 1)
55895577 else
55905578 // Optional representation is bool indicating whether the optional is set
......@@ -5653,7 +5641,7 @@ fn airUnwrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
56535641 const optional_ty = cg.typeOf(ty_op.operand);
56545642 const payload_ty = cg.typeOfIndex(inst);
56555643
5656 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return null;
5644 if (!payload_ty.hasRuntimeBits(zcu)) return null;
56575645
56585646 if (optional_ty.optionalReprIsPayload(zcu)) {
56595647 return operand_id;
......@@ -5672,7 +5660,7 @@ fn airUnwrapOptionalPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
56725660 const result_ty = cg.typeOfIndex(inst);
56735661 const result_ty_id = try cg.resolveType(result_ty, .direct);
56745662
5675 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5663 if (!payload_ty.hasRuntimeBits(zcu)) {
56765664 // There is no payload, but we still need to return a valid pointer.
56775665 // We can just return anything here, so just return a pointer to the operand.
56785666 return try cg.bitCast(result_ty, operand_ty, operand_id);
......@@ -5691,9 +5679,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
56915679 const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56925680 const payload_ty = cg.typeOf(ty_op.operand);
56935681
5694 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5695 return try cg.constBool(true, .indirect);
5696 }
5682 assert(payload_ty.hasRuntimeBits(zcu));
56975683
56985684 const operand_id = try cg.resolve(ty_op.operand);
56995685
......@@ -5789,8 +5775,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) !void {
57895775 const int_val: u64 = switch (cond_ty.zigTypeTag(zcu)) {
57905776 .bool, .int => if (cond_ty.isSignedInt(zcu)) @bitCast(value.toSignedInt(zcu)) else value.toUnsignedInt(zcu),
57915777 .@"enum" => blk: {
5792 // TODO: figure out of cond_ty is correct (something with enum literals)
5793 break :blk (try value.intFromEnum(cond_ty, pt)).toUnsignedInt(zcu); // TODO: composite integer constants
5778 break :blk value.intFromEnum(zcu).toUnsignedInt(zcu); // TODO: composite integer constants
57945779 },
57955780 .error_set => value.getErrorInt(zcu),
57965781 .pointer => value.toUnsignedInt(zcu),
......@@ -6067,7 +6052,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
60676052 // before starting to emit OpFunctionCall instructions. Hence the
60686053 // temporary params buffer.
60696054 const arg_ty = cg.typeOf(arg);
6070 if (!arg_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
6055 if (!arg_ty.hasRuntimeBits(zcu)) continue;
60716056 const arg_id = try cg.resolve(arg);
60726057
60736058 params[n_params] = arg_id;
......@@ -6081,7 +6066,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
60816066 .id_ref_3 = params[0..n_params],
60826067 });
60836068
6084 if (cg.liveness.isUnused(inst) or !Type.fromInterned(return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
6069 if (cg.liveness.isUnused(inst) or !Type.fromInterned(return_type).hasRuntimeBits(zcu)) {
60856070 return null;
60866071 }
60876072
src/codegen/wasm/CodeGen.zig+77-142
......@@ -759,7 +759,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
759759 const zcu = pt.zcu;
760760 const val = (try cg.air.value(ref, pt)).?;
761761 const ty = cg.typeOf(ref);
762 if (!ty.hasRuntimeBitsIgnoreComptime(zcu) and !ty.isInt(zcu) and !ty.isError(zcu)) {
762 if (!ty.hasRuntimeBits(zcu) and !ty.isInt(zcu) and !ty.isError(zcu)) {
763763 gop.value_ptr.* = .none;
764764 return .none;
765765 }
......@@ -773,7 +773,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
773773 const result: WValue = if (isByRef(ty, zcu, cg.target))
774774 .{ .uav_ref = .{ .ip_index = val.toIntern() } }
775775 else
776 try cg.lowerConstant(val, ty);
776 try cg.lowerConstant(val);
777777
778778 gop.value_ptr.* = result;
779779 return result;
......@@ -786,7 +786,7 @@ fn resolveValue(cg: *CodeGen, val: Value) InnerError!WValue {
786786 return if (isByRef(ty, zcu, cg.target))
787787 .{ .uav_ref = .{ .ip_index = val.toIntern() } }
788788 else
789 try cg.lowerConstant(val, ty);
789 try cg.lowerConstant(val);
790790}
791791
792792/// NOTE: if result == .stack, it will be stored in .local
......@@ -980,7 +980,6 @@ fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
980980
981981/// For `std.builtin.CallingConvention.auto`.
982982pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.wasm.Valtype {
983 const ip = &zcu.intern_pool;
984983 return switch (ty.zigTypeTag(zcu)) {
985984 .float => switch (ty.floatBits(target)) {
986985 16 => .i32, // stored/loaded as u16
......@@ -994,25 +993,13 @@ pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.w
994993 33...64 => .i64,
995994 else => .i32,
996995 },
997 .@"struct" => blk: {
998 if (zcu.typeToPackedStruct(ty)) |packed_struct| {
999 const backing_int_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
1000 break :blk typeToValtype(backing_int_ty, zcu, target);
1001 } else {
1002 break :blk .i32;
1003 }
1004 },
1005996 .vector => switch (CodeGen.determineSimdStoreStrategy(ty, zcu, target)) {
1006997 .direct => .v128,
1007998 .unrolled => .i32,
1008999 },
1009 .@"union" => switch (ty.containerLayout(zcu)) {
1010 .@"packed" => switch (ty.bitSize(zcu)) {
1011 0...32 => .i32,
1012 33...64 => .i64,
1013 else => .i32,
1014 },
1015 else => .i32,
1000 .@"union", .@"struct" => switch (ty.containerLayout(zcu)) {
1001 .@"packed" => typeToValtype(ty.bitpackBackingInt(zcu), zcu, target),
1002 .auto, .@"extern" => .i32,
10161003 },
10171004 else => .i32, // all represented as reference/immediate
10181005 };
......@@ -1185,7 +1172,7 @@ pub fn generate(
11851172 const fn_ty = zcu.navValue(cg.owner_nav).typeOf(zcu);
11861173 const fn_info = zcu.typeToFunc(fn_ty).?;
11871174 const ret_ty: Type = .fromInterned(fn_info.return_type);
1188 const any_returns = !firstParamSRet(fn_info.cc, ret_ty, zcu, target) and ret_ty.hasRuntimeBitsIgnoreComptime(zcu);
1175 const any_returns = !firstParamSRet(fn_info.cc, ret_ty, zcu, target) and ret_ty.hasRuntimeBits(zcu);
11891176
11901177 var cc_result = try resolveCallingConventionValues(zcu, fn_ty, target);
11911178 defer cc_result.deinit(gpa);
......@@ -1244,7 +1231,7 @@ fn generateInner(cg: *CodeGen, any_returns: bool) InnerError!Mir {
12441231 if (any_returns and cg.air.instructions.len > 0) {
12451232 const inst: Air.Inst.Index = @enumFromInt(cg.air.instructions.len - 1);
12461233 const last_inst_ty = cg.typeOfIndex(inst);
1247 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1234 if (!last_inst_ty.hasRuntimeBits(zcu)) {
12481235 try cg.addTag(.@"unreachable");
12491236 }
12501237 }
......@@ -1316,7 +1303,7 @@ fn resolveCallingConventionValues(
13161303 switch (cc) {
13171304 .auto => {
13181305 for (fn_info.param_types.get(ip)) |ty| {
1319 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(zcu)) {
1306 if (!Type.fromInterned(ty).hasRuntimeBits(zcu)) {
13201307 continue;
13211308 }
13221309
......@@ -1326,7 +1313,7 @@ fn resolveCallingConventionValues(
13261313 },
13271314 .wasm_mvp => {
13281315 for (fn_info.param_types.get(ip)) |ty| {
1329 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(zcu)) {
1316 if (!Type.fromInterned(ty).hasRuntimeBits(zcu)) {
13301317 continue;
13311318 }
13321319 switch (abi.classifyType(.fromInterned(ty), zcu)) {
......@@ -1357,7 +1344,7 @@ pub fn firstParamSRet(
13571344 zcu: *const Zcu,
13581345 target: *const std.Target,
13591346) bool {
1360 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) return false;
1347 if (!return_type.hasRuntimeBits(zcu)) return false;
13611348 switch (cc) {
13621349 .@"inline" => unreachable,
13631350 .auto => return isByRef(return_type, zcu, target),
......@@ -1457,7 +1444,7 @@ fn restoreStackPointer(cg: *CodeGen) !void {
14571444fn allocStack(cg: *CodeGen, ty: Type) !WValue {
14581445 const pt = cg.pt;
14591446 const zcu = pt.zcu;
1460 assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
1447 assert(ty.hasRuntimeBits(zcu));
14611448 if (cg.initial_stack_value == .none) {
14621449 try cg.initializeStack();
14631450 }
......@@ -1491,7 +1478,7 @@ fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue {
14911478 try cg.initializeStack();
14921479 }
14931480
1494 if (!pointee_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1481 if (!pointee_ty.hasRuntimeBits(zcu)) {
14951482 return cg.allocStack(Type.usize); // create a value containing just the stack pointer.
14961483 }
14971484
......@@ -1676,7 +1663,6 @@ fn ptrSize(cg: *const CodeGen) u16 {
16761663/// For a given `Type`, will return true when the type will be passed
16771664/// by reference, rather than by value
16781665fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
1679 const ip = &zcu.intern_pool;
16801666 switch (ty.zigTypeTag(zcu)) {
16811667 .type,
16821668 .comptime_int,
......@@ -1697,20 +1683,10 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
16971683
16981684 .array,
16991685 .frame,
1700 => return ty.hasRuntimeBitsIgnoreComptime(zcu),
1701 .@"union" => {
1702 if (zcu.typeToUnion(ty)) |union_obj| {
1703 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1704 return ty.abiSize(zcu) > 8;
1705 }
1706 }
1707 return ty.hasRuntimeBitsIgnoreComptime(zcu);
1708 },
1709 .@"struct" => {
1710 if (zcu.typeToPackedStruct(ty)) |packed_struct| {
1711 return isByRef(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), zcu, target);
1712 }
1713 return ty.hasRuntimeBitsIgnoreComptime(zcu);
1686 => return ty.hasRuntimeBits(zcu),
1687 .@"struct", .@"union" => switch (ty.containerLayout(zcu)) {
1688 .@"packed" => return isByRef(ty.bitpackBackingInt(zcu), zcu, target),
1689 .@"extern", .auto => return ty.hasRuntimeBits(zcu),
17141690 },
17151691 .vector => return determineSimdStoreStrategy(ty, zcu, target) == .unrolled,
17161692 .int => return ty.intInfo(zcu).bits > 64,
......@@ -1718,7 +1694,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
17181694 .float => return ty.floatBits(target) > 64,
17191695 .error_union => {
17201696 const pl_ty = ty.errorUnionPayload(zcu);
1721 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1697 if (!pl_ty.hasRuntimeBits(zcu)) {
17221698 return false;
17231699 }
17241700 return true;
......@@ -1727,7 +1703,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
17271703 if (ty.isPtrLikeOptional(zcu)) return false;
17281704 const pl_type = ty.optionalChild(zcu);
17291705 if (pl_type.zigTypeTag(zcu) == .error_set) return false;
1730 return pl_type.hasRuntimeBitsIgnoreComptime(zcu);
1706 return pl_type.hasRuntimeBits(zcu);
17311707 },
17321708 .pointer => {
17331709 // Slices act like struct and will be passed by reference
......@@ -2069,7 +2045,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20692045 // to the stack instead
20702046 if (cg.return_value != .none) {
20712047 try cg.store(cg.return_value, operand, ret_ty, 0);
2072 } else if (fn_info.cc == .wasm_mvp and ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2048 } else if (fn_info.cc == .wasm_mvp and ret_ty.hasRuntimeBits(zcu)) {
20732049 switch (abi.classifyType(ret_ty, zcu)) {
20742050 .direct => |scalar_type| {
20752051 assert(!abi.lowerAsDoubleI64(scalar_type, zcu));
......@@ -2082,7 +2058,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20822058 .indirect => unreachable,
20832059 }
20842060 } else {
2085 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and ret_ty.isError(zcu)) {
2061 if (!ret_ty.hasRuntimeBits(zcu) and ret_ty.isError(zcu)) {
20862062 try cg.addImm32(0);
20872063 } else {
20882064 try cg.emitWValue(operand);
......@@ -2121,7 +2097,7 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21212097 const ret_ty = cg.typeOf(un_op).childType(zcu);
21222098
21232099 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;
2124 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2100 if (!ret_ty.hasRuntimeBits(zcu)) {
21252101 if (ret_ty.isError(zcu)) {
21262102 try cg.addImm32(0);
21272103 }
......@@ -2177,7 +2153,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
21772153 const arg_val = try cg.resolveInst(arg);
21782154
21792155 const arg_ty = cg.typeOf(arg);
2180 if (!arg_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
2156 if (!arg_ty.hasRuntimeBits(zcu)) continue;
21812157
21822158 try cg.lowerArg(zcu.typeToFunc(fn_ty).?.cc, arg_ty, arg_val);
21832159 }
......@@ -2199,7 +2175,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
21992175 }
22002176
22012177 const result_value = result_value: {
2202 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and !ret_ty.isError(zcu)) {
2178 if (!ret_ty.hasRuntimeBits(zcu) and !ret_ty.isError(zcu)) {
22032179 break :result_value .none;
22042180 } else if (first_param_sret) {
22052181 break :result_value sret;
......@@ -2320,12 +2296,12 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErr
23202296 const zcu = pt.zcu;
23212297 const abi_size = ty.abiSize(zcu);
23222298
2323 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
2299 if (!ty.hasRuntimeBits(zcu)) return;
23242300
23252301 switch (ty.zigTypeTag(zcu)) {
23262302 .error_union => {
23272303 const pl_ty = ty.errorUnionPayload(zcu);
2328 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2304 if (!pl_ty.hasRuntimeBits(zcu)) {
23292305 return cg.store(lhs, rhs, Type.anyerror, offset);
23302306 }
23312307
......@@ -2338,7 +2314,7 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErr
23382314 return cg.store(lhs, rhs, Type.usize, offset);
23392315 }
23402316 const pl_ty = ty.optionalChild(zcu);
2341 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2317 if (!pl_ty.hasRuntimeBits(zcu)) {
23422318 return cg.store(lhs, rhs, Type.u8, offset);
23432319 }
23442320 if (pl_ty.zigTypeTag(zcu) == .error_set) {
......@@ -2438,7 +2414,7 @@ fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
24382414 const ptr_ty = cg.typeOf(ty_op.operand);
24392415 const ptr_info = ptr_ty.ptrInfo(zcu);
24402416
2441 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return cg.finishAir(inst, .none, &.{ty_op.operand});
2417 if (!ty.hasRuntimeBits(zcu)) return cg.finishAir(inst, .none, &.{ty_op.operand});
24422418
24432419 const result = result: {
24442420 if (isByRef(ty, zcu, cg.target)) {
......@@ -3089,7 +3065,7 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro
30893065 return switch (ptr.base_addr) {
30903066 .nav => |nav| return .{ .nav_ref = .{ .nav_index = nav, .offset = @intCast(offset) } },
30913067 .uav => |uav| return .{ .uav_ref = .{ .ip_index = uav.val, .offset = @intCast(offset), .orig_ptr_ty = uav.orig_ty } },
3092 .int => return cg.lowerConstant(try pt.intValue(Type.usize, offset), Type.usize),
3068 .int => return cg.lowerConstant(try pt.intValue(.usize, offset)),
30933069 .eu_payload => |eu_ptr| try cg.lowerPtr(
30943070 eu_ptr,
30953071 offset + codegen.errUnionPayloadOffset(
......@@ -3126,10 +3102,11 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro
31263102 };
31273103}
31283104
3129/// Asserts that `isByRef` returns `false` for `ty`.
3130fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3105/// Asserts that `isByRef` returns `false` for `val.typeOf(zcu)`.
3106fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue {
31313107 const pt = cg.pt;
31323108 const zcu = pt.zcu;
3109 const ty = val.typeOf(zcu);
31333110 assert(!isByRef(ty, zcu, cg.target));
31343111 const ip = &zcu.intern_pool;
31353112 if (val.isUndef(zcu)) return cg.emitUndefined(ty);
......@@ -3191,31 +3168,22 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {
31913168 },
31923169 .error_union => |error_union| {
31933170 const err_int_ty = try pt.errorIntType();
3194 const err_ty, const err_val = switch (error_union.val) {
3195 .err_name => |err_name| .{
3196 ty.errorUnionSet(zcu),
3197 Value.fromInterned(try pt.intern(.{ .err = .{
3198 .ty = ty.errorUnionSet(zcu).toIntern(),
3199 .name = err_name,
3200 } })),
3201 },
3202 .payload => .{
3203 err_int_ty,
3204 try pt.intValue(err_int_ty, 0),
3205 },
3171 const err_val: Value = switch (error_union.val) {
3172 .err_name => |err_name| .fromInterned(try pt.intern(.{ .err = .{
3173 .ty = ty.errorUnionSet(zcu).toIntern(),
3174 .name = err_name,
3175 } })),
3176 .payload => try pt.intValue(err_int_ty, 0),
32063177 };
32073178 const payload_type = ty.errorUnionPayload(zcu);
3208 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
3179 if (!payload_type.hasRuntimeBits(zcu)) {
32093180 // We use the error type directly as the type.
3210 return cg.lowerConstant(err_val, err_ty);
3181 return cg.lowerConstant(err_val);
32113182 }
32123183
32133184 return cg.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});
32143185 },
3215 .enum_tag => |enum_tag| {
3216 const int_tag_ty = ip.typeOf(enum_tag.int);
3217 return cg.lowerConstant(Value.fromInterned(enum_tag.int), Type.fromInterned(int_tag_ty));
3218 },
3186 .enum_tag => |enum_tag| return cg.lowerConstant(.fromInterned(enum_tag.int)),
32193187 .float => |float| switch (float.storage) {
32203188 .f16 => |f16_val| return .{ .imm32 = @as(u16, @bitCast(f16_val)) },
32213189 .f32 => |f32_val| return .{ .float32 = f32_val },
......@@ -3225,9 +3193,8 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {
32253193 .slice => unreachable, // isByRef == true
32263194 .ptr => return cg.lowerPtr(val.toIntern(), 0),
32273195 .opt => if (ty.optionalReprIsPayload(zcu)) {
3228 const pl_ty = ty.optionalChild(zcu);
32293196 if (val.optionalValue(zcu)) |payload| {
3230 return cg.lowerConstant(payload, pl_ty);
3197 return cg.lowerConstant(payload);
32313198 } else {
32323199 return .{ .imm32 = 0 };
32333200 }
......@@ -3242,33 +3209,11 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {
32423209 val.writeToMemory(pt, &buf) catch unreachable;
32433210 return cg.storeSimdImmd(buf);
32443211 },
3245 .struct_type => {
3246 const struct_type = ip.loadStructType(ty.toIntern());
3247 // non-packed structs are not handled in this function because they
3248 // are by-ref types.
3249 assert(struct_type.layout == .@"packed");
3250 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer
3251 val.writeToPackedMemory(pt, &buf, 0) catch unreachable;
3252 const backing_int_ty = Type.fromInterned(struct_type.backingIntTypeUnordered(ip));
3253 const int_val = try pt.intValue(
3254 backing_int_ty,
3255 mem.readInt(u64, &buf, .little),
3256 );
3257 return cg.lowerConstant(int_val, backing_int_ty);
3258 },
3212 .struct_type => unreachable, // packed structs use `bitpack`
32593213 else => unreachable,
32603214 },
3261 .un => {
3262 const int_type = try pt.intType(.unsigned, @intCast(ty.bitSize(zcu)));
3263
3264 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer
3265 val.writeToPackedMemory(pt, &buf, 0) catch unreachable;
3266 const int_val = try pt.intValue(
3267 int_type,
3268 mem.readInt(u64, &buf, .little),
3269 );
3270 return cg.lowerConstant(int_val, int_type);
3271 },
3215 .un => unreachable, // packed unions use `bitpack`
3216 .bitpack => |bitpack| return cg.lowerConstant(.fromInterned(bitpack.backing_int_val)),
32723217 .memoized_call => unreachable,
32733218 }
32743219}
......@@ -3283,7 +3228,6 @@ fn storeSimdImmd(cg: *CodeGen, value: [16]u8) !WValue {
32833228
32843229fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {
32853230 const zcu = cg.pt.zcu;
3286 const ip = &zcu.intern_pool;
32873231 switch (ty.zigTypeTag(zcu)) {
32883232 .bool, .error_set => return .{ .imm32 = 0xaaaaaaaa },
32893233 .int, .@"enum" => switch (ty.intInfo(zcu).bits) {
......@@ -3311,17 +3255,9 @@ fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {
33113255 .error_union => {
33123256 return .{ .imm32 = 0xaaaaaaaa };
33133257 },
3314 .@"struct" => {
3315 const packed_struct = zcu.typeToPackedStruct(ty).?;
3316 return cg.emitUndefined(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)));
3317 },
3318 .@"union" => switch (ty.containerLayout(zcu)) {
3319 .@"packed" => switch (ty.bitSize(zcu)) {
3320 0...32 => return .{ .imm32 = 0xaaaaaaaa },
3321 33...64 => return .{ .imm64 = 0xaaaaaaaaaaaaaaaa },
3322 else => unreachable,
3323 },
3324 else => unreachable,
3258 .@"struct", .@"union" => {
3259 const backing_int_ty = ty.bitpackBackingInt(zcu);
3260 return cg.emitUndefined(backing_int_ty);
33253261 },
33263262 else => return cg.fail("Wasm TODO: emitUndefined for type: {t}\n", .{ty.zigTypeTag(zcu)}),
33273263 }
......@@ -3335,7 +3271,7 @@ fn airBlock(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
33353271fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, block_ty: Type, body: []const Air.Inst.Index) InnerError!void {
33363272 const zcu = cg.pt.zcu;
33373273 // if wasm_block_ty is non-empty, we create a register to store the temporary value
3338 const block_result: WValue = if (block_ty.hasRuntimeBitsIgnoreComptime(zcu))
3274 const block_result: WValue = if (block_ty.hasRuntimeBits(zcu))
33393275 try cg.allocLocal(block_ty)
33403276 else
33413277 .none;
......@@ -3449,7 +3385,7 @@ fn cmp(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOpe
34493385 const zcu = cg.pt.zcu;
34503386 if (ty.zigTypeTag(zcu) == .optional and !ty.optionalReprIsPayload(zcu)) {
34513387 const payload_ty = ty.optionalChild(zcu);
3452 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3388 if (payload_ty.hasRuntimeBits(zcu)) {
34533389 // When we hit this case, we must check the value of optionals
34543390 // that are not pointers. This means first checking against non-null for
34553391 // both lhs and rhs, as well as checking the payload are matching of lhs and rhs
......@@ -3792,7 +3728,6 @@ fn structFieldPtr(
37923728fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37933729 const pt = cg.pt;
37943730 const zcu = pt.zcu;
3795 const ip = &zcu.intern_pool;
37963731 const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
37973732 const struct_field = cg.air.extraData(Air.StructField, ty_pl.payload).data;
37983733
......@@ -3800,14 +3735,14 @@ fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38003735 const operand = try cg.resolveInst(struct_field.struct_operand);
38013736 const field_index = struct_field.field_index;
38023737 const field_ty = struct_ty.fieldType(field_index, zcu);
3803 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) return cg.finishAir(inst, .none, &.{struct_field.struct_operand});
3738 if (!field_ty.hasRuntimeBits(zcu)) return cg.finishAir(inst, .none, &.{struct_field.struct_operand});
38043739
38053740 const result: WValue = switch (struct_ty.containerLayout(zcu)) {
38063741 .@"packed" => switch (struct_ty.zigTypeTag(zcu)) {
38073742 .@"struct" => result: {
38083743 const packed_struct = zcu.typeToPackedStruct(struct_ty).?;
38093744 const offset = zcu.structPackedFieldBitOffset(packed_struct, field_index);
3810 const backing_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
3745 const backing_ty = Type.fromInterned(packed_struct.packed_backing_int_type);
38113746 const host_bits = backing_ty.intInfo(zcu).bits;
38123747
38133748 const const_wvalue: WValue = if (33 <= host_bits and host_bits <= 64)
......@@ -3885,7 +3820,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index, is_dispatch_loop: bool) Inner
38853820 const switch_br = cg.air.unwrapSwitch(inst);
38863821 const target_ty = cg.typeOf(switch_br.operand);
38873822
3888 assert(target_ty.hasRuntimeBitsIgnoreComptime(zcu));
3823 assert(target_ty.hasRuntimeBits(zcu));
38893824
38903825 // swap target value with placeholder local, for dispatching
38913826 const target = if (is_dispatch_loop) target: {
......@@ -4119,7 +4054,7 @@ fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kind
41194054 }
41204055
41214056 try cg.emitWValue(operand);
4122 if (op_kind == .ptr or pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4057 if (op_kind == .ptr or pl_ty.hasRuntimeBits(zcu)) {
41234058 try cg.addMemArg(.i32_load16_u, .{
41244059 .offset = operand.offset() + @as(u32, @intCast(errUnionErrorOffset(pl_ty, zcu))),
41254060 .alignment = @intCast(Type.anyerror.abiAlignment(zcu).toByteUnits().?),
......@@ -4146,7 +4081,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
41464081 const payload_ty = eu_ty.errorUnionPayload(zcu);
41474082
41484083 const result: WValue = result: {
4149 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4084 if (!payload_ty.hasRuntimeBits(zcu)) {
41504085 if (op_is_ptr) {
41514086 break :result cg.reuseOperand(ty_op.operand, operand);
41524087 } else {
......@@ -4166,7 +4101,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
41664101}
41674102
41684103/// E!T -> E op_is_ptr == false
4169/// *(E!T) -> E op_is_prt == true
4104/// *(E!T) -> E op_is_ptr == true
41704105/// NOTE: op_is_ptr will not change return type
41714106fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
41724107 const zcu = cg.pt.zcu;
......@@ -4186,7 +4121,7 @@ fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) I
41864121 if (op_is_ptr or isByRef(eu_ty, zcu, cg.target)) {
41874122 break :result try cg.load(operand, Type.anyerror, err_offset);
41884123 } else {
4189 assert(!payload_ty.hasRuntimeBitsIgnoreComptime(zcu));
4124 assert(!payload_ty.hasRuntimeBits(zcu));
41904125 break :result cg.reuseOperand(ty_op.operand, operand);
41914126 }
41924127 };
......@@ -4202,7 +4137,7 @@ fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42024137
42034138 const pl_ty = cg.typeOf(ty_op.operand);
42044139 const result = result: {
4205 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4140 if (!pl_ty.hasRuntimeBits(zcu)) {
42064141 break :result cg.reuseOperand(ty_op.operand, operand);
42074142 }
42084143
......@@ -4232,7 +4167,7 @@ fn airWrapErrUnionErr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42324167 const pl_ty = err_ty.errorUnionPayload(zcu);
42334168
42344169 const result = result: {
4235 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4170 if (!pl_ty.hasRuntimeBits(zcu)) {
42364171 break :result cg.reuseOperand(ty_op.operand, operand);
42374172 }
42384173
......@@ -4348,7 +4283,7 @@ fn isNull(cg: *CodeGen, operand: WValue, optional_ty: Type, opcode: std.wasm.Opc
43484283 if (!optional_ty.optionalReprIsPayload(zcu)) {
43494284 // When payload is zero-bits, we can treat operand as a value, rather than
43504285 // a pointer to the stack value
4351 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4286 if (payload_ty.hasRuntimeBits(zcu)) {
43524287 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
43534288 return cg.fail("Optional type {f} too big to fit into stack frame", .{optional_ty.fmt(pt)});
43544289 };
......@@ -4373,7 +4308,7 @@ fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43734308 const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
43744309 const opt_ty = cg.typeOf(ty_op.operand);
43754310 const payload_ty = cg.typeOfIndex(inst);
4376 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4311 if (!payload_ty.hasRuntimeBits(zcu)) {
43774312 return cg.finishAir(inst, .none, &.{ty_op.operand});
43784313 }
43794314
......@@ -4398,7 +4333,7 @@ fn airOptionalPayloadPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43984333
43994334 const result = result: {
44004335 const payload_ty = opt_ty.optionalChild(zcu);
4401 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu) or opt_ty.optionalReprIsPayload(zcu)) {
4336 if (!payload_ty.hasRuntimeBits(zcu) or opt_ty.optionalReprIsPayload(zcu)) {
44024337 break :result cg.reuseOperand(ty_op.operand, operand);
44034338 }
44044339
......@@ -4438,7 +4373,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44384373 const zcu = pt.zcu;
44394374
44404375 const result = result: {
4441 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4376 if (!payload_ty.hasRuntimeBits(zcu)) {
44424377 const non_null_bit = try cg.allocStack(Type.u1);
44434378 try cg.emitWValue(non_null_bit);
44444379 try cg.addImm32(1);
......@@ -4606,7 +4541,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46064541 const slice_local = try cg.allocStack(slice_ty);
46074542
46084543 // store the array ptr in the slice
4609 if (array_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4544 if (array_ty.hasRuntimeBits(zcu)) {
46104545 try cg.store(slice_local, operand, Type.usize, 0);
46114546 }
46124547
......@@ -5105,7 +5040,7 @@ fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51055040 try cg.emitWValue(dest_alloc);
51065041 const elem_val = switch (mask_elem.unwrap()) {
51075042 .elem => |idx| try cg.load(operand, elem_ty, @intCast(elem_size * idx)),
5108 .value => |val| try cg.lowerConstant(.fromInterned(val), elem_ty),
5043 .value => |val| try cg.lowerConstant(.fromInterned(val)),
51095044 };
51105045 try cg.store(.stack, elem_val, elem_ty, @intCast(dest_alloc.offset() + elem_size * out_idx));
51115046 }
......@@ -5246,7 +5181,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52465181 }
52475182 const packed_struct = zcu.typeToPackedStruct(result_ty).?;
52485183 const field_types = packed_struct.field_types;
5249 const backing_type = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
5184 const backing_type = Type.fromInterned(packed_struct.packed_backing_int_type);
52505185
52515186 // ensure the result is zero'd
52525187 const result = try cg.allocLocal(backing_type);
......@@ -5259,7 +5194,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52595194 var current_bit: u16 = 0;
52605195 for (elements, 0..) |elem, elem_index| {
52615196 const field_ty = Type.fromInterned(field_types.get(ip)[elem_index]);
5262 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
5197 if (!field_ty.hasRuntimeBits(zcu)) continue;
52635198
52645199 const shift_val: WValue = if (backing_type.bitSize(zcu) <= 32)
52655200 .{ .imm32 = current_bit }
......@@ -5332,13 +5267,13 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53325267 const layout = union_ty.unionGetLayout(zcu);
53335268 const union_obj = zcu.typeToUnion(union_ty).?;
53345269 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
5335 const field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];
5270 const field_name = ip.loadEnumType(union_obj.enum_tag_type).field_names.get(ip)[extra.field_index];
53365271
53375272 const tag_int = blk: {
5338 const tag_ty = union_ty.unionTagTypeRuntime(zcu).?;
5273 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
53395274 const enum_field_index = tag_ty.enumFieldIndex(field_name, zcu).?;
53405275 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);
5341 break :blk try cg.lowerConstant(tag_val, tag_ty);
5276 break :blk try cg.lowerConstant(tag_val);
53425277 };
53435278 if (layout.payload_size == 0) {
53445279 if (layout.tag_size == 0) {
......@@ -5360,7 +5295,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53605295 }
53615296
53625297 if (layout.tag_size > 0) {
5363 try cg.store(result_ptr, tag_int, Type.fromInterned(union_obj.enum_tag_ty), 0);
5298 try cg.store(result_ptr, tag_int, .fromInterned(union_obj.enum_tag_type), 0);
53645299 }
53655300 } else {
53665301 try cg.store(result_ptr, payload, field_ty, 0);
......@@ -5368,7 +5303,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53685303 try cg.store(
53695304 result_ptr,
53705305 tag_int,
5371 Type.fromInterned(union_obj.enum_tag_ty),
5306 .fromInterned(union_obj.enum_tag_type),
53725307 @intCast(layout.payload_size),
53735308 );
53745309 }
......@@ -5415,7 +5350,7 @@ fn airWasmMemoryGrow(cg: *CodeGen, inst: Air.Inst.Index) !void {
54155350
54165351fn cmpOptionals(cg: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {
54175352 const zcu = cg.pt.zcu;
5418 assert(operand_ty.hasRuntimeBitsIgnoreComptime(zcu));
5353 assert(operand_ty.hasRuntimeBits(zcu));
54195354 assert(op == .eq or op == .neq);
54205355 const payload_ty = operand_ty.optionalChild(zcu);
54215356 assert(!isByRef(payload_ty, zcu, cg.target));
......@@ -5669,7 +5604,7 @@ fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void
56695604 );
56705605
56715606 const result = result: {
5672 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5607 if (!payload_ty.hasRuntimeBits(zcu)) {
56735608 break :result cg.reuseOperand(ty_op.operand, operand);
56745609 }
56755610
......@@ -6458,7 +6393,7 @@ fn lowerTry(
64586393 const zcu = cg.pt.zcu;
64596394
64606395 const pl_ty = err_union_ty.errorUnionPayload(zcu);
6461 const pl_has_bits = pl_ty.hasRuntimeBitsIgnoreComptime(zcu);
6396 const pl_has_bits = pl_ty.hasRuntimeBits(zcu);
64626397
64636398 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
64646399 // Block we can jump out of when error is not set
......@@ -7096,13 +7031,13 @@ fn callIntrinsic(
70967031 // Lower all arguments to the stack before we call our function
70977032 for (args, 0..) |arg, arg_i| {
70987033 assert(!(want_sret_param and arg == .stack));
7099 assert(Type.fromInterned(param_types[arg_i]).hasRuntimeBitsIgnoreComptime(zcu));
7034 assert(Type.fromInterned(param_types[arg_i]).hasRuntimeBits(zcu));
71007035 try cg.lowerArg(.{ .wasm_mvp = .{} }, Type.fromInterned(param_types[arg_i]), arg);
71017036 }
71027037
71037038 try cg.addInst(.{ .tag = .call_intrinsic, .data = .{ .intrinsic = intrinsic } });
71047039
7105 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
7040 if (!return_type.hasRuntimeBits(zcu)) {
71067041 return .none;
71077042 } else if (want_sret_param) {
71087043 return sret;
src/link/MachO/Atom.zig+1-1
......@@ -561,7 +561,7 @@ fn reportUndefSymbol(self: Atom, rel: Relocation, macho_file: *MachO) !bool {
561561 defer macho_file.undefs_mutex.unlock(io);
562562 const gop = try macho_file.undefs.getOrPut(gpa, file.getGlobals()[rel.target]);
563563 if (!gop.found_existing) {
564 gop.value_ptr.* = .{ .refs = .{} };
564 gop.value_ptr.* = .{ .refs = .empty };
565565 }
566566 try gop.value_ptr.refs.append(gpa, .{ .index = self.atom_index, .file = self.file });
567567 return true;
src/link/MachO/ZigObject.zig+1-1
......@@ -150,7 +150,7 @@ fn newAtom(self: *ZigObject, allocator: Allocator, name: MachO.String, macho_fil
150150 atom.name = name;
151151
152152 const relocs_index = @as(u32, @intCast(self.relocs.items.len));
153 self.relocs.addOneAssumeCapacity().* = .{};
153 self.relocs.addOneAssumeCapacity().* = .empty;
154154 atom.addExtra(.{ .rel_index = relocs_index, .rel_count = 0 }, macho_file);
155155
156156 return index;
src/link/MachO/file.zig+1-1
......@@ -258,7 +258,7 @@ pub const File = union(enum) {
258258
259259 const gop = try macho_file.dupes.getOrPut(gpa, file.getGlobals()[i]);
260260 if (!gop.found_existing) {
261 gop.value_ptr.* = .{};
261 gop.value_ptr.* = .empty;
262262 }
263263 try gop.value_ptr.append(gpa, file.getIndex());
264264 }
src/link/Wasm.zig+2-2
......@@ -4226,7 +4226,7 @@ fn convertZcuFnType(
42264226
42274227 if (CodeGen.firstParamSRet(cc, return_type, zcu, target)) {
42284228 try params_buffer.append(gpa, .i32); // memory address is always a 32-bit handle
4229 } else if (return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
4229 } else if (return_type.hasRuntimeBits(zcu)) {
42304230 if (cc == .wasm_mvp) {
42314231 switch (abi.classifyType(return_type, zcu)) {
42324232 .direct => |scalar_ty| {
......@@ -4245,7 +4245,7 @@ fn convertZcuFnType(
42454245 // param types
42464246 for (params) |param_type_ip| {
42474247 const param_type = Zcu.Type.fromInterned(param_type_ip);
4248 if (!param_type.hasRuntimeBitsIgnoreComptime(zcu)) continue;
4248 if (!param_type.hasRuntimeBits(zcu)) continue;
42494249
42504250 switch (cc) {
42514251 .wasm_mvp => {
src/link/Wasm/Flush.zig+3-3
......@@ -154,7 +154,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
154154 .type_index = try wasm.internFunctionType(.auto, &.{int_tag_ty.ip_index}, .slice_const_u8_sentinel_0, target),
155155 .table_index = @intCast(wasm.tag_name_offs.items.len),
156156 } };
157 const tag_names = ip.loadEnumType(data.ip_index).names;
157 const tag_names = ip.loadEnumType(data.ip_index).field_names;
158158 for (tag_names.get(ip)) |tag_name| {
159159 const slice = tag_name.toSlice(ip);
160160 try wasm.tag_name_offs.append(gpa, @intCast(wasm.tag_name_bytes.items.len));
......@@ -1869,7 +1869,7 @@ fn emitTagNameFunction(
18691869 const zcu = comp.zcu.?;
18701870 const ip = &zcu.intern_pool;
18711871 const enum_type = ip.loadEnumType(enum_type_ip);
1872 const tag_values = enum_type.values.get(ip);
1872 const tag_values = enum_type.field_values.get(ip);
18731873
18741874 const slice_abi_size = 8;
18751875 const encoded_alignment = @ctz(@as(u32, 4));
......@@ -1908,7 +1908,7 @@ fn emitTagNameFunction(
19081908 return;
19091909 }
19101910
1911 const int_info = Zcu.Type.intInfo(.fromInterned(enum_type.tag_ty), zcu);
1911 const int_info = Zcu.Type.intInfo(.fromInterned(enum_type.int_tag_type), zcu);
19121912 const outer_block_type: std.wasm.BlockType = switch (int_info.bits) {
19131913 0...32 => .i32,
19141914 33...64 => .i64,
src/link/tapi/parse.zig+1-1
......@@ -530,7 +530,7 @@ const Parser = struct {
530530 fn leaf_value(self: *Parser) ParseError!*Node {
531531 const node = try self.allocator.create(Node.Value);
532532 errdefer self.allocator.destroy(node);
533 node.* = .{ .string_value = .{} };
533 node.* = .{ .string_value = .empty };
534534 node.base.tree = self.tree;
535535 node.base.start = self.token_it.pos;
536536 errdefer node.string_value.deinit(self.allocator);