-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relax A: 'static
bound for boxed Pin
APIs
#90822
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @yaahc (or someone else) soon. Please see the contribution instructions for more information. |
cc @rust-lang/wg-allocators |
Is this true, given that there is a |
It would suggest that the blanket impl for |
Can you add the "broken case" as a test? That way we're guaranteed that it'll keep working - given future changes. |
I would be happy to add some tests that exercise these APIs. First, I think there's a need for some clarification on the safety requirements of the |
What about something like: let mut an_allocator = Allocator::new();
an_allocator.with_sub_allocator(|sub_allocator| {
let pinned = Box::pin_in(42, sub_allocator);
mem::forget(pinned);
}); where the closure has the type Edit: Never mind. That violates a safety condition of |
In your example, the suballocator in
Such a sub-allocator is not sound under these requirements. |
TBH this requirement (the explicit "dropped" requirement ala Pin) seems sketchy to have on all Allocators as opposed to an additional requirement for Pin. It basically means that you need a refcount on the allocator or equivalently flags for individual allocations, and for stack allocators you have to abort if any allocation has been forgotten. |
☔ The latest upstream changes (presumably #92556) made this pull request unmergeable. Please resolve the merge conflicts. |
Hey, I've begun reviewing this PR and as part of that I'm trying to familiarize myself with the
The first question is my own and is probably the best starting point. |
Thanks for taking a look. The What usage of
|
Regarding the
Regarding the pin drop requirements by either using reference counting or by abort-on-leak, @talchas you seem to be dissatisfied with those as available options. Do you have an example usecase for Also, its unclear to me on if you're talking about the allocator requirement that memory remains valid until all allocators are dropped vs the pin requirement that memory remain valid until drop is called. Are these in-fact the same requirement? I'm wondering if this requirement got added to allocator because of I'm trying to understand what it would look like to remove this requirement from allocator and my best guess is that it would disallow pinning any data from an allocator that isn't |
Good question, I don't know the answer :P
It would have to be |
Is panicking sufficient? What happens if the panic gets caught? |
Ah, no that is not sufficient and stack allocators must abort in that situation. I've corrected the referenced section. |
Here's one argument against. With the even more experimental storages API, This is done in such a way that Importantly, there's no extra state involved, so So if we're going to use storages (cc @TimDiekmann again), we'll need a "pinning compatible" bound for storages/allocators anyway. It's probably better to spell this out separately, anyway, rather than having it implicit in So put me down as a +1 to replacing the pinning guarantee on Footnotes
|
As long as |
☔ The latest upstream changes (presumably #94901) made this pull request unmergeable. Please resolve the merge conflicts. |
Abandoning in favor of #94114 |
In #79327, the
Pin
APIs forBox
were restricted toA: 'static
. This was overly cautious and restricts thePin
APIs unnecessarily. The justification for doing this was as follows:In the comment thread, @TimDiekmann correctly observed that the given code produces a compiler error:
This is a hint that the reasoning may not be correct. Forgetting the box will also forget the allocator, which will prevent the memory from being freed and therefore reused. If you move a clone of
alloc
into the box, you're still covered by the safety conditions forAllocator
:At least one clone of the allocator must be forgotten along with the pinned box. This is also why
Box::leak
is sound with a restriction ofA: 'a
; the allocator is not dropped when the box is leaked.It is important to note that naive implementations of non-
'static
allocators cannot fulfill the safety requirements forAllocator
. The allocator can be forgotten and its allocated memory will still be released at the end of its lifetime, which may cause the memory of undropped pinned values to be reused. The unsoundness is actually in the unsafeAllocator
impl though, and not the boxedPin
APIs.