Skip to content

Commit

Permalink
Rework some wording around out and inout parameters (#312)
Browse files Browse the repository at this point in the history
This somewhat future proofs some aspects of the language here by saying
that [in]out parameter initialization is copy-initialization, but the
writeback assignment is _assignment_. That allows for clarity around
overloaded operators so that the argument life becomes something like
this:

```
auto &ArgTmp = (Arg); // Evaluate the argument expr saving it.
T Param = ArgTmp;     // Copy-initialize Param with Arg's result.
call(Param);          // Call the function.
ArgTmp = Param;       // Assign back the Param result with =.
```
  • Loading branch information
llvm-beanz authored Sep 16, 2024
1 parent 8b2b3df commit 7d83acd
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions specs/language/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@

\p Parameters are either \textit{input parameters}, \textit{output parameters},
or \textit{input/output parameters} as denoted in the called function's
declaration (\ref{Decl.Function}).
declaration (\ref{Decl.Function}). For all types of parameters the argument
expressions are evaluated before the function call occurs.

\p \textit{Input parameters} are passed by-value into a function. If an argument
to an \textit{input parameter} is of constant-sized array type, the array is
Expand All @@ -207,9 +208,11 @@
undefined behavior to not explicitly initialize an \textit{output parameter}
before returning from the function in which it is defined. The cxvalue created
from an argument to an \textit{input/output parameter} is initialized through
copy-initialization from the lvalue argument expression. In both cases, the
cxvalue shall have the type of the parameter and the argument can be converted
to that type through implicit or explicit conversion.
copy-initialization from the lvalue argument expression. Overload resolution
shall occur on argument initialization as if the expression \texttt{T Param =
Arg} were evaluated. In both cases, the cxvalue shall have the type of the
parameter and the argument can be converted to that type through implicit or
explicit conversion.

\p If an argument to an \textit{output} or \textit{input/output parameter} is a
constant sized array, the array is copied to a temporary cxvalue following the
Expand All @@ -222,11 +225,14 @@
\texttt{T[N]}.

\p On expiration of the cxvalue, the value is assigned back to the argument
lvalue expression following an inverted conversion if applicable. The argument
expression must be of a type or able to convert to a type that has defined
copy-initialization to and from the parameter type. The lifetime of the cxvalue
begins at argument expression evaluation, and ends after the function returns. A
cxvalue argument is passed by-address to the caller.
lvalue expression using a resolved assignment expression as if the expression
\texttt{Arg = Param} were written\footnote{The argument expression is not
re-evaluated after the call, so any side effects of the call occur only before
the call.}. The argument expression must be of a type or able to convert to a
type that has defined copy-initialization to and assignment from the parameter
type. The lifetime of the cxvalue begins at argument expression evaluation, and
ends after the function returns. A cxvalue argument is passed by-address to the
caller.

\p If the lvalue passed to an \textit{output} or \textit{input/output parameter}
does not alias any other parameter passed to that function, an implementation
Expand Down

0 comments on commit 7d83acd

Please sign in to comment.