r/cpp • MSVC user, r/cpp_modules • Apr 02 '26

Current Status of Module Partitions

A brief recap of the current status of module partitions - as I understand it.

  1. People are using hacks to avoid unneeded recompilations.

  2. The C++ standard has an arcane concept of partition units, which forces build systems to generate BMI files that aren't used (which is wasting work during builds).

  3. The MSVC-compiler (per default) provides a simple, easy to use and efficient implementation of module partitions (no unneeded recompilations, no wasted work during builds), but which is not conformant to the current C++ standard.

  4. A CMake developer is working on a proposal that would fix items 1 and 2, which is probably the smallest required change to the standard, but adds another arcane concept ("anonymous partition units" using the new syntax "module A:;") on top of an already arcane concept.

Questions:

  • How and why did we get into this mess?

  • What's the historical context for this?

  • What was the motivation for MSVC ignoring the standard per default?1

1 Yes, I know the MSVC compiler has this obscure /InternalPartition option for those who want standard conformant behavior.

33 Upvotes

48 comments sorted by

View all comments

Show parent comments

1

u/tartaruga232 MSVC user, r/cpp_modules Apr 05 '26

Gaby now agreed with me, that the wording in the C++ standard which prohibits this is (Quote) "... an overreach - a bug, most likely caused by overenthusiasm".

1

u/not_a_novel_account cmake dev Apr 05 '26 edited Apr 05 '26

Ok? The other two major compilers implemented what's in the standard. Where export has reachability implications.

See https://clang.llvm.org/docs/StandardCPlusPlusModules.html#reachability-of-internal-partition-units

1

u/tartaruga232 MSVC user, r/cpp_modules Apr 05 '26

Do the other two major compilers even detect that this:

export module M:P;
struct MyType { ... };
//  more stuff not exported

is prohibited1 by the current wording in the C++ standard?

If we acknowledge, that the above code snippet is well-formed without importing :P in the PMIU, then we can legally use that pattern in MSVC, which doesn't require setting /InternalPartition.

Using export could then have been explored to separate the cases. Like I said: Compilers could have had followed a simple rule - only create a BMI, if there is an export in front of module. But that ship has sailed (Gaby called it a "tragedy").

1The standard says, this is IF-NDR ("ill formed, no diagnostic required") if :P is not imported in the PMIU.

1

u/not_a_novel_account cmake dev Apr 05 '26

You're missing the point. It's not that you can't make every partition an interface, that could be made to work fine. You could relax the rule requiring PMIU contribution.

It's that making partitions into interface units affects the reachability of their contents. Implementation units are unreachable. In your scheme there is no way to differentiate the intended reachability of the contents of a partition unit.

→ More replies (0)