[clang] [clang][modules] Lazily load by name lookups in module maps (PR #132853)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 26 09:43:45 PDT 2025


================
@@ -2128,9 +2245,16 @@ bool ModuleMap::loadModuleMapFile(FileEntryRef File, bool IsSystem,
 
   // If the module map file wasn't already entered, do so now.
   if (ID.isInvalid()) {
-    auto FileCharacter =
-        IsSystem ? SrcMgr::C_System_ModuleMap : SrcMgr::C_User_ModuleMap;
-    ID = SourceMgr.createFileID(File, ExternModuleLoc, FileCharacter);
+    ID = SourceMgr.translateFile(File);
+    // TODO: The way we compute affecting module maps requires this to be a
+    //       local FileID. This should be changed to reuse loaded FileIDs when
+    //       available, and change the way that affecting module maps are
+    //       computed to not require this.
+    if (ID.isInvalid() || SourceMgr.isLoadedFileID(ID)) {
----------------
jansvoboda11 wrote:

Can you explain why adding the call to `translateFile()` and conditionalizing `createFileID()` was necessary? Is the idea that this is the right thing to do to avoid creating an unnecessary `SLocEntry`? And we can eventually remove the `isLoadedFileID()` check when affecting module map computation improves?

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


More information about the cfe-commits mailing list