ThinLTO is there. I think that should settle the final/virtual debate

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Sun Dec 4 08:19:06 PST 2016


On Sun, 04 Dec 2016 10:36:30 +0000, angel wrote:
> IMHO it was always obvious that the proper way is "devirtualization"
> within compiler optimization process.

Incremental compilation. You can't in general do this in the compiler.

* I write a library that uses std.socket:InternetHost.
* You compile it into libawesome.a. The compiler must use virtual 
dispatch (you might override members elsewhere).
* You write an app that uses libawesome.
* You compile it all together. Only now does the compiler know it can use 
static dispatch -- but it's too late; libawesome.a was already compiled.

That's why this is a *link* time optimization.

You can get around this by only doing whole program compilation, but that 
can be slow. You *could* have a compiler flag that enables whole-program 
compilation and associated optimizations, but if you can do it faster at 
link time, that's better. What you test with should be as close to what 
you ship with as possible, and the longer the optimization step is, the 
more likely it is that I'll turn it off while developing.

> From the developer's POV, the
> correct semantics is when each method is virtual.

Assuming the developer made the function final for speed and not to 
indicate that this function should not be overridden.


More information about the Digitalmars-d mailing list