Steven Schveighoffer wrote:
On Mon, 02 Nov 2009 11:53:12 -0500, Andrei Alexandrescu
<[email protected]> wrote:
This question may actually belong in .learn.
What's exactly eliminated from the header generated with -H? I tried
it just now and was surprised to see that the generated .di file
includes the function bodies of regular (non-template) functions and
methods.
I was under the impression that generated headers exclude function
bodies, and found documentation to support that viewpoint:
http://www.digitalmars.com/d/2.0/dmd-windows.html#interface_files
says:
============
A D interface file contains only what an import of the module needs,
rather than the whole implementation of that module.
The advantages of using a D interface file for imports rather than a D
source file are:
* D interface files are often significantly smaller and much
faster to process than the corresponding D source file.
* They can be used to hide the source code, for example, one can
ship an object code library along with D interface files rather than
the complete source code.
============
This strongly suggests that function bodies are eliminated. But what
I'm seeing is that pretty much all function bodies are kept
(exception: static this() functions are not), and only comments are
removed.
So what's -H really doing?
It removes whitespace and comments.
My understanding of why it does not remove implementations is for CTFE
and inlining.
Somehow I got it in my head that a significantly large enough function
would have it's body removed, but I can't remember why I think that...
You're right. I just added a loop to a function, and its body
disappeared from the .di file. Thanks!
The CTFE-ability of functions seems to play no role in they being kept
around, however.
Note that the above snippit from the docs suggests reasons for using d
interface files, *NOT* reasons for using dmd -H :)
Yeah, I'd agree if the link didn't come from the same page's explanation
of -H.
I think the doc should be clearer about the fact that the compiler has
the freedom to keep whichever function bodies it finds fit for inlining.
Andrei