Can the D compiler detect final and optimize?

Dennis dkorpel at gmail.com
Fri Mar 13 16:13:31 UTC 2020


On Friday, 13 March 2020 at 15:08:34 UTC, IGotD- wrote:
> Instead of having final as default, can't the compiler itself 
> infer when a class is implicitly final and do the optimizations 
> itself?

The problem is that only at runtime are all the derived classes 
known, and by then the code is already compiled. I think the Java 
Virtual Machine can automatically elide virtual calls by virtue 
of being a JIT, but for D this would mean either telling the 
compiler 'assume all derived classes are present in the source 
files provided here' or doing fancy link-time optimization.


More information about the Digitalmars-d mailing list