Skip to content

Commit 8959923

Browse files
committed
[ModuleInterface] Propagate dependencies to outer DependencyTracker for use in .d files.
1 parent d44943a commit 8959923

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class DependencyTracker {
6363

6464
/// \brief Abstract interface that loads named modules into the AST.
6565
class ModuleLoader {
66-
DependencyTracker * const dependencyTracker;
6766
virtual void anchor();
6867

6968
protected:
69+
DependencyTracker * const dependencyTracker;
7070
ModuleLoader(DependencyTracker *tracker) : dependencyTracker(tracker) {}
7171

7272
void addDependency(StringRef file, bool IsSystem=false) {

lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ static bool
173173
swiftModuleIsUpToDate(clang::vfs::FileSystem &FS,
174174
StringRef ModuleCachePath,
175175
StringRef OutPath,
176-
DiagnosticEngine &Diags) {
176+
DiagnosticEngine &Diags,
177+
DependencyTracker *OuterTracker) {
177178

178179
auto OutBuf = FS.getBufferForFile(OutPath);
179180
if (!OutBuf)
@@ -189,6 +190,8 @@ swiftModuleIsUpToDate(clang::vfs::FileSystem &FS,
189190
return false;
190191

191192
for (auto In : AllDeps) {
193+
if (OuterTracker)
194+
OuterTracker->addDependency(In.Path, /*IsSystem=*/false);
192195
auto DepBuf = getBufferOfDependency(FS, OutPath, In.Path, Diags);
193196
if (!DepBuf ||
194197
DepBuf->getBufferSize() != In.Size ||
@@ -218,13 +221,16 @@ collectDepsForSerialization(clang::vfs::FileSystem &FS,
218221
CompilerInstance &SubInstance,
219222
StringRef InPath, StringRef ModuleCachePath,
220223
SmallVectorImpl<FileDependency> &Deps,
221-
DiagnosticEngine &Diags) {
224+
DiagnosticEngine &Diags,
225+
DependencyTracker *OuterTracker) {
222226
auto DTDeps = SubInstance.getDependencyTracker()->getDependencies();
223227
SmallVector<StringRef, 16> InitialDepNames(DTDeps.begin(), DTDeps.end());
224228
InitialDepNames.push_back(InPath);
225229
llvm::StringSet<> AllDepNames;
226230
for (auto const &DepName : InitialDepNames) {
227231
AllDepNames.insert(DepName);
232+
if (OuterTracker)
233+
OuterTracker->addDependency(DepName, /*IsSystem=*/false);
228234
auto DepBuf = getBufferOfDependency(FS, InPath, DepName, Diags);
229235
if (!DepBuf) {
230236
return true;
@@ -255,6 +261,8 @@ collectDepsForSerialization(clang::vfs::FileSystem &FS,
255261
if (AllDepNames.count(SubDep.Path) == 0) {
256262
AllDepNames.insert(SubDep.Path);
257263
Deps.push_back(SubDep);
264+
if (OuterTracker)
265+
OuterTracker->addDependency(SubDep.Path, /*IsSystem=*/false);
258266
}
259267
}
260268
}
@@ -265,7 +273,7 @@ collectDepsForSerialization(clang::vfs::FileSystem &FS,
265273
static bool buildSwiftModuleFromSwiftInterface(
266274
clang::vfs::FileSystem &FS, DiagnosticEngine &Diags,
267275
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath,
268-
StringRef ModuleCachePath) {
276+
StringRef ModuleCachePath, DependencyTracker *OuterTracker) {
269277
bool SubError = false;
270278
bool RunSuccess = llvm::CrashRecoveryContext().RunSafelyOnThread([&] {
271279

@@ -328,7 +336,7 @@ static bool buildSwiftModuleFromSwiftInterface(
328336
SerializationOpts.SerializeAllSIL = true;
329337
SmallVector<FileDependency, 16> Deps;
330338
if (collectDepsForSerialization(FS, SubInstance, InPath, ModuleCachePath,
331-
Deps, Diags)) {
339+
Deps, Diags, OuterTracker)) {
332340
SubError = true;
333341
return;
334342
}
@@ -369,9 +377,9 @@ std::error_code ParseableInterfaceModuleLoader::openModuleFiles(
369377
configureSubInvocationAndOutputPaths(SubInvocation, InPath, OutPath);
370378

371379
// Evaluate if we need to run this sub-invocation, and if so run it.
372-
if (!swiftModuleIsUpToDate(FS, CacheDir, OutPath, Diags)) {
380+
if (!swiftModuleIsUpToDate(FS, CacheDir, OutPath, Diags, dependencyTracker)) {
373381
if (buildSwiftModuleFromSwiftInterface(FS, Diags, SubInvocation, InPath,
374-
OutPath, CacheDir))
382+
OutPath, CacheDir, dependencyTracker))
375383
return std::make_error_code(std::errc::invalid_argument);
376384
}
377385

test/ParseableInterface/ModuleCache/module-cache-init.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,26 @@
3333
//
3434
// Phase 3: build TestModule into a .swiftmodule explicitly us OtherModule via OtherModule.swiftinterface, creating OtherModule-*.swiftmodule along the way.
3535
//
36-
// 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
36+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -emit-dependencies -emit-dependencies-path %t/TestModule.d -o %t/TestModule.swiftmodule -module-name TestModule %s
3737
// RUN: test -f %t/TestModule.swiftmodule
3838
// RUN: test -f %t/modulecache/OtherModule-*.swiftmodule
39+
// RUN: test -f %t/TestModule.d
3940
// RUN: llvm-bcanalyzer -dump %t/modulecache/OtherModule-*.swiftmodule | %FileCheck %s -check-prefix=CHECK-OTHERMODULE
41+
// RUN: %FileCheck %s -check-prefix=CHECK-DEPENDS <%t/TestModule.d
4042
// CHECK-OTHERMODULE: {{MODULE_NAME.*blob data = 'OtherModule'}}
4143
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*Swift.swiftmodule'}}
4244
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*SwiftOnoneSupport.swiftmodule'}}
43-
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*LeafModule-.*.swiftmodule'}}
4445
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*LeafModule.swiftinterface'}}
46+
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*LeafModule-.*.swiftmodule'}}
4547
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*OtherModule.swiftinterface'}}
4648
// CHECK-OTHERMODULE: FUNC_DECL
49+
// CHECK-DEPENDS: TestModule.swiftmodule :
50+
// CHECK-DEPENDS-SAME: LeafModule.swiftinterface
51+
// CHECK-DEPENDS-SAME: OtherModule.swiftinterface
52+
// CHECK-DEPENDS-SAME: {{LeafModule-[^ ]+.swiftmodule}}
53+
// CHECK-DEPENDS-SAME: {{OtherModule-[^ ]+.swiftmodule}}
54+
// CHECK-DEPENDS-SAME: Swift.swiftmodule
55+
// CHECK-DEPENDS-SAME: SwiftOnoneSupport.swiftmodule
4756

4857
import OtherModule
4958

0 commit comments

Comments
 (0)