Skip to content

Commit e92e00b

Browse files
authored
[Serialization] Ignore filesystem errors when loading modules. (#4547)
Instead, just go on to the next search path. This prevents a present-but-unreadable directory from leading to a module load failure, which happens when one user builds a module and another user loads it (even if those search paths aren't even being used). There might still be some other errors that would be useful to treat as "module found but invalid" rather than "module not found", but experience has shown that it's the wrong default. There is a Radar for this but I can't find it.
1 parent 4904101 commit e92e00b

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ openModuleFiles(StringRef DirName, StringRef ModuleFilename,
6767
return std::error_code();
6868
}
6969

70-
static std::error_code
70+
static bool
7171
findModule(ASTContext &ctx, AccessPathElem moduleID,
7272
std::unique_ptr<llvm::MemoryBuffer> &moduleBuffer,
7373
std::unique_ptr<llvm::MemoryBuffer> &moduleDocBuffer,
@@ -110,8 +110,8 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
110110
moduleBuffer, moduleDocBuffer,
111111
scratch);
112112
}
113-
if (!err || err != std::errc::no_such_file_or_directory)
114-
return err;
113+
if (!err)
114+
return true;
115115
}
116116

117117
{
@@ -127,20 +127,20 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
127127
archFile.str(), archDocFile.str(),
128128
moduleBuffer, moduleDocBuffer,
129129
scratch);
130-
if (!err || err != std::errc::no_such_file_or_directory)
131-
return err;
130+
if (!err)
131+
return true;
132132
}
133133
}
134134

135135
// If we're not allowed to look in the runtime library import path, stop.
136136
if (ctx.SearchPathOpts.SkipRuntimeLibraryImportPath)
137-
return std::make_error_code(std::errc::no_such_file_or_directory);
137+
return false;
138138

139139
// Search the runtime import path.
140140
isFramework = false;
141-
return openModuleFiles(ctx.SearchPathOpts.RuntimeLibraryImportPath,
142-
moduleFilename.str(), moduleDocFilename.str(),
143-
moduleBuffer, moduleDocBuffer, scratch);
141+
return !openModuleFiles(ctx.SearchPathOpts.RuntimeLibraryImportPath,
142+
moduleFilename.str(), moduleDocFilename.str(),
143+
moduleBuffer, moduleDocBuffer, scratch);
144144
}
145145

146146
FileUnit *SerializedModuleLoader::loadAST(
@@ -378,14 +378,8 @@ Module *SerializedModuleLoader::loadModule(SourceLoc importLoc,
378378

379379
// Otherwise look on disk.
380380
if (!moduleInputBuffer) {
381-
if (std::error_code err = findModule(Ctx, moduleID, moduleInputBuffer,
382-
moduleDocInputBuffer,
383-
isFramework)) {
384-
if (err != std::errc::no_such_file_or_directory) {
385-
Ctx.Diags.diagnose(moduleID.second, diag::sema_opening_import,
386-
moduleID.first, err.message());
387-
}
388-
381+
if (!findModule(Ctx, moduleID, moduleInputBuffer, moduleDocInputBuffer,
382+
isFramework)) {
389383
return nullptr;
390384
}
391385

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: if [[ -d %t ]]; then chmod -R u+rwx %t && rm -rf %t; fi
2+
// RUN: mkdir -p %t/good
3+
// RUN: mkdir %t/bad
4+
// RUN: chmod a-rx %t/bad
5+
// RUN: %target-swift-frontend -emit-module -o %t/good %S/../Inputs/empty.swift
6+
// RUN: not %target-swift-frontend %s -parse -I %t/bad -I %t/good -show-diagnostics-after-fatal 2>&1 | %FileCheck %s
7+
// RUN: not %target-swift-frontend %s -parse -I %t/good -I %t/bad -show-diagnostics-after-fatal 2>&1 | %FileCheck %s
8+
9+
import empty // CHECK-NOT: empty
10+
import ThisOneReallyDoesNotExist // CHECK: [[@LINE]]:{{[0-9]+}}: error: no such module 'ThisOneReallyDoesNotExist'

0 commit comments

Comments
 (0)