Skip to content

Commit

Permalink
Revert "Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, H…
Browse files Browse the repository at this point in the history
…eader, and DirectoryName, NFC"

This (mostly) reverts 32c501d.  Hit a
case where this causes a behaviour change, perhaps the same root cause
that triggered the revert of a40db55 in
7799ef7.

(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
  • Loading branch information
dexonsmith committed Feb 23, 2021
1 parent eb16509 commit 64d8c78
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 36 deletions.
18 changes: 8 additions & 10 deletions clang/include/clang/Basic/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/Lex/ModuleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -38,6 +37,7 @@ namespace clang {

class DiagnosticsEngine;
class DirectoryEntry;
class FileEntry;
class FileManager;
class HeaderSearch;
class SourceManager;
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions clang/lib/Basic/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
26 changes: 13 additions & 13 deletions clang/lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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));
}
Expand All @@ -2459,15 +2459,15 @@ 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;
return;
}

// Record this umbrella directory.
Map.setUmbrellaDir(ActiveModule, *Dir, DirName);
Map.setUmbrellaDir(ActiveModule, Dir, DirName);
}

/// Parse a module export declaration.
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 difference.
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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 64d8c78

Please sign in to comment.