Skip to content

Commit 91e8c92

Browse files
committed
[Serialization] Make ModuleSearchPath a class with explicit getters
Improves debugging because you can set breakpoints on the getters and constructor.
1 parent bac3b67 commit 91e8c92

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

include/swift/AST/SearchPathOptions.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum class ModuleSearchPathKind {
3636

3737
/// A single module search path that can come from different sources, e.g.
3838
/// framework search paths, import search path etc.
39-
struct ModuleSearchPath {
39+
class ModuleSearchPath {
4040
/// The actual path of the module search path. References a search path string
4141
/// stored inside \c SearchPathOptions, which must outlive this reference.
4242
StringRef Path;
@@ -52,6 +52,18 @@ struct ModuleSearchPath {
5252
/// different file names in \c searchPathsContainingFile.
5353
unsigned Index;
5454

55+
public:
56+
ModuleSearchPath(StringRef Path, ModuleSearchPathKind Kind, bool IsSystem,
57+
unsigned Index)
58+
: Path(Path), Kind(Kind), IsSystem(IsSystem), Index(Index) {}
59+
60+
StringRef getPath() const { return Path; }
61+
ModuleSearchPathKind getKind() const { return Kind; }
62+
63+
bool isSystem() const { return IsSystem; }
64+
65+
unsigned getIndex() const { return Index; }
66+
5567
bool operator<(const ModuleSearchPath &Other) const {
5668
if (this->Kind == Other.Kind) {
5769
return this->Index < Other.Index;

lib/AST/SearchPathOptions.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@ void ModuleSearchPathLookup::addFilesInPathToLookupTable(
1919
llvm::vfs::FileSystem *FS, StringRef SearchPath, ModuleSearchPathKind Kind,
2020
bool IsSystem, unsigned SearchPathIndex) {
2121
std::error_code Error;
22-
assert(llvm::all_of(LookupTable, [&](const auto &LookupTableEntry) {
23-
return llvm::none_of(LookupTableEntry.second, [&](const ModuleSearchPath &ExistingSearchPath) -> bool {
24-
return ExistingSearchPath.Kind == Kind && ExistingSearchPath.Index == SearchPathIndex;
25-
});
26-
}) && "Search path with this kind and index already exists");
22+
assert(llvm::all_of(
23+
LookupTable,
24+
[&](const auto &LookupTableEntry) {
25+
return llvm::none_of(
26+
LookupTableEntry.second,
27+
[&](const ModuleSearchPath &ExistingSearchPath) -> bool {
28+
return ExistingSearchPath.getKind() == Kind &&
29+
ExistingSearchPath.getIndex() == SearchPathIndex;
30+
});
31+
}) &&
32+
"Search path with this kind and index already exists");
2733
for (auto Dir = FS->dir_begin(SearchPath, Error);
2834
!Error && Dir != llvm::vfs::directory_iterator(); Dir.increment(Error)) {
2935
StringRef Filename = llvm::sys::path::filename(Dir->path());
30-
LookupTable[Filename].push_back(
31-
{SearchPath, Kind, IsSystem, SearchPathIndex});
36+
LookupTable[Filename].emplace_back(SearchPath, Kind, IsSystem,
37+
SearchPathIndex);
3238
}
3339
}
3440

@@ -92,7 +98,8 @@ ModuleSearchPathLookup::searchPathsContainingFile(
9298

9399
for (auto &Filename : Filenames) {
94100
for (auto &Entry : LookupTable[Filename]) {
95-
if (ResultIds.insert(std::make_pair(Entry.Kind, Entry.Index)).second) {
101+
if (ResultIds.insert(std::make_pair(Entry.getKind(), Entry.getIndex()))
102+
.second) {
96103
Result.push_back(&Entry);
97104
}
98105
}

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,10 @@ SerializedModuleLoaderBase::findModule(ImportPath::Element moduleID,
608608
InterestingFilenames, Ctx.SourceMgr.getFileSystem().get(),
609609
Ctx.LangOpts.Target.isOSDarwin());
610610
for (const auto &searchPath : searchPaths) {
611-
currPath = searchPath->Path;
612-
isSystemModule = searchPath->IsSystem;
611+
currPath = searchPath->getPath();
612+
isSystemModule = searchPath->isSystem();
613613

614-
switch (searchPath->Kind) {
614+
switch (searchPath->getKind()) {
615615
case ModuleSearchPathKind::Import:
616616
case ModuleSearchPathKind::RuntimeLibrary: {
617617
isFramework = false;
@@ -621,7 +621,7 @@ SerializedModuleLoaderBase::findModule(ImportPath::Element moduleID,
621621
// This was not always true on non-Apple platforms, and in order to
622622
// ease the transition, check both layouts.
623623
bool checkTargetSpecificModule = true;
624-
if (searchPath->Kind != ModuleSearchPathKind::RuntimeLibrary ||
624+
if (searchPath->getKind() != ModuleSearchPathKind::RuntimeLibrary ||
625625
!Ctx.LangOpts.Target.isOSDarwin()) {
626626
auto modulePath = currPath;
627627
llvm::sys::path::append(modulePath, genericModuleFileName);

0 commit comments

Comments
 (0)