www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - A case for -H header files, avoid repeating expensive compile-time

reply cy <dlang verge.info.tm> writes:
I made a module that looped for a while in compile time (since 
you can't sleep during compile time), to see if I could 
pre-compile the module, and thus save time compiling the main 
application. It didn't work at first, because any file that 
depended on the module would import it, and importing it would 
execute the compile time code again, thus taking a long time to 
compile... twice.

But then I remembered about the rarely used -H option for dmd. -H 
outputs a stripped down version of the source file being 
compiled, with all the function definitions replaced with 
declarations. So if your expensive to compile code is 
encapsulated within a function... it doesn't appear in the -H 
output.

So uh... git://critter.cloudns.org/test-dlang-encapsulation I 
guess. It might be a neat trick to speed up compilation, if you 
have a lot of complicated code that can be hidden behind a simple 
interface.
Aug 27 2016
parent rikki cattermole <rikki cattermole.co.nz> writes:
On 28/08/2016 6:34 AM, cy wrote:
 I made a module that looped for a while in compile time (since you can't
 sleep during compile time), to see if I could pre-compile the module,
 and thus save time compiling the main application. It didn't work at
 first, because any file that depended on the module would import it, and
 importing it would execute the compile time code again, thus taking a
 long time to compile... twice.

 But then I remembered about the rarely used -H option for dmd. -H
 outputs a stripped down version of the source file being compiled, with
 all the function definitions replaced with declarations. So if your
 expensive to compile code is encapsulated within a function... it
 doesn't appear in the -H output.

 So uh... git://critter.cloudns.org/test-dlang-encapsulation I guess. It
 might be a neat trick to speed up compilation, if you have a lot of
 complicated code that can be hidden behind a simple interface.
Sounds like a use case for creating a source file in a pregeneration step.
Aug 27 2016