Skip to content
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

destructive move #18977

Open
dlangBugzillaToGithub opened this issue Apr 19, 2015 · 2 comments
Open

destructive move #18977

dlangBugzillaToGithub opened this issue Apr 19, 2015 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

Martin Nowak (@MartinNowak) reported this on 2015-04-19T23:31:37Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=14466

Description

Currently the moved from object has to be reinitialized in order to avoid double freeing in it's destructor.
Both operations reinitialization and destroying the moved from object are superfluous, if we had a mean to tell the compiler not to destroy a particular object.
https://github.com/D-Programming-Language/phobos/blob/41d1162619039e8e535060b920ff54cc2c44ebbb/std/algorithm/mutation.d#L1015

A destructive move intrinsic would turn an object into an rvalue, disable destruction of the moved from object, and disallow any further usage of the moved from object.
The object must be unaliased to make destructive move @safe.
Destructively moving anything but named variables (such as fields or single array elements) would be prohibited as it adds compiler complexity or runtime overhead.
@dlangBugzillaToGithub
Copy link
Author

code (@MartinNowak) commented on 2015-09-02T08:05:00Z

This should only be allowed on "value" declarations to avoid complications like destructive move via ref parameter in a function call or moving of array elements.

@dlangBugzillaToGithub
Copy link
Author

code (@MartinNowak) commented on 2016-10-09T18:07:45Z

DMD internally uses a storage class flag (STCnodtor) for a similar purpose.
So an @unsafe __nodtor(var) intrinsic to instruct the compiler to not destruct a variable could hopefully just set this flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant