Wanted to get peoples thoughts on this. The idea is to have a way to tell the compiler (probably with a command line option) that you'd like to "compile imported modules". Say you have a program "prog" that depends on modules "foo" and "bar".

    import foo;
    import bar;

Compilation could look like:

    dmd prog.d foo.d bar.d

Or it could look like

    dmd -c foo.d
    dmd -c bar.d
    dmd prog.d foo.obj bar.obj

With this command line option, let's call it "-compile-imports" for now, you could do something like:

    dmd -compile-imports prog.d

This tells the compiler that after it has processed all the input files (source code/object files/library files), if it is missing modules, it should go back and look for those modules in it's list of imported modules, then compile them from there. It's important that it only checks this after processing all the input files so that precompiled modules take precedence. So you could still do something like this:

    dmd -c foo.d
    dmd -compile-imports prog.d foo.obj

In this example we use the precompiled foo module and then the compiler notices that the bar module is missing. So it looks for the source in it's list of imports, then includes that in it's list of files to compile essentialy behaving as if that file was passed on the command line.

This is a simple example with only 2 modules, but for projects that use alot of libraries it could turn into something like this:

dmd prog.d -Isomelib somelib\foo\module1.d somelib\foo\module2.d somelib\foo\module3.d somelib\foo\module4.d somelib\foo\module5.d somelib\foo\module6.d -Ianotherlib anotherlib\bar\module1.d anotherlib\bar\module2.d anotherlib\bar\module3.d anotherlib\bar\module4.d anotherlib\bar\module5.d

into this:

    dmd -compile-imports prog.d -Isomelib -Ianotherlib

This would also simplify rdmd and make it "less brittle" because it will not need to duplicate the logic inside the compiler that locates and selects which module files to compile. Instead, it can simply use the -compile-imports switch leave that logic completely in the compiler.

Reply via email to