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 comment

2

u/tartaruga232 MSVC user, r/cpp_modules Apr 02 '26 edited Apr 02 '26

By the way: For users of the MSVC compiler, using the partition naming pattern to avoid unneeded recompilations would require:

  • Setting the /InternalPartition flag on every single cpp-file which implements functions of the external partition.
  • Adding a unique character sequence to the name of the partition unit (and making sure it won't clash with any other name in the module).

For example, our file Core/Attach/IPointAttachment.cpp would need to look like this:

module Core:Attach.IPointAttachment;

import :Attach;

namespace Core
{

auto IPointAttachment::findNearestPointImpl(const d1::fPoint&, bool) const
    -> NearestRes
{
    ...
}

}

The compiler then generates a .ifc and a.obj file for that input file. The .ifc file is unused, because Core:Attach.IPointAttachment will never ever be imported anywhere.

This would be conformant to the current C++ standard.

I don't think anyone using the MSVC compiler will ever do this in the long run for large projects, if they can instead simply write:

module Core:Attach;

namespace Core
{

auto IPointAttachment::findNearestPointImpl(const d1::fPoint&, bool) const
    -> NearestRes
{
    ...
}

}

which does the same by default (i.e. /InternalPartition not set), and without producing an unneeded .ifc file.