[clang] 64d8c78 - Revert "Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, and DirectoryName, NFC"
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 23 09:57:38 PST 2021
Author: Duncan P. N. Exon Smith
Date: 2021-02-23T09:57:28-08:00
New Revision: 64d8c7818db2bd428d4e2a9f27661ee49225477f
URL: https://github.com/llvm/llvm-project/commit/64d8c7818db2bd428d4e2a9f27661ee49225477f
DIFF: https://github.com/llvm/llvm-project/commit/64d8c7818db2bd428d4e2a9f27661ee49225477f.diff
LOG: Revert "Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, and DirectoryName, NFC"
This (mostly) reverts 32c501dd88b62787d3a5ffda7aabcf4650dbe3cd. Hit a
case where this causes a behaviour change, perhaps the same root cause
that triggered the revert of a40db5502b2515a6f2f1676b5d7a655ae0f41179 in
7799ef7121aa7d59f4bd95cdf70035de724ead6f.
(The API changes in DirectoryEntry.h have NOT been reverted as a number
of subsequent commits depend on those.)
https://reviews.llvm.org/D90497#2582166
Added:
Modified:
clang/include/clang/Basic/Module.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Basic/Module.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Serialization/ASTReader.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index f5b176f8d20b..82ea1f462949 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -133,9 +133,7 @@ class Module {
std::string PresumedModuleMapFile;
/// The umbrella header or directory.
- llvm::PointerUnion<const FileEntryRef::MapEntry *,
- const DirectoryEntryRef::MapEntry *>
- Umbrella;
+ llvm::PointerUnion<const FileEntry *, const DirectoryEntry *> Umbrella;
/// The module signature.
ASTFileSignature Signature;
@@ -190,18 +188,18 @@ class Module {
/// file.
struct Header {
std::string NameAsWritten;
- OptionalFileEntryRefDegradesToFileEntryPtr Entry;
+ const FileEntry *Entry;
- explicit operator bool() { return Entry != None; }
+ explicit operator bool() { return Entry; }
};
/// Information about a directory name as found in the module map
/// file.
struct DirectoryName {
std::string NameAsWritten;
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr Entry;
+ const DirectoryEntry *Entry;
- explicit operator bool() { return Entry != None; }
+ explicit operator bool() { return Entry; }
};
/// The headers that are part of this module.
@@ -546,15 +544,15 @@ class Module {
/// Retrieve the header that serves as the umbrella header for this
/// module.
Header getUmbrellaHeader() const {
- if (auto *ME = Umbrella.dyn_cast<const FileEntryRef::MapEntry *>())
- return Header{UmbrellaAsWritten, FileEntryRef(*ME)};
+ if (auto *FE = Umbrella.dyn_cast<const FileEntry *>())
+ return Header{UmbrellaAsWritten, FE};
return Header{};
}
/// Determine whether this module has an umbrella directory that is
/// not based on an umbrella header.
bool hasUmbrellaDir() const {
- return Umbrella && Umbrella.is<const DirectoryEntryRef::MapEntry *>();
+ return Umbrella && Umbrella.is<const DirectoryEntry *>();
}
/// Add a top-level header associated with this module.
diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 6827408f10a3..f6423e5b4258 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -14,7 +14,6 @@
#ifndef LLVM_CLANG_LEX_MODULEMAP_H
#define LLVM_CLANG_LEX_MODULEMAP_H
-#include "clang/Basic/FileEntry.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/Module.h"
@@ -38,6 +37,7 @@ namespace clang {
class DiagnosticsEngine;
class DirectoryEntry;
+class FileEntry;
class FileManager;
class HeaderSearch;
class SourceManager;
@@ -648,12 +648,12 @@ class ModuleMap {
/// Sets the umbrella header of the given module to the given
/// header.
- void setUmbrellaHeader(Module *Mod, FileEntryRef UmbrellaHeader,
+ void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
Twine NameAsWritten);
/// Sets the umbrella directory of the given module to the given
/// directory.
- void setUmbrellaDir(Module *Mod, DirectoryEntryRef UmbrellaDir,
+ void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
Twine NameAsWritten);
/// Adds this header to the given module.
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 2dd53b05d442..8730a5d5f4e7 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -247,10 +247,7 @@ Module::DirectoryName Module::getUmbrellaDir() const {
if (Header U = getUmbrellaHeader())
return {"", U.Entry->getDir()};
- if (auto *ME = Umbrella.dyn_cast<const DirectoryEntryRef::MapEntry *>())
- return {UmbrellaAsWritten, DirectoryEntryRef(*ME)};
-
- return {"", None};
+ return {UmbrellaAsWritten, Umbrella.dyn_cast<const DirectoryEntry *>()};
}
void Module::addTopHeader(const FileEntry *File) {
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index 060cec23acc4..38b6f753134c 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -297,7 +297,7 @@ bool GenerateHeaderModuleAction::BeginSourceFileAction(
<< Name;
continue;
}
- Headers.push_back({std::string(Name), *FE});
+ Headers.push_back({std::string(Name), &FE->getFileEntry()});
}
HS.getModuleMap().createHeaderModule(CI.getLangOpts().CurrentModule, Headers);
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index bbda1f15a702..28dd7ed969ad 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -300,7 +300,7 @@ bool ModuleMap::resolveAsBuiltinHeader(
// supplied by Clang. Find that builtin header.
SmallString<128> Path;
llvm::sys::path::append(Path, BuiltinIncludeDir->getName(), Header.FileName);
- auto File = SourceMgr.getFileManager().getOptionalFileRef(Path);
+ auto File = SourceMgr.getFileManager().getFile(Path);
if (!File)
return false;
@@ -1012,7 +1012,7 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
// Look for an umbrella header.
SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
llvm::sys::path::append(UmbrellaName, "Headers", ModuleName + ".h");
- auto UmbrellaHeader = FileMgr.getOptionalFileRef(UmbrellaName);
+ auto UmbrellaHeader = FileMgr.getFile(UmbrellaName);
// FIXME: If there's no umbrella header, we could probably scan the
// framework to load *everything*. But, it's not clear that this is a good
@@ -1121,21 +1121,21 @@ Module *ModuleMap::createShadowedModule(StringRef Name, bool IsFramework,
return Result;
}
-void ModuleMap::setUmbrellaHeader(Module *Mod, FileEntryRef UmbrellaHeader,
+void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
Twine NameAsWritten) {
Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
- Mod->Umbrella = &UmbrellaHeader.getMapEntry();
+ Mod->Umbrella = UmbrellaHeader;
Mod->UmbrellaAsWritten = NameAsWritten.str();
- UmbrellaDirs[UmbrellaHeader.getDir()] = Mod;
+ UmbrellaDirs[UmbrellaHeader->getDir()] = Mod;
// Notify callbacks that we just added a new header.
for (const auto &Cb : Callbacks)
Cb->moduleMapAddUmbrellaHeader(&SourceMgr.getFileManager(), UmbrellaHeader);
}
-void ModuleMap::setUmbrellaDir(Module *Mod, DirectoryEntryRef UmbrellaDir,
+void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
Twine NameAsWritten) {
- Mod->Umbrella = &UmbrellaDir.getMapEntry();
+ Mod->Umbrella = UmbrellaDir;
Mod->UmbrellaAsWritten = NameAsWritten.str();
UmbrellaDirs[UmbrellaDir] = Mod;
}
@@ -2416,15 +2416,15 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
}
// Look for this file.
- Optional<DirectoryEntryRef> Dir;
+ const DirectoryEntry *Dir = nullptr;
if (llvm::sys::path::is_absolute(DirName)) {
- if (auto D = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName))
+ if (auto D = SourceMgr.getFileManager().getDirectory(DirName))
Dir = *D;
} else {
SmallString<128> PathName;
PathName = Directory->getName();
llvm::sys::path::append(PathName, DirName);
- if (auto D = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName))
+ if (auto D = SourceMgr.getFileManager().getDirectory(PathName))
Dir = *D;
}
@@ -2445,7 +2445,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
SourceMgr.getFileManager().getVirtualFileSystem();
for (llvm::vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E;
I != E && !EC; I.increment(EC)) {
- if (auto FE = SourceMgr.getFileManager().getOptionalFileRef(I->path())) {
+ if (auto FE = SourceMgr.getFileManager().getFile(I->path())) {
Module::Header Header = {std::string(I->path()), *FE};
Headers.push_back(std::move(Header));
}
@@ -2459,7 +2459,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
return;
}
- if (Module *OwningModule = Map.UmbrellaDirs[*Dir]) {
+ if (Module *OwningModule = Map.UmbrellaDirs[Dir]) {
Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
<< OwningModule->getFullModuleName();
HadError = true;
@@ -2467,7 +2467,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
}
// Record this umbrella directory.
- Map.setUmbrellaDir(ActiveModule, *Dir, DirName);
+ Map.setUmbrellaDir(ActiveModule, Dir, DirName);
}
/// Parse a module export declaration.
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index ccd3e8d69d3a..9752a7c0b1e7 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1924,8 +1924,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
// FIXME: This is not always the right filename-as-written, but we're not
// going to use this information to rebuild the module, so it doesn't make
// a lot of
diff erence.
- Module::Header H = {std::string(key.Filename),
- *FileMgr.getOptionalFileRef(Filename)};
+ Module::Header H = {std::string(key.Filename), *FileMgr.getFile(Filename)};
ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader);
}
@@ -5614,7 +5613,7 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
case SUBMODULE_UMBRELLA_HEADER: {
std::string Filename = std::string(Blob);
ResolveImportedPath(F, Filename);
- if (auto Umbrella = PP.getFileManager().getOptionalFileRef(Filename)) {
+ if (auto Umbrella = PP.getFileManager().getFile(Filename)) {
if (!CurrentModule->getUmbrellaHeader())
ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob);
else if (CurrentModule->getUmbrellaHeader().Entry != *Umbrella) {
@@ -5647,8 +5646,7 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
case SUBMODULE_UMBRELLA_DIR: {
std::string Dirname = std::string(Blob);
ResolveImportedPath(F, Dirname);
- if (auto Umbrella =
- PP.getFileManager().getOptionalDirectoryRef(Dirname)) {
+ if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
if (!CurrentModule->getUmbrellaDir())
ModMap.setUmbrellaDir(CurrentModule, *Umbrella, Blob);
else if (CurrentModule->getUmbrellaDir().Entry != *Umbrella) {
More information about the cfe-commits
mailing list