alloc: stabilise Allocator - #156882
Conversation
|
r? @Amanieu |
This comment has been minimized.
This comment has been minimized.
|
I believe the safety requirements are not yet correct. See #156544 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
cc also @rust-lang/libs-api + @rust-lang/lang |
|
Do we intend (now or later) to make any ABI guarantees about |
|
I'd be fine with making guarantees for the case where |
|
Should we be firing |
This comment has been minimized.
This comment has been minimized.
|
I'm happy having them under that lint |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
|
Thanks @nia-e. As I understand it, on lang, we're signing off on two things: One, we're agreeing that impl<A: Allocator> PartialEq<LocalTy> for Box<u8, A> {
fn eq(&self, _: &LocalTy) -> bool { true }
}Two, we're agreeing that See:
@rfcbot reviewed |
|
Based on conversations elsewhere, I don't think this will be an issue, I don't think this will be a problem. But it's worth mentioning for awareness. Based on the documentation of This in turns means that if we ever wanted to implement |
|
And now for a concern that I think is actually blocking: Some traits in std are currently implemented on (This is also a semver hazard for third-party crates that have blanket impls on Boxes. Generalizing such impls to include boxes with custom allocators is a breaking change.) |
Is it a breaking change? Such implementations are effectively |
|
@bushrat011899 The following code currently compiles on nightly, and would break if we were to change the #![feature(allocator_api)]
use std::alloc::Global;
use std::io::{self, Read};
struct Thing;
impl Read for Thing {
fn read(&mut self, _: &mut [u8]) -> Result<usize, io::Error> {
Ok(0)
}
}
impl Read for Box<Thing, &'static Global> {
fn read(&mut self, _: &mut [u8]) -> Result<usize, io::Error> {
Ok(0)
}
} |
|
Interesting, that's only an issue because the first type parameter is fundamental? For example, an implementation of |
Yes.
I think so, yes. |
|
I'm happy to expand all appropriate trait impls before landing this. I believe some of them can't † be expanded directly (e.g. Default) since they'd be breaking on stable today, but I'll do a pass over all other downstream-implementable traits and shoot a PR generalising them if possible. † Doing so would require effectively splitting |
Here is some more discussion about that splitting. I think we should do this ^^ |
|
Not sure if discussed, but moving the allocator into the heap allocation can make sense for Rc/Arc and if that were to happen it might be strange if |
|
We have an RFC for that? I think we were just planning to move the allocator to the heap on |
Box is guaranteed to be fat since you can construct
|
|
@rfcbot reviewed |
|
The two asks make sense to me:
Thanks to wg-allocators and @nia-e for driving this forward and providing context. @rfcbot reviewed |
|
The stabilization report mentions that the API being stabilized was developed with the input of "interested parties in the ecosystem". I'd be curious to know who those third-parties were, and to hear from them to know if they've had enough time to kick the tires on the API for everyone to be confident in its final shape. |
|
Reasonable question! We particularly spoke to folks from Rust for Linux, PyO3/Pydantic, and Canonical during the all-hands and shortly after, who all expressed that the proposed API surface is one they can worth with (with further extensions in the future, of course). Significant efforts were also made to keep the stabilised API surface virtually identical to the old one from before the trait refactor landed, so a lot of past feedback (including real-world testing via |
View all comments
See the current proposed stabilisation report for up-to-date information on the proposed stable API.
outdated former status
Stabilise a bare-minimum (dyn-incompatible, but could be in the future)
Allocatortrait, alongsideBox::new_in(),Vec::new_in(), theSystem&GlobalAllocators, and a blanket impl ofAllocator for T: GlobalAlloc. For now, we should take care not to make it possible to instantiate anything other than aVecorBoxwith custom allocators; it's Probably Fine, but worth a proper look before we rush in.The soundness requirements for implementors were tightened to the most restrictive ones we could reasonably want per a conversation with @RalfJung.
This was discussed extensively at the all-hands with an apparent tentative consensus from libs and participating ecosystem stakeholders that the current design can be extended backwards-compatibly to address almost all usecases.
cc @rust-lang/libs @rust-lang/libs-api @rust-lang/opsem
r? libs