Skip to content

Commit 1bb463b

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents d4f3519 + e4c1de6 commit 1bb463b

File tree

6 files changed

+197
-160
lines changed

6 files changed

+197
-160
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
148148
ArrayRef<std::string> PreferInterfaceForModules;
149149

150150
std::error_code findModuleFilesInDirectory(
151-
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
152-
StringRef ModuleDocFilename,
153-
StringRef ModuleSourceInfoFilename,
151+
AccessPathElem ModuleID,
152+
const SerializedModuleBaseName &BaseName,
154153
SmallVectorImpl<char> *ModuleInterfacePath,
155154
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
156155
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,

include/swift/Serialization/SerializedModuleLoader.h

+49-33
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
namespace swift {
2222
class ModuleFile;
23+
namespace file_types {
24+
enum ID : uint8_t;
25+
}
2326

2427
/// Spceifies how to load modules when both a module interface and serialized
2528
/// AST are present, or whether to disallow one format or the other altogether.
@@ -30,6 +33,24 @@ enum class ModuleLoadingMode {
3033
OnlySerialized
3134
};
3235

36+
/// Helper type used to pass and compute the sets of related filenames used by
37+
/// \c SerializedModuleLoader subclasses.
38+
struct SerializedModuleBaseName {
39+
/// The base filename, wtihout any extension.
40+
SmallString<256> baseName;
41+
42+
/// Creates a \c SerializedModuleBaseName.
43+
SerializedModuleBaseName(StringRef baseName) : baseName(baseName) { }
44+
45+
/// Creates a \c SerializedModuleBaseName by contextualizing an existing one
46+
/// with a \c parentDir.
47+
SerializedModuleBaseName(StringRef parentDir,
48+
const SerializedModuleBaseName &name);
49+
50+
/// Gets the filename with a particular extension appended to it.
51+
std::string getName(file_types::ID fileTy) const;
52+
};
53+
3354
/// Common functionality shared between \c SerializedModuleLoader,
3455
/// \c ModuleInterfaceLoader and \c MemoryBufferSerializedModuleLoader.
3556
class SerializedModuleLoaderBase : public ModuleLoader {
@@ -71,43 +92,40 @@ class SerializedModuleLoaderBase : public ModuleLoader {
7192
/// modules and will defer to the remaining module loaders to look up this
7293
/// module.
7394
virtual std::error_code findModuleFilesInDirectory(
74-
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
75-
StringRef ModuleDocFilename,
76-
StringRef ModuleSourceInfoFilename,
95+
AccessPathElem ModuleID,
96+
const SerializedModuleBaseName &BaseName,
7797
SmallVectorImpl<char> *ModuleInterfacePath,
7898
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
7999
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
80100
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer) = 0;
81101

82102
std::error_code
83-
openModuleFiles(AccessPathElem ModuleID,
84-
StringRef ModulePath, StringRef ModuleDocPath,
85-
StringRef ModuleSourceInfoName,
86-
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
87-
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
88-
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer);
103+
openModuleFile(
104+
AccessPathElem ModuleID,
105+
const SerializedModuleBaseName &BaseName,
106+
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer);
89107

90108
std::error_code
91-
openModuleDocFile(AccessPathElem ModuleID,
92-
StringRef ModuleDocPath,
93-
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer);
109+
openModuleDocFileIfPresent(
110+
AccessPathElem ModuleID,
111+
const SerializedModuleBaseName &BaseName,
112+
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer);
94113

95-
void
114+
std::error_code
96115
openModuleSourceInfoFileIfPresent(
97116
AccessPathElem ModuleID,
98-
StringRef ModulePath,
99-
StringRef ModuleSourceInfoFileName,
117+
const SerializedModuleBaseName &BaseName,
100118
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer);
101119

102120
/// If the module loader subclass knows that all options have been tried for
103121
/// loading an architecture-specific file out of a swiftmodule bundle, try
104122
/// to list the architectures that \e are present.
105123
///
106124
/// \returns true if an error diagnostic was emitted
107-
virtual bool maybeDiagnoseTargetMismatch(SourceLoc sourceLocation,
108-
StringRef moduleName,
109-
StringRef archName,
110-
StringRef directoryPath) {
125+
virtual bool maybeDiagnoseTargetMismatch(
126+
SourceLoc sourceLocation,
127+
StringRef moduleName,
128+
const SerializedModuleBaseName &BaseName) {
111129
return false;
112130
}
113131

@@ -178,18 +196,17 @@ class SerializedModuleLoader : public SerializedModuleLoaderBase {
178196
{}
179197

180198
std::error_code findModuleFilesInDirectory(
181-
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
182-
StringRef ModuleDocFilename,
183-
StringRef ModuleSourceInfoFilename,
199+
AccessPathElem ModuleID,
200+
const SerializedModuleBaseName &BaseName,
184201
SmallVectorImpl<char> *ModuleInterfacePath,
185202
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
186203
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
187204
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer) override;
188205

189-
bool maybeDiagnoseTargetMismatch(SourceLoc sourceLocation,
190-
StringRef moduleName,
191-
StringRef archName,
192-
StringRef directoryPath) override;
206+
bool maybeDiagnoseTargetMismatch(
207+
SourceLoc sourceLocation,
208+
StringRef moduleName,
209+
const SerializedModuleBaseName &BaseName) override;
193210

194211
public:
195212
virtual ~SerializedModuleLoader();
@@ -224,18 +241,17 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
224241
IgnoreSwiftSourceInfo) {}
225242

226243
std::error_code findModuleFilesInDirectory(
227-
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
228-
StringRef ModuleDocFilename,
229-
StringRef ModuleSourceInfoFilename,
244+
AccessPathElem ModuleID,
245+
const SerializedModuleBaseName &BaseName,
230246
SmallVectorImpl<char> *ModuleInterfacePath,
231247
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
232248
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
233249
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer) override;
234250

235-
bool maybeDiagnoseTargetMismatch(SourceLoc sourceLocation,
236-
StringRef moduleName,
237-
StringRef archName,
238-
StringRef directoryPath) override;
251+
bool maybeDiagnoseTargetMismatch(
252+
SourceLoc sourceLocation,
253+
StringRef moduleName,
254+
const SerializedModuleBaseName &BaseName) override;
239255

240256
public:
241257
virtual ~MemoryBufferSerializedModuleLoader();

lib/Frontend/ModuleInterfaceLoader.cpp

+14-21
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,8 @@ bool ModuleInterfaceLoader::isCached(StringRef DepPath) {
987987
/// cache or by converting it in a subordinate \c CompilerInstance, caching
988988
/// the results.
989989
std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
990-
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
991-
StringRef ModuleDocFilename,
992-
StringRef ModuleSourceInfoFilename,
990+
AccessPathElem ModuleID,
991+
const SerializedModuleBaseName &BaseName,
993992
SmallVectorImpl<char> *ModuleInterfacePath,
994993
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
995994
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
@@ -999,16 +998,12 @@ std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
999998
// should not have been constructed at all.
1000999
assert(LoadMode != ModuleLoadingMode::OnlySerialized);
10011000

1002-
auto &fs = *Ctx.SourceMgr.getFileSystem();
1003-
llvm::SmallString<256> ModPath, InPath;
1001+
llvm::SmallString<256>
1002+
ModPath{ BaseName.getName(file_types::TY_SwiftModuleFile) },
1003+
InPath{ BaseName.getName(file_types::TY_SwiftModuleInterfaceFile) };
10041004

10051005
// First check to see if the .swiftinterface exists at all. Bail if not.
1006-
ModPath = DirPath;
1007-
path::append(ModPath, ModuleFilename);
1008-
1009-
auto Ext = file_types::getExtension(file_types::TY_SwiftModuleInterfaceFile);
1010-
InPath = ModPath;
1011-
path::replace_extension(InPath, Ext);
1006+
auto &fs = *Ctx.SourceMgr.getFileSystem();
10121007
if (!fs.exists(InPath)) {
10131008
if (fs.exists(ModPath)) {
10141009
LLVM_DEBUG(llvm::dbgs()
@@ -1040,18 +1035,16 @@ std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
10401035
if (ModuleInterfacePath)
10411036
*ModuleInterfacePath = InPath;
10421037
}
1038+
10431039
// Open .swiftsourceinfo file if it's present.
1044-
SerializedModuleLoaderBase::openModuleSourceInfoFileIfPresent(ModuleID,
1045-
ModPath,
1046-
ModuleSourceInfoFilename,
1047-
ModuleSourceInfoBuffer);
1040+
if (auto SourceInfoError = openModuleSourceInfoFileIfPresent(ModuleID,
1041+
BaseName,
1042+
ModuleSourceInfoBuffer))
1043+
return SourceInfoError;
1044+
10481045
// Delegate back to the serialized module loader to load the module doc.
1049-
llvm::SmallString<256> DocPath{DirPath};
1050-
path::append(DocPath, ModuleDocFilename);
1051-
auto DocLoadErr =
1052-
SerializedModuleLoaderBase::openModuleDocFile(ModuleID, DocPath,
1053-
ModuleDocBuffer);
1054-
if (DocLoadErr)
1046+
if (auto DocLoadErr = openModuleDocFileIfPresent(ModuleID, BaseName,
1047+
ModuleDocBuffer))
10551048
return DocLoadErr;
10561049

10571050
return std::error_code();

0 commit comments

Comments
 (0)