remove many usingnamespace, introduce new ref count and ref leak debugging tools (#18353)

This commit is contained in:
chloe caruso
2025-03-31 17:17:38 -07:00
committed by GitHub
parent 323d78df5e
commit a199b85f2b
99 changed files with 1857 additions and 1018 deletions

View File

@@ -191,7 +191,7 @@ pub fn parseJSON(
.fail => |fail| return fail.err,
};
const ptr = ParsedSourceMap.new(map_data);
const ptr = bun.new(ParsedSourceMap, map_data);
ptr.external_source_names = source_paths_slice.?;
break :map ptr;
} else null;
@@ -582,6 +582,7 @@ pub const Mapping = struct {
}
return .{ .success = .{
.ref_count = .init(),
.mappings = mapping,
.input_line_count = input_line_count,
} };
@@ -612,6 +613,14 @@ pub const ParseResult = union(enum) {
};
pub const ParsedSourceMap = struct {
const RefCount = bun.ptr.ThreadSafeRefCount(@This(), "ref_count", deinit, .{});
pub const ref = RefCount.ref;
pub const deref = RefCount.deref;
/// ParsedSourceMap can be acquired by different threads via the thread-safe
/// source map store (SavedSourceMap), so the reference count must be thread-safe.
ref_count: RefCount,
input_line_count: usize = 0,
mappings: Mapping.List = .{},
/// If this is empty, this implies that the source code is a single file
@@ -629,12 +638,8 @@ pub const ParsedSourceMap = struct {
/// rely on source contents)
underlying_provider: SourceContentPtr = .none,
ref_count: std.atomic.Value(u32) = .init(1),
is_standalone_module_graph: bool = false,
pub usingnamespace bun.NewThreadSafeRefCounted(ParsedSourceMap, deinitFn, null);
const SourceContentPtr = packed struct(u64) {
load_hint: SourceMapLoadHint,
data: u62,
@@ -654,11 +659,9 @@ pub const ParsedSourceMap = struct {
return psm.external_source_names.len != 0;
}
fn deinitFn(this: *ParsedSourceMap) void {
this.deinitWithAllocator(bun.default_allocator);
}
fn deinit(this: *ParsedSourceMap) void {
const allocator = bun.default_allocator;
fn deinitWithAllocator(this: *ParsedSourceMap, allocator: std.mem.Allocator) void {
this.mappings.deinit(allocator);
if (this.external_source_names.len > 0) {
@@ -667,7 +670,7 @@ pub const ParsedSourceMap = struct {
allocator.free(this.external_source_names);
}
this.destroy();
bun.destroy(this);
}
fn standaloneModuleGraphData(this: *ParsedSourceMap) *bun.StandaloneModuleGraph.SerializedSourceMap.Loaded {