summaryrefslogtreecommitdiffstats
path: root/vendor/bumpalo
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/bumpalo
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bumpalo')
-rw-r--r--vendor/bumpalo/.cargo-checksum.json2
-rw-r--r--vendor/bumpalo/CHANGELOG.md29
-rw-r--r--vendor/bumpalo/Cargo.toml3
-rw-r--r--vendor/bumpalo/README.md2
-rw-r--r--vendor/bumpalo/src/alloc.rs2
-rw-r--r--vendor/bumpalo/src/boxed.rs15
-rw-r--r--vendor/bumpalo/src/collections/string.rs18
-rw-r--r--vendor/bumpalo/src/collections/vec.rs20
-rwxr-xr-x[-rw-r--r--]vendor/bumpalo/src/lib.rs58
9 files changed, 106 insertions, 43 deletions
diff --git a/vendor/bumpalo/.cargo-checksum.json b/vendor/bumpalo/.cargo-checksum.json
index c0aee5c0a..64cfc40a9 100644
--- a/vendor/bumpalo/.cargo-checksum.json
+++ b/vendor/bumpalo/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"CHANGELOG.md":"d5e5dd1003e24fac2d0fa25beae573f3dcc374f0e124db1a8a5d8e40f044690f","Cargo.toml":"01e00b19c457f1a6674f6eac87f9383a954b5b72bfc22b020284be10f6d19eaf","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"65f94e99ddaf4f5d1782a6dae23f35d4293a9a01444a13135a6887017d353cee","README.md":"00c9224790248ec71d1505615429699fd685b0290a0c2b6d7c0df0214e7f80eb","src/alloc.rs":"ab0f23fa11c26efdd8f0596ebdf0e3faa75d097881fb59639b0fb23340c106bc","src/boxed.rs":"53c72a0f85f293307f468ec31c71b5d7667aee0f119f0a8dee2162b1f34d6561","src/collections/collect_in.rs":"0588a4ff3967a4323abb4218bbd615af4b123639ab4fae9130c6590c258b3d15","src/collections/mod.rs":"d58dc46eb4f9fcdde574f09bc5b8646f53e42d49c169561d98e0c23e5b36848a","src/collections/raw_vec.rs":"8829cc9a693fde38aa93e47a7bbbc2dac247620d07f60519f2e6cb44f5494bc5","src/collections/str/lossy.rs":"c5d62b16e01071e2a574ae41ef6693ad12f1e6c786c5d38f7a13ebd6cb23c088","src/collections/str/mod.rs":"d82a8bd417fbf52a589d89a16ea2a0ac4f6ac920c3976ab1f5b6ac0c8493c4f2","src/collections/string.rs":"5c43caaa5b3c305f7eae148513619829e35824e20818527422f86c0212ca632b","src/collections/vec.rs":"dfc39029b950ba9430c66f3de33a3484d85454c74b988b71c1d1806bf24d78bf","src/lib.rs":"1150c18aa21b7327aeed2c2a9d94957f0c1436a82440ced30a5e18dd794545e1"},"package":"572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"} \ No newline at end of file
+{"files":{"CHANGELOG.md":"a4add8d9ec2f992a216d354c9272a67831cb52e436abee7dcace2ecf0b5748df","Cargo.toml":"37d412794bd2a4a0e438ffbab3e76bd4a8e63a969e74072fb286035b669749bb","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"65f94e99ddaf4f5d1782a6dae23f35d4293a9a01444a13135a6887017d353cee","README.md":"db3b9ea7989b8d6e1c334c1af4ab3670867cd4327603afebdee4d8415abcfba6","src/alloc.rs":"3a9645d9e8db1f2a8549ee928cafa5263a828f25c88ce4d2b07996ecc14bfa81","src/boxed.rs":"5fc935f8e1a7bc1b8f6a39b2bcc4355a2be4743f2308fe3ffd557455a3a27cb2","src/collections/collect_in.rs":"0588a4ff3967a4323abb4218bbd615af4b123639ab4fae9130c6590c258b3d15","src/collections/mod.rs":"d58dc46eb4f9fcdde574f09bc5b8646f53e42d49c169561d98e0c23e5b36848a","src/collections/raw_vec.rs":"8829cc9a693fde38aa93e47a7bbbc2dac247620d07f60519f2e6cb44f5494bc5","src/collections/str/lossy.rs":"c5d62b16e01071e2a574ae41ef6693ad12f1e6c786c5d38f7a13ebd6cb23c088","src/collections/str/mod.rs":"d82a8bd417fbf52a589d89a16ea2a0ac4f6ac920c3976ab1f5b6ac0c8493c4f2","src/collections/string.rs":"388d39b999788baf5c14ccc3f5cb57da728060ea3295ddfc28f0f2e1ca5858ec","src/collections/vec.rs":"2eaf52e085e6d04767e97b224e82688dd0debd231c6536d6034f431376aa8bf0","src/lib.rs":"3b3cea76afb3befca1163c578d030a07a621b2e4b6d44e988cec57f820ba9818"},"package":"9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8"} \ No newline at end of file
diff --git a/vendor/bumpalo/CHANGELOG.md b/vendor/bumpalo/CHANGELOG.md
index abe5b2fe6..d7b510f20 100644
--- a/vendor/bumpalo/CHANGELOG.md
+++ b/vendor/bumpalo/CHANGELOG.md
@@ -8,6 +8,7 @@ Released YYYY-MM-DD.
### Changed
+* The minimum supported Rust version (MSRV) is now 1.60.0.
* TODO (or remove section if none)
### Deprecated
@@ -28,6 +29,34 @@ Released YYYY-MM-DD.
--------------------------------------------------------------------------------
+## 3.12.1
+
+Released 2023-04-21.
+
+### Fixed
+
+* Fixed a bug where `Bump::try_with_capacity(n)` where `n > isize::MAX` could
+ lead to attempts to create invalid `Layout`s.
+
+--------------------------------------------------------------------------------
+
+## 3.12.0
+
+Released 2023-01-17.
+
+### Added
+
+* Added the `bumpalo::boxed::Box::bump` and `bumpalo::collections::String::bump`
+ getters to get the underlying `Bump` that a string or box was allocated into.
+
+### Changed
+
+* Some uses of `Box` that MIRI did not previously consider as UB are now
+ reported as UB, and `bumpalo`'s internals have been adjusted to avoid the new
+ UB.
+
+--------------------------------------------------------------------------------
+
## 3.11.1
Released 2022-10-18.
diff --git a/vendor/bumpalo/Cargo.toml b/vendor/bumpalo/Cargo.toml
index ff3ec3e5a..34f92ad6d 100644
--- a/vendor/bumpalo/Cargo.toml
+++ b/vendor/bumpalo/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2021"
name = "bumpalo"
-version = "3.11.1"
+version = "3.12.1"
authors = ["Nick Fitzgerald <fitzgen@gmail.com>"]
exclude = [
"/.github/*",
@@ -31,7 +31,6 @@ categories = [
]
license = "MIT/Apache-2.0"
repository = "https://github.com/fitzgen/bumpalo"
-resolver = "2"
[package.metadata.docs.rs]
all-features = true
diff --git a/vendor/bumpalo/README.md b/vendor/bumpalo/README.md
index 3d73e2967..d0ee1431e 100644
--- a/vendor/bumpalo/README.md
+++ b/vendor/bumpalo/README.md
@@ -209,7 +209,7 @@ v.push(2);
#### Minimum Supported Rust Version (MSRV)
-This crate is guaranteed to compile on stable Rust **1.56** and up. It might
+This crate is guaranteed to compile on stable Rust **1.60** and up. It might
compile with older versions but that may change in any new patch release.
We reserve the right to increment the MSRV on minor releases, however we will
diff --git a/vendor/bumpalo/src/alloc.rs b/vendor/bumpalo/src/alloc.rs
index 0bcc21f22..6947e2a6c 100644
--- a/vendor/bumpalo/src/alloc.rs
+++ b/vendor/bumpalo/src/alloc.rs
@@ -752,7 +752,7 @@ pub unsafe trait Alloc {
match (Layout::array::<T>(n_old), Layout::array::<T>(n_new)) {
(Ok(ref k_old), Ok(ref k_new)) if k_old.size() > 0 && k_new.size() > 0 => {
debug_assert!(k_old.align() == k_new.align());
- self.realloc(ptr.cast(), k_old.clone(), k_new.size())
+ self.realloc(ptr.cast(), *k_old, k_new.size())
.map(NonNull::cast)
}
_ => Err(AllocErr),
diff --git a/vendor/bumpalo/src/boxed.rs b/vendor/bumpalo/src/boxed.rs
index cf9f4d6fe..af0737cfb 100644
--- a/vendor/bumpalo/src/boxed.rs
+++ b/vendor/bumpalo/src/boxed.rs
@@ -130,7 +130,7 @@ use {
future::Future,
hash::{Hash, Hasher},
iter::FusedIterator,
- mem,
+ mem::ManuallyDrop,
ops::{Deref, DerefMut},
pin::Pin,
task::{Context, Poll},
@@ -280,9 +280,8 @@ impl<'a, T: ?Sized> Box<'a, T> {
/// ```
#[inline]
pub fn into_raw(b: Box<'a, T>) -> *mut T {
- let ptr = b.0 as *mut T;
- mem::forget(b);
- ptr
+ let mut b = ManuallyDrop::new(b);
+ b.deref_mut().0 as *mut T
}
/// Consumes and leaks the `Box`, returning a mutable reference,
@@ -662,9 +661,9 @@ impl<'a, F: ?Sized + Future + Unpin> Future for Box<'a, F> {
/// This impl replaces unsize coercion.
impl<'a, T, const N: usize> From<Box<'a, [T; N]>> for Box<'a, [T]> {
- fn from(mut arr: Box<'a, [T; N]>) -> Box<'a, [T]> {
+ fn from(arr: Box<'a, [T; N]>) -> Box<'a, [T]> {
+ let mut arr = ManuallyDrop::new(arr);
let ptr = core::ptr::slice_from_raw_parts_mut(arr.as_mut_ptr(), N);
- mem::forget(arr);
unsafe { Box::from_raw(ptr) }
}
}
@@ -672,10 +671,10 @@ impl<'a, T, const N: usize> From<Box<'a, [T; N]>> for Box<'a, [T]> {
/// This impl replaces unsize coercion.
impl<'a, T, const N: usize> TryFrom<Box<'a, [T]>> for Box<'a, [T; N]> {
type Error = Box<'a, [T]>;
- fn try_from(mut slice: Box<'a, [T]>) -> Result<Box<'a, [T; N]>, Box<'a, [T]>> {
+ fn try_from(slice: Box<'a, [T]>) -> Result<Box<'a, [T; N]>, Box<'a, [T]>> {
if slice.len() == N {
+ let mut slice = ManuallyDrop::new(slice);
let ptr = slice.as_mut_ptr() as *mut [T; N];
- mem::forget(slice);
Ok(unsafe { Box::from_raw(ptr) })
} else {
Err(slice)
diff --git a/vendor/bumpalo/src/collections/string.rs b/vendor/bumpalo/src/collections/string.rs
index 6b7af9a4b..ffd1db92d 100644
--- a/vendor/bumpalo/src/collections/string.rs
+++ b/vendor/bumpalo/src/collections/string.rs
@@ -798,6 +798,24 @@ impl<'bump> String<'bump> {
String { vec: bytes }
}
+ /// Returns a shared reference to the allocator backing this `String`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use bumpalo::{Bump, collections::String};
+ ///
+ /// // uses the same allocator as the provided `String`
+ /// fn copy_string<'bump>(s: &String<'bump>) -> &'bump str {
+ /// s.bump().alloc_str(s.as_str())
+ /// }
+ /// ```
+ #[inline]
+ #[must_use]
+ pub fn bump(&self) -> &'bump Bump {
+ self.vec.bump()
+ }
+
/// Converts a `String` into a byte vector.
///
/// This consumes the `String`, so we do not need to copy its contents.
diff --git a/vendor/bumpalo/src/collections/vec.rs b/vendor/bumpalo/src/collections/vec.rs
index b5a60029e..312aa055b 100644
--- a/vendor/bumpalo/src/collections/vec.rs
+++ b/vendor/bumpalo/src/collections/vec.rs
@@ -675,6 +675,26 @@ impl<'bump, T: 'bump> Vec<'bump, T> {
}
}
+ /// Returns a shared reference to the allocator backing this `Vec`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use bumpalo::{Bump, collections::Vec};
+ ///
+ /// // uses the same allocator as the provided `Vec`
+ /// fn add_strings<'bump>(vec: &mut Vec<'bump, &'bump str>) {
+ /// for string in ["foo", "bar", "baz"] {
+ /// vec.push(vec.bump().alloc_str(string));
+ /// }
+ /// }
+ /// ```
+ #[inline]
+ #[must_use]
+ pub fn bump(&self) -> &'bump Bump {
+ self.buf.bump()
+ }
+
/// Returns the number of elements the vector can hold without
/// reallocating.
///
diff --git a/vendor/bumpalo/src/lib.rs b/vendor/bumpalo/src/lib.rs
index be68365c8..db5d41bbd 100644..100755
--- a/vendor/bumpalo/src/lib.rs
+++ b/vendor/bumpalo/src/lib.rs
@@ -354,7 +354,7 @@ static EMPTY_CHUNK: EmptyChunkFooter = EmptyChunkFooter(ChunkFooter {
impl EmptyChunkFooter {
fn get(&'static self) -> NonNull<ChunkFooter> {
- unsafe { NonNull::new_unchecked(&self.0 as *const ChunkFooter as *mut ChunkFooter) }
+ NonNull::from(&self.0)
}
}
@@ -463,12 +463,8 @@ struct NewChunkMemoryDetails {
/// Wrapper around `Layout::from_size_align` that adds debug assertions.
#[inline]
-unsafe fn layout_from_size_align(size: usize, align: usize) -> Layout {
- if cfg!(debug_assertions) {
- Layout::from_size_align(size, align).unwrap()
- } else {
- Layout::from_size_align_unchecked(size, align)
- }
+fn layout_from_size_align(size: usize, align: usize) -> Result<Layout, AllocErr> {
+ Layout::from_size_align(size, align).map_err(|_| AllocErr)
}
#[inline(never)]
@@ -476,12 +472,6 @@ fn allocation_size_overflow<T>() -> T {
panic!("requested allocation size overflowed")
}
-// This can be migrated to directly use `usize::abs_diff` when the MSRV
-// reaches `1.60`
-fn abs_diff(a: usize, b: usize) -> usize {
- usize::max(a, b) - usize::min(a, b)
-}
-
impl Bump {
/// Construct a new arena to bump allocate into.
///
@@ -535,7 +525,7 @@ impl Bump {
});
}
- let layout = unsafe { layout_from_size_align(capacity, 1) };
+ let layout = layout_from_size_align(capacity, 1)?;
let chunk_footer = unsafe {
Self::new_chunk(
@@ -600,7 +590,7 @@ impl Bump {
if allocated_bytes > allocation_limit {
None
} else {
- Some(abs_diff(allocation_limit, allocated_bytes))
+ Some(usize::abs_diff(allocation_limit, allocated_bytes))
}
})
}
@@ -682,7 +672,7 @@ impl Bump {
size,
} = new_chunk_memory_details;
- let layout = layout_from_size_align(size, align);
+ let layout = layout_from_size_align(size, align).ok()?;
debug_assert!(size >= requested_layout.size());
@@ -1470,6 +1460,7 @@ impl Bump {
/// Slow path allocation for when we need to allocate a new chunk from the
/// parent bump set because there isn't enough room in our current chunk.
#[inline(never)]
+ #[cold]
fn alloc_layout_slow(&self, layout: Layout) -> Option<NonNull<u8>> {
unsafe {
let size = layout.size();
@@ -1488,21 +1479,14 @@ impl Bump {
.checked_mul(2)?
.max(min_new_chunk_size);
let chunk_memory_details = iter::from_fn(|| {
- let bypass_min_chunk_size_for_small_limits = match self.allocation_limit() {
- Some(limit)
- if layout.size() < limit
+ let bypass_min_chunk_size_for_small_limits = matches!(self.allocation_limit(), Some(limit) if layout.size() < limit
&& base_size >= layout.size()
&& limit < DEFAULT_CHUNK_SIZE_WITHOUT_FOOTER
- && self.allocated_bytes() == 0 =>
- {
- true
- }
- _ => false,
- };
+ && self.allocated_bytes() == 0);
if base_size >= min_new_chunk_size || bypass_min_chunk_size_for_small_limits {
let size = base_size;
- base_size = base_size / 2;
+ base_size /= 2;
Bump::new_chunk_memory_details(Some(size), layout)
} else {
None
@@ -1678,6 +1662,10 @@ impl Bump {
/// on it only counting the sum of the sizes of the things
/// you've allocated in the arena.
///
+ /// The allocated bytes do not include the size of bumpalo's metadata,
+ /// so the amount of memory requested from the Rust allocator is higher
+ /// than the returned value.
+ ///
/// ## Example
///
/// ```
@@ -1692,6 +1680,16 @@ impl Bump {
unsafe { footer.as_ref().allocated_bytes }
}
+ /// Calculates the number of bytes requested from the Rust allocator for this `Bump`.
+ ///
+ /// This number is equal to the [`allocated_bytes()`](Self::allocated_bytes) plus
+ /// the size of the bump metadata.
+ pub fn allocated_bytes_including_metadata(&self) -> usize {
+ let metadata_size =
+ unsafe { self.iter_allocated_chunks_raw().count() * mem::size_of::<ChunkFooter>() };
+ self.allocated_bytes() + metadata_size
+ }
+
#[inline]
unsafe fn is_last_allocation(&self, ptr: NonNull<u8>) -> bool {
let footer = self.current_chunk_footer.get();
@@ -1746,9 +1744,9 @@ impl Bump {
// in the `if` condition.
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_ptr(), new_size);
- return Ok(new_ptr);
+ Ok(new_ptr)
} else {
- return Ok(ptr);
+ Ok(ptr)
}
}
@@ -1768,7 +1766,7 @@ impl Bump {
// reuse the currently allocated space.
let delta = new_size - old_size;
if let Some(p) =
- self.try_alloc_layout_fast(layout_from_size_align(delta, old_layout.align()))
+ self.try_alloc_layout_fast(layout_from_size_align(delta, old_layout.align())?)
{
ptr::copy(ptr.as_ptr(), p.as_ptr(), old_size);
return Ok(p);
@@ -1879,7 +1877,7 @@ unsafe impl<'a> alloc::Alloc for &'a Bump {
return self.try_alloc_layout(layout);
}
- let new_layout = layout_from_size_align(new_size, layout.align());
+ let new_layout = layout_from_size_align(new_size, layout.align())?;
if new_size <= old_size {
self.shrink(ptr, layout, new_layout)
} else {