Skip to content

Commit 7799ef7

Browse files
committed
Revert "Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef"
This reverts commit a40db55. and follow-up d636b88 Somewhat speculative, likely broke check-clang on Windows: https://reviews.llvm.org/D92975#2453482
1 parent c9ede6f commit 7799ef7

File tree

7 files changed

+53
-49
lines changed

7 files changed

+53
-49
lines changed

clang-tools-extra/modularize/ModularizeUtilities.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,22 @@ std::error_code ModularizeUtilities::loadProblemHeaderList(
258258
std::error_code ModularizeUtilities::loadModuleMap(
259259
llvm::StringRef InputPath) {
260260
// Get file entry for module.modulemap file.
261-
auto ExpectedModuleMapEntry =
262-
SourceMgr->getFileManager().getFileRef(InputPath);
261+
auto ModuleMapEntryOrErr =
262+
SourceMgr->getFileManager().getFile(InputPath);
263263

264264
// return error if not found.
265-
if (!ExpectedModuleMapEntry) {
265+
if (!ModuleMapEntryOrErr) {
266266
llvm::errs() << "error: File \"" << InputPath << "\" not found.\n";
267-
return errorToErrorCode(ExpectedModuleMapEntry.takeError());
267+
return ModuleMapEntryOrErr.getError();
268268
}
269-
FileEntryRef ModuleMapEntry = *ExpectedModuleMapEntry;
269+
const FileEntry *ModuleMapEntry = *ModuleMapEntryOrErr;
270270

271271
// Because the module map parser uses a ForwardingDiagnosticConsumer,
272272
// which doesn't forward the BeginSourceFile call, we do it explicitly here.
273273
DC.BeginSourceFile(*LangOpts, nullptr);
274274

275275
// Figure out the home directory for the module map file.
276-
const DirectoryEntry *Dir = ModuleMapEntry.getDir();
276+
const DirectoryEntry *Dir = ModuleMapEntry->getDir();
277277
StringRef DirName(Dir->getName());
278278
if (llvm::sys::path::filename(DirName) == "Modules") {
279279
DirName = llvm::sys::path::parent_path(DirName);

clang/include/clang/Lex/HeaderSearch.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class HeaderSearch {
239239

240240
/// Set of module map files we've already loaded, and a flag indicating
241241
/// whether they were valid or not.
242-
llvm::DenseMap<FileEntryRef, bool> LoadedModuleMaps;
242+
llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
243243

244244
/// Uniqued set of framework names, which is used to track which
245245
/// headers were included as framework headers.
@@ -560,8 +560,8 @@ class HeaderSearch {
560560

561561
/// Try to find a module map file in the given directory, returning
562562
/// \c nullptr if none is found.
563-
Optional<FileEntryRef> lookupModuleMapFile(const DirectoryEntry *Dir,
564-
bool IsFramework);
563+
const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir,
564+
bool IsFramework);
565565

566566
/// Determine whether there is a module map that may map the header
567567
/// with the given file name to a (sub)module.
@@ -603,8 +603,8 @@ class HeaderSearch {
603603
/// used to resolve paths within the module (this is required when
604604
/// building the module from preprocessed source).
605605
/// \returns true if an error occurred, false otherwise.
606-
bool loadModuleMapFile(FileEntryRef File, bool IsSystem, FileID ID = FileID(),
607-
unsigned *Offset = nullptr,
606+
bool loadModuleMapFile(const FileEntry *File, bool IsSystem,
607+
FileID ID = FileID(), unsigned *Offset = nullptr,
608608
StringRef OriginalModuleMapFile = StringRef());
609609

610610
/// Collect the set of all known, top-level modules.
@@ -794,7 +794,8 @@ class HeaderSearch {
794794
LMM_InvalidModuleMap
795795
};
796796

797-
LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
797+
LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File,
798+
bool IsSystem,
798799
const DirectoryEntry *Dir,
799800
FileID ID = FileID(),
800801
unsigned *Offset = nullptr);

clang/include/clang/Lex/ModuleMap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,9 @@ class ModuleMap {
684684
/// that caused us to load this module map file, if any.
685685
///
686686
/// \returns true if an error occurred, false otherwise.
687-
bool parseModuleMapFile(FileEntryRef File, bool IsSystem,
688-
const DirectoryEntry *HomeDir, FileID ID = FileID(),
689-
unsigned *Offset = nullptr,
687+
bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
688+
const DirectoryEntry *HomeDir,
689+
FileID ID = FileID(), unsigned *Offset = nullptr,
690690
SourceLocation ExternModuleLoc = SourceLocation());
691691

692692
/// Dump the contents of the module map, for debugging purposes.

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
432432

433433
// Map the current input to a file.
434434
FileID ModuleMapID = SrcMgr.getMainFileID();
435-
Optional<FileEntryRef> ModuleMap = SrcMgr.getFileEntryRefForID(ModuleMapID);
435+
const FileEntry *ModuleMap = SrcMgr.getFileEntryForID(ModuleMapID);
436436

437437
// If the module map is preprocessed, handle the initial line marker;
438438
// line directives are not part of the module map syntax in general.
@@ -445,7 +445,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
445445
}
446446

447447
// Load the module map file.
448-
if (HS.loadModuleMapFile(*ModuleMap, IsSystem, ModuleMapID, &Offset,
448+
if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset,
449449
PresumedModuleMapFile))
450450
return true;
451451

@@ -807,7 +807,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
807807

808808
// If we were asked to load any module map files, do so now.
809809
for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
810-
if (auto File = CI.getFileManager().getOptionalFileRef(Filename))
810+
if (auto File = CI.getFileManager().getFile(Filename))
811811
CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile(
812812
*File, /*IsSystem*/false);
813813
else

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,20 +1499,22 @@ bool HeaderSearch::findUsableModuleForFrameworkHeader(
14991499
return true;
15001500
}
15011501

1502-
static Optional<FileEntryRef> getPrivateModuleMap(FileEntryRef File,
1503-
FileManager &FileMgr) {
1504-
StringRef Filename = llvm::sys::path::filename(File.getName());
1505-
SmallString<128> PrivateFilename(File.getDir().getName());
1502+
static const FileEntry *getPrivateModuleMap(const FileEntry *File,
1503+
FileManager &FileMgr) {
1504+
StringRef Filename = llvm::sys::path::filename(File->getName());
1505+
SmallString<128> PrivateFilename(File->getDir()->getName());
15061506
if (Filename == "module.map")
15071507
llvm::sys::path::append(PrivateFilename, "module_private.map");
15081508
else if (Filename == "module.modulemap")
15091509
llvm::sys::path::append(PrivateFilename, "module.private.modulemap");
15101510
else
1511-
return None;
1512-
return FileMgr.getOptionalFileRef(PrivateFilename);
1511+
return nullptr;
1512+
if (auto File = FileMgr.getFile(PrivateFilename))
1513+
return *File;
1514+
return nullptr;
15131515
}
15141516

1515-
bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem,
1517+
bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,
15161518
FileID ID, unsigned *Offset,
15171519
StringRef OriginalModuleMapFile) {
15181520
// Find the directory for the module. For frameworks, that may require going
@@ -1534,7 +1536,7 @@ bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem,
15341536
Dir = FakeFile->getDir();
15351537
}
15361538
} else {
1537-
Dir = File.getDir();
1539+
Dir = File->getDir();
15381540
}
15391541

15401542
StringRef DirName(Dir->getName());
@@ -1561,9 +1563,11 @@ bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem,
15611563
}
15621564

15631565
HeaderSearch::LoadModuleMapResult
1564-
HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
1566+
HeaderSearch::loadModuleMapFileImpl(const FileEntry *File, bool IsSystem,
15651567
const DirectoryEntry *Dir, FileID ID,
15661568
unsigned *Offset) {
1569+
assert(File && "expected FileEntry");
1570+
15671571
// Check whether we've already loaded this module map, and mark it as being
15681572
// loaded in case we recursively try to load it from itself.
15691573
auto AddResult = LoadedModuleMaps.insert(std::make_pair(File, true));
@@ -1576,8 +1580,8 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
15761580
}
15771581

15781582
// Try to load a corresponding private module map.
1579-
if (Optional<FileEntryRef> PMMFile = getPrivateModuleMap(File, FileMgr)) {
1580-
if (ModMap.parseModuleMapFile(*PMMFile, IsSystem, Dir)) {
1583+
if (const FileEntry *PMMFile = getPrivateModuleMap(File, FileMgr)) {
1584+
if (ModMap.parseModuleMapFile(PMMFile, IsSystem, Dir)) {
15811585
LoadedModuleMaps[File] = false;
15821586
return LMM_InvalidModuleMap;
15831587
}
@@ -1587,35 +1591,35 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
15871591
return LMM_NewlyLoaded;
15881592
}
15891593

1590-
Optional<FileEntryRef>
1594+
const FileEntry *
15911595
HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
15921596
if (!HSOpts->ImplicitModuleMaps)
1593-
return None;
1597+
return nullptr;
15941598
// For frameworks, the preferred spelling is Modules/module.modulemap, but
15951599
// module.map at the framework root is also accepted.
15961600
SmallString<128> ModuleMapFileName(Dir->getName());
15971601
if (IsFramework)
15981602
llvm::sys::path::append(ModuleMapFileName, "Modules");
15991603
llvm::sys::path::append(ModuleMapFileName, "module.modulemap");
1600-
if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
1601-
return F;
1604+
if (auto F = FileMgr.getFile(ModuleMapFileName))
1605+
return *F;
16021606

16031607
// Continue to allow module.map
16041608
ModuleMapFileName = Dir->getName();
16051609
llvm::sys::path::append(ModuleMapFileName, "module.map");
1606-
if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
1607-
return F;
1610+
if (auto F = FileMgr.getFile(ModuleMapFileName))
1611+
return *F;
16081612

16091613
// For frameworks, allow to have a private module map with a preferred
16101614
// spelling when a public module map is absent.
16111615
if (IsFramework) {
16121616
ModuleMapFileName = Dir->getName();
16131617
llvm::sys::path::append(ModuleMapFileName, "Modules",
16141618
"module.private.modulemap");
1615-
if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
1616-
return F;
1619+
if (auto F = FileMgr.getFile(ModuleMapFileName))
1620+
return *F;
16171621
}
1618-
return None;
1622+
return nullptr;
16191623
}
16201624

16211625
Module *HeaderSearch::loadFrameworkModule(StringRef Name,
@@ -1659,10 +1663,9 @@ HeaderSearch::loadModuleMapFile(const DirectoryEntry *Dir, bool IsSystem,
16591663
if (KnownDir != DirectoryHasModuleMap.end())
16601664
return KnownDir->second ? LMM_AlreadyLoaded : LMM_InvalidModuleMap;
16611665

1662-
if (Optional<FileEntryRef> ModuleMapFile =
1663-
lookupModuleMapFile(Dir, IsFramework)) {
1666+
if (const FileEntry *ModuleMapFile = lookupModuleMapFile(Dir, IsFramework)) {
16641667
LoadModuleMapResult Result =
1665-
loadModuleMapFileImpl(*ModuleMapFile, IsSystem, Dir);
1668+
loadModuleMapFileImpl(ModuleMapFile, IsSystem, Dir);
16661669
// Add Dir explicitly in case ModuleMapFile is in a subdirectory.
16671670
// E.g. Foo.framework/Modules/module.modulemap
16681671
// ^Dir ^ModuleMapFile

clang/lib/Lex/ModuleMap.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,9 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
973973
// We haven't looked here before. Load a module map, if there is
974974
// one.
975975
bool IsFrameworkDir = Parent.endswith(".framework");
976-
if (Optional<FileEntryRef> ModMapFile =
977-
HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
978-
parseModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir);
976+
if (const FileEntry *ModMapFile =
977+
HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
978+
parseModuleMapFile(ModMapFile, Attrs.IsSystem, *ParentDir);
979979
inferred = InferredDirectories.find(*ParentDir);
980980
}
981981

@@ -2163,12 +2163,12 @@ void ModuleMapParser::parseExternModuleDecl() {
21632163
llvm::sys::path::append(ModuleMapFileName, FileName);
21642164
FileNameRef = ModuleMapFileName;
21652165
}
2166-
if (auto File = SourceMgr.getFileManager().getOptionalFileRef(FileNameRef))
2166+
if (auto File = SourceMgr.getFileManager().getFile(FileNameRef))
21672167
Map.parseModuleMapFile(
21682168
*File, /*IsSystem=*/false,
21692169
Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd
21702170
? Directory
2171-
: File->getDir(),
2171+
: (*File)->getDir(),
21722172
FileID(), nullptr, ExternLoc);
21732173
}
21742174

@@ -2984,7 +2984,7 @@ bool ModuleMapParser::parseModuleMapFile() {
29842984
} while (true);
29852985
}
29862986

2987-
bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
2987+
bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
29882988
const DirectoryEntry *Dir, FileID ID,
29892989
unsigned *Offset,
29902990
SourceLocation ExternModuleLoc) {

lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ bool ClangModulesDeclVendorImpl::AddModule(const SourceModule &module,
278278
HS.getFileMgr().getDirectory(module.search_path.GetStringRef());
279279
if (!dir)
280280
return error();
281-
auto file = HS.lookupModuleMapFile(*dir, is_framework);
281+
auto *file = HS.lookupModuleMapFile(*dir, is_framework);
282282
if (!file)
283283
return error();
284-
if (!HS.loadModuleMapFile(*file, is_system))
284+
if (!HS.loadModuleMapFile(file, is_system))
285285
return error();
286286
}
287287
}

0 commit comments

Comments
 (0)