From 6535834494439e7e1ee5ece886564060cdb4f1aa Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 26 May 2026 06:03:04 +0000 Subject: [PATCH] refactor: drop allocator-api2 in favor of bumpalo::collections The allocator-api2 trait was only used to allow `bumpalo::Bump` to back the arena's `Vec` allocations. Switching to `bumpalo::collections::Vec` and `Bump::alloc_slice_copy` removes the abstraction layer, drops a workspace dependency, and unblocks future bumpalo upgrades (bumpalo still pins allocator-api2 to ^0.2.8, which prevents updating allocator-api2 to 0.4.x). --- Cargo.lock | 8 ++------ Cargo.toml | 3 +-- crates/fspy/Cargo.toml | 1 - crates/fspy/src/arena.rs | 5 ++--- crates/fspy_shared/Cargo.toml | 2 +- crates/fspy_shared/src/ipc/native_path.rs | 9 +++------ crates/native_str/Cargo.toml | 2 +- crates/native_str/src/lib.rs | 13 +++---------- 8 files changed, 13 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0be84b5df..eb132b9de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,9 +350,6 @@ name = "bumpalo" version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" -dependencies = [ - "allocator-api2", -] [[package]] name = "bytemuck" @@ -1232,7 +1229,6 @@ dependencies = [ name = "fspy" version = "0.1.0" dependencies = [ - "allocator-api2", "anyhow", "bstr", "bumpalo", @@ -1342,10 +1338,10 @@ dependencies = [ name = "fspy_shared" version = "0.0.0" dependencies = [ - "allocator-api2", "assert2", "bitflags 2.10.0", "bstr", + "bumpalo", "bytemuck", "ctor", "native_str", @@ -2040,7 +2036,7 @@ dependencies = [ name = "native_str" version = "0.0.0" dependencies = [ - "allocator-api2", + "bumpalo", "bytemuck", "wincode", ] diff --git a/Cargo.toml b/Cargo.toml index 5d349b26a..a9934d3a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ multiple_crate_versions = "allow" future_not_send = "allow" [workspace.dependencies] -allocator-api2 = { version = "0.2.21", default-features = false, features = ["alloc", "std"] } anstream = "1.0.0" anyhow = "1.0.98" assert2 = "0.4.0" @@ -51,7 +50,7 @@ bindgen = "0.72.1" bitflags = "2.10.0" brush-parser = "0.4.0" bstr = { version = "1.12.0", default-features = false, features = ["alloc", "std"] } -bumpalo = { version = "3.17.0", features = ["allocator-api2"] } +bumpalo = { version = "3.17.0", features = ["collections"] } bytemuck = { version = "1.23.0", features = ["extern_crate_alloc", "must_cast"] } cc = "1.2.39" clap = "4.5.53" diff --git a/crates/fspy/Cargo.toml b/crates/fspy/Cargo.toml index 8c1018596..f99d25241 100644 --- a/crates/fspy/Cargo.toml +++ b/crates/fspy/Cargo.toml @@ -6,7 +6,6 @@ license.workspace = true publish = false [dependencies] -allocator-api2 = { workspace = true, features = ["alloc"] } wincode = { workspace = true } bstr = { workspace = true, default-features = false } bumpalo = { workspace = true } diff --git a/crates/fspy/src/arena.rs b/crates/fspy/src/arena.rs index aa6dde788..e0d466ba7 100644 --- a/crates/fspy/src/arena.rs +++ b/crates/fspy/src/arena.rs @@ -1,5 +1,4 @@ -use allocator_api2::vec::Vec; -use bumpalo::Bump; +use bumpalo::{Bump, collections::Vec}; use crate::PathAccess; @@ -10,7 +9,7 @@ pub struct PathAccessArena { #[borrows(bump)] #[covariant] // TODO(pref): use linked list to avoid realloc & copy. We don't need random access. - pub accesses: Vec, &'this Bump>, + pub accesses: Vec<'this, PathAccess<'this>>, } impl Default for PathAccessArena { diff --git a/crates/fspy_shared/Cargo.toml b/crates/fspy_shared/Cargo.toml index 78ae69704..a9e21b003 100644 --- a/crates/fspy_shared/Cargo.toml +++ b/crates/fspy_shared/Cargo.toml @@ -6,9 +6,9 @@ license.workspace = true publish = false [dependencies] -allocator-api2 = { workspace = true } wincode = { workspace = true, features = ["derive"] } bitflags = { workspace = true } +bumpalo = { workspace = true } bstr = { workspace = true } bytemuck = { workspace = true, features = ["must_cast", "derive"] } native_str = { workspace = true } diff --git a/crates/fspy_shared/src/ipc/native_path.rs b/crates/fspy_shared/src/ipc/native_path.rs index 26903e9e6..95e392076 100644 --- a/crates/fspy_shared/src/ipc/native_path.rs +++ b/crates/fspy_shared/src/ipc/native_path.rs @@ -7,7 +7,7 @@ use std::{ path::{Path, StripPrefixError}, }; -use allocator_api2::alloc::Allocator; +use bumpalo::Bump; use bytemuck::TransparentWrapper; use native_str::NativeStr; use wincode::{ @@ -61,11 +61,8 @@ impl NativePath { Self::wrap_ref(NativeStr::from_wide(wide)) } - pub fn clone_in<'new_alloc, A>(&self, alloc: &'new_alloc A) -> &'new_alloc Self - where - &'new_alloc A: Allocator, - { - Self::wrap_ref(self.inner.clone_in(alloc)) + pub fn clone_in<'bump>(&self, bump: &'bump Bump) -> &'bump Self { + Self::wrap_ref(self.inner.clone_in(bump)) } pub fn strip_path_prefix, R, F: FnOnce(Result<&Path, StripPrefixError>) -> R>( diff --git a/crates/native_str/Cargo.toml b/crates/native_str/Cargo.toml index 2baa2d181..0b84da406 100644 --- a/crates/native_str/Cargo.toml +++ b/crates/native_str/Cargo.toml @@ -7,7 +7,7 @@ publish = false rust-version.workspace = true [dependencies] -allocator-api2 = { workspace = true } +bumpalo = { workspace = true } bytemuck = { workspace = true, features = ["must_cast", "derive"] } wincode = { workspace = true } diff --git a/crates/native_str/src/lib.rs b/crates/native_str/src/lib.rs index 84a841a07..64d4a930a 100644 --- a/crates/native_str/src/lib.rs +++ b/crates/native_str/src/lib.rs @@ -8,7 +8,7 @@ use std::os::windows::ffi::OsStrExt as _; use std::os::windows::ffi::OsStringExt as _; use std::{borrow::Cow, ffi::OsStr, fmt::Debug, mem::MaybeUninit}; -use allocator_api2::alloc::Allocator; +use bumpalo::Bump; #[cfg(windows)] use bytemuck::must_cast_slice; use bytemuck::{TransparentWrapper, TransparentWrapperAlloc}; @@ -87,15 +87,8 @@ impl NativeStr { return Cow::Borrowed(self.as_os_str()); } - pub fn clone_in<'new_alloc, A>(&self, alloc: &'new_alloc A) -> &'new_alloc Self - where - &'new_alloc A: Allocator, - { - use allocator_api2::vec::Vec; - let mut data = Vec::::with_capacity_in(self.data.len(), alloc); - data.extend_from_slice(&self.data); - let data = data.leak::<'new_alloc>(); - Self::wrap_ref(data) + pub fn clone_in<'bump>(&self, bump: &'bump Bump) -> &'bump Self { + Self::wrap_ref(bump.alloc_slice_copy(&self.data)) } }