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

Move semantics not respected #18674

Closed
dlangBugzillaToGithub opened this issue Sep 20, 2013 · 4 comments
Closed

Move semantics not respected #18674

dlangBugzillaToGithub opened this issue Sep 20, 2013 · 4 comments
Labels
Arch:x86 Issues specific to x86 P3 Severity:normal

Comments

@dlangBugzillaToGithub
Copy link

badlink reported this on 2013-09-20T05:08:41Z

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

CC List

Description

DMD version: 2.063.2

Code: http://pastebin.com/sTLhnNdV

Output:
CTor A with 42
CTor A with 23
CTor A with 65
Value call with A::65
DTor A with 65
CTor A with 1337
Value call with A::1337
DTor A with 1337
Ref call with A::42
DTor A with 23
DTor A with 42

Disassembly: http://pastebin.com/5emmwqJc
Compilation flags: -release -O

Issue:
The first two value calls receive their arguments via move semantics, i.e. the argument is not copied but passed directly to the function.
This behavior is showed in the output (the postblit function is not called) but the disassembly shows that the struct is actually copied before the function call.
@dlangBugzillaToGithub
Copy link
Author

rswhite4 commented on 2013-09-20T11:42:14Z

If that is fixed, there could be a huge performance boost.

@WalterBright
Copy link
Member

The sample code:

import std.stdio;
 
struct A {
public:
    uint id;
    uint data[128];
    
    this(uint id) {
        this.id = id;
        
        writeln("CTor A with ", id);
    }
    
    this(this) {
        writeln("Postblit A with ", this.id);
    }
    
    ~this() {
        writeln("DTor A with ", this.id);
    }
    
    A opBinary(string op : "+")(ref const A a) {
        A r = A(this.id + a.id);
        r.data[] += a.data[];
        return r;
    }
}
 
void func(const A a) {
    writeln("Value call with A::", a.id);   
}
 
void func(ref const A a) {
    writeln("Ref call with A::", a.id);
}
 
void main()
{
    A a = A(42);
    A b = A(23);
    
    asm { int 3; }
    func(a + b);
    asm { int 3; }
    func(A(1337));
    func(a);
}

@TurkeyMan
Copy link
Contributor

I'm pretty confident this will be resolved by __rvalue semantics. The unit tests in Walter's branch already prove these things as far as I can tell.

@thewilsonator
Copy link
Contributor

closing this then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86 Issues specific to x86 P3 Severity:normal
Projects
None yet
Development

No branches or pull requests

4 participants