diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2024-07-10 10:43:51 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2024-07-10 11:20:08 -0400 |
| commit | f290b54f891a67af456529da0f4f824a1e27b4ef (patch) | |
| tree | db471701e43acc6f640643fab8ba529162daa69f /src/Zcu/PerThread.zig | |
| parent | 8f292431b03055e789f75aa98888c0f49520e268 (diff) | |
| download | zig-f290b54f891a67af456529da0f4f824a1e27b4ef.tar.gz zig-f290b54f891a67af456529da0f4f824a1e27b4ef.zip | |
InternPool: make `files` more thread-safe
Diffstat (limited to 'src/Zcu/PerThread.zig')
| -rw-r--r-- | src/Zcu/PerThread.zig | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 03d9b08261..7fa9f89d40 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -1386,15 +1386,16 @@ pub fn importPkg(pt: Zcu.PerThread, mod: *Module) !Zcu.ImportFileResult { } const ip = &zcu.intern_pool; - try ip.files.ensureUnusedCapacity(gpa, 1); - if (mod.builtin_file) |builtin_file| { - const file_index = try ip.createFile(gpa, pt.tid, builtin_file); + const path_digest = Zcu.computePathDigest(zcu, mod, builtin_file.sub_file_path); + const file_index = try ip.createFile(gpa, pt.tid, .{ + .bin_digest = path_digest, + .file = builtin_file, + .root_decl = .none, + }); keep_resolved_path = true; // It's now owned by import_table. gop.value_ptr.* = file_index; try builtin_file.addReference(zcu, .{ .root = mod }); - const path_digest = Zcu.computePathDigest(zcu, mod, builtin_file.sub_file_path); - ip.files.putAssumeCapacityNoClobber(path_digest, .none); return .{ .file = builtin_file, .file_index = file_index, @@ -1409,7 +1410,12 @@ pub fn importPkg(pt: Zcu.PerThread, mod: *Module) !Zcu.ImportFileResult { const new_file = try gpa.create(Zcu.File); errdefer gpa.destroy(new_file); - const new_file_index = try ip.createFile(gpa, pt.tid, new_file); + const path_digest = zcu.computePathDigest(mod, sub_file_path); + const new_file_index = try ip.createFile(gpa, pt.tid, .{ + .bin_digest = path_digest, + .file = new_file, + .root_decl = .none, + }); keep_resolved_path = true; // It's now owned by import_table. gop.value_ptr.* = new_file_index; new_file.* = .{ @@ -1425,10 +1431,7 @@ pub fn importPkg(pt: Zcu.PerThread, mod: *Module) !Zcu.ImportFileResult { .mod = mod, }; - const path_digest = zcu.computePathDigest(mod, sub_file_path); - try new_file.addReference(zcu, .{ .root = mod }); - ip.files.putAssumeCapacityNoClobber(path_digest, .none); return .{ .file = new_file, .file_index = new_file_index, @@ -1489,8 +1492,6 @@ pub fn importFile( const ip = &zcu.intern_pool; - try ip.files.ensureUnusedCapacity(gpa, 1); - const new_file = try gpa.create(Zcu.File); errdefer gpa.destroy(new_file); @@ -1515,7 +1516,12 @@ pub fn importFile( resolved_root_path, resolved_path, sub_file_path, import_string, }); - const new_file_index = try ip.createFile(gpa, pt.tid, new_file); + const path_digest = zcu.computePathDigest(mod, sub_file_path); + const new_file_index = try ip.createFile(gpa, pt.tid, .{ + .bin_digest = path_digest, + .file = new_file, + .root_decl = .none, + }); keep_resolved_path = true; // It's now owned by import_table. gop.value_ptr.* = new_file_index; new_file.* = .{ @@ -1531,8 +1537,6 @@ pub fn importFile( .mod = mod, }; - const path_digest = zcu.computePathDigest(mod, sub_file_path); - ip.files.putAssumeCapacityNoClobber(path_digest, .none); return .{ .file = new_file, .file_index = new_file_index, |
