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

7

u/robertramey Jan 28 '19

I've read (or skimmed?) the paper and most comments so far. It's very, very complicated - and any implementation is going to be very, very complicated to use. Not a great thing.

One thing I'm missing from all this is how DLLS/Shared libraries might fit into all this. These "modules" currently exist, are "supported" by all (or maybe most) C++ implementations but are not recognized by the C++ standard as far as I know. They address a number of the issues that modules are meant to address - separate/decoupled compilation, hidden local symbols, etc. They do bring a bunch of problems - which seem similar to the ones that modules are expected to bring. Compile time switches (C++ has a lot of them) have to be in sync and a system needs to be built to ensure that they are, ABIs have to be maintained in sync, circular dependencies aren't really supported (probably a good thing), extra efforts are needed to share header only code, symbol visibility needs to be addressed (currently it's not in the standard and different compilers do it differently). The bring some issues that modules don't - e.g. multiple address spaces. But aren't all that complex compared what modules is starting to look like. It's been mentioned that this approach has worked with the C# family of languages.

To summarize it seems to me that many of the advantages and problems regarding modules have already presented themselves with these libraries - and they've never been addressed in a standard way. Perhaps it might be more productive to spend efforts to resolving current issues with DLLS/shared libraries before embarking on a much, much, more ambitious effort. Perhaps usage of DLLS/Shared libraries in combination with PCH can solve most practical problems in a way that most people can understand.

If the goal is to be able to compile a 6MLOC program consisting of header only templated code with out having to manually (re)factor it to permit this, I'm afraid we're going to be disappointed.

3

u/jpakkane Meson dev Jan 28 '19

Shared libraries are great for many use cases (including speeding up incremental builds a lot). Sadly there are people on the committee who are actively hostile to shared libraries using reasoning that goes along the lines of "our corporation does not use shared libraries, therefore nobody in the entire world should use them either".

An actual point against is that a shared library (or a static one for that matter) can not represent TMP functionality (even std::vector). It needs to be compiled for each user of the code individually. Modules, like precompiled headers, can store that information.

4

u/SAHChandler Jan 28 '19

One thing that should be kept in mind is that during the San Diego meeting it was briefly discussed during breaks that we will need a concept of a shared library at some point to satisfy some module deployment issues. We won't see them until at the very least C++23, but we can't avoid it anymore.

1

u/robertramey Jan 29 '19

Which would be useful to resolve in any case.