-preview=in might break code

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Fri Oct 2 19:20:27 UTC 2020


On Friday, 2 October 2020 at 19:03:52 UTC, Steven Schveighoffer 
wrote:
> On 10/2/20 2:33 PM, Ola Fosheim Grøstad wrote:
> How does the compiler prove that passing by value or by 
> reference is not going to affect the resulting code? I mean, it 
> could potentially say, there are no references in all the 
> mutable parameters, and so I can pass by value. But that's kind 
> of a wide net.

It can do bookeeping of how one param can influence another.
If you have potential aliasing you can analyse if the affected 
const ref is read after a mutation is possible. If it is read 
before then there is no issue.

It may track ownership intenally and determine that the reference 
is isolated (the only one). Then track it as if it is effectively 
immutable.

> You mean by ref or by value isn't part of the language spec? I 
> don't understand the point.

The spec should list undefined behaviour and required observable 
effects, but not parameter passing strategies.

You can call something pass-by-value, but the compiler can still 
pass a reference as long as it cannot be observed unless 
undefined behaviour has been triggered by the programmer (by 
stepping outside the language).



More information about the Digitalmars-d mailing list