Can the D compiler detect final and optimize?

kindouchoud jeyak10528 at ailiking.com
Fri Dec 25 16:39:05 UTC 2020


On Friday, 13 March 2020 at 15:08:34 UTC, IGotD- wrote:
> A little bit related to that some want class methods to be 
> final by default just like in C++. If I'm not mistaken one 
> benefit of final as default is that the compiler will insert 
> hard coded branches to the method as well as the possibility to 
> do inlining. Are my assumptions correct?
>
> Instead of having final as default, can't the compiler itself 
> infer when a class is implicitly final and do the optimizations 
> itself? Benefits would be that a programmer has the possibility 
> to extend about all classes (in C++ would only be possible if 
> class author makes all methods virtual). The final keyword 
> would just mean that a class method is not allowed to be 
> overridden.
>
> Is this possible at all?

The issue is that just at runtime are for the most part the 
inferred classes known, and by then the code is as of now 
arranged.


More information about the Digitalmars-d mailing list