Skip to content

Commit 35e6915

Browse files
[Serialization] Avoid file buffer lookup if not needed
When serializing module dependencies, avoid look up the file if it is not needed for serailization. This also adds a proper diagnostics if the lookup failed so user can understand which file is missing.
1 parent 07a35e9 commit 35e6915

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
145145
continue;
146146

147147
auto Status = fs.status(DepName);
148-
if (!Status)
148+
if (!Status) {
149+
Instance.getDiags().diagnose(SourceLoc(), diag::cannot_open_file, DepName,
150+
Status.getError().message());
149151
return true;
152+
}
150153

151154
/// Lazily load the dependency buffer if we need it. If we're not
152155
/// dealing with a hash-based dependencies, and if the dependency is
@@ -155,11 +158,14 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
155158
auto getDepBuf = [&]() -> llvm::MemoryBuffer * {
156159
if (DepBuf)
157160
return DepBuf.get();
158-
if (auto Buf = fs.getBufferForFile(DepName, /*FileSize=*/-1,
159-
/*RequiresNullTerminator=*/false)) {
161+
auto Buf = fs.getBufferForFile(DepName, /*FileSize=*/-1,
162+
/*RequiresNullTerminator=*/false);
163+
if (Buf) {
160164
DepBuf = std::move(Buf.get());
161165
return DepBuf.get();
162166
}
167+
Instance.getDiags().diagnose(SourceLoc(), diag::cannot_open_file, DepName,
168+
Buf.getError().message());
163169
return nullptr;
164170
};
165171

@@ -287,11 +293,11 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
287293
SerializationOpts.ABIDescriptorPath = ABIDescriptorPath.str();
288294
SmallVector<FileDependency, 16> Deps;
289295
bool SerializeHashes = FEOpts.SerializeModuleInterfaceDependencyHashes;
290-
if (collectDepsForSerialization(Deps, InterfacePath, SerializeHashes)) {
291-
return std::make_error_code(std::errc::not_supported);
292-
}
293-
if (ShouldSerializeDeps)
296+
if (ShouldSerializeDeps) {
297+
if (collectDepsForSerialization(Deps, InterfacePath, SerializeHashes))
298+
return std::make_error_code(std::errc::not_supported);
294299
SerializationOpts.Dependencies = Deps;
300+
}
295301
SerializationOpts.IsOSSA = SILOpts.EnableOSSAModules;
296302

297303
SILMod->setSerializeSILAction([&]() {

0 commit comments

Comments
 (0)