| ... | ... | @@ -105,19 +105,6 @@ multi_exports: std.AutoArrayHashMapUnmanaged(AnalUnit, extern struct { |
| 105 | 105 | /// Indexes correspond 1:1 to `files`. |
| 106 | 106 | import_table: std.StringArrayHashMapUnmanaged(*File) = .{}, |
| 107 | 107 | |
| 108 | | /// Elements are ordered identically to `import_table`. |
| 109 | | /// |
| 110 | | /// Unlike `import_table`, this data is serialized as part of incremental |
| 111 | | /// compilation state. |
| 112 | | /// |
| 113 | | /// Key is the hash of the path to this file, used to store |
| 114 | | /// `InternPool.TrackedInst`. |
| 115 | | /// |
| 116 | | /// Value is the `Decl` of the struct that represents this `File`. |
| 117 | | /// |
| 118 | | /// Protected by Compilation's mutex. |
| 119 | | files: std.AutoArrayHashMapUnmanaged(Cache.BinDigest, Decl.OptionalIndex) = .{}, |
| 120 | | |
| 121 | 108 | /// The set of all the files which have been loaded with `@embedFile` in the Module. |
| 122 | 109 | /// We keep track of this in order to iterate over it and check which files have been |
| 123 | 110 | /// modified on the file system when an update is requested, as well as to cache |
| ... | ... | @@ -572,19 +559,20 @@ pub const Decl = struct { |
| 572 | 559 | } |
| 573 | 560 | |
| 574 | 561 | pub fn navSrcLine(decl: Decl, zcu: *Zcu) u32 { |
| 562 | const ip = &zcu.intern_pool; |
| 575 | 563 | const tracked = decl.zir_decl_index.unwrap() orelse inst: { |
| 576 | 564 | // generic instantiation |
| 577 | 565 | assert(decl.has_tv); |
| 578 | 566 | assert(decl.owns_tv); |
| 579 | | const generic_owner_func = switch (zcu.intern_pool.indexToKey(decl.val.toIntern())) { |
| 567 | const generic_owner_func = switch (ip.indexToKey(decl.val.toIntern())) { |
| 580 | 568 | .func => |func| func.generic_owner, |
| 581 | 569 | else => return 0, // TODO: this is probably a `variable` or something; figure this out when we finish sorting out `Decl`. |
| 582 | 570 | }; |
| 583 | 571 | const generic_owner_decl = zcu.declPtr(zcu.funcInfo(generic_owner_func).owner_decl); |
| 584 | 572 | break :inst generic_owner_decl.zir_decl_index.unwrap().?; |
| 585 | 573 | }; |
| 586 | | const info = tracked.resolveFull(&zcu.intern_pool); |
| 587 | | const file = zcu.import_table.values()[zcu.files.getIndex(info.path_digest).?]; |
| 574 | const info = tracked.resolveFull(ip); |
| 575 | const file = zcu.fileByIndex(info.file); |
| 588 | 576 | assert(file.zir_loaded); |
| 589 | 577 | const zir = file.zir; |
| 590 | 578 | const inst = zir.instructions.get(@intFromEnum(info.inst)); |
| ... | ... | @@ -969,9 +957,7 @@ pub const File = struct { |
| 969 | 957 | } |
| 970 | 958 | } |
| 971 | 959 | |
| 972 | | pub const Index = enum(u32) { |
| 973 | | _, |
| 974 | | }; |
| 960 | pub const Index = InternPool.FileIndex; |
| 975 | 961 | }; |
| 976 | 962 | |
| 977 | 963 | pub const EmbedFile = struct { |
| ... | ... | @@ -2351,14 +2337,12 @@ pub const LazySrcLoc = struct { |
| 2351 | 2337 | }; |
| 2352 | 2338 | |
| 2353 | 2339 | pub fn resolveBaseNode(base_node_inst: InternPool.TrackedInst.Index, zcu: *Zcu) struct { *File, Ast.Node.Index } { |
| 2354 | | const want_path_digest, const zir_inst = inst: { |
| 2355 | | const info = base_node_inst.resolveFull(&zcu.intern_pool); |
| 2356 | | break :inst .{ info.path_digest, info.inst }; |
| 2357 | | }; |
| 2358 | | const file = file: { |
| 2359 | | const index = zcu.files.getIndex(want_path_digest).?; |
| 2360 | | break :file zcu.import_table.values()[index]; |
| 2340 | const ip = &zcu.intern_pool; |
| 2341 | const file_index, const zir_inst = inst: { |
| 2342 | const info = base_node_inst.resolveFull(ip); |
| 2343 | break :inst .{ info.file, info.inst }; |
| 2361 | 2344 | }; |
| 2345 | const file = zcu.fileByIndex(file_index); |
| 2362 | 2346 | assert(file.zir_loaded); |
| 2363 | 2347 | |
| 2364 | 2348 | const zir = file.zir; |
| ... | ... | @@ -2429,7 +2413,6 @@ pub fn deinit(zcu: *Zcu) void { |
| 2429 | 2413 | zcu.destroyFile(file_index); |
| 2430 | 2414 | } |
| 2431 | 2415 | zcu.import_table.deinit(gpa); |
| 2432 | | zcu.files.deinit(gpa); |
| 2433 | 2416 | |
| 2434 | 2417 | for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| { |
| 2435 | 2418 | gpa.free(path); |
| ... | ... | @@ -2596,7 +2579,16 @@ comptime { |
| 2596 | 2579 | } |
| 2597 | 2580 | } |
| 2598 | 2581 | |
| 2599 | | pub fn astGenFile(zcu: *Zcu, file: *File, path_digest: Cache.BinDigest, opt_root_decl: Zcu.Decl.OptionalIndex) !void { |
| 2582 | pub fn astGenFile( |
| 2583 | zcu: *Zcu, |
| 2584 | file: *File, |
| 2585 | /// This parameter is provided separately from `file` because it is not |
| 2586 | /// safe to access `import_table` without a lock, and this index is needed |
| 2587 | /// in the call to `updateZirRefs`. |
| 2588 | file_index: File.Index, |
| 2589 | path_digest: Cache.BinDigest, |
| 2590 | opt_root_decl: Zcu.Decl.OptionalIndex, |
| 2591 | ) !void { |
| 2600 | 2592 | assert(!file.mod.isBuiltin()); |
| 2601 | 2593 | |
| 2602 | 2594 | const tracy = trace(@src()); |
| ... | ... | @@ -2850,7 +2842,7 @@ pub fn astGenFile(zcu: *Zcu, file: *File, path_digest: Cache.BinDigest, opt_root |
| 2850 | 2842 | } |
| 2851 | 2843 | |
| 2852 | 2844 | if (file.prev_zir) |prev_zir| { |
| 2853 | | try updateZirRefs(zcu, file, prev_zir.*, path_digest); |
| 2845 | try updateZirRefs(zcu, file, file_index, prev_zir.*); |
| 2854 | 2846 | // No need to keep previous ZIR. |
| 2855 | 2847 | prev_zir.deinit(gpa); |
| 2856 | 2848 | gpa.destroy(prev_zir); |
| ... | ... | @@ -2939,7 +2931,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) |
| 2939 | 2931 | |
| 2940 | 2932 | /// This is called from the AstGen thread pool, so must acquire |
| 2941 | 2933 | /// the Compilation mutex when acting on shared state. |
| 2942 | | fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir, path_digest: Cache.BinDigest) !void { |
| 2934 | fn updateZirRefs(zcu: *Module, file: *File, file_index: File.Index, old_zir: Zir) !void { |
| 2943 | 2935 | const gpa = zcu.gpa; |
| 2944 | 2936 | const new_zir = file.zir; |
| 2945 | 2937 | |
| ... | ... | @@ -2955,7 +2947,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir, path_digest: Cache.Bin |
| 2955 | 2947 | // iterating over this full set for every updated file. |
| 2956 | 2948 | for (zcu.intern_pool.tracked_insts.keys(), 0..) |*ti, idx_raw| { |
| 2957 | 2949 | const ti_idx: InternPool.TrackedInst.Index = @enumFromInt(idx_raw); |
| 2958 | | if (!std.mem.eql(u8, &ti.path_digest, &path_digest)) continue; |
| 2950 | if (ti.file != file_index) continue; |
| 2959 | 2951 | const old_inst = ti.inst; |
| 2960 | 2952 | ti.inst = inst_map.get(ti.inst) orelse { |
| 2961 | 2953 | // Tracking failed for this instruction. Invalidate associated `src_hash` deps. |
| ... | ... | @@ -3849,7 +3841,7 @@ fn getFileRootStruct( |
| 3849 | 3841 | const decls = file.zir.bodySlice(extra_index, decls_len); |
| 3850 | 3842 | extra_index += decls_len; |
| 3851 | 3843 | |
| 3852 | | const tracked_inst = try ip.trackZir(gpa, zcu.filePathDigest(file_index), .main_struct_inst); |
| 3844 | const tracked_inst = try ip.trackZir(gpa, file_index, .main_struct_inst); |
| 3853 | 3845 | const wip_ty = switch (try ip.getStructType(gpa, .{ |
| 3854 | 3846 | .layout = .auto, |
| 3855 | 3847 | .fields_len = fields_len, |
| ... | ... | @@ -4151,7 +4143,7 @@ fn semaDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult { |
| 4151 | 4143 | // Every Decl (other than file root Decls, which do not have a ZIR index) has a dependency on its own source. |
| 4152 | 4144 | try sema.declareDependency(.{ .src_hash = try ip.trackZir( |
| 4153 | 4145 | gpa, |
| 4154 | | zcu.filePathDigest(decl.getFileScopeIndex(zcu)), |
| 4146 | decl.getFileScopeIndex(zcu), |
| 4155 | 4147 | decl_inst, |
| 4156 | 4148 | ) }); |
| 4157 | 4149 | |
| ... | ... | @@ -4391,17 +4383,19 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult { |
| 4391 | 4383 | }; |
| 4392 | 4384 | } |
| 4393 | 4385 | |
| 4394 | | try zcu.files.ensureUnusedCapacity(gpa, 1); |
| 4386 | const ip = &zcu.intern_pool; |
| 4387 | |
| 4388 | try ip.files.ensureUnusedCapacity(gpa, 1); |
| 4395 | 4389 | |
| 4396 | 4390 | if (mod.builtin_file) |builtin_file| { |
| 4397 | 4391 | keep_resolved_path = true; // It's now owned by import_table. |
| 4398 | 4392 | gop.value_ptr.* = builtin_file; |
| 4399 | 4393 | try builtin_file.addReference(zcu.*, .{ .root = mod }); |
| 4400 | 4394 | const path_digest = computePathDigest(zcu, mod, builtin_file.sub_file_path); |
| 4401 | | zcu.files.putAssumeCapacityNoClobber(path_digest, .none); |
| 4395 | ip.files.putAssumeCapacityNoClobber(path_digest, .none); |
| 4402 | 4396 | return .{ |
| 4403 | 4397 | .file = builtin_file, |
| 4404 | | .file_index = @enumFromInt(zcu.files.entries.len - 1), |
| 4398 | .file_index = @enumFromInt(ip.files.entries.len - 1), |
| 4405 | 4399 | .is_new = false, |
| 4406 | 4400 | .is_pkg = true, |
| 4407 | 4401 | }; |
| ... | ... | @@ -4431,10 +4425,10 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult { |
| 4431 | 4425 | const path_digest = computePathDigest(zcu, mod, sub_file_path); |
| 4432 | 4426 | |
| 4433 | 4427 | try new_file.addReference(zcu.*, .{ .root = mod }); |
| 4434 | | zcu.files.putAssumeCapacityNoClobber(path_digest, .none); |
| 4428 | ip.files.putAssumeCapacityNoClobber(path_digest, .none); |
| 4435 | 4429 | return .{ |
| 4436 | 4430 | .file = new_file, |
| 4437 | | .file_index = @enumFromInt(zcu.files.entries.len - 1), |
| 4431 | .file_index = @enumFromInt(ip.files.entries.len - 1), |
| 4438 | 4432 | .is_new = true, |
| 4439 | 4433 | .is_pkg = true, |
| 4440 | 4434 | }; |
| ... | ... | @@ -4486,7 +4480,9 @@ pub fn importFile( |
| 4486 | 4480 | .is_pkg = false, |
| 4487 | 4481 | }; |
| 4488 | 4482 | |
| 4489 | | try zcu.files.ensureUnusedCapacity(gpa, 1); |
| 4483 | const ip = &zcu.intern_pool; |
| 4484 | |
| 4485 | try ip.files.ensureUnusedCapacity(gpa, 1); |
| 4490 | 4486 | |
| 4491 | 4487 | const new_file = try gpa.create(File); |
| 4492 | 4488 | errdefer gpa.destroy(new_file); |
| ... | ... | @@ -4528,10 +4524,10 @@ pub fn importFile( |
| 4528 | 4524 | }; |
| 4529 | 4525 | |
| 4530 | 4526 | const path_digest = computePathDigest(zcu, mod, sub_file_path); |
| 4531 | | zcu.files.putAssumeCapacityNoClobber(path_digest, .none); |
| 4527 | ip.files.putAssumeCapacityNoClobber(path_digest, .none); |
| 4532 | 4528 | return .{ |
| 4533 | 4529 | .file = new_file, |
| 4534 | | .file_index = @enumFromInt(zcu.files.entries.len - 1), |
| 4530 | .file_index = @enumFromInt(ip.files.entries.len - 1), |
| 4535 | 4531 | .is_new = true, |
| 4536 | 4532 | .is_pkg = false, |
| 4537 | 4533 | }; |
| ... | ... | @@ -4892,7 +4888,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4892 | 4888 | } |
| 4893 | 4889 | |
| 4894 | 4890 | const parent_file_scope_index = iter.parent_decl.getFileScopeIndex(zcu); |
| 4895 | | const tracked_inst = try ip.trackZir(gpa, zcu.filePathDigest(parent_file_scope_index), decl_inst); |
| 4891 | const tracked_inst = try ip.trackZir(gpa, parent_file_scope_index, decl_inst); |
| 4896 | 4892 | |
| 4897 | 4893 | // We create a Decl for it regardless of analysis status. |
| 4898 | 4894 | |
| ... | ... | @@ -5743,7 +5739,7 @@ fn reportRetryableFileError( |
| 5743 | 5739 | const err_msg = try ErrorMsg.create( |
| 5744 | 5740 | gpa, |
| 5745 | 5741 | .{ |
| 5746 | | .base_node_inst = try ip.trackZir(gpa, zcu.filePathDigest(file_index), .main_struct_inst), |
| 5742 | .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst), |
| 5747 | 5743 | .offset = .entire_file, |
| 5748 | 5744 | }, |
| 5749 | 5745 | format, |
| ... | ... | @@ -6601,13 +6597,16 @@ pub fn fileByIndex(zcu: *const Zcu, i: File.Index) *File { |
| 6601 | 6597 | |
| 6602 | 6598 | /// Returns the `Decl` of the struct that represents this `File`. |
| 6603 | 6599 | pub fn fileRootDecl(zcu: *const Zcu, i: File.Index) Decl.OptionalIndex { |
| 6604 | | return zcu.files.values()[@intFromEnum(i)]; |
| 6600 | const ip = &zcu.intern_pool; |
| 6601 | return ip.files.values()[@intFromEnum(i)]; |
| 6605 | 6602 | } |
| 6606 | 6603 | |
| 6607 | 6604 | pub fn setFileRootDecl(zcu: *Zcu, i: File.Index, root_decl: Decl.OptionalIndex) void { |
| 6608 | | zcu.files.values()[@intFromEnum(i)] = root_decl; |
| 6605 | const ip = &zcu.intern_pool; |
| 6606 | ip.files.values()[@intFromEnum(i)] = root_decl; |
| 6609 | 6607 | } |
| 6610 | 6608 | |
| 6611 | 6609 | pub fn filePathDigest(zcu: *const Zcu, i: File.Index) Cache.BinDigest { |
| 6612 | | return zcu.files.keys()[@intFromEnum(i)]; |
| 6610 | const ip = &zcu.intern_pool; |
| 6611 | return ip.files.keys()[@intFromEnum(i)]; |
| 6613 | 6612 | } |