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
12 changes: 6 additions & 6 deletions src/raw/alloc.rs → src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ pub(crate) use self::inner::{Allocator, Global, do_alloc};
// This is used when building for `std`.
#[cfg(feature = "nightly")]
mod inner {
#[cfg(test)]
pub(crate) use crate::alloc::alloc::AllocError;
use crate::alloc::alloc::Layout;
pub(crate) use crate::alloc::alloc::{Allocator, Global};
use core::ptr::NonNull;
#[cfg(test)]
pub(crate) use stdalloc::alloc::AllocError;
use stdalloc::alloc::Layout;
pub(crate) use stdalloc::alloc::{Allocator, Global};

pub(crate) fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<[u8]>, ()> {
match alloc.allocate(layout) {
Expand All @@ -30,11 +30,11 @@ mod inner {
// `core::alloc::Allocator`.
#[cfg(all(not(feature = "nightly"), feature = "allocator-api2"))]
mod inner {
use crate::alloc::alloc::Layout;
#[cfg(test)]
pub(crate) use allocator_api2::alloc::AllocError;
pub(crate) use allocator_api2::alloc::{Allocator, Global};
use core::ptr::NonNull;
use stdalloc::alloc::Layout;

pub(crate) fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<[u8]>, ()> {
match alloc.allocate(layout) {
Expand All @@ -54,8 +54,8 @@ mod inner {
// or `nightly` without disturbing users that don't want to use it.
#[cfg(not(any(feature = "nightly", feature = "allocator-api2")))]
mod inner {
use crate::alloc::alloc::{Layout, alloc, dealloc};
use core::ptr::NonNull;
use stdalloc::alloc::{Layout, alloc, dealloc};

#[expect(clippy::missing_safety_doc)] // not exposed outside of this crate
pub unsafe trait Allocator {
Expand Down
4 changes: 2 additions & 2 deletions src/external_trait_impls/rayon/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::collections::LinkedList;
use alloc::vec::Vec;
use stdalloc::collections::LinkedList;
use stdalloc::vec::Vec;

use rayon::iter::{IntoParallelIterator, ParallelIterator};

Expand Down
8 changes: 4 additions & 4 deletions src/external_trait_impls/rayon/map.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Rayon extensions for `HashMap`.

use super::raw::{RawIntoParIter, RawParDrain, RawParIter};
use crate::hash_map::HashMap;
use crate::raw::{Allocator, Global};
use crate::HashMap;
use crate::alloc::{Allocator, Global};
use core::fmt;
use core::hash::{BuildHasher, Hash};
use core::marker::PhantomData;
Expand Down Expand Up @@ -456,13 +456,13 @@ where

#[cfg(test)]
mod test_par_map {
use alloc::vec::Vec;
use core::hash::{Hash, Hasher};
use core::sync::atomic::{AtomicUsize, Ordering};
use stdalloc::vec::Vec;

use rayon::prelude::*;

use crate::hash_map::HashMap;
use crate::HashMap;

struct Droppable<'a> {
k: usize,
Expand Down
4 changes: 2 additions & 2 deletions src/external_trait_impls/rayon/raw.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::raw::Bucket;
use crate::raw::{Allocator, Global, RawIter, RawIterRange, RawTable};
use crate::alloc::{Allocator, Global};
use crate::raw::{Bucket, RawIter, RawIterRange, RawTable};
use crate::scopeguard::guard;
use core::marker::PhantomData;
use core::mem;
Expand Down
8 changes: 4 additions & 4 deletions src/external_trait_impls/rayon/set.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Rayon extensions for `HashSet`.

use super::map;
use crate::hash_set::HashSet;
use crate::raw::{Allocator, Global};
use crate::HashSet;
use crate::alloc::{Allocator, Global};
use core::hash::{BuildHasher, Hash};
use rayon::iter::plumbing::UnindexedConsumer;
use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelExtend, ParallelIterator};
Expand Down Expand Up @@ -386,12 +386,12 @@ where

#[cfg(test)]
mod test_par_set {
use alloc::vec::Vec;
use core::sync::atomic::{AtomicUsize, Ordering};
use stdalloc::vec::Vec;

use rayon::prelude::*;

use crate::hash_set::HashSet;
use crate::HashSet;

#[test]
fn test_disjoint() {
Expand Down
6 changes: 3 additions & 3 deletions src/external_trait_impls/rayon/table.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Rayon extensions for `HashTable`.

use super::raw::{RawIntoParIter, RawParDrain, RawParIter};
use crate::hash_table::HashTable;
use crate::raw::{Allocator, Global};
use crate::HashTable;
use crate::alloc::{Allocator, Global};
use core::fmt;
use core::marker::PhantomData;
use rayon::iter::plumbing::UnindexedConsumer;
Expand Down Expand Up @@ -206,8 +206,8 @@ impl<'a, T: Send, A: Allocator> IntoParallelIterator for &'a mut HashTable<T, A>

#[cfg(test)]
mod test_par_table {
use alloc::vec::Vec;
use core::sync::atomic::{AtomicUsize, Ordering};
use stdalloc::vec::Vec;

use rayon::prelude::*;

Expand Down
8 changes: 4 additions & 4 deletions src/external_trait_impls/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ mod size_hint {
}

mod map {
use crate::raw::Allocator;
use crate::alloc::Allocator;
use core::fmt;
use core::hash::{BuildHasher, Hash};
use core::marker::PhantomData;
use serde_core::de::{Deserialize, Deserializer, MapAccess, Visitor};
use serde_core::ser::{Serialize, Serializer};

use crate::hash_map::HashMap;
use crate::HashMap;

use super::size_hint;

Expand Down Expand Up @@ -97,14 +97,14 @@ mod map {
}

mod set {
use crate::raw::Allocator;
use crate::alloc::Allocator;
use core::fmt;
use core::hash::{BuildHasher, Hash};
use core::marker::PhantomData;
use serde_core::de::{Deserialize, Deserializer, SeqAccess, Visitor};
use serde_core::ser::{Serialize, Serializer};

use crate::hash_set::HashSet;
use crate::HashSet;

use super::size_hint;

Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern crate std;

#[cfg_attr(test, macro_use)]
#[cfg_attr(feature = "rustc-dep-of-std", allow(unused_extern_crates))]
extern crate alloc;
extern crate alloc as stdalloc;

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
Expand All @@ -52,6 +52,7 @@ pub struct ReadmeDoctests;
#[macro_use]
mod macros;

mod alloc;
mod control;
mod hasher;
mod raw;
Expand Down Expand Up @@ -170,6 +171,6 @@ pub enum TryReserveError {
/// The memory allocator returned an error
AllocError {
/// The layout of the allocation request that failed.
layout: alloc::alloc::Layout,
layout: stdalloc::alloc::Layout,
},
}
17 changes: 8 additions & 9 deletions src/map.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::raw::{
Allocator, Bucket, Global, RawDrain, RawExtractIf, RawIntoIter, RawIter, RawTable,
};
use crate::alloc::{Allocator, Global};
use crate::raw::{Bucket, RawDrain, RawExtractIf, RawIntoIter, RawIter, RawTable};
use crate::{DefaultHashBuilder, Equivalent, TryReserveError};
use ::alloc::borrow::ToOwned;
use core::borrow::Borrow;
use core::fmt::{self, Debug};
use core::hash::{BuildHasher, Hash};
use core::iter::FusedIterator;
use core::marker::PhantomData;
use core::mem;
use core::ops::Index;
use stdalloc::borrow::ToOwned;

#[cfg(feature = "raw-entry")]
pub use crate::raw_entry::*;
Expand Down Expand Up @@ -1055,7 +1054,7 @@ where
/// in case of allocation error. Use [`try_reserve`](HashMap::try_reserve) instead
/// if you want to handle memory allocation failure.
///
/// [`abort`]: alloc::alloc::handle_alloc_error
/// [`abort`]: stdalloc::alloc::handle_alloc_error
///
/// # Examples
///
Expand Down Expand Up @@ -4863,16 +4862,16 @@ mod test_map {
use super::Entry::{Occupied, Vacant};
use super::EntryRef;
use super::HashMap;
use crate::raw::{AllocError, Allocator, Global};
use alloc::string::{String, ToString};
use alloc::sync::Arc;
use crate::alloc::{AllocError, Allocator, Global};
use core::alloc::Layout;
use core::ptr::NonNull;
use core::sync::atomic::{AtomicI8, Ordering};
use rand::{Rng, SeedableRng, rngs::SmallRng};
use std::borrow::ToOwned;
use std::cell::RefCell;
use std::vec::Vec;
use stdalloc::string::{String, ToString};
use stdalloc::sync::Arc;

#[test]
fn test_zero_capacities() {
Expand Down Expand Up @@ -6241,7 +6240,7 @@ mod test_map {
#[test]
#[should_panic = "panic in clone"]
fn test_clone_from_memory_leaks() {
use alloc::vec::Vec;
use stdalloc::vec::Vec;

struct CheckedClone {
panic_in_clone: bool,
Expand Down
27 changes: 13 additions & 14 deletions src/raw/mod.rs → src/raw.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::TryReserveError;
use crate::alloc::alloc::{Layout, handle_alloc_error};
use crate::control::{BitMaskIter, Group, Tag, TagSliceExt};
use crate::scopeguard::{ScopeGuard, guard};
use crate::util::{invalid_mut, likely, unlikely};
Expand All @@ -10,11 +9,11 @@ use core::mem;
use core::ptr::NonNull;
use core::slice;
use core::{hint, ptr};
use stdalloc::alloc::{Layout, handle_alloc_error};

mod alloc;
#[cfg(test)]
pub(crate) use self::alloc::AllocError;
pub(crate) use self::alloc::{Allocator, Global, do_alloc};
use crate::alloc::AllocError;
use crate::alloc::{Allocator, Global, do_alloc};

#[inline]
unsafe fn offset_from<T>(to: *const T, from: *const T) -> usize {
Expand Down Expand Up @@ -1571,7 +1570,7 @@ impl RawTableInner {
///
/// See also [`Allocator`] API for other safety concerns.
///
/// [`Allocator`]: alloc::alloc::Allocator
/// [`Allocator`]: stdalloc::alloc::Allocator
#[cfg_attr(feature = "inline-more", inline)]
unsafe fn new_uninitialized<A>(
alloc: &A,
Expand Down Expand Up @@ -1670,7 +1669,7 @@ impl RawTableInner {
/// All the control bytes are initialized with the [`Tag::EMPTY`] bytes.
///
/// [`fallible_with_capacity`]: RawTableInner::fallible_with_capacity
/// [`abort`]: alloc::abort::handle_alloc_error
/// [`abort`]: stdalloc::abort::handle_alloc_error
fn with_capacity<A>(alloc: &A, table_layout: TableLayout, capacity: usize) -> Self
where
A: Allocator,
Expand Down Expand Up @@ -3118,8 +3117,8 @@ impl RawTableInner {
/// See also [`GlobalAlloc::dealloc`] or [`Allocator::deallocate`] for more information.
///
/// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
/// [`GlobalAlloc::dealloc`]: alloc::alloc::GlobalAlloc::dealloc
/// [`Allocator::deallocate`]: alloc::alloc::Allocator::deallocate
/// [`GlobalAlloc::dealloc`]: stdalloc::alloc::GlobalAlloc::dealloc
/// [`Allocator::deallocate`]: stdalloc::alloc::Allocator::deallocate
#[inline]
unsafe fn free_buckets<A>(&mut self, alloc: &A, table_layout: TableLayout)
where
Expand Down Expand Up @@ -3150,8 +3149,8 @@ impl RawTableInner {
/// See also [`GlobalAlloc::dealloc`] or [`Allocator::deallocate`] for more information.
///
/// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
/// [`GlobalAlloc::dealloc`]: alloc::GlobalAlloc::dealloc
/// [`Allocator::deallocate`]: alloc::Allocator::deallocate
/// [`GlobalAlloc::dealloc`]: stdalloc::GlobalAlloc::dealloc
/// [`Allocator::deallocate`]: stdalloc::Allocator::deallocate
#[inline]
unsafe fn allocation_info(&self, table_layout: TableLayout) -> (NonNull<u8>, Layout) {
debug_assert!(
Expand Down Expand Up @@ -4441,7 +4440,7 @@ mod test_map {
/// AN UNINITIALIZED TABLE DURING THE DROP
#[test]
fn test_drop_uninitialized() {
use ::alloc::vec::Vec;
use stdalloc::vec::Vec;

let table = unsafe {
// SAFETY: The `buckets` is power of two and we're not
Expand All @@ -4456,7 +4455,7 @@ mod test_map {
/// ARE ZERO, EVEN IF WE HAVE `FULL` CONTROL BYTES.
#[test]
fn test_drop_zero_items() {
use ::alloc::vec::Vec;
use stdalloc::vec::Vec;
unsafe {
// SAFETY: The `buckets` is power of two and we're not
// trying to actually use the returned RawTable.
Expand Down Expand Up @@ -4502,10 +4501,10 @@ mod test_map {
#[test]
fn test_catch_panic_clone_from() {
use super::{AllocError, Allocator, Global};
use ::alloc::sync::Arc;
use ::alloc::vec::Vec;
use core::sync::atomic::{AtomicI8, Ordering};
use std::thread;
use stdalloc::sync::Arc;
use stdalloc::vec::Vec;

struct MyAllocInner {
drop_count: Arc<AtomicI8>,
Expand Down
7 changes: 4 additions & 3 deletions src/raw_entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::hash_map::{equivalent, make_hash, make_hasher};
use crate::raw::{Allocator, Bucket, Global, RawTable};
use crate::{Equivalent, HashMap};
use crate::Equivalent;
use crate::alloc::{Allocator, Global};
use crate::map::{HashMap, equivalent, make_hash, make_hasher};
use crate::raw::{Bucket, RawTable};
use core::fmt::{self, Debug};
use core::hash::{BuildHasher, Hash};
use core::mem;
Expand Down
3 changes: 2 additions & 1 deletion src/rustc_entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use self::RustcEntry::*;
use crate::alloc::{Allocator, Global};
use crate::map::{Drain, HashMap, IntoIter, Iter, IterMut, make_hash};
use crate::raw::{Allocator, Bucket, Global, RawTable};
use crate::raw::{Bucket, RawTable};
use core::fmt::{self, Debug};
use core::hash::{BuildHasher, Hash};
use core::mem;
Expand Down
5 changes: 3 additions & 2 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use map::make_hash;

use super::map::{self, HashMap, Keys};
use crate::DefaultHashBuilder;
use crate::raw::{Allocator, Global, RawExtractIf};
use crate::alloc::{Allocator, Global};
use crate::raw::RawExtractIf;

// Future Optimization (FIXME!)
// =============================
Expand Down Expand Up @@ -616,7 +617,7 @@ where
/// in case of allocation error. Use [`try_reserve`](HashSet::try_reserve) instead
/// if you want to handle memory allocation failure.
///
/// [`abort`]: alloc::alloc::handle_alloc_error
/// [`abort`]: stdalloc::alloc::handle_alloc_error
///
/// # Examples
///
Expand Down
7 changes: 4 additions & 3 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use core::{fmt, iter::FusedIterator, marker::PhantomData, ptr::NonNull};

use crate::{
TryReserveError,
alloc::{Allocator, Global},
control::Tag,
raw::{
Allocator, Bucket, FullBucketsIndices, Global, RawDrain, RawExtractIf, RawIntoIter,
RawIter, RawIterHash, RawIterHashIndices, RawTable,
Bucket, FullBucketsIndices, RawDrain, RawExtractIf, RawIntoIter, RawIter, RawIterHash,
RawIterHashIndices, RawTable,
},
};

Expand Down Expand Up @@ -816,7 +817,7 @@ where
/// in case of allocation error. Use [`try_reserve`](HashTable::try_reserve) instead
/// if you want to handle memory allocation failure.
///
/// [`abort`]: alloc::alloc::handle_alloc_error
/// [`abort`]: stdalloc::alloc::handle_alloc_error
///
/// # Examples
///
Expand Down