What is NOT in the interface file?

I got the impression that "The AD interface file contains only what you need to import the module, and not for the entire implementation of this module." For me, this translates to signatures - just return the types, names and arguments so that the compiler knows that it is valid and the linker can do the dirty work later.

Running a file through dmd , however, skips almost nothing:

 import std.stdio; void SayHello(const string Name) { writeln("Hello, ", Name, "!"); } 

 dmd Interface.d -o- -H 

 // D import file generated from 'Interface.d' import std.stdio; void SayHello(const string Name) { writeln("Hello, ",Name,"!"); } 

Hardly an optimization sample.

What exactly is torn in interface files?

( because this is the closest thing I could find.)

+6
source share
2 answers

Any function that is going to be built-in must have a full source in the .di file. Any function that will be used in CTFE should not only have a full source in the .di file, but the full source of every function that it uses - directly or indirectly, must be available to the compiler. In addition, due to the way the templates work, their full source must also be in the .di file (which is the same as the templates should be in the C ++ header files). Thus, there are a number of cases where you need the material to be in the .di file.

In what circumstances the compiler decides to remove the material or not, I do not know (except that the templates automatically fall into the .di files completely, because they should). It may vary depending on the current implementation of the compiler and what kind of optimization it does. But, at a minimum, he will have to go to small functional organs if he is going to make any insertion. Large functional bodies and bodies of small virtual functions (which in any case cannot be built-in) are likely to be removed. But your example gives a little non-virtual function, so dmd probably left it so that it could inline any calls. If you want to see dmd highlight a lot of things when creating a .di file, then you probably have to have great functions and / or use classes.

+7
source

Hardly an optimization sample.

Not, optimization. The compiler will leave the implementation in the interface file if the implementation is small enough so that it can later be embedded.

+4
source

Source: https://habr.com/ru/post/899010/


All Articles