Skip to content

Commit dda09b3

Browse files
committed
fix(allocator): remove Vec::bump method
1 parent 6b33f35 commit dda09b3

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

crates/oxc_allocator/src/vec2/mod.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -720,26 +720,6 @@ impl<'a, T: 'a, A: Alloc> Vec<'a, T, A> {
720720
self.buf.set_len(new_len);
721721
}
722722

723-
/// Returns a shared reference to the allocator backing this `Vec`.
724-
///
725-
/// # Examples
726-
///
727-
/// ```
728-
/// use bumpalo::{Bump, collections::Vec};
729-
///
730-
/// // uses the same allocator as the provided `Vec`
731-
/// fn add_strings<'a>(vec: &mut Vec<'a, &'a str>) {
732-
/// for string in ["foo", "bar", "baz"] {
733-
/// vec.push(vec.bump().alloc_str(string));
734-
/// }
735-
/// }
736-
/// ```
737-
#[inline]
738-
#[must_use]
739-
pub fn bump(&self) -> &'a A {
740-
self.buf.bump()
741-
}
742-
743723
/// Reserves capacity for at least `additional` more elements to be inserted
744724
/// in the given `Vec<'a, T>`. The collection may reserve more space to avoid
745725
/// frequent reallocations. After calling `reserve`, capacity will be

crates/oxc_allocator/src/vec2/raw_vec.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ impl<'a, T, A: Alloc> RawVec<'a, T, A> {
193193
}
194194

195195
/// Returns a shared reference to the allocator backing this RawVec.
196+
///
197+
/// IMPORTANT:
198+
/// The ability to obtain a reference to the allocator MUST NOT be exposed outside of `Vec`.
199+
///
200+
/// `Bump` is not `Sync` (and can't be because it contains `Cell`s which provide no synchronization),
201+
/// but `Vec<T>` is `Sync` if `T` is.
202+
///
203+
/// If external code could obtain a `&Bump` from a `&Vec`, then it could obtain 2 references to same
204+
/// `Bump` on different threads, and use both those refs to allocate into same `Bump` simultaneously.
205+
/// This could result in data corruption, aliasing violations, or writing out of bounds of the arena.
196206
pub fn bump(&self) -> &'a A {
197207
self.alloc
198208
}

0 commit comments

Comments
 (0)