About structs and performant handling

deadalnix deadalnix at gmail.com
Tue Mar 12 08:50:24 PDT 2013


On Tuesday, 12 March 2013 at 15:19:14 UTC, Namespace wrote:
>> As a consequence, if the compiler choose to pass by ref 
>> instead of passing by value as an optimization, it must do so 
>> only if it can prove that the resulting code will do the same 
>> thing.
> And how could it be proved? IMO with const (not mutable) scope 
> (no escaping). What are your thoughts?

To repeat myself :

The caller is free to call the ref version of the function unless
(rules evaluate in order) :
  - The argument is an rvalue (in such case, no postblit is
executed as well).
  - The argument is shared.
  - The argument's postblit in not pure (weakly).

The callee must create a local copy if (this is not verbatim from 
previous post as it has limitations as been pointed pointed) :
  - Mutate the struct or anything that *may* alias/be transitively 
reached through the struct.
  - Pass by ref/address taken to a non const/non weakly pure 
function (including method call) of the struct or anything that 
*may* alias/be transitively reached through the struct.

It does guarantee that visible result will be the same.


More information about the Digitalmars-d mailing list