authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-08-11 22:03:50-07:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-08-25 15:17:40-07:00
log1c1feba08edf1ded85af0ec003939a7756f4ab0b
tree5bf36c67a1271f74e5e2bbec44ae9f737a91217a
parent9868ed44b31483b21236623e16e5a73b8c026a47
signaturelock-open Commit is signed but in an unrecognized format.

remove `mod` aliases for Zcus


10 files changed, 139 insertions(+), 143 deletions(-)

src/Compilation.zig+6-6
......@@ -4350,8 +4350,8 @@ fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Zcu.EmbedFile) void {
43504350}
43514351
43524352fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Zcu.EmbedFile) !void {
4353 const mod = comp.zcu.?;
4354 const ip = &mod.intern_pool;
4353 const zcu = comp.zcu.?;
4354 const ip = &zcu.intern_pool;
43554355 var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{});
43564356 defer file.close();
43574357
......@@ -4663,10 +4663,10 @@ fn reportRetryableEmbedFileError(
46634663 embed_file: *Zcu.EmbedFile,
46644664 err: anyerror,
46654665) error{OutOfMemory}!void {
4666 const mod = comp.zcu.?;
4667 const gpa = mod.gpa;
4666 const zcu = comp.zcu.?;
4667 const gpa = zcu.gpa;
46684668 const src_loc = embed_file.src_loc;
4669 const ip = &mod.intern_pool;
4669 const ip = &zcu.intern_pool;
46704670 const err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "unable to load '{}/{s}': {s}", .{
46714671 embed_file.owner.root,
46724672 embed_file.sub_file_path.toSlice(ip),
......@@ -4678,7 +4678,7 @@ fn reportRetryableEmbedFileError(
46784678 {
46794679 comp.mutex.lock();
46804680 defer comp.mutex.unlock();
4681 try mod.failed_embed_files.putNoClobber(gpa, embed_file, err_msg);
4681 try zcu.failed_embed_files.putNoClobber(gpa, embed_file, err_msg);
46824682 }
46834683}
46844684
src/Type.zig+14-14
......@@ -3028,9 +3028,9 @@ pub fn getParentNamespace(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex
30283028
30293029// Works for vectors and vectors of integers.
30303030pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
3031 const mod = pt.zcu;
3032 const scalar = try minIntScalar(ty.scalarType(mod), pt, dest_ty.scalarType(mod));
3033 return if (ty.zigTypeTag(mod) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
3031 const zcu = pt.zcu;
3032 const scalar = try minIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));
3033 return if (ty.zigTypeTag(zcu) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
30343034 .ty = dest_ty.toIntern(),
30353035 .storage = .{ .repeated_elem = scalar.toIntern() },
30363036 } })) else scalar;
......@@ -3038,8 +3038,8 @@ pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
30383038
30393039/// Asserts that the type is an integer.
30403040pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
3041 const mod = pt.zcu;
3042 const info = ty.intInfo(mod);
3041 const zcu = pt.zcu;
3042 const info = ty.intInfo(zcu);
30433043 if (info.signedness == .unsigned) return pt.intValue(dest_ty, 0);
30443044 if (info.bits == 0) return pt.intValue(dest_ty, -1);
30453045
......@@ -3048,7 +3048,7 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
30483048 return pt.intValue(dest_ty, n);
30493049 }
30503050
3051 var res = try std.math.big.int.Managed.init(mod.gpa);
3051 var res = try std.math.big.int.Managed.init(zcu.gpa);
30523052 defer res.deinit();
30533053
30543054 try res.setTwosCompIntLimit(.min, info.signedness, info.bits);
......@@ -3059,9 +3059,9 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
30593059// Works for vectors and vectors of integers.
30603060/// The returned Value will have type dest_ty.
30613061pub fn maxInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
3062 const mod = pt.zcu;
3063 const scalar = try maxIntScalar(ty.scalarType(mod), pt, dest_ty.scalarType(mod));
3064 return if (ty.zigTypeTag(mod) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
3062 const zcu = pt.zcu;
3063 const scalar = try maxIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));
3064 return if (ty.zigTypeTag(zcu) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
30653065 .ty = dest_ty.toIntern(),
30663066 .storage = .{ .repeated_elem = scalar.toIntern() },
30673067 } })) else scalar;
......@@ -3546,12 +3546,12 @@ pub fn optEuBaseType(ty: Type, zcu: *const Zcu) Type {
35463546}
35473547
35483548pub fn toUnsigned(ty: Type, pt: Zcu.PerThread) !Type {
3549 const mod = pt.zcu;
3550 return switch (ty.zigTypeTag(mod)) {
3551 .Int => pt.intType(.unsigned, ty.intInfo(mod).bits),
3549 const zcu = pt.zcu;
3550 return switch (ty.zigTypeTag(zcu)) {
3551 .Int => pt.intType(.unsigned, ty.intInfo(zcu).bits),
35523552 .Vector => try pt.vectorType(.{
3553 .len = ty.vectorLen(mod),
3554 .child = (try ty.childType(mod).toUnsigned(pt)).toIntern(),
3553 .len = ty.vectorLen(zcu),
3554 .child = (try ty.childType(zcu).toUnsigned(pt)).toIntern(),
35553555 }),
35563556 else => unreachable,
35573557 };
src/Zcu/PerThread.zig+16-16
......@@ -1555,8 +1555,8 @@ pub fn embedFile(
15551555 import_string: []const u8,
15561556 src_loc: Zcu.LazySrcLoc,
15571557) !InternPool.Index {
1558 const mod = pt.zcu;
1559 const gpa = mod.gpa;
1558 const zcu = pt.zcu;
1559 const gpa = zcu.gpa;
15601560
15611561 if (cur_file.mod.deps.get(import_string)) |pkg| {
15621562 const resolved_path = try std.fs.path.resolve(gpa, &.{
......@@ -1567,9 +1567,9 @@ pub fn embedFile(
15671567 var keep_resolved_path = false;
15681568 defer if (!keep_resolved_path) gpa.free(resolved_path);
15691569
1570 const gop = try mod.embed_table.getOrPut(gpa, resolved_path);
1570 const gop = try zcu.embed_table.getOrPut(gpa, resolved_path);
15711571 errdefer {
1572 assert(std.mem.eql(u8, mod.embed_table.pop().key, resolved_path));
1572 assert(std.mem.eql(u8, zcu.embed_table.pop().key, resolved_path));
15731573 keep_resolved_path = false;
15741574 }
15751575 if (gop.found_existing) return gop.value_ptr.*.val;
......@@ -1594,9 +1594,9 @@ pub fn embedFile(
15941594 var keep_resolved_path = false;
15951595 defer if (!keep_resolved_path) gpa.free(resolved_path);
15961596
1597 const gop = try mod.embed_table.getOrPut(gpa, resolved_path);
1597 const gop = try zcu.embed_table.getOrPut(gpa, resolved_path);
15981598 errdefer {
1599 assert(std.mem.eql(u8, mod.embed_table.pop().key, resolved_path));
1599 assert(std.mem.eql(u8, zcu.embed_table.pop().key, resolved_path));
16001600 keep_resolved_path = false;
16011601 }
16021602 if (gop.found_existing) return gop.value_ptr.*.val;
......@@ -1631,9 +1631,9 @@ fn newEmbedFile(
16311631 result: **Zcu.EmbedFile,
16321632 src_loc: Zcu.LazySrcLoc,
16331633) !InternPool.Index {
1634 const mod = pt.zcu;
1635 const gpa = mod.gpa;
1636 const ip = &mod.intern_pool;
1634 const zcu = pt.zcu;
1635 const gpa = zcu.gpa;
1636 const ip = &zcu.intern_pool;
16371637
16381638 const new_file = try gpa.create(Zcu.EmbedFile);
16391639 errdefer gpa.destroy(new_file);
......@@ -1655,7 +1655,7 @@ fn newEmbedFile(
16551655 if (actual_read != size) return error.UnexpectedEndOfFile;
16561656 bytes[0][size] = 0;
16571657
1658 const comp = mod.comp;
1658 const comp = zcu.comp;
16591659 switch (comp.cache_use) {
16601660 .whole => |whole| if (whole.cache_manifest) |man| {
16611661 const copied_resolved_path = try gpa.dupe(u8, resolved_path);
......@@ -2857,9 +2857,9 @@ pub fn errorSetFromUnsortedNames(
28572857
28582858/// Supports only pointers, not pointer-like optionals.
28592859pub fn ptrIntValue(pt: Zcu.PerThread, ty: Type, x: u64) Allocator.Error!Value {
2860 const mod = pt.zcu;
2861 assert(ty.zigTypeTag(mod) == .Pointer and !ty.isSlice(mod));
2862 assert(x != 0 or ty.isAllowzeroPtr(mod));
2860 const zcu = pt.zcu;
2861 assert(ty.zigTypeTag(zcu) == .Pointer and !ty.isSlice(zcu));
2862 assert(x != 0 or ty.isAllowzeroPtr(zcu));
28632863 return Value.fromInterned(try pt.intern(.{ .ptr = .{
28642864 .ty = ty.toIntern(),
28652865 .base_addr = .int,
......@@ -3008,10 +3008,10 @@ pub fn intFittingRange(pt: Zcu.PerThread, min: Value, max: Value) !Type {
30083008/// twos-complement integer; otherwise in an unsigned integer.
30093009/// Asserts that `val` is not undef. If `val` is negative, asserts that `sign` is true.
30103010pub fn intBitsForValue(pt: Zcu.PerThread, val: Value, sign: bool) u16 {
3011 const mod = pt.zcu;
3012 assert(!val.isUndef(mod));
3011 const zcu = pt.zcu;
3012 assert(!val.isUndef(zcu));
30133013
3014 const key = mod.intern_pool.indexToKey(val.toIntern());
3014 const key = zcu.intern_pool.indexToKey(val.toIntern());
30153015 switch (key.int.storage) {
30163016 .i64 => |x| {
30173017 if (std.math.cast(u64, x)) |casted| return Type.smallestUnsignedBits(casted) + @intFromBool(sign);
src/arch/sparc64/CodeGen.zig+40-44
......@@ -365,8 +365,8 @@ pub fn generate(
365365
366366fn gen(self: *Self) !void {
367367 const pt = self.pt;
368 const mod = pt.zcu;
369 const cc = self.fn_type.fnCallingConvention(mod);
368 const zcu = pt.zcu;
369 const cc = self.fn_type.fnCallingConvention(zcu);
370370 if (cc != .Naked) {
371371 // TODO Finish function prologue and epilogue for sparc64.
372372
......@@ -494,8 +494,8 @@ fn gen(self: *Self) !void {
494494
495495fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
496496 const pt = self.pt;
497 const mod = pt.zcu;
498 const ip = &mod.intern_pool;
497 const zcu = pt.zcu;
498 const ip = &zcu.intern_pool;
499499 const air_tags = self.air.instructions.items(.tag);
500500
501501 for (body) |inst| {
......@@ -760,18 +760,18 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
760760 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
761761 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
762762 const pt = self.pt;
763 const mod = pt.zcu;
763 const zcu = pt.zcu;
764764 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
765765 const lhs = try self.resolveInst(extra.lhs);
766766 const rhs = try self.resolveInst(extra.rhs);
767767 const lhs_ty = self.typeOf(extra.lhs);
768768 const rhs_ty = self.typeOf(extra.rhs);
769769
770 switch (lhs_ty.zigTypeTag(mod)) {
770 switch (lhs_ty.zigTypeTag(zcu)) {
771771 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
772772 .Int => {
773 assert(lhs_ty.eql(rhs_ty, mod));
774 const int_info = lhs_ty.intInfo(mod);
773 assert(lhs_ty.eql(rhs_ty, zcu));
774 const int_info = lhs_ty.intInfo(zcu);
775775 switch (int_info.bits) {
776776 32, 64 => {
777777 // Only say yes if the operation is
......@@ -839,9 +839,9 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
839839
840840fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
841841 const pt = self.pt;
842 const mod = pt.zcu;
842 const zcu = pt.zcu;
843843 const vector_ty = self.typeOfIndex(inst);
844 const len = vector_ty.vectorLen(mod);
844 const len = vector_ty.vectorLen(zcu);
845845 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
846846 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
847847 const result: MCValue = res: {
......@@ -874,13 +874,13 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
874874
875875fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
876876 const pt = self.pt;
877 const mod = pt.zcu;
877 const zcu = pt.zcu;
878878 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
879879 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
880880 const ptr_ty = self.typeOf(ty_op.operand);
881881 const ptr = try self.resolveInst(ty_op.operand);
882 const array_ty = ptr_ty.childType(mod);
883 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));
882 const array_ty = ptr_ty.childType(zcu);
883 const array_len = @as(u32, @intCast(array_ty.arrayLen(zcu)));
884884 const ptr_bytes = 8;
885885 const stack_offset = try self.allocMem(inst, ptr_bytes * 2, .@"8");
886886 try self.genSetStack(ptr_ty, stack_offset, ptr);
......@@ -1305,11 +1305,11 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13051305 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end .. extra.end + extra.data.args_len]));
13061306 const ty = self.typeOf(callee);
13071307 const pt = self.pt;
1308 const mod = pt.zcu;
1309 const ip = &mod.intern_pool;
1310 const fn_ty = switch (ty.zigTypeTag(mod)) {
1308 const zcu = pt.zcu;
1309 const ip = &zcu.intern_pool;
1310 const fn_ty = switch (ty.zigTypeTag(zcu)) {
13111311 .Fn => ty,
1312 .Pointer => ty.childType(mod),
1312 .Pointer => ty.childType(zcu),
13131313 else => unreachable,
13141314 };
13151315
......@@ -1361,7 +1361,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13611361 return self.fail("TODO implement calling bitcasted functions", .{});
13621362 },
13631363 } else {
1364 assert(ty.zigTypeTag(mod) == .Pointer);
1364 assert(ty.zigTypeTag(zcu) == .Pointer);
13651365 const mcv = try self.resolveInst(callee);
13661366 try self.genSetReg(ty, .o7, mcv);
13671367
......@@ -1636,13 +1636,9 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
16361636}
16371637
16381638fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {
1639 const pt = self.pt;
1640 const mod = pt.zcu;
16411639 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
16421640 const extra = self.air.extraData(Air.DbgInlineBlock, ty_pl.payload);
1643 const func = mod.funcInfo(extra.data.func);
16441641 // TODO emit debug info for function change
1645 _ = func;
16461642 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
16471643}
16481644
......@@ -1736,11 +1732,11 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
17361732 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
17371733
17381734 const pt = self.pt;
1739 const mod = pt.zcu;
1735 const zcu = pt.zcu;
17401736 const operand_ty = self.typeOf(ty_op.operand);
17411737 const operand = try self.resolveInst(ty_op.operand);
1742 const info_a = operand_ty.intInfo(mod);
1743 const info_b = self.typeOfIndex(inst).intInfo(mod);
1738 const info_a = operand_ty.intInfo(zcu);
1739 const info_b = self.typeOfIndex(inst).intInfo(zcu);
17441740 if (info_a.signedness != info_b.signedness)
17451741 return self.fail("TODO gen intcast sign safety in semantic analysis", .{});
17461742
......@@ -2025,18 +2021,18 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
20252021 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
20262022 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
20272023 const pt = self.pt;
2028 const mod = pt.zcu;
2024 const zcu = pt.zcu;
20292025 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20302026 const lhs = try self.resolveInst(extra.lhs);
20312027 const rhs = try self.resolveInst(extra.rhs);
20322028 const lhs_ty = self.typeOf(extra.lhs);
20332029 const rhs_ty = self.typeOf(extra.rhs);
20342030
2035 switch (lhs_ty.zigTypeTag(mod)) {
2031 switch (lhs_ty.zigTypeTag(zcu)) {
20362032 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
20372033 .Int => {
2038 assert(lhs_ty.eql(rhs_ty, mod));
2039 const int_info = lhs_ty.intInfo(mod);
2034 assert(lhs_ty.eql(rhs_ty, zcu));
2035 const int_info = lhs_ty.intInfo(zcu);
20402036 switch (int_info.bits) {
20412037 1...32 => {
20422038 try self.spillConditionFlagsIfOccupied();
......@@ -2090,7 +2086,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
20902086fn airNot(self: *Self, inst: Air.Inst.Index) !void {
20912087 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
20922088 const pt = self.pt;
2093 const mod = pt.zcu;
2089 const zcu = pt.zcu;
20942090 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20952091 const operand = try self.resolveInst(ty_op.operand);
20962092 const operand_ty = self.typeOf(ty_op.operand);
......@@ -2106,7 +2102,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
21062102 };
21072103 },
21082104 else => {
2109 switch (operand_ty.zigTypeTag(mod)) {
2105 switch (operand_ty.zigTypeTag(zcu)) {
21102106 .Bool => {
21112107 const op_reg = switch (operand) {
21122108 .register => |r| r,
......@@ -2140,7 +2136,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
21402136 },
21412137 .Vector => return self.fail("TODO bitwise not for vectors", .{}),
21422138 .Int => {
2143 const int_info = operand_ty.intInfo(mod);
2139 const int_info = operand_ty.intInfo(zcu);
21442140 if (int_info.bits <= 64) {
21452141 const op_reg = switch (operand) {
21462142 .register => |r| r,
......@@ -2323,17 +2319,17 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
23232319 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
23242320 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
23252321 const pt = self.pt;
2326 const mod = pt.zcu;
2322 const zcu = pt.zcu;
23272323 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
23282324 const lhs = try self.resolveInst(extra.lhs);
23292325 const rhs = try self.resolveInst(extra.rhs);
23302326 const lhs_ty = self.typeOf(extra.lhs);
23312327 const rhs_ty = self.typeOf(extra.rhs);
23322328
2333 switch (lhs_ty.zigTypeTag(mod)) {
2329 switch (lhs_ty.zigTypeTag(zcu)) {
23342330 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
23352331 .Int => {
2336 const int_info = lhs_ty.intInfo(mod);
2332 const int_info = lhs_ty.intInfo(zcu);
23372333 if (int_info.bits <= 64) {
23382334 try self.spillConditionFlagsIfOccupied();
23392335
......@@ -4328,13 +4324,13 @@ fn minMax(
43284324 rhs_ty: Type,
43294325) InnerError!MCValue {
43304326 const pt = self.pt;
4331 const mod = pt.zcu;
4332 assert(lhs_ty.eql(rhs_ty, mod));
4333 switch (lhs_ty.zigTypeTag(mod)) {
4327 const zcu = pt.zcu;
4328 assert(lhs_ty.eql(rhs_ty, zcu));
4329 switch (lhs_ty.zigTypeTag(zcu)) {
43344330 .Float => return self.fail("TODO min/max on floats", .{}),
43354331 .Vector => return self.fail("TODO min/max on vectors", .{}),
43364332 .Int => {
4337 const int_info = lhs_ty.intInfo(mod);
4333 const int_info = lhs_ty.intInfo(zcu);
43384334 if (int_info.bits <= 64) {
43394335 // TODO skip register setting when one of the operands
43404336 // is a small (fits in i13) immediate.
......@@ -4556,8 +4552,8 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
45564552
45574553fn ret(self: *Self, mcv: MCValue) !void {
45584554 const pt = self.pt;
4559 const mod = pt.zcu;
4560 const ret_ty = self.fn_type.fnReturnType(mod);
4555 const zcu = pt.zcu;
4556 const ret_ty = self.fn_type.fnReturnType(zcu);
45614557 try self.setRegOrMem(ret_ty, self.ret_mcv, mcv);
45624558
45634559 // Just add space for a branch instruction, patch this later
......@@ -4744,9 +4740,9 @@ fn trunc(
47444740 dest_ty: Type,
47454741) !MCValue {
47464742 const pt = self.pt;
4747 const mod = pt.zcu;
4748 const info_a = operand_ty.intInfo(mod);
4749 const info_b = dest_ty.intInfo(mod);
4743 const zcu = pt.zcu;
4744 const info_a = operand_ty.intInfo(zcu);
4745 const info_b = dest_ty.intInfo(zcu);
47504746
47514747 if (info_b.bits <= 64) {
47524748 const operand_reg = switch (operand) {
src/link/Elf/ZigObject.zig+16-16
......@@ -1382,8 +1382,8 @@ fn updateLazySymbol(
13821382 sym: link.File.LazySymbol,
13831383 symbol_index: Symbol.Index,
13841384) !void {
1385 const mod = pt.zcu;
1386 const gpa = mod.gpa;
1385 const zcu = pt.zcu;
1386 const gpa = zcu.gpa;
13871387
13881388 var required_alignment: InternPool.Alignment = .none;
13891389 var code_buffer = std.ArrayList(u8).init(gpa);
......@@ -1398,7 +1398,7 @@ fn updateLazySymbol(
13981398 break :blk try self.strtab.insert(gpa, name);
13991399 };
14001400
1401 const src = Type.fromInterned(sym.ty).srcLocOrNull(mod) orelse Zcu.LazySrcLoc.unneeded;
1401 const src = Type.fromInterned(sym.ty).srcLocOrNull(zcu) orelse Zcu.LazySrcLoc.unneeded;
14021402 const res = try codegen.generateLazySymbol(
14031403 &elf_file.base,
14041404 pt,
......@@ -1513,7 +1513,7 @@ pub fn updateExports(
15131513 const tracy = trace(@src());
15141514 defer tracy.end();
15151515
1516 const mod = pt.zcu;
1516 const zcu = pt.zcu;
15171517 const gpa = elf_file.base.comp.gpa;
15181518 const metadata = switch (exported) {
15191519 .nav => |nav| blk: {
......@@ -1521,15 +1521,15 @@ pub fn updateExports(
15211521 break :blk self.navs.getPtr(nav).?;
15221522 },
15231523 .uav => |uav| self.uavs.getPtr(uav) orelse blk: {
1524 const first_exp = mod.all_exports.items[export_indices[0]];
1524 const first_exp = zcu.all_exports.items[export_indices[0]];
15251525 const res = try self.lowerUav(elf_file, pt, uav, .none, first_exp.src);
15261526 switch (res) {
15271527 .mcv => {},
15281528 .fail => |em| {
15291529 // TODO maybe it's enough to return an error here and let Zcu.processExportsInner
15301530 // handle the error?
1531 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1532 mod.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
1531 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1532 zcu.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
15331533 return;
15341534 },
15351535 }
......@@ -1542,11 +1542,11 @@ pub fn updateExports(
15421542 const esym_shndx = self.symtab.items(.shndx)[esym_index];
15431543
15441544 for (export_indices) |export_idx| {
1545 const exp = mod.all_exports.items[export_idx];
1545 const exp = zcu.all_exports.items[export_idx];
15461546 if (exp.opts.section.unwrap()) |section_name| {
1547 if (!section_name.eqlSlice(".text", &mod.intern_pool)) {
1548 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1549 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1547 if (!section_name.eqlSlice(".text", &zcu.intern_pool)) {
1548 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1549 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
15501550 gpa,
15511551 exp.src,
15521552 "Unimplemented: ExportOptions.section",
......@@ -1560,8 +1560,8 @@ pub fn updateExports(
15601560 .strong => elf.STB_GLOBAL,
15611561 .weak => elf.STB_WEAK,
15621562 .link_once => {
1563 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1564 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1563 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1564 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
15651565 gpa,
15661566 exp.src,
15671567 "Unimplemented: GlobalLinkage.LinkOnce",
......@@ -1571,7 +1571,7 @@ pub fn updateExports(
15711571 },
15721572 };
15731573 const stt_bits: u8 = @as(u4, @truncate(esym.st_info));
1574 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1574 const exp_name = exp.opts.name.toSlice(&zcu.intern_pool);
15751575 const name_off = try self.strtab.insert(gpa, exp_name);
15761576 const global_sym_index = if (metadata.@"export"(self, exp_name)) |exp_index|
15771577 exp_index.*
......@@ -1626,8 +1626,8 @@ pub fn deleteExport(
16261626 .nav => |nav| self.navs.getPtr(nav),
16271627 .uav => |uav| self.uavs.getPtr(uav),
16281628 } orelse return;
1629 const mod = elf_file.base.comp.zcu.?;
1630 const exp_name = name.toSlice(&mod.intern_pool);
1629 const zcu = elf_file.base.comp.zcu.?;
1630 const exp_name = name.toSlice(&zcu.intern_pool);
16311631 const esym_index = metadata.@"export"(self, exp_name) orelse return;
16321632 log.debug("deleting export '{s}'", .{exp_name});
16331633 const esym = &self.symtab.items(.elf_sym)[esym_index.*];
src/link/MachO/ZigObject.zig+13-13
......@@ -1256,7 +1256,7 @@ pub fn updateExports(
12561256 const tracy = trace(@src());
12571257 defer tracy.end();
12581258
1259 const mod = pt.zcu;
1259 const zcu = pt.zcu;
12601260 const gpa = macho_file.base.comp.gpa;
12611261 const metadata = switch (exported) {
12621262 .nav => |nav| blk: {
......@@ -1264,15 +1264,15 @@ pub fn updateExports(
12641264 break :blk self.navs.getPtr(nav).?;
12651265 },
12661266 .uav => |uav| self.uavs.getPtr(uav) orelse blk: {
1267 const first_exp = mod.all_exports.items[export_indices[0]];
1267 const first_exp = zcu.all_exports.items[export_indices[0]];
12681268 const res = try self.lowerUav(macho_file, pt, uav, .none, first_exp.src);
12691269 switch (res) {
12701270 .mcv => {},
12711271 .fail => |em| {
12721272 // TODO maybe it's enough to return an error here and let Zcu.processExportsInner
12731273 // handle the error?
1274 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1275 mod.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
1274 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1275 zcu.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
12761276 return;
12771277 },
12781278 }
......@@ -1284,11 +1284,11 @@ pub fn updateExports(
12841284 const nlist = self.symtab.items(.nlist)[nlist_idx];
12851285
12861286 for (export_indices) |export_idx| {
1287 const exp = mod.all_exports.items[export_idx];
1287 const exp = zcu.all_exports.items[export_idx];
12881288 if (exp.opts.section.unwrap()) |section_name| {
1289 if (!section_name.eqlSlice("__text", &mod.intern_pool)) {
1290 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1291 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1289 if (!section_name.eqlSlice("__text", &zcu.intern_pool)) {
1290 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1291 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
12921292 gpa,
12931293 exp.src,
12941294 "Unimplemented: ExportOptions.section",
......@@ -1298,7 +1298,7 @@ pub fn updateExports(
12981298 }
12991299 }
13001300 if (exp.opts.linkage == .link_once) {
1301 try mod.failed_exports.putNoClobber(mod.gpa, export_idx, try Zcu.ErrorMsg.create(
1301 try zcu.failed_exports.putNoClobber(zcu.gpa, export_idx, try Zcu.ErrorMsg.create(
13021302 gpa,
13031303 exp.src,
13041304 "Unimplemented: GlobalLinkage.link_once",
......@@ -1307,7 +1307,7 @@ pub fn updateExports(
13071307 continue;
13081308 }
13091309
1310 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1310 const exp_name = exp.opts.name.toSlice(&zcu.intern_pool);
13111311 const global_nlist_index = if (metadata.@"export"(self, exp_name)) |exp_index|
13121312 exp_index.*
13131313 else blk: {
......@@ -1437,15 +1437,15 @@ pub fn deleteExport(
14371437 exported: Zcu.Exported,
14381438 name: InternPool.NullTerminatedString,
14391439) void {
1440 const mod = macho_file.base.comp.zcu.?;
1440 const zcu = macho_file.base.comp.zcu.?;
14411441
14421442 const metadata = switch (exported) {
14431443 .nav => |nav| self.navs.getPtr(nav),
14441444 .uav => |uav| self.uavs.getPtr(uav),
14451445 } orelse return;
1446 const nlist_index = metadata.@"export"(self, name.toSlice(&mod.intern_pool)) orelse return;
1446 const nlist_index = metadata.@"export"(self, name.toSlice(&zcu.intern_pool)) orelse return;
14471447
1448 log.debug("deleting export '{}'", .{name.fmt(&mod.intern_pool)});
1448 log.debug("deleting export '{}'", .{name.fmt(&zcu.intern_pool)});
14491449
14501450 const nlist = &self.symtab.items(.nlist)[nlist_index.*];
14511451 self.symtab.items(.size)[nlist_index.*] = 0;
src/link/Plan9.zig+16-16
......@@ -317,8 +317,8 @@ pub fn createEmpty(
317317
318318fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void {
319319 const gpa = self.base.comp.gpa;
320 const mod = self.base.comp.zcu.?;
321 const file_scope = mod.navFileScopeIndex(nav_index);
320 const zcu = self.base.comp.zcu.?;
321 const file_scope = zcu.navFileScopeIndex(nav_index);
322322 const fn_map_res = try self.fn_nav_table.getOrPut(gpa, file_scope);
323323 if (fn_map_res.found_existing) {
324324 if (try fn_map_res.value_ptr.functions.fetchPut(gpa, nav_index, out)) |old_entry| {
......@@ -326,7 +326,7 @@ fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void
326326 gpa.free(old_entry.value.lineinfo);
327327 }
328328 } else {
329 const file = mod.fileByIndex(file_scope);
329 const file = zcu.fileByIndex(file_scope);
330330 const arena = self.path_arena.allocator();
331331 // each file gets a symbol
332332 fn_map_res.value_ptr.* = .{
......@@ -391,10 +391,10 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
391391 @panic("Attempted to compile for object format that was disabled by build configuration");
392392 }
393393
394 const mod = pt.zcu;
395 const gpa = mod.gpa;
394 const zcu = pt.zcu;
395 const gpa = zcu.gpa;
396396 const target = self.base.comp.root_mod.resolved_target.result;
397 const func = mod.funcInfo(func_index);
397 const func = zcu.funcInfo(func_index);
398398
399399 const atom_idx = try self.seeNav(pt, func.owner_nav);
400400
......@@ -413,7 +413,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
413413 const res = try codegen.generateFunction(
414414 &self.base,
415415 pt,
416 mod.navSrcLoc(func.owner_nav),
416 zcu.navSrcLoc(func.owner_nav),
417417 func_index,
418418 air,
419419 liveness,
......@@ -423,7 +423,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
423423 const code = switch (res) {
424424 .ok => try code_buffer.toOwnedSlice(),
425425 .fail => |em| {
426 try mod.failed_codegen.put(gpa, func.owner_nav, em);
426 try zcu.failed_codegen.put(gpa, func.owner_nav, em);
427427 return;
428428 },
429429 };
......@@ -952,11 +952,11 @@ pub fn freeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) void {
952952 const gpa = self.base.comp.gpa;
953953 // TODO audit the lifetimes of decls table entries. It's possible to get
954954 // freeDecl without any updateDecl in between.
955 const mod = self.base.comp.zcu.?;
956 const decl = mod.declPtr(decl_index);
957 const is_fn = decl.val.isFuncBody(mod);
955 const zcu = self.base.comp.zcu.?;
956 const decl = zcu.declPtr(decl_index);
957 const is_fn = decl.val.isFuncBody(zcu);
958958 if (is_fn) {
959 const symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?;
959 const symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(zcu)).?;
960960 var submap = symidx_and_submap.functions;
961961 if (submap.fetchSwapRemove(decl_index)) |removed_entry| {
962962 gpa.free(removed_entry.value.code);
......@@ -1256,8 +1256,8 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void {
12561256}
12571257
12581258pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
1259 const mod = self.base.comp.zcu.?;
1260 const ip = &mod.intern_pool;
1259 const zcu = self.base.comp.zcu.?;
1260 const ip = &zcu.intern_pool;
12611261 const writer = buf.writer();
12621262 // write __GOT
12631263 try self.writeSym(writer, self.syms.items[0]);
......@@ -1284,7 +1284,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
12841284 try self.writeSym(writer, sym);
12851285 if (self.nav_exports.get(nav_index)) |export_indices| {
12861286 for (export_indices) |export_idx| {
1287 const exp = mod.all_exports.items[export_idx];
1287 const exp = zcu.all_exports.items[export_idx];
12881288 if (nav_metadata.getExport(self, exp.opts.name.toSlice(ip))) |exp_i| {
12891289 try self.writeSym(writer, self.syms.items[exp_i]);
12901290 }
......@@ -1323,7 +1323,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
13231323 try self.writeSym(writer, sym);
13241324 if (self.nav_exports.get(nav_index)) |export_indices| {
13251325 for (export_indices) |export_idx| {
1326 const exp = mod.all_exports.items[export_idx];
1326 const exp = zcu.all_exports.items[export_idx];
13271327 if (nav_metadata.getExport(self, exp.opts.name.toSlice(ip))) |exp_i| {
13281328 const s = self.syms.items[exp_i];
13291329 if (mem.eql(u8, s.name, "_start"))
src/link/Wasm/ZigObject.zig+8-8
......@@ -803,9 +803,9 @@ pub fn getUavVAddr(
803803 const parent_atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
804804 const parent_atom = wasm_file.getAtomPtr(parent_atom_index);
805805 const is_wasm32 = target.cpu.arch == .wasm32;
806 const mod = wasm_file.base.comp.zcu.?;
807 const ty = Type.fromInterned(mod.intern_pool.typeOf(uav));
808 if (ty.zigTypeTag(mod) == .Fn) {
806 const zcu = wasm_file.base.comp.zcu.?;
807 const ty = Type.fromInterned(zcu.intern_pool.typeOf(uav));
808 if (ty.zigTypeTag(zcu) == .Fn) {
809809 std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
810810 try parent_atom.relocs.append(gpa, .{
811811 .index = target_symbol_index,
......@@ -834,13 +834,13 @@ pub fn deleteExport(
834834 exported: Zcu.Exported,
835835 name: InternPool.NullTerminatedString,
836836) void {
837 const mod = wasm_file.base.comp.zcu.?;
837 const zcu = wasm_file.base.comp.zcu.?;
838838 const nav_index = switch (exported) {
839839 .nav => |nav_index| nav_index,
840840 .uav => @panic("TODO: implement Wasm linker code for exporting a constant value"),
841841 };
842842 const nav_info = zig_object.navs.getPtr(nav_index) orelse return;
843 if (nav_info.@"export"(zig_object, name.toSlice(&mod.intern_pool))) |sym_index| {
843 if (nav_info.@"export"(zig_object, name.toSlice(&zcu.intern_pool))) |sym_index| {
844844 const sym = zig_object.symbol(sym_index);
845845 nav_info.deleteExport(sym_index);
846846 std.debug.assert(zig_object.global_syms.remove(sym.name));
......@@ -930,8 +930,8 @@ pub fn updateExports(
930930
931931pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.Nav.Index) void {
932932 const gpa = wasm_file.base.comp.gpa;
933 const mod = wasm_file.base.comp.zcu.?;
934 const ip = &mod.intern_pool;
933 const zcu = wasm_file.base.comp.zcu.?;
934 const ip = &zcu.intern_pool;
935935 const nav_info = zig_object.navs.getPtr(nav_index).?;
936936 const atom_index = nav_info.atom;
937937 const atom = wasm_file.getAtomPtr(atom_index);
......@@ -956,7 +956,7 @@ pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.N
956956 segment.name = &.{}; // Ensure no accidental double free
957957 }
958958
959 const nav_val = mod.navValue(nav_index).toIntern();
959 const nav_val = zcu.navValue(nav_index).toIntern();
960960 if (ip.indexToKey(nav_val) == .@"extern") {
961961 std.debug.assert(zig_object.imports.remove(atom.sym_index));
962962 }
src/print_air.zig+6-6
......@@ -428,10 +428,10 @@ const Writer = struct {
428428 }
429429
430430 fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
431 const mod = w.pt.zcu;
431 const zcu = w.pt.zcu;
432432 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
433433 const vector_ty = ty_pl.ty.toType();
434 const len = @as(usize, @intCast(vector_ty.arrayLen(mod)));
434 const len = @as(usize, @intCast(vector_ty.arrayLen(zcu)));
435435 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));
436436
437437 try w.writeType(s, vector_ty);
......@@ -508,11 +508,11 @@ const Writer = struct {
508508 }
509509
510510 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
511 const mod = w.pt.zcu;
511 const zcu = w.pt.zcu;
512512 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
513513 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
514514
515 const elem_ty = w.typeOfIndex(inst).childType(mod);
515 const elem_ty = w.typeOfIndex(inst).childType(zcu);
516516 try w.writeType(s, elem_ty);
517517 try s.writeAll(", ");
518518 try w.writeOperand(s, inst, 0, pl_op.operand);
......@@ -974,7 +974,7 @@ const Writer = struct {
974974 }
975975
976976 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {
977 const mod = w.pt.zcu;
978 return w.air.typeOfIndex(inst, &mod.intern_pool);
977 const zcu = w.pt.zcu;
978 return w.air.typeOfIndex(inst, &zcu.intern_pool);
979979 }
980980};
src/print_value.zig+4-4
......@@ -62,8 +62,8 @@ pub fn print(
6262 comptime have_sema: bool,
6363 sema: if (have_sema) *Sema else void,
6464) (@TypeOf(writer).Error || Zcu.CompileError)!void {
65 const mod = pt.zcu;
66 const ip = &mod.intern_pool;
65 const zcu = pt.zcu;
66 const ip = &zcu.intern_pool;
6767 switch (ip.indexToKey(val.toIntern())) {
6868 .int_type,
6969 .ptr_type,
......@@ -116,7 +116,7 @@ pub fn print(
116116 enum_literal.fmt(ip),
117117 }),
118118 .enum_tag => |enum_tag| {
119 const enum_type = ip.loadEnumType(val.typeOf(mod).toIntern());
119 const enum_type = ip.loadEnumType(val.typeOf(zcu).toIntern());
120120 if (enum_type.tagValueIndex(ip, val.toIntern())) |tag_index| {
121121 return writer.print(".{i}", .{enum_type.names.get(ip)[tag_index].fmt(ip)});
122122 }
......@@ -173,7 +173,7 @@ pub fn print(
173173 return;
174174 }
175175 if (un.tag == .none) {
176 const backing_ty = try val.typeOf(mod).unionBackingType(pt);
176 const backing_ty = try val.typeOf(zcu).unionBackingType(pt);
177177 try writer.print("@bitCast(@as({}, ", .{backing_ty.fmt(pt)});
178178 try print(Value.fromInterned(un.val), writer, level - 1, pt, have_sema, sema);
179179 try writer.writeAll("))");