Modules ... "import" vs. "compilation" ... what is the real process here?

james.p.leblanc james.p.leblanc at gmail.com
Mon Sep 27 17:38:29 UTC 2021


Dear D-ers,

I have trouble understanding "module imports" vs. "module 
compilations".

For example, in the dlang.org/tour, we have:

**"The import statement makes all public functions and types from 
the given module available."**

And from the dlang.org/spec we have:

**"Modules are always compiled at global scope and are unaffected 
by surrounding attributes or other modifiers."**

Finally, there have been discussions about allowing new ways of 
"compiling a module" by including its name on the command line.  
For example this from 2017:

https://forum.dlang.org/post/tcrdpvqvwxffnewzohuj@forum.dlang.org

The more I look into this, the more that I realize that I do not 
understand this as well as I had hoped.

So, when we specify the module name on the command line, then it 
gets compiled along with the other files on the command line 
(seems reasonable).

But, if it is NOT a command line argument, then when does it get 
compiled??
(I believe that at first cut, only the public functions and types 
are "grabbed").

But, when and how are the subsequent and necessary module 
compilation (and linking) steps performed?

Finally, we use a "-I" for telling dmd to look for imports in a 
directory, but why only
"look for imports", and not "grab anything from there that is 
used, AND compile them"?

(This question is prompted by some recent desires to use ldc and 
"fastmath"... which, if I
understand correctly, will require me to include all of the 
related modules on the command
line for immediate compilation).  But, in a broader sense, I need 
to understand the related issues better.

Thank for all responses, as well as continued patience with my 
questions.

Best Regards,
James




More information about the Digitalmars-d-learn mailing list