Parametrize RawTable, HashSet and HashMap over an allocator#133
Parametrize RawTable, HashSet and HashMap over an allocator#133bors merged 16 commits intorust-lang:masterfrom
Conversation
* `RawTable` has a new type parameter, `A: Alloc + Clone` * When the `nightly` flag is passed, `Alloc` will be the trait in `alloc::Alloc`. * On stable, a minimal shim implementation is provided, along with an implementation for the global allocator. * No public APIs changed. * For `HashMap`, everything is monomorphized to the global allocator, and there should be no performance or size overhead.
* Change order of type parameters * Handle null case for `alloc` * Run rustfmt
|
Ah, and I didn't test the |
|
Pretty sure the last errors are not my fault |
|
Yea we're having CI issues due to cross-rs/cross#357. I will merge as soon as this is resolved. |
|
@Amanieu Regarding your reply in fitzgen/bumpalo#54
Wouldn't this cause problems with API stability? Or were you thinking behind a feature flag? |
|
I'll just make a major version bump, it's fine. |
|
Just to add some context as to why this hasn't moved anywhere on my end. I am a bit unsure how to handle things like pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
let (smaller, larger) = if self.len() <= other.len() {
(self, other)
} else {
(other, self)
};
Union {
iter: larger.iter().chain(smaller.difference(larger)),
}
}This function takes two sets, which we presumably want the ability to be from two different allocators. Internally it does a compare, and returns a If the two sets are from different allocators, this approach wouldn't work as the returned struct would have a different allocator type parameter depending on which set is larger. I see a couple of different options:
Thoughts? |
|
I think for now it would be best to stick to the simplest solution, which is to require both |
|
Again, I don't think the last error is due to my changes |
RawTable over an allocator|
Seems like the allocator trait (AllocRef right now) is under major flux right now in the latest nightlies. I'll update to latest, but I guess it might make sense to wait with merging until things settle a bit? |
|
Yea we've got a few changes lined up. Ideally I would like to wait until |
|
I'm fine with using my forks for now. Would you mind dropping a comment when you believe most changes are out of the way and I'll update to latest? |
|
Sure! Will do. |
Add allocator parameter to HashMap Hashbrown support originally added in rust-lang/hashbrown#133 Part of rust-lang/wg-allocators#7 ~See also: hashset support in #148550 (Edit: merged into this PR for crater)
Add allocator parameter to HashMap Hashbrown support originally added in rust-lang/hashbrown#133 Part of rust-lang/wg-allocators#7 ~See also: hashset support in rust-lang/rust#148550 (Edit: merged into this PR for crater)
Add allocator parameter to HashMap Hashbrown support originally added in rust-lang/hashbrown#133 Part of rust-lang/wg-allocators#7 ~See also: hashset support in rust-lang/rust#148550 (Edit: merged into this PR for crater)
Add allocator parameter to HashMap Hashbrown support originally added in rust-lang/hashbrown#133 Part of rust-lang/wg-allocators#7 ~See also: hashset support in rust-lang/rust#148550 (Edit: merged into this PR for crater)
Add allocator parameter to HashMap Hashbrown support originally added in rust-lang/hashbrown#133 Part of rust-lang/wg-allocators#7 ~See also: hashset support in rust-lang/rust#148550 (Edit: merged into this PR for crater)
This change would make the
RawTableusable with things like arena allocation.RawTablehas a new type parameter,A: Alloc + Clonenightlyflag is passed,Allocwill be the trait inalloc::Alloc.implementation for the global allocator.
HashMap, everything is monomorphized to the global allocator,and there should be no performance or size overhead.