Skip to content

Commit 0a3bd3e

Browse files
committed
[ModuleInterface] Address more review comments.
1 parent a0de5b3 commit 0a3bd3e

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,7 @@ ParseableInterfaceModuleLoader::configureSubInvocationAndOutputPaths(
121121
SubInvocation.setInputKind(InputFileKind::SwiftModuleInterface);
122122
SubInvocation.setRuntimeResourcePath(SearchPathOpts.RuntimeResourcePath);
123123
SubInvocation.setTargetTriple(LangOpts.Target);
124-
125-
if (auto ClangLoader = Ctx.getClangModuleLoader()) {
126-
auto const &Clang = ClangLoader->getClangInstance();
127-
std::string ModuleCachePath = getModuleCachePathFromClang(Clang);
128-
SubInvocation.setClangModuleCachePath(ModuleCachePath);
129-
}
124+
SubInvocation.setClangModuleCachePath(CacheDir);
130125

131126
// Calculate an output filename that includes a hash of relevant key data, and
132127
// wire up the SubInvocation's InputsAndOutputs to contain both input and
@@ -152,7 +147,9 @@ ParseableInterfaceModuleLoader::configureSubInvocationAndOutputPaths(
152147
// Check that the output .swiftmodule file is at least as new as all the
153148
// dependencies it read when it was built last time.
154149
static bool
155-
swiftModuleIsUpToDate(clang::vfs::FileSystem &FS, StringRef OutPath) {
150+
swiftModuleIsUpToDate(clang::vfs::FileSystem &FS,
151+
StringRef ModuleCachePath,
152+
StringRef OutPath) {
156153

157154
if (!FS.exists(OutPath))
158155
return false;
@@ -183,11 +180,12 @@ swiftModuleIsUpToDate(clang::vfs::FileSystem &FS, StringRef OutPath) {
183180
<< " is directly out of date\n");
184181
return false;
185182
}
186-
// Recursively probe any .swiftmodules for up-to-date-ness.
183+
// Recursively check freshness of any .swiftmodules in the module cache.
187184
auto Ext = llvm::sys::path::extension(In.Path);
188185
auto Ty = file_types::lookupTypeForExtension(Ext);
189186
if (Ty == file_types::TY_SwiftModuleFile &&
190-
!swiftModuleIsUpToDate(FS, In.Path)) {
187+
In.Path.startswith(ModuleCachePath) &&
188+
!swiftModuleIsUpToDate(FS, ModuleCachePath, In.Path)) {
191189
LLVM_DEBUG(llvm::dbgs() << "Dep " << In.Path
192190
<< " is indirectly out of date\n");
193191
return false;
@@ -312,7 +310,7 @@ std::error_code ParseableInterfaceModuleLoader::openModuleFiles(
312310
configureSubInvocationAndOutputPaths(SubInvocation, InPath, OutPath);
313311

314312
// Evaluate if we need to run this sub-invocation, and if so run it.
315-
if (!swiftModuleIsUpToDate(FS, OutPath)) {
313+
if (!swiftModuleIsUpToDate(FS, CacheDir, OutPath)) {
316314
if (buildSwiftModuleFromSwiftInterface(FS, Diags, SubInvocation, InPath,
317315
OutPath))
318316
return std::make_error_code(std::errc::invalid_argument);

test/ParseableInterface/client.swift

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,64 @@
5858
//
5959
//
6060
// Phase 4: Same command as in phase 3, but check that none of the cached modules are rebuilt.
61+
// (The initial touch commands here are redundant, but are repeated to remind the reader of context.)
62+
// RUN: touch -t 201401240006 %t/LeafModule.swiftinterface
63+
// RUN: touch -t 201401240007 %t/OtherModule.swiftinterface
64+
// RUN: touch -t 201401240007 %t/modulecache/LeafModule-*.swiftmodule
65+
// RUN: touch -t 201401240008 %t/TestModule.swiftmodule
66+
// RUN: touch -t 201401240008 %t/modulecache/OtherModule-*.swiftmodule
6167
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
68+
// (Reset TestModule to where it was moments ago)
6269
// RUN: touch -t 201401240008 %t/TestModule.swiftmodule
70+
// (Check that TestModule -- at minute 08 -- is still not-older than the two cached modules, which should still be at minutes 08 and 07.)
6371
// RUN: test ! %t/TestModule.swiftmodule -ot %t/modulecache/OtherModule-*.swiftmodule
6472
// RUN: test ! %t/TestModule.swiftmodule -ot %t/modulecache/LeafModule-*.swiftmodule
6573
//
6674
//
6775
// Phase 5: change the mtime on LeafModule.swiftinterface and watch LeafModule-*.swiftmodule and OtherModule-*.swiftmodule recompile.
76+
// (The initial touch commands here are redundant, but are repeated to remind the reader of context.)
77+
// RUN: touch -t 201401240006 %t/LeafModule.swiftinterface
78+
// RUN: touch -t 201401240007 %t/OtherModule.swiftinterface
79+
// RUN: touch -t 201401240007 %t/modulecache/LeafModule-*.swiftmodule
80+
// RUN: touch -t 201401240008 %t/TestModule.swiftmodule
81+
// RUN: touch -t 201401240008 %t/modulecache/OtherModule-*.swiftmodule
82+
// (Push LeafModule's interface forward 10 minutes from the minute 06 timestamp stored in both cached modules, invalidating them)
6883
// RUN: touch -t 201401240016 %t/LeafModule.swiftinterface
6984
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
85+
// (Check that the two cached modules were rebuit -- that the LeafModule.swiftinterface at minute 16 is older than them.)
7086
// RUN: test %t/LeafModule.swiftinterface -ot %t/modulecache/LeafModule-*.swiftmodule
7187
// RUN: test %t/LeafModule.swiftinterface -ot %t/modulecache/OtherModule-*.swiftmodule
7288
//
7389
//
7490
// Phase 6: change the mtimes on LeafModule-*.swiftmodule and OtherModule.swiftinterface, and watch just OtherModule-*.swiftmodule recompile, leaving LeafModule-*.swiftmodule alone.
91+
// (The initial touch commands here are redundant, but are repeated to remind the reader of context.)
92+
// RUN: touch -t 201401240016 %t/LeafModule.swiftinterface
93+
// RUN: touch -t 201401240007 %t/OtherModule.swiftinterface
94+
// RUN: touch %t/modulecache/LeafModule-*.swiftmodule
95+
// RUN: touch %t/modulecache/OtherModule-*.swiftmodule
96+
// (Perturb LeafModule's cached module and OtherModule's interface mtimes, so they do not match values stored in OtherModule's cached module.)
7597
// RUN: touch -t 201401240016 %t/modulecache/LeafModule-*.swiftmodule
7698
// RUN: touch -t 201401240017 %t/OtherModule.swiftinterface
7799
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
100+
// (Check that Othermodule.swiftinterface at minute 17 is not older than the LeafModule's cached module which should still be at minute 16.)
78101
// RUN: test ! %t/OtherModule.swiftinterface -ot %t/modulecache/LeafModule-*.swiftmodule
102+
// (Check that Othermodule.swiftinterface at minute 17 _is_ older than the OtherModule's cached module, which was just rebuilt.)
79103
// RUN: test %t/OtherModule.swiftinterface -ot %t/modulecache/OtherModule-*.swiftmodule
80104
//
81105
//
82-
// Phase 7: change the size on LeafModule.swiftinterface (keeping mtime fixed) and watch LeafModule-*.swiftmodule and OtherModule-*.swiftmodule recompile.
106+
// Phase 7: change the _size_ on LeafModule.swiftinterface (keeping mtime fixed) and watch LeafModule-*.swiftmodule and OtherModule-*.swiftmodule recompile.
107+
// (The initial touch commands here are redundant, but are repeated to remind the reader of context.)
108+
// RUN: touch -t 201401240016 %t/LeafModule.swiftinterface
109+
// RUN: touch -t 201401240016 %t/modulecache/LeafModule-*.swiftmodule
110+
// RUN: touch -t 201401240017 %t/OtherModule.swiftinterface
83111
// RUN: touch -t 201401240017 %t/modulecache/OtherModule-*.swiftmodule
112+
// (Perturb the size of the LeafModule interface while keeping its mtime fixed.)
84113
// RUN: echo '// size change' >>%t/LeafModule.swiftinterface
85114
// RUN: touch -t 201401240016 %t/LeafModule.swiftinterface
86115
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
116+
// (Check that both of the cached modules were rebuilt and are now newer than their respective interfaces.)
87117
// RUN: test %t/LeafModule.swiftinterface -ot %t/modulecache/LeafModule-*.swiftmodule
88-
// RUN: test %t/LeafModule.swiftinterface -ot %t/modulecache/OtherModule-*.swiftmodule
118+
// RUN: test %t/OtherModule.swiftinterface -ot %t/modulecache/OtherModule-*.swiftmodule
89119

90120
import OtherModule
91121

0 commit comments

Comments
 (0)