Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign updrop could take self by-value, and allow early destruction #4330
Comments
This comment has been minimized.
This comment has been minimized.
|
Now that we can move out of methods, could we just change the |
This comment has been minimized.
This comment has been minimized.
|
@erickt: that was actually the original idea, and the idea of doing it with a trait actually came later to avoid needing compiler changes since I hadn't considered that it would result in a destruction cycle. However, it turns out there's already |
thestinger
referenced this issue
Jan 18, 2013
Closed
Should the drop method take mutable self? #4514
This comment has been minimized.
This comment has been minimized.
|
I was thinking this would be useful as well, but I don't know how it can work. During destruction the allocator essentially 'owns' the value and by passing self to |
This comment has been minimized.
This comment has been minimized.
|
I do think that the finalizer should take self "by value". @brson I'm not quite sure what you think would be wrong with that. |
metajack
referenced this issue
Apr 29, 2013
Closed
Destroy a box in core::gc::cleanup_stack_for_failure #4420
This comment has been minimized.
This comment has been minimized.
|
Nominating for milestone 2. |
This comment has been minimized.
This comment has been minimized.
|
We discussed at the work week why by-value finalizers are ok and you convinced me at the time, but yet again I don't understand how that works. |
This comment has been minimized.
This comment has been minimized.
|
Short version: what we call "by-value" really just means that ownership of the contents is transferred to the callee. So the callee is responsible for freeing the contents, basically. In most cases, the value of a "by-value" parameter is still passed by pointer, it's just that we create a value on our stack and give a pointer to the callee. They are responsible then to free the data in that stack region, we don't free its contents. This seems to match destructors perfectly, if you generalize "stack region" to "memory region". |
This comment has been minimized.
This comment has been minimized.
|
It isn't true though that the |
This comment has been minimized.
This comment has been minimized.
|
Yes, today the compiler generates the code to free the contents, but that's precisely what I propose to change. Instead, the contents would be freed (or sent, or moved) by the destructor, just as with any other by-value argument. I don't see a problem with the fact that the destructor can send or move |
graydon
closed this
May 1, 2013
graydon
reopened this
May 1, 2013
This comment has been minimized.
This comment has been minimized.
|
oops, closed by accident. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis If the finalizer moves Here's some code, annotated with what I think you are proposing.
In both those blocks a
|
This comment has been minimized.
This comment has been minimized.
|
Hmm, so, I think if you move self as a whole, then it would re-run the finalizer. The only magic thing, I suppose, is that the finalizer does not run on |
This comment has been minimized.
This comment has been minimized.
|
We discussed this at the meeting today. Conclusion was that dtors |
bblum
added a commit
to bblum/rust
that referenced
this issue
Jun 11, 2013
bblum
referenced this issue
Jun 11, 2013
Closed
add an intrinsic for calling a type's destructor #6239
This comment has been minimized.
This comment has been minimized.
|
On Thu, Jun 27, 2013 at 12:54:01AM -0700, Daniel Micay wrote:
There is nothing "safe" about this flag, as far as I can tell? You |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis: yup, it's not actually safe - that's why I deleted the comment :) |
This comment has been minimized.
This comment has been minimized.
|
My current opinion as that there are too many special cases required to support by-value finalizers, not enough real use cases, and |
This comment has been minimized.
This comment has been minimized.
|
We decided in today's meeting (https://github.com/mozilla/rust/wiki/Meeting-weekly-2013-10-22) that drop by value requires too many special rules and semantics about it to warrant the convenience of taking self by value instead of by reference. For that reason, I'm de-milestoning the bug, removing the P-backcompat-lang label, and removing the I-completion label. While we don't plan on doing this for 1.0, there is always the possibility of doing it afterwards. It would be a little painful, but types could implement a |
This comment has been minimized.
This comment has been minimized.
|
I no longer think this is a great idea. It's certainly possible to implement with special cases in the language, but I don't think the additional complexity is worth it. It's easy enough to do anything you could do this way by using |
thestinger commentedJan 2, 2013
There's currently a
util::ignorefunction that consumes a value to destroy it early.It would be nicer the if
Droptrait'sdropmethod tookselfby value and could be called early, which would require some compiler magic to avoid an infinite destruction cycle in thedropmethod. This would also allowdropto move out ofself, which is potentially useful.