D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14466 - destructive move
Summary: destructive move
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-19 23:31 UTC by Martin Nowak
Modified: 2024-12-13 18:42 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2015-04-19 23:31:37 UTC
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.
Comment 1 Martin Nowak 2015-09-02 08:05:00 UTC
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.
Comment 2 Martin Nowak 2016-10-09 18:07:45 UTC
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.
Comment 3 dlangBugzillaToGithub 2024-12-13 18:42:15 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18977

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB