Skip to content

Commit

Permalink
[clang] NFCI: Split HeaderSearch::findAllModulesForHeader()
Browse files Browse the repository at this point in the history
This mimics the `ModuleMap` API and enables D151854, where the `AllowCreation = true` function needs `FileEntryRef` but `AllowCreation = false` functions is happy with plain `FileEntry`. No functional change intended.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D151853
  • Loading branch information
jansvoboda11 committed Jun 1, 2023
1 parent f097290 commit 2e1ec4c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
8 changes: 6 additions & 2 deletions clang/include/clang/Lex/HeaderSearch.h
Expand Up @@ -670,8 +670,12 @@ class HeaderSearch {
///
/// \ref findModuleForHeader should typically be used instead of this.
ArrayRef<ModuleMap::KnownHeader>
findAllModulesForHeader(const FileEntry *File,
bool AllowCreation = true) const;
findAllModulesForHeader(const FileEntry *File) const;

/// Like \ref findAllModulesForHeader, but do not attempt to infer module
/// ownership from umbrella headers if we've not already done so.
ArrayRef<ModuleMap::KnownHeader>
findResolvedModulesForHeader(const FileEntry *File) const;

/// Read the contents of the given module map file.
///
Expand Down
6 changes: 1 addition & 5 deletions clang/include/clang/Lex/ModuleMap.h
Expand Up @@ -446,13 +446,9 @@ class ModuleMap {
/// and does not consult the external source. (Those checks are the
/// responsibility of \ref HeaderSearch.)
///
/// \param AllowCreation Whether to allow inference of a new submodule, or to
/// only return existing known modules.
///
/// Typically, \ref findModuleForHeader should be used instead, as it picks
/// the preferred module for the header.
ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File,
bool AllowCreation = true);
ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File);

/// Like \ref findAllModulesForHeader, but do not attempt to infer module
/// ownership from umbrella headers if we've not already done so.
Expand Down
15 changes: 12 additions & 3 deletions clang/lib/Lex/HeaderSearch.cpp
Expand Up @@ -1570,14 +1570,23 @@ HeaderSearch::findModuleForHeader(const FileEntry *File, bool AllowTextual,
}

ArrayRef<ModuleMap::KnownHeader>
HeaderSearch::findAllModulesForHeader(const FileEntry *File,
bool AllowCreation) const {
HeaderSearch::findAllModulesForHeader(const FileEntry *File) const {
if (ExternalSource) {
// Make sure the external source has handled header info about this file,
// which includes whether the file is part of a module.
(void)getExistingFileInfo(File);
}
return ModMap.findAllModulesForHeader(File, AllowCreation);
return ModMap.findAllModulesForHeader(File);
}

ArrayRef<ModuleMap::KnownHeader>
HeaderSearch::findResolvedModulesForHeader(const FileEntry *File) const {
if (ExternalSource) {
// Make sure the external source has handled header info about this file,
// which includes whether the file is part of a module.
(void)getExistingFileInfo(File);
}
return ModMap.findResolvedModulesForHeader(File);
}

static bool suggestModule(HeaderSearch &HS, const FileEntry *File,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Lex/ModuleMap.cpp
Expand Up @@ -684,12 +684,12 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) {
}

ArrayRef<ModuleMap::KnownHeader>
ModuleMap::findAllModulesForHeader(const FileEntry *File, bool AllowCreation) {
ModuleMap::findAllModulesForHeader(const FileEntry *File) {
HeadersMap::iterator Known = findKnownHeader(File);
if (Known != Headers.end())
return Known->second;

if (AllowCreation && findOrCreateModuleForHeaderInUmbrellaDir(File))
if (findOrCreateModuleForHeaderInUmbrellaDir(File))
return Headers.find(File)->second;

return std::nullopt;
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Serialization/ASTWriter.cpp
Expand Up @@ -185,8 +185,7 @@ std::set<const FileEntry *> GetAffectingModuleMaps(const Preprocessor &PP,
if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
continue;

for (const auto &KH :
HS.findAllModulesForHeader(File, /*AllowCreation=*/false)) {
for (const auto &KH : HS.findResolvedModulesForHeader(File)) {
if (!KH.getModule())
continue;
ModulesToProcess.push_back(KH.getModule());
Expand Down

0 comments on commit 2e1ec4c

Please sign in to comment.