Alek86
Alek86

Reputation: 1569

C++ modules: module implementation units for unnecessary recompilation?

Recently watched video from CppCon 2017: Boris Kolpackov “Building C++ Modules” https://www.youtube.com/watch?v=E8EbDcLQAoc

Approximately at 31:35 he starts explaining that we should still use header/source splitting and shows 3 reasons. The first reason:

If you have both declarations/definitions in the same place when you touch this module all other modules that depend on the module interface (BMI) will be recompiled.

And that I didn't like at all. It sounded like we are still in 90s and compilers cannot be smart enough to see difference in BMI-related changes and implementation related changes. As I see it, compilers are able to quickly scan each module and generate only BMI from it. And if BMI is not changed - don't recompile other modules that depend on it.

Or am I missing something?

Upvotes: 3

Views: 860

Answers (1)

Smi
Smi

Reputation: 14316

The author of that talk later said the recompilation issue is a matter of implementation. Quoting the article Common C++ Modules TS Misconceptions by Boris Kolpackov:

It turns out a lot of people would like to get rid of the header/source split (or, in modules terms, interface/implementation split) and keep everything in a single file. You can do that in Modules TS: with modules (unlike headers) you can define non-inline functions and variables in module interface units. So if you want to keep everything in a single file, you can.

and

Now, keeping everything in a single file may have negative build performance implications but it appears a smart enough build system in cooperation with the compiler should be able to overcome this. See this discussion for details.

Quoting Gor Nishanov (the Project Editor of Coroutines TS) from the linked thread:

That is up to you how to structure your code. Module TS does not impose on you how you decompose your module into individual files. If you want, you can implement your entire module in the interface file (thus you will have C# like experience), or you can partition your module into an interface and one or more implementation files.

The Project Editor of Modules TS, Gabriel Dos Reis, commented on the MSVC implementation:

Ideally, only semantics-relevant changes should trigger recompilation keyed on the IFC.

(As a side note, the Modules TS has now been approved and sent to ISO for publication.)

Upvotes: 4

Related Questions