Skip to content

Commit 51786eb

Browse files
authored
[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.
1 parent fc3dff9 commit 51786eb

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
@@ -163,8 +163,13 @@ static TypeCode getTypeCodeForTypeClass(Type::TypeClass id) {
163163

164164
namespace {
165165

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

170175
const HeaderSearch &HS = PP.getHeaderSearchInfo();
@@ -4735,8 +4740,16 @@ void ASTWriter::computeNonAffectingInputFiles() {
47354740
if (!Cache->OrigEntry)
47364741
continue;
47374742

4738-
if (!isModuleMap(File.getFileCharacteristic()) ||
4739-
llvm::is_contained(AffectingModuleMaps, *Cache->OrigEntry))
4743+
// Don't prune anything other than module maps.
4744+
if (!isModuleMap(File.getFileCharacteristic()))
4745+
continue;
4746+
4747+
// Don't prune module maps if all are guaranteed to be affecting.
4748+
if (!AffectingModuleMaps)
4749+
continue;
4750+
4751+
// Don't prune module maps that are affecting.
4752+
if (llvm::is_contained(*AffectingModuleMaps, *Cache->OrigEntry))
47404753
continue;
47414754

47424755
IsSLocAffecting[I] = false;

0 commit comments

Comments
 (0)