-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Forbid destructors on objects that aren't 'static bounded #11406
Comments
A typed arena is a type of arena that can only allocate objects of one type. It is 3x faster than the existing arena and 13x faster than malloc on Mac.
Should |
Yeah, Maybe we should have two traits: |
There's a real problem with using I think we should either thoroughly document and improve the error message about unsafe destructors, try to not have unsafe destructors, or possibly some other route (a bound indicating the flavor of destructor?). How would |
Also, if we're pushing for smart pointers, we're basically saying that all smart pointer (and their borrowed variants) all have to have unsafe destructors (which seems a little unreasonable?). |
It doesn't seem too unreasonable to me. The destructors can be unsafe, if implemented incorrectly. The syntax could be a little different, but it seems very similar to an |
I think UnsafeDrop would be the same as Drop, except that it avoids using an attribute and actually uses the I'm not sure that's unreasonable. Smart pointer destructors are nearly all unsafe anyway, as they deal with memory. |
I guess I'm also worried about all destructors in general. RAII is "the way to go", and RAII very frequently has borrowed pointers, so if the "official sanctioned way" includes using unsafe code, it seems like we've made a mistake? I may be worried about nothing, but I'm concerned about the number of |
I don't know of any alternative off the top of my head, although maybe there is some. How frequent are destructors on types with references? Arenas are very useful and it'd be a shame to give them up. |
A quick grep through the source code finds the following destructors that are using lifetimes:
So there would be no additional |
This seems like a conservative approximation of #8861? |
It is already supposed to be the case that one cannot define Drop There are a lot of RAII applications however that really rely on |
Ah, #8861 is the "new destructor semantics" I was speaking of. |
On Wed, Jan 08, 2014 at 08:45:18AM -0800, Alex Crichton wrote:
I 100% agree. unsafe_destructor should almost never or never be used, The reason I say that an unsafe destructor should never be used is A sound case for unsafe destructor is some private RAII type that is These thoughts were the motivation for #8861. |
Closing as dupe of #8861. |
There is a problem with destruction of arenas. Objects in an arena can freely point to other objects in the arena. While an object is being destroyed, it can therefore access any other arbitrary object in the arena, including objects that were already destroyed. This can cause badness.
To me the easiest fix seems to be to require that objects with destructors be
'static
bounded.cc @nikomatsakis
The text was updated successfully, but these errors were encountered: