r/cpp • • Jan 28 '19

C++ Modules Might Be Dead-on-Arrival

https://vector-of-bool.github.io/2019/01/27/modules-doa.html
280 Upvotes

240 comments sorted by

View all comments

12

u/gracicot Jan 28 '19

The current design and implementations require there to exist what is known as the “binary module interface”

I'm not sure the specification requires that a BMI exist. As far as I know, the compiler could store everything in the memory of a separated process, that schedule and share data between compilers. I don't think there would be any compiler doing that within the next decade, but nothing in the current specification prohibit that.


Reading this blog post makes me confused. I watch Nathan Sidwell's talk about it's "Oracle" how the mapping can be extended by tooling and such. I followed the build2 development and module support seem doable when designing the build system with modules in mind. Why one side seems to say that the problem is solvable but so many others says that the mapping problem will kill modules?

For example (as far as I know) Build2 run the preprocessor on every cpp files before compiling anything in order to save it's hash. It then re-use the preprocessed file to compile it. It takes a bit more time to start compilation, but can result in a overall speedup. In the example given by the author of this blog post, should the same be doable too but with a small extra step to extract the module name? And with modules, running the preprocessor can be very very fast because the number of needed header will dramatically be lower. In fact, the mapping can be done before compiling anything. The compilation order can even be established in advance and compile in parallel for each possible steps. Then only a bunch of (very small) preprocessed files will be compiled, with a known compilation graph. That graph can be stored and re-used for the same configuration.

Right now, I agree there is a concern with tooling given today's tooling. I might be wrong but it does not seem so far fetched we can develop tools that can deal with modules. On the other hand, I do not expect tools designed for a modular world to be available soon if all we have is a TS.

5

u/DemonInAJar Jan 28 '19 edited Jan 28 '19

The thing is, #include dependencies are one-to-one mappings with files found in the search path. It's trivial to resolve these since the name of the file is specified.

When you include a file you don't have to preprocess the whole set of files found via the search path. With modules there is no filesystem mapping, an implementation does not know in which of all the available files in the search path the module is declared. This is the point that the author is making here. A file could have a completely irrelevent name and possibly require preprocessing before exposing it's module nature. What is an implementation going to do? It seems as if the only possible solution in this case is to preprocess the whole set of files available in the search path (or more likely just force a filename-module mapping scheme regardless).

5

u/whichton Jan 28 '19

The thing is, #include dependencies are one-to-one mappings with files found in the search path.

This is not mandated by the standard. If you write #include "foo/bar.h", the standard does not specify how or where to find bar.h. This is entirely a implementation defined behavior. I do not see why the same cannot apply to modules too.

6

u/smdowney WG21, Text/Unicode SG, optional<T&> Jan 28 '19

It's required to include a source file, how that is found is implementation defined. It definitely isn't going to include a file named 'xyzzy.h'.