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 {...@@ -519,10 +519,13 @@ pub fn intAlignment(target: *const std.Target, bits: u16) u16 {
519 33...64 => 8,519 33...64 => 8,
520 else => 16,520 else => 16,
521 },521 },
522 else => return @min(522 else => switch (bits) {
523 std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))),523 0 => 1,
524 target.cMaxIntAlignment(),524 else => @min(
525 ),525 std.math.ceilPowerOfTwoPromote(u16, @intCast((@as(u17, bits) + 7) / 8)),
526 target.cMaxIntAlignment(),
527 ),
528 },
526 };529 };
527}530}
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,...@@ -2791,9 +2791,9 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
2791 } else return isel.fail("invalid constraint: '{s}'", .{constraint});2791 } else return isel.fail("invalid constraint: '{s}'", .{constraint});
2792 }2792 }
27932793
2794 const clobbers_val: Value = .fromInterned(unwrapped_asm.clobbers);2794 const clobbers_val: Constant = .fromInterned(unwrapped_asm.clobbers);
2795 const clobbers_ty = clobbers_val.typeOf(zcu);2795 const clobbers_ty = clobbers_val.typeOf(zcu);
2796 var clobbers_bigint_buf: Value.BigIntSpace = undefined;2796 var clobbers_bigint_buf: Constant.BigIntSpace = undefined;
2797 const clobbers_bigint = clobbers_val.toBigInt(&clobbers_bigint_buf, zcu);2797 const clobbers_bigint = clobbers_val.toBigInt(&clobbers_bigint_buf, zcu);
2798 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {2798 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {
2799 assert(clobbers_ty.fieldType(field_index, zcu).toIntern() == .bool_type);2799 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,...@@ -2818,7 +2818,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
2818 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {2818 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {
2819 const limb_bits = @bitSizeOf(std.math.big.Limb);2819 const limb_bits = @bitSizeOf(std.math.big.Limb);
2820 if (field_index / limb_bits >= clobbers_bigint.limbs.len) continue; // field is false2820 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)))) {
2822 0 => continue, // field is false2822 0 => continue, // field is false
2823 1 => {}, // field is true2823 1 => {}, // field is true
2824 }2824 }
...@@ -2871,7 +2871,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,...@@ -2871,7 +2871,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
2871 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {2871 for (0..clobbers_ty.structFieldCount(zcu)) |field_index| {
2872 const limb_bits = @bitSizeOf(std.math.big.Limb);2872 const limb_bits = @bitSizeOf(std.math.big.Limb);
2873 if (field_index / limb_bits >= clobbers_bigint.limbs.len) continue; // field is false2873 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)))) {
2875 0 => continue, // field is false2875 0 => continue, // field is false
2876 1 => {}, // field is true2876 1 => {}, // field is true
2877 }2877 }
...@@ -3283,8 +3283,8 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,...@@ -3283,8 +3283,8 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
3283 } else if (dst_ty.isSliceAtRuntime(zcu) and src_ty.isSliceAtRuntime(zcu)) {3283 } else if (dst_ty.isSliceAtRuntime(zcu) and src_ty.isSliceAtRuntime(zcu)) {
3284 try dst_vi.value.move(isel, ty_op.operand);3284 try dst_vi.value.move(isel, ty_op.operand);
3285 } else if (dst_tag == .error_union and src_tag == .error_union) {3285 } else if (dst_tag == .error_union and src_tag == .error_union) {
3286 assert(dst_ty.errorUnionSet(zcu).hasRuntimeBitsIgnoreComptime(zcu) ==3286 assert(dst_ty.errorUnionSet(zcu).hasRuntimeBits(zcu) ==
3287 src_ty.errorUnionSet(zcu).hasRuntimeBitsIgnoreComptime(zcu));3287 src_ty.errorUnionSet(zcu).hasRuntimeBits(zcu));
3288 if (dst_ty.errorUnionPayload(zcu).toIntern() == src_ty.errorUnionPayload(zcu).toIntern()) {3288 if (dst_ty.errorUnionPayload(zcu).toIntern() == src_ty.errorUnionPayload(zcu).toIntern()) {
3289 try dst_vi.value.move(isel, ty_op.operand);3289 try dst_vi.value.move(isel, ty_op.operand);
3290 } else return isel.fail("bad {t} {f} {f}", .{ air_tag, isel.fmtType(dst_ty), isel.fmtType(src_ty) });3290 } 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,...@@ -4562,7 +4562,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
4562 }4562 }
4563 if (case.ranges.len == 0 and case.items.len == 1 and Constant.fromInterned(4563 if (case.ranges.len == 0 and case.items.len == 1 and Constant.fromInterned(
4564 case.items[0].toInterned().?,4564 case.items[0].toInterned().?,
4565 ).orderAgainstZero(zcu).compare(.eq)) {4565 ).compareHetero(.eq, .zero_comptime_int, zcu)) {
4566 try isel.emit(.cbnz(4566 try isel.emit(.cbnz(
4567 cond_reg,4567 cond_reg,
4568 @intCast((isel.instructions.items.len + 1 - next_label) << 2),4568 @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,...@@ -6893,11 +6893,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
6893 var field_it = loaded_struct.iterateRuntimeOrder(ip);6893 var field_it = loaded_struct.iterateRuntimeOrder(ip);
6894 while (field_it.next()) |field_index| {6894 while (field_it.next()) |field_index| {
6895 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);6895 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
6896 field_offset = field_ty.structFieldAlignment(6896 field_offset = loaded_struct.field_offsets.get(ip)[field_index];
6897 loaded_struct.fieldAlign(ip, field_index),
6898 loaded_struct.layout,
6899 zcu,
6900 ).forward(field_offset);
6901 const field_size = field_ty.abiSize(zcu);6897 const field_size = field_ty.abiSize(zcu);
6902 if (field_size == 0) continue;6898 if (field_size == 0) continue;
6903 var agg_part_it = agg_vi.value.field(agg_ty, field_offset, field_size);6899 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,...@@ -6905,7 +6901,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
6905 try agg_part_vi.?.move(isel, elems[field_index]);6901 try agg_part_vi.?.move(isel, elems[field_index]);
6906 field_offset += field_size;6902 field_offset += field_size;
6907 }6903 }
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));
6909 },6905 },
6910 .tuple_type => |tuple_type| {6906 .tuple_type => |tuple_type| {
6911 const elems: []const Air.Inst.Ref =6907 const elems: []const Air.Inst.Ref =
...@@ -6947,23 +6943,23 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,...@@ -6947,23 +6943,23 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
6947 const union_layout = ZigType.getUnionLayout(loaded_union, zcu);6943 const union_layout = ZigType.getUnionLayout(loaded_union, zcu);
69486944
6949 if (union_layout.tag_size > 0) unused_tag: {6945 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);
6951 var tag_it = union_vi.value.field(union_ty, union_layout.tagOffset(), union_layout.tag_size);6947 var tag_it = union_vi.value.field(union_ty, union_layout.tagOffset(), union_layout.tag_size);
6952 const tag_vi = try tag_it.only(isel);6948 const tag_vi = try tag_it.only(isel);
6953 const tag_ra = try tag_vi.?.defReg(isel) orelse break :unused_tag;6949 const tag_ra = try tag_vi.?.defReg(isel) orelse break :unused_tag;
6954 switch (union_layout.tag_size) {6950 switch (union_layout.tag_size) {
6955 0 => unreachable,6951 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) {
6957 0 => extra.field_index,6953 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) {
6959 .u64 => |imm| @intCast(imm),6955 .u64 => |imm| @intCast(imm),
6960 .i64 => |imm| @bitCast(@as(i32, @intCast(imm))),6956 .i64 => |imm| @bitCast(@as(i32, @intCast(imm))),
6961 else => unreachable,6957 else => unreachable,
6962 },6958 },
6963 })),6959 })),
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) {
6965 0 => extra.field_index,6961 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) {
6967 .u64 => |imm| imm,6963 .u64 => |imm| imm,
6968 .i64 => |imm| @bitCast(imm),6964 .i64 => |imm| @bitCast(imm),
6969 else => unreachable,6965 else => unreachable,
...@@ -10391,7 +10387,7 @@ pub const Value = struct {...@@ -10391,7 +10387,7 @@ pub const Value = struct {
10391 switch (loaded_struct.layout) {10387 switch (loaded_struct.layout) {
10392 .auto, .@"extern" => {},10388 .auto, .@"extern" => {},
10393 .@"packed" => continue :type_key .{10389 .@"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,
10395 },10391 },
10396 }10392 }
10397 const min_part_log2_stride: u5 = if (size > 16) 4 else if (size > 8) 3 else 0;10393 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 {...@@ -10406,7 +10402,7 @@ pub const Value = struct {
10406 var field_it = loaded_struct.iterateRuntimeOrder(ip);10402 var field_it = loaded_struct.iterateRuntimeOrder(ip);
10407 while (field_it.next()) |field_index| {10403 while (field_it.next()) |field_index| {
10408 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);10404 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)) {
10410 .none => field_ty.abiAlignment(zcu),10406 .none => field_ty.abiAlignment(zcu),
10411 else => |field_align| field_align,10407 else => |field_align| field_align,
10412 }.forward(field_end);10408 }.forward(field_end);
...@@ -10504,7 +10500,7 @@ pub const Value = struct {...@@ -10504,7 +10500,7 @@ pub const Value = struct {
10504 },10500 },
10505 .union_type => {10501 .union_type => {
10506 const loaded_union = ip.loadUnionType(ty.toIntern());10502 const loaded_union = ip.loadUnionType(ty.toIntern());
10507 switch (loaded_union.flagsUnordered(ip).layout) {10503 switch (loaded_union.layout) {
10508 .auto, .@"extern" => {},10504 .auto, .@"extern" => {},
10509 .@"packed" => continue :type_key .{ .int_type = .{10505 .@"packed" => continue :type_key .{ .int_type = .{
10510 .signedness = .unsigned,10506 .signedness = .unsigned,
...@@ -10539,12 +10535,13 @@ pub const Value = struct {...@@ -10539,12 +10535,13 @@ pub const Value = struct {
10539 const field_signedness = field_signedness: switch (field) {10535 const field_signedness = field_signedness: switch (field) {
10540 .tag => {10536 .tag => {
10541 if (offset >= field_begin and offset + size <= field_begin + field_size) {10537 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);
10543 ty_size = field_size;10539 ty_size = field_size;
10544 offset -= field_begin;10540 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);
10546 }10542 }
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;
10548 },10545 },
10549 .payload => null,10546 .payload => null,
10550 };10547 };
...@@ -10574,7 +10571,7 @@ pub const Value = struct {...@@ -10574,7 +10571,7 @@ pub const Value = struct {
10574 }10571 }
10575 },10572 },
10576 .opaque_type, .func_type => continue :type_key .{ .simple_type = .anyopaque },10573 .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),
10578 .error_set_type,10575 .error_set_type,
10579 .inferred_error_set_type,10576 .inferred_error_set_type,
10580 => continue :type_key .{ .simple_type = .anyerror },10577 => continue :type_key .{ .simple_type = .anyerror },
...@@ -10740,7 +10737,7 @@ pub const Value = struct {...@@ -10740,7 +10737,7 @@ pub const Value = struct {
10740 .storage = .{ .u64 = 0 },10737 .storage = .{ .u64 = 0 },
10741 } },10738 } },
10742 },10739 },
10743 .int => |int| break :free storage: switch (int.storage) {10740 .int => |int| break :free switch (int.storage) {
10744 .u64 => |imm| try isel.movImmediate(switch (size) {10741 .u64 => |imm| try isel.movImmediate(switch (size) {
10745 else => unreachable,10742 else => unreachable,
10746 1...4 => mat.ra.w(),10743 1...4 => mat.ra.w(),
...@@ -10772,12 +10769,6 @@ pub const Value = struct {...@@ -10772,12 +10769,6 @@ pub const Value = struct {
10772 }10769 }
10773 try isel.movImmediate(mat.ra.x(), imm);10770 try isel.movImmediate(mat.ra.x(), imm);
10774 },10771 },
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 },
10781 },10772 },
10782 .err => |err| continue :constant_key .{ .int = .{10773 .err => |err| continue :constant_key .{ .int = .{
10783 .ty = err.ty,10774 .ty = err.ty,
...@@ -11084,13 +11075,9 @@ pub const Value = struct {...@@ -11084,13 +11075,9 @@ pub const Value = struct {
11084 var field_offset: u64 = 0;11075 var field_offset: u64 = 0;
11085 var field_it = loaded_struct.iterateRuntimeOrder(ip);11076 var field_it = loaded_struct.iterateRuntimeOrder(ip);
11086 while (field_it.next()) |field_index| {11077 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;
11088 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);11079 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
11089 field_offset = field_ty.structFieldAlignment(11080 field_offset = loaded_struct.field_offsets.get(ip)[field_index];
11090 loaded_struct.fieldAlign(ip, field_index),
11091 loaded_struct.layout,
11092 zcu,
11093 ).forward(field_offset);
11094 const field_size = field_ty.abiSize(zcu);11081 const field_size = field_ty.abiSize(zcu);
11095 if (offset >= field_offset and offset + size <= field_offset + field_size) {11082 if (offset >= field_offset and offset + size <= field_offset + field_size) {
11096 offset -= field_offset;11083 offset -= field_offset;
...@@ -11132,7 +11119,7 @@ pub const Value = struct {...@@ -11132,7 +11119,7 @@ pub const Value = struct {
11132 .un => |un| {11119 .un => |un| {
11133 const loaded_union = ip.loadUnionType(un.ty);11120 const loaded_union = ip.loadUnionType(un.ty);
11134 const union_layout = ZigType.getUnionLayout(loaded_union, zcu);11121 const union_layout = ZigType.getUnionLayout(loaded_union, zcu);
11135 if (loaded_union.hasTag(ip)) {11122 if (loaded_union.has_runtime_tag) {
11136 const tag_offset = union_layout.tagOffset();11123 const tag_offset = union_layout.tagOffset();
11137 if (offset >= tag_offset and offset + size <= tag_offset + union_layout.tag_size) {11124 if (offset >= tag_offset and offset + size <= tag_offset + union_layout.tag_size) {
11138 offset -= tag_offset;11125 offset -= tag_offset;
...@@ -11477,13 +11464,9 @@ fn writeKeyToMemory(isel: *Select, constant_key: InternPool.Key, buffer: []u8) e...@@ -11477,13 +11464,9 @@ fn writeKeyToMemory(isel: *Select, constant_key: InternPool.Key, buffer: []u8) e
11477 var field_offset: u64 = 0;11464 var field_offset: u64 = 0;
11478 var field_it = loaded_struct.iterateRuntimeOrder(ip);11465 var field_it = loaded_struct.iterateRuntimeOrder(ip);
11479 while (field_it.next()) |field_index| {11466 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;
11481 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);11468 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);
11482 field_offset = field_ty.structFieldAlignment(11469 field_offset = loaded_struct.field_offsets.get(ip)[field_index];
11483 loaded_struct.fieldAlign(ip, field_index),
11484 loaded_struct.layout,
11485 zcu,
11486 ).forward(field_offset);
11487 const field_size = field_ty.abiSize(zcu);11470 const field_size = field_ty.abiSize(zcu);
11488 if (!try isel.writeToMemory(.fromInterned(switch (aggregate.storage) {11471 if (!try isel.writeToMemory(.fromInterned(switch (aggregate.storage) {
11489 .bytes => unreachable,11472 .bytes => unreachable,
...@@ -12082,7 +12065,7 @@ pub const CallAbiIterator = struct {...@@ -12082,7 +12065,7 @@ pub const CallAbiIterator = struct {
12082 const zcu = isel.pt.zcu;12065 const zcu = isel.pt.zcu;
12083 const ip = &zcu.intern_pool;12066 const ip = &zcu.intern_pool;
1208412067
12085 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return null;12068 if (!ty.hasRuntimeBits(zcu)) return null;
12086 try isel.values.ensureUnusedCapacity(zcu.gpa, Value.max_parts);12069 try isel.values.ensureUnusedCapacity(zcu.gpa, Value.max_parts);
12087 const wip_vi = isel.initValue(ty);12070 const wip_vi = isel.initValue(ty);
12088 type_key: switch (ip.indexToKey(ty.toIntern())) {12071 type_key: switch (ip.indexToKey(ty.toIntern())) {
...@@ -12186,7 +12169,7 @@ pub const CallAbiIterator = struct {...@@ -12186,7 +12169,7 @@ pub const CallAbiIterator = struct {
12186 switch (loaded_struct.layout) {12169 switch (loaded_struct.layout) {
12187 .auto, .@"extern" => {},12170 .auto, .@"extern" => {},
12188 .@"packed" => continue :type_key .{12171 .@"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,
12190 },12173 },
12191 }12174 }
12192 const size = wip_vi.size(isel);12175 const size = wip_vi.size(isel);
...@@ -12210,7 +12193,7 @@ pub const CallAbiIterator = struct {...@@ -12210,7 +12193,7 @@ pub const CallAbiIterator = struct {
12210 const field_end = next_field_end;12193 const field_end = next_field_end;
12211 const next_field_begin = if (field_it.next()) |field_index| next_field_begin: {12194 const next_field_begin = if (field_it.next()) |field_index| next_field_begin: {
12212 const field_ty: ZigType = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);12195 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)) {
12214 .none => field_ty.abiAlignment(zcu),12197 .none => field_ty.abiAlignment(zcu),
12215 else => |field_align| field_align,12198 else => |field_align| field_align,
12216 }.forward(field_end);12199 }.forward(field_end);
...@@ -12276,7 +12259,7 @@ pub const CallAbiIterator = struct {...@@ -12276,7 +12259,7 @@ pub const CallAbiIterator = struct {
12276 },12259 },
12277 .union_type => {12260 .union_type => {
12278 const loaded_union = ip.loadUnionType(ty.toIntern());12261 const loaded_union = ip.loadUnionType(ty.toIntern());
12279 switch (loaded_union.flagsUnordered(ip).layout) {12262 switch (loaded_union.layout) {
12280 .auto, .@"extern" => {},12263 .auto, .@"extern" => {},
12281 .@"packed" => continue :type_key .{ .int_type = .{12264 .@"packed" => continue :type_key .{ .int_type = .{
12282 .signedness = .unsigned,12265 .signedness = .unsigned,
...@@ -12309,7 +12292,9 @@ pub const CallAbiIterator = struct {...@@ -12309,7 +12292,9 @@ pub const CallAbiIterator = struct {
12309 }12292 }
12310 },12293 },
12311 .opaque_type, .func_type => continue :type_key .{ .simple_type = .anyopaque },12294 .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 },
12313 .error_set_type,12298 .error_set_type,
12314 .inferred_error_set_type,12299 .inferred_error_set_type,
12315 => continue :type_key .{ .simple_type = .anyerror },12300 => continue :type_key .{ .simple_type = .anyerror },
...@@ -12414,8 +12399,8 @@ pub const CallAbiIterator = struct {...@@ -12414,8 +12399,8 @@ pub const CallAbiIterator = struct {
12414 const ip = &zcu.intern_pool;12399 const ip = &zcu.intern_pool;
12415 var common_fdt: ?FundamentalDataType = null;12400 var common_fdt: ?FundamentalDataType = null;
12416 for (0.., loaded_struct.field_types.get(ip)) |field_index, field_ty| {12401 for (0.., loaded_struct.field_types.get(ip)) |field_index, field_ty| {
12417 if (loaded_struct.fieldIsComptime(ip, field_index)) continue;12402 if (loaded_struct.field_is_comptime_bits.get(ip, field_index)) continue;
12418 if (loaded_struct.fieldAlign(ip, field_index) != .none) return null;12403 if (loaded_struct.field_aligns.getOrNone(ip, field_index) != .none) return null;
12419 if (!ZigType.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;12404 if (!ZigType.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
12420 const fdt = homogeneousAggregateBaseType(zcu, field_ty);12405 const fdt = homogeneousAggregateBaseType(zcu, field_ty);
12421 if (common_fdt == null) common_fdt = fdt else if (fdt != common_fdt) return null;12406 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 {...@@ -1052,17 +1052,7 @@ pub const DeclGen = struct {
1052 .func,1052 .func,
1053 .enum_literal,1053 .enum_literal,
1054 => unreachable, // non-runtime values1054 => unreachable, // non-runtime values
1055 .int => |int| switch (int.storage) {1055 .int => try w.print("{f}", .{try dg.fmtIntLiteralDec(val, location)}),
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 },
1066 .err => |err| try dg.renderErrorName(w, err.name),1056 .err => |err| try dg.renderErrorName(w, err.name),
1067 .error_union => |error_union| switch (ctype.info(ctype_pool)) {1057 .error_union => |error_union| switch (ctype.info(ctype_pool)) {
1068 .basic => switch (error_union.val) {1058 .basic => switch (error_union.val) {
...@@ -1338,7 +1328,7 @@ pub const DeclGen = struct {...@@ -1338,7 +1328,7 @@ pub const DeclGen = struct {
1338 const comptime_val = tuple.values.get(ip)[field_index];1328 const comptime_val = tuple.values.get(ip)[field_index];
1339 if (comptime_val != .none) continue;1329 if (comptime_val != .none) continue;
1340 const field_ty: Type = .fromInterned(tuple.types.get(ip)[field_index]);1330 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
1343 if (!empty) try w.writeByte(',');1333 if (!empty) try w.writeByte(',');
13441334
...@@ -1373,7 +1363,7 @@ pub const DeclGen = struct {...@@ -1373,7 +1363,7 @@ pub const DeclGen = struct {
1373 var need_comma = false;1363 var need_comma = false;
1374 while (field_it.next()) |field_index| {1364 while (field_it.next()) |field_index| {
1375 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);1365 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
1378 if (need_comma) try w.writeByte(',');1368 if (need_comma) try w.writeByte(',');
1379 need_comma = true;1369 need_comma = true;
...@@ -1396,7 +1386,7 @@ pub const DeclGen = struct {...@@ -1396,7 +1386,7 @@ pub const DeclGen = struct {
1396 const loaded_union = ip.loadUnionType(ty.toIntern());1386 const loaded_union = ip.loadUnionType(ty.toIntern());
1397 if (un.tag == .none) {1387 if (un.tag == .none) {
1398 const backing_ty = try ty.externUnionBackingType(pt);1388 const backing_ty = try ty.externUnionBackingType(pt);
1399 assert(loaded_union.flagsUnordered(ip).layout == .@"extern");1389 assert(loaded_union.layout == .@"extern");
1400 if (location == .StaticInitializer) {1390 if (location == .StaticInitializer) {
1401 return dg.fail("TODO: C backend: implement extern union backing type rendering in static initializers", .{});1391 return dg.fail("TODO: C backend: implement extern union backing type rendering in static initializers", .{});
1402 }1392 }
...@@ -1418,9 +1408,9 @@ pub const DeclGen = struct {...@@ -1418,9 +1408,9 @@ pub const DeclGen = struct {
14181408
1419 const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;1409 const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;
1420 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);1410 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;
1424 if (has_tag) try w.writeByte('{');1414 if (has_tag) try w.writeByte('{');
1425 const aggregate = ctype.info(ctype_pool).aggregate;1415 const aggregate = ctype.info(ctype_pool).aggregate;
1426 for (0..if (has_tag) aggregate.fields.len else 1) |outer_field_index| {1416 for (0..if (has_tag) aggregate.fields.len else 1) |outer_field_index| {
...@@ -1597,7 +1587,7 @@ pub const DeclGen = struct {...@@ -1597,7 +1587,7 @@ pub const DeclGen = struct {
1597 var need_comma = false;1587 var need_comma = false;
1598 while (field_it.next()) |field_index| {1588 while (field_it.next()) |field_index| {
1599 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);1589 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
1602 if (need_comma) try w.writeByte(',');1592 if (need_comma) try w.writeByte(',');
1603 need_comma = true;1593 need_comma = true;
...@@ -1620,7 +1610,7 @@ pub const DeclGen = struct {...@@ -1620,7 +1610,7 @@ pub const DeclGen = struct {
1620 for (0..tuple_info.types.len) |field_index| {1610 for (0..tuple_info.types.len) |field_index| {
1621 if (tuple_info.values.get(ip)[field_index] != .none) continue;1611 if (tuple_info.values.get(ip)[field_index] != .none) continue;
1622 const field_ty: Type = .fromInterned(tuple_info.types.get(ip)[field_index]);1612 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
1625 if (need_comma) try w.writeByte(',');1615 if (need_comma) try w.writeByte(',');
1626 need_comma = true;1616 need_comma = true;
...@@ -1630,7 +1620,7 @@ pub const DeclGen = struct {...@@ -1630,7 +1620,7 @@ pub const DeclGen = struct {
1630 },1620 },
1631 .union_type => {1621 .union_type => {
1632 const loaded_union = ip.loadUnionType(ty.toIntern());1622 const loaded_union = ip.loadUnionType(ty.toIntern());
1633 switch (loaded_union.flagsUnordered(ip).layout) {1623 switch (loaded_union.layout) {
1634 .auto, .@"extern" => {1624 .auto, .@"extern" => {
1635 if (!location.isInitializer()) {1625 if (!location.isInitializer()) {
1636 try w.writeByte('(');1626 try w.writeByte('(');
...@@ -1638,7 +1628,7 @@ pub const DeclGen = struct {...@@ -1638,7 +1628,7 @@ pub const DeclGen = struct {
1638 try w.writeByte(')');1628 try w.writeByte(')');
1639 }1629 }
16401630
1641 const has_tag = loaded_union.hasTag(ip);1631 const has_tag = loaded_union.has_runtime_tag;
1642 if (has_tag) try w.writeByte('{');1632 if (has_tag) try w.writeByte('{');
1643 const aggregate = ctype.info(ctype_pool).aggregate;1633 const aggregate = ctype.info(ctype_pool).aggregate;
1644 for (0..if (has_tag) aggregate.fields.len else 1) |outer_field_index| {1634 for (0..if (has_tag) aggregate.fields.len else 1) |outer_field_index| {
...@@ -1649,7 +1639,7 @@ pub const DeclGen = struct {...@@ -1649,7 +1639,7 @@ pub const DeclGen = struct {
1649 .payload) {1639 .payload) {
1650 .tag => try dg.renderUndefValue(1640 .tag => try dg.renderUndefValue(
1651 w,1641 w,
1652 .fromInterned(loaded_union.enum_tag_ty),1642 .fromInterned(loaded_union.enum_tag_type),
1653 initializer_type,1643 initializer_type,
1654 ),1644 ),
1655 .payload => {1645 .payload => {
...@@ -1760,6 +1750,7 @@ pub const DeclGen = struct {...@@ -1760,6 +1750,7 @@ pub const DeclGen = struct {
1760 .opt,1750 .opt,
1761 .aggregate,1751 .aggregate,
1762 .un,1752 .un,
1753 .bitpack,
1763 .memoized_call,1754 .memoized_call,
1764 => unreachable, // values, not types1755 => unreachable, // values, not types
1765 },1756 },
...@@ -2797,7 +2788,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn...@@ -2797,7 +2788,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
2797 } });2788 } });
27982789
2799 try w.print("case {f}: {{", .{2790 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),
2801 });2792 });
2802 o.indent();2793 o.indent();
2803 try o.newline();2794 try o.newline();
...@@ -3599,10 +3590,7 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3599,10 +3590,7 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3599 const zcu = f.object.dg.pt.zcu;3590 const zcu = f.object.dg.pt.zcu;
3600 const inst_ty = f.typeOfIndex(inst);3591 const inst_ty = f.typeOfIndex(inst);
3601 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3592 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3602 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3593 assert(inst_ty.hasRuntimeBits(zcu));
3603 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3604 return .none;
3605 }
36063594
3607 const ptr = try f.resolveInst(bin_op.lhs);3595 const ptr = try f.resolveInst(bin_op.lhs);
3608 const index = try f.resolveInst(bin_op.rhs);3596 const index = try f.resolveInst(bin_op.rhs);
...@@ -3629,7 +3617,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3629,7 +3617,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
36293617
3630 const inst_ty = f.typeOfIndex(inst);3618 const inst_ty = f.typeOfIndex(inst);
3631 const ptr_ty = f.typeOf(bin_op.lhs);3619 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
3634 const ptr = try f.resolveInst(bin_op.lhs);3622 const ptr = try f.resolveInst(bin_op.lhs);
3635 const index = try f.resolveInst(bin_op.rhs);3623 const index = try f.resolveInst(bin_op.rhs);
...@@ -3643,16 +3631,14 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3643,16 +3631,14 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3643 try w.writeByte('(');3631 try w.writeByte('(');
3644 try f.renderType(w, inst_ty);3632 try f.renderType(w, inst_ty);
3645 try w.writeByte(')');3633 try w.writeByte(')');
3646 if (elem_has_bits) try w.writeByte('&');3634 try w.writeByte('&');
3647 if (elem_has_bits and ptr_ty.ptrSize(zcu) == .one) {3635 if (ptr_ty.ptrSize(zcu) == .one) {
3648 // It's a pointer to an array, so we need to de-reference.3636 // It's a pointer to an array, so we need to de-reference.
3649 try f.writeCValueDeref(w, ptr);3637 try f.writeCValueDeref(w, ptr);
3650 } else try f.writeCValue(w, ptr, .Other);3638 } else try f.writeCValue(w, ptr, .Other);
3651 if (elem_has_bits) {3639 try w.writeByte('[');
3652 try w.writeByte('[');3640 try f.writeCValue(w, index, .Other);
3653 try f.writeCValue(w, index, .Other);3641 try w.writeByte(']');
3654 try w.writeByte(']');
3655 }
3656 try a.end(f, w);3642 try a.end(f, w);
3657 return local;3643 return local;
3658}3644}
...@@ -3661,10 +3647,7 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3661,10 +3647,7 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3661 const zcu = f.object.dg.pt.zcu;3647 const zcu = f.object.dg.pt.zcu;
3662 const inst_ty = f.typeOfIndex(inst);3648 const inst_ty = f.typeOfIndex(inst);
3663 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3649 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3664 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3650 assert(inst_ty.hasRuntimeBits(zcu));
3665 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3666 return .none;
3667 }
36683651
3669 const slice = try f.resolveInst(bin_op.lhs);3652 const slice = try f.resolveInst(bin_op.lhs);
3670 const index = try f.resolveInst(bin_op.rhs);3653 const index = try f.resolveInst(bin_op.rhs);
...@@ -3692,7 +3675,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3692,7 +3675,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3692 const inst_ty = f.typeOfIndex(inst);3675 const inst_ty = f.typeOfIndex(inst);
3693 const slice_ty = f.typeOf(bin_op.lhs);3676 const slice_ty = f.typeOf(bin_op.lhs);
3694 const elem_ty = slice_ty.childType(zcu);3677 const elem_ty = slice_ty.childType(zcu);
3695 const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(zcu);3678 assert(elem_ty.hasRuntimeBits(zcu));
36963679
3697 const slice = try f.resolveInst(bin_op.lhs);3680 const slice = try f.resolveInst(bin_op.lhs);
3698 const index = try f.resolveInst(bin_op.rhs);3681 const index = try f.resolveInst(bin_op.rhs);
...@@ -3703,13 +3686,11 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3703,13 +3686,11 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3703 const a = try Assignment.start(f, w, try f.ctypeFromType(inst_ty, .complete));3686 const a = try Assignment.start(f, w, try f.ctypeFromType(inst_ty, .complete));
3704 try f.writeCValue(w, local, .Other);3687 try f.writeCValue(w, local, .Other);
3705 try a.assign(f, w);3688 try a.assign(f, w);
3706 if (elem_has_bits) try w.writeByte('&');3689 try w.writeByte('&');
3707 try f.writeCValueMember(w, slice, .{ .identifier = "ptr" });3690 try f.writeCValueMember(w, slice, .{ .identifier = "ptr" });
3708 if (elem_has_bits) {3691 try w.writeByte('[');
3709 try w.writeByte('[');3692 try f.writeCValue(w, index, .Other);
3710 try f.writeCValue(w, index, .Other);3693 try w.writeByte(']');
3711 try w.writeByte(']');
3712 }
3713 try a.end(f, w);3694 try a.end(f, w);
3714 return local;3695 return local;
3715}3696}
...@@ -3718,10 +3699,7 @@ fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3718,10 +3699,7 @@ fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3718 const zcu = f.object.dg.pt.zcu;3699 const zcu = f.object.dg.pt.zcu;
3719 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3700 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3720 const inst_ty = f.typeOfIndex(inst);3701 const inst_ty = f.typeOfIndex(inst);
3721 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3702 assert(inst_ty.hasRuntimeBits(zcu));
3722 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3723 return .none;
3724 }
37253703
3726 const array = try f.resolveInst(bin_op.lhs);3704 const array = try f.resolveInst(bin_op.lhs);
3727 const index = try f.resolveInst(bin_op.rhs);3705 const index = try f.resolveInst(bin_op.rhs);
...@@ -3853,10 +3831,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3853,10 +3831,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
3853 // bit-pointers we see here are vector element pointers.3831 // bit-pointers we see here are vector element pointers.
3854 assert(ptr_info.packed_offset.host_size == 0 or ptr_info.flags.vector_index != .none);3832 assert(ptr_info.packed_offset.host_size == 0 or ptr_info.flags.vector_index != .none);
38553833
3856 if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3834 assert(src_ty.hasRuntimeBits(zcu));
3857 try reap(f, inst, &.{ty_op.operand});
3858 return .none;
3859 }
38603835
3861 const operand = try f.resolveInst(ty_op.operand);3836 const operand = try f.resolveInst(ty_op.operand);
38623837
...@@ -4456,7 +4431,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {...@@ -4456,7 +4431,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
4456 const inst_ty = f.typeOfIndex(inst);4431 const inst_ty = f.typeOfIndex(inst);
4457 const inst_scalar_ty = inst_ty.scalarType(zcu);4432 const inst_scalar_ty = inst_ty.scalarType(zcu);
4458 const elem_ty = inst_scalar_ty.indexableElem(zcu);4433 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));
4460 const inst_scalar_ctype = try f.ctypeFromType(inst_scalar_ty, .complete);4435 const inst_scalar_ctype = try f.ctypeFromType(inst_scalar_ty, .complete);
44614436
4462 const local = try f.allocLocal(inst, inst_ty);4437 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)...@@ -4787,7 +4762,7 @@ fn lowerBlock(f: *Function, inst: Air.Inst.Index, body: []const Air.Inst.Index)
4787 const w = &f.object.code.writer;4762 const w = &f.object.code.writer;
47884763
4789 const inst_ty = f.typeOfIndex(inst);4764 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))
4791 try f.allocLocal(inst, inst_ty)4766 try f.allocLocal(inst, inst_ty)
4792 else4767 else
4793 .none;4768 .none;
...@@ -4853,7 +4828,7 @@ fn lowerTry(...@@ -4853,7 +4828,7 @@ fn lowerTry(
4853 const liveness_condbr = f.liveness.getCondBr(inst);4828 const liveness_condbr = f.liveness.getCondBr(inst);
4854 const w = &f.object.code.writer;4829 const w = &f.object.code.writer;
4855 const payload_ty = err_union_ty.errorUnionPayload(zcu);4830 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
4858 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {4833 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
4859 try w.writeAll("if (");4834 try w.writeAll("if (");
...@@ -5393,7 +5368,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5393,7 +5368,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5393 const result = result: {5368 const result = result: {
5394 const w = &f.object.code.writer;5369 const w = &f.object.code.writer;
5395 const inst_ty = f.typeOfIndex(inst);5370 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: {
5397 const inst_local = try f.allocLocalValue(.{5372 const inst_local = try f.allocLocalValue(.{
5398 .ctype = try f.ctypeFromType(inst_ty, .complete),5373 .ctype = try f.ctypeFromType(inst_ty, .complete),
5399 .alignas = CType.AlignAs.fromAbiAlignment(inst_ty.abiAlignment(zcu)),5374 .alignas = CType.AlignAs.fromAbiAlignment(inst_ty.abiAlignment(zcu)),
...@@ -5820,12 +5795,12 @@ fn fieldLocation(...@@ -5820,12 +5795,12 @@ fn fieldLocation(
5820 .struct_type => {5795 .struct_type => {
5821 const loaded_struct = ip.loadStructType(container_ty.toIntern());5796 const loaded_struct = ip.loadStructType(container_ty.toIntern());
5822 return switch (loaded_struct.layout) {5797 return switch (loaded_struct.layout) {
5823 .auto, .@"extern" => if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu))5798 .auto, .@"extern" => if (!container_ty.hasRuntimeBits(zcu))
5824 .begin5799 .begin
5825 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu))5800 else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu))
5826 .{ .byte_offset = loaded_struct.offsets.get(ip)[field_index] }5801 .{ .byte_offset = loaded_struct.field_offsets.get(ip)[field_index] }
5827 else5802 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) } },
5829 .@"packed" => if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0)5804 .@"packed" => if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0)
5830 .{ .byte_offset = @divExact(zcu.structPackedFieldBitOffset(loaded_struct, field_index) +5805 .{ .byte_offset = @divExact(zcu.structPackedFieldBitOffset(loaded_struct, field_index) +
5831 container_ptr_ty.ptrInfo(zcu).packed_offset.bit_offset, 8) }5806 container_ptr_ty.ptrInfo(zcu).packed_offset.bit_offset, 8) }
...@@ -5833,24 +5808,24 @@ fn fieldLocation(...@@ -5833,24 +5808,24 @@ fn fieldLocation(
5833 .begin,5808 .begin,
5834 };5809 };
5835 },5810 },
5836 .tuple_type => return if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu))5811 .tuple_type => return if (!container_ty.hasRuntimeBits(zcu))
5837 .begin5812 .begin
5838 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu))5813 else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu))
5839 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }5814 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }
5840 else5815 else
5841 .{ .field = .{ .field = field_index } },5816 .{ .field = .{ .field = field_index } },
5842 .union_type => {5817 .union_type => {
5843 const loaded_union = ip.loadUnionType(container_ty.toIntern());5818 const loaded_union = ip.loadUnionType(container_ty.toIntern());
5844 switch (loaded_union.flagsUnordered(ip).layout) {5819 switch (loaded_union.layout) {
5845 .auto, .@"extern" => {5820 .auto, .@"extern" => {
5846 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);5821 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))
5848 return if (loaded_union.has_runtime_tag and !container_ty.unionHasAllZeroBitFieldTypes(zcu))5823 return if (loaded_union.has_runtime_tag and !container_ty.unionHasAllZeroBitFieldTypes(zcu))
5849 .{ .field = .{ .identifier = "payload" } }5824 .{ .field = .{ .identifier = "payload" } }
5850 else5825 else
5851 .begin;5826 .begin;
5852 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];5827 const field_name = ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[field_index];
5853 return .{ .field = if (loaded_union.hasTag(ip))5828 return .{ .field = if (loaded_union.has_runtime_tag)
5854 .{ .payload_identifier = field_name.toSlice(ip) }5829 .{ .payload_identifier = field_name.toSlice(ip) }
5855 else5830 else
5856 .{ .identifier = field_name.toSlice(ip) } };5831 .{ .identifier = field_name.toSlice(ip) } };
...@@ -5996,10 +5971,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5996,10 +5971,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5996 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;5971 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
59975972
5998 const inst_ty = f.typeOfIndex(inst);5973 const inst_ty = f.typeOfIndex(inst);
5999 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {5974 assert(inst_ty.hasRuntimeBits(zcu));
6000 try reap(f, inst, &.{extra.struct_operand});
6001 return .none;
6002 }
60035975
6004 const struct_byval = try f.resolveInst(extra.struct_operand);5976 const struct_byval = try f.resolveInst(extra.struct_operand);
6005 try reap(f, inst, &.{extra.struct_operand});5977 try reap(f, inst, &.{extra.struct_operand});
...@@ -6014,9 +5986,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6014,9 +5986,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
6014 .struct_type => .{ .identifier = struct_ty.structFieldName(extra.field_index, zcu).unwrap().?.toSlice(ip) },5986 .struct_type => .{ .identifier = struct_ty.structFieldName(extra.field_index, zcu).unwrap().?.toSlice(ip) },
6015 .union_type => name: {5987 .union_type => name: {
6016 const union_type = ip.loadUnionType(struct_ty.toIntern());5988 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);
6018 const field_name_str = enum_tag_ty.enumFieldName(extra.field_index, zcu).toSlice(ip);5990 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) {
6020 break :name .{ .payload_identifier = field_name_str };5992 break :name .{ .payload_identifier = field_name_str };
6021 } else {5993 } else {
6022 break :name .{ .identifier = field_name_str };5994 break :name .{ .identifier = field_name_str };
...@@ -6161,7 +6133,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6161,7 +6133,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
61616133
6162 const inst_ty = f.typeOfIndex(inst);6134 const inst_ty = f.typeOfIndex(inst);
6163 const payload_ty = inst_ty.errorUnionPayload(zcu);6135 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);
6165 const err_ty = inst_ty.errorUnionSet(zcu);6137 const err_ty = inst_ty.errorUnionSet(zcu);
6166 const err = try f.resolveInst(ty_op.operand);6138 const err = try f.resolveInst(ty_op.operand);
6167 try reap(f, inst, &.{ty_op.operand});6139 try reap(f, inst, &.{ty_op.operand});
...@@ -6210,7 +6182,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6210,7 +6182,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
6210 try reap(f, inst, &.{ty_op.operand});6182 try reap(f, inst, &.{ty_op.operand});
62116183
6212 // First, set the non-error value.6184 // First, set the non-error value.
6213 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {6185 if (!payload_ty.hasRuntimeBits(zcu)) {
6214 const a = try Assignment.start(f, w, try f.ctypeFromType(operand_ty, .complete));6186 const a = try Assignment.start(f, w, try f.ctypeFromType(operand_ty, .complete));
6215 try f.writeCValueDeref(w, operand);6187 try f.writeCValueDeref(w, operand);
6216 try a.assign(f, w);6188 try a.assign(f, w);
...@@ -6262,13 +6234,13 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6262,13 +6234,13 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
6262 const inst_ty = f.typeOfIndex(inst);6234 const inst_ty = f.typeOfIndex(inst);
6263 const payload_ty = inst_ty.errorUnionPayload(zcu);6235 const payload_ty = inst_ty.errorUnionPayload(zcu);
6264 const payload = try f.resolveInst(ty_op.operand);6236 const payload = try f.resolveInst(ty_op.operand);
6265 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(zcu);6237 assert(payload_ty.hasRuntimeBits(zcu));
6266 const err_ty = inst_ty.errorUnionSet(zcu);6238 const err_ty = inst_ty.errorUnionSet(zcu);
6267 try reap(f, inst, &.{ty_op.operand});6239 try reap(f, inst, &.{ty_op.operand});
62686240
6269 const w = &f.object.code.writer;6241 const w = &f.object.code.writer;
6270 const local = try f.allocLocal(inst, inst_ty);6242 const local = try f.allocLocal(inst, inst_ty);
6271 if (!repr_is_err) {6243 {
6272 const a = try Assignment.start(f, w, try f.ctypeFromType(payload_ty, .complete));6244 const a = try Assignment.start(f, w, try f.ctypeFromType(payload_ty, .complete));
6273 try f.writeCValueMember(w, local, .{ .identifier = "payload" });6245 try f.writeCValueMember(w, local, .{ .identifier = "payload" });
6274 try a.assign(f, w);6246 try a.assign(f, w);
...@@ -6277,10 +6249,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6277,10 +6249,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
6277 }6249 }
6278 {6250 {
6279 const a = try Assignment.start(f, w, try f.ctypeFromType(err_ty, .complete));6251 const a = try Assignment.start(f, w, try f.ctypeFromType(err_ty, .complete));
6280 if (repr_is_err)6252 try f.writeCValueMember(w, local, .{ .identifier = "error" });
6281 try f.writeCValue(w, local, .Other)
6282 else
6283 try f.writeCValueMember(w, local, .{ .identifier = "error" });
6284 try a.assign(f, w);6253 try a.assign(f, w);
6285 try f.object.dg.renderValue(w, try pt.intValue(try pt.errorIntType(), 0), .Other);6254 try f.object.dg.renderValue(w, try pt.intValue(try pt.errorIntType(), 0), .Other);
6286 try a.end(f, w);6255 try a.end(f, w);
...@@ -7411,10 +7380,10 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7411,10 +7380,10 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
7411 var field_it = loaded_struct.iterateRuntimeOrder(ip);7380 var field_it = loaded_struct.iterateRuntimeOrder(ip);
7412 while (field_it.next()) |field_index| {7381 while (field_it.next()) |field_index| {
7413 const field_ty: Type = .fromInterned(loaded_struct.field_types.get(ip)[field_index]);7382 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
7416 const a = try Assignment.start(f, w, try f.ctypeFromType(field_ty, .complete));7385 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) });
7418 try a.assign(f, w);7387 try a.assign(f, w);
7419 try f.writeCValue(w, resolved_elements[field_index], .Other);7388 try f.writeCValue(w, resolved_elements[field_index], .Other);
7420 try a.end(f, w);7389 try a.end(f, w);
...@@ -7426,7 +7395,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7426,7 +7395,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
7426 .tuple_type => |tuple_info| for (0..tuple_info.types.len) |field_index| {7395 .tuple_type => |tuple_info| for (0..tuple_info.types.len) |field_index| {
7427 if (tuple_info.values.get(ip)[field_index] != .none) continue;7396 if (tuple_info.values.get(ip)[field_index] != .none) continue;
7428 const field_ty: Type = .fromInterned(tuple_info.types.get(ip)[field_index]);7397 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
7431 const a = try Assignment.start(f, w, try f.ctypeFromType(field_ty, .complete));7400 const a = try Assignment.start(f, w, try f.ctypeFromType(field_ty, .complete));
7432 try f.writeCValueMember(w, local, .{ .field = field_index });7401 try f.writeCValueMember(w, local, .{ .field = field_index });
...@@ -7449,13 +7418,13 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7449,13 +7418,13 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
74497418
7450 const union_ty = f.typeOfIndex(inst);7419 const union_ty = f.typeOfIndex(inst);
7451 const loaded_union = ip.loadUnionType(union_ty.toIntern());7420 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];
7453 const payload_ty = f.typeOf(extra.init);7422 const payload_ty = f.typeOf(extra.init);
7454 const payload = try f.resolveInst(extra.init);7423 const payload = try f.resolveInst(extra.init);
7455 try reap(f, inst, &.{extra.init});7424 try reap(f, inst, &.{extra.init});
74567425
7457 const w = &f.object.code.writer;7426 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
7460 const local = try f.allocLocal(inst, union_ty);7429 const local = try f.allocLocal(inst, union_ty);
74617430
...@@ -7466,7 +7435,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7466,7 +7435,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
7466 const a = try Assignment.start(f, w, try f.ctypeFromType(tag_ty, .complete));7435 const a = try Assignment.start(f, w, try f.ctypeFromType(tag_ty, .complete));
7467 try f.writeCValueMember(w, local, .{ .identifier = "tag" });7436 try f.writeCValueMember(w, local, .{ .identifier = "tag" });
7468 try a.assign(f, w);7437 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))});
7470 try a.end(f, w);7439 try a.end(f, w);
7471 break :field .{ .payload_identifier = field_name.toSlice(ip) };7440 break :field .{ .payload_identifier = field_name.toSlice(ip) };
7472 } else .{ .identifier = field_name.toSlice(ip) };7441 } else .{ .identifier = field_name.toSlice(ip) };
src/codegen/c/Type.zig+30-29
...@@ -2558,7 +2558,7 @@ pub const Pool = struct {...@@ -2558,7 +2558,7 @@ pub const Pool = struct {
2558 .tag = .@"struct",2558 .tag = .@"struct",
2559 .name = .{ .index = ip_index },2559 .name = .{ .index = ip_index },
2560 });2560 });
2561 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))2561 if (kind.isForward()) return if (ty.hasRuntimeBits(zcu))
2562 fwd_decl2562 fwd_decl
2563 else2563 else
2564 .void;2564 .void;
...@@ -2584,9 +2584,9 @@ pub const Pool = struct {...@@ -2584,9 +2584,9 @@ pub const Pool = struct {
2584 kind.noParameter(),2584 kind.noParameter(),
2585 );2585 );
2586 if (field_ctype.index == .void) continue;2586 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));
2588 const field_alignas = AlignAs.fromAlignment(.{2588 const field_alignas = AlignAs.fromAlignment(.{
2589 .@"align" = loaded_struct.fieldAlign(ip, field_index),2589 .@"align" = loaded_struct.field_aligns.getOrNone(ip, field_index),
2590 .abi = field_type.abiAlignment(zcu),2590 .abi = field_type.abiAlignment(zcu),
2591 });2591 });
2592 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{2592 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
...@@ -2613,7 +2613,7 @@ pub const Pool = struct {...@@ -2613,7 +2613,7 @@ pub const Pool = struct {
2613 .@"packed" => return pool.fromType(2613 .@"packed" => return pool.fromType(
2614 allocator,2614 allocator,
2615 scratch,2615 scratch,
2616 Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)),2616 .fromInterned(loaded_struct.packed_backing_int_type),
2617 pt,2617 pt,
2618 mod,2618 mod,
2619 kind,2619 kind,
...@@ -2682,17 +2682,17 @@ pub const Pool = struct {...@@ -2682,17 +2682,17 @@ pub const Pool = struct {
2682 },2682 },
2683 .union_type => {2683 .union_type => {
2684 const loaded_union = ip.loadUnionType(ip_index);2684 const loaded_union = ip.loadUnionType(ip_index);
2685 switch (loaded_union.flagsUnordered(ip).layout) {2685 switch (loaded_union.layout) {
2686 .auto, .@"extern" => {2686 .auto, .@"extern" => {
2687 const fwd_decl = try pool.getFwdDecl(allocator, .{2687 const fwd_decl = try pool.getFwdDecl(allocator, .{
2688 .tag = if (loaded_union.has_runtime_tag) .@"struct" else .@"union",2688 .tag = if (loaded_union.has_runtime_tag) .@"struct" else .@"union",
2689 .name = .{ .index = ip_index },2689 .name = .{ .index = ip_index },
2690 });2690 });
2691 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))2691 if (kind.isForward()) return if (ty.hasRuntimeBits(zcu))
2692 fwd_decl2692 fwd_decl
2693 else2693 else
2694 .void;2694 .void;
2695 const loaded_tag = loaded_union.loadTagType(ip);2695 const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type);
2696 const scratch_top = scratch.items.len;2696 const scratch_top = scratch.items.len;
2697 defer scratch.shrinkRetainingCapacity(scratch_top);2697 defer scratch.shrinkRetainingCapacity(scratch_top);
2698 try scratch.ensureUnusedCapacity(2698 try scratch.ensureUnusedCapacity(
...@@ -2718,10 +2718,10 @@ pub const Pool = struct {...@@ -2718,10 +2718,10 @@ pub const Pool = struct {
2718 if (field_ctype.index == .void) continue;2718 if (field_ctype.index == .void) continue;
2719 const field_name = try pool.string(2719 const field_name = try pool.string(
2720 allocator,2720 allocator,
2721 loaded_tag.names.get(ip)[field_index].toSlice(ip),2721 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
2722 );2722 );
2723 const field_alignas = AlignAs.fromAlignment(.{2723 const field_alignas = AlignAs.fromAlignment(.{
2724 .@"align" = loaded_union.fieldAlign(ip, field_index),2724 .@"align" = loaded_union.field_aligns.getOrNone(ip, field_index),
2725 .abi = field_type.abiAlignment(zcu),2725 .abi = field_type.abiAlignment(zcu),
2726 });2726 });
2727 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{2727 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
...@@ -2753,24 +2753,22 @@ pub const Pool = struct {...@@ -2753,24 +2753,22 @@ pub const Pool = struct {
2753 try pool.ensureUnusedCapacity(allocator, 2);2753 try pool.ensureUnusedCapacity(allocator, 2);
2754 var struct_fields: [2]Info.Field = undefined;2754 var struct_fields: [2]Info.Field = undefined;
2755 var struct_fields_len: usize = 0;2755 var struct_fields_len: usize = 0;
2756 if (loaded_tag.tag_ty != .comptime_int_type) {2756 const tag_type = Type.fromInterned(loaded_tag.int_tag_type);
2757 const tag_type = Type.fromInterned(loaded_tag.tag_ty);2757 const tag_ctype: CType = try pool.fromType(
2758 const tag_ctype: CType = try pool.fromType(2758 allocator,
2759 allocator,2759 scratch,
2760 scratch,2760 tag_type,
2761 tag_type,2761 pt,
2762 pt,2762 mod,
2763 mod,2763 kind.noParameter(),
2764 kind.noParameter(),2764 );
2765 );2765 if (tag_ctype.index != .void) {
2766 if (tag_ctype.index != .void) {2766 struct_fields[struct_fields_len] = .{
2767 struct_fields[struct_fields_len] = .{2767 .name = .{ .index = .tag },
2768 .name = .{ .index = .tag },2768 .ctype = tag_ctype,
2769 .ctype = tag_ctype,2769 .alignas = AlignAs.fromAbiAlignment(tag_type.abiAlignment(zcu)),
2770 .alignas = AlignAs.fromAbiAlignment(tag_type.abiAlignment(zcu)),2770 };
2771 };2771 struct_fields_len += 1;
2772 struct_fields_len += 1;
2773 }
2774 }2772 }
2775 if (fields_len > 0) {2773 if (fields_len > 0) {
2776 const payload_ctype = payload_ctype: {2774 const payload_ctype = payload_ctype: {
...@@ -2823,12 +2821,14 @@ pub const Pool = struct {...@@ -2823,12 +2821,14 @@ pub const Pool = struct {
2823 .enum_type => return pool.fromType(2821 .enum_type => return pool.fromType(
2824 allocator,2822 allocator,
2825 scratch,2823 scratch,
2826 Type.fromInterned(ip.loadEnumType(ip_index).tag_ty),2824 .fromInterned(ip.loadEnumType(ip_index).int_tag_type),
2827 pt,2825 pt,
2828 mod,2826 mod,
2829 kind,2827 kind,
2830 ),2828 ),
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
2832 const scratch_top = scratch.items.len;2832 const scratch_top = scratch.items.len;
2833 defer scratch.shrinkRetainingCapacity(scratch_top);2833 defer scratch.shrinkRetainingCapacity(scratch_top);
2834 try scratch.ensureUnusedCapacity(allocator, func_info.param_types.len);2834 try scratch.ensureUnusedCapacity(allocator, func_info.param_types.len);
...@@ -2894,6 +2894,7 @@ pub const Pool = struct {...@@ -2894,6 +2894,7 @@ pub const Pool = struct {
2894 .opt,2894 .opt,
2895 .aggregate,2895 .aggregate,
2896 .un,2896 .un,
2897 .bitpack,
2897 .memoized_call,2898 .memoized_call,
2898 => unreachable, // values, not types2899 => unreachable, // values, not types
2899 },2900 },
src/codegen/riscv64/CodeGen.zig+23-30
...@@ -3257,7 +3257,7 @@ fn airOptionalPayload(func: *Func, inst: Air.Inst.Index) !void {...@@ -3257,7 +3257,7 @@ fn airOptionalPayload(func: *Func, inst: Air.Inst.Index) !void {
3257 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3257 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3258 const result: MCValue = result: {3258 const result: MCValue = result: {
3259 const pl_ty = func.typeOfIndex(inst);3259 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
3262 const opt_mcv = try func.resolveInst(ty_op.operand);3262 const opt_mcv = try func.resolveInst(ty_op.operand);
3263 if (func.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {3263 if (func.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {
...@@ -3331,7 +3331,7 @@ fn airUnwrapErrErr(func: *Func, inst: Air.Inst.Index) !void {...@@ -3331,7 +3331,7 @@ fn airUnwrapErrErr(func: *Func, inst: Air.Inst.Index) !void {
3331 break :result .{ .immediate = 0 };3331 break :result .{ .immediate = 0 };
3332 }3332 }
33333333
3334 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3334 if (!payload_ty.hasRuntimeBits(zcu)) {
3335 break :result operand;3335 break :result operand;
3336 }3336 }
33373337
...@@ -3384,7 +3384,7 @@ fn genUnwrapErrUnionPayloadMir(...@@ -3384,7 +3384,7 @@ fn genUnwrapErrUnionPayloadMir(
3384 const payload_ty = err_union_ty.errorUnionPayload(zcu);3384 const payload_ty = err_union_ty.errorUnionPayload(zcu);
33853385
3386 const result: MCValue = result: {3386 const result: MCValue = result: {
3387 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;3387 if (!payload_ty.hasRuntimeBits(zcu)) break :result .none;
33883388
3389 const payload_off: u31 = @intCast(errUnionPayloadOffset(payload_ty, zcu));3389 const payload_off: u31 = @intCast(errUnionPayloadOffset(payload_ty, zcu));
3390 switch (err_union) {3390 switch (err_union) {
...@@ -3547,7 +3547,7 @@ fn airWrapErrUnionPayload(func: *Func, inst: Air.Inst.Index) !void {...@@ -3547,7 +3547,7 @@ fn airWrapErrUnionPayload(func: *Func, inst: Air.Inst.Index) !void {
3547 const operand = try func.resolveInst(ty_op.operand);3547 const operand = try func.resolveInst(ty_op.operand);
35483548
3549 const result: MCValue = result: {3549 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
3552 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));3552 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
3553 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));3553 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
...@@ -3571,7 +3571,7 @@ fn airWrapErrUnionErr(func: *Func, inst: Air.Inst.Index) !void {...@@ -3571,7 +3571,7 @@ fn airWrapErrUnionErr(func: *Func, inst: Air.Inst.Index) !void {
3571 const err_ty = eu_ty.errorUnionSet(zcu);3571 const err_ty = eu_ty.errorUnionSet(zcu);
35723572
3573 const result: MCValue = result: {3573 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
3576 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));3576 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
3577 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));3577 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
...@@ -3761,7 +3761,7 @@ fn airSliceElemVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -3761,7 +3761,7 @@ fn airSliceElemVal(func: *Func, inst: Air.Inst.Index) !void {
37613761
3762 const result: MCValue = result: {3762 const result: MCValue = result: {
3763 const elem_ty = func.typeOfIndex(inst);3763 const elem_ty = func.typeOfIndex(inst);
3764 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;3764 assert(elem_ty.hasRuntimeBits(zcu));
37653765
3766 const slice_ty = func.typeOf(bin_op.lhs);3766 const slice_ty = func.typeOf(bin_op.lhs);
3767 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);3767 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);
...@@ -3914,7 +3914,7 @@ fn airPtrElemVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -3914,7 +3914,7 @@ fn airPtrElemVal(func: *Func, inst: Air.Inst.Index) !void {
39143914
3915 const result: MCValue = if (!is_volatile and func.liveness.isUnused(inst)) .unreach else result: {3915 const result: MCValue = if (!is_volatile and func.liveness.isUnused(inst)) .unreach else result: {
3916 const elem_ty = base_ptr_ty.indexableElem(zcu);3916 const elem_ty = base_ptr_ty.indexableElem(zcu);
3917 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;3917 assert(elem_ty.hasRuntimeBits(zcu));
3918 const base_ptr_mcv = try func.resolveInst(bin_op.lhs);3918 const base_ptr_mcv = try func.resolveInst(bin_op.lhs);
3919 const base_ptr_lock: ?RegisterLock = switch (base_ptr_mcv) {3919 const base_ptr_lock: ?RegisterLock = switch (base_ptr_mcv) {
3920 .register => |reg| func.register_manager.lockRegAssumeUnused(reg),3920 .register => |reg| func.register_manager.lockRegAssumeUnused(reg),
...@@ -4617,7 +4617,7 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -4617,7 +4617,7 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
4617 const src_mcv = try func.resolveInst(operand);4617 const src_mcv = try func.resolveInst(operand);
4618 const struct_ty = func.typeOf(operand);4618 const struct_ty = func.typeOf(operand);
4619 const field_ty = struct_ty.fieldType(index, zcu);4619 const field_ty = struct_ty.fieldType(index, zcu);
4620 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;4620 assert(field_ty.hasRuntimeBits(zcu));
46214621
4622 const field_off: u32 = switch (struct_ty.containerLayout(zcu)) {4622 const field_off: u32 = switch (struct_ty.containerLayout(zcu)) {
4623 .auto, .@"extern" => @intCast(struct_ty.structFieldOffset(index, zcu) * 8),4623 .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 {...@@ -5126,7 +5126,6 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
5126 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;5126 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5127 const pt = func.pt;5127 const pt = func.pt;
5128 const zcu = pt.zcu;5128 const zcu = pt.zcu;
5129 const ip = &zcu.intern_pool;
51305129
5131 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {5130 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
5132 const lhs_ty = func.typeOf(bin_op.lhs);5131 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 {...@@ -5140,28 +5139,23 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
5140 .optional,5139 .optional,
5141 .@"struct",5140 .@"struct",
5142 => {5141 => {
5143 const int_ty = switch (lhs_ty.zigTypeTag(zcu)) {5142 const int_ty: Type = switch (lhs_ty.zigTypeTag(zcu)) {
5144 .@"enum" => lhs_ty.intTagType(zcu),5143 .@"enum" => lhs_ty.intTagType(zcu),
5145 .int => lhs_ty,5144 .int => lhs_ty,
5146 .bool => Type.u1,5145 .bool => .u1,
5147 .pointer => Type.u64,5146 .pointer => .u64,
5148 .error_set => Type.anyerror,5147 .error_set => .anyerror,
5149 .optional => blk: {5148 .optional => blk: {
5150 const payload_ty = lhs_ty.optionalChild(zcu);5149 const payload_ty = lhs_ty.optionalChild(zcu);
5151 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {5150 if (!payload_ty.hasRuntimeBits(zcu)) {
5152 break :blk Type.u1;5151 break :blk .u1;
5153 } else if (lhs_ty.isPtrLikeOptional(zcu)) {5152 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
5154 break :blk Type.u64;5153 break :blk .u64;
5155 } else {5154 } else {
5156 return func.fail("TODO riscv cmp non-pointer optionals", .{});5155 return func.fail("TODO riscv cmp non-pointer optionals", .{});
5157 }5156 }
5158 },5157 },
5159 .@"struct" => blk: {5158 .@"struct", .@"union" => lhs_ty.bitpackBackingInt(zcu),
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 },
5165 else => unreachable,5159 else => unreachable,
5166 };5160 };
51675161
...@@ -5925,8 +5919,7 @@ fn airBr(func: *Func, inst: Air.Inst.Index) !void {...@@ -5925,8 +5919,7 @@ fn airBr(func: *Func, inst: Air.Inst.Index) !void {
5925 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;5919 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;
59265920
5927 const block_ty = func.typeOfIndex(br.block_inst);5921 const block_ty = func.typeOfIndex(br.block_inst);
5928 const block_unused =5922 const block_unused = !block_ty.hasRuntimeBits(zcu) or func.liveness.isUnused(br.block_inst);
5929 !block_ty.hasRuntimeBitsIgnoreComptime(zcu) or func.liveness.isUnused(br.block_inst);
5930 const block_tracking = func.inst_tracking.getPtr(br.block_inst).?;5923 const block_tracking = func.inst_tracking.getPtr(br.block_inst).?;
5931 const block_data = func.blocks.getPtr(br.block_inst).?;5924 const block_data = func.blocks.getPtr(br.block_inst).?;
5932 const first_br = block_data.relocs.items.len == 0;5925 const first_br = block_data.relocs.items.len == 0;
...@@ -8249,7 +8242,7 @@ fn resolveCallingConventionValues(...@@ -8249,7 +8242,7 @@ fn resolveCallingConventionValues(
8249 // Return values8242 // Return values
8250 if (ret_ty.zigTypeTag(zcu) == .noreturn) {8243 if (ret_ty.zigTypeTag(zcu) == .noreturn) {
8251 result.return_value = InstTracking.init(.unreach);8244 result.return_value = InstTracking.init(.unreach);
8252 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {8245 } else if (!ret_ty.hasRuntimeBits(zcu)) {
8253 result.return_value = InstTracking.init(.none);8246 result.return_value = InstTracking.init(.none);
8254 } else {8247 } else {
8255 var ret_tracking: [2]InstTracking = undefined;8248 var ret_tracking: [2]InstTracking = undefined;
...@@ -8300,7 +8293,7 @@ fn resolveCallingConventionValues(...@@ -8300,7 +8293,7 @@ fn resolveCallingConventionValues(
8300 var param_float_reg_i: usize = 0;8293 var param_float_reg_i: usize = 0;
83018294
8302 for (param_types, result.args) |ty, *arg| {8295 for (param_types, result.args) |ty, *arg| {
8303 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {8296 if (!ty.hasRuntimeBits(zcu)) {
8304 assert(cc == .auto);8297 assert(cc == .auto);
8305 arg.* = .none;8298 arg.* = .none;
8306 continue;8299 continue;
...@@ -8415,10 +8408,10 @@ fn hasFeature(func: *Func, feature: Target.riscv.Feature) bool {...@@ -8415,10 +8408,10 @@ fn hasFeature(func: *Func, feature: Target.riscv.Feature) bool {
8415}8408}
84168409
8417pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {8410pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {
8418 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;8411 if (!payload_ty.hasRuntimeBits(zcu)) return 0;
8419 const payload_align = payload_ty.abiAlignment(zcu);8412 const payload_align = payload_ty.abiAlignment(zcu);
8420 const error_align = Type.anyerror.abiAlignment(zcu);8413 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)) {
8422 return 0;8415 return 0;
8423 } else {8416 } else {
8424 return payload_align.forward(Type.anyerror.abiSize(zcu));8417 return payload_align.forward(Type.anyerror.abiSize(zcu));
...@@ -8426,10 +8419,10 @@ pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {...@@ -8426,10 +8419,10 @@ pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {
8426}8419}
84278420
8428pub fn errUnionErrorOffset(payload_ty: Type, zcu: *Zcu) u64 {8421pub fn errUnionErrorOffset(payload_ty: Type, zcu: *Zcu) u64 {
8429 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;8422 if (!payload_ty.hasRuntimeBits(zcu)) return 0;
8430 const payload_align = payload_ty.abiAlignment(zcu);8423 const payload_align = payload_ty.abiAlignment(zcu);
8431 const error_align = Type.anyerror.abiAlignment(zcu);8424 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)) {
8433 return error_align.forward(payload_ty.abiSize(zcu));8426 return error_align.forward(payload_ty.abiSize(zcu));
8434 } else {8427 } else {
8435 return 0;8428 return 0;
src/codegen/sparc64/CodeGen.zig+11-11
...@@ -1102,7 +1102,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -1102,7 +1102,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
1102fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !void {1102fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !void {
1103 try self.blocks.putNoClobber(self.gpa, inst, .{1103 try self.blocks.putNoClobber(self.gpa, inst, .{
1104 // A block is a setup to be able to jump to the end.1104 // A block is a setup to be able to jump to the end.
1105 .relocs = .{},1105 .relocs = .empty,
1106 // It also acts as a receptacle for break operands.1106 // It also acts as a receptacle for break operands.
1107 // Here we use `MCValue.none` to represent a null value so that the first1107 // Here we use `MCValue.none` to represent a null value so that the first
1108 // break instruction will choose a MCValue for the block result and overwrite1108 // 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 {...@@ -1376,19 +1376,19 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1376 const rhs = try self.resolveInst(bin_op.rhs);1376 const rhs = try self.resolveInst(bin_op.rhs);
1377 const lhs_ty = self.typeOf(bin_op.lhs);1377 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)) {
1380 .vector => unreachable, // Handled by cmp_vector.1380 .vector => unreachable, // Handled by cmp_vector.
1381 .@"enum" => lhs_ty.intTagType(zcu),1381 .@"enum" => lhs_ty.intTagType(zcu),
1382 .int => lhs_ty,1382 .int => lhs_ty,
1383 .bool => Type.u1,1383 .bool => .u1,
1384 .pointer => Type.usize,1384 .pointer => .usize,
1385 .error_set => Type.u16,1385 .error_set => .u16,
1386 .optional => blk: {1386 .optional => blk: {
1387 const payload_ty = lhs_ty.optionalChild(zcu);1387 const payload_ty = lhs_ty.optionalChild(zcu);
1388 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {1388 if (!payload_ty.hasRuntimeBits(zcu)) {
1389 break :blk Type.u1;1389 break :blk .u1;
1390 } else if (lhs_ty.isPtrLikeOptional(zcu)) {1390 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
1391 break :blk Type.usize;1391 break :blk .usize;
1392 } else {1392 } else {
1393 return self.fail("TODO SPARCv9 cmp non-pointer optionals", .{});1393 return self.fail("TODO SPARCv9 cmp non-pointer optionals", .{});
1394 }1394 }
...@@ -3452,8 +3452,8 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)...@@ -3452,8 +3452,8 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
3452 if (err_ty.errorSetIsEmpty(zcu)) {3452 if (err_ty.errorSetIsEmpty(zcu)) {
3453 return error_union_mcv;3453 return error_union_mcv;
3454 }3454 }
3455 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3455 if (!payload_ty.hasRuntimeBits(zcu)) {
3456 return MCValue.none;3456 return .none;
3457 }3457 }
34583458
3459 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, zcu));3459 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, zcu));
...@@ -4481,7 +4481,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -4481,7 +4481,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
4481 const ty = self.typeOf(ref);4481 const ty = self.typeOf(ref);
44824482
4483 // If the type has no codegen bits, no need to store it.4483 // 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
4486 if (ref.toIndex()) |inst| {4486 if (ref.toIndex()) |inst| {
4487 return self.getResolvedInstValue(inst);4487 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 {...@@ -208,7 +208,7 @@ pub fn genNav(cg: *CodeGen, do_codegen: bool) Error!void {
208 try cg.args.ensureUnusedCapacity(gpa, fn_info.param_types.len);208 try cg.args.ensureUnusedCapacity(gpa, fn_info.param_types.len);
209 for (fn_info.param_types.get(ip)) |param_ty_index| {209 for (fn_info.param_types.get(ip)) |param_ty_index| {
210 const param_ty: Type = .fromInterned(param_ty_index);210 const param_ty: Type = .fromInterned(param_ty_index);
211 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;211 if (!param_ty.hasRuntimeBits(zcu)) continue;
212212
213 const param_type_id = try cg.resolveType(param_ty, .direct);213 const param_type_id = try cg.resolveType(param_ty, .direct);
214 const arg_result_id = cg.module.allocId();214 const arg_result_id = cg.module.allocId();
...@@ -884,7 +884,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {...@@ -884,7 +884,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
884 return try cg.constructComposite(comp_ty_id, &constituents);884 return try cg.constructComposite(comp_ty_id, &constituents);
885 },885 },
886 .enum_tag => {886 .enum_tag => {
887 const int_val = try val.intFromEnum(ty, pt);887 const int_val = val.intFromEnum(zcu);
888 const int_ty = ty.intTagType(zcu);888 const int_ty = ty.intTagType(zcu);
889 break :cache try cg.constant(int_ty, int_val, repr);889 break :cache try cg.constant(int_ty, int_val, repr);
890 },890 },
...@@ -959,18 +959,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {...@@ -959,18 +959,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
959 },959 },
960 .struct_type => {960 .struct_type => {
961 const struct_type = zcu.typeToStruct(ty).?;961 const struct_type = zcu.typeToStruct(ty).?;
962962 assert(struct_type.layout != .@"packed"); // packed structs use `bitpack`
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 }
974963
975 var types = std.array_list.Managed(Type).init(gpa);964 var types = std.array_list.Managed(Type).init(gpa);
976 defer types.deinit();965 defer types.deinit();
...@@ -981,7 +970,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {...@@ -981,7 +970,7 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
981 var it = struct_type.iterateRuntimeOrder(ip);970 var it = struct_type.iterateRuntimeOrder(ip);
982 while (it.next()) |field_index| {971 while (it.next()) |field_index| {
983 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);972 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)) {
985 // This is a zero-bit field - we only needed it for the alignment.974 // This is a zero-bit field - we only needed it for the alignment.
986 continue;975 continue;
987 }976 }
...@@ -1001,20 +990,24 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {...@@ -1001,20 +990,24 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
1001 else => unreachable,990 else => unreachable,
1002 },991 },
1003 .un => |un| {992 .un => |un| {
993 assert(ty.containerLayout(zcu) != .@"packed"); // packed unions use `bitpack`
1004 if (un.tag == .none) {994 if (un.tag == .none) {
1005 assert(ty.containerLayout(zcu) == .@"packed"); // TODO995 @panic("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));
1008 }996 }
1009 const active_field = ty.unionTagFieldIndex(.fromInterned(un.tag), zcu).?;997 const active_field = ty.unionTagFieldIndex(.fromInterned(un.tag), zcu).?;
1010 const union_obj = zcu.typeToUnion(ty).?;998 const union_obj = zcu.typeToUnion(ty).?;
1011 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[active_field]);999 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))
1013 try cg.constant(field_ty, .fromInterned(un.val), .direct)1001 try cg.constant(field_ty, .fromInterned(un.val), .direct)
1014 else1002 else
1015 null;1003 null;
1016 return try cg.unionInit(ty, active_field, payload);1004 return try cg.unionInit(ty, active_field, payload);
1017 },1005 },
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
1018 .memoized_call => unreachable,1011 .memoized_call => unreachable,
1019 }1012 }
1020 };1013 };
...@@ -1255,17 +1248,16 @@ fn resolveTypeName(cg: *CodeGen, ty: Type) ![]const u8 {...@@ -1255,17 +1248,16 @@ fn resolveTypeName(cg: *CodeGen, ty: Type) ![]const u8 {
1255fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {1248fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {
1256 const gpa = cg.module.gpa;1249 const gpa = cg.module.gpa;
1257 const zcu = cg.module.zcu;1250 const zcu = cg.module.zcu;
1258 const ip = &zcu.intern_pool;
1259 const union_obj = zcu.typeToUnion(ty).?;1251 const union_obj = zcu.typeToUnion(ty).?;
12601252
1261 if (union_obj.flagsUnordered(ip).layout == .@"packed") {1253 if (union_obj.layout == .@"packed") {
1262 return try cg.module.intType(.unsigned, @intCast(ty.bitSize(zcu)));1254 return try cg.module.intType(.unsigned, @intCast(ty.bitSize(zcu)));
1263 }1255 }
12641256
1265 const layout = cg.unionLayout(ty);1257 const layout = cg.unionLayout(ty);
1266 if (!layout.has_payload) {1258 if (!layout.has_payload) {
1267 // No payload, so represent this as just the tag type.1259 // 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);
1269 }1261 }
12701262
1271 var member_types: [4]Id = undefined;1263 var member_types: [4]Id = undefined;
...@@ -1274,7 +1266,7 @@ fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {...@@ -1274,7 +1266,7 @@ fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {
1274 const u8_ty_id = try cg.resolveType(.u8, .direct);1266 const u8_ty_id = try cg.resolveType(.u8, .direct);
12751267
1276 if (layout.tag_size != 0) {1268 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);
1278 member_types[layout.tag_index] = tag_ty_id;1270 member_types[layout.tag_index] = tag_ty_id;
1279 member_names[layout.tag_index] = "(tag)";1271 member_names[layout.tag_index] = "(tag)";
1280 }1272 }
...@@ -1315,7 +1307,7 @@ fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {...@@ -1315,7 +1307,7 @@ fn resolveUnionType(cg: *CodeGen, ty: Type) !Id {
13151307
1316fn resolveFnReturnType(cg: *CodeGen, ret_ty: Type) !Id {1308fn resolveFnReturnType(cg: *CodeGen, ret_ty: Type) !Id {
1317 const zcu = cg.module.zcu;1309 const zcu = cg.module.zcu;
1318 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {1310 if (!ret_ty.hasRuntimeBits(zcu)) {
1319 // If the return type is an error set or an error union, then we make this1311 // If the return type is an error set or an error union, then we make this
1320 // anyerror return type instead, so that it can be coerced into a function1312 // anyerror return type instead, so that it can be coerced into a function
1321 // pointer type which has anyerror as the return type.1313 // pointer type which has anyerror as the return type.
...@@ -1389,7 +1381,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -1389,7 +1381,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
1389 return cg.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(zcu)});1381 return cg.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(zcu)});
1390 };1382 };
13911383
1392 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) {1384 if (!elem_ty.hasRuntimeBits(zcu)) {
1393 assert(repr == .indirect);1385 assert(repr == .indirect);
1394 if (target.os.tag != .opencl) return cg.fail("cannot generate opaque type", .{});1386 if (target.os.tag != .opencl) return cg.fail("cannot generate opaque type", .{});
1395 return try cg.module.opaqueType("zero-sized-array");1387 return try cg.module.opaqueType("zero-sized-array");
...@@ -1453,7 +1445,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -1453,7 +1445,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
1453 var param_index: usize = 0;1445 var param_index: usize = 0;
1454 for (fn_info.param_types.get(ip)) |param_ty_index| {1446 for (fn_info.param_types.get(ip)) |param_ty_index| {
1455 const param_ty: Type = .fromInterned(param_ty_index);1447 const param_ty: Type = .fromInterned(param_ty_index);
1456 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;1448 if (!param_ty.hasRuntimeBits(zcu)) continue;
14571449
1458 param_ty_ids[param_index] = try cg.resolveType(param_ty, .direct);1450 param_ty_ids[param_index] = try cg.resolveType(param_ty, .direct);
1459 param_index += 1;1451 param_index += 1;
...@@ -1518,7 +1510,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -1518,7 +1510,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
1518 };1510 };
15191511
1520 if (struct_type.layout == .@"packed") {1512 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);
1522 }1514 }
15231515
1524 var member_types = std.array_list.Managed(Id).init(gpa);1516 var member_types = std.array_list.Managed(Id).init(gpa);
...@@ -1533,9 +1525,9 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -1533,9 +1525,9 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
1533 var it = struct_type.iterateRuntimeOrder(ip);1525 var it = struct_type.iterateRuntimeOrder(ip);
1534 while (it.next()) |field_index| {1526 while (it.next()) |field_index| {
1535 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);1527 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];
1539 try member_types.append(try cg.resolveType(field_ty, .indirect));1531 try member_types.append(try cg.resolveType(field_ty, .indirect));
1540 try member_names.append(field_name.toSlice(ip));1532 try member_names.append(field_name.toSlice(ip));
1541 try member_offsets.append(@intCast(ty.structFieldOffset(field_index, zcu)));1533 try member_offsets.append(@intCast(ty.structFieldOffset(field_index, zcu)));
...@@ -1556,7 +1548,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -1556,7 +1548,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
1556 },1548 },
1557 .optional => {1549 .optional => {
1558 const payload_ty = ty.optionalChild(zcu);1550 const payload_ty = ty.optionalChild(zcu);
1559 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {1551 if (!payload_ty.hasRuntimeBits(zcu)) {
1560 // Just use a bool.1552 // Just use a bool.
1561 // Note: Always generate the bool with indirect format, to save on some sanity1553 // Note: Always generate the bool with indirect format, to save on some sanity
1562 // Perform the conversion to a direct bool when the field is extracted.1554 // Perform the conversion to a direct bool when the field is extracted.
...@@ -1653,7 +1645,7 @@ fn errorUnionLayout(cg: *CodeGen, payload_ty: Type) ErrorUnionLayout {...@@ -1653,7 +1645,7 @@ fn errorUnionLayout(cg: *CodeGen, payload_ty: Type) ErrorUnionLayout {
16531645
1654 const error_first = error_align.compare(.gt, payload_align);1646 const error_first = error_align.compare(.gt, payload_align);
1655 return .{1647 return .{
1656 .payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu),1648 .payload_has_bits = payload_ty.hasRuntimeBits(zcu),
1657 .error_first = error_first,1649 .error_first = error_first,
1658 };1650 };
1659}1651}
...@@ -3724,7 +3716,6 @@ fn cmp(...@@ -3724,7 +3716,6 @@ fn cmp(
3724 const gpa = cg.module.gpa;3716 const gpa = cg.module.gpa;
3725 const pt = cg.pt;3717 const pt = cg.pt;
3726 const zcu = cg.module.zcu;3718 const zcu = cg.module.zcu;
3727 const ip = &zcu.intern_pool;
3728 const scalar_ty = lhs.ty.scalarType(zcu);3719 const scalar_ty = lhs.ty.scalarType(zcu);
3729 const is_vector = lhs.ty.isVector(zcu);3720 const is_vector = lhs.ty.isVector(zcu);
37303721
...@@ -3737,7 +3728,7 @@ fn cmp(...@@ -3737,7 +3728,7 @@ fn cmp(
3737 },3728 },
3738 .@"struct" => {3729 .@"struct" => {
3739 const struct_ty = zcu.typeToPackedStruct(scalar_ty).?;3730 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);
3741 return try cg.cmp(op, lhs.pun(ty), rhs.pun(ty));3732 return try cg.cmp(op, lhs.pun(ty), rhs.pun(ty));
3742 },3733 },
3743 .error_set => {3734 .error_set => {
...@@ -3778,7 +3769,7 @@ fn cmp(...@@ -3778,7 +3769,7 @@ fn cmp(
37783769
3779 const payload_ty = ty.optionalChild(zcu);3770 const payload_ty = ty.optionalChild(zcu);
3780 if (ty.optionalReprIsPayload(zcu)) {3771 if (ty.optionalReprIsPayload(zcu)) {
3781 assert(payload_ty.hasRuntimeBitsIgnoreComptime(zcu));3772 assert(payload_ty.hasRuntimeBits(zcu));
3782 assert(!payload_ty.isSlice(zcu));3773 assert(!payload_ty.isSlice(zcu));
37833774
3784 return try cg.cmp(op, lhs.pun(payload_ty), rhs.pun(payload_ty));3775 return try cg.cmp(op, lhs.pun(payload_ty), rhs.pun(payload_ty));
...@@ -3787,12 +3778,12 @@ fn cmp(...@@ -3787,12 +3778,12 @@ fn cmp(
3787 const lhs_id = try lhs.materialize(cg);3778 const lhs_id = try lhs.materialize(cg);
3788 const rhs_id = try rhs.materialize(cg);3779 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))
3791 try cg.extractField(.bool, lhs_id, 1)3782 try cg.extractField(.bool, lhs_id, 1)
3792 else3783 else
3793 try cg.convertToDirect(.bool, lhs_id);3784 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))
3796 try cg.extractField(.bool, rhs_id, 1)3787 try cg.extractField(.bool, rhs_id, 1)
3797 else3788 else
3798 try cg.convertToDirect(.bool, rhs_id);3789 try cg.convertToDirect(.bool, rhs_id);
...@@ -3800,7 +3791,7 @@ fn cmp(...@@ -3800,7 +3791,7 @@ fn cmp(
3800 const lhs_valid: Temporary = .init(.bool, lhs_valid_id);3791 const lhs_valid: Temporary = .init(.bool, lhs_valid_id);
3801 const rhs_valid: Temporary = .init(.bool, rhs_valid_id);3792 const rhs_valid: Temporary = .init(.bool, rhs_valid_id);
38023793
3803 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3794 if (!payload_ty.hasRuntimeBits(zcu)) {
3804 return try cg.cmp(op, lhs_valid, rhs_valid);3795 return try cg.cmp(op, lhs_valid, rhs_valid);
3805 }3796 }
38063797
...@@ -4138,7 +4129,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -4138,7 +4129,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
4138 const array_ptr_id = try cg.resolve(ty_op.operand);4129 const array_ptr_id = try cg.resolve(ty_op.operand);
4139 const len_id = try cg.constInt(.usize, array_ty.arrayLen(zcu));4130 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))
4142 // Note: The pointer is something like *opaque{}, so we need to bitcast it to the element type.4133 // Note: The pointer is something like *opaque{}, so we need to bitcast it to the element type.
4143 try cg.bitCast(elem_ptr_ty, array_ptr_ty, array_ptr_id)4134 try cg.bitCast(elem_ptr_ty, array_ptr_ty, array_ptr_id)
4144 else4135 else
...@@ -4174,12 +4165,12 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -4174,12 +4165,12 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
4174 .@"struct" => {4165 .@"struct" => {
4175 if (zcu.typeToPackedStruct(result_ty)) |struct_type| {4166 if (zcu.typeToPackedStruct(result_ty)) |struct_type| {
4176 comptime assert(Type.packed_struct_layout_version == 2);4167 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);
4178 var running_int_id = try cg.constInt(backing_int_ty, 0);4169 var running_int_id = try cg.constInt(backing_int_ty, 0);
4179 var running_bits: u16 = 0;4170 var running_bits: u16 = 0;
4180 for (struct_type.field_types.get(ip), elements) |field_ty_ip, element| {4171 for (struct_type.field_types.get(ip), elements) |field_ty_ip, element| {
4181 const field_ty: Type = .fromInterned(field_ty_ip);4172 const field_ty: Type = .fromInterned(field_ty_ip);
4182 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;4173 if (!field_ty.hasRuntimeBits(zcu)) continue;
4183 const field_id = try cg.resolve(element);4174 const field_id = try cg.resolve(element);
4184 const ty_bit_size: u16 = @intCast(field_ty.bitSize(zcu));4175 const ty_bit_size: u16 = @intCast(field_ty.bitSize(zcu));
4185 const field_int_ty = try cg.pt.intType(.unsigned, ty_bit_size);4176 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 {...@@ -4239,7 +4230,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
4239 const field_index = it.next().?;4230 const field_index = it.next().?;
4240 if ((try result_ty.structFieldValueComptime(pt, i)) != null) continue;4231 if ((try result_ty.structFieldValueComptime(pt, i)) != null) continue;
4241 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);4232 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
4244 const id = try cg.resolve(element);4235 const id = try cg.resolve(element);
4245 types[index] = field_ty;4236 types[index] = field_ty;
...@@ -4399,10 +4390,7 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -4399,10 +4390,7 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
4399 const elem_ty = src_ptr_ty.childType(zcu);4390 const elem_ty = src_ptr_ty.childType(zcu);
4400 const ptr_id = try cg.resolve(bin_op.lhs);4391 const ptr_id = try cg.resolve(bin_op.lhs);
44014392
4402 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4393 assert(elem_ty.hasRuntimeBits(zcu));
4403 const dst_ptr_ty = cg.typeOfIndex(inst);
4404 return try cg.bitCast(dst_ptr_ty, src_ptr_ty, ptr_id);
4405 }
44064394
4407 const index_id = try cg.resolve(bin_op.rhs);4395 const index_id = try cg.resolve(bin_op.rhs);
4408 return try cg.ptrElemPtr(src_ptr_ty, ptr_id, index_id);4396 return try cg.ptrElemPtr(src_ptr_ty, ptr_id, index_id);
...@@ -4526,13 +4514,13 @@ fn unionInit(...@@ -4526,13 +4514,13 @@ fn unionInit(
4526 const zcu = cg.module.zcu;4514 const zcu = cg.module.zcu;
4527 const ip = &zcu.intern_pool;4515 const ip = &zcu.intern_pool;
4528 const union_ty = zcu.typeToUnion(ty).?;4516 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
4531 const layout = cg.unionLayout(ty);4519 const layout = cg.unionLayout(ty);
4532 const payload_ty: Type = .fromInterned(union_ty.field_types.get(ip)[active_field]);4520 const payload_ty: Type = .fromInterned(union_ty.field_types.get(ip)[active_field]);
45334521
4534 if (union_ty.flagsUnordered(ip).layout == .@"packed") {4522 if (union_ty.layout == .@"packed") {
4535 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4523 if (!payload_ty.hasRuntimeBits(zcu)) {
4536 const int_ty = try pt.intType(.unsigned, @intCast(ty.bitSize(zcu)));4524 const int_ty = try pt.intType(.unsigned, @intCast(ty.bitSize(zcu)));
4537 return cg.constInt(int_ty, 0);4525 return cg.constInt(int_ty, 0);
4538 }4526 }
...@@ -4558,7 +4546,7 @@ fn unionInit(...@@ -4558,7 +4546,7 @@ fn unionInit(
45584546
4559 const tag_int = if (layout.tag_size != 0) blk: {4547 const tag_int = if (layout.tag_size != 0) blk: {
4560 const tag_val = try pt.enumValueFieldIndex(tag_ty, active_field);4548 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);
4562 break :blk tag_int_val.toUnsignedInt(zcu);4550 break :blk tag_int_val.toUnsignedInt(zcu);
4563 } else 0;4551 } else 0;
45644552
...@@ -4577,7 +4565,7 @@ fn unionInit(...@@ -4577,7 +4565,7 @@ fn unionInit(
4577 try cg.store(tag_ty, ptr_id, tag_id, .{});4565 try cg.store(tag_ty, ptr_id, tag_id, .{});
4578 }4566 }
45794567
4580 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4568 if (payload_ty.hasRuntimeBits(zcu)) {
4581 const layout_payload_ty_id = try cg.resolveType(layout.payload_ty, .indirect);4569 const layout_payload_ty_id = try cg.resolveType(layout.payload_ty, .indirect);
4582 const pl_ptr_ty_id = try cg.module.ptrType(layout_payload_ty_id, .function);4570 const pl_ptr_ty_id = try cg.module.ptrType(layout_payload_ty_id, .function);
4583 const pl_ptr_id = try cg.accessChain(pl_ptr_ty_id, tmp_id, &.{layout.payload_index});4571 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 {...@@ -4613,7 +4601,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
46134601
4614 const union_obj = zcu.typeToUnion(ty).?;4602 const union_obj = zcu.typeToUnion(ty).?;
4615 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[extra.field_index]);4603 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))
4617 try cg.resolve(extra.init)4605 try cg.resolve(extra.init)
4618 else4606 else
4619 null;4607 null;
...@@ -4631,7 +4619,7 @@ fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -4631,7 +4619,7 @@ fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
4631 const field_index = struct_field.field_index;4619 const field_index = struct_field.field_index;
4632 const field_ty = object_ty.fieldType(field_index, zcu);4620 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
4636 switch (object_ty.zigTypeTag(zcu)) {4624 switch (object_ty.zigTypeTag(zcu)) {
4637 .@"struct" => switch (object_ty.containerLayout(zcu)) {4625 .@"struct" => switch (object_ty.containerLayout(zcu)) {
...@@ -5332,7 +5320,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) !void {...@@ -5332,7 +5320,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) !void {
5332 const zcu = cg.module.zcu;5320 const zcu = cg.module.zcu;
5333 const operand = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5321 const operand = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5334 const ret_ty = cg.typeOf(operand);5322 const ret_ty = cg.typeOf(operand);
5335 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {5323 if (!ret_ty.hasRuntimeBits(zcu)) {
5336 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;5324 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;
5337 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {5325 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
5338 // Functions with an empty error set are emitted with an error code5326 // 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 {...@@ -5356,7 +5344,7 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void {
5356 const ptr_ty = cg.typeOf(un_op);5344 const ptr_ty = cg.typeOf(un_op);
5357 const ret_ty = ptr_ty.childType(zcu);5345 const ret_ty = ptr_ty.childType(zcu);
53585346
5359 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {5347 if (!ret_ty.hasRuntimeBits(zcu)) {
5360 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;5348 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;
5361 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {5349 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
5362 // Functions with an empty error set are emitted with an error code5350 // 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 {...@@ -5573,7 +5561,7 @@ fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum {
55735561
5574 const is_non_null_id = blk: {5562 const is_non_null_id = blk: {
5575 if (is_pointer) {5563 if (is_pointer) {
5576 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {5564 if (payload_ty.hasRuntimeBits(zcu)) {
5577 const storage_class = cg.module.storageClass(operand_ty.ptrAddressSpace(zcu));5565 const storage_class = cg.module.storageClass(operand_ty.ptrAddressSpace(zcu));
5578 const bool_indirect_ty_id = try cg.resolveType(.bool, .indirect);5566 const bool_indirect_ty_id = try cg.resolveType(.bool, .indirect);
5579 const bool_ptr_ty_id = try cg.module.ptrType(bool_indirect_ty_id, storage_class);5567 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 {...@@ -5584,7 +5572,7 @@ fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum {
5584 break :blk try cg.load(.bool, operand_id, .{});5572 break :blk try cg.load(.bool, operand_id, .{});
5585 }5573 }
55865574
5587 break :blk if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu))5575 break :blk if (payload_ty.hasRuntimeBits(zcu))
5588 try cg.extractField(.bool, operand_id, 1)5576 try cg.extractField(.bool, operand_id, 1)
5589 else5577 else
5590 // Optional representation is bool indicating whether the optional is set5578 // Optional representation is bool indicating whether the optional is set
...@@ -5653,7 +5641,7 @@ fn airUnwrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -5653,7 +5641,7 @@ fn airUnwrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
5653 const optional_ty = cg.typeOf(ty_op.operand);5641 const optional_ty = cg.typeOf(ty_op.operand);
5654 const payload_ty = cg.typeOfIndex(inst);5642 const payload_ty = cg.typeOfIndex(inst);
56555643
5656 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return null;5644 if (!payload_ty.hasRuntimeBits(zcu)) return null;
56575645
5658 if (optional_ty.optionalReprIsPayload(zcu)) {5646 if (optional_ty.optionalReprIsPayload(zcu)) {
5659 return operand_id;5647 return operand_id;
...@@ -5672,7 +5660,7 @@ fn airUnwrapOptionalPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -5672,7 +5660,7 @@ fn airUnwrapOptionalPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
5672 const result_ty = cg.typeOfIndex(inst);5660 const result_ty = cg.typeOfIndex(inst);
5673 const result_ty_id = try cg.resolveType(result_ty, .direct);5661 const result_ty_id = try cg.resolveType(result_ty, .direct);
56745662
5675 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {5663 if (!payload_ty.hasRuntimeBits(zcu)) {
5676 // There is no payload, but we still need to return a valid pointer.5664 // There is no payload, but we still need to return a valid pointer.
5677 // We can just return anything here, so just return a pointer to the operand.5665 // We can just return anything here, so just return a pointer to the operand.
5678 return try cg.bitCast(result_ty, operand_ty, operand_id);5666 return try cg.bitCast(result_ty, operand_ty, operand_id);
...@@ -5691,9 +5679,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -5691,9 +5679,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
5691 const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5679 const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5692 const payload_ty = cg.typeOf(ty_op.operand);5680 const payload_ty = cg.typeOf(ty_op.operand);
56935681
5694 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {5682 assert(payload_ty.hasRuntimeBits(zcu));
5695 return try cg.constBool(true, .indirect);
5696 }
56975683
5698 const operand_id = try cg.resolve(ty_op.operand);5684 const operand_id = try cg.resolve(ty_op.operand);
56995685
...@@ -5789,8 +5775,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) !void {...@@ -5789,8 +5775,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) !void {
5789 const int_val: u64 = switch (cond_ty.zigTypeTag(zcu)) {5775 const int_val: u64 = switch (cond_ty.zigTypeTag(zcu)) {
5790 .bool, .int => if (cond_ty.isSignedInt(zcu)) @bitCast(value.toSignedInt(zcu)) else value.toUnsignedInt(zcu),5776 .bool, .int => if (cond_ty.isSignedInt(zcu)) @bitCast(value.toSignedInt(zcu)) else value.toUnsignedInt(zcu),
5791 .@"enum" => blk: {5777 .@"enum" => blk: {
5792 // TODO: figure out of cond_ty is correct (something with enum literals)5778 break :blk value.intFromEnum(zcu).toUnsignedInt(zcu); // TODO: composite integer constants
5793 break :blk (try value.intFromEnum(cond_ty, pt)).toUnsignedInt(zcu); // TODO: composite integer constants
5794 },5779 },
5795 .error_set => value.getErrorInt(zcu),5780 .error_set => value.getErrorInt(zcu),
5796 .pointer => value.toUnsignedInt(zcu),5781 .pointer => value.toUnsignedInt(zcu),
...@@ -6067,7 +6052,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie...@@ -6067,7 +6052,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
6067 // before starting to emit OpFunctionCall instructions. Hence the6052 // before starting to emit OpFunctionCall instructions. Hence the
6068 // temporary params buffer.6053 // temporary params buffer.
6069 const arg_ty = cg.typeOf(arg);6054 const arg_ty = cg.typeOf(arg);
6070 if (!arg_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;6055 if (!arg_ty.hasRuntimeBits(zcu)) continue;
6071 const arg_id = try cg.resolve(arg);6056 const arg_id = try cg.resolve(arg);
60726057
6073 params[n_params] = arg_id;6058 params[n_params] = arg_id;
...@@ -6081,7 +6066,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie...@@ -6081,7 +6066,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
6081 .id_ref_3 = params[0..n_params],6066 .id_ref_3 = params[0..n_params],
6082 });6067 });
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)) {
6085 return null;6070 return null;
6086 }6071 }
60876072
src/codegen/wasm/CodeGen.zig+77-142
...@@ -759,7 +759,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {...@@ -759,7 +759,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
759 const zcu = pt.zcu;759 const zcu = pt.zcu;
760 const val = (try cg.air.value(ref, pt)).?;760 const val = (try cg.air.value(ref, pt)).?;
761 const ty = cg.typeOf(ref);761 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)) {
763 gop.value_ptr.* = .none;763 gop.value_ptr.* = .none;
764 return .none;764 return .none;
765 }765 }
...@@ -773,7 +773,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {...@@ -773,7 +773,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
773 const result: WValue = if (isByRef(ty, zcu, cg.target))773 const result: WValue = if (isByRef(ty, zcu, cg.target))
774 .{ .uav_ref = .{ .ip_index = val.toIntern() } }774 .{ .uav_ref = .{ .ip_index = val.toIntern() } }
775 else775 else
776 try cg.lowerConstant(val, ty);776 try cg.lowerConstant(val);
777777
778 gop.value_ptr.* = result;778 gop.value_ptr.* = result;
779 return result;779 return result;
...@@ -786,7 +786,7 @@ fn resolveValue(cg: *CodeGen, val: Value) InnerError!WValue {...@@ -786,7 +786,7 @@ fn resolveValue(cg: *CodeGen, val: Value) InnerError!WValue {
786 return if (isByRef(ty, zcu, cg.target))786 return if (isByRef(ty, zcu, cg.target))
787 .{ .uav_ref = .{ .ip_index = val.toIntern() } }787 .{ .uav_ref = .{ .ip_index = val.toIntern() } }
788 else788 else
789 try cg.lowerConstant(val, ty);789 try cg.lowerConstant(val);
790}790}
791791
792/// NOTE: if result == .stack, it will be stored in .local792/// NOTE: if result == .stack, it will be stored in .local
...@@ -980,7 +980,6 @@ fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {...@@ -980,7 +980,6 @@ fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
980980
981/// For `std.builtin.CallingConvention.auto`.981/// For `std.builtin.CallingConvention.auto`.
982pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.wasm.Valtype {982pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.wasm.Valtype {
983 const ip = &zcu.intern_pool;
984 return switch (ty.zigTypeTag(zcu)) {983 return switch (ty.zigTypeTag(zcu)) {
985 .float => switch (ty.floatBits(target)) {984 .float => switch (ty.floatBits(target)) {
986 16 => .i32, // stored/loaded as u16985 16 => .i32, // stored/loaded as u16
...@@ -994,25 +993,13 @@ pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.w...@@ -994,25 +993,13 @@ pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.w
994 33...64 => .i64,993 33...64 => .i64,
995 else => .i32,994 else => .i32,
996 },995 },
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 },
1005 .vector => switch (CodeGen.determineSimdStoreStrategy(ty, zcu, target)) {996 .vector => switch (CodeGen.determineSimdStoreStrategy(ty, zcu, target)) {
1006 .direct => .v128,997 .direct => .v128,
1007 .unrolled => .i32,998 .unrolled => .i32,
1008 },999 },
1009 .@"union" => switch (ty.containerLayout(zcu)) {1000 .@"union", .@"struct" => switch (ty.containerLayout(zcu)) {
1010 .@"packed" => switch (ty.bitSize(zcu)) {1001 .@"packed" => typeToValtype(ty.bitpackBackingInt(zcu), zcu, target),
1011 0...32 => .i32,1002 .auto, .@"extern" => .i32,
1012 33...64 => .i64,
1013 else => .i32,
1014 },
1015 else => .i32,
1016 },1003 },
1017 else => .i32, // all represented as reference/immediate1004 else => .i32, // all represented as reference/immediate
1018 };1005 };
...@@ -1185,7 +1172,7 @@ pub fn generate(...@@ -1185,7 +1172,7 @@ pub fn generate(
1185 const fn_ty = zcu.navValue(cg.owner_nav).typeOf(zcu);1172 const fn_ty = zcu.navValue(cg.owner_nav).typeOf(zcu);
1186 const fn_info = zcu.typeToFunc(fn_ty).?;1173 const fn_info = zcu.typeToFunc(fn_ty).?;
1187 const ret_ty: Type = .fromInterned(fn_info.return_type);1174 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
1190 var cc_result = try resolveCallingConventionValues(zcu, fn_ty, target);1177 var cc_result = try resolveCallingConventionValues(zcu, fn_ty, target);
1191 defer cc_result.deinit(gpa);1178 defer cc_result.deinit(gpa);
...@@ -1244,7 +1231,7 @@ fn generateInner(cg: *CodeGen, any_returns: bool) InnerError!Mir {...@@ -1244,7 +1231,7 @@ fn generateInner(cg: *CodeGen, any_returns: bool) InnerError!Mir {
1244 if (any_returns and cg.air.instructions.len > 0) {1231 if (any_returns and cg.air.instructions.len > 0) {
1245 const inst: Air.Inst.Index = @enumFromInt(cg.air.instructions.len - 1);1232 const inst: Air.Inst.Index = @enumFromInt(cg.air.instructions.len - 1);
1246 const last_inst_ty = cg.typeOfIndex(inst);1233 const last_inst_ty = cg.typeOfIndex(inst);
1247 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {1234 if (!last_inst_ty.hasRuntimeBits(zcu)) {
1248 try cg.addTag(.@"unreachable");1235 try cg.addTag(.@"unreachable");
1249 }1236 }
1250 }1237 }
...@@ -1316,7 +1303,7 @@ fn resolveCallingConventionValues(...@@ -1316,7 +1303,7 @@ fn resolveCallingConventionValues(
1316 switch (cc) {1303 switch (cc) {
1317 .auto => {1304 .auto => {
1318 for (fn_info.param_types.get(ip)) |ty| {1305 for (fn_info.param_types.get(ip)) |ty| {
1319 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(zcu)) {1306 if (!Type.fromInterned(ty).hasRuntimeBits(zcu)) {
1320 continue;1307 continue;
1321 }1308 }
13221309
...@@ -1326,7 +1313,7 @@ fn resolveCallingConventionValues(...@@ -1326,7 +1313,7 @@ fn resolveCallingConventionValues(
1326 },1313 },
1327 .wasm_mvp => {1314 .wasm_mvp => {
1328 for (fn_info.param_types.get(ip)) |ty| {1315 for (fn_info.param_types.get(ip)) |ty| {
1329 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(zcu)) {1316 if (!Type.fromInterned(ty).hasRuntimeBits(zcu)) {
1330 continue;1317 continue;
1331 }1318 }
1332 switch (abi.classifyType(.fromInterned(ty), zcu)) {1319 switch (abi.classifyType(.fromInterned(ty), zcu)) {
...@@ -1357,7 +1344,7 @@ pub fn firstParamSRet(...@@ -1357,7 +1344,7 @@ pub fn firstParamSRet(
1357 zcu: *const Zcu,1344 zcu: *const Zcu,
1358 target: *const std.Target,1345 target: *const std.Target,
1359) bool {1346) bool {
1360 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) return false;1347 if (!return_type.hasRuntimeBits(zcu)) return false;
1361 switch (cc) {1348 switch (cc) {
1362 .@"inline" => unreachable,1349 .@"inline" => unreachable,
1363 .auto => return isByRef(return_type, zcu, target),1350 .auto => return isByRef(return_type, zcu, target),
...@@ -1457,7 +1444,7 @@ fn restoreStackPointer(cg: *CodeGen) !void {...@@ -1457,7 +1444,7 @@ fn restoreStackPointer(cg: *CodeGen) !void {
1457fn allocStack(cg: *CodeGen, ty: Type) !WValue {1444fn allocStack(cg: *CodeGen, ty: Type) !WValue {
1458 const pt = cg.pt;1445 const pt = cg.pt;
1459 const zcu = pt.zcu;1446 const zcu = pt.zcu;
1460 assert(ty.hasRuntimeBitsIgnoreComptime(zcu));1447 assert(ty.hasRuntimeBits(zcu));
1461 if (cg.initial_stack_value == .none) {1448 if (cg.initial_stack_value == .none) {
1462 try cg.initializeStack();1449 try cg.initializeStack();
1463 }1450 }
...@@ -1491,7 +1478,7 @@ fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue {...@@ -1491,7 +1478,7 @@ fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue {
1491 try cg.initializeStack();1478 try cg.initializeStack();
1492 }1479 }
14931480
1494 if (!pointee_ty.hasRuntimeBitsIgnoreComptime(zcu)) {1481 if (!pointee_ty.hasRuntimeBits(zcu)) {
1495 return cg.allocStack(Type.usize); // create a value containing just the stack pointer.1482 return cg.allocStack(Type.usize); // create a value containing just the stack pointer.
1496 }1483 }
14971484
...@@ -1676,7 +1663,6 @@ fn ptrSize(cg: *const CodeGen) u16 {...@@ -1676,7 +1663,6 @@ fn ptrSize(cg: *const CodeGen) u16 {
1676/// For a given `Type`, will return true when the type will be passed1663/// For a given `Type`, will return true when the type will be passed
1677/// by reference, rather than by value1664/// by reference, rather than by value
1678fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {1665fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
1679 const ip = &zcu.intern_pool;
1680 switch (ty.zigTypeTag(zcu)) {1666 switch (ty.zigTypeTag(zcu)) {
1681 .type,1667 .type,
1682 .comptime_int,1668 .comptime_int,
...@@ -1697,20 +1683,10 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {...@@ -1697,20 +1683,10 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
16971683
1698 .array,1684 .array,
1699 .frame,1685 .frame,
1700 => return ty.hasRuntimeBitsIgnoreComptime(zcu),1686 => return ty.hasRuntimeBits(zcu),
1701 .@"union" => {1687 .@"struct", .@"union" => switch (ty.containerLayout(zcu)) {
1702 if (zcu.typeToUnion(ty)) |union_obj| {1688 .@"packed" => return isByRef(ty.bitpackBackingInt(zcu), zcu, target),
1703 if (union_obj.flagsUnordered(ip).layout == .@"packed") {1689 .@"extern", .auto => return ty.hasRuntimeBits(zcu),
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);
1714 },1690 },
1715 .vector => return determineSimdStoreStrategy(ty, zcu, target) == .unrolled,1691 .vector => return determineSimdStoreStrategy(ty, zcu, target) == .unrolled,
1716 .int => return ty.intInfo(zcu).bits > 64,1692 .int => return ty.intInfo(zcu).bits > 64,
...@@ -1718,7 +1694,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {...@@ -1718,7 +1694,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
1718 .float => return ty.floatBits(target) > 64,1694 .float => return ty.floatBits(target) > 64,
1719 .error_union => {1695 .error_union => {
1720 const pl_ty = ty.errorUnionPayload(zcu);1696 const pl_ty = ty.errorUnionPayload(zcu);
1721 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {1697 if (!pl_ty.hasRuntimeBits(zcu)) {
1722 return false;1698 return false;
1723 }1699 }
1724 return true;1700 return true;
...@@ -1727,7 +1703,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {...@@ -1727,7 +1703,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
1727 if (ty.isPtrLikeOptional(zcu)) return false;1703 if (ty.isPtrLikeOptional(zcu)) return false;
1728 const pl_type = ty.optionalChild(zcu);1704 const pl_type = ty.optionalChild(zcu);
1729 if (pl_type.zigTypeTag(zcu) == .error_set) return false;1705 if (pl_type.zigTypeTag(zcu) == .error_set) return false;
1730 return pl_type.hasRuntimeBitsIgnoreComptime(zcu);1706 return pl_type.hasRuntimeBits(zcu);
1731 },1707 },
1732 .pointer => {1708 .pointer => {
1733 // Slices act like struct and will be passed by reference1709 // Slices act like struct and will be passed by reference
...@@ -2069,7 +2045,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2069,7 +2045,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2069 // to the stack instead2045 // to the stack instead
2070 if (cg.return_value != .none) {2046 if (cg.return_value != .none) {
2071 try cg.store(cg.return_value, operand, ret_ty, 0);2047 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)) {
2073 switch (abi.classifyType(ret_ty, zcu)) {2049 switch (abi.classifyType(ret_ty, zcu)) {
2074 .direct => |scalar_type| {2050 .direct => |scalar_type| {
2075 assert(!abi.lowerAsDoubleI64(scalar_type, zcu));2051 assert(!abi.lowerAsDoubleI64(scalar_type, zcu));
...@@ -2082,7 +2058,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2082,7 +2058,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2082 .indirect => unreachable,2058 .indirect => unreachable,
2083 }2059 }
2084 } else {2060 } else {
2085 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and ret_ty.isError(zcu)) {2061 if (!ret_ty.hasRuntimeBits(zcu) and ret_ty.isError(zcu)) {
2086 try cg.addImm32(0);2062 try cg.addImm32(0);
2087 } else {2063 } else {
2088 try cg.emitWValue(operand);2064 try cg.emitWValue(operand);
...@@ -2121,7 +2097,7 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2121,7 +2097,7 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2121 const ret_ty = cg.typeOf(un_op).childType(zcu);2097 const ret_ty = cg.typeOf(un_op).childType(zcu);
21222098
2123 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;2099 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;
2124 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {2100 if (!ret_ty.hasRuntimeBits(zcu)) {
2125 if (ret_ty.isError(zcu)) {2101 if (ret_ty.isError(zcu)) {
2126 try cg.addImm32(0);2102 try cg.addImm32(0);
2127 }2103 }
...@@ -2177,7 +2153,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie...@@ -2177,7 +2153,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
2177 const arg_val = try cg.resolveInst(arg);2153 const arg_val = try cg.resolveInst(arg);
21782154
2179 const arg_ty = cg.typeOf(arg);2155 const arg_ty = cg.typeOf(arg);
2180 if (!arg_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;2156 if (!arg_ty.hasRuntimeBits(zcu)) continue;
21812157
2182 try cg.lowerArg(zcu.typeToFunc(fn_ty).?.cc, arg_ty, arg_val);2158 try cg.lowerArg(zcu.typeToFunc(fn_ty).?.cc, arg_ty, arg_val);
2183 }2159 }
...@@ -2199,7 +2175,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie...@@ -2199,7 +2175,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
2199 }2175 }
22002176
2201 const result_value = result_value: {2177 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)) {
2203 break :result_value .none;2179 break :result_value .none;
2204 } else if (first_param_sret) {2180 } else if (first_param_sret) {
2205 break :result_value sret;2181 break :result_value sret;
...@@ -2320,12 +2296,12 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErr...@@ -2320,12 +2296,12 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErr
2320 const zcu = pt.zcu;2296 const zcu = pt.zcu;
2321 const abi_size = ty.abiSize(zcu);2297 const abi_size = ty.abiSize(zcu);
23222298
2323 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return;2299 if (!ty.hasRuntimeBits(zcu)) return;
23242300
2325 switch (ty.zigTypeTag(zcu)) {2301 switch (ty.zigTypeTag(zcu)) {
2326 .error_union => {2302 .error_union => {
2327 const pl_ty = ty.errorUnionPayload(zcu);2303 const pl_ty = ty.errorUnionPayload(zcu);
2328 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {2304 if (!pl_ty.hasRuntimeBits(zcu)) {
2329 return cg.store(lhs, rhs, Type.anyerror, offset);2305 return cg.store(lhs, rhs, Type.anyerror, offset);
2330 }2306 }
23312307
...@@ -2338,7 +2314,7 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErr...@@ -2338,7 +2314,7 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErr
2338 return cg.store(lhs, rhs, Type.usize, offset);2314 return cg.store(lhs, rhs, Type.usize, offset);
2339 }2315 }
2340 const pl_ty = ty.optionalChild(zcu);2316 const pl_ty = ty.optionalChild(zcu);
2341 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {2317 if (!pl_ty.hasRuntimeBits(zcu)) {
2342 return cg.store(lhs, rhs, Type.u8, offset);2318 return cg.store(lhs, rhs, Type.u8, offset);
2343 }2319 }
2344 if (pl_ty.zigTypeTag(zcu) == .error_set) {2320 if (pl_ty.zigTypeTag(zcu) == .error_set) {
...@@ -2438,7 +2414,7 @@ fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2438,7 +2414,7 @@ fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2438 const ptr_ty = cg.typeOf(ty_op.operand);2414 const ptr_ty = cg.typeOf(ty_op.operand);
2439 const ptr_info = ptr_ty.ptrInfo(zcu);2415 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
2443 const result = result: {2419 const result = result: {
2444 if (isByRef(ty, zcu, cg.target)) {2420 if (isByRef(ty, zcu, cg.target)) {
...@@ -3089,7 +3065,7 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro...@@ -3089,7 +3065,7 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro
3089 return switch (ptr.base_addr) {3065 return switch (ptr.base_addr) {
3090 .nav => |nav| return .{ .nav_ref = .{ .nav_index = nav, .offset = @intCast(offset) } },3066 .nav => |nav| return .{ .nav_ref = .{ .nav_index = nav, .offset = @intCast(offset) } },
3091 .uav => |uav| return .{ .uav_ref = .{ .ip_index = uav.val, .offset = @intCast(offset), .orig_ptr_ty = uav.orig_ty } },3067 .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)),
3093 .eu_payload => |eu_ptr| try cg.lowerPtr(3069 .eu_payload => |eu_ptr| try cg.lowerPtr(
3094 eu_ptr,3070 eu_ptr,
3095 offset + codegen.errUnionPayloadOffset(3071 offset + codegen.errUnionPayloadOffset(
...@@ -3126,10 +3102,11 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro...@@ -3126,10 +3102,11 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro
3126 };3102 };
3127}3103}
31283104
3129/// Asserts that `isByRef` returns `false` for `ty`.3105/// Asserts that `isByRef` returns `false` for `val.typeOf(zcu)`.
3130fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {3106fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue {
3131 const pt = cg.pt;3107 const pt = cg.pt;
3132 const zcu = pt.zcu;3108 const zcu = pt.zcu;
3109 const ty = val.typeOf(zcu);
3133 assert(!isByRef(ty, zcu, cg.target));3110 assert(!isByRef(ty, zcu, cg.target));
3134 const ip = &zcu.intern_pool;3111 const ip = &zcu.intern_pool;
3135 if (val.isUndef(zcu)) return cg.emitUndefined(ty);3112 if (val.isUndef(zcu)) return cg.emitUndefined(ty);
...@@ -3191,31 +3168,22 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3191,31 +3168,22 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3191 },3168 },
3192 .error_union => |error_union| {3169 .error_union => |error_union| {
3193 const err_int_ty = try pt.errorIntType();3170 const err_int_ty = try pt.errorIntType();
3194 const err_ty, const err_val = switch (error_union.val) {3171 const err_val: Value = switch (error_union.val) {
3195 .err_name => |err_name| .{3172 .err_name => |err_name| .fromInterned(try pt.intern(.{ .err = .{
3196 ty.errorUnionSet(zcu),3173 .ty = ty.errorUnionSet(zcu).toIntern(),
3197 Value.fromInterned(try pt.intern(.{ .err = .{3174 .name = err_name,
3198 .ty = ty.errorUnionSet(zcu).toIntern(),3175 } })),
3199 .name = err_name,3176 .payload => try pt.intValue(err_int_ty, 0),
3200 } })),
3201 },
3202 .payload => .{
3203 err_int_ty,
3204 try pt.intValue(err_int_ty, 0),
3205 },
3206 };3177 };
3207 const payload_type = ty.errorUnionPayload(zcu);3178 const payload_type = ty.errorUnionPayload(zcu);
3208 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {3179 if (!payload_type.hasRuntimeBits(zcu)) {
3209 // We use the error type directly as the type.3180 // We use the error type directly as the type.
3210 return cg.lowerConstant(err_val, err_ty);3181 return cg.lowerConstant(err_val);
3211 }3182 }
32123183
3213 return cg.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});3184 return cg.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});
3214 },3185 },
3215 .enum_tag => |enum_tag| {3186 .enum_tag => |enum_tag| return cg.lowerConstant(.fromInterned(enum_tag.int)),
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 },
3219 .float => |float| switch (float.storage) {3187 .float => |float| switch (float.storage) {
3220 .f16 => |f16_val| return .{ .imm32 = @as(u16, @bitCast(f16_val)) },3188 .f16 => |f16_val| return .{ .imm32 = @as(u16, @bitCast(f16_val)) },
3221 .f32 => |f32_val| return .{ .float32 = f32_val },3189 .f32 => |f32_val| return .{ .float32 = f32_val },
...@@ -3225,9 +3193,8 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3225,9 +3193,8 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3225 .slice => unreachable, // isByRef == true3193 .slice => unreachable, // isByRef == true
3226 .ptr => return cg.lowerPtr(val.toIntern(), 0),3194 .ptr => return cg.lowerPtr(val.toIntern(), 0),
3227 .opt => if (ty.optionalReprIsPayload(zcu)) {3195 .opt => if (ty.optionalReprIsPayload(zcu)) {
3228 const pl_ty = ty.optionalChild(zcu);
3229 if (val.optionalValue(zcu)) |payload| {3196 if (val.optionalValue(zcu)) |payload| {
3230 return cg.lowerConstant(payload, pl_ty);3197 return cg.lowerConstant(payload);
3231 } else {3198 } else {
3232 return .{ .imm32 = 0 };3199 return .{ .imm32 = 0 };
3233 }3200 }
...@@ -3242,33 +3209,11 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3242,33 +3209,11 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3242 val.writeToMemory(pt, &buf) catch unreachable;3209 val.writeToMemory(pt, &buf) catch unreachable;
3243 return cg.storeSimdImmd(buf);3210 return cg.storeSimdImmd(buf);
3244 },3211 },
3245 .struct_type => {3212 .struct_type => unreachable, // packed structs use `bitpack`
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 },
3259 else => unreachable,3213 else => unreachable,
3260 },3214 },
3261 .un => {3215 .un => unreachable, // packed unions use `bitpack`
3262 const int_type = try pt.intType(.unsigned, @intCast(ty.bitSize(zcu)));3216 .bitpack => |bitpack| return cg.lowerConstant(.fromInterned(bitpack.backing_int_val)),
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 },
3272 .memoized_call => unreachable,3217 .memoized_call => unreachable,
3273 }3218 }
3274}3219}
...@@ -3283,7 +3228,6 @@ fn storeSimdImmd(cg: *CodeGen, value: [16]u8) !WValue {...@@ -3283,7 +3228,6 @@ fn storeSimdImmd(cg: *CodeGen, value: [16]u8) !WValue {
32833228
3284fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {3229fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {
3285 const zcu = cg.pt.zcu;3230 const zcu = cg.pt.zcu;
3286 const ip = &zcu.intern_pool;
3287 switch (ty.zigTypeTag(zcu)) {3231 switch (ty.zigTypeTag(zcu)) {
3288 .bool, .error_set => return .{ .imm32 = 0xaaaaaaaa },3232 .bool, .error_set => return .{ .imm32 = 0xaaaaaaaa },
3289 .int, .@"enum" => switch (ty.intInfo(zcu).bits) {3233 .int, .@"enum" => switch (ty.intInfo(zcu).bits) {
...@@ -3311,17 +3255,9 @@ fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {...@@ -3311,17 +3255,9 @@ fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {
3311 .error_union => {3255 .error_union => {
3312 return .{ .imm32 = 0xaaaaaaaa };3256 return .{ .imm32 = 0xaaaaaaaa };
3313 },3257 },
3314 .@"struct" => {3258 .@"struct", .@"union" => {
3315 const packed_struct = zcu.typeToPackedStruct(ty).?;3259 const backing_int_ty = ty.bitpackBackingInt(zcu);
3316 return cg.emitUndefined(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)));3260 return cg.emitUndefined(backing_int_ty);
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,
3325 },3261 },
3326 else => return cg.fail("Wasm TODO: emitUndefined for type: {t}\n", .{ty.zigTypeTag(zcu)}),3262 else => return cg.fail("Wasm TODO: emitUndefined for type: {t}\n", .{ty.zigTypeTag(zcu)}),
3327 }3263 }
...@@ -3335,7 +3271,7 @@ fn airBlock(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3335,7 +3271,7 @@ fn airBlock(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3335fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, block_ty: Type, body: []const Air.Inst.Index) InnerError!void {3271fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, block_ty: Type, body: []const Air.Inst.Index) InnerError!void {
3336 const zcu = cg.pt.zcu;3272 const zcu = cg.pt.zcu;
3337 // if wasm_block_ty is non-empty, we create a register to store the temporary value3273 // 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))
3339 try cg.allocLocal(block_ty)3275 try cg.allocLocal(block_ty)
3340 else3276 else
3341 .none;3277 .none;
...@@ -3449,7 +3385,7 @@ fn cmp(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOpe...@@ -3449,7 +3385,7 @@ fn cmp(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOpe
3449 const zcu = cg.pt.zcu;3385 const zcu = cg.pt.zcu;
3450 if (ty.zigTypeTag(zcu) == .optional and !ty.optionalReprIsPayload(zcu)) {3386 if (ty.zigTypeTag(zcu) == .optional and !ty.optionalReprIsPayload(zcu)) {
3451 const payload_ty = ty.optionalChild(zcu);3387 const payload_ty = ty.optionalChild(zcu);
3452 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3388 if (payload_ty.hasRuntimeBits(zcu)) {
3453 // When we hit this case, we must check the value of optionals3389 // When we hit this case, we must check the value of optionals
3454 // that are not pointers. This means first checking against non-null for3390 // that are not pointers. This means first checking against non-null for
3455 // both lhs and rhs, as well as checking the payload are matching of lhs and rhs3391 // both lhs and rhs, as well as checking the payload are matching of lhs and rhs
...@@ -3792,7 +3728,6 @@ fn structFieldPtr(...@@ -3792,7 +3728,6 @@ fn structFieldPtr(
3792fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {3728fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3793 const pt = cg.pt;3729 const pt = cg.pt;
3794 const zcu = pt.zcu;3730 const zcu = pt.zcu;
3795 const ip = &zcu.intern_pool;
3796 const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3731 const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3797 const struct_field = cg.air.extraData(Air.StructField, ty_pl.payload).data;3732 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 {...@@ -3800,14 +3735,14 @@ fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3800 const operand = try cg.resolveInst(struct_field.struct_operand);3735 const operand = try cg.resolveInst(struct_field.struct_operand);
3801 const field_index = struct_field.field_index;3736 const field_index = struct_field.field_index;
3802 const field_ty = struct_ty.fieldType(field_index, zcu);3737 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
3805 const result: WValue = switch (struct_ty.containerLayout(zcu)) {3740 const result: WValue = switch (struct_ty.containerLayout(zcu)) {
3806 .@"packed" => switch (struct_ty.zigTypeTag(zcu)) {3741 .@"packed" => switch (struct_ty.zigTypeTag(zcu)) {
3807 .@"struct" => result: {3742 .@"struct" => result: {
3808 const packed_struct = zcu.typeToPackedStruct(struct_ty).?;3743 const packed_struct = zcu.typeToPackedStruct(struct_ty).?;
3809 const offset = zcu.structPackedFieldBitOffset(packed_struct, field_index);3744 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);
3811 const host_bits = backing_ty.intInfo(zcu).bits;3746 const host_bits = backing_ty.intInfo(zcu).bits;
38123747
3813 const const_wvalue: WValue = if (33 <= host_bits and host_bits <= 64)3748 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...@@ -3885,7 +3820,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index, is_dispatch_loop: bool) Inner
3885 const switch_br = cg.air.unwrapSwitch(inst);3820 const switch_br = cg.air.unwrapSwitch(inst);
3886 const target_ty = cg.typeOf(switch_br.operand);3821 const target_ty = cg.typeOf(switch_br.operand);
38873822
3888 assert(target_ty.hasRuntimeBitsIgnoreComptime(zcu));3823 assert(target_ty.hasRuntimeBits(zcu));
38893824
3890 // swap target value with placeholder local, for dispatching3825 // swap target value with placeholder local, for dispatching
3891 const target = if (is_dispatch_loop) target: {3826 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...@@ -4119,7 +4054,7 @@ fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kind
4119 }4054 }
41204055
4121 try cg.emitWValue(operand);4056 try cg.emitWValue(operand);
4122 if (op_kind == .ptr or pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4057 if (op_kind == .ptr or pl_ty.hasRuntimeBits(zcu)) {
4123 try cg.addMemArg(.i32_load16_u, .{4058 try cg.addMemArg(.i32_load16_u, .{
4124 .offset = operand.offset() + @as(u32, @intCast(errUnionErrorOffset(pl_ty, zcu))),4059 .offset = operand.offset() + @as(u32, @intCast(errUnionErrorOffset(pl_ty, zcu))),
4125 .alignment = @intCast(Type.anyerror.abiAlignment(zcu).toByteUnits().?),4060 .alignment = @intCast(Type.anyerror.abiAlignment(zcu).toByteUnits().?),
...@@ -4146,7 +4081,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)...@@ -4146,7 +4081,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
4146 const payload_ty = eu_ty.errorUnionPayload(zcu);4081 const payload_ty = eu_ty.errorUnionPayload(zcu);
41474082
4148 const result: WValue = result: {4083 const result: WValue = result: {
4149 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4084 if (!payload_ty.hasRuntimeBits(zcu)) {
4150 if (op_is_ptr) {4085 if (op_is_ptr) {
4151 break :result cg.reuseOperand(ty_op.operand, operand);4086 break :result cg.reuseOperand(ty_op.operand, operand);
4152 } else {4087 } else {
...@@ -4166,7 +4101,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)...@@ -4166,7 +4101,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
4166}4101}
41674102
4168/// E!T -> E op_is_ptr == false4103/// E!T -> E op_is_ptr == false
4169/// *(E!T) -> E op_is_prt == true4104/// *(E!T) -> E op_is_ptr == true
4170/// NOTE: op_is_ptr will not change return type4105/// NOTE: op_is_ptr will not change return type
4171fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {4106fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
4172 const zcu = cg.pt.zcu;4107 const zcu = cg.pt.zcu;
...@@ -4186,7 +4121,7 @@ fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) I...@@ -4186,7 +4121,7 @@ fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) I
4186 if (op_is_ptr or isByRef(eu_ty, zcu, cg.target)) {4121 if (op_is_ptr or isByRef(eu_ty, zcu, cg.target)) {
4187 break :result try cg.load(operand, Type.anyerror, err_offset);4122 break :result try cg.load(operand, Type.anyerror, err_offset);
4188 } else {4123 } else {
4189 assert(!payload_ty.hasRuntimeBitsIgnoreComptime(zcu));4124 assert(!payload_ty.hasRuntimeBits(zcu));
4190 break :result cg.reuseOperand(ty_op.operand, operand);4125 break :result cg.reuseOperand(ty_op.operand, operand);
4191 }4126 }
4192 };4127 };
...@@ -4202,7 +4137,7 @@ fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4202,7 +4137,7 @@ fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42024137
4203 const pl_ty = cg.typeOf(ty_op.operand);4138 const pl_ty = cg.typeOf(ty_op.operand);
4204 const result = result: {4139 const result = result: {
4205 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4140 if (!pl_ty.hasRuntimeBits(zcu)) {
4206 break :result cg.reuseOperand(ty_op.operand, operand);4141 break :result cg.reuseOperand(ty_op.operand, operand);
4207 }4142 }
42084143
...@@ -4232,7 +4167,7 @@ fn airWrapErrUnionErr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4232,7 +4167,7 @@ fn airWrapErrUnionErr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4232 const pl_ty = err_ty.errorUnionPayload(zcu);4167 const pl_ty = err_ty.errorUnionPayload(zcu);
42334168
4234 const result = result: {4169 const result = result: {
4235 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4170 if (!pl_ty.hasRuntimeBits(zcu)) {
4236 break :result cg.reuseOperand(ty_op.operand, operand);4171 break :result cg.reuseOperand(ty_op.operand, operand);
4237 }4172 }
42384173
...@@ -4348,7 +4283,7 @@ fn isNull(cg: *CodeGen, operand: WValue, optional_ty: Type, opcode: std.wasm.Opc...@@ -4348,7 +4283,7 @@ fn isNull(cg: *CodeGen, operand: WValue, optional_ty: Type, opcode: std.wasm.Opc
4348 if (!optional_ty.optionalReprIsPayload(zcu)) {4283 if (!optional_ty.optionalReprIsPayload(zcu)) {
4349 // When payload is zero-bits, we can treat operand as a value, rather than4284 // When payload is zero-bits, we can treat operand as a value, rather than
4350 // a pointer to the stack value4285 // a pointer to the stack value
4351 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4286 if (payload_ty.hasRuntimeBits(zcu)) {
4352 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {4287 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
4353 return cg.fail("Optional type {f} too big to fit into stack frame", .{optional_ty.fmt(pt)});4288 return cg.fail("Optional type {f} too big to fit into stack frame", .{optional_ty.fmt(pt)});
4354 };4289 };
...@@ -4373,7 +4308,7 @@ fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4373,7 +4308,7 @@ fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4373 const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4308 const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4374 const opt_ty = cg.typeOf(ty_op.operand);4309 const opt_ty = cg.typeOf(ty_op.operand);
4375 const payload_ty = cg.typeOfIndex(inst);4310 const payload_ty = cg.typeOfIndex(inst);
4376 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4311 if (!payload_ty.hasRuntimeBits(zcu)) {
4377 return cg.finishAir(inst, .none, &.{ty_op.operand});4312 return cg.finishAir(inst, .none, &.{ty_op.operand});
4378 }4313 }
43794314
...@@ -4398,7 +4333,7 @@ fn airOptionalPayloadPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4398,7 +4333,7 @@ fn airOptionalPayloadPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43984333
4399 const result = result: {4334 const result = result: {
4400 const payload_ty = opt_ty.optionalChild(zcu);4335 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)) {
4402 break :result cg.reuseOperand(ty_op.operand, operand);4337 break :result cg.reuseOperand(ty_op.operand, operand);
4403 }4338 }
44044339
...@@ -4438,7 +4373,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4438,7 +4373,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4438 const zcu = pt.zcu;4373 const zcu = pt.zcu;
44394374
4440 const result = result: {4375 const result = result: {
4441 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4376 if (!payload_ty.hasRuntimeBits(zcu)) {
4442 const non_null_bit = try cg.allocStack(Type.u1);4377 const non_null_bit = try cg.allocStack(Type.u1);
4443 try cg.emitWValue(non_null_bit);4378 try cg.emitWValue(non_null_bit);
4444 try cg.addImm32(1);4379 try cg.addImm32(1);
...@@ -4606,7 +4541,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4606,7 +4541,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4606 const slice_local = try cg.allocStack(slice_ty);4541 const slice_local = try cg.allocStack(slice_ty);
46074542
4608 // store the array ptr in the slice4543 // store the array ptr in the slice
4609 if (array_ty.hasRuntimeBitsIgnoreComptime(zcu)) {4544 if (array_ty.hasRuntimeBits(zcu)) {
4610 try cg.store(slice_local, operand, Type.usize, 0);4545 try cg.store(slice_local, operand, Type.usize, 0);
4611 }4546 }
46124547
...@@ -5105,7 +5040,7 @@ fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5105,7 +5040,7 @@ fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5105 try cg.emitWValue(dest_alloc);5040 try cg.emitWValue(dest_alloc);
5106 const elem_val = switch (mask_elem.unwrap()) {5041 const elem_val = switch (mask_elem.unwrap()) {
5107 .elem => |idx| try cg.load(operand, elem_ty, @intCast(elem_size * idx)),5042 .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)),
5109 };5044 };
5110 try cg.store(.stack, elem_val, elem_ty, @intCast(dest_alloc.offset() + elem_size * out_idx));5045 try cg.store(.stack, elem_val, elem_ty, @intCast(dest_alloc.offset() + elem_size * out_idx));
5111 }5046 }
...@@ -5246,7 +5181,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5246,7 +5181,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5246 }5181 }
5247 const packed_struct = zcu.typeToPackedStruct(result_ty).?;5182 const packed_struct = zcu.typeToPackedStruct(result_ty).?;
5248 const field_types = packed_struct.field_types;5183 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
5251 // ensure the result is zero'd5186 // ensure the result is zero'd
5252 const result = try cg.allocLocal(backing_type);5187 const result = try cg.allocLocal(backing_type);
...@@ -5259,7 +5194,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5259,7 +5194,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5259 var current_bit: u16 = 0;5194 var current_bit: u16 = 0;
5260 for (elements, 0..) |elem, elem_index| {5195 for (elements, 0..) |elem, elem_index| {
5261 const field_ty = Type.fromInterned(field_types.get(ip)[elem_index]);5196 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
5264 const shift_val: WValue = if (backing_type.bitSize(zcu) <= 32)5199 const shift_val: WValue = if (backing_type.bitSize(zcu) <= 32)
5265 .{ .imm32 = current_bit }5200 .{ .imm32 = current_bit }
...@@ -5332,13 +5267,13 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5332,13 +5267,13 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5332 const layout = union_ty.unionGetLayout(zcu);5267 const layout = union_ty.unionGetLayout(zcu);
5333 const union_obj = zcu.typeToUnion(union_ty).?;5268 const union_obj = zcu.typeToUnion(union_ty).?;
5334 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);5269 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
5337 const tag_int = blk: {5272 const tag_int = blk: {
5338 const tag_ty = union_ty.unionTagTypeRuntime(zcu).?;5273 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
5339 const enum_field_index = tag_ty.enumFieldIndex(field_name, zcu).?;5274 const enum_field_index = tag_ty.enumFieldIndex(field_name, zcu).?;
5340 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);5275 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);
5342 };5277 };
5343 if (layout.payload_size == 0) {5278 if (layout.payload_size == 0) {
5344 if (layout.tag_size == 0) {5279 if (layout.tag_size == 0) {
...@@ -5360,7 +5295,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5360,7 +5295,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5360 }5295 }
53615296
5362 if (layout.tag_size > 0) {5297 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);
5364 }5299 }
5365 } else {5300 } else {
5366 try cg.store(result_ptr, payload, field_ty, 0);5301 try cg.store(result_ptr, payload, field_ty, 0);
...@@ -5368,7 +5303,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5368,7 +5303,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5368 try cg.store(5303 try cg.store(
5369 result_ptr,5304 result_ptr,
5370 tag_int,5305 tag_int,
5371 Type.fromInterned(union_obj.enum_tag_ty),5306 .fromInterned(union_obj.enum_tag_type),
5372 @intCast(layout.payload_size),5307 @intCast(layout.payload_size),
5373 );5308 );
5374 }5309 }
...@@ -5415,7 +5350,7 @@ fn airWasmMemoryGrow(cg: *CodeGen, inst: Air.Inst.Index) !void {...@@ -5415,7 +5350,7 @@ fn airWasmMemoryGrow(cg: *CodeGen, inst: Air.Inst.Index) !void {
54155350
5416fn cmpOptionals(cg: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {5351fn cmpOptionals(cg: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {
5417 const zcu = cg.pt.zcu;5352 const zcu = cg.pt.zcu;
5418 assert(operand_ty.hasRuntimeBitsIgnoreComptime(zcu));5353 assert(operand_ty.hasRuntimeBits(zcu));
5419 assert(op == .eq or op == .neq);5354 assert(op == .eq or op == .neq);
5420 const payload_ty = operand_ty.optionalChild(zcu);5355 const payload_ty = operand_ty.optionalChild(zcu);
5421 assert(!isByRef(payload_ty, zcu, cg.target));5356 assert(!isByRef(payload_ty, zcu, cg.target));
...@@ -5669,7 +5604,7 @@ fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void...@@ -5669,7 +5604,7 @@ fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void
5669 );5604 );
56705605
5671 const result = result: {5606 const result = result: {
5672 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {5607 if (!payload_ty.hasRuntimeBits(zcu)) {
5673 break :result cg.reuseOperand(ty_op.operand, operand);5608 break :result cg.reuseOperand(ty_op.operand, operand);
5674 }5609 }
56755610
...@@ -6458,7 +6393,7 @@ fn lowerTry(...@@ -6458,7 +6393,7 @@ fn lowerTry(
6458 const zcu = cg.pt.zcu;6393 const zcu = cg.pt.zcu;
64596394
6460 const pl_ty = err_union_ty.errorUnionPayload(zcu);6395 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
6463 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {6398 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
6464 // Block we can jump out of when error is not set6399 // Block we can jump out of when error is not set
...@@ -7096,13 +7031,13 @@ fn callIntrinsic(...@@ -7096,13 +7031,13 @@ fn callIntrinsic(
7096 // Lower all arguments to the stack before we call our function7031 // Lower all arguments to the stack before we call our function
7097 for (args, 0..) |arg, arg_i| {7032 for (args, 0..) |arg, arg_i| {
7098 assert(!(want_sret_param and arg == .stack));7033 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));
7100 try cg.lowerArg(.{ .wasm_mvp = .{} }, Type.fromInterned(param_types[arg_i]), arg);7035 try cg.lowerArg(.{ .wasm_mvp = .{} }, Type.fromInterned(param_types[arg_i]), arg);
7101 }7036 }
71027037
7103 try cg.addInst(.{ .tag = .call_intrinsic, .data = .{ .intrinsic = intrinsic } });7038 try cg.addInst(.{ .tag = .call_intrinsic, .data = .{ .intrinsic = intrinsic } });
71047039
7105 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {7040 if (!return_type.hasRuntimeBits(zcu)) {
7106 return .none;7041 return .none;
7107 } else if (want_sret_param) {7042 } else if (want_sret_param) {
7108 return sret;7043 return sret;
src/link/MachO/Atom.zig+1-1
...@@ -561,7 +561,7 @@ fn reportUndefSymbol(self: Atom, rel: Relocation, macho_file: *MachO) !bool {...@@ -561,7 +561,7 @@ fn reportUndefSymbol(self: Atom, rel: Relocation, macho_file: *MachO) !bool {
561 defer macho_file.undefs_mutex.unlock(io);561 defer macho_file.undefs_mutex.unlock(io);
562 const gop = try macho_file.undefs.getOrPut(gpa, file.getGlobals()[rel.target]);562 const gop = try macho_file.undefs.getOrPut(gpa, file.getGlobals()[rel.target]);
563 if (!gop.found_existing) {563 if (!gop.found_existing) {
564 gop.value_ptr.* = .{ .refs = .{} };564 gop.value_ptr.* = .{ .refs = .empty };
565 }565 }
566 try gop.value_ptr.refs.append(gpa, .{ .index = self.atom_index, .file = self.file });566 try gop.value_ptr.refs.append(gpa, .{ .index = self.atom_index, .file = self.file });
567 return true;567 return true;
src/link/MachO/ZigObject.zig+1-1
...@@ -150,7 +150,7 @@ fn newAtom(self: *ZigObject, allocator: Allocator, name: MachO.String, macho_fil...@@ -150,7 +150,7 @@ fn newAtom(self: *ZigObject, allocator: Allocator, name: MachO.String, macho_fil
150 atom.name = name;150 atom.name = name;
151151
152 const relocs_index = @as(u32, @intCast(self.relocs.items.len));152 const relocs_index = @as(u32, @intCast(self.relocs.items.len));
153 self.relocs.addOneAssumeCapacity().* = .{};153 self.relocs.addOneAssumeCapacity().* = .empty;
154 atom.addExtra(.{ .rel_index = relocs_index, .rel_count = 0 }, macho_file);154 atom.addExtra(.{ .rel_index = relocs_index, .rel_count = 0 }, macho_file);
155155
156 return index;156 return index;
src/link/MachO/file.zig+1-1
...@@ -258,7 +258,7 @@ pub const File = union(enum) {...@@ -258,7 +258,7 @@ pub const File = union(enum) {
258258
259 const gop = try macho_file.dupes.getOrPut(gpa, file.getGlobals()[i]);259 const gop = try macho_file.dupes.getOrPut(gpa, file.getGlobals()[i]);
260 if (!gop.found_existing) {260 if (!gop.found_existing) {
261 gop.value_ptr.* = .{};261 gop.value_ptr.* = .empty;
262 }262 }
263 try gop.value_ptr.append(gpa, file.getIndex());263 try gop.value_ptr.append(gpa, file.getIndex());
264 }264 }
src/link/Wasm.zig+2-2
...@@ -4226,7 +4226,7 @@ fn convertZcuFnType(...@@ -4226,7 +4226,7 @@ fn convertZcuFnType(
42264226
4227 if (CodeGen.firstParamSRet(cc, return_type, zcu, target)) {4227 if (CodeGen.firstParamSRet(cc, return_type, zcu, target)) {
4228 try params_buffer.append(gpa, .i32); // memory address is always a 32-bit handle4228 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)) {
4230 if (cc == .wasm_mvp) {4230 if (cc == .wasm_mvp) {
4231 switch (abi.classifyType(return_type, zcu)) {4231 switch (abi.classifyType(return_type, zcu)) {
4232 .direct => |scalar_ty| {4232 .direct => |scalar_ty| {
...@@ -4245,7 +4245,7 @@ fn convertZcuFnType(...@@ -4245,7 +4245,7 @@ fn convertZcuFnType(
4245 // param types4245 // param types
4246 for (params) |param_type_ip| {4246 for (params) |param_type_ip| {
4247 const param_type = Zcu.Type.fromInterned(param_type_ip);4247 const param_type = Zcu.Type.fromInterned(param_type_ip);
4248 if (!param_type.hasRuntimeBitsIgnoreComptime(zcu)) continue;4248 if (!param_type.hasRuntimeBits(zcu)) continue;
42494249
4250 switch (cc) {4250 switch (cc) {
4251 .wasm_mvp => {4251 .wasm_mvp => {
src/link/Wasm/Flush.zig+3-3
...@@ -154,7 +154,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {...@@ -154,7 +154,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
154 .type_index = try wasm.internFunctionType(.auto, &.{int_tag_ty.ip_index}, .slice_const_u8_sentinel_0, target),154 .type_index = try wasm.internFunctionType(.auto, &.{int_tag_ty.ip_index}, .slice_const_u8_sentinel_0, target),
155 .table_index = @intCast(wasm.tag_name_offs.items.len),155 .table_index = @intCast(wasm.tag_name_offs.items.len),
156 } };156 } };
157 const tag_names = ip.loadEnumType(data.ip_index).names;157 const tag_names = ip.loadEnumType(data.ip_index).field_names;
158 for (tag_names.get(ip)) |tag_name| {158 for (tag_names.get(ip)) |tag_name| {
159 const slice = tag_name.toSlice(ip);159 const slice = tag_name.toSlice(ip);
160 try wasm.tag_name_offs.append(gpa, @intCast(wasm.tag_name_bytes.items.len));160 try wasm.tag_name_offs.append(gpa, @intCast(wasm.tag_name_bytes.items.len));
...@@ -1869,7 +1869,7 @@ fn emitTagNameFunction(...@@ -1869,7 +1869,7 @@ fn emitTagNameFunction(
1869 const zcu = comp.zcu.?;1869 const zcu = comp.zcu.?;
1870 const ip = &zcu.intern_pool;1870 const ip = &zcu.intern_pool;
1871 const enum_type = ip.loadEnumType(enum_type_ip);1871 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
1874 const slice_abi_size = 8;1874 const slice_abi_size = 8;
1875 const encoded_alignment = @ctz(@as(u32, 4));1875 const encoded_alignment = @ctz(@as(u32, 4));
...@@ -1908,7 +1908,7 @@ fn emitTagNameFunction(...@@ -1908,7 +1908,7 @@ fn emitTagNameFunction(
1908 return;1908 return;
1909 }1909 }
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);
1912 const outer_block_type: std.wasm.BlockType = switch (int_info.bits) {1912 const outer_block_type: std.wasm.BlockType = switch (int_info.bits) {
1913 0...32 => .i32,1913 0...32 => .i32,
1914 33...64 => .i64,1914 33...64 => .i64,
src/link/tapi/parse.zig+1-1
...@@ -530,7 +530,7 @@ const Parser = struct {...@@ -530,7 +530,7 @@ const Parser = struct {
530 fn leaf_value(self: *Parser) ParseError!*Node {530 fn leaf_value(self: *Parser) ParseError!*Node {
531 const node = try self.allocator.create(Node.Value);531 const node = try self.allocator.create(Node.Value);
532 errdefer self.allocator.destroy(node);532 errdefer self.allocator.destroy(node);
533 node.* = .{ .string_value = .{} };533 node.* = .{ .string_value = .empty };
534 node.base.tree = self.tree;534 node.base.tree = self.tree;
535 node.base.start = self.token_it.pos;535 node.base.start = self.token_it.pos;
536 errdefer node.string_value.deinit(self.allocator);536 errdefer node.string_value.deinit(self.allocator);