Summary: Move semantics require full spec NRVO
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD

--- Comment #0 from Kenji Hara <> 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 '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 . Attachment code 
  includes workaround for this issue, But it's too ugly.

Do you think?

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to