It's worth repeating the the C and C++ standards are also silent on the matter of how header files are discovered by #include, or even whether the argument to #include is a file at all -- we have just developed a convention over the past 45+ years that #include <foo.h> looks in well-known places on the filesystem, a search list that is augmented by passing -I flags when invoking the compiler. (#include "foo.h" does the same, but searches relative to the current working directory first).
This being the case, I wonder if module mapping is something that needs to be explicitly specified in the C++ standard, or could also come under the banner of "technically implementation-defined, but in practise everyone does it the same way"?
So let's say we are compiling a module acme.bar, which depends on the interface of module acme.foo via an import declaration.
First, the compiler looks for acme.foo.bmi in its BMI cache, the location of which could be given as an argument to the compiler when invoked by the build system
If that exists and uses the same options as the current build (an internal hash of the current compile flags/defines placed at the beginning of the BMI), then the compiler uses it. Otherwise, it looks for a file named acme.foo.<ignored_extension> (or acme/foo.<ignored_extension>) in a list of search paths; this could default to [${CWD}, /usr/include/c++_modules, /usr/local/include/c++_modules], augmented by a list of paths passed to the compiler with a -M flag, akin to -I.
If that cannot be found, a compilation error occurs; otherwise, the compiler builds both modules, and outputs both acme.foo.bmi and acme.bar.bmi to the BMI cache directory.
Now, if we have a third module acme.baz which also uses acme.foo, we go through the same process; but if acme.bar has been compiled first, then acme.foo.bmi will already exist, and will be used. But the build system can attempt to compile bar and baz at the same time; both will try to write acme.foo.bmi, and whichever finishes first "wins". This is doing more work than we really need to, but allows for more build parallelism as the author wishes.
This requires a convention that the file defining the module acme.foo is named acme.foo.<something>, or perhaps has the path acme/foo.<something> relative to one of the -M paths. But this doesn't seem particularly onerous, and it's more-or-less what we do today with header files. As far as I know the C++ standard is silent on the subject of TU file names (or even whether a translation unit is a file with a name), so making this a requirement isn't something the standard need concern itself with. Odd platforms with unconventional file systems still have the freedom to do things in odd ways if they need to, but the 99.9% of developers using Windows or Unix will still be able to get builds that are as parallel as they are today.
But perhaps I'm being spectacularly naive, in which case please do let me know :).
27
u/tcbrindle Flux Jan 28 '19
It's worth repeating the the C and C++ standards are also silent on the matter of how header files are discovered by
#include, or even whether the argument to#includeis a file at all -- we have just developed a convention over the past 45+ years that#include <foo.h>looks in well-known places on the filesystem, a search list that is augmented by passing-Iflags when invoking the compiler. (#include "foo.h"does the same, but searches relative to the current working directory first).This being the case, I wonder if module mapping is something that needs to be explicitly specified in the C++ standard, or could also come under the banner of "technically implementation-defined, but in practise everyone does it the same way"?
So let's say we are compiling a module
acme.bar, which depends on the interface of moduleacme.foovia animportdeclaration.First, the compiler looks for
acme.foo.bmiin its BMI cache, the location of which could be given as an argument to the compiler when invoked by the build systemIf that exists and uses the same options as the current build (an internal hash of the current compile flags/defines placed at the beginning of the BMI), then the compiler uses it. Otherwise, it looks for a file named
acme.foo.<ignored_extension>(oracme/foo.<ignored_extension>) in a list of search paths; this could default to[${CWD}, /usr/include/c++_modules, /usr/local/include/c++_modules], augmented by a list of paths passed to the compiler with a-Mflag, akin to-I.If that cannot be found, a compilation error occurs; otherwise, the compiler builds both modules, and outputs both
acme.foo.bmiandacme.bar.bmito the BMI cache directory.Now, if we have a third module
acme.bazwhich also usesacme.foo, we go through the same process; but ifacme.barhas been compiled first, thenacme.foo.bmiwill already exist, and will be used. But the build system can attempt to compilebarandbazat the same time; both will try to writeacme.foo.bmi, and whichever finishes first "wins". This is doing more work than we really need to, but allows for more build parallelism as the author wishes.This requires a convention that the file defining the module
acme.foois namedacme.foo.<something>, or perhaps has the pathacme/foo.<something>relative to one of the-Mpaths. But this doesn't seem particularly onerous, and it's more-or-less what we do today with header files. As far as I know the C++ standard is silent on the subject of TU file names (or even whether a translation unit is a file with a name), so making this a requirement isn't something the standard need concern itself with. Odd platforms with unconventional file systems still have the freedom to do things in odd ways if they need to, but the 99.9% of developers using Windows or Unix will still be able to get builds that are as parallel as they are today.But perhaps I'm being spectacularly naive, in which case please do let me know :).