authorgravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2026-10-20 03:52:17+02:00
committergravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2026-10-20 23:10:13+02:00
log72f3d3aeea07c5b16fb97c789b898f18e05eda9e
treee1aa8b61c795c87c7565fdf6dd2fca449648d1ea
parent151597cc0dcfcad384218a2b92cae4b23b11ebe6

wasm: no pt in CodeGen


1 files changed, 123 insertions(+), 131 deletions(-)

src/codegen/wasm/CodeGen.zig+123-131
......@@ -157,7 +157,7 @@ simd_immediates: std.ArrayList([16]u8) = .empty,
157157/// The Target we're emitting (used to call intInfo)
158158target: *const std.Target,
159159ptr_size: enum { wasm32, wasm64 },
160pt: Zcu.PerThread,
160zcu: *Zcu,
161161/// List of MIR Instructions
162162mir_instructions: std.MultiArrayList(Mir.Inst),
163163/// Contains extra data for MIR
......@@ -380,7 +380,7 @@ pub fn deinit(cg: *CodeGen) void {
380380}
381381
382382pub fn fail(cg: *CodeGen, comptime fmt: []const u8, args: anytype) Error {
383 const zcu = cg.pt.zcu;
383 const zcu = cg.zcu;
384384 const func = zcu.funcInfo(cg.func_index);
385385 return zcu.codegenFail(func.owner_nav, fmt, args);
386386}
......@@ -395,8 +395,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
395395 const gop = try cg.values.getOrPut(cg.gpa, ref);
396396 assert(!gop.found_existing);
397397
398 const pt = cg.pt;
399 const zcu = pt.zcu;
398 const zcu = cg.zcu;
400399 const val: Value = .fromInterned(ref.toInterned().?);
401400 const ty = cg.typeOf(ref);
402401 if (!ty.hasRuntimeBits(zcu) and !ty.isInt(zcu) and !ty.isError(zcu)) {
......@@ -420,7 +419,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
420419}
421420
422421fn resolveValue(cg: *CodeGen, val: Value) InnerError!WValue {
423 const zcu = cg.pt.zcu;
422 const zcu = cg.zcu;
424423 const ty = val.typeOf(zcu);
425424
426425 return if (isByRef(ty, zcu, cg.target))
......@@ -761,7 +760,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void {
761760 .float32 => |val| try cg.addFloat32(val),
762761 .float64 => |val| try cg.addFloat64(val),
763762 .nav_ref => |nav_ref| {
764 const zcu = cg.pt.zcu;
763 const zcu = cg.zcu;
765764 const ip = &zcu.intern_pool;
766765 if (ip.zigTypeTag(ip.getNav(nav_ref.nav_index).resolved.?.type) == .@"fn") {
767766 assert(nav_ref.offset == 0);
......@@ -782,7 +781,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void {
782781 }
783782 },
784783 .uav_ref => |uav| {
785 const zcu = cg.pt.zcu;
784 const zcu = cg.zcu;
786785 const ip = &zcu.intern_pool;
787786 assert(!ip.isFunctionType(ip.typeOf(uav.ip_index)));
788787 const gop = try cg.mir_uavs.getOrPut(cg.gpa, uav.ip_index);
......@@ -853,7 +852,7 @@ fn releaseLocal(cg: *CodeGen, index: u32) void {
853852/// Creates one locals for a given `Type`.
854853/// Returns a corresponding `Wvalue` with `local` as active tag
855854fn allocLocal(cg: *CodeGen, ty: Type) InnerError!WValue {
856 const zcu = cg.pt.zcu;
855 const zcu = cg.zcu;
857856 const valtype = typeToValtype(ty, zcu, cg.target);
858857 const free_list = cg.local_pool.freeList(valtype);
859858 if (free_list.unwrap()) |index| {
......@@ -870,7 +869,7 @@ fn allocLocal(cg: *CodeGen, ty: Type) InnerError!WValue {
870869/// Ensures a new local will be created. This is useful when it's useful
871870/// to use a zero-initialized local.
872871fn ensureAllocLocal(cg: *CodeGen, ty: Type) InnerError!WValue {
873 const zcu = cg.pt.zcu;
872 const zcu = cg.zcu;
874873 try cg.mir_locals.ensureUnusedCapacity(cg.gpa, 1);
875874 try cg.local_pool.locals.ensureUnusedCapacity(cg.gpa, 1);
876875 assert(cg.mir_locals.items.len == cg.local_pool.locals.items.len);
......@@ -905,7 +904,7 @@ pub fn generate(
905904
906905 var code_gen: CodeGen = .{
907906 .gpa = gpa,
908 .pt = pt,
907 .zcu = zcu,
909908 .air = air.*,
910909 .liveness = liveness.*.?,
911910 .owner_nav = cg.owner_nav,
......@@ -940,7 +939,7 @@ pub fn generate(
940939}
941940
942941fn generateInner(cg: *CodeGen, any_returns: bool) InnerError!Mir {
943 const zcu = cg.pt.zcu;
942 const zcu = cg.zcu;
944943 cg.wasm_param_count = @intCast(cg.args.len + @intFromBool(cg.return_value != .none) + @intFromBool(cg.varargs != .none));
945944 cg.initial_stack_value = try cg.ensureAllocLocal(Type.usize);
946945 cg.bottom_stack_value = try cg.ensureAllocLocal(Type.usize);
......@@ -1099,7 +1098,7 @@ fn lowerArg(cg: *CodeGen, cc: std.lang.CallingConvention, ty: Type, value: WValu
10991098 return cg.emitWValue(value);
11001099 }
11011100
1102 const zcu = cg.pt.zcu;
1101 const zcu = cg.zcu;
11031102
11041103 switch (abi.classifyType(ty, zcu, cg.target)) {
11051104 .direct => |scalar_ty| {
......@@ -1148,8 +1147,7 @@ fn restoreStackPointer(cg: *CodeGen) !void {
11481147///
11491148/// Asserts Type has codegenbits
11501149fn allocStack(cg: *CodeGen, ty: Type) !WValue {
1151 const pt = cg.pt;
1152 const zcu = pt.zcu;
1150 const zcu = cg.zcu;
11531151 assert(ty.hasRuntimeBits(zcu));
11541152
11551153 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {
......@@ -1187,8 +1185,7 @@ fn allocStackBytes(cg: *CodeGen, size: u32, alignment: Alignment) !WValue {
11871185/// This is different from allocStack where this will use the pointer's alignment
11881186/// if it is set, to ensure the stack alignment will be set correctly.
11891187fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue {
1190 const pt = cg.pt;
1191 const zcu = pt.zcu;
1188 const zcu = cg.zcu;
11921189 const ptr_ty = cg.typeOfIndex(inst);
11931190 const pointee_ty = ptr_ty.childType(zcu);
11941191
......@@ -1356,7 +1353,7 @@ pub fn determineSimdStoreStrategy(ty: Type, zcu: *const Zcu, target: *const std.
13561353}
13571354
13581355fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
1359 const zcu = cg.pt.zcu;
1356 const zcu = cg.zcu;
13601357 const air_tags = cg.air.instructions.items(.tag);
13611358 return switch (air_tags[@backingInt(inst)]) {
13621359 // No soft float legalizations are enabled.
......@@ -1492,7 +1489,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
14921489 const rhs = try cg.resolveInst(bin_op.rhs);
14931490 const ty = cg.typeOfIndex(inst);
14941491
1495 if (ty.zigTypeTag(cg.pt.zcu) == .vector) {
1492 if (ty.zigTypeTag(cg.zcu) == .vector) {
14961493 return cg.fail("TODO: implement AIR op: mul_add for vectors", .{});
14971494 }
14981495
......@@ -1510,7 +1507,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
15101507 const rhs = try cg.resolveInst(bin_op.rhs);
15111508 const ty = cg.typeOfIndex(inst);
15121509
1513 if (ty.zigTypeTag(cg.pt.zcu) == .vector) {
1510 if (ty.zigTypeTag(cg.zcu) == .vector) {
15141511 return cg.fail("TODO: implement AIR op: {s} for vectors", .{@tagName(tag)});
15151512 }
15161513
......@@ -1555,7 +1552,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
15551552 defer res_tmp.free(cg);
15561553
15571554 const result = try cg.allocStack(cg.typeOfIndex(inst));
1558 const offset: u32 = @intCast(ty.abiSize(cg.pt.zcu));
1555 const offset: u32 = @intCast(ty.abiSize(cg.zcu));
15591556
15601557 try cg.store(result, res_tmp, ty, .{});
15611558 try cg.store(result, ov_tmp, .u1, .{ .offset = offset });
......@@ -1675,7 +1672,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
16751672 const src_ty = cg.typeOf(ty_op.operand);
16761673 const dest_ty = cg.typeOfIndex(inst);
16771674
1678 if (dest_ty.zigTypeTag(cg.pt.zcu) == .vector) {
1675 if (dest_ty.zigTypeTag(cg.zcu) == .vector) {
16791676 return cg.fail("TODO: implement AIR op: {s} for vectors", .{@tagName(tag)});
16801677 }
16811678
......@@ -1959,7 +1956,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
19591956}
19601957
19611958fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
1962 const zcu = cg.pt.zcu;
1959 const zcu = cg.zcu;
19631960 const ip = &zcu.intern_pool;
19641961
19651962 for (body) |inst| {
......@@ -1979,7 +1976,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
19791976}
19801977
19811978fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
1982 const zcu = cg.pt.zcu;
1979 const zcu = cg.zcu;
19831980 const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op;
19841981 const operand = try cg.resolveInst(un_op);
19851982 const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?;
......@@ -2019,7 +2016,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20192016}
20202017
20212018fn airRetPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2022 const zcu = cg.pt.zcu;
2019 const zcu = cg.zcu;
20232020 const child_type = cg.typeOfIndex(inst).childType(zcu);
20242021
20252022 const result = result: {
......@@ -2039,7 +2036,7 @@ fn airRetPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20392036}
20402037
20412038fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2042 const zcu = cg.pt.zcu;
2039 const zcu = cg.zcu;
20432040 const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op;
20442041 const operand = try cg.resolveInst(un_op);
20452042 const ret_ty = cg.typeOf(un_op).childType(zcu);
......@@ -2076,8 +2073,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.lang.CallModifier)
20762073 const args = call.args;
20772074 const ty = cg.typeOf(call.callee);
20782075
2079 const pt = cg.pt;
2080 const zcu = pt.zcu;
2076 const zcu = cg.zcu;
20812077 const ip = &zcu.intern_pool;
20822078 const fn_ty = switch (ty.zigTypeTag(zcu)) {
20832079 .@"fn" => ty,
......@@ -2250,7 +2246,7 @@ fn airVaCopy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
22502246}
22512247
22522248fn airVaArg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2253 const zcu = cg.pt.zcu;
2249 const zcu = cg.zcu;
22542250 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
22552251 const operand = try cg.resolveInst(ty_op.operand);
22562252
......@@ -2322,8 +2318,7 @@ fn airAlloc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
23222318}
23232319
23242320fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
2325 const pt = cg.pt;
2326 const zcu = pt.zcu;
2321 const zcu = cg.zcu;
23272322 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
23282323
23292324 const lhs = try cg.resolveInst(bin_op.lhs);
......@@ -2366,8 +2361,7 @@ const MemArg = struct {
23662361
23672362fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, memarg: MemArg) InnerError!void {
23682363 assert(!(lhs != .stack and rhs == .stack));
2369 const pt = cg.pt;
2370 const zcu = pt.zcu;
2364 const zcu = cg.zcu;
23712365 const abi_size = ty.abiSize(zcu);
23722366
23732367 if (!ty.hasRuntimeBits(zcu)) return;
......@@ -2432,8 +2426,7 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, memarg: MemArg) Inner
24322426}
24332427
24342428fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2435 const pt = cg.pt;
2436 const zcu = pt.zcu;
2429 const zcu = cg.zcu;
24372430 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
24382431 const operand = try cg.resolveInst(ty_op.operand);
24392432 const elem_ty = ty_op.ty;
......@@ -2459,7 +2452,7 @@ fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
24592452/// Loads an operand from the linear memory section.
24602453/// NOTE: Leaves the value on the stack, if isByRef == false.
24612454fn load(cg: *CodeGen, operand: WValue, ty: Type, memarg: MemArg) InnerError!WValue {
2462 const zcu = cg.pt.zcu;
2455 const zcu = cg.zcu;
24632456
24642457 const natural_alignment = ty.abiAlignment(zcu);
24652458 // wasm memory instruction alignment is <= access width
......@@ -2537,8 +2530,7 @@ fn load(cg: *CodeGen, operand: WValue, ty: Type, memarg: MemArg) InnerError!WVal
25372530}
25382531
25392532fn airArg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2540 const pt = cg.pt;
2541 const zcu = pt.zcu;
2533 const zcu = cg.zcu;
25422534 const arg_index = cg.arg_index;
25432535 const arg = cg.args[arg_index];
25442536 const cc = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?.cc;
......@@ -2590,7 +2582,7 @@ const IntType = struct {
25902582 // Adapted from x86_64 backend
25912583 // Differ from Type.intInfo as it treats pointers/booleans/packed/enums/errors as integer
25922584 fn fromType(cg: *CodeGen, ty: Type) IntType {
2593 const zcu = cg.pt.zcu;
2585 const zcu = cg.zcu;
25942586 const ip = &zcu.intern_pool;
25952587 var ty_index = ty.ip_index;
25962588 while (true) switch (ip.indexToKey(ty_index)) {
......@@ -5041,8 +5033,7 @@ fn floatFromInt(cg: *CodeGen, dest_ty: FloatType, src_ty: IntType, operand: WVal
50415033}
50425034
50435035fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerError!WValue {
5044 const pt = cg.pt;
5045 const zcu = pt.zcu;
5036 const zcu = cg.zcu;
50465037 const ip = &zcu.intern_pool;
50475038 const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr;
50485039 const offset: u64 = prev_offset + ptr.byte_offset;
......@@ -5056,7 +5047,10 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro
50565047 .{ .uav_ref = .{ .ip_index = uav.val, .offset = @intCast(offset), .orig_ptr_ty = uav.orig_ty } }
50575048 else
50585049 .{ .imm32 = @intCast(Type.fromInterned(uav.orig_ty).ptrAlignment(zcu).forward(@as(u32, 0xaaaaaaaa))) },
5059 .int => return cg.lowerConstant(try pt.intValue(.usize, offset)),
5050 .int => return switch (cg.ptr_size) {
5051 .wasm32 => .{ .imm32 = @intCast(offset) },
5052 .wasm64 => .{ .imm64 = offset },
5053 },
50605054 .eu_payload => |eu_ptr| try cg.lowerPtr(
50615055 eu_ptr,
50625056 offset + codegen.errUnionPayloadOffset(
......@@ -5095,8 +5089,7 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro
50955089
50965090/// Asserts that `isByRef` returns `false` for `val.typeOf(zcu)`.
50975091fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue {
5098 const pt = cg.pt;
5099 const zcu = pt.zcu;
5092 const zcu = cg.zcu;
51005093 const ty = val.typeOf(zcu);
51015094 assert(!isByRef(ty, zcu, cg.target));
51025095 const ip = &zcu.intern_pool;
......@@ -5154,22 +5147,16 @@ fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue {
51545147 }
51555148 },
51565149 .err => |err| {
5157 const int = try pt.getErrorValue(err.name);
5150 const int = ip.getErrorValueIfExists(err.name).?;
51585151 return .{ .imm32 = int };
51595152 },
51605153 .error_union => |error_union| {
5161 const err_int_ty = try pt.errorIntType();
5162 const err_val: Value = switch (error_union.val) {
5163 .err_name => |err_name| .fromInterned(try pt.intern(.{ .err = .{
5164 .ty = ty.errorUnionSet(zcu).toIntern(),
5165 .name = err_name,
5166 } })),
5167 .payload => try pt.intValue(err_int_ty, 0),
5168 };
51695154 const payload_type = ty.errorUnionPayload(zcu);
51705155 if (!payload_type.hasRuntimeBits(zcu)) {
5171 // We use the error type directly as the type.
5172 return cg.lowerConstant(err_val);
5156 return .{ .imm32 = switch (error_union.val) {
5157 .err_name => |err_name| ip.getErrorValueIfExists(err_name).?,
5158 .payload => 0,
5159 } };
51735160 }
51745161
51755162 return cg.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});
......@@ -5233,7 +5220,7 @@ fn storeSimdImmd(cg: *CodeGen, value: [16]u8) !WValue {
52335220}
52345221
52355222fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {
5236 const zcu = cg.pt.zcu;
5223 const zcu = cg.zcu;
52375224 switch (ty.zigTypeTag(zcu)) {
52385225 .vector => return cg.storeSimdImmd(@splat(0xaa)),
52395226 .bool, .error_set => return .{ .imm32 = 0xaaaaaaaa },
......@@ -5276,7 +5263,7 @@ fn airBlock(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52765263}
52775264
52785265fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, block_ty: Type, body: []const Air.Inst.Index) InnerError!void {
5279 const zcu = cg.pt.zcu;
5266 const zcu = cg.zcu;
52805267
52815268 if (block_ty.isNoReturn(zcu)) {
52825269 assert(cg.liveness.getBlock(inst).deaths.len == 0);
......@@ -5385,7 +5372,7 @@ fn airCmp(cg: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) Inne
53855372 const lhs = try cg.resolveInst(bin_op.lhs);
53865373 const rhs = try cg.resolveInst(bin_op.rhs);
53875374 const operand_ty = cg.typeOf(bin_op.lhs);
5388 const zcu = cg.pt.zcu;
5375 const zcu = cg.zcu;
53895376
53905377 const type_tag = operand_ty.zigTypeTag(zcu);
53915378
......@@ -5617,10 +5604,10 @@ fn airCmpLteErrorsLen(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56175604 const operand = try cg.resolveInst(un_op);
56185605
56195606 try cg.emitWValue(operand);
5620 const pt = cg.pt;
5621 const err_int_ty = try pt.errorIntType();
5607 const zcu = cg.zcu;
5608 const err_int_ty: IntType = .{ .is_signed = false, .bits = zcu.errorSetBits() };
56225609 try cg.addTag(.errors_len);
5623 const result = try cg.intCmp(.fromType(cg, err_int_ty), .lt, .stack, .stack);
5610 const result = try cg.intCmp(err_int_ty, .lt, .stack, .stack);
56245611
56255612 return cg.finishAir(inst, result, &.{un_op});
56265613}
......@@ -5676,7 +5663,7 @@ fn airUnreachable(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56765663}
56775664
56785665fn airNopCast(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5679 const zcu = cg.pt.zcu;
5666 const zcu = cg.zcu;
56805667 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
56815668
56825669 const operand_ty = cg.typeOf(ty_op.operand);
......@@ -5690,7 +5677,7 @@ fn airNopCast(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56905677}
56915678
56925679fn airIntFromPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5693 const zcu = cg.pt.zcu;
5680 const zcu = cg.zcu;
56945681 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
56955682
56965683 const operand_ty = cg.typeOf(ty_op.operand);
......@@ -5709,7 +5696,7 @@ fn airIntFromPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57095696}
57105697
57115698fn airUnionFromEnum(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5712 const zcu = cg.pt.zcu;
5699 const zcu = cg.zcu;
57135700 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
57145701
57155702 const union_ty = cg.typeOfIndex(inst);
......@@ -5741,7 +5728,7 @@ const BitcastClass = union(enum) {
57415728};
57425729
57435730fn bitcastClass(cg: *CodeGen, ty: Type) BitcastClass {
5744 const zcu = cg.pt.zcu;
5731 const zcu = cg.zcu;
57455732 return switch (ty.zigTypeTag(zcu)) {
57465733 .bool,
57475734 .int,
......@@ -5759,7 +5746,7 @@ fn bitcastClass(cg: *CodeGen, ty: Type) BitcastClass {
57595746fn bitcast(cg: *CodeGen, dest_ty: Type, src_ty: Type, operand: WValue) InnerError!WValue {
57605747 if (dest_ty.eql(src_ty)) return operand;
57615748
5762 const zcu = cg.pt.zcu;
5749 const zcu = cg.zcu;
57635750 const src_class = cg.bitcastClass(src_ty);
57645751 const dest_class = cg.bitcastClass(dest_ty);
57655752 const src_by_ref = isByRef(src_ty, zcu, cg.target);
......@@ -5835,7 +5822,7 @@ fn bitcast(cg: *CodeGen, dest_ty: Type, src_ty: Type, operand: WValue) InnerErro
58355822}
58365823
58375824fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5838 const zcu = cg.pt.zcu;
5825 const zcu = cg.zcu;
58395826 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
58405827 const extra = cg.air.extraData(Air.StructField, ty_pl.payload);
58415828
......@@ -5847,7 +5834,7 @@ fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58475834}
58485835
58495836fn airStructFieldPtrIndex(cg: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
5850 const zcu = cg.pt.zcu;
5837 const zcu = cg.zcu;
58515838 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
58525839 const struct_ptr = try cg.resolveInst(ty_op.operand);
58535840 const struct_ptr_ty = cg.typeOf(ty_op.operand);
......@@ -5865,8 +5852,7 @@ fn structFieldPtr(
58655852 struct_ty: Type,
58665853 index: u32,
58675854) InnerError!WValue {
5868 const pt = cg.pt;
5869 const zcu = pt.zcu;
5855 const zcu = cg.zcu;
58705856 const result_ty = cg.typeOfIndex(inst);
58715857 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(zcu);
58725858
......@@ -5888,8 +5874,7 @@ fn structFieldPtr(
58885874}
58895875
58905876fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5891 const pt = cg.pt;
5892 const zcu = pt.zcu;
5877 const zcu = cg.zcu;
58935878 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
58945879 const struct_field = cg.air.extraData(Air.StructField, ty_pl.payload).data;
58955880
......@@ -5917,8 +5902,7 @@ fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59175902
59185903// Both `.switch_br` and `.loop_switch_br` are noreturn.
59195904fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index, is_dispatch_loop: bool) InnerError!void {
5920 const pt = cg.pt;
5921 const zcu = pt.zcu;
5905 const zcu = cg.zcu;
59225906
59235907 const switch_br = cg.air.unwrapSwitch(inst);
59245908 const target_ty = cg.typeOf(switch_br.operand);
......@@ -6146,7 +6130,7 @@ fn airSwitchDispatch(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61466130}
61476131
61486132fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {
6149 const zcu = cg.pt.zcu;
6133 const zcu = cg.zcu;
61506134 const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op;
61516135 const operand = try cg.resolveInst(un_op);
61526136 const err_union_ty = switch (op_kind) {
......@@ -6185,7 +6169,7 @@ fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kind
61856169/// E!T -> T op_is_ptr == false
61866170/// *(E!T) -> *T op_is_prt == true
61876171fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
6188 const zcu = cg.pt.zcu;
6172 const zcu = cg.zcu;
61896173 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
61906174
61916175 const operand = try cg.resolveInst(ty_op.operand);
......@@ -6217,7 +6201,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
62176201/// *(E!T) -> E op_is_ptr == true
62186202/// NOTE: op_is_ptr will not change return type
62196203fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
6220 const zcu = cg.pt.zcu;
6204 const zcu = cg.zcu;
62216205 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
62226206
62236207 const operand = try cg.resolveInst(ty_op.operand);
......@@ -6242,7 +6226,7 @@ fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) I
62426226}
62436227
62446228fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6245 const zcu = cg.pt.zcu;
6229 const zcu = cg.zcu;
62466230 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
62476231
62486232 const operand = try cg.resolveInst(ty_op.operand);
......@@ -6271,7 +6255,7 @@ fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
62716255}
62726256
62736257fn airWrapErrUnionErr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6274 const zcu = cg.pt.zcu;
6258 const zcu = cg.zcu;
62756259 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
62766260
62776261 const operand = try cg.resolveInst(ty_op.operand);
......@@ -6311,8 +6295,7 @@ fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kin
63116295/// For a given type and operand, checks if it's considered `null`.
63126296/// NOTE: Leaves the result on the stack
63136297fn isNull(cg: *CodeGen, operand: WValue, op_ty: Type, opcode: std.wasm.Opcode, op_kind: OpKind) InnerError!WValue {
6314 const pt = cg.pt;
6315 const zcu = pt.zcu;
6298 const zcu = cg.zcu;
63166299 const optional_ty = switch (op_kind) {
63176300 .value => op_ty,
63186301 .ptr => op_ty.childType(zcu),
......@@ -6357,7 +6340,7 @@ fn isNull(cg: *CodeGen, operand: WValue, op_ty: Type, opcode: std.wasm.Opcode, o
63576340}
63586341
63596342fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6360 const zcu = cg.pt.zcu;
6343 const zcu = cg.zcu;
63616344 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
63626345 const opt_ty = cg.typeOf(ty_op.operand);
63636346 const payload_ty = cg.typeOfIndex(inst);
......@@ -6379,7 +6362,7 @@ fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63796362}
63806363
63816364fn airOptionalPayloadPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6382 const zcu = cg.pt.zcu;
6365 const zcu = cg.zcu;
63836366 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
63846367 const operand = try cg.resolveInst(ty_op.operand);
63856368 const opt_ty = cg.typeOf(ty_op.operand).childType(zcu);
......@@ -6396,8 +6379,7 @@ fn airOptionalPayloadPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63966379}
63976380
63986381fn airOptionalPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6399 const pt = cg.pt;
6400 const zcu = pt.zcu;
6382 const zcu = cg.zcu;
64016383 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
64026384 const operand = try cg.resolveInst(ty_op.operand);
64036385 const opt_ty = cg.typeOf(ty_op.operand).childType(zcu);
......@@ -6421,8 +6403,7 @@ fn airOptionalPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void
64216403fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64226404 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
64236405 const payload_ty = cg.typeOf(ty_op.operand);
6424 const pt = cg.pt;
6425 const zcu = pt.zcu;
6406 const zcu = cg.zcu;
64266407
64276408 const result = result: {
64286409 if (!payload_ty.hasRuntimeBits(zcu)) {
......@@ -6478,7 +6459,7 @@ fn airSliceLen(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64786459}
64796460
64806461fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6481 const zcu = cg.pt.zcu;
6462 const zcu = cg.zcu;
64826463 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
64836464
64846465 const slice_ty = cg.typeOf(bin_op.lhs);
......@@ -6499,7 +6480,7 @@ fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64996480}
65006481
65016482fn airSliceElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6502 const zcu = cg.pt.zcu;
6483 const zcu = cg.zcu;
65036484 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
65046485 const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data;
65056486
......@@ -6534,7 +6515,7 @@ fn sliceLen(cg: *CodeGen, operand: WValue) InnerError!WValue {
65346515}
65356516
65366517fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6537 const zcu = cg.pt.zcu;
6518 const zcu = cg.zcu;
65386519 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
65396520
65406521 const operand = try cg.resolveInst(ty_op.operand);
......@@ -6554,7 +6535,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
65546535}
65556536
65566537fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6557 const zcu = cg.pt.zcu;
6538 const zcu = cg.zcu;
65586539 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
65596540
65606541 const ptr_ty = cg.typeOf(bin_op.lhs);
......@@ -6579,7 +6560,7 @@ fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
65796560}
65806561
65816562fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6582 const zcu = cg.pt.zcu;
6563 const zcu = cg.zcu;
65836564 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
65846565 const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data;
65856566
......@@ -6604,7 +6585,7 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66046585}
66056586
66066587fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: PointerOffsetOp) InnerError!void {
6607 const zcu = cg.pt.zcu;
6588 const zcu = cg.zcu;
66086589 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
66096590 const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data;
66106591
......@@ -6623,7 +6604,7 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: PointerOffsetOp) InnerErr
66236604}
66246605
66256606fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
6626 const zcu = cg.pt.zcu;
6607 const zcu = cg.zcu;
66276608 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
66286609
66296610 const ptr = try cg.resolveInst(bin_op.lhs);
......@@ -6657,7 +6638,7 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
66576638/// this to wasm's memset instruction. When the feature is not present,
66586639/// we implement it manually.
66596640fn memset(cg: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void {
6660 const zcu = cg.pt.zcu;
6641 const zcu = cg.zcu;
66616642 const abi_size = @as(u32, @intCast(elem_ty.abiSize(zcu)));
66626643 const len_known_neq_0 = switch (len) {
66636644 .imm32 => |imm| if (imm != 0) true else return,
......@@ -6774,7 +6755,7 @@ fn memset(cg: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue)
67746755}
67756756
67766757fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6777 const zcu = cg.pt.zcu;
6758 const zcu = cg.zcu;
67786759 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
67796760
67806761 const array_ty = cg.typeOf(bin_op.lhs);
......@@ -6828,7 +6809,7 @@ fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
68286809}
68296810
68306811fn airSplat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6831 const zcu = cg.pt.zcu;
6812 const zcu = cg.zcu;
68326813 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
68336814 const operand = try cg.resolveInst(ty_op.operand);
68346815 const ty = cg.typeOfIndex(inst);
......@@ -6899,8 +6880,7 @@ fn airSelect(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
68996880}
69006881
69016882fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6902 const pt = cg.pt;
6903 const zcu = pt.zcu;
6883 const zcu = cg.zcu;
69046884
69056885 const unwrapped = cg.air.unwrapShuffleOne(zcu, inst);
69066886 const result_ty = unwrapped.result_ty;
......@@ -6931,8 +6911,7 @@ fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
69316911}
69326912
69336913fn airShuffleTwo(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6934 const pt = cg.pt;
6935 const zcu = pt.zcu;
6914 const zcu = cg.zcu;
69366915
69376916 const unwrapped = cg.air.unwrapShuffleTwo(zcu, inst);
69386917 const result_ty = unwrapped.result_ty;
......@@ -7008,8 +6987,7 @@ fn airReduce(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70086987}
70096988
70106989fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7011 const pt = cg.pt;
7012 const zcu = pt.zcu;
6990 const zcu = cg.zcu;
70136991 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
70146992 const result_ty = cg.typeOfIndex(inst);
70156993 const len = @as(usize, @intCast(result_ty.arrayLen(zcu)));
......@@ -7067,9 +7045,10 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70677045 else => {
70687046 const result = try cg.allocStack(result_ty);
70697047 for (elements, 0..) |elem, elem_index| {
7070 if (try result_ty.structFieldValueComptime(pt, elem_index) != null) continue;
7048 if (result_ty.structFieldIsComptime(elem_index, zcu)) continue;
70717049
70727050 const elem_ty = result_ty.fieldType(elem_index, zcu);
7051 if (!elem_ty.hasRuntimeBits(zcu)) continue;
70737052 const field_offset = result_ty.structFieldOffset(elem_index, zcu);
70747053
70757054 const value = try cg.resolveInst(elem);
......@@ -7089,8 +7068,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70897068}
70907069
70917070fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7092 const pt = cg.pt;
7093 const zcu = pt.zcu;
7071 const zcu = cg.zcu;
70947072 const ip = &zcu.intern_pool;
70957073 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
70967074 const extra = cg.air.extraData(Air.UnionInit, ty_pl.payload).data;
......@@ -7102,11 +7080,27 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
71027080 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
71037081 const field_name = ip.loadEnumType(union_obj.enum_tag_type).field_names.get(ip)[extra.field_index];
71047082
7105 const tag_int = blk: {
7083 const tag_int: WValue = blk: {
71067084 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
71077085 const enum_field_index = tag_ty.enumFieldIndex(field_name, zcu).?;
7108 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);
7109 break :blk try cg.lowerConstant(tag_val);
7086 const enum_type = ip.loadEnumType(tag_ty.toIntern());
7087 const int_ty = Type.fromInterned(enum_type.int_tag_type);
7088 const int_bits = int_ty.intInfo(zcu).bits;
7089 if (int_bits > 64) {
7090 return cg.fail("TODO: union tags > 64 bits", .{});
7091 }
7092
7093 if (enum_type.field_values.len == 0) {
7094 // Auto-numbered fields.
7095 break :blk switch (int_bits) {
7096 0...32 => .{ .imm32 = enum_field_index },
7097 33...64 => .{ .imm64 = enum_field_index },
7098 else => unreachable,
7099 };
7100 }
7101
7102 const int_value = enum_type.field_values.get(ip)[enum_field_index];
7103 break :blk try cg.lowerConstant(.fromInterned(int_value));
71107104 };
71117105 if (layout.payload_size == 0) {
71127106 if (layout.tag_size == 0) {
......@@ -7167,8 +7161,7 @@ fn airWasmMemoryGrow(cg: *CodeGen, inst: Air.Inst.Index) !void {
71677161}
71687162
71697163fn airSetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7170 const pt = cg.pt;
7171 const zcu = pt.zcu;
7164 const zcu = cg.zcu;
71727165 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
71737166 const un_ty = cg.typeOf(bin_op.lhs).childType(zcu);
71747167 const tag_ty = cg.typeOf(bin_op.rhs);
......@@ -7192,7 +7185,7 @@ fn airSetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
71927185}
71937186
71947187fn airGetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7195 const zcu = cg.pt.zcu;
7188 const zcu = cg.zcu;
71967189 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
71977190
71987191 const un_ty = cg.typeOf(ty_op.operand);
......@@ -7212,7 +7205,7 @@ fn airGetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
72127205}
72137206
72147207fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7215 const zcu = cg.pt.zcu;
7208 const zcu = cg.zcu;
72167209 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
72177210
72187211 const err_set_ty = cg.typeOf(ty_op.operand).childType(zcu);
......@@ -7236,8 +7229,7 @@ fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void
72367229}
72377230
72387231fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7239 const pt = cg.pt;
7240 const zcu = pt.zcu;
7232 const zcu = cg.zcu;
72417233 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
72427234 const extra = cg.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
72437235
......@@ -7276,7 +7268,7 @@ fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
72767268}
72777269
72787270fn sliceOrArrayPtr(cg: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue {
7279 const zcu = cg.pt.zcu;
7271 const zcu = cg.zcu;
72807272 if (ptr_ty.isSlice(zcu)) {
72817273 return cg.slicePtr(ptr);
72827274 } else {
......@@ -7285,7 +7277,7 @@ fn sliceOrArrayPtr(cg: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue {
72857277}
72867278
72877279fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7288 const zcu = cg.pt.zcu;
7280 const zcu = cg.zcu;
72897281 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
72907282 const dst = try cg.resolveInst(bin_op.lhs);
72917283 const dst_ty = cg.typeOf(bin_op.lhs);
......@@ -7319,7 +7311,7 @@ fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73197311}
73207312
73217313fn airMemmove(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7322 const zcu = cg.pt.zcu;
7314 const zcu = cg.zcu;
73237315 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
73247316 const dst = try cg.resolveInst(bin_op.lhs);
73257317 const dst_ty = cg.typeOf(bin_op.lhs);
......@@ -7370,9 +7362,9 @@ fn airErrorName(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73707362 //
73717363 // As the names are global and the slice elements are constant, we do not have
73727364 // to make a copy of the ptr+value but can point towards them directly.
7373 const pt = cg.pt;
7365 const zcu = cg.zcu;
73747366 const name_ty = Type.slice_const_u8_sentinel_0;
7375 const abi_size = name_ty.abiSize(pt.zcu);
7367 const abi_size = name_ty.abiSize(zcu);
73767368
73777369 // Lowers to a i32.const or i64.const with the error table memory address.
73787370 cg.error_name_table_ref_count += 1;
......@@ -7433,7 +7425,7 @@ fn airTry(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
74337425}
74347426
74357427fn airTryPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7436 const zcu = cg.pt.zcu;
7428 const zcu = cg.zcu;
74377429 const unwrapped_try = cg.air.unwrapTryPtr(inst);
74387430 const err_union_ptr = try cg.resolveInst(unwrapped_try.error_union_ptr);
74397431 const body = unwrapped_try.else_body;
......@@ -7456,7 +7448,7 @@ fn lowerTry(
74567448 err_union_ty: Type,
74577449 operand_is_ptr: bool,
74587450) InnerError!WValue {
7459 const zcu = cg.pt.zcu;
7451 const zcu = cg.zcu;
74607452 const branch_liveness = cg.liveness.getCondBr(inst);
74617453
74627454 const pl_ty = err_union_ty.errorUnionPayload(zcu);
......@@ -7516,7 +7508,7 @@ fn callIntrinsic(
75167508 args: []const WValue,
75177509) InnerError!WValue {
75187510 assert(param_types.len == args.len);
7519 const zcu = cg.pt.zcu;
7511 const zcu = cg.zcu;
75207512
75217513 // Always pass over C-ABI
75227514
......@@ -7574,7 +7566,7 @@ fn airIsNamedEnumValue(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75747566}
75757567
75767568fn airErrorSetHasValue(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7577 const zcu = cg.pt.zcu;
7569 const zcu = cg.zcu;
75787570 const ip = &zcu.intern_pool;
75797571 const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op;
75807572
......@@ -7661,7 +7653,7 @@ inline fn useAtomicFeature(cg: *const CodeGen) bool {
76617653}
76627654
76637655fn airCmpxchg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7664 const zcu = cg.pt.zcu;
7656 const zcu = cg.zcu;
76657657 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
76667658 const extra = cg.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
76677659
......@@ -7739,7 +7731,7 @@ fn airCmpxchg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77397731}
77407732
77417733fn airAtomicLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7742 const zcu = cg.pt.zcu;
7734 const zcu = cg.zcu;
77437735 const atomic_load = cg.air.instructions.items(.data)[@backingInt(inst)].atomic_load;
77447736 const ptr = try cg.resolveInst(atomic_load.ptr);
77457737 const ty = cg.typeOfIndex(inst);
......@@ -7765,7 +7757,7 @@ fn airAtomicLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77657757}
77667758
77677759fn airAtomicRmw(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7768 const zcu = cg.pt.zcu;
7760 const zcu = cg.zcu;
77697761 const pl_op = cg.air.instructions.items(.data)[@backingInt(inst)].pl_op;
77707762 const extra = cg.air.extraData(Air.AtomicRmw, pl_op.payload).data;
77717763
......@@ -7972,7 +7964,7 @@ fn airAtomicRmw(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
79727964}
79737965
79747966fn airAtomicStore(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7975 const zcu = cg.pt.zcu;
7967 const zcu = cg.zcu;
79767968 const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op;
79777969
79787970 const ptr = try cg.resolveInst(bin_op.lhs);
......@@ -8008,7 +8000,7 @@ fn airFrameAddress(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
80088000
80098001fn airRuntimeNavPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
80108002 const ty_nav = cg.air.instructions.items(.data)[@backingInt(inst)].ty_nav;
8011 const mod = cg.pt.zcu.navFileScope(cg.owner_nav).mod.?;
8003 const mod = cg.zcu.navFileScope(cg.owner_nav).mod.?;
80128004 if (mod.single_threaded) {
80138005 const result: WValue = .{ .nav_ref = .{
80148006 .nav_index = ty_nav.nav,
......@@ -8024,7 +8016,7 @@ fn airAsm(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
80248016 const outputs = unwrapped_asm.outputs;
80258017 const inputs = unwrapped_asm.inputs;
80268018
8027 const zcu = cg.pt.zcu;
8019 const zcu = cg.zcu;
80288020 const output_ty = cg.typeOfIndex(inst);
80298021
80308022 const result: WValue = if (output_ty.hasRuntimeBits(zcu))
......@@ -8091,11 +8083,11 @@ fn airAsm(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
80918083}
80928084
80938085fn typeOf(cg: *CodeGen, inst: Air.Inst.Ref) Type {
8094 const zcu = cg.pt.zcu;
8086 const zcu = cg.zcu;
80958087 return cg.air.typeOf(inst, &zcu.intern_pool);
80968088}
80978089
80988090fn typeOfIndex(cg: *CodeGen, inst: Air.Inst.Index) Type {
8099 const zcu = cg.pt.zcu;
8091 const zcu = cg.zcu;
81008092 return cg.air.typeOfIndex(inst, &zcu.intern_pool);
81018093}