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.
|
Per conversations here, I've written up a new, comprehensive stabilisation report per my understanding of what a stabilised trait would look like. Note that this is not yet fully reflective of the state of this PR, as I'd like to first merge #157153 and then rebase on that. I'll update the top-level PR summary with a link as well. If there are points not explicitly addressed, please ping me and I'll either expand on the relevant rationale or - if it is a new point - see what should be done about it ^^ |
|
this also means the FCP can be restarted if the team agrees with the stabilisation report next meeting |
This comment has been minimized.
This comment has been minimized.
|
Wouldn't the |
|
We can use specialisation internally in |
|
What about downstream users? Also I'm pretty sure that |
|
As an aside, I've been trying around with my writing my own |
|
Tbh I think the likelier case is that we just don't add blanket impls for |
|
Are there examples of deallocators in other languages or real use cases? |
|
|
|
|
This comment has been minimized.
This comment has been minimized.
| /// deallocating functions unwind, and must not rely on other side effects | ||
| /// of these calls being observable (e.g. it is sound for an allocation followed | ||
| /// immediately by a deallocation to be optimised away). |
There was a problem hiding this comment.
The second point ("and must not rely...") is more about users of allocators than about implementors, isn't it? It's a bit confusing to handle both of these very different properties in a single sentence.
| /// The pointer passed back in via [`shrink`], [`grow`], etc. must only be used to access | ||
| /// memory inside of that allocation. Furthermore, if the allocator uses pointers that it tracks | ||
| /// itself in order to access this same memory, the user-provided pointer gets invalidated. |
There was a problem hiding this comment.
| /// The pointer passed back in via [`shrink`], [`grow`], etc. must only be used to access | |
| /// memory inside of that allocation. Furthermore, if the allocator uses pointers that it tracks | |
| /// itself in order to access this same memory, the user-provided pointer gets invalidated. | |
| /// The pointer passed back in via [`deallocate`], [`shrink`], [`grow`], etc. must only be used to access | |
| /// memory inside of that allocation. Furthermore, this pointer should be considered "mutably borrowed" | |
| /// from the pointer returned by [`allocate`] etc. and the usual aliasing rules for | |
| /// mutable borrows apply: when their lifetime ends (e.g. because a pointer they | |
| /// were derived from gets used again), they are invalidated must not be used any more. |
Happy to wordsmith this some more.
There was a problem hiding this comment.
Actually... the Box part isn't even being stabilized now, right? This is only really relevant for Box. OTOH I guess we need allocators to be forward-compatible with having Box<T, A> later...
There was a problem hiding this comment.
Actually never mind, it's also relevant for when the user derived an &mut from the allocated pointer and then passes that (turned back into a raw pointer) to deallocate.
I was thinking on zulip that we should do this, particularly moving Yes, this does mean we would have to be careful about how we deallocate and drop, but I think it's doable. |
|
Hmm, if this is sound then I really like that idea. There would presumably also be many benefits to not moving around the allocator field together with the pointer all the time. |
Considering the last-minute nature in which really big lurking soundness issues were found and the scope of the proposed changes I don't think the next step would be to immediately jump into another final comment period. As much as I would like to see the allocator trait get stabilized I think this means we need a bit more time for people to play with the new design and see what they run into. |
|
I think there may be benefits to moving the allocator inside an allocation for all containers. For box the destructor is a bit annoying though because the pointee is dropped by the compiler instead of the We would need some mechanism to clone allocators regardless to justify |
If there's outstanding concerns about soundness, I'm happy to postpone landing this a couple weeks. It would still be nice to know if the team is in agreement with the design though |
|
This PR is now a mix of stabilization and other changes, and I hope those other changes (even the documentation ones) can get landed for testing on nightly before stabilization, without being delayed along with the (clearly needed) delay of stabilization. |
|
Yes, please extract the various API changes. Stabilization PRs should not change the API being stabilized. |
View all comments
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
Edit, following more points being discovered: see the new stabilisation report