[clang] [clang][modules] Always keep submodule index up-to-date (PR #194039)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 24 12:51:24 PDT 2026
https://github.com/jansvoboda11 updated https://github.com/llvm/llvm-project/pull/194039
>From 1187106a8bdc0652b4b8a7e2cb340eb05f4795da Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Thu, 23 Apr 2026 14:08:42 -0700
Subject: [PATCH 1/2] [clang][modules] Always keep submodule index up-to-date
---
clang/include/clang/Basic/Module.h | 2 +-
clang/lib/Basic/Module.cpp | 5 +----
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index 1d9953af057ad..c5e53456869ab 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -352,7 +352,7 @@ class alignas(8) Module {
/// A mapping from the submodule name to the index into the
/// \c SubModules vector at which that submodule resides.
- mutable llvm::StringMap<unsigned> SubModuleIndex;
+ llvm::StringMap<unsigned> SubModuleIndex;
/// The AST file name and key if this is a top-level module which has a
/// corresponding serialized AST file, or null otherwise.
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 97f742d292224..244b6575bf3b3 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -53,6 +53,7 @@ Module::Module(ModuleConstructorTag, StringRef Name,
NoUndeclaredIncludes = Parent->NoUndeclaredIncludes;
ModuleMapIsPrivate = Parent->ModuleMapIsPrivate;
+ Parent->SubModuleIndex[Name] = Parent->SubModules.size();
Parent->SubModules.push_back(this);
}
}
@@ -348,10 +349,6 @@ void Module::markUnavailable(bool Unimportable) {
}
Module *Module::findSubmodule(StringRef Name) const {
- // Add new submodules into the index.
- for (unsigned I = SubModuleIndex.size(), E = SubModules.size(); I != E; ++I)
- SubModuleIndex[SubModules[I]->Name] = I;
-
if (auto It = SubModuleIndex.find(Name); It != SubModuleIndex.end())
return SubModules[It->second];
>From 8d30b348361f883a008c668e8d2422cf8ce75b06 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Fri, 24 Apr 2026 12:51:11 -0700
Subject: [PATCH 2/2] Handle `Module::setParent()`
---
clang/include/clang/Basic/Module.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index c5e53456869ab..5bd66adc188ca 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -738,6 +738,7 @@ class alignas(8) Module {
void setParent(Module *M) {
assert(!Parent);
Parent = M;
+ Parent->SubModuleIndex[M->Name] = Parent->SubModules.size();
Parent->SubModules.push_back(this);
}
More information about the cfe-commits
mailing list