Skip to content

Commit 0df6ff4

Browse files
committed
[NFC] Generalize target-specific module loading…
…from 1-2 target-specific names to 0-N target-specific names.
1 parent 70ba0aa commit 0df6ff4

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,17 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
167167
ModuleFilenamePair fileNames(moduleName);
168168

169169
StringRef archName = Ctx.LangOpts.Target.getArchName();
170-
ModuleFilenamePair archFileNames(archName);
170+
171+
SmallVector<ModuleFilenamePair, 4> targetFileNamePairs;
172+
targetFileNamePairs.push_back(archName);
171173

172174
// FIXME: We used to use "major architecture" names for these files---the
173175
// names checked in "#if arch(...)". Fall back to that name in the one case
174176
// where it's different from what Swift 4.2 supported: 32-bit ARM platforms.
175177
// We should be able to drop this once there's an Xcode that supports the
176178
// new names.
177-
StringRef alternateArchName;
178179
if (Ctx.LangOpts.Target.getArch() == llvm::Triple::ArchType::arm)
179-
alternateArchName = "arm";
180-
ModuleFilenamePair alternateArchFileNames(alternateArchName);
180+
targetFileNamePairs.push_back(StringRef("arm"));
181181

182182
auto &fs = *Ctx.SourceMgr.getFileSystem();
183183
isFramework = false;
@@ -188,30 +188,25 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
188188
/// was diagnosed, or None if neither one happened and the search should
189189
/// continue.
190190
auto findTargetSpecificModuleFiles = [&]() -> Optional<bool> {
191-
auto result = findModuleFilesInDirectory(moduleID, currPath,
192-
archFileNames.module,
193-
archFileNames.moduleDoc,
194-
moduleBuffer, moduleDocBuffer);
195-
196-
if (result == std::errc::no_such_file_or_directory &&
197-
!alternateArchName.empty()) {
198-
result = findModuleFilesInDirectory(moduleID, currPath,
199-
alternateArchFileNames.module,
200-
alternateArchFileNames.moduleDoc,
201-
moduleBuffer, moduleDocBuffer);
202-
}
203-
204-
if (result == std::errc::no_such_file_or_directory) {
205-
if (maybeDiagnoseArchitectureMismatch(moduleID.second, moduleName,
206-
archName, currPath)) {
207-
return false;
191+
for (const auto &targetFileNames : targetFileNamePairs) {
192+
auto result = findModuleFilesInDirectory(moduleID, currPath,
193+
targetFileNames.module, targetFileNames.moduleDoc,
194+
moduleBuffer, moduleDocBuffer);
195+
if (!result) {
196+
return true;
197+
} else if (result != std::errc::no_such_file_or_directory) {
198+
return None;
208199
}
209200
}
210201

211-
if (!result)
212-
return true;
213-
else
202+
// We can only get here if all targetFileNamePairs failed with
203+
// 'std::errc::no_such_file_or_directory'.
204+
if (maybeDiagnoseArchitectureMismatch(moduleID.second,
205+
moduleName, archName, currPath)) {
206+
return false;
207+
} else {
214208
return None;
209+
}
215210
};
216211

217212
for (auto path : Ctx.SearchPathOpts.ImportSearchPaths) {

0 commit comments

Comments
 (0)