Skip to content

Commit

Permalink
[C++20][Modules][6/8] Record direct module imports.
Browse files Browse the repository at this point in the history
This is a small cache to avoid having to check both Exports and
Imports.

Differential Revision: https://reviews.llvm.org/D118589
  • Loading branch information
iains committed Feb 27, 2022
1 parent 2bbe650 commit 853ca54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clang/include/clang/Sema/Sema.h
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaModule.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit 853ca54

Please sign in to comment.