`in` on function parameters: const, scope const, ref scope const ?

tsbockman thomas.bockman at gmail.com
Sun Apr 5 02:01:05 UTC 2020


On Friday, 3 April 2020 at 06:19:38 UTC, Mathias LANG wrote:
> I have submitted a PR for it: 
> https://github.com/dlang/dmd/pull/11000 and would like to know 
> how other users of `in` expect it to behave, or would want it 
> to behave.

Given the possibility of aliasing, adding `ref` to parameters 
that are merely `const`, but not `immutable`, could break 
existing code in very subtle ways. (I know there has been talk of 
disallowing aliasing of `ref` arguments, but I don't think D's 
tracking of such things is reliable enough to depend on to 
prevent code breakage yet. Also, I'm hoping that proposal isn't 
actually implemented, anyway, because I find intentionally 
aliasing `ref` parameters useful.) Less importantly, adding `ref` 
where it wasn't intended may cause minor performance problems.

However, if I ignore the code breakage issue, then `in` == `ref 
scope const` is the most aesthetically pleasing option for the 
symmetry with `out`. I'll also guess that by-value `scope const` 
is needed a lot less often than `ref scope const`, so this is 
probably the better long-term option to reduce the considerable 
verbosity of the language - IF we can avoid breaking too much 
existing code due the altered run-time semantics from adding 
`ref`.


More information about the Digitalmars-d mailing list