Why does RDMD evaluate templates twice?

Nick Sabalausky a at a.a
Wed May 18 21:39:33 PDT 2011


"Andrej Mitrovic" <none at none.none> wrote in message 
news:ir1tv8$12ch$1 at digitalmars.com...
> This is a very odd behavior I've been seeing for quite a while now with 
> RDMD. DMD doesn't recreate this behavior.
>
> Take this module:
> module test;
>
> template Foo(T)
> {
>    pragma(msg, "test");
> }
>
> alias Foo!int a;
> // alias Foo!double b;
>
> void main()
> {
> }
>
> Notice one of the instantiations is commented out. $ is my prompt, > are 
> the printed results:
>
> $ rdmd test.d
>> test
>> test
>
> $ rdmd test.d
>> test
>
> The first time I run it, it instantiates (or evaluates) the template 
> twice. The second time I run rdmd, with no changes to the module, it only 
> evaluates the template once.
>
> Now I comment out the second instantiation in the module and try again:
> $ rdmd test.d
>> test
>> test
>> test
>> test
>
> $ rdmd test.d
>> test
>> test
>
> Quite weird.  I'm thinking this could cause some kind of slowdown. Anyone 
> have a clue what's going on here?
>

When you run RDMD, it invokes DMD twice: The first time is *just* to find 
out all the dependencies. Then it checks the dependencies to see if the 
executable needs to be rebuilt. If so, it passes all the dependencies to DMD 
to compile for real.

You can run it like this to see the DMD-invoking commands RDMD makes:

$ rdmd --chatty test.d

If you've changed test.d (and anything it depends on), then you'll see it 
runds dmd twice, each time with a different command.

If you haven't changed test.d (or anything it depends on), then it'll only 
run the first command: the one to find the dependencies.

You can see it without templates, too:

// test.d
import std.stdio;
pragma(msg, "Compile Time");
void main()
{
    writeln("Runtime");
}


> rdmd --chatty test.d
dmd  -v -o- "test.d" >test.d.deps
Compile Time
dmd  -of"C:\DOCUME~1\NICKSA~1\LOCALS~1\Temp\.rdmd\test-d-A8FD055311F603E847689B6FC07BFF23.exe" 
 -od"C:\DOCUME~1\NICKSA~1\LOCALS~1\Temp\.rdmd\rdmd-test.d-A8FD055311F603E847689B6FC07BFF23""test.d"Compile TimeRuntime> rdmd --chatty test.ddmd  -v -o- "test.d" >test.d.depsCompile TimeRuntime



More information about the Digitalmars-d-learn mailing list