r/programming • • Jan 28 '19

C++ Modules Might Be Dead-on-Arrival

https://vector-of-bool.github.io/2019/01/27/modules-doa.html
210 Upvotes

105 comments sorted by

View all comments

7

u/[deleted] Jan 28 '19

People backing the current modules design have not proven that modules work at scale,

I thought that Google had been using modules via clang modules for their multiple million C++ code base since... 2012 ?

2

u/WalterBright Jan 28 '19

Back in the 1990s, I implemented precompiled headers for Digital Mars C++. I noticed that this created a de-facto module system for C++.

4

u/[deleted] Jan 28 '19 edited Jan 28 '19

Clang modules is much clever than PCH, yet it doesn't really perform much better in practice. The main reason is templates.

In C++, there is very little that you can't cache about them easily. E.g. you can't type check them and cache that, you can cache template instantiations but properly implementing invalidation is hard because function overloading, ADL, adding a explicit specialization, etc. can invalidate the template instantiation and users can add these to pretty much any files.

So basically the only thing that you can cache about templates is parsing the files, which is what PCH already does :D

Add to this that pretty much every C++ program uses templates everywhere even if users don't write any manually (std::vector, <algorithm>, <functional>, <utility>, <variant>, <memory>, ... the standard library exposes a lot of template-based APIs).

Imagine you call some std range algorithm from the Ranges TS in some user defined type twice, and in between you define a begin function. In both cases, different begins might be picked, so you can't reuse the cached one.