From bb7776116d4988f8ab836712ba90f0d29c885db8 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 30 Jan 2025 07:11:03 -0800 Subject: [PATCH] https://github.com/ziglang/zig/issues/18949 --- src/Watcher.zig | 2 +- src/baby_list.zig | 6 ++++++ src/bun.js/test/jest.zig | 4 ++-- src/bundler/bundle_v2.zig | 6 +++--- src/js_ast.zig | 6 +++--- src/options.zig | 2 +- src/resolver/package_json.zig | 2 +- src/resolver/resolver.zig | 2 +- src/router.zig | 6 +++--- src/sourcemap/sourcemap.zig | 2 +- src/string_mutable.zig | 2 +- src/url.zig | 2 +- src/watcher.zig | 2 +- 13 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/Watcher.zig b/src/Watcher.zig index 7639bc11be..44e9252169 100644 --- a/src/Watcher.zig +++ b/src/Watcher.zig @@ -5,7 +5,7 @@ pub const max_count = 128; pub const Event = WatchEvent; pub const Item = WatchItem; pub const ItemList = WatchList; -pub const WatchList = std.MultiArrayList(WatchItem); +pub const WatchList = bun.MultiArrayList(WatchItem); pub const HashType = u32; const no_watch_item: WatchItemIndex = std.math.maxInt(WatchItemIndex); diff --git a/src/baby_list.zig b/src/baby_list.zig index 4db8655638..0484513ae4 100644 --- a/src/baby_list.zig +++ b/src/baby_list.zig @@ -52,7 +52,13 @@ pub fn BabyList(comptime Type: type) type { pub fn shrinkAndFree(this: *@This(), allocator: std.mem.Allocator, size: usize) void { var list_ = this.listManaged(allocator); + const new_len = @min(size, @as(usize, list_.items.len)); + + // Workaround terrible zig std.ArrayList shrinkAndFree() behavior + list_.items.len = list_.capacity; list_.shrinkAndFree(size); + list_.items.len = new_len; + this.update(list_); } diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 4220c41e11..63f736543a 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -250,7 +250,7 @@ pub const TestRunner = struct { log: logger.Log = logger.Log.initComptime(default_allocator), module_scope: *DescribeScope = undefined, - pub const List = std.MultiArrayList(File); + pub const List = bun.MultiArrayList(File); pub const ID = u32; pub const Map = std.ArrayHashMapUnmanaged(u32, u32, ArrayIdentityContext, false); }; @@ -259,7 +259,7 @@ pub const TestRunner = struct { status: Status = Status.pending, pub const ID = u32; - pub const List = std.MultiArrayList(Test); + pub const List = bun.MultiArrayList(Test); pub const Status = enum(u3) { pending, diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 066843e323..3d564fd4aa 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -10269,7 +10269,7 @@ pub const LinkerContext = struct { // Concatenate the generated CSS chunks together const compile_results = chunk.compile_results_for_chunk; - var compile_results_for_source_map: std.MultiArrayList(CompileResultForSourceMap) = .{}; + var compile_results_for_source_map: bun.MultiArrayList(CompileResultForSourceMap) = .{}; compile_results_for_source_map.setCapacity(worker.allocator, compile_results.len) catch bun.outOfMemory(); const sources: []const Logger.Source = c.parse_graph.input_files.items(.source); @@ -10558,7 +10558,7 @@ pub const LinkerContext = struct { // Concatenate the generated JavaScript chunks together var prev_filename_comment: Index.Int = 0; - var compile_results_for_source_map: std.MultiArrayList(CompileResultForSourceMap) = .{}; + var compile_results_for_source_map: bun.MultiArrayList(CompileResultForSourceMap) = .{}; compile_results_for_source_map.setCapacity(worker.allocator, compile_results.len) catch bun.outOfMemory(); const show_comments = c.options.mode == .bundle and @@ -10773,7 +10773,7 @@ pub const LinkerContext = struct { c: *LinkerContext, isolated_hash: u64, worker: *ThreadPool.Worker, - results: std.MultiArrayList(CompileResultForSourceMap), + results: bun.MultiArrayList(CompileResultForSourceMap), chunk_abs_dir: string, can_have_shifts: bool, ) !sourcemap.SourceMapPieces { diff --git a/src/js_ast.zig b/src/js_ast.zig index 3736cbc11c..06fac77bb2 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -8654,7 +8654,7 @@ pub const ServerComponentBoundary = struct { /// speed, but also being able to pull a `[]const Index.Int` of all /// boundaries for iteration. pub const List = struct { - list: std.MultiArrayList(ServerComponentBoundary) = .{}, + list: bun.MultiArrayList(ServerComponentBoundary) = .{}, /// Used to facilitate fast lookups into `items` by `.source_index` map: Map = .{}, @@ -8698,7 +8698,7 @@ pub const ServerComponentBoundary = struct { } pub const Slice = struct { - list: std.MultiArrayList(ServerComponentBoundary).Slice, + list: bun.MultiArrayList(ServerComponentBoundary).Slice, map: Map, pub fn getIndex(l: *const Slice, real_source_index: Index.Int) ?usize { @@ -8727,7 +8727,7 @@ pub const ServerComponentBoundary = struct { }; pub const Adapter = struct { - list: std.MultiArrayList(ServerComponentBoundary).Slice, + list: bun.MultiArrayList(ServerComponentBoundary).Slice, pub fn hash(_: Adapter, key: Index.Int) u32 { return std.hash.uint32(key); diff --git a/src/options.zig b/src/options.zig index c73fa65806..e2de46121f 100644 --- a/src/options.zig +++ b/src/options.zig @@ -1931,7 +1931,7 @@ pub const Env = struct { key: string, value: string, }; - const List = std.MultiArrayList(Entry); + const List = bun.MultiArrayList(Entry); behavior: Api.DotEnvBehavior = Api.DotEnvBehavior.disable, prefix: string = "", diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index 21860d42a3..9220bf480a 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -1204,7 +1204,7 @@ pub const ExportsMap = struct { pub const Map = struct { // This is not a std.ArrayHashMap because we also store the key_range which is a little weird - pub const List = std.MultiArrayList(MapEntry); + pub const List = bun.MultiArrayList(MapEntry); expansion_keys: []MapEntry, list: List, diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 24f81b2fd4..22aa0a6cd1 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -399,7 +399,7 @@ pub const PendingResolution = struct { string_buf: []u8 = "", tag: Tag, - pub const List = std.MultiArrayList(PendingResolution); + pub const List = bun.MultiArrayList(PendingResolution); pub fn deinitListItems(list_: List, allocator: std.mem.Allocator) void { var list = list_; diff --git a/src/router.zig b/src/router.zig index 23f61bf315..bc25e42c71 100644 --- a/src/router.zig +++ b/src/router.zig @@ -35,7 +35,7 @@ pub const Param = struct { name: string, value: string, - pub const List = std.MultiArrayList(Param); + pub const List = bun.MultiArrayList(Param); }; dir: StoredFileDescriptorType = .zero, @@ -102,7 +102,7 @@ const RouteIndex = struct { public_path: string, hash: u32, - pub const List = std.MultiArrayList(RouteIndex); + pub const List = bun.MultiArrayList(RouteIndex); }; pub const Routes = struct { @@ -1553,7 +1553,7 @@ test "Pattern Match" { const TestList = struct { pub fn run(comptime list: anytype) usize { - const ParamListType = std.MultiArrayList(Entry); + const ParamListType = bun.MultiArrayList(Entry); var parameters = ParamListType{}; var failures: usize = 0; inline for (comptime std.meta.fieldNames(@TypeOf(list))) |pattern| { diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index 41ddfd67f1..f895defdda 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -1324,7 +1324,7 @@ pub const LineOffsetTable = struct { byte_offset_to_first_non_ascii: u32 = 0, byte_offset_to_start_of_line: u32 = 0, - pub const List = std.MultiArrayList(LineOffsetTable); + pub const List = bun.MultiArrayList(LineOffsetTable); pub fn findLine(byte_offsets_to_start_of_line: []const u32, loc: Logger.Loc) i32 { assert(loc.start > -1); // checked by caller diff --git a/src/string_mutable.zig b/src/string_mutable.zig index 6b3b08aa4c..bf4627fdee 100644 --- a/src/string_mutable.zig +++ b/src/string_mutable.zig @@ -264,7 +264,7 @@ pub const MutableString = struct { } pub fn toOwnedSliceLength(self: *MutableString, length: usize) string { - self.list.shrinkAndFree(self.allocator, length); + self.list.items.len = @min(length, self.list.items.len); return self.list.toOwnedSlice(self.allocator) catch bun.outOfMemory(); // TODO } diff --git a/src/url.zig b/src/url.zig index 451060cfa1..6335ca20f2 100644 --- a/src/url.zig +++ b/src/url.zig @@ -598,7 +598,7 @@ pub const QueryStringMap = struct { name_hash: u64, value: Api.StringPointer, - pub const List = std.MultiArrayList(Param); + pub const List = bun.MultiArrayList(Param); }; pub fn initWithScanner( diff --git a/src/watcher.zig b/src/watcher.zig index 7639bc11be..44e9252169 100644 --- a/src/watcher.zig +++ b/src/watcher.zig @@ -5,7 +5,7 @@ pub const max_count = 128; pub const Event = WatchEvent; pub const Item = WatchItem; pub const ItemList = WatchList; -pub const WatchList = std.MultiArrayList(WatchItem); +pub const WatchList = bun.MultiArrayList(WatchItem); pub const HashType = u32; const no_watch_item: WatchItemIndex = std.math.maxInt(WatchItemIndex);