`in` parameters made useful
Mathias LANG
geod24 at gmail.com
Tue Aug 4 09:35:56 UTC 2020
On Saturday, 1 August 2020 at 07:48:10 UTC, Rainer Schuetze wrote:
>
> I like most of your proposal, but
>
> On 31/07/2020 23:49, Mathias LANG wrote:
>> B) It makes `in` take the effect of `ref` when it makes sense.
>> It always pass something by `ref` if the type has elaborate
>> construction / destruction (postblit, copy constructor,
>> destructors). If the type doesn't have any of those it is only
>> passed by `ref` if it cannot be passed in register. Some types
>> (dynamic arrays, probably AA in the future) are not affected
>> to allow for covariance (more on that later). The heuristics
>> there still need some small improvements, e.g. w.r.t. floating
>> points (currently the heuristic is based on size, and not
>> asking the backend) and small struct slicing, but that should
>> not affect correctness.
>
> Please note that many C/C++-ABIs already define similar rules
> for passing function arguments by value (referencing a copy on
> the stack). It might not be the best idea to stack two similar,
> but maybe slightly conflicting rule sets.
>
> Maybe we can leverage that and define that if the ABI uses a
> reference for an `in`-value, the compiler may/must elide an
> extra copy. That avoids having to define our own rule set.
Do you have a link ? I did some research beforehand, but all I
could find was about NRVO and throwing exception, nothing about
actually promoting values to references.
Itanium C++ ABI doesn't have anything:
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#value-parameter
Nor does MS:
https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019#parameter-passing
More information about the Digitalmars-d
mailing list