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.
This comment has been minimized.
This comment has been minimized.
Thanks @nia-e for pushing this through! @rfcbot merge lang,libs-api |
|
@Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
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 |
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