authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-06-15 19:57:47-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-07 22:59:52-04:00
logca02266157ee72e41068672c8ca6f928fcbf6fdf
treed827ad6e5d0d311c4fca7fa83a32a98d3d201ac4
parent525f341f33af9b8aad53931fd5511f00a82cb090

Zcu: pass `PerThread` to intern pool string functions


22 files changed, 1025 insertions(+), 963 deletions(-)

src/Compilation.zig+44-45
......@@ -29,8 +29,6 @@ const wasi_libc = @import("wasi_libc.zig");
2929const fatal = @import("main.zig").fatal;
3030const clangMain = @import("main.zig").clangMain;
3131const Zcu = @import("Zcu.zig");
32/// Deprecated; use `Zcu`.
33const Module = Zcu;
3432const Sema = @import("Sema.zig");
3533const InternPool = @import("InternPool.zig");
3634const Cache = std.Build.Cache;
......@@ -50,7 +48,7 @@ gpa: Allocator,
5048arena: Allocator,
5149/// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`.
5250/// TODO: rename to zcu: ?*Zcu
53module: ?*Module,
51module: ?*Zcu,
5452/// Contains different state depending on whether the Compilation uses
5553/// incremental or whole cache mode.
5654cache_use: CacheUse,
......@@ -120,7 +118,7 @@ astgen_work_queue: std.fifo.LinearFifo(Zcu.File.Index, .Dynamic),
120118/// These jobs are to inspect the file system stat() and if the embedded file has changed
121119/// on disk, mark the corresponding Decl outdated and queue up an `analyze_decl`
122120/// task for it.
123embed_file_work_queue: std.fifo.LinearFifo(*Module.EmbedFile, .Dynamic),
121embed_file_work_queue: std.fifo.LinearFifo(*Zcu.EmbedFile, .Dynamic),
124122
125123/// The ErrorMsg memory is owned by the `CObject`, using Compilation's general purpose allocator.
126124/// This data is accessed by multiple threads and is protected by `mutex`.
......@@ -252,7 +250,7 @@ pub const Emit = struct {
252250};
253251
254252pub const default_stack_protector_buffer_size = target_util.default_stack_protector_buffer_size;
255pub const SemaError = Module.SemaError;
253pub const SemaError = Zcu.SemaError;
256254
257255pub const CRTFile = struct {
258256 lock: Cache.Lock,
......@@ -1138,7 +1136,7 @@ pub const CreateOptions = struct {
11381136 pdb_source_path: ?[]const u8 = null,
11391137 /// (Windows) PDB output path
11401138 pdb_out_path: ?[]const u8 = null,
1141 error_limit: ?Compilation.Module.ErrorInt = null,
1139 error_limit: ?Zcu.ErrorInt = null,
11421140 global_cc_argv: []const []const u8 = &.{},
11431141
11441142 pub const Entry = link.File.OpenOptions.Entry;
......@@ -1344,7 +1342,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
13441342
13451343 const main_mod = options.main_mod orelse options.root_mod;
13461344 const comp = try arena.create(Compilation);
1347 const opt_zcu: ?*Module = if (have_zcu) blk: {
1345 const opt_zcu: ?*Zcu = if (have_zcu) blk: {
13481346 // Pre-open the directory handles for cached ZIR code so that it does not need
13491347 // to redundantly happen for each AstGen operation.
13501348 const zir_sub_dir = "z";
......@@ -1362,8 +1360,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
13621360 .path = try options.global_cache_directory.join(arena, &[_][]const u8{zir_sub_dir}),
13631361 };
13641362
1365 const emit_h: ?*Module.GlobalEmitH = if (options.emit_h) |loc| eh: {
1366 const eh = try arena.create(Module.GlobalEmitH);
1363 const emit_h: ?*Zcu.GlobalEmitH = if (options.emit_h) |loc| eh: {
1364 const eh = try arena.create(Zcu.GlobalEmitH);
13671365 eh.* = .{ .loc = loc };
13681366 break :eh eh;
13691367 } else null;
......@@ -1386,7 +1384,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
13861384 .builtin_modules = null, // `builtin_mod` is set
13871385 });
13881386
1389 const zcu = try arena.create(Module);
1387 const zcu = try arena.create(Zcu);
13901388 zcu.* = .{
13911389 .gpa = gpa,
13921390 .comp = comp,
......@@ -1434,7 +1432,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
14341432 .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa),
14351433 .win32_resource_work_queue = if (build_options.only_core_functionality) {} else std.fifo.LinearFifo(*Win32Resource, .Dynamic).init(gpa),
14361434 .astgen_work_queue = std.fifo.LinearFifo(Zcu.File.Index, .Dynamic).init(gpa),
1437 .embed_file_work_queue = std.fifo.LinearFifo(*Module.EmbedFile, .Dynamic).init(gpa),
1435 .embed_file_work_queue = std.fifo.LinearFifo(*Zcu.EmbedFile, .Dynamic).init(gpa),
14381436 .c_source_files = options.c_source_files,
14391437 .rc_source_files = options.rc_source_files,
14401438 .cache_parent = cache,
......@@ -2626,7 +2624,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void {
26262624 var num_errors: u32 = 0;
26272625 const max_errors = 5;
26282626 // Attach the "some omitted" note to the final error message
2629 var last_err: ?*Module.ErrorMsg = null;
2627 var last_err: ?*Zcu.ErrorMsg = null;
26302628
26312629 for (zcu.import_table.values(), 0..) |file, file_index_usize| {
26322630 if (!file.multi_pkg) continue;
......@@ -2642,13 +2640,13 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void {
26422640 const omitted = file.references.items.len -| max_notes;
26432641 const num_notes = file.references.items.len - omitted;
26442642
2645 const notes = try gpa.alloc(Module.ErrorMsg, if (omitted > 0) num_notes + 1 else num_notes);
2643 const notes = try gpa.alloc(Zcu.ErrorMsg, if (omitted > 0) num_notes + 1 else num_notes);
26462644 errdefer gpa.free(notes);
26472645
26482646 for (notes[0..num_notes], file.references.items[0..num_notes], 0..) |*note, ref, i| {
26492647 errdefer for (notes[0..i]) |*n| n.deinit(gpa);
26502648 note.* = switch (ref) {
2651 .import => |import| try Module.ErrorMsg.init(
2649 .import => |import| try Zcu.ErrorMsg.init(
26522650 gpa,
26532651 .{
26542652 .base_node_inst = try ip.trackZir(gpa, import.file, .main_struct_inst),
......@@ -2657,7 +2655,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void {
26572655 "imported from module {s}",
26582656 .{zcu.fileByIndex(import.file).mod.fully_qualified_name},
26592657 ),
2660 .root => |pkg| try Module.ErrorMsg.init(
2658 .root => |pkg| try Zcu.ErrorMsg.init(
26612659 gpa,
26622660 .{
26632661 .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst),
......@@ -2671,7 +2669,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void {
26712669 errdefer for (notes[0..num_notes]) |*n| n.deinit(gpa);
26722670
26732671 if (omitted > 0) {
2674 notes[num_notes] = try Module.ErrorMsg.init(
2672 notes[num_notes] = try Zcu.ErrorMsg.init(
26752673 gpa,
26762674 .{
26772675 .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst),
......@@ -2683,7 +2681,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void {
26832681 }
26842682 errdefer if (omitted > 0) notes[num_notes].deinit(gpa);
26852683
2686 const err = try Module.ErrorMsg.create(
2684 const err = try Zcu.ErrorMsg.create(
26872685 gpa,
26882686 .{
26892687 .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst),
......@@ -2706,7 +2704,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void {
27062704
27072705 // There isn't really any meaningful place to put this note, so just attach it to the
27082706 // last failed file
2709 var note = try Module.ErrorMsg.init(
2707 var note = try Zcu.ErrorMsg.init(
27102708 gpa,
27112709 err.src_loc,
27122710 "{} more errors omitted",
......@@ -3095,10 +3093,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30953093 const values = zcu.compile_log_sources.values();
30963094 // First one will be the error; subsequent ones will be notes.
30973095 const src_loc = values[0].src();
3098 const err_msg: Module.ErrorMsg = .{
3096 const err_msg: Zcu.ErrorMsg = .{
30993097 .src_loc = src_loc,
31003098 .msg = "found compile log statement",
3101 .notes = try gpa.alloc(Module.ErrorMsg, zcu.compile_log_sources.count() - 1),
3099 .notes = try gpa.alloc(Zcu.ErrorMsg, zcu.compile_log_sources.count() - 1),
31023100 };
31033101 defer gpa.free(err_msg.notes);
31043102
......@@ -3166,9 +3164,9 @@ pub const ErrorNoteHashContext = struct {
31663164};
31673165
31683166pub fn addModuleErrorMsg(
3169 mod: *Module,
3167 mod: *Zcu,
31703168 eb: *ErrorBundle.Wip,
3171 module_err_msg: Module.ErrorMsg,
3169 module_err_msg: Zcu.ErrorMsg,
31723170 all_references: *const std.AutoHashMapUnmanaged(InternPool.AnalUnit, Zcu.ResolvedReference),
31733171) !void {
31743172 const gpa = eb.gpa;
......@@ -3299,7 +3297,7 @@ pub fn addModuleErrorMsg(
32993297 }
33003298}
33013299
3302pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
3300pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Zcu.File) !void {
33033301 assert(file.zir_loaded);
33043302 assert(file.tree_loaded);
33053303 assert(file.source_loaded);
......@@ -3378,7 +3376,7 @@ pub fn performAllTheWork(
33783376 const path_digest = zcu.filePathDigest(file_index);
33793377 const root_decl = zcu.fileRootDecl(file_index);
33803378 const file = zcu.fileByIndex(file_index);
3381 comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerAstGenFile, .{
3379 comp.thread_pool.spawnWgId(&comp.astgen_wait_group, workerAstGenFile, .{
33823380 comp, file, file_index, path_digest, root_decl, zir_prog_node, &comp.astgen_wait_group, .root,
33833381 });
33843382 }
......@@ -3587,22 +3585,22 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
35873585 defer named_frame.end();
35883586
35893587 const gpa = comp.gpa;
3590 const zcu = comp.module.?;
3591 const decl = zcu.declPtr(decl_index);
3588 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3589 const decl = pt.zcu.declPtr(decl_index);
35923590 const lf = comp.bin_file.?;
3593 lf.updateDeclLineNumber(zcu, decl_index) catch |err| {
3594 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
3595 zcu.failed_analysis.putAssumeCapacityNoClobber(
3591 lf.updateDeclLineNumber(pt, decl_index) catch |err| {
3592 try pt.zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
3593 pt.zcu.failed_analysis.putAssumeCapacityNoClobber(
35963594 InternPool.AnalUnit.wrap(.{ .decl = decl_index }),
35973595 try Zcu.ErrorMsg.create(
35983596 gpa,
3599 decl.navSrcLoc(zcu),
3597 decl.navSrcLoc(pt.zcu),
36003598 "unable to update line number: {s}",
36013599 .{@errorName(err)},
36023600 ),
36033601 );
36043602 decl.analysis = .codegen_failure;
3605 try zcu.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
3603 try pt.zcu.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
36063604 };
36073605 },
36083606 .analyze_mod => |mod| {
......@@ -4049,6 +4047,7 @@ const AstGenSrc = union(enum) {
40494047};
40504048
40514049fn workerAstGenFile(
4050 tid: usize,
40524051 comp: *Compilation,
40534052 file: *Zcu.File,
40544053 file_index: Zcu.File.Index,
......@@ -4061,8 +4060,8 @@ fn workerAstGenFile(
40614060 const child_prog_node = prog_node.start(file.sub_file_path, 0);
40624061 defer child_prog_node.end();
40634062
4064 const zcu = comp.module.?;
4065 zcu.astGenFile(file, file_index, path_digest, root_decl) catch |err| switch (err) {
4063 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
4064 pt.astGenFile(file, file_index, path_digest, root_decl) catch |err| switch (err) {
40664065 error.AnalysisFail => return,
40674066 else => {
40684067 file.status = .retryable_failure;
......@@ -4097,15 +4096,15 @@ fn workerAstGenFile(
40974096 comp.mutex.lock();
40984097 defer comp.mutex.unlock();
40994098
4100 const res = zcu.importFile(file, import_path) catch continue;
4099 const res = pt.zcu.importFile(file, import_path) catch continue;
41014100 if (!res.is_pkg) {
4102 res.file.addReference(zcu.*, .{ .import = .{
4101 res.file.addReference(pt.zcu.*, .{ .import = .{
41034102 .file = file_index,
41044103 .token = item.data.token,
41054104 } }) catch continue;
41064105 }
4107 const imported_path_digest = zcu.filePathDigest(res.file_index);
4108 const imported_root_decl = zcu.fileRootDecl(res.file_index);
4106 const imported_path_digest = pt.zcu.filePathDigest(res.file_index);
4107 const imported_root_decl = pt.zcu.fileRootDecl(res.file_index);
41094108 break :blk .{ res, imported_path_digest, imported_root_decl };
41104109 };
41114110 if (import_result.is_new) {
......@@ -4116,7 +4115,7 @@ fn workerAstGenFile(
41164115 .importing_file = file_index,
41174116 .import_tok = item.data.token,
41184117 } };
4119 comp.thread_pool.spawnWg(wg, workerAstGenFile, .{
4118 comp.thread_pool.spawnWgId(wg, workerAstGenFile, .{
41204119 comp, import_result.file, import_result.file_index, imported_path_digest, imported_root_decl, prog_node, wg, sub_src,
41214120 });
41224121 }
......@@ -4127,7 +4126,7 @@ fn workerAstGenFile(
41274126fn workerUpdateBuiltinZigFile(
41284127 comp: *Compilation,
41294128 mod: *Package.Module,
4130 file: *Module.File,
4129 file: *Zcu.File,
41314130) void {
41324131 Builtin.populateFile(comp, mod, file) catch |err| {
41334132 comp.mutex.lock();
......@@ -4139,7 +4138,7 @@ fn workerUpdateBuiltinZigFile(
41394138 };
41404139}
41414140
4142fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Module.EmbedFile) void {
4141fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Zcu.EmbedFile) void {
41434142 comp.detectEmbedFileUpdate(embed_file) catch |err| {
41444143 comp.reportRetryableEmbedFileError(embed_file, err) catch |oom| switch (oom) {
41454144 // Swallowing this error is OK because it's implied to be OOM when
......@@ -4150,7 +4149,7 @@ fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Module.EmbedFile) void
41504149 };
41514150}
41524151
4153fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Module.EmbedFile) !void {
4152fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Zcu.EmbedFile) !void {
41544153 const mod = comp.module.?;
41554154 const ip = &mod.intern_pool;
41564155 var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{});
......@@ -4477,7 +4476,7 @@ fn reportRetryableAstGenError(
44774476 const file = zcu.fileByIndex(file_index);
44784477 file.status = .retryable_failure;
44794478
4480 const src_loc: Module.LazySrcLoc = switch (src) {
4479 const src_loc: Zcu.LazySrcLoc = switch (src) {
44814480 .root => .{
44824481 .base_node_inst = try zcu.intern_pool.trackZir(gpa, file_index, .main_struct_inst),
44834482 .offset = .entire_file,
......@@ -4488,7 +4487,7 @@ fn reportRetryableAstGenError(
44884487 },
44894488 };
44904489
4491 const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{
4490 const err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{
44924491 file.mod.root, file.sub_file_path, @errorName(err),
44934492 });
44944493 errdefer err_msg.destroy(gpa);
......@@ -4502,14 +4501,14 @@ fn reportRetryableAstGenError(
45024501
45034502fn reportRetryableEmbedFileError(
45044503 comp: *Compilation,
4505 embed_file: *Module.EmbedFile,
4504 embed_file: *Zcu.EmbedFile,
45064505 err: anyerror,
45074506) error{OutOfMemory}!void {
45084507 const mod = comp.module.?;
45094508 const gpa = mod.gpa;
45104509 const src_loc = embed_file.src_loc;
45114510 const ip = &mod.intern_pool;
4512 const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{
4511 const err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{
45134512 embed_file.owner.root,
45144513 embed_file.sub_file_path.toSlice(ip),
45154514 @errorName(err),
src/InternPool.zig+15-6
......@@ -4539,7 +4539,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void {
45394539 assert(ip.items.len == 0);
45404540
45414541 // Reserve string index 0 for an empty string.
4542 assert((try ip.getOrPutString(gpa, "", .no_embedded_nulls)) == .empty);
4542 assert((try ip.getOrPutString(gpa, .main, "", .no_embedded_nulls)) == .empty);
45434543
45444544 // So that we can use `catch unreachable` below.
45454545 try ip.items.ensureUnusedCapacity(gpa, static_keys.len);
......@@ -5986,6 +5986,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All
59865986 );
59875987 const string = try ip.getOrPutTrailingString(
59885988 gpa,
5989 tid,
59895990 @intCast(len_including_sentinel),
59905991 .maybe_embedded_nulls,
59915992 );
......@@ -6865,6 +6866,7 @@ pub fn getFuncInstance(
68656866 return finishFuncInstance(
68666867 ip,
68676868 gpa,
6869 tid,
68686870 generic_owner,
68696871 func_index,
68706872 func_extra_index,
......@@ -6879,7 +6881,7 @@ pub fn getFuncInstance(
68796881pub fn getFuncInstanceIes(
68806882 ip: *InternPool,
68816883 gpa: Allocator,
6882 _: Zcu.PerThread.Id,
6884 tid: Zcu.PerThread.Id,
68836885 arg: GetFuncInstanceKey,
68846886) Allocator.Error!Index {
68856887 // Validate input parameters.
......@@ -6994,6 +6996,7 @@ pub fn getFuncInstanceIes(
69946996 return finishFuncInstance(
69956997 ip,
69966998 gpa,
6999 tid,
69977000 generic_owner,
69987001 func_index,
69997002 func_extra_index,
......@@ -7005,6 +7008,7 @@ pub fn getFuncInstanceIes(
70057008fn finishFuncInstance(
70067009 ip: *InternPool,
70077010 gpa: Allocator,
7011 tid: Zcu.PerThread.Id,
70087012 generic_owner: Index,
70097013 func_index: Index,
70107014 func_extra_index: u32,
......@@ -7036,7 +7040,7 @@ fn finishFuncInstance(
70367040
70377041 // TODO: improve this name
70387042 const decl = ip.declPtr(decl_index);
7039 decl.name = try ip.getOrPutStringFmt(gpa, "{}__anon_{d}", .{
7043 decl.name = try ip.getOrPutStringFmt(gpa, tid, "{}__anon_{d}", .{
70407044 fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index),
70417045 }, .no_embedded_nulls);
70427046
......@@ -8782,18 +8786,20 @@ const EmbeddedNulls = enum {
87828786pub fn getOrPutString(
87838787 ip: *InternPool,
87848788 gpa: Allocator,
8789 tid: Zcu.PerThread.Id,
87858790 slice: []const u8,
87868791 comptime embedded_nulls: EmbeddedNulls,
87878792) Allocator.Error!embedded_nulls.StringType() {
87888793 try ip.string_bytes.ensureUnusedCapacity(gpa, slice.len + 1);
87898794 ip.string_bytes.appendSliceAssumeCapacity(slice);
87908795 ip.string_bytes.appendAssumeCapacity(0);
8791 return ip.getOrPutTrailingString(gpa, slice.len + 1, embedded_nulls);
8796 return ip.getOrPutTrailingString(gpa, tid, slice.len + 1, embedded_nulls);
87928797}
87938798
87948799pub fn getOrPutStringFmt(
87958800 ip: *InternPool,
87968801 gpa: Allocator,
8802 tid: Zcu.PerThread.Id,
87978803 comptime format: []const u8,
87988804 args: anytype,
87998805 comptime embedded_nulls: EmbeddedNulls,
......@@ -8803,16 +8809,17 @@ pub fn getOrPutStringFmt(
88038809 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
88048810 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;
88058811 ip.string_bytes.appendAssumeCapacity(0);
8806 return ip.getOrPutTrailingString(gpa, len, embedded_nulls);
8812 return ip.getOrPutTrailingString(gpa, tid, len, embedded_nulls);
88078813}
88088814
88098815pub fn getOrPutStringOpt(
88108816 ip: *InternPool,
88118817 gpa: Allocator,
8818 tid: Zcu.PerThread.Id,
88128819 slice: ?[]const u8,
88138820 comptime embedded_nulls: EmbeddedNulls,
88148821) Allocator.Error!embedded_nulls.OptionalStringType() {
8815 const string = try getOrPutString(ip, gpa, slice orelse return .none, embedded_nulls);
8822 const string = try getOrPutString(ip, gpa, tid, slice orelse return .none, embedded_nulls);
88168823 return string.toOptional();
88178824}
88188825
......@@ -8820,9 +8827,11 @@ pub fn getOrPutStringOpt(
88208827pub fn getOrPutTrailingString(
88218828 ip: *InternPool,
88228829 gpa: Allocator,
8830 tid: Zcu.PerThread.Id,
88238831 len: usize,
88248832 comptime embedded_nulls: EmbeddedNulls,
88258833) Allocator.Error!embedded_nulls.StringType() {
8834 _ = tid;
88268835 const string_bytes = &ip.string_bytes;
88278836 const str_index: u32 = @intCast(string_bytes.items.len - len);
88288837 if (len > 0 and string_bytes.getLast() == 0) {
src/Sema.zig+141-121
......@@ -2093,12 +2093,12 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
20932093 const st_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(stack_trace_ty));
20942094
20952095 // st.instruction_addresses = &addrs;
2096 const instruction_addresses_field_name = try ip.getOrPutString(gpa, "instruction_addresses", .no_embedded_nulls);
2096 const instruction_addresses_field_name = try ip.getOrPutString(gpa, pt.tid, "instruction_addresses", .no_embedded_nulls);
20972097 const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, instruction_addresses_field_name, src, true);
20982098 try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store);
20992099
21002100 // st.index = 0;
2101 const index_field_name = try ip.getOrPutString(gpa, "index", .no_embedded_nulls);
2101 const index_field_name = try ip.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
21022102 const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, index_field_name, src, true);
21032103 try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store);
21042104
......@@ -2691,6 +2691,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
26912691 .decl_val => |str| capture: {
26922692 const decl_name = try ip.getOrPutString(
26932693 sema.gpa,
2694 pt.tid,
26942695 sema.code.nullTerminatedString(str),
26952696 .no_embedded_nulls,
26962697 );
......@@ -2700,6 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
27002701 .decl_ref => |str| capture: {
27012702 const decl_name = try ip.getOrPutString(
27022703 sema.gpa,
2704 pt.tid,
27032705 sema.code.nullTerminatedString(str),
27042706 .no_embedded_nulls,
27052707 );
......@@ -2847,7 +2849,7 @@ fn zirStructDecl(
28472849
28482850 if (new_namespace_index.unwrap()) |ns| {
28492851 const decls = sema.code.bodySlice(extra_index, decls_len);
2850 try mod.scanNamespace(ns, decls, mod.declPtr(new_decl_index));
2852 try pt.scanNamespace(ns, decls, mod.declPtr(new_decl_index));
28512853 }
28522854
28532855 try pt.finalizeAnonDecl(new_decl_index);
......@@ -2919,7 +2921,7 @@ fn createAnonymousDeclTypeNamed(
29192921 };
29202922
29212923 try writer.writeByte(')');
2922 const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls);
2924 const name = try ip.getOrPutString(gpa, pt.tid, buf.items, .no_embedded_nulls);
29232925 try zcu.initNewAnonDecl(new_decl_index, val, name);
29242926 return new_decl_index;
29252927 },
......@@ -2931,7 +2933,7 @@ fn createAnonymousDeclTypeNamed(
29312933 .dbg_var_ptr, .dbg_var_val => {
29322934 if (zir_data[i].str_op.operand != ref) continue;
29332935
2934 const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{
2936 const name = try ip.getOrPutStringFmt(gpa, pt.tid, "{}.{s}", .{
29352937 block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code),
29362938 }, .no_embedded_nulls);
29372939 try zcu.initNewAnonDecl(new_decl_index, val, name);
......@@ -2952,7 +2954,7 @@ fn createAnonymousDeclTypeNamed(
29522954 // This name is also used as the key in the parent namespace so it cannot be
29532955 // renamed.
29542956
2955 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2957 const name = ip.getOrPutStringFmt(gpa, pt.tid, "{}__{s}_{d}", .{
29562958 block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
29572959 }, .no_embedded_nulls) catch unreachable;
29582960 try zcu.initNewAnonDecl(new_decl_index, val, name);
......@@ -3084,7 +3086,7 @@ fn zirEnumDecl(
30843086 errdefer if (!done) if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns);
30853087
30863088 if (new_namespace_index.unwrap()) |ns| {
3087 try mod.scanNamespace(ns, decls, new_decl);
3089 try pt.scanNamespace(ns, decls, new_decl);
30883090 }
30893091
30903092 // We've finished the initial construction of this type, and are about to perform analysis.
......@@ -3169,7 +3171,7 @@ fn zirEnumDecl(
31693171 const field_name_zir = sema.code.nullTerminatedString(field_name_index);
31703172 extra_index += 2; // field name, doc comment
31713173
3172 const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
3174 const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls);
31733175
31743176 const value_src: LazySrcLoc = .{
31753177 .base_node_inst = tracked_inst,
......@@ -3352,7 +3354,7 @@ fn zirUnionDecl(
33523354
33533355 if (new_namespace_index.unwrap()) |ns| {
33543356 const decls = sema.code.bodySlice(extra_index, decls_len);
3355 try mod.scanNamespace(ns, decls, mod.declPtr(new_decl_index));
3357 try pt.scanNamespace(ns, decls, mod.declPtr(new_decl_index));
33563358 }
33573359
33583360 try pt.finalizeAnonDecl(new_decl_index);
......@@ -3441,7 +3443,7 @@ fn zirOpaqueDecl(
34413443
34423444 if (new_namespace_index.unwrap()) |ns| {
34433445 const decls = sema.code.bodySlice(extra_index, decls_len);
3444 try mod.scanNamespace(ns, decls, mod.declPtr(new_decl_index));
3446 try pt.scanNamespace(ns, decls, mod.declPtr(new_decl_index));
34453447 }
34463448
34473449 try pt.finalizeAnonDecl(new_decl_index);
......@@ -3470,7 +3472,7 @@ fn zirErrorSetDecl(
34703472 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
34713473 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);
34723474 const name = sema.code.nullTerminatedString(name_index);
3473 const name_ip = try mod.intern_pool.getOrPutString(gpa, name, .no_embedded_nulls);
3475 const name_ip = try mod.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
34743476 _ = try mod.getErrorValue(name_ip);
34753477 const result = names.getOrPutAssumeCapacity(name_ip);
34763478 assert(!result.found_existing); // verified in AstGen
......@@ -3634,7 +3636,7 @@ fn indexablePtrLen(
36343636 const is_pointer_to = object_ty.isSinglePointer(mod);
36353637 const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty;
36363638 try checkIndexable(sema, block, src, indexable_ty);
3637 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len", .no_embedded_nulls);
3639 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls);
36383640 return sema.fieldVal(block, src, object, field_name, src);
36393641}
36403642
......@@ -3649,7 +3651,7 @@ fn indexablePtrLenOrNone(
36493651 const operand_ty = sema.typeOf(operand);
36503652 try checkMemOperand(sema, block, src, operand_ty);
36513653 if (operand_ty.ptrSize(mod) == .Many) return .none;
3652 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len", .no_embedded_nulls);
3654 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls);
36533655 return sema.fieldVal(block, src, operand, field_name, src);
36543656}
36553657
......@@ -4405,7 +4407,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44054407 }
44064408 if (!object_ty.indexableHasLen(mod)) continue;
44074409
4408 break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, "len", .no_embedded_nulls), arg_src);
4410 break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), arg_src);
44094411 };
44104412 const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src);
44114413 if (len == .none) {
......@@ -4797,6 +4799,7 @@ fn validateUnionInit(
47974799 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
47984800 const field_name = try mod.intern_pool.getOrPutString(
47994801 gpa,
4802 pt.tid,
48004803 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
48014804 .no_embedded_nulls,
48024805 );
......@@ -4942,6 +4945,7 @@ fn validateStructInit(
49424945 struct_ptr_zir_ref = field_ptr_extra.lhs;
49434946 const field_name = try ip.getOrPutString(
49444947 gpa,
4948 pt.tid,
49454949 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
49464950 .no_embedded_nulls,
49474951 );
......@@ -5518,10 +5522,11 @@ fn failWithBadStructFieldAccess(
55185522 field_src: LazySrcLoc,
55195523 field_name: InternPool.NullTerminatedString,
55205524) CompileError {
5521 const zcu = sema.pt.zcu;
5525 const pt = sema.pt;
5526 const zcu = pt.zcu;
55225527 const ip = &zcu.intern_pool;
55235528 const decl = zcu.declPtr(struct_type.decl.unwrap().?);
5524 const fqn = try decl.fullyQualifiedName(zcu);
5529 const fqn = try decl.fullyQualifiedName(pt);
55255530
55265531 const msg = msg: {
55275532 const msg = try sema.errMsg(
......@@ -5544,12 +5549,13 @@ fn failWithBadUnionFieldAccess(
55445549 field_src: LazySrcLoc,
55455550 field_name: InternPool.NullTerminatedString,
55465551) CompileError {
5547 const zcu = sema.pt.zcu;
5552 const pt = sema.pt;
5553 const zcu = pt.zcu;
55485554 const ip = &zcu.intern_pool;
55495555 const gpa = sema.gpa;
55505556
55515557 const decl = zcu.declPtr(union_obj.decl);
5552 const fqn = try decl.fullyQualifiedName(zcu);
5558 const fqn = try decl.fullyQualifiedName(pt);
55535559
55545560 const msg = msg: {
55555561 const msg = try sema.errMsg(
......@@ -5715,7 +5721,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
57155721fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
57165722 const bytes = sema.code.instructions.items(.data)[@intFromEnum(inst)].str.get(sema.code);
57175723 return sema.addStrLit(
5718 try sema.pt.zcu.intern_pool.getOrPutString(sema.gpa, bytes, .maybe_embedded_nulls),
5724 try sema.pt.zcu.intern_pool.getOrPutString(sema.gpa, sema.pt.tid, bytes, .maybe_embedded_nulls),
57195725 bytes.len,
57205726 );
57215727}
......@@ -6057,7 +6063,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
60576063
60586064 const path_digest = zcu.filePathDigest(result.file_index);
60596065 const root_decl = zcu.fileRootDecl(result.file_index);
6060 zcu.astGenFile(result.file, result.file_index, path_digest, root_decl) catch |err|
6066 pt.astGenFile(result.file, result.file_index, path_digest, root_decl) catch |err|
60616067 return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
60626068
60636069 try pt.ensureFileAnalyzed(result.file_index);
......@@ -6418,6 +6424,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
64186424 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
64196425 const decl_name = try mod.intern_pool.getOrPutString(
64206426 mod.gpa,
6427 pt.tid,
64216428 sema.code.nullTerminatedString(extra.decl_name),
64226429 .no_embedded_nulls,
64236430 );
......@@ -6737,6 +6744,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
67376744 const src = block.tokenOffset(inst_data.src_tok);
67386745 const decl_name = try mod.intern_pool.getOrPutString(
67396746 sema.gpa,
6747 pt.tid,
67406748 inst_data.get(sema.code),
67416749 .no_embedded_nulls,
67426750 );
......@@ -6751,6 +6759,7 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
67516759 const src = block.tokenOffset(inst_data.src_tok);
67526760 const decl_name = try mod.intern_pool.getOrPutString(
67536761 sema.gpa,
6762 pt.tid,
67546763 inst_data.get(sema.code),
67556764 .no_embedded_nulls,
67566765 );
......@@ -6907,7 +6916,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
69076916
69086917 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
69096918 try stack_trace_ty.resolveFields(pt);
6910 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6919 const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
69116920 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {
69126921 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),
69136922 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
......@@ -6951,7 +6960,7 @@ fn popErrorReturnTrace(
69516960 try stack_trace_ty.resolveFields(pt);
69526961 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
69536962 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);
6954 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6963 const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
69556964 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true);
69566965 try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store);
69576966 } else if (is_non_error == null) {
......@@ -6977,7 +6986,7 @@ fn popErrorReturnTrace(
69776986 try stack_trace_ty.resolveFields(pt);
69786987 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
69796988 const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty);
6980 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6989 const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
69816990 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);
69826991 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);
69836992 _ = try then_block.addBr(cond_block_inst, .void_value);
......@@ -7038,6 +7047,7 @@ fn zirCall(
70387047 const object_ptr = try sema.resolveInst(extra.data.obj_ptr);
70397048 const field_name = try mod.intern_pool.getOrPutString(
70407049 sema.gpa,
7050 pt.tid,
70417051 sema.code.nullTerminatedString(extra.data.field_name_start),
70427052 .no_embedded_nulls,
70437053 );
......@@ -7103,7 +7113,7 @@ fn zirCall(
71037113 if (input_is_error or (pop_error_return_trace and return_ty.isError(mod))) {
71047114 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
71057115 try stack_trace_ty.resolveFields(pt);
7106 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "index", .no_embedded_nulls);
7116 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "index", .no_embedded_nulls);
71077117 const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src);
71087118
71097119 // Insert a save instruction before the arg resolution + call instructions we just generated
......@@ -8687,6 +8697,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
86878697 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
86888698 const name = try pt.zcu.intern_pool.getOrPutString(
86898699 sema.gpa,
8700 pt.tid,
86908701 inst_data.get(sema.code),
86918702 .no_embedded_nulls,
86928703 );
......@@ -8849,7 +8860,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88498860 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
88508861 const name = inst_data.get(sema.code);
88518862 return Air.internedToRef((try pt.intern(.{
8852 .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name, .no_embedded_nulls),
8863 .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, name, .no_embedded_nulls),
88538864 })));
88548865}
88558866
......@@ -9820,7 +9831,7 @@ fn funcCommon(
98209831 const func_index = try ip.getExternFunc(gpa, pt.tid, .{
98219832 .ty = func_ty,
98229833 .decl = sema.owner_decl_index,
9823 .lib_name = try mod.intern_pool.getOrPutStringOpt(gpa, opt_lib_name, .no_embedded_nulls),
9834 .lib_name = try mod.intern_pool.getOrPutStringOpt(gpa, pt.tid, opt_lib_name, .no_embedded_nulls),
98249835 });
98259836 return finishFunc(
98269837 sema,
......@@ -10281,6 +10292,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1028110292 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1028210293 const field_name = try mod.intern_pool.getOrPutString(
1028310294 sema.gpa,
10295 pt.tid,
1028410296 sema.code.nullTerminatedString(extra.field_name_start),
1028510297 .no_embedded_nulls,
1028610298 );
......@@ -10300,6 +10312,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1030010312 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1030110313 const field_name = try mod.intern_pool.getOrPutString(
1030210314 sema.gpa,
10315 pt.tid,
1030310316 sema.code.nullTerminatedString(extra.field_name_start),
1030410317 .no_embedded_nulls,
1030510318 );
......@@ -10319,6 +10332,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
1031910332 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1032010333 const field_name = try mod.intern_pool.getOrPutString(
1032110334 sema.gpa,
10335 pt.tid,
1032210336 sema.code.nullTerminatedString(extra.field_name_start),
1032310337 .no_embedded_nulls,
1032410338 );
......@@ -13983,6 +13997,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R
1398313997 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
1398413998 const name = try mod.intern_pool.getOrPutString(
1398513999 sema.gpa,
14000 pt.tid,
1398614001 inst_data.get(sema.code),
1398714002 .no_embedded_nulls,
1398814003 );
......@@ -17716,7 +17731,7 @@ fn zirBuiltinSrc(
1771617731 .val = try pt.intern(.{ .aggregate = .{
1771717732 .ty = array_ty,
1771817733 .storage = .{
17719 .bytes = try ip.getOrPutString(gpa, file_name, .maybe_embedded_nulls),
17734 .bytes = try ip.getOrPutString(gpa, pt.tid, file_name, .maybe_embedded_nulls),
1772017735 },
1772117736 } }),
1772217737 } },
......@@ -17778,7 +17793,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1777817793 block,
1777917794 src,
1778017795 type_info_ty.getNamespaceIndex(mod),
17781 try ip.getOrPutString(gpa, "Fn", .no_embedded_nulls),
17796 try ip.getOrPutString(gpa, pt.tid, "Fn", .no_embedded_nulls),
1778217797 )).?;
1778317798 try sema.ensureDeclAnalyzed(fn_info_decl_index);
1778417799 const fn_info_decl = mod.declPtr(fn_info_decl_index);
......@@ -17788,7 +17803,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1778817803 block,
1778917804 src,
1779017805 fn_info_ty.getNamespaceIndex(mod),
17791 try ip.getOrPutString(gpa, "Param", .no_embedded_nulls),
17806 try ip.getOrPutString(gpa, pt.tid, "Param", .no_embedded_nulls),
1779217807 )).?;
1779317808 try sema.ensureDeclAnalyzed(param_info_decl_index);
1779417809 const param_info_decl = mod.declPtr(param_info_decl_index);
......@@ -17890,7 +17905,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1789017905 block,
1789117906 src,
1789217907 type_info_ty.getNamespaceIndex(mod),
17893 try ip.getOrPutString(gpa, "Int", .no_embedded_nulls),
17908 try ip.getOrPutString(gpa, pt.tid, "Int", .no_embedded_nulls),
1789417909 )).?;
1789517910 try sema.ensureDeclAnalyzed(int_info_decl_index);
1789617911 const int_info_decl = mod.declPtr(int_info_decl_index);
......@@ -17918,7 +17933,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1791817933 block,
1791917934 src,
1792017935 type_info_ty.getNamespaceIndex(mod),
17921 try ip.getOrPutString(gpa, "Float", .no_embedded_nulls),
17936 try ip.getOrPutString(gpa, pt.tid, "Float", .no_embedded_nulls),
1792217937 )).?;
1792317938 try sema.ensureDeclAnalyzed(float_info_decl_index);
1792417939 const float_info_decl = mod.declPtr(float_info_decl_index);
......@@ -17950,7 +17965,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1795017965 block,
1795117966 src,
1795217967 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),
17953 try ip.getOrPutString(gpa, "Pointer", .no_embedded_nulls),
17968 try ip.getOrPutString(gpa, pt.tid, "Pointer", .no_embedded_nulls),
1795417969 )).?;
1795517970 try sema.ensureDeclAnalyzed(decl_index);
1795617971 const decl = mod.declPtr(decl_index);
......@@ -17961,7 +17976,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1796117976 block,
1796217977 src,
1796317978 pointer_ty.getNamespaceIndex(mod),
17964 try ip.getOrPutString(gpa, "Size", .no_embedded_nulls),
17979 try ip.getOrPutString(gpa, pt.tid, "Size", .no_embedded_nulls),
1796517980 )).?;
1796617981 try sema.ensureDeclAnalyzed(decl_index);
1796717982 const decl = mod.declPtr(decl_index);
......@@ -18004,7 +18019,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1800418019 block,
1800518020 src,
1800618021 type_info_ty.getNamespaceIndex(mod),
18007 try ip.getOrPutString(gpa, "Array", .no_embedded_nulls),
18022 try ip.getOrPutString(gpa, pt.tid, "Array", .no_embedded_nulls),
1800818023 )).?;
1800918024 try sema.ensureDeclAnalyzed(array_field_ty_decl_index);
1801018025 const array_field_ty_decl = mod.declPtr(array_field_ty_decl_index);
......@@ -18035,7 +18050,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1803518050 block,
1803618051 src,
1803718052 type_info_ty.getNamespaceIndex(mod),
18038 try ip.getOrPutString(gpa, "Vector", .no_embedded_nulls),
18053 try ip.getOrPutString(gpa, pt.tid, "Vector", .no_embedded_nulls),
1803918054 )).?;
1804018055 try sema.ensureDeclAnalyzed(vector_field_ty_decl_index);
1804118056 const vector_field_ty_decl = mod.declPtr(vector_field_ty_decl_index);
......@@ -18064,7 +18079,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1806418079 block,
1806518080 src,
1806618081 type_info_ty.getNamespaceIndex(mod),
18067 try ip.getOrPutString(gpa, "Optional", .no_embedded_nulls),
18082 try ip.getOrPutString(gpa, pt.tid, "Optional", .no_embedded_nulls),
1806818083 )).?;
1806918084 try sema.ensureDeclAnalyzed(optional_field_ty_decl_index);
1807018085 const optional_field_ty_decl = mod.declPtr(optional_field_ty_decl_index);
......@@ -18091,7 +18106,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1809118106 block,
1809218107 src,
1809318108 type_info_ty.getNamespaceIndex(mod),
18094 try ip.getOrPutString(gpa, "Error", .no_embedded_nulls),
18109 try ip.getOrPutString(gpa, pt.tid, "Error", .no_embedded_nulls),
1809518110 )).?;
1809618111 try sema.ensureDeclAnalyzed(set_field_ty_decl_index);
1809718112 const set_field_ty_decl = mod.declPtr(set_field_ty_decl_index);
......@@ -18197,7 +18212,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1819718212 block,
1819818213 src,
1819918214 type_info_ty.getNamespaceIndex(mod),
18200 try ip.getOrPutString(gpa, "ErrorUnion", .no_embedded_nulls),
18215 try ip.getOrPutString(gpa, pt.tid, "ErrorUnion", .no_embedded_nulls),
1820118216 )).?;
1820218217 try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index);
1820318218 const error_union_field_ty_decl = mod.declPtr(error_union_field_ty_decl_index);
......@@ -18227,7 +18242,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1822718242 block,
1822818243 src,
1822918244 type_info_ty.getNamespaceIndex(mod),
18230 try ip.getOrPutString(gpa, "EnumField", .no_embedded_nulls),
18245 try ip.getOrPutString(gpa, pt.tid, "EnumField", .no_embedded_nulls),
1823118246 )).?;
1823218247 try sema.ensureDeclAnalyzed(enum_field_ty_decl_index);
1823318248 const enum_field_ty_decl = mod.declPtr(enum_field_ty_decl_index);
......@@ -18324,7 +18339,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1832418339 block,
1832518340 src,
1832618341 type_info_ty.getNamespaceIndex(mod),
18327 try ip.getOrPutString(gpa, "Enum", .no_embedded_nulls),
18342 try ip.getOrPutString(gpa, pt.tid, "Enum", .no_embedded_nulls),
1832818343 )).?;
1832918344 try sema.ensureDeclAnalyzed(type_enum_ty_decl_index);
1833018345 const type_enum_ty_decl = mod.declPtr(type_enum_ty_decl_index);
......@@ -18356,7 +18371,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1835618371 block,
1835718372 src,
1835818373 type_info_ty.getNamespaceIndex(mod),
18359 try ip.getOrPutString(gpa, "Union", .no_embedded_nulls),
18374 try ip.getOrPutString(gpa, pt.tid, "Union", .no_embedded_nulls),
1836018375 )).?;
1836118376 try sema.ensureDeclAnalyzed(type_union_ty_decl_index);
1836218377 const type_union_ty_decl = mod.declPtr(type_union_ty_decl_index);
......@@ -18368,7 +18383,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1836818383 block,
1836918384 src,
1837018385 type_info_ty.getNamespaceIndex(mod),
18371 try ip.getOrPutString(gpa, "UnionField", .no_embedded_nulls),
18386 try ip.getOrPutString(gpa, pt.tid, "UnionField", .no_embedded_nulls),
1837218387 )).?;
1837318388 try sema.ensureDeclAnalyzed(union_field_ty_decl_index);
1837418389 const union_field_ty_decl = mod.declPtr(union_field_ty_decl_index);
......@@ -18473,7 +18488,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1847318488 block,
1847418489 src,
1847518490 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),
18476 try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls),
18491 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),
1847718492 )).?;
1847818493 try sema.ensureDeclAnalyzed(decl_index);
1847918494 const decl = mod.declPtr(decl_index);
......@@ -18506,7 +18521,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1850618521 block,
1850718522 src,
1850818523 type_info_ty.getNamespaceIndex(mod),
18509 try ip.getOrPutString(gpa, "Struct", .no_embedded_nulls),
18524 try ip.getOrPutString(gpa, pt.tid, "Struct", .no_embedded_nulls),
1851018525 )).?;
1851118526 try sema.ensureDeclAnalyzed(type_struct_ty_decl_index);
1851218527 const type_struct_ty_decl = mod.declPtr(type_struct_ty_decl_index);
......@@ -18518,7 +18533,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1851818533 block,
1851918534 src,
1852018535 type_info_ty.getNamespaceIndex(mod),
18521 try ip.getOrPutString(gpa, "StructField", .no_embedded_nulls),
18536 try ip.getOrPutString(gpa, pt.tid, "StructField", .no_embedded_nulls),
1852218537 )).?;
1852318538 try sema.ensureDeclAnalyzed(struct_field_ty_decl_index);
1852418539 const struct_field_ty_decl = mod.declPtr(struct_field_ty_decl_index);
......@@ -18540,7 +18555,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1854018555 const field_name = if (anon_struct_type.names.len != 0)
1854118556 anon_struct_type.names.get(ip)[field_index]
1854218557 else
18543 try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls);
18558 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
1854418559 const field_name_len = field_name.length(ip);
1854518560 const new_decl_ty = try pt.arrayType(.{
1854618561 .len = field_name_len,
......@@ -18600,7 +18615,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1860018615 const field_name = if (struct_type.fieldName(ip, field_index).unwrap()) |field_name|
1860118616 field_name
1860218617 else
18603 try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls);
18618 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
1860418619 const field_name_len = field_name.length(ip);
1860518620 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
1860618621 const field_init = struct_type.fieldInit(ip, field_index);
......@@ -18706,7 +18721,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1870618721 block,
1870718722 src,
1870818723 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),
18709 try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls),
18724 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),
1871018725 )).?;
1871118726 try sema.ensureDeclAnalyzed(decl_index);
1871218727 const decl = mod.declPtr(decl_index);
......@@ -18742,7 +18757,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1874218757 block,
1874318758 src,
1874418759 type_info_ty.getNamespaceIndex(mod),
18745 try ip.getOrPutString(gpa, "Opaque", .no_embedded_nulls),
18760 try ip.getOrPutString(gpa, pt.tid, "Opaque", .no_embedded_nulls),
1874618761 )).?;
1874718762 try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index);
1874818763 const type_opaque_ty_decl = mod.declPtr(type_opaque_ty_decl_index);
......@@ -18786,7 +18801,7 @@ fn typeInfoDecls(
1878618801 block,
1878718802 src,
1878818803 type_info_ty.getNamespaceIndex(mod),
18789 try mod.intern_pool.getOrPutString(gpa, "Declaration", .no_embedded_nulls),
18804 try mod.intern_pool.getOrPutString(gpa, pt.tid, "Declaration", .no_embedded_nulls),
1879018805 )).?;
1879118806 try sema.ensureDeclAnalyzed(declaration_ty_decl_index);
1879218807 const declaration_ty_decl = mod.declPtr(declaration_ty_decl_index);
......@@ -19541,6 +19556,7 @@ fn zirRetErrValue(
1954119556 const src = block.tokenOffset(inst_data.src_tok);
1954219557 const err_name = try mod.intern_pool.getOrPutString(
1954319558 sema.gpa,
19559 pt.tid,
1954419560 inst_data.get(sema.code),
1954519561 .no_embedded_nulls,
1954619562 );
......@@ -20251,6 +20267,7 @@ fn zirStructInit(
2025120267 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
2025220268 const field_name = try ip.getOrPutString(
2025320269 gpa,
20270 pt.tid,
2025420271 sema.code.nullTerminatedString(field_type_extra.name_start),
2025520272 .no_embedded_nulls,
2025620273 );
......@@ -20292,6 +20309,7 @@ fn zirStructInit(
2029220309 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
2029320310 const field_name = try ip.getOrPutString(
2029420311 gpa,
20312 pt.tid,
2029520313 sema.code.nullTerminatedString(field_type_extra.name_start),
2029620314 .no_embedded_nulls,
2029720315 );
......@@ -20581,7 +20599,7 @@ fn structInitAnon(
2058120599 },
2058220600 };
2058320601
20584 field_name.* = try mod.intern_pool.getOrPutString(gpa, name, .no_embedded_nulls);
20602 field_name.* = try mod.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
2058520603
2058620604 const init = try sema.resolveInst(item.data.init);
2058720605 field_ty.* = sema.typeOf(init).toIntern();
......@@ -20958,7 +20976,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
2095820976 };
2095920977 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod);
2096020978 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);
20961 const field_name = try ip.getOrPutString(sema.gpa, zir_field_name, .no_embedded_nulls);
20979 const field_name = try ip.getOrPutString(sema.gpa, pt.tid, zir_field_name, .no_embedded_nulls);
2096220980 return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src);
2096320981}
2096420982
......@@ -21344,11 +21362,11 @@ fn zirReify(
2134421362 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2134521363 const signedness_val = try Value.fromInterned(union_val.val).fieldValue(
2134621364 pt,
21347 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness", .no_embedded_nulls)).?,
21365 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "signedness", .no_embedded_nulls)).?,
2134821366 );
2134921367 const bits_val = try Value.fromInterned(union_val.val).fieldValue(
2135021368 pt,
21351 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits", .no_embedded_nulls)).?,
21369 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls)).?,
2135221370 );
2135321371
2135421372 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
......@@ -21360,11 +21378,11 @@ fn zirReify(
2136021378 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2136121379 const len_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2136221380 ip,
21363 try ip.getOrPutString(gpa, "len", .no_embedded_nulls),
21381 try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls),
2136421382 ).?);
2136521383 const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2136621384 ip,
21367 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
21385 try ip.getOrPutString(gpa, pt.tid, "child", .no_embedded_nulls),
2136821386 ).?);
2136921387
2137021388 const len: u32 = @intCast(try len_val.toUnsignedIntSema(pt));
......@@ -21382,7 +21400,7 @@ fn zirReify(
2138221400 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2138321401 const bits_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2138421402 ip,
21385 try ip.getOrPutString(gpa, "bits", .no_embedded_nulls),
21403 try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls),
2138621404 ).?);
2138721405
2138821406 const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt));
......@@ -21400,35 +21418,35 @@ fn zirReify(
2140021418 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2140121419 const size_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2140221420 ip,
21403 try ip.getOrPutString(gpa, "size", .no_embedded_nulls),
21421 try ip.getOrPutString(gpa, pt.tid, "size", .no_embedded_nulls),
2140421422 ).?);
2140521423 const is_const_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2140621424 ip,
21407 try ip.getOrPutString(gpa, "is_const", .no_embedded_nulls),
21425 try ip.getOrPutString(gpa, pt.tid, "is_const", .no_embedded_nulls),
2140821426 ).?);
2140921427 const is_volatile_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2141021428 ip,
21411 try ip.getOrPutString(gpa, "is_volatile", .no_embedded_nulls),
21429 try ip.getOrPutString(gpa, pt.tid, "is_volatile", .no_embedded_nulls),
2141221430 ).?);
2141321431 const alignment_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2141421432 ip,
21415 try ip.getOrPutString(gpa, "alignment", .no_embedded_nulls),
21433 try ip.getOrPutString(gpa, pt.tid, "alignment", .no_embedded_nulls),
2141621434 ).?);
2141721435 const address_space_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2141821436 ip,
21419 try ip.getOrPutString(gpa, "address_space", .no_embedded_nulls),
21437 try ip.getOrPutString(gpa, pt.tid, "address_space", .no_embedded_nulls),
2142021438 ).?);
2142121439 const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2142221440 ip,
21423 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
21441 try ip.getOrPutString(gpa, pt.tid, "child", .no_embedded_nulls),
2142421442 ).?);
2142521443 const is_allowzero_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2142621444 ip,
21427 try ip.getOrPutString(gpa, "is_allowzero", .no_embedded_nulls),
21445 try ip.getOrPutString(gpa, pt.tid, "is_allowzero", .no_embedded_nulls),
2142821446 ).?);
2142921447 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2143021448 ip,
21431 try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls),
21449 try ip.getOrPutString(gpa, pt.tid, "sentinel", .no_embedded_nulls),
2143221450 ).?);
2143321451
2143421452 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
......@@ -21505,15 +21523,15 @@ fn zirReify(
2150521523 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2150621524 const len_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2150721525 ip,
21508 try ip.getOrPutString(gpa, "len", .no_embedded_nulls),
21526 try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls),
2150921527 ).?);
2151021528 const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2151121529 ip,
21512 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
21530 try ip.getOrPutString(gpa, pt.tid, "child", .no_embedded_nulls),
2151321531 ).?);
2151421532 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2151521533 ip,
21516 try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls),
21534 try ip.getOrPutString(gpa, pt.tid, "sentinel", .no_embedded_nulls),
2151721535 ).?);
2151821536
2151921537 const len = try len_val.toUnsignedIntSema(pt);
......@@ -21534,7 +21552,7 @@ fn zirReify(
2153421552 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2153521553 const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2153621554 ip,
21537 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
21555 try ip.getOrPutString(gpa, pt.tid, "child", .no_embedded_nulls),
2153821556 ).?);
2153921557
2154021558 const child_ty = child_val.toType();
......@@ -21546,11 +21564,11 @@ fn zirReify(
2154621564 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2154721565 const error_set_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2154821566 ip,
21549 try ip.getOrPutString(gpa, "error_set", .no_embedded_nulls),
21567 try ip.getOrPutString(gpa, pt.tid, "error_set", .no_embedded_nulls),
2155021568 ).?);
2155121569 const payload_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2155221570 ip,
21553 try ip.getOrPutString(gpa, "payload", .no_embedded_nulls),
21571 try ip.getOrPutString(gpa, pt.tid, "payload", .no_embedded_nulls),
2155421572 ).?);
2155521573
2155621574 const error_set_ty = error_set_val.toType();
......@@ -21579,7 +21597,7 @@ fn zirReify(
2157921597 const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern()));
2158021598 const name_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex(
2158121599 ip,
21582 try ip.getOrPutString(gpa, "name", .no_embedded_nulls),
21600 try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls),
2158321601 ).?);
2158421602
2158521603 const name = try sema.sliceToIpString(block, src, name_val, .{
......@@ -21601,23 +21619,23 @@ fn zirReify(
2160121619 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2160221620 const layout_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2160321621 ip,
21604 try ip.getOrPutString(gpa, "layout", .no_embedded_nulls),
21622 try ip.getOrPutString(gpa, pt.tid, "layout", .no_embedded_nulls),
2160521623 ).?);
2160621624 const backing_integer_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2160721625 ip,
21608 try ip.getOrPutString(gpa, "backing_integer", .no_embedded_nulls),
21626 try ip.getOrPutString(gpa, pt.tid, "backing_integer", .no_embedded_nulls),
2160921627 ).?);
2161021628 const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2161121629 ip,
21612 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
21630 try ip.getOrPutString(gpa, pt.tid, "fields", .no_embedded_nulls),
2161321631 ).?);
2161421632 const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2161521633 ip,
21616 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
21634 try ip.getOrPutString(gpa, pt.tid, "decls", .no_embedded_nulls),
2161721635 ).?);
2161821636 const is_tuple_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2161921637 ip,
21620 try ip.getOrPutString(gpa, "is_tuple", .no_embedded_nulls),
21638 try ip.getOrPutString(gpa, pt.tid, "is_tuple", .no_embedded_nulls),
2162121639 ).?);
2162221640
2162321641 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);
......@@ -21641,19 +21659,19 @@ fn zirReify(
2164121659 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2164221660 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2164321661 ip,
21644 try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls),
21662 try ip.getOrPutString(gpa, pt.tid, "tag_type", .no_embedded_nulls),
2164521663 ).?);
2164621664 const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2164721665 ip,
21648 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
21666 try ip.getOrPutString(gpa, pt.tid, "fields", .no_embedded_nulls),
2164921667 ).?);
2165021668 const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2165121669 ip,
21652 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
21670 try ip.getOrPutString(gpa, pt.tid, "decls", .no_embedded_nulls),
2165321671 ).?);
2165421672 const is_exhaustive_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2165521673 ip,
21656 try ip.getOrPutString(gpa, "is_exhaustive", .no_embedded_nulls),
21674 try ip.getOrPutString(gpa, pt.tid, "is_exhaustive", .no_embedded_nulls),
2165721675 ).?);
2165821676
2165921677 if (try decls_val.sliceLen(pt) > 0) {
......@@ -21670,7 +21688,7 @@ fn zirReify(
2167021688 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2167121689 const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2167221690 ip,
21673 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
21691 try ip.getOrPutString(gpa, pt.tid, "decls", .no_embedded_nulls),
2167421692 ).?);
2167521693
2167621694 // Decls
......@@ -21707,19 +21725,19 @@ fn zirReify(
2170721725 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2170821726 const layout_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2170921727 ip,
21710 try ip.getOrPutString(gpa, "layout", .no_embedded_nulls),
21728 try ip.getOrPutString(gpa, pt.tid, "layout", .no_embedded_nulls),
2171121729 ).?);
2171221730 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2171321731 ip,
21714 try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls),
21732 try ip.getOrPutString(gpa, pt.tid, "tag_type", .no_embedded_nulls),
2171521733 ).?);
2171621734 const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2171721735 ip,
21718 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
21736 try ip.getOrPutString(gpa, pt.tid, "fields", .no_embedded_nulls),
2171921737 ).?);
2172021738 const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2172121739 ip,
21722 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
21740 try ip.getOrPutString(gpa, pt.tid, "decls", .no_embedded_nulls),
2172321741 ).?);
2172421742
2172521743 if (try decls_val.sliceLen(pt) > 0) {
......@@ -21737,23 +21755,23 @@ fn zirReify(
2173721755 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
2173821756 const calling_convention_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2173921757 ip,
21740 try ip.getOrPutString(gpa, "calling_convention", .no_embedded_nulls),
21758 try ip.getOrPutString(gpa, pt.tid, "calling_convention", .no_embedded_nulls),
2174121759 ).?);
2174221760 const is_generic_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2174321761 ip,
21744 try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls),
21762 try ip.getOrPutString(gpa, pt.tid, "is_generic", .no_embedded_nulls),
2174521763 ).?);
2174621764 const is_var_args_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2174721765 ip,
21748 try ip.getOrPutString(gpa, "is_var_args", .no_embedded_nulls),
21766 try ip.getOrPutString(gpa, pt.tid, "is_var_args", .no_embedded_nulls),
2174921767 ).?);
2175021768 const return_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2175121769 ip,
21752 try ip.getOrPutString(gpa, "return_type", .no_embedded_nulls),
21770 try ip.getOrPutString(gpa, pt.tid, "return_type", .no_embedded_nulls),
2175321771 ).?);
2175421772 const params_slice_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex(
2175521773 ip,
21756 try ip.getOrPutString(gpa, "params", .no_embedded_nulls),
21774 try ip.getOrPutString(gpa, pt.tid, "params", .no_embedded_nulls),
2175721775 ).?);
2175821776
2175921777 const is_generic = is_generic_val.toBool();
......@@ -21783,15 +21801,15 @@ fn zirReify(
2178321801 const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern()));
2178421802 const param_is_generic_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex(
2178521803 ip,
21786 try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls),
21804 try ip.getOrPutString(gpa, pt.tid, "is_generic", .no_embedded_nulls),
2178721805 ).?);
2178821806 const param_is_noalias_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex(
2178921807 ip,
21790 try ip.getOrPutString(gpa, "is_noalias", .no_embedded_nulls),
21808 try ip.getOrPutString(gpa, pt.tid, "is_noalias", .no_embedded_nulls),
2179121809 ).?);
2179221810 const opt_param_type_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex(
2179321811 ip,
21794 try ip.getOrPutString(gpa, "type", .no_embedded_nulls),
21812 try ip.getOrPutString(gpa, pt.tid, "type", .no_embedded_nulls),
2179521813 ).?);
2179621814
2179721815 if (param_is_generic_val.toBool()) {
......@@ -22535,7 +22553,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2253522553 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2253622554 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2253722555
22538 const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(pt)}, .no_embedded_nulls);
22556 const type_name = try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{}", .{ty.fmt(pt)}, .no_embedded_nulls);
2253922557 return sema.addNullTerminatedStrLit(type_name);
2254022558}
2254122559
......@@ -24143,18 +24161,18 @@ fn resolveExportOptions(
2414324161 const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2414424162 const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2414524163
24146 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
24164 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src);
2414724165 const name = try sema.toConstString(block, name_src, name_operand, .{
2414824166 .needed_comptime_reason = "name of exported value must be comptime-known",
2414924167 });
2415024168
24151 const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage", .no_embedded_nulls), linkage_src);
24169 const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src);
2415224170 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{
2415324171 .needed_comptime_reason = "linkage of exported value must be comptime-known",
2415424172 });
2415524173 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2415624174
24157 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section", .no_embedded_nulls), section_src);
24175 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src);
2415824176 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{
2415924177 .needed_comptime_reason = "linksection of exported value must be comptime-known",
2416024178 });
......@@ -24165,7 +24183,7 @@ fn resolveExportOptions(
2416524183 else
2416624184 null;
2416724185
24168 const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility", .no_embedded_nulls), visibility_src);
24186 const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "visibility", .no_embedded_nulls), visibility_src);
2416924187 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{
2417024188 .needed_comptime_reason = "visibility of exported value must be comptime-known",
2417124189 });
......@@ -24182,9 +24200,9 @@ fn resolveExportOptions(
2418224200 }
2418324201
2418424202 return .{
24185 .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls),
24203 .name = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls),
2418624204 .linkage = linkage,
24187 .section = try ip.getOrPutStringOpt(gpa, section, .no_embedded_nulls),
24205 .section = try ip.getOrPutStringOpt(gpa, pt.tid, section, .no_embedded_nulls),
2418824206 .visibility = visibility,
2418924207 };
2419024208}
......@@ -25821,7 +25839,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2582125839
2582225840 const runtime_src = rs: {
2582325841 const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;
25824 const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, "len", .no_embedded_nulls), dest_src);
25842 const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), dest_src);
2582525843 const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src;
2582625844 const len_u64 = (try len_val.getUnsignedIntAdvanced(pt, .sema)).?;
2582725845 const len = try sema.usizeCast(block, dest_src, len_u64);
......@@ -25952,7 +25970,7 @@ fn zirVarExtended(
2595225970 .ty = var_ty.toIntern(),
2595325971 .init = init_val,
2595425972 .decl = sema.owner_decl_index,
25955 .lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, lib_name, .no_embedded_nulls),
25973 .lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, pt.tid, lib_name, .no_embedded_nulls),
2595625974 .is_extern = small.is_extern,
2595725975 .is_const = small.is_const,
2595825976 .is_threadlocal = small.is_threadlocal,
......@@ -26323,17 +26341,17 @@ fn resolvePrefetchOptions(
2632326341 const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2632426342 const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2632526343
26326 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src);
26344 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "rw", .no_embedded_nulls), rw_src);
2632726345 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
2632826346 .needed_comptime_reason = "prefetch read/write must be comptime-known",
2632926347 });
2633026348
26331 const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality", .no_embedded_nulls), locality_src);
26349 const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "locality", .no_embedded_nulls), locality_src);
2633226350 const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{
2633326351 .needed_comptime_reason = "prefetch locality must be comptime-known",
2633426352 });
2633526353
26336 const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache", .no_embedded_nulls), cache_src);
26354 const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "cache", .no_embedded_nulls), cache_src);
2633726355 const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{
2633826356 .needed_comptime_reason = "prefetch cache must be comptime-known",
2633926357 });
......@@ -26397,23 +26415,23 @@ fn resolveExternOptions(
2639726415 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2639826416 const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2639926417
26400 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
26418 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src);
2640126419 const name = try sema.toConstString(block, name_src, name_ref, .{
2640226420 .needed_comptime_reason = "name of the extern symbol must be comptime-known",
2640326421 });
2640426422
26405 const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name", .no_embedded_nulls), library_src);
26423 const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "library_name", .no_embedded_nulls), library_src);
2640626424 const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{
2640726425 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
2640826426 });
2640926427
26410 const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage", .no_embedded_nulls), linkage_src);
26428 const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src);
2641126429 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{
2641226430 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
2641326431 });
2641426432 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2641526433
26416 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local", .no_embedded_nulls), thread_local_src);
26434 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_thread_local", .no_embedded_nulls), thread_local_src);
2641726435 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{
2641826436 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
2641926437 });
......@@ -26438,8 +26456,8 @@ fn resolveExternOptions(
2643826456 }
2643926457
2644026458 return .{
26441 .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls),
26442 .library_name = try ip.getOrPutStringOpt(gpa, library_name, .no_embedded_nulls),
26459 .name = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls),
26460 .library_name = try ip.getOrPutStringOpt(gpa, pt.tid, library_name, .no_embedded_nulls),
2644326461 .linkage = linkage,
2644426462 .is_thread_local = is_thread_local_val.toBool(),
2644526463 };
......@@ -27052,7 +27070,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP
2705227070 block,
2705327071 LazySrcLoc.unneeded,
2705427072 panic_messages_ty.getNamespaceIndex(mod),
27055 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls),
27073 try mod.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls),
2705627074 ) catch |err| switch (err) {
2705727075 error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"),
2705827076 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
......@@ -31745,7 +31763,7 @@ fn coerceTupleToStruct(
3174531763 .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0)
3174631764 anon_struct_type.names.get(ip)[tuple_field_index]
3174731765 else
31748 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{tuple_field_index}, .no_embedded_nulls),
31766 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{tuple_field_index}, .no_embedded_nulls),
3174931767 .struct_type => ip.loadStructType(inst_ty.toIntern()).field_names.get(ip)[tuple_field_index],
3175031768 else => unreachable,
3175131769 };
......@@ -31858,13 +31876,13 @@ fn coerceTupleToTuple(
3185831876 .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0)
3185931877 anon_struct_type.names.get(ip)[field_i]
3186031878 else
31861 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls),
31879 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_i}, .no_embedded_nulls),
3186231880 .struct_type => s: {
3186331881 const struct_type = ip.loadStructType(inst_ty.toIntern());
3186431882 if (struct_type.field_names.len > 0) {
3186531883 break :s struct_type.field_names.get(ip)[field_i];
3186631884 } else {
31867 break :s try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls);
31885 break :s try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_i}, .no_embedded_nulls);
3186831886 }
3186931887 },
3187031888 else => unreachable,
......@@ -34849,7 +34867,7 @@ fn resolvePeerTypesInner(
3484934867 const result_buf = try sema.arena.create(PeerResolveResult);
3485034868 result_buf.* = result;
3485134869 const field_name = if (is_tuple)
34852 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_index}, .no_embedded_nulls)
34870 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls)
3485334871 else
3485434872 field_names[field_index];
3485534873
......@@ -36066,7 +36084,7 @@ fn semaStructFields(
3606636084
3606736085 // This string needs to outlive the ZIR code.
3606836086 if (opt_field_name_zir) |field_name_zir| {
36069 const field_name = try ip.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
36087 const field_name = try ip.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls);
3607036088 assert(struct_type.addFieldName(ip, field_name) == null);
3607136089 }
3607236090
......@@ -36567,7 +36585,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3656736585 }
3656836586
3656936587 // This string needs to outlive the ZIR code.
36570 const field_name = try ip.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
36588 const field_name = try ip.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls);
3657136589 if (enum_field_names.len != 0) {
3657236590 enum_field_names[field_i] = field_name;
3657336591 }
......@@ -36716,9 +36734,10 @@ fn generateUnionTagTypeNumbered(
3671636734
3671736735 const new_decl_index = try mod.allocateNewDecl(block.namespace);
3671836736 errdefer mod.destroyDecl(new_decl_index);
36719 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36737 const fqn = try union_owner_decl.fullyQualifiedName(pt);
3672036738 const name = try ip.getOrPutStringFmt(
3672136739 gpa,
36740 pt.tid,
3672236741 "@typeInfo({}).Union.tag_type.?",
3672336742 .{fqn.fmt(ip)},
3672436743 .no_embedded_nulls,
......@@ -36764,11 +36783,12 @@ fn generateUnionTagTypeSimple(
3676436783 const gpa = sema.gpa;
3676536784
3676636785 const new_decl_index = new_decl_index: {
36767 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36786 const fqn = try union_owner_decl.fullyQualifiedName(pt);
3676836787 const new_decl_index = try mod.allocateNewDecl(block.namespace);
3676936788 errdefer mod.destroyDecl(new_decl_index);
3677036789 const name = try ip.getOrPutStringFmt(
3677136790 gpa,
36791 pt.tid,
3677236792 "@typeInfo({}).Union.tag_type.?",
3677336793 .{fqn.fmt(ip)},
3677436794 .no_embedded_nulls,
src/Value.zig+2-2
......@@ -67,7 +67,7 @@ pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTermi
6767 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(pt));
6868 const len: usize = @intCast(ty.arrayLen(mod));
6969 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);
70 return ip.getOrPutTrailingString(mod.gpa, len, .no_embedded_nulls);
70 return ip.getOrPutTrailingString(mod.gpa, pt.tid, len, .no_embedded_nulls);
7171 },
7272 }
7373}
......@@ -118,7 +118,7 @@ fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.Null
118118 const byte: u8 = @intCast(elem_val.toUnsignedInt(pt));
119119 ip.string_bytes.appendAssumeCapacity(byte);
120120 }
121 return ip.getOrPutTrailingString(gpa, len, .no_embedded_nulls);
121 return ip.getOrPutTrailingString(gpa, pt.tid, len, .no_embedded_nulls);
122122}
123123
124124pub fn fromInterned(i: InternPool.Index) Value {
src/Zcu.zig+13-674
......@@ -420,11 +420,11 @@ pub const Decl = struct {
420420 return zcu.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(zcu, decl.name, writer);
421421 }
422422
423 pub fn fullyQualifiedName(decl: Decl, zcu: *Zcu) !InternPool.NullTerminatedString {
423 pub fn fullyQualifiedName(decl: Decl, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
424424 return if (decl.name_fully_qualified)
425425 decl.name
426426 else
427 zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(zcu, decl.name);
427 pt.zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(pt, decl.name);
428428 }
429429
430430 pub fn typeOf(decl: Decl, zcu: *const Zcu) Type {
......@@ -688,9 +688,10 @@ pub const Namespace = struct {
688688
689689 pub fn fullyQualifiedName(
690690 ns: Namespace,
691 zcu: *Zcu,
691 pt: Zcu.PerThread,
692692 name: InternPool.NullTerminatedString,
693693 ) !InternPool.NullTerminatedString {
694 const zcu = pt.zcu;
694695 const ip = &zcu.intern_pool;
695696 const count = count: {
696697 var count: usize = name.length(ip) + 1;
......@@ -723,7 +724,7 @@ pub const Namespace = struct {
723724 };
724725 }
725726
726 return ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start, .no_embedded_nulls);
727 return ip.getOrPutTrailingString(gpa, pt.tid, ip.string_bytes.items.len - start, .no_embedded_nulls);
727728 }
728729
729730 pub fn getType(ns: Namespace, zcu: *Zcu) Type {
......@@ -875,11 +876,12 @@ pub const File = struct {
875876 };
876877 }
877878
878 pub fn fullyQualifiedName(file: File, mod: *Module) !InternPool.NullTerminatedString {
879 const ip = &mod.intern_pool;
879 pub fn fullyQualifiedName(file: File, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
880 const gpa = pt.zcu.gpa;
881 const ip = &pt.zcu.intern_pool;
880882 const start = ip.string_bytes.items.len;
881 try file.renderFullyQualifiedName(ip.string_bytes.writer(mod.gpa));
882 return ip.getOrPutTrailingString(mod.gpa, ip.string_bytes.items.len - start, .no_embedded_nulls);
883 try file.renderFullyQualifiedName(ip.string_bytes.writer(gpa));
884 return ip.getOrPutTrailingString(gpa, pt.tid, ip.string_bytes.items.len - start, .no_embedded_nulls);
883885 }
884886
885887 pub fn fullPath(file: File, ally: Allocator) ![]u8 {
......@@ -2569,8 +2571,8 @@ pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool {
25692571}
25702572
25712573// TODO https://github.com/ziglang/zig/issues/8643
2572const data_has_safety_tag = @sizeOf(Zir.Inst.Data) != 8;
2573const HackDataLayout = extern struct {
2574pub const data_has_safety_tag = @sizeOf(Zir.Inst.Data) != 8;
2575pub const HackDataLayout = extern struct {
25742576 data: [8]u8 align(@alignOf(Zir.Inst.Data)),
25752577 safety_tag: u8,
25762578};
......@@ -2580,291 +2582,11 @@ comptime {
25802582 }
25812583}
25822584
2583pub fn astGenFile(
2584 zcu: *Zcu,
2585 file: *File,
2586 /// This parameter is provided separately from `file` because it is not
2587 /// safe to access `import_table` without a lock, and this index is needed
2588 /// in the call to `updateZirRefs`.
2589 file_index: File.Index,
2590 path_digest: Cache.BinDigest,
2591 opt_root_decl: Zcu.Decl.OptionalIndex,
2592) !void {
2593 assert(!file.mod.isBuiltin());
2594
2595 const tracy = trace(@src());
2596 defer tracy.end();
2597
2598 const comp = zcu.comp;
2599 const gpa = zcu.gpa;
2600
2601 // In any case we need to examine the stat of the file to determine the course of action.
2602 var source_file = try file.mod.root.openFile(file.sub_file_path, .{});
2603 defer source_file.close();
2604
2605 const stat = try source_file.stat();
2606
2607 const want_local_cache = file.mod == zcu.main_mod;
2608 const hex_digest = Cache.binToHex(path_digest);
2609 const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache;
2610 const zir_dir = cache_directory.handle;
2611
2612 // Determine whether we need to reload the file from disk and redo parsing and AstGen.
2613 var lock: std.fs.File.Lock = switch (file.status) {
2614 .never_loaded, .retryable_failure => lock: {
2615 // First, load the cached ZIR code, if any.
2616 log.debug("AstGen checking cache: {s} (local={}, digest={s})", .{
2617 file.sub_file_path, want_local_cache, &hex_digest,
2618 });
2619
2620 break :lock .shared;
2621 },
2622 .parse_failure, .astgen_failure, .success_zir => lock: {
2623 const unchanged_metadata =
2624 stat.size == file.stat.size and
2625 stat.mtime == file.stat.mtime and
2626 stat.inode == file.stat.inode;
2627
2628 if (unchanged_metadata) {
2629 log.debug("unmodified metadata of file: {s}", .{file.sub_file_path});
2630 return;
2631 }
2632
2633 log.debug("metadata changed: {s}", .{file.sub_file_path});
2634
2635 break :lock .exclusive;
2636 },
2637 };
2638
2639 // We ask for a lock in order to coordinate with other zig processes.
2640 // If another process is already working on this file, we will get the cached
2641 // version. Likewise if we're working on AstGen and another process asks for
2642 // the cached file, they'll get it.
2643 const cache_file = while (true) {
2644 break zir_dir.createFile(&hex_digest, .{
2645 .read = true,
2646 .truncate = false,
2647 .lock = lock,
2648 }) catch |err| switch (err) {
2649 error.NotDir => unreachable, // no dir components
2650 error.InvalidUtf8 => unreachable, // it's a hex encoded name
2651 error.InvalidWtf8 => unreachable, // it's a hex encoded name
2652 error.BadPathName => unreachable, // it's a hex encoded name
2653 error.NameTooLong => unreachable, // it's a fixed size name
2654 error.PipeBusy => unreachable, // it's not a pipe
2655 error.WouldBlock => unreachable, // not asking for non-blocking I/O
2656 // There are no dir components, so you would think that this was
2657 // unreachable, however we have observed on macOS two processes racing
2658 // to do openat() with O_CREAT manifest in ENOENT.
2659 error.FileNotFound => continue,
2660
2661 else => |e| return e, // Retryable errors are handled at callsite.
2662 };
2663 };
2664 defer cache_file.close();
2665
2666 while (true) {
2667 update: {
2668 // First we read the header to determine the lengths of arrays.
2669 const header = cache_file.reader().readStruct(Zir.Header) catch |err| switch (err) {
2670 // This can happen if Zig bails out of this function between creating
2671 // the cached file and writing it.
2672 error.EndOfStream => break :update,
2673 else => |e| return e,
2674 };
2675 const unchanged_metadata =
2676 stat.size == header.stat_size and
2677 stat.mtime == header.stat_mtime and
2678 stat.inode == header.stat_inode;
2679
2680 if (!unchanged_metadata) {
2681 log.debug("AstGen cache stale: {s}", .{file.sub_file_path});
2682 break :update;
2683 }
2684 log.debug("AstGen cache hit: {s} instructions_len={d}", .{
2685 file.sub_file_path, header.instructions_len,
2686 });
2687
2688 file.zir = loadZirCacheBody(gpa, header, cache_file) catch |err| switch (err) {
2689 error.UnexpectedFileSize => {
2690 log.warn("unexpected EOF reading cached ZIR for {s}", .{file.sub_file_path});
2691 break :update;
2692 },
2693 else => |e| return e,
2694 };
2695 file.zir_loaded = true;
2696 file.stat = .{
2697 .size = header.stat_size,
2698 .inode = header.stat_inode,
2699 .mtime = header.stat_mtime,
2700 };
2701 file.status = .success_zir;
2702 log.debug("AstGen cached success: {s}", .{file.sub_file_path});
2703
2704 // TODO don't report compile errors until Sema @importFile
2705 if (file.zir.hasCompileErrors()) {
2706 {
2707 comp.mutex.lock();
2708 defer comp.mutex.unlock();
2709 try zcu.failed_files.putNoClobber(gpa, file, null);
2710 }
2711 file.status = .astgen_failure;
2712 return error.AnalysisFail;
2713 }
2714 return;
2715 }
2716
2717 // If we already have the exclusive lock then it is our job to update.
2718 if (builtin.os.tag == .wasi or lock == .exclusive) break;
2719 // Otherwise, unlock to give someone a chance to get the exclusive lock
2720 // and then upgrade to an exclusive lock.
2721 cache_file.unlock();
2722 lock = .exclusive;
2723 try cache_file.lock(lock);
2724 }
2725
2726 // The cache is definitely stale so delete the contents to avoid an underwrite later.
2727 cache_file.setEndPos(0) catch |err| switch (err) {
2728 error.FileTooBig => unreachable, // 0 is not too big
2729
2730 else => |e| return e,
2731 };
2732
2733 zcu.lockAndClearFileCompileError(file);
2734
2735 // If the previous ZIR does not have compile errors, keep it around
2736 // in case parsing or new ZIR fails. In case of successful ZIR update
2737 // at the end of this function we will free it.
2738 // We keep the previous ZIR loaded so that we can use it
2739 // for the update next time it does not have any compile errors. This avoids
2740 // needlessly tossing out semantic analysis work when an error is
2741 // temporarily introduced.
2742 if (file.zir_loaded and !file.zir.hasCompileErrors()) {
2743 assert(file.prev_zir == null);
2744 const prev_zir_ptr = try gpa.create(Zir);
2745 file.prev_zir = prev_zir_ptr;
2746 prev_zir_ptr.* = file.zir;
2747 file.zir = undefined;
2748 file.zir_loaded = false;
2749 }
2750 file.unload(gpa);
2751
2752 if (stat.size > std.math.maxInt(u32))
2753 return error.FileTooBig;
2754
2755 const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0);
2756 defer if (!file.source_loaded) gpa.free(source);
2757 const amt = try source_file.readAll(source);
2758 if (amt != stat.size)
2759 return error.UnexpectedEndOfFile;
2760
2761 file.stat = .{
2762 .size = stat.size,
2763 .inode = stat.inode,
2764 .mtime = stat.mtime,
2765 };
2766 file.source = source;
2767 file.source_loaded = true;
2768
2769 file.tree = try Ast.parse(gpa, source, .zig);
2770 file.tree_loaded = true;
2771
2772 // Any potential AST errors are converted to ZIR errors here.
2773 file.zir = try AstGen.generate(gpa, file.tree);
2774 file.zir_loaded = true;
2775 file.status = .success_zir;
2776 log.debug("AstGen fresh success: {s}", .{file.sub_file_path});
2777
2778 const safety_buffer = if (data_has_safety_tag)
2779 try gpa.alloc([8]u8, file.zir.instructions.len)
2780 else
2781 undefined;
2782 defer if (data_has_safety_tag) gpa.free(safety_buffer);
2783 const data_ptr = if (data_has_safety_tag)
2784 if (file.zir.instructions.len == 0)
2785 @as([*]const u8, undefined)
2786 else
2787 @as([*]const u8, @ptrCast(safety_buffer.ptr))
2788 else
2789 @as([*]const u8, @ptrCast(file.zir.instructions.items(.data).ptr));
2790 if (data_has_safety_tag) {
2791 // The `Data` union has a safety tag but in the file format we store it without.
2792 for (file.zir.instructions.items(.data), 0..) |*data, i| {
2793 const as_struct = @as(*const HackDataLayout, @ptrCast(data));
2794 safety_buffer[i] = as_struct.data;
2795 }
2796 }
2797
2798 const header: Zir.Header = .{
2799 .instructions_len = @as(u32, @intCast(file.zir.instructions.len)),
2800 .string_bytes_len = @as(u32, @intCast(file.zir.string_bytes.len)),
2801 .extra_len = @as(u32, @intCast(file.zir.extra.len)),
2802
2803 .stat_size = stat.size,
2804 .stat_inode = stat.inode,
2805 .stat_mtime = stat.mtime,
2806 };
2807 var iovecs = [_]std.posix.iovec_const{
2808 .{
2809 .base = @as([*]const u8, @ptrCast(&header)),
2810 .len = @sizeOf(Zir.Header),
2811 },
2812 .{
2813 .base = @as([*]const u8, @ptrCast(file.zir.instructions.items(.tag).ptr)),
2814 .len = file.zir.instructions.len,
2815 },
2816 .{
2817 .base = data_ptr,
2818 .len = file.zir.instructions.len * 8,
2819 },
2820 .{
2821 .base = file.zir.string_bytes.ptr,
2822 .len = file.zir.string_bytes.len,
2823 },
2824 .{
2825 .base = @as([*]const u8, @ptrCast(file.zir.extra.ptr)),
2826 .len = file.zir.extra.len * 4,
2827 },
2828 };
2829 cache_file.writevAll(&iovecs) catch |err| {
2830 log.warn("unable to write cached ZIR code for {}{s} to {}{s}: {s}", .{
2831 file.mod.root, file.sub_file_path, cache_directory, &hex_digest, @errorName(err),
2832 });
2833 };
2834
2835 if (file.zir.hasCompileErrors()) {
2836 {
2837 comp.mutex.lock();
2838 defer comp.mutex.unlock();
2839 try zcu.failed_files.putNoClobber(gpa, file, null);
2840 }
2841 file.status = .astgen_failure;
2842 return error.AnalysisFail;
2843 }
2844
2845 if (file.prev_zir) |prev_zir| {
2846 try updateZirRefs(zcu, file, file_index, prev_zir.*);
2847 // No need to keep previous ZIR.
2848 prev_zir.deinit(gpa);
2849 gpa.destroy(prev_zir);
2850 file.prev_zir = null;
2851 }
2852
2853 if (opt_root_decl.unwrap()) |root_decl| {
2854 // The root of this file must be re-analyzed, since the file has changed.
2855 comp.mutex.lock();
2856 defer comp.mutex.unlock();
2857
2858 log.debug("outdated root Decl: {}", .{root_decl});
2859 try zcu.outdated_file_root.put(gpa, root_decl, {});
2860 }
2861}
2862
28632585pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir {
28642586 return loadZirCacheBody(gpa, try cache_file.reader().readStruct(Zir.Header), cache_file);
28652587}
28662588
2867fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) !Zir {
2589pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) !Zir {
28682590 var instructions: std.MultiArrayList(Zir.Inst) = .{};
28692591 errdefer instructions.deinit(gpa);
28702592
......@@ -2930,127 +2652,6 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)
29302652 return zir;
29312653}
29322654
2933/// This is called from the AstGen thread pool, so must acquire
2934/// the Compilation mutex when acting on shared state.
2935fn updateZirRefs(zcu: *Module, file: *File, file_index: File.Index, old_zir: Zir) !void {
2936 const gpa = zcu.gpa;
2937 const new_zir = file.zir;
2938
2939 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{};
2940 defer inst_map.deinit(gpa);
2941
2942 try mapOldZirToNew(gpa, old_zir, new_zir, &inst_map);
2943
2944 const old_tag = old_zir.instructions.items(.tag);
2945 const old_data = old_zir.instructions.items(.data);
2946
2947 // TODO: this should be done after all AstGen workers complete, to avoid
2948 // iterating over this full set for every updated file.
2949 for (zcu.intern_pool.tracked_insts.keys(), 0..) |*ti, idx_raw| {
2950 const ti_idx: InternPool.TrackedInst.Index = @enumFromInt(idx_raw);
2951 if (ti.file != file_index) continue;
2952 const old_inst = ti.inst;
2953 ti.inst = inst_map.get(ti.inst) orelse {
2954 // Tracking failed for this instruction. Invalidate associated `src_hash` deps.
2955 zcu.comp.mutex.lock();
2956 defer zcu.comp.mutex.unlock();
2957 log.debug("tracking failed for %{d}", .{old_inst});
2958 try zcu.markDependeeOutdated(.{ .src_hash = ti_idx });
2959 continue;
2960 };
2961
2962 if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: {
2963 if (new_zir.getAssociatedSrcHash(ti.inst)) |new_hash| {
2964 if (std.zig.srcHashEql(old_hash, new_hash)) {
2965 break :hash_changed;
2966 }
2967 log.debug("hash for (%{d} -> %{d}) changed: {} -> {}", .{
2968 old_inst,
2969 ti.inst,
2970 std.fmt.fmtSliceHexLower(&old_hash),
2971 std.fmt.fmtSliceHexLower(&new_hash),
2972 });
2973 }
2974 // The source hash associated with this instruction changed - invalidate relevant dependencies.
2975 zcu.comp.mutex.lock();
2976 defer zcu.comp.mutex.unlock();
2977 try zcu.markDependeeOutdated(.{ .src_hash = ti_idx });
2978 }
2979
2980 // If this is a `struct_decl` etc, we must invalidate any outdated namespace dependencies.
2981 const has_namespace = switch (old_tag[@intFromEnum(old_inst)]) {
2982 .extended => switch (old_data[@intFromEnum(old_inst)].extended.opcode) {
2983 .struct_decl, .union_decl, .opaque_decl, .enum_decl => true,
2984 else => false,
2985 },
2986 else => false,
2987 };
2988 if (!has_namespace) continue;
2989
2990 var old_names: std.AutoArrayHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{};
2991 defer old_names.deinit(zcu.gpa);
2992 {
2993 var it = old_zir.declIterator(old_inst);
2994 while (it.next()) |decl_inst| {
2995 const decl_name = old_zir.getDeclaration(decl_inst)[0].name;
2996 switch (decl_name) {
2997 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue,
2998 _ => if (decl_name.isNamedTest(old_zir)) continue,
2999 }
3000 const name_zir = decl_name.toString(old_zir).?;
3001 const name_ip = try zcu.intern_pool.getOrPutString(
3002 zcu.gpa,
3003 old_zir.nullTerminatedString(name_zir),
3004 .no_embedded_nulls,
3005 );
3006 try old_names.put(zcu.gpa, name_ip, {});
3007 }
3008 }
3009 var any_change = false;
3010 {
3011 var it = new_zir.declIterator(ti.inst);
3012 while (it.next()) |decl_inst| {
3013 const decl_name = old_zir.getDeclaration(decl_inst)[0].name;
3014 switch (decl_name) {
3015 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue,
3016 _ => if (decl_name.isNamedTest(old_zir)) continue,
3017 }
3018 const name_zir = decl_name.toString(old_zir).?;
3019 const name_ip = try zcu.intern_pool.getOrPutString(
3020 zcu.gpa,
3021 old_zir.nullTerminatedString(name_zir),
3022 .no_embedded_nulls,
3023 );
3024 if (!old_names.swapRemove(name_ip)) continue;
3025 // Name added
3026 any_change = true;
3027 zcu.comp.mutex.lock();
3028 defer zcu.comp.mutex.unlock();
3029 try zcu.markDependeeOutdated(.{ .namespace_name = .{
3030 .namespace = ti_idx,
3031 .name = name_ip,
3032 } });
3033 }
3034 }
3035 // The only elements remaining in `old_names` now are any names which were removed.
3036 for (old_names.keys()) |name_ip| {
3037 any_change = true;
3038 zcu.comp.mutex.lock();
3039 defer zcu.comp.mutex.unlock();
3040 try zcu.markDependeeOutdated(.{ .namespace_name = .{
3041 .namespace = ti_idx,
3042 .name = name_ip,
3043 } });
3044 }
3045
3046 if (any_change) {
3047 zcu.comp.mutex.lock();
3048 defer zcu.comp.mutex.unlock();
3049 try zcu.markDependeeOutdated(.{ .namespace = ti_idx });
3050 }
3051 }
3052}
3053
30542655pub fn markDependeeOutdated(zcu: *Zcu, dependee: InternPool.Dependee) !void {
30552656 log.debug("outdated dependee: {}", .{dependee});
30562657 var it = zcu.intern_pool.dependencyIterator(dependee);
......@@ -3695,268 +3296,6 @@ fn computePathDigest(zcu: *Zcu, mod: *Package.Module, sub_file_path: []const u8)
36953296 return bin;
36963297}
36973298
3698pub fn scanNamespace(
3699 zcu: *Zcu,
3700 namespace_index: Namespace.Index,
3701 decls: []const Zir.Inst.Index,
3702 parent_decl: *Decl,
3703) Allocator.Error!void {
3704 const tracy = trace(@src());
3705 defer tracy.end();
3706
3707 const gpa = zcu.gpa;
3708 const namespace = zcu.namespacePtr(namespace_index);
3709
3710 // For incremental updates, `scanDecl` wants to look up existing decls by their ZIR index rather
3711 // than their name. We'll build an efficient mapping now, then discard the current `decls`.
3712 var existing_by_inst: std.AutoHashMapUnmanaged(InternPool.TrackedInst.Index, Decl.Index) = .{};
3713 defer existing_by_inst.deinit(gpa);
3714
3715 try existing_by_inst.ensureTotalCapacity(gpa, @intCast(namespace.decls.count()));
3716
3717 for (namespace.decls.keys()) |decl_index| {
3718 const decl = zcu.declPtr(decl_index);
3719 existing_by_inst.putAssumeCapacityNoClobber(decl.zir_decl_index.unwrap().?, decl_index);
3720 }
3721
3722 var seen_decls: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{};
3723 defer seen_decls.deinit(gpa);
3724
3725 try zcu.comp.work_queue.ensureUnusedCapacity(decls.len);
3726
3727 namespace.decls.clearRetainingCapacity();
3728 try namespace.decls.ensureTotalCapacity(gpa, decls.len);
3729
3730 namespace.usingnamespace_set.clearRetainingCapacity();
3731
3732 var scan_decl_iter: ScanDeclIter = .{
3733 .zcu = zcu,
3734 .namespace_index = namespace_index,
3735 .parent_decl = parent_decl,
3736 .seen_decls = &seen_decls,
3737 .existing_by_inst = &existing_by_inst,
3738 .pass = .named,
3739 };
3740 for (decls) |decl_inst| {
3741 try scanDecl(&scan_decl_iter, decl_inst);
3742 }
3743 scan_decl_iter.pass = .unnamed;
3744 for (decls) |decl_inst| {
3745 try scanDecl(&scan_decl_iter, decl_inst);
3746 }
3747
3748 if (seen_decls.count() != namespace.decls.count()) {
3749 // Do a pass over the namespace contents and remove any decls from the last update
3750 // which were removed in this one.
3751 var i: usize = 0;
3752 while (i < namespace.decls.count()) {
3753 const decl_index = namespace.decls.keys()[i];
3754 const decl = zcu.declPtr(decl_index);
3755 if (!seen_decls.contains(decl.name)) {
3756 // We must preserve namespace ordering for @typeInfo.
3757 namespace.decls.orderedRemoveAt(i);
3758 i -= 1;
3759 }
3760 }
3761 }
3762}
3763
3764const ScanDeclIter = struct {
3765 zcu: *Zcu,
3766 namespace_index: Namespace.Index,
3767 parent_decl: *Decl,
3768 seen_decls: *std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void),
3769 existing_by_inst: *const std.AutoHashMapUnmanaged(InternPool.TrackedInst.Index, Decl.Index),
3770 /// Decl scanning is run in two passes, so that we can detect when a generated
3771 /// name would clash with an explicit name and use a different one.
3772 pass: enum { named, unnamed },
3773 usingnamespace_index: usize = 0,
3774 comptime_index: usize = 0,
3775 unnamed_test_index: usize = 0,
3776
3777 fn avoidNameConflict(iter: *ScanDeclIter, comptime fmt: []const u8, args: anytype) !InternPool.NullTerminatedString {
3778 const zcu = iter.zcu;
3779 const gpa = zcu.gpa;
3780 const ip = &zcu.intern_pool;
3781 var name = try ip.getOrPutStringFmt(gpa, fmt, args, .no_embedded_nulls);
3782 var gop = try iter.seen_decls.getOrPut(gpa, name);
3783 var next_suffix: u32 = 0;
3784 while (gop.found_existing) {
3785 name = try ip.getOrPutStringFmt(gpa, "{}_{d}", .{ name.fmt(ip), next_suffix }, .no_embedded_nulls);
3786 gop = try iter.seen_decls.getOrPut(gpa, name);
3787 next_suffix += 1;
3788 }
3789 return name;
3790 }
3791};
3792
3793fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void {
3794 const tracy = trace(@src());
3795 defer tracy.end();
3796
3797 const zcu = iter.zcu;
3798 const namespace_index = iter.namespace_index;
3799 const namespace = zcu.namespacePtr(namespace_index);
3800 const gpa = zcu.gpa;
3801 const zir = namespace.fileScope(zcu).zir;
3802 const ip = &zcu.intern_pool;
3803
3804 const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration;
3805 const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index);
3806 const declaration = extra.data;
3807
3808 // Every Decl needs a name.
3809 const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) {
3810 .@"comptime" => info: {
3811 if (iter.pass != .unnamed) return;
3812 const i = iter.comptime_index;
3813 iter.comptime_index += 1;
3814 break :info .{
3815 try iter.avoidNameConflict("comptime_{d}", .{i}),
3816 .@"comptime",
3817 false,
3818 };
3819 },
3820 .@"usingnamespace" => info: {
3821 // TODO: this isn't right! These should be considered unnamed. Name conflicts can happen here.
3822 // The problem is, we need to preserve the decl ordering for `@typeInfo`.
3823 // I'm not bothering to fix this now, since some upcoming changes will change this code significantly anyway.
3824 if (iter.pass != .named) return;
3825 const i = iter.usingnamespace_index;
3826 iter.usingnamespace_index += 1;
3827 break :info .{
3828 try iter.avoidNameConflict("usingnamespace_{d}", .{i}),
3829 .@"usingnamespace",
3830 false,
3831 };
3832 },
3833 .unnamed_test => info: {
3834 if (iter.pass != .unnamed) return;
3835 const i = iter.unnamed_test_index;
3836 iter.unnamed_test_index += 1;
3837 break :info .{
3838 try iter.avoidNameConflict("test_{d}", .{i}),
3839 .@"test",
3840 false,
3841 };
3842 },
3843 .decltest => info: {
3844 // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary.
3845 if (iter.pass != .unnamed) return;
3846 assert(declaration.flags.has_doc_comment);
3847 const name = zir.nullTerminatedString(@enumFromInt(zir.extra[extra.end]));
3848 break :info .{
3849 try iter.avoidNameConflict("decltest.{s}", .{name}),
3850 .@"test",
3851 true,
3852 };
3853 },
3854 _ => if (declaration.name.isNamedTest(zir)) info: {
3855 // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary.
3856 if (iter.pass != .unnamed) return;
3857 break :info .{
3858 try iter.avoidNameConflict("test.{s}", .{zir.nullTerminatedString(declaration.name.toString(zir).?)}),
3859 .@"test",
3860 true,
3861 };
3862 } else info: {
3863 if (iter.pass != .named) return;
3864 const name = try ip.getOrPutString(
3865 gpa,
3866 zir.nullTerminatedString(declaration.name.toString(zir).?),
3867 .no_embedded_nulls,
3868 );
3869 try iter.seen_decls.putNoClobber(gpa, name, {});
3870 break :info .{
3871 name,
3872 .named,
3873 false,
3874 };
3875 },
3876 };
3877
3878 switch (kind) {
3879 .@"usingnamespace" => try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1),
3880 .@"test" => try zcu.test_functions.ensureUnusedCapacity(gpa, 1),
3881 else => {},
3882 }
3883
3884 const parent_file_scope_index = iter.parent_decl.getFileScopeIndex(zcu);
3885 const tracked_inst = try ip.trackZir(gpa, parent_file_scope_index, decl_inst);
3886
3887 // We create a Decl for it regardless of analysis status.
3888
3889 const prev_exported, const decl_index = if (iter.existing_by_inst.get(tracked_inst)) |decl_index| decl_index: {
3890 // We need only update this existing Decl.
3891 const decl = zcu.declPtr(decl_index);
3892 const was_exported = decl.is_exported;
3893 assert(decl.kind == kind); // ZIR tracking should preserve this
3894 decl.name = decl_name;
3895 decl.is_pub = declaration.flags.is_pub;
3896 decl.is_exported = declaration.flags.is_export;
3897 break :decl_index .{ was_exported, decl_index };
3898 } else decl_index: {
3899 // Create and set up a new Decl.
3900 const new_decl_index = try zcu.allocateNewDecl(namespace_index);
3901 const new_decl = zcu.declPtr(new_decl_index);
3902 new_decl.kind = kind;
3903 new_decl.name = decl_name;
3904 new_decl.is_pub = declaration.flags.is_pub;
3905 new_decl.is_exported = declaration.flags.is_export;
3906 new_decl.zir_decl_index = tracked_inst.toOptional();
3907 break :decl_index .{ false, new_decl_index };
3908 };
3909
3910 const decl = zcu.declPtr(decl_index);
3911
3912 namespace.decls.putAssumeCapacityNoClobberContext(decl_index, {}, .{ .zcu = zcu });
3913
3914 const comp = zcu.comp;
3915 const decl_mod = namespace.fileScope(zcu).mod;
3916 const want_analysis = declaration.flags.is_export or switch (kind) {
3917 .anon => unreachable,
3918 .@"comptime" => true,
3919 .@"usingnamespace" => a: {
3920 namespace.usingnamespace_set.putAssumeCapacityNoClobber(decl_index, declaration.flags.is_pub);
3921 break :a true;
3922 },
3923 .named => false,
3924 .@"test" => a: {
3925 if (!comp.config.is_test) break :a false;
3926 if (decl_mod != zcu.main_mod) break :a false;
3927 if (is_named_test and comp.test_filters.len > 0) {
3928 const decl_fqn = try namespace.fullyQualifiedName(zcu, decl_name);
3929 const decl_fqn_slice = decl_fqn.toSlice(ip);
3930 for (comp.test_filters) |test_filter| {
3931 if (mem.indexOf(u8, decl_fqn_slice, test_filter)) |_| break;
3932 } else break :a false;
3933 }
3934 zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update
3935 break :a true;
3936 },
3937 };
3938
3939 if (want_analysis) {
3940 // We will not queue analysis if the decl has been analyzed on a previous update and
3941 // `is_export` is unchanged. In this case, the incremental update mechanism will handle
3942 // re-analysis for us if necessary.
3943 if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) {
3944 log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{
3945 namespace.fileScope(zcu).sub_file_path, decl_name.fmt(ip), decl_index,
3946 });
3947 comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index });
3948 }
3949 }
3950
3951 if (decl.getOwnedFunction(zcu) != null) {
3952 // TODO this logic is insufficient; namespaces we don't re-scan may still require
3953 // updated line numbers. Look into this!
3954 // TODO Look into detecting when this would be unnecessary by storing enough state
3955 // in `Decl` to notice that the line number did not change.
3956 comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
3957 }
3958}
3959
39603299/// Cancel the creation of an anon decl and delete any references to it.
39613300/// If other decls depend on this decl, they must be aborted first.
39623301pub fn abortAnonDecl(mod: *Module, decl_index: Decl.Index) void {
src/Zcu/PerThread.zig+705-20
......@@ -5,6 +5,411 @@ tid: Id,
55
66pub const Id = if (builtin.single_threaded) enum { main } else enum(usize) { main, _ };
77
8pub fn astGenFile(
9 pt: Zcu.PerThread,
10 file: *Zcu.File,
11 /// This parameter is provided separately from `file` because it is not
12 /// safe to access `import_table` without a lock, and this index is needed
13 /// in the call to `updateZirRefs`.
14 file_index: Zcu.File.Index,
15 path_digest: Cache.BinDigest,
16 opt_root_decl: Zcu.Decl.OptionalIndex,
17) !void {
18 assert(!file.mod.isBuiltin());
19
20 const tracy = trace(@src());
21 defer tracy.end();
22
23 const zcu = pt.zcu;
24 const comp = zcu.comp;
25 const gpa = zcu.gpa;
26
27 // In any case we need to examine the stat of the file to determine the course of action.
28 var source_file = try file.mod.root.openFile(file.sub_file_path, .{});
29 defer source_file.close();
30
31 const stat = try source_file.stat();
32
33 const want_local_cache = file.mod == zcu.main_mod;
34 const hex_digest = Cache.binToHex(path_digest);
35 const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache;
36 const zir_dir = cache_directory.handle;
37
38 // Determine whether we need to reload the file from disk and redo parsing and AstGen.
39 var lock: std.fs.File.Lock = switch (file.status) {
40 .never_loaded, .retryable_failure => lock: {
41 // First, load the cached ZIR code, if any.
42 log.debug("AstGen checking cache: {s} (local={}, digest={s})", .{
43 file.sub_file_path, want_local_cache, &hex_digest,
44 });
45
46 break :lock .shared;
47 },
48 .parse_failure, .astgen_failure, .success_zir => lock: {
49 const unchanged_metadata =
50 stat.size == file.stat.size and
51 stat.mtime == file.stat.mtime and
52 stat.inode == file.stat.inode;
53
54 if (unchanged_metadata) {
55 log.debug("unmodified metadata of file: {s}", .{file.sub_file_path});
56 return;
57 }
58
59 log.debug("metadata changed: {s}", .{file.sub_file_path});
60
61 break :lock .exclusive;
62 },
63 };
64
65 // We ask for a lock in order to coordinate with other zig processes.
66 // If another process is already working on this file, we will get the cached
67 // version. Likewise if we're working on AstGen and another process asks for
68 // the cached file, they'll get it.
69 const cache_file = while (true) {
70 break zir_dir.createFile(&hex_digest, .{
71 .read = true,
72 .truncate = false,
73 .lock = lock,
74 }) catch |err| switch (err) {
75 error.NotDir => unreachable, // no dir components
76 error.InvalidUtf8 => unreachable, // it's a hex encoded name
77 error.InvalidWtf8 => unreachable, // it's a hex encoded name
78 error.BadPathName => unreachable, // it's a hex encoded name
79 error.NameTooLong => unreachable, // it's a fixed size name
80 error.PipeBusy => unreachable, // it's not a pipe
81 error.WouldBlock => unreachable, // not asking for non-blocking I/O
82 // There are no dir components, so you would think that this was
83 // unreachable, however we have observed on macOS two processes racing
84 // to do openat() with O_CREAT manifest in ENOENT.
85 error.FileNotFound => continue,
86
87 else => |e| return e, // Retryable errors are handled at callsite.
88 };
89 };
90 defer cache_file.close();
91
92 while (true) {
93 update: {
94 // First we read the header to determine the lengths of arrays.
95 const header = cache_file.reader().readStruct(Zir.Header) catch |err| switch (err) {
96 // This can happen if Zig bails out of this function between creating
97 // the cached file and writing it.
98 error.EndOfStream => break :update,
99 else => |e| return e,
100 };
101 const unchanged_metadata =
102 stat.size == header.stat_size and
103 stat.mtime == header.stat_mtime and
104 stat.inode == header.stat_inode;
105
106 if (!unchanged_metadata) {
107 log.debug("AstGen cache stale: {s}", .{file.sub_file_path});
108 break :update;
109 }
110 log.debug("AstGen cache hit: {s} instructions_len={d}", .{
111 file.sub_file_path, header.instructions_len,
112 });
113
114 file.zir = Zcu.loadZirCacheBody(gpa, header, cache_file) catch |err| switch (err) {
115 error.UnexpectedFileSize => {
116 log.warn("unexpected EOF reading cached ZIR for {s}", .{file.sub_file_path});
117 break :update;
118 },
119 else => |e| return e,
120 };
121 file.zir_loaded = true;
122 file.stat = .{
123 .size = header.stat_size,
124 .inode = header.stat_inode,
125 .mtime = header.stat_mtime,
126 };
127 file.status = .success_zir;
128 log.debug("AstGen cached success: {s}", .{file.sub_file_path});
129
130 // TODO don't report compile errors until Sema @importFile
131 if (file.zir.hasCompileErrors()) {
132 {
133 comp.mutex.lock();
134 defer comp.mutex.unlock();
135 try zcu.failed_files.putNoClobber(gpa, file, null);
136 }
137 file.status = .astgen_failure;
138 return error.AnalysisFail;
139 }
140 return;
141 }
142
143 // If we already have the exclusive lock then it is our job to update.
144 if (builtin.os.tag == .wasi or lock == .exclusive) break;
145 // Otherwise, unlock to give someone a chance to get the exclusive lock
146 // and then upgrade to an exclusive lock.
147 cache_file.unlock();
148 lock = .exclusive;
149 try cache_file.lock(lock);
150 }
151
152 // The cache is definitely stale so delete the contents to avoid an underwrite later.
153 cache_file.setEndPos(0) catch |err| switch (err) {
154 error.FileTooBig => unreachable, // 0 is not too big
155
156 else => |e| return e,
157 };
158
159 pt.lockAndClearFileCompileError(file);
160
161 // If the previous ZIR does not have compile errors, keep it around
162 // in case parsing or new ZIR fails. In case of successful ZIR update
163 // at the end of this function we will free it.
164 // We keep the previous ZIR loaded so that we can use it
165 // for the update next time it does not have any compile errors. This avoids
166 // needlessly tossing out semantic analysis work when an error is
167 // temporarily introduced.
168 if (file.zir_loaded and !file.zir.hasCompileErrors()) {
169 assert(file.prev_zir == null);
170 const prev_zir_ptr = try gpa.create(Zir);
171 file.prev_zir = prev_zir_ptr;
172 prev_zir_ptr.* = file.zir;
173 file.zir = undefined;
174 file.zir_loaded = false;
175 }
176 file.unload(gpa);
177
178 if (stat.size > std.math.maxInt(u32))
179 return error.FileTooBig;
180
181 const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0);
182 defer if (!file.source_loaded) gpa.free(source);
183 const amt = try source_file.readAll(source);
184 if (amt != stat.size)
185 return error.UnexpectedEndOfFile;
186
187 file.stat = .{
188 .size = stat.size,
189 .inode = stat.inode,
190 .mtime = stat.mtime,
191 };
192 file.source = source;
193 file.source_loaded = true;
194
195 file.tree = try Ast.parse(gpa, source, .zig);
196 file.tree_loaded = true;
197
198 // Any potential AST errors are converted to ZIR errors here.
199 file.zir = try AstGen.generate(gpa, file.tree);
200 file.zir_loaded = true;
201 file.status = .success_zir;
202 log.debug("AstGen fresh success: {s}", .{file.sub_file_path});
203
204 const safety_buffer = if (Zcu.data_has_safety_tag)
205 try gpa.alloc([8]u8, file.zir.instructions.len)
206 else
207 undefined;
208 defer if (Zcu.data_has_safety_tag) gpa.free(safety_buffer);
209 const data_ptr = if (Zcu.data_has_safety_tag)
210 if (file.zir.instructions.len == 0)
211 @as([*]const u8, undefined)
212 else
213 @as([*]const u8, @ptrCast(safety_buffer.ptr))
214 else
215 @as([*]const u8, @ptrCast(file.zir.instructions.items(.data).ptr));
216 if (Zcu.data_has_safety_tag) {
217 // The `Data` union has a safety tag but in the file format we store it without.
218 for (file.zir.instructions.items(.data), 0..) |*data, i| {
219 const as_struct: *const Zcu.HackDataLayout = @ptrCast(data);
220 safety_buffer[i] = as_struct.data;
221 }
222 }
223
224 const header: Zir.Header = .{
225 .instructions_len = @as(u32, @intCast(file.zir.instructions.len)),
226 .string_bytes_len = @as(u32, @intCast(file.zir.string_bytes.len)),
227 .extra_len = @as(u32, @intCast(file.zir.extra.len)),
228
229 .stat_size = stat.size,
230 .stat_inode = stat.inode,
231 .stat_mtime = stat.mtime,
232 };
233 var iovecs = [_]std.posix.iovec_const{
234 .{
235 .base = @as([*]const u8, @ptrCast(&header)),
236 .len = @sizeOf(Zir.Header),
237 },
238 .{
239 .base = @as([*]const u8, @ptrCast(file.zir.instructions.items(.tag).ptr)),
240 .len = file.zir.instructions.len,
241 },
242 .{
243 .base = data_ptr,
244 .len = file.zir.instructions.len * 8,
245 },
246 .{
247 .base = file.zir.string_bytes.ptr,
248 .len = file.zir.string_bytes.len,
249 },
250 .{
251 .base = @as([*]const u8, @ptrCast(file.zir.extra.ptr)),
252 .len = file.zir.extra.len * 4,
253 },
254 };
255 cache_file.writevAll(&iovecs) catch |err| {
256 log.warn("unable to write cached ZIR code for {}{s} to {}{s}: {s}", .{
257 file.mod.root, file.sub_file_path, cache_directory, &hex_digest, @errorName(err),
258 });
259 };
260
261 if (file.zir.hasCompileErrors()) {
262 {
263 comp.mutex.lock();
264 defer comp.mutex.unlock();
265 try zcu.failed_files.putNoClobber(gpa, file, null);
266 }
267 file.status = .astgen_failure;
268 return error.AnalysisFail;
269 }
270
271 if (file.prev_zir) |prev_zir| {
272 try pt.updateZirRefs(file, file_index, prev_zir.*);
273 // No need to keep previous ZIR.
274 prev_zir.deinit(gpa);
275 gpa.destroy(prev_zir);
276 file.prev_zir = null;
277 }
278
279 if (opt_root_decl.unwrap()) |root_decl| {
280 // The root of this file must be re-analyzed, since the file has changed.
281 comp.mutex.lock();
282 defer comp.mutex.unlock();
283
284 log.debug("outdated root Decl: {}", .{root_decl});
285 try zcu.outdated_file_root.put(gpa, root_decl, {});
286 }
287}
288
289/// This is called from the AstGen thread pool, so must acquire
290/// the Compilation mutex when acting on shared state.
291fn updateZirRefs(pt: Zcu.PerThread, file: *Zcu.File, file_index: Zcu.File.Index, old_zir: Zir) !void {
292 const zcu = pt.zcu;
293 const gpa = zcu.gpa;
294 const new_zir = file.zir;
295
296 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{};
297 defer inst_map.deinit(gpa);
298
299 try Zcu.mapOldZirToNew(gpa, old_zir, new_zir, &inst_map);
300
301 const old_tag = old_zir.instructions.items(.tag);
302 const old_data = old_zir.instructions.items(.data);
303
304 // TODO: this should be done after all AstGen workers complete, to avoid
305 // iterating over this full set for every updated file.
306 for (zcu.intern_pool.tracked_insts.keys(), 0..) |*ti, idx_raw| {
307 const ti_idx: InternPool.TrackedInst.Index = @enumFromInt(idx_raw);
308 if (ti.file != file_index) continue;
309 const old_inst = ti.inst;
310 ti.inst = inst_map.get(ti.inst) orelse {
311 // Tracking failed for this instruction. Invalidate associated `src_hash` deps.
312 zcu.comp.mutex.lock();
313 defer zcu.comp.mutex.unlock();
314 log.debug("tracking failed for %{d}", .{old_inst});
315 try zcu.markDependeeOutdated(.{ .src_hash = ti_idx });
316 continue;
317 };
318
319 if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: {
320 if (new_zir.getAssociatedSrcHash(ti.inst)) |new_hash| {
321 if (std.zig.srcHashEql(old_hash, new_hash)) {
322 break :hash_changed;
323 }
324 log.debug("hash for (%{d} -> %{d}) changed: {} -> {}", .{
325 old_inst,
326 ti.inst,
327 std.fmt.fmtSliceHexLower(&old_hash),
328 std.fmt.fmtSliceHexLower(&new_hash),
329 });
330 }
331 // The source hash associated with this instruction changed - invalidate relevant dependencies.
332 zcu.comp.mutex.lock();
333 defer zcu.comp.mutex.unlock();
334 try zcu.markDependeeOutdated(.{ .src_hash = ti_idx });
335 }
336
337 // If this is a `struct_decl` etc, we must invalidate any outdated namespace dependencies.
338 const has_namespace = switch (old_tag[@intFromEnum(old_inst)]) {
339 .extended => switch (old_data[@intFromEnum(old_inst)].extended.opcode) {
340 .struct_decl, .union_decl, .opaque_decl, .enum_decl => true,
341 else => false,
342 },
343 else => false,
344 };
345 if (!has_namespace) continue;
346
347 var old_names: std.AutoArrayHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{};
348 defer old_names.deinit(zcu.gpa);
349 {
350 var it = old_zir.declIterator(old_inst);
351 while (it.next()) |decl_inst| {
352 const decl_name = old_zir.getDeclaration(decl_inst)[0].name;
353 switch (decl_name) {
354 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue,
355 _ => if (decl_name.isNamedTest(old_zir)) continue,
356 }
357 const name_zir = decl_name.toString(old_zir).?;
358 const name_ip = try zcu.intern_pool.getOrPutString(
359 zcu.gpa,
360 pt.tid,
361 old_zir.nullTerminatedString(name_zir),
362 .no_embedded_nulls,
363 );
364 try old_names.put(zcu.gpa, name_ip, {});
365 }
366 }
367 var any_change = false;
368 {
369 var it = new_zir.declIterator(ti.inst);
370 while (it.next()) |decl_inst| {
371 const decl_name = old_zir.getDeclaration(decl_inst)[0].name;
372 switch (decl_name) {
373 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue,
374 _ => if (decl_name.isNamedTest(old_zir)) continue,
375 }
376 const name_zir = decl_name.toString(old_zir).?;
377 const name_ip = try zcu.intern_pool.getOrPutString(
378 zcu.gpa,
379 pt.tid,
380 old_zir.nullTerminatedString(name_zir),
381 .no_embedded_nulls,
382 );
383 if (!old_names.swapRemove(name_ip)) continue;
384 // Name added
385 any_change = true;
386 zcu.comp.mutex.lock();
387 defer zcu.comp.mutex.unlock();
388 try zcu.markDependeeOutdated(.{ .namespace_name = .{
389 .namespace = ti_idx,
390 .name = name_ip,
391 } });
392 }
393 }
394 // The only elements remaining in `old_names` now are any names which were removed.
395 for (old_names.keys()) |name_ip| {
396 any_change = true;
397 zcu.comp.mutex.lock();
398 defer zcu.comp.mutex.unlock();
399 try zcu.markDependeeOutdated(.{ .namespace_name = .{
400 .namespace = ti_idx,
401 .name = name_ip,
402 } });
403 }
404
405 if (any_change) {
406 zcu.comp.mutex.lock();
407 defer zcu.comp.mutex.unlock();
408 try zcu.markDependeeOutdated(.{ .namespace = ti_idx });
409 }
410 }
411}
412
8413/// Like `ensureDeclAnalyzed`, but the Decl is a file's root Decl.
9414pub fn ensureFileAnalyzed(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void {
10415 if (pt.zcu.fileRootDecl(file_index).unwrap()) |existing_root| {
......@@ -91,7 +496,7 @@ pub fn ensureDeclAnalyzed(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Zcu.Sem
91496 };
92497 }
93498
94 const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(mod)).toSlice(ip), 0);
499 const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0);
95500 defer decl_prog_node.end();
96501
97502 break :blk pt.semaDecl(decl_index) catch |err| switch (err) {
......@@ -290,7 +695,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
290695 defer liveness.deinit(gpa);
291696
292697 if (build_options.enable_debug_extensions and comp.verbose_air) {
293 const fqn = try decl.fullyQualifiedName(zcu);
698 const fqn = try decl.fullyQualifiedName(pt);
294699 std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(ip)});
295700 @import("../print_air.zig").dump(pt, air, liveness);
296701 std.debug.print("# End Function AIR: {}\n\n", .{fqn.fmt(ip)});
......@@ -324,7 +729,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
324729 };
325730 }
326731
327 const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(zcu)).toSlice(ip), 0);
732 const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0);
328733 defer codegen_prog_node.end();
329734
330735 if (!air.typesFullyResolved(zcu)) {
......@@ -434,7 +839,7 @@ fn getFileRootStruct(
434839 decl.owns_tv = true;
435840 decl.analysis = .complete;
436841
437 try zcu.scanNamespace(namespace_index, decls, decl);
842 try pt.scanNamespace(namespace_index, decls, decl);
438843 try zcu.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });
439844 return wip_ty.finish(ip, decl_index, namespace_index.toOptional());
440845}
......@@ -502,7 +907,7 @@ fn semaFileUpdate(pt: Zcu.PerThread, file_index: Zcu.File.Index, type_outdated:
502907 const decls = file.zir.bodySlice(extra_index, decls_len);
503908
504909 if (!type_outdated) {
505 try zcu.scanNamespace(decl.src_namespace, decls, decl);
910 try pt.scanNamespace(decl.src_namespace, decls, decl);
506911 }
507912
508913 return false;
......@@ -539,7 +944,7 @@ fn semaFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void {
539944 zcu.setFileRootDecl(file_index, new_decl_index.toOptional());
540945 zcu.namespacePtr(new_namespace_index).decl_index = new_decl_index;
541946
542 new_decl.name = try file.fullyQualifiedName(zcu);
947 new_decl.name = try file.fullyQualifiedName(pt);
543948 new_decl.name_fully_qualified = true;
544949 new_decl.is_pub = true;
545950 new_decl.is_exported = false;
......@@ -601,9 +1006,9 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
6011006 }
6021007
6031008 log.debug("semaDecl '{d}'", .{@intFromEnum(decl_index)});
604 log.debug("decl name '{}'", .{(try decl.fullyQualifiedName(zcu)).fmt(ip)});
1009 log.debug("decl name '{}'", .{(try decl.fullyQualifiedName(pt)).fmt(ip)});
6051010 defer blk: {
606 log.debug("finish decl name '{}'", .{(decl.fullyQualifiedName(zcu) catch break :blk).fmt(ip)});
1011 log.debug("finish decl name '{}'", .{(decl.fullyQualifiedName(pt) catch break :blk).fmt(ip)});
6071012 }
6081013
6091014 const old_has_tv = decl.has_tv;
......@@ -631,7 +1036,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
6311036 const std_file_root_decl_index = zcu.fileRootDecl(std_file_imported.file_index);
6321037 const std_decl = zcu.declPtr(std_file_root_decl_index.unwrap().?);
6331038 const std_namespace = std_decl.getInnerNamespace(zcu).?;
634 const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls);
1039 const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls);
6351040 const builtin_decl = zcu.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse break :ip_index .none);
6361041 const builtin_namespace = builtin_decl.getInnerNamespaceIndex(zcu).unwrap() orelse break :ip_index .none;
6371042 if (decl.src_namespace != builtin_namespace) break :ip_index .none;
......@@ -802,7 +1207,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
8021207 } else if (bytes.len == 0) {
8031208 return sema.fail(&block_scope, section_src, "linksection cannot be empty", .{});
8041209 }
805 break :blk try ip.getOrPutStringOpt(gpa, bytes, .no_embedded_nulls);
1210 break :blk try ip.getOrPutStringOpt(gpa, pt.tid, bytes, .no_embedded_nulls);
8061211 };
8071212 decl.@"addrspace" = blk: {
8081213 const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_val.toIntern())) {
......@@ -996,7 +1401,7 @@ fn newEmbedFile(
9961401 } });
9971402 const array_val = try pt.intern(.{ .aggregate = .{
9981403 .ty = array_ty,
999 .storage = .{ .bytes = try ip.getOrPutTrailingString(gpa, bytes.len, .maybe_embedded_nulls) },
1404 .storage = .{ .bytes = try ip.getOrPutTrailingString(gpa, pt.tid, bytes.len, .maybe_embedded_nulls) },
10001405 } });
10011406
10021407 const ptr_ty = (try pt.ptrType(.{
......@@ -1018,7 +1423,7 @@ fn newEmbedFile(
10181423
10191424 result.* = new_file;
10201425 new_file.* = .{
1021 .sub_file_path = try ip.getOrPutString(gpa, sub_file_path, .no_embedded_nulls),
1426 .sub_file_path = try ip.getOrPutString(gpa, pt.tid, sub_file_path, .no_embedded_nulls),
10221427 .owner = pkg,
10231428 .stat = stat,
10241429 .val = ptr_val,
......@@ -1027,6 +1432,271 @@ fn newEmbedFile(
10271432 return ptr_val;
10281433}
10291434
1435pub fn scanNamespace(
1436 pt: Zcu.PerThread,
1437 namespace_index: Zcu.Namespace.Index,
1438 decls: []const Zir.Inst.Index,
1439 parent_decl: *Zcu.Decl,
1440) Allocator.Error!void {
1441 const tracy = trace(@src());
1442 defer tracy.end();
1443
1444 const zcu = pt.zcu;
1445 const gpa = zcu.gpa;
1446 const namespace = zcu.namespacePtr(namespace_index);
1447
1448 // For incremental updates, `scanDecl` wants to look up existing decls by their ZIR index rather
1449 // than their name. We'll build an efficient mapping now, then discard the current `decls`.
1450 var existing_by_inst: std.AutoHashMapUnmanaged(InternPool.TrackedInst.Index, Zcu.Decl.Index) = .{};
1451 defer existing_by_inst.deinit(gpa);
1452
1453 try existing_by_inst.ensureTotalCapacity(gpa, @intCast(namespace.decls.count()));
1454
1455 for (namespace.decls.keys()) |decl_index| {
1456 const decl = zcu.declPtr(decl_index);
1457 existing_by_inst.putAssumeCapacityNoClobber(decl.zir_decl_index.unwrap().?, decl_index);
1458 }
1459
1460 var seen_decls: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{};
1461 defer seen_decls.deinit(gpa);
1462
1463 try zcu.comp.work_queue.ensureUnusedCapacity(decls.len);
1464
1465 namespace.decls.clearRetainingCapacity();
1466 try namespace.decls.ensureTotalCapacity(gpa, decls.len);
1467
1468 namespace.usingnamespace_set.clearRetainingCapacity();
1469
1470 var scan_decl_iter: ScanDeclIter = .{
1471 .pt = pt,
1472 .namespace_index = namespace_index,
1473 .parent_decl = parent_decl,
1474 .seen_decls = &seen_decls,
1475 .existing_by_inst = &existing_by_inst,
1476 .pass = .named,
1477 };
1478 for (decls) |decl_inst| {
1479 try scan_decl_iter.scanDecl(decl_inst);
1480 }
1481 scan_decl_iter.pass = .unnamed;
1482 for (decls) |decl_inst| {
1483 try scan_decl_iter.scanDecl(decl_inst);
1484 }
1485
1486 if (seen_decls.count() != namespace.decls.count()) {
1487 // Do a pass over the namespace contents and remove any decls from the last update
1488 // which were removed in this one.
1489 var i: usize = 0;
1490 while (i < namespace.decls.count()) {
1491 const decl_index = namespace.decls.keys()[i];
1492 const decl = zcu.declPtr(decl_index);
1493 if (!seen_decls.contains(decl.name)) {
1494 // We must preserve namespace ordering for @typeInfo.
1495 namespace.decls.orderedRemoveAt(i);
1496 i -= 1;
1497 }
1498 }
1499 }
1500}
1501
1502const ScanDeclIter = struct {
1503 pt: Zcu.PerThread,
1504 namespace_index: Zcu.Namespace.Index,
1505 parent_decl: *Zcu.Decl,
1506 seen_decls: *std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void),
1507 existing_by_inst: *const std.AutoHashMapUnmanaged(InternPool.TrackedInst.Index, Zcu.Decl.Index),
1508 /// Decl scanning is run in two passes, so that we can detect when a generated
1509 /// name would clash with an explicit name and use a different one.
1510 pass: enum { named, unnamed },
1511 usingnamespace_index: usize = 0,
1512 comptime_index: usize = 0,
1513 unnamed_test_index: usize = 0,
1514
1515 fn avoidNameConflict(iter: *ScanDeclIter, comptime fmt: []const u8, args: anytype) !InternPool.NullTerminatedString {
1516 const pt = iter.pt;
1517 const gpa = pt.zcu.gpa;
1518 const ip = &pt.zcu.intern_pool;
1519 var name = try ip.getOrPutStringFmt(gpa, pt.tid, fmt, args, .no_embedded_nulls);
1520 var gop = try iter.seen_decls.getOrPut(gpa, name);
1521 var next_suffix: u32 = 0;
1522 while (gop.found_existing) {
1523 name = try ip.getOrPutStringFmt(gpa, pt.tid, "{}_{d}", .{ name.fmt(ip), next_suffix }, .no_embedded_nulls);
1524 gop = try iter.seen_decls.getOrPut(gpa, name);
1525 next_suffix += 1;
1526 }
1527 return name;
1528 }
1529
1530 fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void {
1531 const tracy = trace(@src());
1532 defer tracy.end();
1533
1534 const pt = iter.pt;
1535 const zcu = pt.zcu;
1536 const namespace_index = iter.namespace_index;
1537 const namespace = zcu.namespacePtr(namespace_index);
1538 const gpa = zcu.gpa;
1539 const zir = namespace.fileScope(zcu).zir;
1540 const ip = &zcu.intern_pool;
1541
1542 const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration;
1543 const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index);
1544 const declaration = extra.data;
1545
1546 // Every Decl needs a name.
1547 const decl_name: InternPool.NullTerminatedString, const kind: Zcu.Decl.Kind, const is_named_test: bool = switch (declaration.name) {
1548 .@"comptime" => info: {
1549 if (iter.pass != .unnamed) return;
1550 const i = iter.comptime_index;
1551 iter.comptime_index += 1;
1552 break :info .{
1553 try iter.avoidNameConflict("comptime_{d}", .{i}),
1554 .@"comptime",
1555 false,
1556 };
1557 },
1558 .@"usingnamespace" => info: {
1559 // TODO: this isn't right! These should be considered unnamed. Name conflicts can happen here.
1560 // The problem is, we need to preserve the decl ordering for `@typeInfo`.
1561 // I'm not bothering to fix this now, since some upcoming changes will change this code significantly anyway.
1562 if (iter.pass != .named) return;
1563 const i = iter.usingnamespace_index;
1564 iter.usingnamespace_index += 1;
1565 break :info .{
1566 try iter.avoidNameConflict("usingnamespace_{d}", .{i}),
1567 .@"usingnamespace",
1568 false,
1569 };
1570 },
1571 .unnamed_test => info: {
1572 if (iter.pass != .unnamed) return;
1573 const i = iter.unnamed_test_index;
1574 iter.unnamed_test_index += 1;
1575 break :info .{
1576 try iter.avoidNameConflict("test_{d}", .{i}),
1577 .@"test",
1578 false,
1579 };
1580 },
1581 .decltest => info: {
1582 // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary.
1583 if (iter.pass != .unnamed) return;
1584 assert(declaration.flags.has_doc_comment);
1585 const name = zir.nullTerminatedString(@enumFromInt(zir.extra[extra.end]));
1586 break :info .{
1587 try iter.avoidNameConflict("decltest.{s}", .{name}),
1588 .@"test",
1589 true,
1590 };
1591 },
1592 _ => if (declaration.name.isNamedTest(zir)) info: {
1593 // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary.
1594 if (iter.pass != .unnamed) return;
1595 break :info .{
1596 try iter.avoidNameConflict("test.{s}", .{zir.nullTerminatedString(declaration.name.toString(zir).?)}),
1597 .@"test",
1598 true,
1599 };
1600 } else info: {
1601 if (iter.pass != .named) return;
1602 const name = try ip.getOrPutString(
1603 gpa,
1604 pt.tid,
1605 zir.nullTerminatedString(declaration.name.toString(zir).?),
1606 .no_embedded_nulls,
1607 );
1608 try iter.seen_decls.putNoClobber(gpa, name, {});
1609 break :info .{
1610 name,
1611 .named,
1612 false,
1613 };
1614 },
1615 };
1616
1617 switch (kind) {
1618 .@"usingnamespace" => try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1),
1619 .@"test" => try zcu.test_functions.ensureUnusedCapacity(gpa, 1),
1620 else => {},
1621 }
1622
1623 const parent_file_scope_index = iter.parent_decl.getFileScopeIndex(zcu);
1624 const tracked_inst = try ip.trackZir(gpa, parent_file_scope_index, decl_inst);
1625
1626 // We create a Decl for it regardless of analysis status.
1627
1628 const prev_exported, const decl_index = if (iter.existing_by_inst.get(tracked_inst)) |decl_index| decl_index: {
1629 // We need only update this existing Decl.
1630 const decl = zcu.declPtr(decl_index);
1631 const was_exported = decl.is_exported;
1632 assert(decl.kind == kind); // ZIR tracking should preserve this
1633 decl.name = decl_name;
1634 decl.is_pub = declaration.flags.is_pub;
1635 decl.is_exported = declaration.flags.is_export;
1636 break :decl_index .{ was_exported, decl_index };
1637 } else decl_index: {
1638 // Create and set up a new Decl.
1639 const new_decl_index = try zcu.allocateNewDecl(namespace_index);
1640 const new_decl = zcu.declPtr(new_decl_index);
1641 new_decl.kind = kind;
1642 new_decl.name = decl_name;
1643 new_decl.is_pub = declaration.flags.is_pub;
1644 new_decl.is_exported = declaration.flags.is_export;
1645 new_decl.zir_decl_index = tracked_inst.toOptional();
1646 break :decl_index .{ false, new_decl_index };
1647 };
1648
1649 const decl = zcu.declPtr(decl_index);
1650
1651 namespace.decls.putAssumeCapacityNoClobberContext(decl_index, {}, .{ .zcu = zcu });
1652
1653 const comp = zcu.comp;
1654 const decl_mod = namespace.fileScope(zcu).mod;
1655 const want_analysis = declaration.flags.is_export or switch (kind) {
1656 .anon => unreachable,
1657 .@"comptime" => true,
1658 .@"usingnamespace" => a: {
1659 namespace.usingnamespace_set.putAssumeCapacityNoClobber(decl_index, declaration.flags.is_pub);
1660 break :a true;
1661 },
1662 .named => false,
1663 .@"test" => a: {
1664 if (!comp.config.is_test) break :a false;
1665 if (decl_mod != zcu.main_mod) break :a false;
1666 if (is_named_test and comp.test_filters.len > 0) {
1667 const decl_fqn = try namespace.fullyQualifiedName(pt, decl_name);
1668 const decl_fqn_slice = decl_fqn.toSlice(ip);
1669 for (comp.test_filters) |test_filter| {
1670 if (std.mem.indexOf(u8, decl_fqn_slice, test_filter)) |_| break;
1671 } else break :a false;
1672 }
1673 zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update
1674 break :a true;
1675 },
1676 };
1677
1678 if (want_analysis) {
1679 // We will not queue analysis if the decl has been analyzed on a previous update and
1680 // `is_export` is unchanged. In this case, the incremental update mechanism will handle
1681 // re-analysis for us if necessary.
1682 if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) {
1683 log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{
1684 namespace.fileScope(zcu).sub_file_path, decl_name.fmt(ip), decl_index,
1685 });
1686 comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index });
1687 }
1688 }
1689
1690 if (decl.getOwnedFunction(zcu) != null) {
1691 // TODO this logic is insufficient; namespaces we don't re-scan may still require
1692 // updated line numbers. Look into this!
1693 // TODO Look into detecting when this would be unnecessary by storing enough state
1694 // in `Decl` to notice that the line number did not change.
1695 comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
1696 }
1697 }
1698};
1699
10301700pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: Allocator) Zcu.SemaError!Air {
10311701 const tracy = trace(@src());
10321702 defer tracy.end();
......@@ -1038,12 +1708,12 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
10381708 const decl_index = func.owner_decl;
10391709 const decl = mod.declPtr(decl_index);
10401710
1041 log.debug("func name '{}'", .{(try decl.fullyQualifiedName(mod)).fmt(ip)});
1711 log.debug("func name '{}'", .{(try decl.fullyQualifiedName(pt)).fmt(ip)});
10421712 defer blk: {
1043 log.debug("finish func name '{}'", .{(decl.fullyQualifiedName(mod) catch break :blk).fmt(ip)});
1713 log.debug("finish func name '{}'", .{(decl.fullyQualifiedName(pt) catch break :blk).fmt(ip)});
10441714 }
10451715
1046 const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(mod)).toSlice(ip), 0);
1716 const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0);
10471717 defer decl_prog_node.end();
10481718
10491719 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));
......@@ -1273,6 +1943,19 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
12731943 };
12741944}
12751945
1946fn lockAndClearFileCompileError(pt: Zcu.PerThread, file: *Zcu.File) void {
1947 switch (file.status) {
1948 .success_zir, .retryable_failure => {},
1949 .never_loaded, .parse_failure, .astgen_failure => {
1950 pt.zcu.comp.mutex.lock();
1951 defer pt.zcu.comp.mutex.unlock();
1952 if (pt.zcu.failed_files.fetchSwapRemove(file)) |kv| {
1953 if (kv.value) |msg| msg.destroy(pt.zcu.gpa); // Delete previous error message.
1954 }
1955 },
1956 }
1957}
1958
12761959/// Called from `Compilation.update`, after everything is done, just before
12771960/// reporting compile errors. In this function we emit exported symbol collision
12781961/// errors and communicate exported symbols to the linker backend.
......@@ -1397,7 +2080,7 @@ pub fn populateTestFunctions(
13972080 const root_decl_index = zcu.fileRootDecl(builtin_file_index);
13982081 const root_decl = zcu.declPtr(root_decl_index.unwrap().?);
13992082 const builtin_namespace = zcu.namespacePtr(root_decl.src_namespace);
1400 const test_functions_str = try ip.getOrPutString(gpa, "test_functions", .no_embedded_nulls);
2083 const test_functions_str = try ip.getOrPutString(gpa, pt.tid, "test_functions", .no_embedded_nulls);
14012084 const decl_index = builtin_namespace.decls.getKeyAdapted(
14022085 test_functions_str,
14032086 Zcu.DeclAdapter{ .zcu = zcu },
......@@ -1424,7 +2107,7 @@ pub fn populateTestFunctions(
14242107
14252108 for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_decl_index| {
14262109 const test_decl = zcu.declPtr(test_decl_index);
1427 const test_decl_name = try test_decl.fullyQualifiedName(zcu);
2110 const test_decl_name = try test_decl.fullyQualifiedName(pt);
14282111 const test_decl_name_len = test_decl_name.length(ip);
14292112 const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = n: {
14302113 const test_name_ty = try pt.arrayType(.{
......@@ -1530,7 +2213,7 @@ pub fn linkerUpdateDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !void {
15302213
15312214 const decl = zcu.declPtr(decl_index);
15322215
1533 const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(zcu)).toSlice(&zcu.intern_pool), 0);
2216 const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(&zcu.intern_pool), 0);
15342217 defer codegen_prog_node.end();
15352218
15362219 if (comp.bin_file) |lf| {
......@@ -2064,11 +2747,11 @@ pub fn getBuiltinDecl(pt: Zcu.PerThread, name: []const u8) Allocator.Error!Inter
20642747 const std_file_imported = zcu.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig");
20652748 const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index).unwrap().?;
20662749 const std_namespace = zcu.declPtr(std_file_root_decl).getOwnedInnerNamespace(zcu).?;
2067 const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls);
2750 const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls);
20682751 const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std.zig is corrupt and missing 'builtin'");
20692752 pt.ensureDeclAnalyzed(builtin_decl) catch @panic("std.builtin is corrupt");
20702753 const builtin_namespace = zcu.declPtr(builtin_decl).getInnerNamespace(zcu) orelse @panic("std.builtin is corrupt");
2071 const name_str = try ip.getOrPutString(gpa, name, .no_embedded_nulls);
2754 const name_str = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
20722755 return builtin_namespace.decls.getKeyAdapted(name_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std/builtin.zig is corrupt");
20732756}
20742757
......@@ -2082,6 +2765,8 @@ pub fn getBuiltinType(pt: Zcu.PerThread, name: []const u8) Allocator.Error!Type
20822765const Air = @import("../Air.zig");
20832766const Allocator = std.mem.Allocator;
20842767const assert = std.debug.assert;
2768const Ast = std.zig.Ast;
2769const AstGen = std.zig.AstGen;
20852770const BigIntConst = std.math.big.int.Const;
20862771const BigIntMutable = std.math.big.int.Mutable;
20872772const build_options = @import("build_options");
src/arch/wasm/CodeGen.zig+5-5
......@@ -2204,14 +2204,14 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22042204 const func_val = (try func.air.value(pl_op.operand, pt)) orelse break :blk null;
22052205
22062206 if (func_val.getFunction(mod)) |function| {
2207 _ = try func.bin_file.getOrCreateAtomForDecl(function.owner_decl);
2207 _ = try func.bin_file.getOrCreateAtomForDecl(pt, function.owner_decl);
22082208 break :blk function.owner_decl;
22092209 } else if (func_val.getExternFunc(mod)) |extern_func| {
22102210 const ext_decl = mod.declPtr(extern_func.decl);
22112211 const ext_info = mod.typeToFunc(ext_decl.typeOf(mod)).?;
22122212 var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), Type.fromInterned(ext_info.return_type), pt);
22132213 defer func_type.deinit(func.gpa);
2214 const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_func.decl);
2214 const atom_index = try func.bin_file.getOrCreateAtomForDecl(pt, extern_func.decl);
22152215 const atom = func.bin_file.getAtomPtr(atom_index);
22162216 const type_index = try func.bin_file.storeDeclType(extern_func.decl, func_type);
22172217 try func.bin_file.addOrUpdateImport(
......@@ -2224,7 +2224,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22242224 } else switch (mod.intern_pool.indexToKey(func_val.ip_index)) {
22252225 .ptr => |ptr| if (ptr.byte_offset == 0) switch (ptr.base_addr) {
22262226 .decl => |decl| {
2227 _ = try func.bin_file.getOrCreateAtomForDecl(decl);
2227 _ = try func.bin_file.getOrCreateAtomForDecl(pt, decl);
22282228 break :blk decl;
22292229 },
22302230 else => {},
......@@ -3227,7 +3227,7 @@ fn lowerDeclRefValue(func: *CodeGen, decl_index: InternPool.DeclIndex, offset: u
32273227 return WValue{ .imm32 = 0xaaaaaaaa };
32283228 }
32293229
3230 const atom_index = try func.bin_file.getOrCreateAtomForDecl(decl_index);
3230 const atom_index = try func.bin_file.getOrCreateAtomForDecl(pt, decl_index);
32313231 const atom = func.bin_file.getAtom(atom_index);
32323232
32333233 const target_sym_index = @intFromEnum(atom.sym_index);
......@@ -7284,7 +7284,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
72847284 defer arena_allocator.deinit();
72857285 const arena = arena_allocator.allocator();
72867286
7287 const fqn = try mod.declPtr(enum_decl_index).fullyQualifiedName(mod);
7287 const fqn = try mod.declPtr(enum_decl_index).fullyQualifiedName(pt);
72887288 const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(ip)});
72897289
72907290 // check if we already generated code for this.
src/codegen.zig+1-1
......@@ -756,7 +756,7 @@ fn lowerDeclRef(
756756 return Result.ok;
757757 }
758758
759 const vaddr = try lf.getDeclVAddr(decl_index, .{
759 const vaddr = try lf.getDeclVAddr(pt, decl_index, .{
760760 .parent_atom_index = reloc_info.parent_atom_index,
761761 .offset = code.items.len,
762762 .addend = @intCast(offset),
src/codegen/llvm.zig+16-14
......@@ -1744,7 +1744,7 @@ pub const Object = struct {
17441744 if (export_indices.len != 0) {
17451745 return updateExportedGlobal(self, zcu, global_index, export_indices);
17461746 } else {
1747 const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(zcu)).toSlice(ip));
1747 const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(pt)).toSlice(ip));
17481748 try global_index.rename(fqn, &self.builder);
17491749 global_index.setLinkage(.internal, &self.builder);
17501750 if (comp.config.dll_export_fns)
......@@ -2520,7 +2520,7 @@ pub const Object = struct {
25202520 const field_offset = ty.structFieldOffset(field_index, pt);
25212521
25222522 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
2523 try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls);
2523 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
25242524
25252525 fields.appendAssumeCapacity(try o.builder.debugMemberType(
25262526 try o.builder.metadataString(field_name.toSlice(ip)),
......@@ -2807,17 +2807,18 @@ pub const Object = struct {
28072807 }
28082808
28092809 fn getStackTraceType(o: *Object) Allocator.Error!Type {
2810 const zcu = o.pt.zcu;
2810 const pt = o.pt;
2811 const zcu = pt.zcu;
28112812
28122813 const std_mod = zcu.std_mod;
28132814 const std_file_imported = zcu.importPkg(std_mod) catch unreachable;
28142815
2815 const builtin_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "builtin", .no_embedded_nulls);
2816 const builtin_str = try zcu.intern_pool.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls);
28162817 const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index);
28172818 const std_namespace = zcu.namespacePtr(zcu.declPtr(std_file_root_decl.unwrap().?).src_namespace);
28182819 const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }).?;
28192820
2820 const stack_trace_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "StackTrace", .no_embedded_nulls);
2821 const stack_trace_str = try zcu.intern_pool.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls);
28212822 // buffer is only used for int_type, `builtin` is a struct.
28222823 const builtin_ty = zcu.declPtr(builtin_decl).val.toType();
28232824 const builtin_namespace = zcu.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(zcu)).?;
......@@ -2865,7 +2866,7 @@ pub const Object = struct {
28652866 try o.builder.strtabString((if (is_extern)
28662867 decl.name
28672868 else
2868 try decl.fullyQualifiedName(zcu)).toSlice(ip)),
2869 try decl.fullyQualifiedName(pt)).toSlice(ip)),
28692870 toLlvmAddressSpace(decl.@"addrspace", target),
28702871 );
28712872 gop.value_ptr.* = function_index.ptrConst(&o.builder).global;
......@@ -3074,7 +3075,8 @@ pub const Object = struct {
30743075 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;
30753076 errdefer assert(o.decl_map.remove(decl_index));
30763077
3077 const zcu = o.pt.zcu;
3078 const pt = o.pt;
3079 const zcu = pt.zcu;
30783080 const decl = zcu.declPtr(decl_index);
30793081 const is_extern = decl.isExtern(zcu);
30803082
......@@ -3082,7 +3084,7 @@ pub const Object = struct {
30823084 try o.builder.strtabString((if (is_extern)
30833085 decl.name
30843086 else
3085 try decl.fullyQualifiedName(zcu)).toSlice(&zcu.intern_pool)),
3087 try decl.fullyQualifiedName(pt)).toSlice(&zcu.intern_pool)),
30863088 try o.lowerType(decl.typeOf(zcu)),
30873089 toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()),
30883090 );
......@@ -3310,7 +3312,7 @@ pub const Object = struct {
33103312 return int_ty;
33113313 }
33123314
3313 const fqn = try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(mod);
3315 const fqn = try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(pt);
33143316
33153317 var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){};
33163318 defer llvm_field_types.deinit(o.gpa);
......@@ -3464,7 +3466,7 @@ pub const Object = struct {
34643466 return enum_tag_ty;
34653467 }
34663468
3467 const fqn = try mod.declPtr(union_obj.decl).fullyQualifiedName(mod);
3469 const fqn = try mod.declPtr(union_obj.decl).fullyQualifiedName(pt);
34683470
34693471 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);
34703472 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);
......@@ -3525,7 +3527,7 @@ pub const Object = struct {
35253527 const gop = try o.type_map.getOrPut(o.gpa, t.toIntern());
35263528 if (!gop.found_existing) {
35273529 const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl);
3528 const fqn = try decl.fullyQualifiedName(mod);
3530 const fqn = try decl.fullyQualifiedName(pt);
35293531 gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
35303532 }
35313533 return gop.value_ptr.*;
......@@ -4585,7 +4587,7 @@ pub const Object = struct {
45854587
45864588 const usize_ty = try o.lowerType(Type.usize);
45874589 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);
4588 const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(zcu);
4590 const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(pt);
45894591 const target = zcu.root_mod.resolved_target.result;
45904592 const function_index = try o.builder.addFunction(
45914593 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
......@@ -5173,7 +5175,7 @@ pub const FuncGen = struct {
51735175 const line_number = decl.navSrcLine(zcu) + 1;
51745176 self.inlined = self.wip.debug_location;
51755177
5176 const fqn = try decl.fullyQualifiedName(zcu);
5178 const fqn = try decl.fullyQualifiedName(pt);
51775179
51785180 const fn_ty = try pt.funcType(.{
51795181 .param_types = &.{},
......@@ -9707,7 +9709,7 @@ pub const FuncGen = struct {
97079709 if (gop.found_existing) return gop.value_ptr.*;
97089710 errdefer assert(o.named_enum_map.remove(enum_type.decl));
97099711
9710 const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(zcu);
9712 const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(pt);
97119713 const target = zcu.root_mod.resolved_target.result;
97129714 const function_index = try o.builder.addFunction(
97139715 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
src/codegen/spirv.zig+4-4
......@@ -1753,7 +1753,7 @@ const DeclGen = struct {
17531753 }
17541754
17551755 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
1756 try ip.getOrPutStringFmt(mod.gpa, "{d}", .{field_index}, .no_embedded_nulls);
1756 try ip.getOrPutStringFmt(mod.gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
17571757 try member_types.append(try self.resolveType(field_ty, .indirect));
17581758 try member_names.append(field_name.toSlice(ip));
17591759 }
......@@ -3012,7 +3012,7 @@ const DeclGen = struct {
30123012 // Append the actual code into the functions section.
30133013 try self.spv.addFunction(spv_decl_index, self.func);
30143014
3015 const fqn = try decl.fullyQualifiedName(self.pt.zcu);
3015 const fqn = try decl.fullyQualifiedName(self.pt);
30163016 try self.spv.debugName(result_id, fqn.toSlice(ip));
30173017
30183018 // Temporarily generate a test kernel declaration if this is a test function.
......@@ -3041,7 +3041,7 @@ const DeclGen = struct {
30413041 .storage_class = final_storage_class,
30423042 });
30433043
3044 const fqn = try decl.fullyQualifiedName(self.pt.zcu);
3044 const fqn = try decl.fullyQualifiedName(self.pt);
30453045 try self.spv.debugName(result_id, fqn.toSlice(ip));
30463046 try self.spv.declareDeclDeps(spv_decl_index, &.{});
30473047 },
......@@ -3086,7 +3086,7 @@ const DeclGen = struct {
30863086 try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {});
30873087 try self.spv.addFunction(spv_decl_index, self.func);
30883088
3089 const fqn = try decl.fullyQualifiedName(self.pt.zcu);
3089 const fqn = try decl.fullyQualifiedName(self.pt);
30903090 try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{fqn.fmt(ip)});
30913091
30923092 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{
src/link.zig+5-5
......@@ -424,14 +424,14 @@ pub const File = struct {
424424 }
425425 }
426426
427 pub fn updateDeclLineNumber(base: *File, module: *Zcu, decl_index: InternPool.DeclIndex) UpdateDeclError!void {
428 const decl = module.declPtr(decl_index);
427 pub fn updateDeclLineNumber(base: *File, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) UpdateDeclError!void {
428 const decl = pt.zcu.declPtr(decl_index);
429429 assert(decl.has_tv);
430430 switch (base.tag) {
431431 .spirv, .nvptx => {},
432432 inline else => |tag| {
433433 if (tag != .c and build_options.only_c) unreachable;
434 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateDeclLineNumber(module, decl_index);
434 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateDeclLineNumber(pt, decl_index);
435435 },
436436 }
437437 }
......@@ -626,14 +626,14 @@ pub const File = struct {
626626 /// `Decl`'s address was not yet resolved, or the containing atom gets moved in virtual memory.
627627 /// May be called before or after updateFunc/updateDecl therefore it is up to the linker to allocate
628628 /// the block/atom.
629 pub fn getDeclVAddr(base: *File, decl_index: InternPool.DeclIndex, reloc_info: RelocInfo) !u64 {
629 pub fn getDeclVAddr(base: *File, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: RelocInfo) !u64 {
630630 if (build_options.only_c) @compileError("unreachable");
631631 switch (base.tag) {
632632 .c => unreachable,
633633 .spirv => unreachable,
634634 .nvptx => unreachable,
635635 inline else => |tag| {
636 return @as(*tag.Type(), @fieldParentPtr("base", base)).getDeclVAddr(decl_index, reloc_info);
636 return @as(*tag.Type(), @fieldParentPtr("base", base)).getDeclVAddr(pt, decl_index, reloc_info);
637637 },
638638 }
639639 }
src/link/C.zig+2-2
......@@ -383,11 +383,11 @@ pub fn updateDecl(self: *C, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex)
383383 gop.value_ptr.fwd_decl = try self.addString(object.dg.fwd_decl.items);
384384}
385385
386pub fn updateDeclLineNumber(self: *C, zcu: *Zcu, decl_index: InternPool.DeclIndex) !void {
386pub fn updateDeclLineNumber(self: *C, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void {
387387 // The C backend does not have the ability to fix line numbers without re-generating
388388 // the entire Decl.
389389 _ = self;
390 _ = zcu;
390 _ = pt;
391391 _ = decl_index;
392392}
393393
src/link/Coff.zig+5-5
......@@ -1176,7 +1176,7 @@ pub fn lowerUnnamedConst(self: *Coff, pt: Zcu.PerThread, val: Value, decl_index:
11761176 gop.value_ptr.* = .{};
11771177 }
11781178 const unnamed_consts = gop.value_ptr;
1179 const decl_name = try decl.fullyQualifiedName(mod);
1179 const decl_name = try decl.fullyQualifiedName(pt);
11801180 const index = unnamed_consts.items.len;
11811181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
11821182 defer gpa.free(sym_name);
......@@ -1427,7 +1427,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
14271427 const mod = pt.zcu;
14281428 const decl = mod.declPtr(decl_index);
14291429
1430 const decl_name = try decl.fullyQualifiedName(mod);
1430 const decl_name = try decl.fullyQualifiedName(pt);
14311431
14321432 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
14331433 const required_alignment: u32 = @intCast(decl.getAlignment(pt).toByteUnits() orelse 0);
......@@ -1855,7 +1855,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
18551855 assert(!self.imports_count_dirty);
18561856}
18571857
1858pub fn getDeclVAddr(self: *Coff, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
1858pub fn getDeclVAddr(self: *Coff, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
18591859 assert(self.llvm_object == null);
18601860
18611861 const this_atom_index = try self.getOrCreateAtomForDecl(decl_index);
......@@ -1972,9 +1972,9 @@ pub fn getGlobalSymbol(self: *Coff, name: []const u8, lib_name_name: ?[]const u8
19721972 return global_index;
19731973}
19741974
1975pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl_index: InternPool.DeclIndex) !void {
1975pub fn updateDeclLineNumber(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void {
19761976 _ = self;
1977 _ = module;
1977 _ = pt;
19781978 _ = decl_index;
19791979 log.debug("TODO implement updateDeclLineNumber", .{});
19801980}
src/link/Dwarf.zig+1-1
......@@ -1082,7 +1082,7 @@ pub fn initDeclState(self: *Dwarf, pt: Zcu.PerThread, decl_index: InternPool.Dec
10821082 defer tracy.end();
10831083
10841084 const decl = pt.zcu.declPtr(decl_index);
1085 const decl_linkage_name = try decl.fullyQualifiedName(pt.zcu);
1085 const decl_linkage_name = try decl.fullyQualifiedName(pt);
10861086
10871087 log.debug("initDeclState {}{*}", .{ decl_linkage_name.fmt(&pt.zcu.intern_pool), decl });
10881088
src/link/Elf.zig+3-3
......@@ -543,7 +543,7 @@ pub fn deinit(self: *Elf) void {
543543 self.comdat_group_sections.deinit(gpa);
544544}
545545
546pub fn getDeclVAddr(self: *Elf, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
546pub fn getDeclVAddr(self: *Elf, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
547547 assert(self.llvm_object == null);
548548 return self.zigObjectPtr().?.getDeclVAddr(self, decl_index, reloc_info);
549549}
......@@ -3021,9 +3021,9 @@ pub fn updateExports(
30213021 return self.zigObjectPtr().?.updateExports(self, pt, exported, export_indices);
30223022}
30233023
3024pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl_index: InternPool.DeclIndex) !void {
3024pub fn updateDeclLineNumber(self: *Elf, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void {
30253025 if (self.llvm_object) |_| return;
3026 return self.zigObjectPtr().?.updateDeclLineNumber(mod, decl_index);
3026 return self.zigObjectPtr().?.updateDeclLineNumber(pt, decl_index);
30273027}
30283028
30293029pub fn deleteExport(
src/link/Elf/ZigObject.zig+8-8
......@@ -908,7 +908,7 @@ fn updateDeclCode(
908908 const gpa = elf_file.base.comp.gpa;
909909 const mod = pt.zcu;
910910 const decl = mod.declPtr(decl_index);
911 const decl_name = try decl.fullyQualifiedName(mod);
911 const decl_name = try decl.fullyQualifiedName(pt);
912912
913913 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
914914
......@@ -1009,7 +1009,7 @@ fn updateTlv(
10091009 const mod = pt.zcu;
10101010 const gpa = mod.gpa;
10111011 const decl = mod.declPtr(decl_index);
1012 const decl_name = try decl.fullyQualifiedName(mod);
1012 const decl_name = try decl.fullyQualifiedName(pt);
10131013
10141014 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl });
10151015
......@@ -1286,7 +1286,7 @@ pub fn lowerUnnamedConst(
12861286 }
12871287 const unnamed_consts = gop.value_ptr;
12881288 const decl = mod.declPtr(decl_index);
1289 const decl_name = try decl.fullyQualifiedName(mod);
1289 const decl_name = try decl.fullyQualifiedName(pt);
12901290 const index = unnamed_consts.items.len;
12911291 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
12921292 defer gpa.free(name);
......@@ -1466,19 +1466,19 @@ pub fn updateExports(
14661466/// Must be called only after a successful call to `updateDecl`.
14671467pub fn updateDeclLineNumber(
14681468 self: *ZigObject,
1469 mod: *Module,
1469 pt: Zcu.PerThread,
14701470 decl_index: InternPool.DeclIndex,
14711471) !void {
14721472 const tracy = trace(@src());
14731473 defer tracy.end();
14741474
1475 const decl = mod.declPtr(decl_index);
1476 const decl_name = try decl.fullyQualifiedName(mod);
1475 const decl = pt.zcu.declPtr(decl_index);
1476 const decl_name = try decl.fullyQualifiedName(pt);
14771477
1478 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
1478 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&pt.zcu.intern_pool), decl });
14791479
14801480 if (self.dwarf) |*dw| {
1481 try dw.updateDeclLineNumber(mod, decl_index);
1481 try dw.updateDeclLineNumber(pt.zcu, decl_index);
14821482 }
14831483}
14841484
src/link/MachO.zig+3-3
......@@ -3198,9 +3198,9 @@ pub fn updateDecl(self: *MachO, pt: Zcu.PerThread, decl_index: InternPool.DeclIn
31983198 return self.getZigObject().?.updateDecl(self, pt, decl_index);
31993199}
32003200
3201pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: InternPool.DeclIndex) !void {
3201pub fn updateDeclLineNumber(self: *MachO, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void {
32023202 if (self.llvm_object) |_| return;
3203 return self.getZigObject().?.updateDeclLineNumber(module, decl_index);
3203 return self.getZigObject().?.updateDeclLineNumber(pt, decl_index);
32043204}
32053205
32063206pub fn updateExports(
......@@ -3230,7 +3230,7 @@ pub fn freeDecl(self: *MachO, decl_index: InternPool.DeclIndex) void {
32303230 return self.getZigObject().?.freeDecl(decl_index);
32313231}
32323232
3233pub fn getDeclVAddr(self: *MachO, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
3233pub fn getDeclVAddr(self: *MachO, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
32343234 assert(self.llvm_object == null);
32353235 return self.getZigObject().?.getDeclVAddr(self, decl_index, reloc_info);
32363236}
src/link/MachO/ZigObject.zig+8-9
......@@ -810,7 +810,7 @@ fn updateDeclCode(
810810 const gpa = macho_file.base.comp.gpa;
811811 const mod = pt.zcu;
812812 const decl = mod.declPtr(decl_index);
813 const decl_name = try decl.fullyQualifiedName(mod);
813 const decl_name = try decl.fullyQualifiedName(pt);
814814
815815 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
816816
......@@ -893,13 +893,12 @@ fn updateTlv(
893893 sect_index: u8,
894894 code: []const u8,
895895) !void {
896 const mod = pt.zcu;
897 const decl = mod.declPtr(decl_index);
898 const decl_name = try decl.fullyQualifiedName(mod);
896 const decl = pt.zcu.declPtr(decl_index);
897 const decl_name = try decl.fullyQualifiedName(pt);
899898
900 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl });
899 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&pt.zcu.intern_pool), decl });
901900
902 const decl_name_slice = decl_name.toSlice(&mod.intern_pool);
901 const decl_name_slice = decl_name.toSlice(&pt.zcu.intern_pool);
903902 const required_alignment = decl.getAlignment(pt);
904903
905904 // 1. Lower TLV initializer
......@@ -1100,7 +1099,7 @@ pub fn lowerUnnamedConst(
11001099 }
11011100 const unnamed_consts = gop.value_ptr;
11021101 const decl = mod.declPtr(decl_index);
1103 const decl_name = try decl.fullyQualifiedName(mod);
1102 const decl_name = try decl.fullyQualifiedName(pt);
11041103 const index = unnamed_consts.items.len;
11051104 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
11061105 defer gpa.free(name);
......@@ -1363,9 +1362,9 @@ fn updateLazySymbol(
13631362}
13641363
13651364/// Must be called only after a successful call to `updateDecl`.
1366pub fn updateDeclLineNumber(self: *ZigObject, mod: *Module, decl_index: InternPool.DeclIndex) !void {
1365pub fn updateDeclLineNumber(self: *ZigObject, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void {
13671366 if (self.dwarf) |*dw| {
1368 try dw.updateDeclLineNumber(mod, decl_index);
1367 try dw.updateDeclLineNumber(pt.zcu, decl_index);
13691368 }
13701369}
13711370
src/link/Plan9.zig+7-7
......@@ -483,7 +483,7 @@ pub fn lowerUnnamedConst(self: *Plan9, pt: Zcu.PerThread, val: Value, decl_index
483483 }
484484 const unnamed_consts = gop.value_ptr;
485485
486 const decl_name = try decl.fullyQualifiedName(mod);
486 const decl_name = try decl.fullyQualifiedName(pt);
487487
488488 const index = unnamed_consts.items.len;
489489 // name is freed when the unnamed const is freed
......@@ -1496,22 +1496,22 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
14961496}
14971497
14981498/// Must be called only after a successful call to `updateDecl`.
1499pub fn updateDeclLineNumber(self: *Plan9, mod: *Zcu, decl_index: InternPool.DeclIndex) !void {
1499pub fn updateDeclLineNumber(self: *Plan9, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void {
15001500 _ = self;
1501 _ = mod;
1501 _ = pt;
15021502 _ = decl_index;
15031503}
15041504
15051505pub fn getDeclVAddr(
15061506 self: *Plan9,
1507 pt: Zcu.PerThread,
15071508 decl_index: InternPool.DeclIndex,
15081509 reloc_info: link.File.RelocInfo,
15091510) !u64 {
1510 const mod = self.base.comp.module.?;
1511 const ip = &mod.intern_pool;
1512 const decl = mod.declPtr(decl_index);
1511 const ip = &pt.zcu.intern_pool;
1512 const decl = pt.zcu.declPtr(decl_index);
15131513 log.debug("getDeclVAddr for {}", .{decl.name.fmt(ip)});
1514 if (decl.isExtern(mod)) {
1514 if (decl.isExtern(pt.zcu)) {
15151515 if (decl.name.eqlSlice("etext", ip)) {
15161516 try self.addReloc(reloc_info.parent_atom_index, .{
15171517 .target = undefined,
src/link/Wasm.zig+6-5
......@@ -1457,9 +1457,9 @@ pub fn updateDecl(wasm: *Wasm, pt: Zcu.PerThread, decl_index: InternPool.DeclInd
14571457 try wasm.zigObjectPtr().?.updateDecl(wasm, pt, decl_index);
14581458}
14591459
1460pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Zcu, decl_index: InternPool.DeclIndex) !void {
1460pub fn updateDeclLineNumber(wasm: *Wasm, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void {
14611461 if (wasm.llvm_object) |_| return;
1462 try wasm.zigObjectPtr().?.updateDeclLineNumber(mod, decl_index);
1462 try wasm.zigObjectPtr().?.updateDeclLineNumber(pt, decl_index);
14631463}
14641464
14651465/// From a given symbol location, returns its `wasm.GlobalType`.
......@@ -1521,10 +1521,11 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !Sy
15211521/// Returns the given pointer address
15221522pub fn getDeclVAddr(
15231523 wasm: *Wasm,
1524 pt: Zcu.PerThread,
15241525 decl_index: InternPool.DeclIndex,
15251526 reloc_info: link.File.RelocInfo,
15261527) !u64 {
1527 return wasm.zigObjectPtr().?.getDeclVAddr(wasm, decl_index, reloc_info);
1528 return wasm.zigObjectPtr().?.getDeclVAddr(wasm, pt, decl_index, reloc_info);
15281529}
15291530
15301531pub fn lowerAnonDecl(
......@@ -4016,8 +4017,8 @@ pub fn getErrorTableSymbol(wasm_file: *Wasm, pt: Zcu.PerThread) !u32 {
40164017/// For a given `InternPool.DeclIndex` returns its corresponding `Atom.Index`.
40174018/// When the index was not found, a new `Atom` will be created, and its index will be returned.
40184019/// The newly created Atom is empty with default fields as specified by `Atom.empty`.
4019pub fn getOrCreateAtomForDecl(wasm_file: *Wasm, decl_index: InternPool.DeclIndex) !Atom.Index {
4020 return wasm_file.zigObjectPtr().?.getOrCreateAtomForDecl(wasm_file, decl_index);
4020pub fn getOrCreateAtomForDecl(wasm_file: *Wasm, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !Atom.Index {
4021 return wasm_file.zigObjectPtr().?.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
40214022}
40224023
40234024/// Verifies all resolved symbols and checks whether itself needs to be marked alive,
src/link/Wasm/ZigObject.zig+30-22
......@@ -253,7 +253,7 @@ pub fn updateDecl(
253253 }
254254
255255 const gpa = wasm_file.base.comp.gpa;
256 const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index);
256 const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
257257 const atom = wasm_file.getAtomPtr(atom_index);
258258 atom.clear();
259259
......@@ -302,7 +302,7 @@ pub fn updateFunc(
302302 const func = pt.zcu.funcInfo(func_index);
303303 const decl_index = func.owner_decl;
304304 const decl = pt.zcu.declPtr(decl_index);
305 const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index);
305 const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
306306 const atom = wasm_file.getAtomPtr(atom_index);
307307 atom.clear();
308308
......@@ -346,7 +346,7 @@ fn finishUpdateDecl(
346346 const atom_index = decl_info.atom;
347347 const atom = wasm_file.getAtomPtr(atom_index);
348348 const sym = zig_object.symbol(atom.sym_index);
349 const full_name = try decl.fullyQualifiedName(zcu);
349 const full_name = try decl.fullyQualifiedName(pt);
350350 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(ip));
351351 try atom.code.appendSlice(gpa, code);
352352 atom.size = @intCast(code.len);
......@@ -424,17 +424,21 @@ fn createDataSegment(
424424/// For a given `InternPool.DeclIndex` returns its corresponding `Atom.Index`.
425425/// When the index was not found, a new `Atom` will be created, and its index will be returned.
426426/// The newly created Atom is empty with default fields as specified by `Atom.empty`.
427pub fn getOrCreateAtomForDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_index: InternPool.DeclIndex) !Atom.Index {
428 const gpa = wasm_file.base.comp.gpa;
427pub fn getOrCreateAtomForDecl(
428 zig_object: *ZigObject,
429 wasm_file: *Wasm,
430 pt: Zcu.PerThread,
431 decl_index: InternPool.DeclIndex,
432) !Atom.Index {
433 const gpa = pt.zcu.gpa;
429434 const gop = try zig_object.decls_map.getOrPut(gpa, decl_index);
430435 if (!gop.found_existing) {
431436 const sym_index = try zig_object.allocateSymbol(gpa);
432437 gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) };
433 const mod = wasm_file.base.comp.module.?;
434 const decl = mod.declPtr(decl_index);
435 const full_name = try decl.fullyQualifiedName(mod);
438 const decl = pt.zcu.declPtr(decl_index);
439 const full_name = try decl.fullyQualifiedName(pt);
436440 const sym = zig_object.symbol(sym_index);
437 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&mod.intern_pool));
441 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&pt.zcu.intern_pool));
438442 }
439443 return gop.value_ptr.atom;
440444}
......@@ -487,10 +491,10 @@ pub fn lowerUnnamedConst(
487491 std.debug.assert(val.typeOf(mod).zigTypeTag(mod) != .Fn); // cannot create local symbols for functions
488492 const decl = mod.declPtr(decl_index);
489493
490 const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index);
494 const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
491495 const parent_atom = wasm_file.getAtom(parent_atom_index);
492496 const local_index = parent_atom.locals.items.len;
493 const fqn = try decl.fullyQualifiedName(mod);
497 const fqn = try decl.fullyQualifiedName(pt);
494498 const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{}_{d}", .{
495499 fqn.fmt(&mod.intern_pool), local_index,
496500 });
......@@ -775,22 +779,22 @@ pub fn getGlobalSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator, name: []c
775779pub fn getDeclVAddr(
776780 zig_object: *ZigObject,
777781 wasm_file: *Wasm,
782 pt: Zcu.PerThread,
778783 decl_index: InternPool.DeclIndex,
779784 reloc_info: link.File.RelocInfo,
780785) !u64 {
781786 const target = wasm_file.base.comp.root_mod.resolved_target.result;
782 const gpa = wasm_file.base.comp.gpa;
783 const mod = wasm_file.base.comp.module.?;
784 const decl = mod.declPtr(decl_index);
787 const gpa = pt.zcu.gpa;
788 const decl = pt.zcu.declPtr(decl_index);
785789
786 const target_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index);
790 const target_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
787791 const target_symbol_index = @intFromEnum(wasm_file.getAtom(target_atom_index).sym_index);
788792
789793 std.debug.assert(reloc_info.parent_atom_index != 0);
790794 const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
791795 const atom = wasm_file.getAtomPtr(atom_index);
792796 const is_wasm32 = target.cpu.arch == .wasm32;
793 if (decl.typeOf(mod).zigTypeTag(mod) == .Fn) {
797 if (decl.typeOf(pt.zcu).zigTypeTag(pt.zcu) == .Fn) {
794798 std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
795799 try atom.relocs.append(gpa, .{
796800 .index = target_symbol_index,
......@@ -890,7 +894,7 @@ pub fn updateExports(
890894 },
891895 };
892896 const decl = mod.declPtr(decl_index);
893 const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index);
897 const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
894898 const decl_info = zig_object.decls_map.getPtr(decl_index).?;
895899 const atom = wasm_file.getAtom(atom_index);
896900 const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*;
......@@ -1116,13 +1120,17 @@ pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm_file: *Wasm, inde
11161120 return atom_index;
11171121}
11181122
1119pub fn updateDeclLineNumber(zig_object: *ZigObject, mod: *Zcu, decl_index: InternPool.DeclIndex) !void {
1123pub fn updateDeclLineNumber(
1124 zig_object: *ZigObject,
1125 pt: Zcu.PerThread,
1126 decl_index: InternPool.DeclIndex,
1127) !void {
11201128 if (zig_object.dwarf) |*dw| {
1121 const decl = mod.declPtr(decl_index);
1122 const decl_name = try decl.fullyQualifiedName(mod);
1129 const decl = pt.zcu.declPtr(decl_index);
1130 const decl_name = try decl.fullyQualifiedName(pt);
11231131
1124 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
1125 try dw.updateDeclLineNumber(mod, decl_index);
1132 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&pt.zcu.intern_pool), decl });
1133 try dw.updateDeclLineNumber(pt.zcu, decl_index);
11261134 }
11271135}
11281136
src/mutable_value.zig+1-1
......@@ -71,7 +71,7 @@ pub const MutableValue = union(enum) {
7171 } }),
7272 .bytes => |b| try pt.intern(.{ .aggregate = .{
7373 .ty = b.ty,
74 .storage = .{ .bytes = try pt.zcu.intern_pool.getOrPutString(pt.zcu.gpa, b.data, .maybe_embedded_nulls) },
74 .storage = .{ .bytes = try pt.zcu.intern_pool.getOrPutString(pt.zcu.gpa, pt.tid, b.data, .maybe_embedded_nulls) },
7575 } }),
7676 .aggregate => |a| {
7777 const elems = try arena.alloc(InternPool.Index, a.elems.len);