[clang] [clang][modules] Only compute affecting module maps with implicit search (PR #87849)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 16 17:30:53 PDT 2024


================
@@ -161,8 +161,13 @@ static TypeCode getTypeCodeForTypeClass(Type::TypeClass id) {
 
 namespace {
 
-std::set<const FileEntry *> GetAffectingModuleMaps(const Preprocessor &PP,
-                                                   Module *RootModule) {
+std::optional<std::set<const FileEntry *>>
+GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) {
+  // Without implicit module map search, there's no good reason to know about
+  // any module maps that are not affecting.
+  if (!PP.getHeaderSearchInfo().getHeaderSearchOpts().ImplicitModuleMaps)
+    return std::nullopt;
----------------
zygoloid wrote:

Yes, that sounds great, thank you. In our case, it's not that the module map files are unused, it's that we specify the same `-fmodule-map-file=` flag to all of our compilations, and so we *usually* get the information from a `.pcm` file rather than from the module map file, and it turns out that pruning out the repeated module maps make a rather large difference to our source location address space usage :)

All that said, we have some other ideas for how to address the problems we're seeing with source location address space usage. Maybe we can get to a point where we're not relying on this at all -- I think this patch is probably the right behavior, even though I think it's contributing to a regression for us, so I think this new behavior should be the default, and we can clean up the flag once we don't need it any more.

https://github.com/llvm/llvm-project/pull/87849


More information about the cfe-commits mailing list