[Issue 5777] New: Move semantics require full spec NRVO

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 23 18:43:47 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5777

           Summary: Move semantics require full spec NRVO
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2011-03-23 18:40:27 PDT ---
DMD supports Named Return Value Optimization(NRVO), but now this 
doesn't work for struct that has @disabled postblit and user-defined 
destructor (e.g. std.typecons.scoped).

This looks trivial, but serious problem.

1. Need of incorporating NRVO into the language specifications
  D does not contain rvalue seantinc in its type system. 
  ('ref' is storage class, not part of type. This means casting 
  is useless for this purpose, unlike C++.)
  Except for only one, This means D has no way that convert from lvalue 
  to rvalue in current language spec.

  The one way is NRVO. This is not only trivial optimization, but also 
  core of move semantics in D.
  ----
  T f(){
    T ret;        // &ret == hidden pointer, and *hidden is 'move target'.
                // In this example, share memory of t.
    ret = ...
    return ret;    // NRVO.
  }

  T t = f();    // t's memory address is taken hidden pointer
  ---- 

  Moving object caller to callee is now D supports, but reversed flow is 
  limitation. To full support moving callee to caller through return value, 
  NRVO is required.

2. std.algorithm.move problem
  If Issue 4499 will be fixed, unary std.algorithm.move() will not work 
  on noncopyable/has expplicit destructor object.

  To give correct behavior, NRVO spec update is need.

3. ABI problem
  In http://digitalmars.com/d/2.0/abi.html 'Return Value' term,
  struct its size is less than 8 byte is returned using registers.

  Issue 4500 is scoped!T and self-referenced class problem, but the way 
  resolving it will need true NRVO. That has following spec: Any size object 
  returned through hidden pointer,
  if the object has elaborate destructor at least.

  See http://d.puremagic.com/issues/show_bug.cgi?id=4500#c5 . Attachment code 
  includes workaround for this issue, But it's too ugly.

Do you think?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list