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

Let's bite the Bullet: Module Units shouldn't implicitly import anything

https://github.com/abuehl/docs/blob/main/no-implicit-import.md

The correct fix ... is to attack the root cause and stop implicitly importing the interface of module implementation units.

Adding yet another kind of partition is the wrong way to solve it.

19 Upvotes

34 comments sorted by

View all comments

Show parent comment

1

u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions Apr 13 '26

Question about the messy alternative. Given that you made those modules partitions, you'd have to re-import them in the PMIU, correct?

4

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

If you are referring to (quote from my document):

// Translation unit #6
module M:impl.P1.A;
import :P1;
...

// Translation unit #7
module M:impl.P1.B;
import :P1;
...

Then I think the answer to your question is: No.

The sole purpose of these "internal partitions" is, that they implement some functions of module M, which are then linked into the *.exe. The only thing we need is, that these functions are "attached" to module M. The symbols cannot clash with any symbol from a different module. To the linker, these are private symbols.

To do that, TU 6 and 7 import only the declarations from :P1. Because only these declarations are needed there.

When compiling TU #6, the compiler produces a *.obj, containing the compiled code for the functions that were defined in TU #6. It also produces a BMI. The BMI is unused and unwanted, but I think we can't avoid that. Because the intention of internal partitions normally is, that they provide declarations for use in other parts of the same module. But TU #6 and TU #7 are not used for that purpose. They aren't imported anywhere.

Like I said in my document:

Basically, the sole reason to use internal partitions in this case is: Partitions do not implicitly import anything.

Partitions do not implicitly import anything. That's the reason for using them there.

You wrote:

Given that you made those modules partitions ...

Partitions aren't modules. They are module units. They are parts of a module.

See also https://abuehl.github.io/2026/04/09/internal-partitions.html