[clang] 853ca54 - [C++20][Modules][6/8] Record direct module imports.
Iain Sandoe via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 27 02:07:26 PST 2022
Author: Iain Sandoe
Date: 2022-02-27T10:07:11Z
New Revision: 853ca5472314e109b98e46f0985f27f79e17d2bd
URL: https://github.com/llvm/llvm-project/commit/853ca5472314e109b98e46f0985f27f79e17d2bd
DIFF: https://github.com/llvm/llvm-project/commit/853ca5472314e109b98e46f0985f27f79e17d2bd.diff
LOG: [C++20][Modules][6/8] Record direct module imports.
This is a small cache to avoid having to check both Exports and
Imports.
Differential Revision: https://reviews.llvm.org/D118589
Added:
Modified:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaModule.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0b872c48482db..9937846e05658 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2219,6 +2219,9 @@ class Sema final {
/// The global module fragment of the current translation unit.
clang::Module *GlobalModuleFragment = nullptr;
+ /// The modules we imported directly.
+ llvm::SmallPtrSet<clang::Module *, 8> DirectModuleImports;
+
/// Namespace definitions that we will export when they finish.
llvm::SmallPtrSet<const NamespaceDecl*, 8> DeferredExportedNamespaces;
@@ -2246,6 +2249,10 @@ class Sema final {
return Entity->getOwningModule();
}
+ bool isModuleDirectlyImported(const Module *M) {
+ return DirectModuleImports.contains(M);
+ }
+
/// Make a merged definition of an existing hidden definition \p ND
/// visible at the specified location.
void makeMergedDefinitionVisible(NamedDecl *ND);
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 0606b3a4edae8..a829693fafebc 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -514,6 +514,11 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
assert(ThisModule && "was expecting a module if building one");
}
+ // In some cases we need to know if an entity was present in a directly-
+ // imported module (as opposed to a transitive import). This avoids
+ // searching both Imports and Exports.
+ DirectModuleImports.insert(Mod);
+
return Import;
}
More information about the cfe-commits
mailing list