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.

18 Upvotes

34 comments sorted by

View all comments

Show parent comment

2

u/schombert Apr 14 '26

This sounds parallel to the solution with header files that I mentioned in the first post: there will have to be distinct files containing the different parts of the interface, which sounds a lot like having a set of internal headers vs. the external headers. Because if they aren't in different files, even if they are logically distinct, ninja, or the equivalent, won't be able to understand that the file being modified doesn't force a recompilation of all the things that depend on it.

1

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

Yes. With header files it's clear what should happen. We need the same efficiency from modules. No unneeded recompilations. Modules aren't bad, there is only this problem with unneeded recompilations. The proposal not to implicitly import the interface of the module M on cpp files having "module M;" would solve that. It would require to change the current C++ standard accordingly. Unneeded recompilations is unacceptable. The messy solution which is required currently shouldn't be the end of the story.

Note that all major C++ compilers have already agreed to output dependency information as a byproduct of compiling. That's already implemented today.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1689r2.html

This was done by the CMake folks. The dependency info is extracted during the scanning phase when compilers scan for module names in the files. After the scanning, the compiler knows which module is in what file and what the compile dependencies are.

1

u/not_a_novel_account cmake dev Apr 14 '26

I have genuinely no idea what you're talking about here. There's no such thing as a TU which represents "two partitions". A given TU can only contain a single module declaration, which determines both its name and its kind.

"Because if they aren't in different files" isn't meaningful within C++. module Foo:Bar and module Foo:Qux must be in different files, putting both in a single TU is ill-formed.

To answer the top question:

Which sounds a lot like going back to implementation cpp files that include library specific .hpp files combined with a single .hpp file intended for consumers of the library to include. If that analogy holds, what are modules actually adding to the story in that case?

This is exactly how modules work today and how they are intended to work. They bring export control (no more detail namespaces), macro safety, and improved build times. The basic organization of separating interfaces and implementation files remains exactly the same as with headers for performant rebuilds.

1

u/schombert Apr 14 '26

I genuinely have no idea how your response explains how this proposal would solve the recompilation problem.

1

u/not_a_novel_account cmake dev Apr 14 '26

OP's proposal removes the implicit dependency of implementation units on the PMIU. No dependency, no rebuilds on PMIU-visible interface changes.