Modules ... "import" vs. "compilation" ... what is the real process here?
Steven Schveighoffer
schveiguy at gmail.com
Tue Sep 28 14:38:19 UTC 2021
On 9/28/21 1:59 AM, james.p.leblanc wrote:
> On Tuesday, 28 September 2021 at 05:26:29 UTC, Ali Çehreli wrote:
>> On 9/27/21 10:38 AM, james.p.leblanc wrote:
>
>>
>> In addition to what Mike Parker said, templates do complicate matters
>> here: Templates are instantiated (i.e. compiled for a specific set of
>> template arguments) by modules that actually use those templates.
>>
>>
>
> Ali, this is great! ...I had been tempted to also ask about how templates
> figure into this, but realized that including this in my question would be
> over complicating the question, so it remained unasked.
>
> But, now I have this part answered as well. I very much appreciate the
> mind-reading tricks going on here on the forum!
>
Be aware that the compiler might not include the code for the template
in the instantiating module if it detects that the instantiation could
already have been generated in an imported module (not one passed on the
command line).
For example, if Ali's module `a` contained an alias:
```d
module a;
auto doubled(T)(T value) {
return value * 2;
}
alias doubleInt = doubled!int;
```
Now the compiler might say "hey, a.d already has instantiated that one,
and it's not being built by me, so I'll assume it has already generated
the code" and doesn't do it.
-Steve
More information about the Digitalmars-d-learn
mailing list