Skip to content

Commit 64d8c78

Browse files
committed
Revert "Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, 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
1 parent eb16509 commit 64d8c78

File tree

6 files changed

+29
-36
lines changed

6 files changed

+29
-36
lines changed

clang/include/clang/Basic/Module.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ class Module {
133133
std::string PresumedModuleMapFile;
134134

135135
/// The umbrella header or directory.
136-
llvm::PointerUnion<const FileEntryRef::MapEntry *,
137-
const DirectoryEntryRef::MapEntry *>
138-
Umbrella;
136+
llvm::PointerUnion<const FileEntry *, const DirectoryEntry *> Umbrella;
139137

140138
/// The module signature.
141139
ASTFileSignature Signature;
@@ -190,18 +188,18 @@ class Module {
190188
/// file.
191189
struct Header {
192190
std::string NameAsWritten;
193-
OptionalFileEntryRefDegradesToFileEntryPtr Entry;
191+
const FileEntry *Entry;
194192

195-
explicit operator bool() { return Entry != None; }
193+
explicit operator bool() { return Entry; }
196194
};
197195

198196
/// Information about a directory name as found in the module map
199197
/// file.
200198
struct DirectoryName {
201199
std::string NameAsWritten;
202-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr Entry;
200+
const DirectoryEntry *Entry;
203201

204-
explicit operator bool() { return Entry != None; }
202+
explicit operator bool() { return Entry; }
205203
};
206204

207205
/// The headers that are part of this module.
@@ -546,15 +544,15 @@ class Module {
546544
/// Retrieve the header that serves as the umbrella header for this
547545
/// module.
548546
Header getUmbrellaHeader() const {
549-
if (auto *ME = Umbrella.dyn_cast<const FileEntryRef::MapEntry *>())
550-
return Header{UmbrellaAsWritten, FileEntryRef(*ME)};
547+
if (auto *FE = Umbrella.dyn_cast<const FileEntry *>())
548+
return Header{UmbrellaAsWritten, FE};
551549
return Header{};
552550
}
553551

554552
/// Determine whether this module has an umbrella directory that is
555553
/// not based on an umbrella header.
556554
bool hasUmbrellaDir() const {
557-
return Umbrella && Umbrella.is<const DirectoryEntryRef::MapEntry *>();
555+
return Umbrella && Umbrella.is<const DirectoryEntry *>();
558556
}
559557

560558
/// Add a top-level header associated with this module.

clang/include/clang/Lex/ModuleMap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_CLANG_LEX_MODULEMAP_H
1515
#define LLVM_CLANG_LEX_MODULEMAP_H
1616

17-
#include "clang/Basic/FileEntry.h"
1817
#include "clang/Basic/IdentifierTable.h"
1918
#include "clang/Basic/LangOptions.h"
2019
#include "clang/Basic/Module.h"
@@ -38,6 +37,7 @@ namespace clang {
3837

3938
class DiagnosticsEngine;
4039
class DirectoryEntry;
40+
class FileEntry;
4141
class FileManager;
4242
class HeaderSearch;
4343
class SourceManager;
@@ -648,12 +648,12 @@ class ModuleMap {
648648

649649
/// Sets the umbrella header of the given module to the given
650650
/// header.
651-
void setUmbrellaHeader(Module *Mod, FileEntryRef UmbrellaHeader,
651+
void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
652652
Twine NameAsWritten);
653653

654654
/// Sets the umbrella directory of the given module to the given
655655
/// directory.
656-
void setUmbrellaDir(Module *Mod, DirectoryEntryRef UmbrellaDir,
656+
void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
657657
Twine NameAsWritten);
658658

659659
/// Adds this header to the given module.

clang/lib/Basic/Module.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,7 @@ Module::DirectoryName Module::getUmbrellaDir() const {
247247
if (Header U = getUmbrellaHeader())
248248
return {"", U.Entry->getDir()};
249249

250-
if (auto *ME = Umbrella.dyn_cast<const DirectoryEntryRef::MapEntry *>())
251-
return {UmbrellaAsWritten, DirectoryEntryRef(*ME)};
252-
253-
return {"", None};
250+
return {UmbrellaAsWritten, Umbrella.dyn_cast<const DirectoryEntry *>()};
254251
}
255252

256253
void Module::addTopHeader(const FileEntry *File) {

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ bool GenerateHeaderModuleAction::BeginSourceFileAction(
297297
<< Name;
298298
continue;
299299
}
300-
Headers.push_back({std::string(Name), *FE});
300+
Headers.push_back({std::string(Name), &FE->getFileEntry()});
301301
}
302302
HS.getModuleMap().createHeaderModule(CI.getLangOpts().CurrentModule, Headers);
303303

clang/lib/Lex/ModuleMap.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ bool ModuleMap::resolveAsBuiltinHeader(
300300
// supplied by Clang. Find that builtin header.
301301
SmallString<128> Path;
302302
llvm::sys::path::append(Path, BuiltinIncludeDir->getName(), Header.FileName);
303-
auto File = SourceMgr.getFileManager().getOptionalFileRef(Path);
303+
auto File = SourceMgr.getFileManager().getFile(Path);
304304
if (!File)
305305
return false;
306306

@@ -1012,7 +1012,7 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
10121012
// Look for an umbrella header.
10131013
SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
10141014
llvm::sys::path::append(UmbrellaName, "Headers", ModuleName + ".h");
1015-
auto UmbrellaHeader = FileMgr.getOptionalFileRef(UmbrellaName);
1015+
auto UmbrellaHeader = FileMgr.getFile(UmbrellaName);
10161016

10171017
// FIXME: If there's no umbrella header, we could probably scan the
10181018
// 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,
11211121
return Result;
11221122
}
11231123

1124-
void ModuleMap::setUmbrellaHeader(Module *Mod, FileEntryRef UmbrellaHeader,
1124+
void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
11251125
Twine NameAsWritten) {
11261126
Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
1127-
Mod->Umbrella = &UmbrellaHeader.getMapEntry();
1127+
Mod->Umbrella = UmbrellaHeader;
11281128
Mod->UmbrellaAsWritten = NameAsWritten.str();
1129-
UmbrellaDirs[UmbrellaHeader.getDir()] = Mod;
1129+
UmbrellaDirs[UmbrellaHeader->getDir()] = Mod;
11301130

11311131
// Notify callbacks that we just added a new header.
11321132
for (const auto &Cb : Callbacks)
11331133
Cb->moduleMapAddUmbrellaHeader(&SourceMgr.getFileManager(), UmbrellaHeader);
11341134
}
11351135

1136-
void ModuleMap::setUmbrellaDir(Module *Mod, DirectoryEntryRef UmbrellaDir,
1136+
void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
11371137
Twine NameAsWritten) {
1138-
Mod->Umbrella = &UmbrellaDir.getMapEntry();
1138+
Mod->Umbrella = UmbrellaDir;
11391139
Mod->UmbrellaAsWritten = NameAsWritten.str();
11401140
UmbrellaDirs[UmbrellaDir] = Mod;
11411141
}
@@ -2416,15 +2416,15 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
24162416
}
24172417

24182418
// Look for this file.
2419-
Optional<DirectoryEntryRef> Dir;
2419+
const DirectoryEntry *Dir = nullptr;
24202420
if (llvm::sys::path::is_absolute(DirName)) {
2421-
if (auto D = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName))
2421+
if (auto D = SourceMgr.getFileManager().getDirectory(DirName))
24222422
Dir = *D;
24232423
} else {
24242424
SmallString<128> PathName;
24252425
PathName = Directory->getName();
24262426
llvm::sys::path::append(PathName, DirName);
2427-
if (auto D = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName))
2427+
if (auto D = SourceMgr.getFileManager().getDirectory(PathName))
24282428
Dir = *D;
24292429
}
24302430

@@ -2445,7 +2445,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
24452445
SourceMgr.getFileManager().getVirtualFileSystem();
24462446
for (llvm::vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E;
24472447
I != E && !EC; I.increment(EC)) {
2448-
if (auto FE = SourceMgr.getFileManager().getOptionalFileRef(I->path())) {
2448+
if (auto FE = SourceMgr.getFileManager().getFile(I->path())) {
24492449
Module::Header Header = {std::string(I->path()), *FE};
24502450
Headers.push_back(std::move(Header));
24512451
}
@@ -2459,15 +2459,15 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
24592459
return;
24602460
}
24612461

2462-
if (Module *OwningModule = Map.UmbrellaDirs[*Dir]) {
2462+
if (Module *OwningModule = Map.UmbrellaDirs[Dir]) {
24632463
Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
24642464
<< OwningModule->getFullModuleName();
24652465
HadError = true;
24662466
return;
24672467
}
24682468

24692469
// Record this umbrella directory.
2470-
Map.setUmbrellaDir(ActiveModule, *Dir, DirName);
2470+
Map.setUmbrellaDir(ActiveModule, Dir, DirName);
24712471
}
24722472

24732473
/// Parse a module export declaration.

clang/lib/Serialization/ASTReader.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
19241924
// FIXME: This is not always the right filename-as-written, but we're not
19251925
// going to use this information to rebuild the module, so it doesn't make
19261926
// a lot of difference.
1927-
Module::Header H = {std::string(key.Filename),
1928-
*FileMgr.getOptionalFileRef(Filename)};
1927+
Module::Header H = {std::string(key.Filename), *FileMgr.getFile(Filename)};
19291928
ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
19301929
HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader);
19311930
}
@@ -5614,7 +5613,7 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
56145613
case SUBMODULE_UMBRELLA_HEADER: {
56155614
std::string Filename = std::string(Blob);
56165615
ResolveImportedPath(F, Filename);
5617-
if (auto Umbrella = PP.getFileManager().getOptionalFileRef(Filename)) {
5616+
if (auto Umbrella = PP.getFileManager().getFile(Filename)) {
56185617
if (!CurrentModule->getUmbrellaHeader())
56195618
ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob);
56205619
else if (CurrentModule->getUmbrellaHeader().Entry != *Umbrella) {
@@ -5647,8 +5646,7 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
56475646
case SUBMODULE_UMBRELLA_DIR: {
56485647
std::string Dirname = std::string(Blob);
56495648
ResolveImportedPath(F, Dirname);
5650-
if (auto Umbrella =
5651-
PP.getFileManager().getOptionalDirectoryRef(Dirname)) {
5649+
if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
56525650
if (!CurrentModule->getUmbrellaDir())
56535651
ModMap.setUmbrellaDir(CurrentModule, *Umbrella, Blob);
56545652
else if (CurrentModule->getUmbrellaDir().Entry != *Umbrella) {

0 commit comments

Comments
 (0)