Skip to content

Commit a14a33e

Browse files
committed
[clang][modules] Only compute affecting module maps with implicit search (llvm#87849)
When writing out a PCM, we compute the set of module maps that did affect the compilation and we strip the rest to make the output independent of them. The most common way to read a module map that is not affecting is with implicit module map search. The other option is to pass a bunch of unnecessary `-fmodule-map-file=<path>` arguments on the command-line, in which case the client should probably not give those to Clang anyway. This makes serialization of explicit modules faster, mostly due to reduced file system traffic. (cherry picked from commit 51786eb)
1 parent 39d3e65 commit a14a33e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,13 @@ static TypeCode getTypeCodeForTypeClass(Type::TypeClass id) {
161161

162162
namespace {
163163

164-
std::set<const FileEntry *> GetAffectingModuleMaps(const Preprocessor &PP,
165-
Module *RootModule) {
164+
std::optional<std::set<const FileEntry *>>
165+
GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) {
166+
// Without implicit module map search, there's no good reason to know about
167+
// any module maps that are not affecting.
168+
if (!PP.getHeaderSearchInfo().getHeaderSearchOpts().ImplicitModuleMaps)
169+
return std::nullopt;
170+
166171
SmallVector<const Module *> ModulesToProcess{RootModule};
167172

168173
const HeaderSearch &HS = PP.getHeaderSearchInfo();
@@ -4682,8 +4687,16 @@ void ASTWriter::computeNonAffectingInputFiles() {
46824687
if (!Cache->OrigEntry)
46834688
continue;
46844689

4685-
if (!isModuleMap(File.getFileCharacteristic()) ||
4686-
llvm::is_contained(AffectingModuleMaps, *Cache->OrigEntry))
4690+
// Don't prune anything other than module maps.
4691+
if (!isModuleMap(File.getFileCharacteristic()))
4692+
continue;
4693+
4694+
// Don't prune module maps if all are guaranteed to be affecting.
4695+
if (!AffectingModuleMaps)
4696+
continue;
4697+
4698+
// Don't prune module maps that are affecting.
4699+
if (llvm::is_contained(*AffectingModuleMaps, *Cache->OrigEntry))
46874700
continue;
46884701

46894702
IsSLocAffecting[I] = false;

0 commit comments

Comments
 (0)