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
2 changes: 1 addition & 1 deletion apps/oxlint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ lazy-regex = { workspace = true }
default = []
allocator = ["dep:mimalloc-safe"]
oxlint2 = ["oxc_linter/oxlint2", "oxc_allocator/fixed_size", "dep:simdutf8"]
disable_oxlint2 = ["oxc_linter/disable_oxlint2", "oxc_allocator/disable_fixed_size"]
disable_oxlint2 = ["oxc_linter/disable_oxlint2"]
force_test_reporter = ["oxc_linter/force_test_reporter"]
1 change: 0 additions & 1 deletion crates/oxc_allocator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ serde_json = { workspace = true }
[features]
bitset = []
fixed_size = ["from_raw_parts", "pool", "dep:oxc_ast_macros"]
disable_fixed_size = []
from_raw_parts = []
pool = []
serialize = ["dep:serde", "oxc_estree/serialize"]
Expand Down
2 changes: 0 additions & 2 deletions crates/oxc_allocator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,5 @@ This approach is significantly faster than using the system allocator for AST op
- `track_allocations` - Count allocations and reallocations.
For internal use only. The APIs provided by this feature are sketchy at best, and possibly
undefined behavior. Do not enable this feature under any circumstances in production code.
- `disable_fixed_size` - Disables `fixed_size` feature.
Purpose is to prevent `--all-features` enabling fixed sized allocators.
- `disable_track_allocations` - Disables `track_allocations` feature.
Purpose is to prevent `--all-features` enabling allocation tracking.
10 changes: 1 addition & 9 deletions crates/oxc_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
//! For internal use only. The APIs provided by this feature are sketchy at best, and possibly
//! undefined behavior. Do not enable this feature under any circumstances in production code.
//!
//! * `disable_fixed_size` - Disables `fixed_size` feature.
//! Purpose is to prevent `--all-features` enabling fixed sized allocators.
//!
//! * `disable_track_allocations` - Disables `track_allocations` feature.
//! Purpose is to prevent `--all-features` enabling allocation tracking.

Expand Down Expand Up @@ -80,12 +77,7 @@ pub use vec::Vec;
// Fixed size allocators are only supported on 64-bit little-endian platforms at present.
//
// Note: Importing the `fixed_size_constants` module would cause a compilation error on 32-bit systems.
#[cfg(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
#[cfg(all(feature = "fixed_size", target_pointer_width = "64", target_endian = "little"))]
mod generated {
#[cfg(debug_assertions)]
mod assert_layouts;
Expand Down
47 changes: 7 additions & 40 deletions crates/oxc_allocator/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,16 @@ mod standard;
use standard::StandardAllocatorPool;

// Fixed size allocators are only supported on 64-bit little-endian platforms at present.
// They are only enabled if `fixed_size` feature enabled, and `disable_fixed_size` feature is not enabled.
// They are only enabled if `fixed_size` Cargo feature is enabled.
//
// Note: Importing the `fixed_size` module would cause a compilation error on 32-bit systems.
#[cfg(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
#[cfg(all(feature = "fixed_size", target_pointer_width = "64", target_endian = "little"))]
mod fixed_size;
#[cfg(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
#[cfg(all(feature = "fixed_size", target_pointer_width = "64", target_endian = "little"))]
use fixed_size::FixedSizeAllocatorPool;
#[cfg(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
#[cfg(all(feature = "fixed_size", target_pointer_width = "64", target_endian = "little"))]
pub use fixed_size::{FixedSizeAllocatorMetadata, free_fixed_size_allocator};

// Dummy implementations of interfaces from `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"
)))]
pub use standard::{FixedSizeAllocatorMetadata, free_fixed_size_allocator};

/// A thread-safe pool for reusing [`Allocator`] instances to reduce allocation overhead.
///
/// Uses either:
Expand All @@ -51,20 +26,14 @@ pub use standard::{FixedSizeAllocatorMetadata, free_fixed_size_allocator};
/// Fixed-size allocator pool is created by [`AllocatorPool::new_fixed_size`].
///
/// Fixed-size allocators are only supported on 64-bit little-endian platforms at present,
/// and require the `fixed_size` Cargo feature to be enabled, and `disable_fixed_size` Cargo feature
/// to not be enabled.
/// and require the `fixed_size` Cargo feature to be enabled.
#[repr(transparent)]
pub struct AllocatorPool(AllocatorPoolInner);

/// Inner type of [`AllocatorPool`], holding either a standard or fixed-size allocator pool.
enum AllocatorPoolInner {
Standard(StandardAllocatorPool),
#[cfg(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
#[cfg(all(feature = "fixed_size", target_pointer_width = "64", target_endian = "little"))]
FixedSize(FixedSizeAllocatorPool),
}

Expand All @@ -77,7 +46,7 @@ impl AllocatorPool {

/// Create a new [`AllocatorPool`] for use across the specified number of threads,
/// which uses fixed-size allocators (suitable for raw transfer).
#[cfg(all(feature = "fixed_size", not(feature = "disable_fixed_size")))]
#[cfg(feature = "fixed_size")]
pub fn new_fixed_size(thread_count: usize) -> AllocatorPool {
#[cfg(all(target_pointer_width = "64", target_endian = "little"))]
{
Expand All @@ -102,7 +71,6 @@ impl AllocatorPool {
AllocatorPoolInner::Standard(pool) => pool.get(),
#[cfg(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
Expand All @@ -128,7 +96,6 @@ impl AllocatorPool {
AllocatorPoolInner::Standard(pool) => pool.add(allocator),
#[cfg(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
))]
Expand Down
47 changes: 0 additions & 47 deletions crates/oxc_allocator/src/pool/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,3 @@ impl StandardAllocatorPool {
allocators.push(allocator);
}
}

// Dummy implementations of interfaces from `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"
)))]
#[allow(
dead_code,
missing_docs,
clippy::missing_safety_doc,
clippy::unused_self,
clippy::allow_attributes
)]
mod dummies {
use std::{ptr::NonNull, sync::atomic::AtomicBool};

use crate::Allocator;

#[doc(hidden)]
pub struct FixedSizeAllocatorMetadata {
pub id: u32,
pub(crate) alloc_ptr: NonNull<u8>,
pub is_double_owned: AtomicBool,
}

#[doc(hidden)]
pub unsafe fn free_fixed_size_allocator(_metadata_ptr: NonNull<FixedSizeAllocatorMetadata>) {
unreachable!();
}

#[doc(hidden)]
impl Allocator {
pub unsafe fn fixed_size_metadata_ptr(&self) -> NonNull<FixedSizeAllocatorMetadata> {
unreachable!();
}
}
}
#[cfg(not(all(
feature = "fixed_size",
not(feature = "disable_fixed_size"),
target_pointer_width = "64",
target_endian = "little"
)))]
pub use dummies::*;
Loading