Can the D compiler detect final and optimize?
IGotD-
nise at nise.com
Fri Mar 13 15:31:24 UTC 2020
On Friday, 13 March 2020 at 15:15:50 UTC, rikki cattermole wrote:
> Why would this be needed?
>
> With ldc -O3 the test function can be completely erased:
>
> import std;
> void main()
> {
> Foo foo = new Foo;
> foo.x = 7;
> test(foo);
> }
>
> void test(Foo foo) {
> writeln(foo.get);
> }
>
> class Foo {
> int x;
>
> int get() { return x; }
> }
The D programming language by Andrei Alexandrescu. Chapter 6.6.
"So final non-override methods are never subjected to indrect
calls; instead they enjoy the same calling convention, low
overhead and inlining opportunities as regular functions"
I think I saw a difference between DMD and LDC previously where
LDC actually could in some cases infer that the method is final.
If the compiler can infer that a method is final (officially by
language standard), then what would the argument for final as
default be?
More information about the Digitalmars-d
mailing list