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
3 changes: 2 additions & 1 deletion crates/oxc_allocator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ serde = { workspace = true }
serde_json = { workspace = true }

[features]
fixed_size = ["from_raw_parts", "dep:oxc_ast_macros"]
fixed_size = ["from_raw_parts", "pool", "dep:oxc_ast_macros"]
disable_fixed_size = []
from_raw_parts = []
pool = []
serialize = ["dep:serde", "oxc_estree/serialize"]
track_allocations = []
disable_track_allocations = []
1 change: 1 addition & 0 deletions crates/oxc_allocator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This approach is significantly faster than using the system allocator for AST op
## Features

- `serialize` - Enables serialization support for `Box` and `Vec` with `serde` and `oxc_estree`.
- `pool` - Enables `AllocatorPool`.
- `from_raw_parts` - Adds unsafe `from_raw_parts` method (not recommended for general use).
- `fixed_size` - Makes `AllocatorPool` create large fixed-size allocators, instead of flexibly-sized ones.
Only supported on 64-bit little-endian platforms at present.
Expand Down
54 changes: 36 additions & 18 deletions crates/oxc_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
//!
//! * `serialize` - Enables serialization support for [`Box`] and [`Vec`] with `serde` and `oxc_estree`.
//!
//! * `pool` - Enables [`AllocatorPool`].
//!
//! * `from_raw_parts` - Adds [`Allocator::from_raw_parts`] method.
//! Usage of this feature is not advisable, and it will be removed as soon as we're able to.
//!
Expand Down Expand Up @@ -67,22 +69,27 @@ pub use vec::Vec;

// Fixed size allocators are only supported on 64-bit little-endian platforms at present

#[cfg(not(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
)))]
#[cfg(all(
feature = "pool",
not(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))
))]
mod pool;

#[cfg(all(
feature = "pool",
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
mod pool_fixed_size;
#[cfg(all(
feature = "pool",
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
Expand All @@ -94,6 +101,7 @@ use pool_fixed_size as pool;
// so this is required to avoid unused vars lint warning in release mode.
#[cfg(all(
debug_assertions,
feature = "pool",
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
Expand All @@ -102,23 +110,28 @@ use pool_fixed_size as pool;
use pool_fixed_size::FixedSizeAllocatorMetadata;
// Export so can be used in `napi/oxlint2`
#[cfg(all(
feature = "pool",
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
pub use pool_fixed_size::free_fixed_size_allocator;

#[cfg(feature = "pool")]
pub use pool::{AllocatorGuard, AllocatorPool};

// Dummy implementations of interfaces from `pool_fixed_size`, just to stop clippy complaining.
// Seems to be necessary due to feature unification.
#[cfg(not(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
)))]
#[cfg(all(
feature = "pool",
not(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))
))]
#[allow(missing_docs, clippy::missing_safety_doc, clippy::unused_self, clippy::allow_attributes)]
mod dummies {
use std::{ptr::NonNull, sync::atomic::AtomicBool};
Expand All @@ -144,15 +157,19 @@ mod dummies {
}
}
}
#[cfg(not(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
)))]
#[cfg(all(
feature = "pool",
not(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))
))]
pub use dummies::*;

#[cfg(all(
feature = "pool",
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
Expand All @@ -164,6 +181,7 @@ mod generated {
pub mod fixed_size_constants;
}
#[cfg(all(
feature = "pool",
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ workspace = true
doctest = true

[dependencies]
oxc_allocator = { workspace = true }
oxc_allocator = { workspace = true, features = ["pool"] }
oxc_ast = { workspace = true }
oxc_ast_macros = { workspace = true, optional = true }
oxc_ast_visit = { workspace = true }
Expand Down
Loading