Skip to content

Commit 6bf4a0e

Browse files
author
Harlan Haskins
committed
[ModuleInterfaces] Clear dependencies before checking a different module
Sometimes, if one module we tried failed, we would leave the dependencies from the previous check and fail a different module which would have succeeded. This manifested as the prebuilt-module-cache-forwarding test testing the wrong thing, because it retained a mod-time based dependency in the prebuilt cache, which should have been hash based, and used it.
1 parent 1e4ee19 commit 6bf4a0e

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,12 @@ class ParseableInterfaceModuleLoaderImpl {
913913
bool serializedASTBufferIsUpToDate(
914914
StringRef path, const llvm::MemoryBuffer &buf,
915915
SmallVectorImpl<FileDependency> &allDeps) {
916-
LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << modulePath << "\n");
916+
917+
// Clear the existing dependencies, because we're going to re-fill them
918+
// in validateSerializedAST.
919+
allDeps.clear();
920+
921+
LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << path << "\n");
917922
auto validationInfo = serialization::validateSerializedAST(
918923
buf.getBuffer(), /*ExtendedValidationInfo=*/nullptr, &allDeps);
919924

@@ -944,6 +949,13 @@ class ParseableInterfaceModuleLoaderImpl {
944949
StringRef path, const ForwardingModule &fwd,
945950
SmallVectorImpl<FileDependency> &deps,
946951
std::unique_ptr<llvm::MemoryBuffer> &moduleBuffer) {
952+
953+
// Clear the existing dependencies, because we're going to re-fill them
954+
// from the forwarding module.
955+
deps.clear();
956+
957+
LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << path << "\n");
958+
947959
// First, make sure the underlying module path exists and is valid.
948960
auto modBuf = fs.getBufferForFile(fwd.underlyingModulePath);
949961
if (!modBuf || !serializedASTLooksValid(*modBuf.get()))

test/ParseableInterface/ModuleCache/prebuilt-module-cache-forwarding.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212

1313
// Make sure we installed a forwarding module.
1414
// RUN: %{python} %S/Inputs/check-is-forwarding-module.py %t/MCP/Lib-*.swiftmodule
15+
// RUN: cat %t/MCP/Lib-*.swiftmodule
1516

16-
// Make sure it passes:
17-
// RUN: sleep 1
17+
// Now invalidate a dependency of the prebuilt module, by changing the hash of the .swiftinterface.
18+
// RUN: cp %t/Lib.swiftinterface %t/Lib.swiftinterface.moved-aside
19+
// RUN: echo ' ' >> %t/Lib.swiftinterface
1820

19-
// Now invalidate a dependency of the prebuilt module, and make sure the forwarding file is replaced with a real module.
20-
// RUN: %{python} %S/Inputs/make-old.py %t/Lib.swiftinterface
21+
// Make sure the forwarding file is replaced with a real module.
2122
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
2223

23-
// Delete the cached module we just created, and create the forwarding module again
24+
// Delete the cached module we just created, put the old .swiftinterface back, and create the forwarding module again
2425
// RUN: %empty-directory(%t/MCP)
26+
// RUN: mv %t/Lib.swiftinterface.moved-aside %t/Lib.swiftinterface
2527
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT %s
2628

2729
// Move the prebuilt module out of the way, so the forwarding module points to nothing.

0 commit comments

Comments
 (0)