Skip to content

Commit e8c0e07

Browse files
committed
refactor(allocator): remove AllocError from fixed size allocator
1 parent fb9e193 commit e8c0e07

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

crates/oxc_allocator/src/pool/fixed_size.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::{
22
alloc::{GlobalAlloc, Layout, System},
33
cmp::max,
4-
error::Error,
5-
fmt,
64
mem::{self, ManuallyDrop},
75
ptr::NonNull,
86
sync::{
@@ -18,26 +16,6 @@ use crate::{
1816
generated::fixed_size_constants::{BLOCK_ALIGN, BLOCK_SIZE, RAW_METADATA_SIZE},
1917
};
2018

21-
/// Error returned when a fixed-size allocator cannot be created due to allocation failure.
22-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23-
pub struct AllocError {
24-
/// The layout of the allocation that failed.
25-
pub layout: Layout,
26-
}
27-
28-
impl fmt::Display for AllocError {
29-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30-
write!(
31-
f,
32-
"memory allocation failed for fixed-size allocator: requested {} bytes with {} byte alignment",
33-
self.layout.size(),
34-
self.layout.align()
35-
)
36-
}
37-
}
38-
39-
impl Error for AllocError {}
40-
4119
const TWO_GIB: usize = 1 << 31;
4220
const FOUR_GIB: usize = 1 << 32;
4321

@@ -121,7 +99,7 @@ impl FixedSizeAllocatorPool {
12199
}
122100
}
123101

124-
fn create_new_allocator(&self) -> Option<Result<FixedSizeAllocator, AllocError>> {
102+
fn create_new_allocator(&self) -> Option<Result<FixedSizeAllocator, ()>> {
125103
// If a previous allocation attempt failed, don't try again - it will also fail.
126104
if self.allocation_failed.load(Ordering::Relaxed) {
127105
return None;
@@ -273,9 +251,9 @@ struct FixedSizeAllocator {
273251
impl FixedSizeAllocator {
274252
/// Try to create a new [`FixedSizeAllocator`].
275253
///
276-
/// Returns `Err(AllocError)` if memory allocation fails.
254+
/// Returns `Err` if memory allocation fails.
277255
#[expect(clippy::items_after_statements)]
278-
fn try_new(id: u32) -> Result<Self, AllocError> {
256+
fn try_new(id: u32) -> Result<Self, ()> {
279257
// Only support little-endian systems. `Allocator::from_raw_parts` includes this same assertion.
280258
// This module is only compiled on 64-bit little-endian systems, so it should be impossible for
281259
// this panic to occur. But we want to make absolutely sure that if there's a mistake elsewhere,
@@ -289,7 +267,7 @@ impl FixedSizeAllocator {
289267
// Allocate block of memory.
290268
// SAFETY: `ALLOC_LAYOUT` does not have zero size.
291269
let alloc_ptr = unsafe { System.alloc(ALLOC_LAYOUT) };
292-
let alloc_ptr = NonNull::new(alloc_ptr).ok_or(AllocError { layout: ALLOC_LAYOUT })?;
270+
let alloc_ptr = NonNull::new(alloc_ptr).ok_or(())?;
293271

294272
// All code in the rest of this function is infallible, so the allocation will always end up
295273
// owned by a `FixedSizeAllocator`, which takes care of freeing the memory correctly on drop

0 commit comments

Comments
 (0)