Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ allocator-api2 = "=0.2.21" # Allocator trait
base64 = "0.22.1" # Base64 encoding
bitflags = "2.10.0" # Bitflag types
bpaf = "0.9.20" # CLI parser
# `bumpalo` must be pinned to exactly version 3.19.0.
# `Allocator::from_raw_parts` (used in raw transfer) depends on internal implementation details
# of `bumpalo` which may change in a future version.
# This is a temporary situation - we'll replace `bumpalo` with our own allocator.
bumpalo = "=3.19.1" # Bump allocator
compact_str = "0.9.0" # Compact string type
console = "0.16.2" # Terminal utilities
constcat = "0.6.1" # Const string concatenation
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_allocator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ oxc_data_structures = { workspace = true, features = ["assert_unchecked", "stack
oxc_estree = { workspace = true, optional = true }

allocator-api2 = { workspace = true }
bumpalo = { workspace = true, features = ["allocator-api2", "collections"] }
hashbrown = { workspace = true, default-features = false, features = [
"inline-more",
"allocator-api2",
Expand Down
7 changes: 4 additions & 3 deletions crates/oxc_allocator/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::{
};

use allocator_api2::alloc::Allocator;
use bumpalo::Bump;

use crate::bump::Bump;

/// Trait describing an allocator.
///
Expand Down Expand Up @@ -81,7 +82,7 @@ pub trait Alloc {
) -> NonNull<u8>;
}

/// Implement [`Alloc`] for [`bumpalo::Bump`].
/// Implement [`Alloc`] for [`Bump`].
///
/// All methods except `alloc` delegate to [`Bump`]'s impl of `allocator_api2`'s [`Allocator`] trait.
impl Alloc for Bump {
Expand Down Expand Up @@ -114,7 +115,7 @@ impl Alloc for Bump {
#[inline(always)]
unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout) {
// SAFETY: Safety requirements of `Allocator::deallocate` are the same as for this method
unsafe { self.deallocate(ptr, layout) }
unsafe { Allocator::deallocate(&self, ptr, layout) }
}

/// Grow an existing allocation to new [`Layout`].
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_allocator/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
#[cfg(all(feature = "track_allocations", not(feature = "disable_track_allocations")))]
use std::mem::offset_of;

use bumpalo::Bump;
use crate::bump::Bump;

use oxc_data_structures::assert_unchecked;

Expand Down Expand Up @@ -613,7 +613,7 @@ impl Allocator {
bytes
}

/// Get inner [`bumpalo::Bump`].
/// Get inner [`Bump`].
///
/// This method is not public. We don't want to expose `Bump` to user.
/// The fact that we're using `bumpalo` is an internal implementation detail.
Expand All @@ -625,7 +625,7 @@ impl Allocator {
&self.bump
}

/// Create [`Allocator`] from a [`bumpalo::Bump`].
/// Create [`Allocator`] from a [`Bump`].
///
/// This method is not public. Only used by [`Allocator::from_raw_parts`].
//
Expand Down
17 changes: 8 additions & 9 deletions crates/oxc_allocator/src/allocator_api2.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
// All methods just delegate to `bumpalo`, so all marked `#[inline(always)]`.
// All have same safety preconditions of `bumpalo` methods of the same name.
// All methods just delegate to `Bump`, so all marked `#[inline(always)]`.
// All have same safety preconditions of `Bump` methods of the same name.
#![expect(clippy::inline_always, clippy::undocumented_unsafe_blocks)]

use std::{alloc::Layout, ptr::NonNull};

use allocator_api2::alloc::{AllocError, Allocator};

/// SAFETY:
/// <https://github.com/fitzgen/bumpalo/blob/4eeab8847c85d5cde135ca21ae14a54e56b05224/src/lib.rs#L1938>
/// SAFETY: See `bump.rs` for the implementation of `Allocator` for `&Bump`.
unsafe impl Allocator for &crate::Allocator {
#[inline(always)]
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
self.bump().allocate(layout)
Allocator::allocate(&self.bump(), layout)
}

#[inline(always)]
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
unsafe {
self.bump().deallocate(ptr, layout);
Allocator::deallocate(&self.bump(), ptr, layout);
}
}

Expand All @@ -28,7 +27,7 @@ unsafe impl Allocator for &crate::Allocator {
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
unsafe { self.bump().shrink(ptr, old_layout, new_layout) }
unsafe { Allocator::shrink(&self.bump(), ptr, old_layout, new_layout) }
}

#[inline(always)]
Expand All @@ -38,7 +37,7 @@ unsafe impl Allocator for &crate::Allocator {
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
unsafe { self.bump().grow(ptr, old_layout, new_layout) }
unsafe { Allocator::grow(&self.bump(), ptr, old_layout, new_layout) }
}

#[inline(always)]
Expand All @@ -48,6 +47,6 @@ unsafe impl Allocator for &crate::Allocator {
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
unsafe { self.bump().grow_zeroed(ptr, old_layout, new_layout) }
unsafe { Allocator::grow_zeroed(&self.bump(), ptr, old_layout, new_layout) }
}
}
Loading
Loading