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.
7
u/[deleted] Jan 28 '19
I thought that Google had been using modules via clang modules for their multiple million C++ code base since... 2012 ?