-
Notifications
You must be signed in to change notification settings - Fork 9
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
Separate dealloc
from Alloc
into other trait
#9
Comments
Other possibility:
|
dealloc
from Alloc
into other traitdealloc
from Alloc
into other trait
This is not quite true. Other APIs like I think it’s important for this issue to provide some context and motivation. Current proposals revolve around adding an This issue is about reducing this cost in a narrow set of circumstances:
In that case we could in theory have zero-size deallocation-only handles to keep in |
So far I haven’t seen a complete proposal of what an API supporting this use case might look like. It’s not just the trait:
Before we accept it as a goal to support this use case, I’d like someone who wants it to come up with a more comprehensive API proposal. That should be the starting point of the discussion. But if this adds significant complexity to the type signature even for users who do not use this feature, I’m not sure we should accept such a narrow use case. |
I'm sorry, I think I expressed myself misunderstandably. The struct itself only needs |
Yeah, the |
I don’t understand. If |
Not a signature, but with |
You're right, my previous suggestion was incorrect. However, it can be done like this (unless I'm missing something): struct Box<T: ?Sized, D>(Unique<T>, D);
impl<T: ?Sized, D: Dealloc> Drop for Box<T, D> {
fn drop(&mut self);
}
impl<T: ?Sized, D: Dealloc, A: Alloc<Dealloc=D>> Box<T, D> {
fn new_in(x: T, a: A) -> Box<T, D>;
} |
@TimDiekmann So the only way to use this feature would require @scottjmaddox So we’d have an |
Yes, you would need something like Ideally, there would be additional methods like |
Yes. I don't know if the analogy helps, but have you used C++'s IIUC what's being proposed here is the same. Most of the |
@gnzlbg Is there any reason my suggestion for a safe |
One of the main use cases for Ideally, you'd just implement I'm not sure how you would be able to achieve that with |
@gnzlbg I totally agree that that's a use case worth supporting, and that |
@scott-maddox would that require implementing |
@gnzlbg No, it would not. With my suggestion, implementing (Side note: this is the same person as scott-maddox; I meant to use this account.) |
I was thinking about this a little, and I think this means there needs to be a different trait for |
The problem with that is that, without specialization, users cannot override that impl. |
Thus "default" in my sentence. |
I thought that wasn't intended. If that's by design, then the main downside is still that we would be blocking the stabilization of these APIs on stable specialization. I'm not sure that would make strategic sense. |
I'm not sure it would need to block on stable specialization. Implementers should be able to |
Without a |
Is there is some already-stable magic that allows users to specialize without specialization If not, your blanket here are two impls for your allocator, the blanket one that you provide (e.g. Dealloc, and Realloc), and the one that a user might want to write. Without specialization, those two conflict. |
A user wouldn't have to write a |
I’m not sure we are talking about the same trait hierarchy then.
I understood this issue as separating dealloc from the Alloc trait into a
different trait, such that ‘trait Alloc: Dealloc { ... no dealloc here ...
}’.
|
If we decide to introduce either of the traits, this would be done in three steps:
|
If we think that the |
I'm fine with that. Does anyone want to write the documentation for |
Do you still want to create the actual PR to rustc? It might be good if it is the same person making PRs (for recognisability). In that case someone'd need to push/pr to your fork. |
I am strongly opposed to having a separate Regarding |
Just leak the box and keep the &mut around however long you would have kept the box around |
Yes, I think that makes sense.
One could also make a PR to |
i vote this idea is just way too niche |
That's one of the things this working group is trying to fix, though. It would be much better if Rust std lib collections had first-class support for custom allocators. |
I originally voted to also split realloc for consistency but @Amanieu's arguments had me change my mind. Updated my vote above, thanks for taking it into account. :) |
Whops, wrong Issue... Sorry for the noise |
Will close this as we probably won't implement this. If we will do, we can still reopen it (again). |
Most (all?) of the structs mentioned in #7 only needs the
dealloc
method forDrop
. It'd may be useful to split upAlloc
into two traits. We didn't came up however with the exact layout and relationship with those two traits. So far, those possibilities showed up:trait Alloc: Dealloc { ... }
(Separatedealloc
fromAlloc
into other trait #9 (comment))Associate theAlloc
trait:trait Dealloc { type Alloc: Alloc; ... }
trait GetDealloc { unsafe fn get_dealloc() -> ???; }
get_alloc
as method inAlloc
instead of an extra trait (Separatedealloc
fromAlloc
into other trait #9 (comment))realloc
intoRealloc
and associateDealloc
withAlloc
andRealloc
(Separatedealloc
fromAlloc
into other trait #9 (comment))Alloc
withRealloc
(Separatedealloc
fromAlloc
into other trait #9 (comment))dealloc
fromAlloc
into other trait #9 (comment))Edits
The text was updated successfully, but these errors were encountered: