Delegate Literals + Immutability, pure and closures

Christophe travert at phare.normalesup.org
Fri Sep 30 06:01:11 PDT 2011


dsimcha , dans le message (digitalmars.D:145792), a écrit :
> 4.  Auto return type inference is limited to cases where all return statements
> return the exact type.  Is there any reason I'm missing why, if multiple
> return statements with different types are present, an auto return function
> couldn't just return a common type?

If the common type is obvious, the programmer can just type it. If not, 
I do not want to rely on the compiler to perform implicit casting to a 
type that I don't even know, and where I might loose informations, 
unless there is an unambiguous and error-free way to determine the comon 
type. I prefer the compiler to complain about an ill-defined return type 
than a compiler making uncontrolled casting to a type I don't even know. 
If auto return type has to be improved, it must be using a very safe and 
clearly defined behavior.

About other points, of course, the compiler should optimize out all heap 
allocation when it knows the data do not escape the scope (there is 
delegate, but I think also initializer lists), and it 
should also be able to inline obvious delegates. I guess that will come 
in time.

On that matter, I regret that the scope attribute is meant to disappear. 
It could be a way for the compiler to enforce that the data do not 
escape the scope, so the programer can be sure the compiler will be able 
to perform this kind of optimization (and not only for delegates) - just 
like pure and immutable enforce behaviors than enable more 
optimizations.

-- 
Christophe



More information about the Digitalmars-d mailing list