Skip to content

Commit c88c8b5

Browse files
committed
[ParseableInterface] Don't serialize deps for explicit builds
If the frontend is invoked with -build-module-from-parseable-interface, we might be trying to persist and distribute the swiftmodule that gets built. In that case, any dependencies we list might not be relevant. This probably isn't really the final answer here; what we want is some way to say /which/ dependencies are relevant, and how they're related to how the swiftmodule that gets used. Most likely the right answer here is to limit this to dependencies within the SDK or something.
1 parent 614deb6 commit c88c8b5

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

include/swift/Frontend/ParseableInterfaceSupport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
8282
static bool buildSwiftModuleFromSwiftInterface(
8383
clang::vfs::FileSystem &FS, DiagnosticEngine &Diags, SourceLoc DiagLoc,
8484
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath,
85-
StringRef ModuleCachePath, DependencyTracker *OuterTracker);
85+
StringRef ModuleCachePath, DependencyTracker *OuterTracker,
86+
bool ShouldSerializeDeps);
8687

8788
std::error_code findModuleFilesInDirectory(
8889
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,

lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ collectDepsForSerialization(clang::vfs::FileSystem &FS,
307307
bool ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
308308
clang::vfs::FileSystem &FS, DiagnosticEngine &Diags, SourceLoc DiagLoc,
309309
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath,
310-
StringRef ModuleCachePath, DependencyTracker *OuterTracker) {
310+
StringRef ModuleCachePath, DependencyTracker *OuterTracker,
311+
bool ShouldSerializeDeps) {
311312
bool SubError = false;
312313
bool RunSuccess = llvm::CrashRecoveryContext().RunSafelyOnThread([&] {
313314
// Note that we don't assume ModuleCachePath is the same as the Clang
@@ -411,7 +412,8 @@ bool ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
411412
SubError = true;
412413
return;
413414
}
414-
SerializationOpts.Dependencies = Deps;
415+
if (ShouldSerializeDeps)
416+
SerializationOpts.Dependencies = Deps;
415417
SILMod->setSerializeSILAction([&]() {
416418
serialize(Mod, SerializationOpts, SILMod.get());
417419
});
@@ -525,7 +527,8 @@ std::error_code ParseableInterfaceModuleLoader::findModuleFilesInDirectory(
525527
dependencyTracker)) {
526528
if (buildSwiftModuleFromSwiftInterface(FS, Diags, ModuleID.second,
527529
SubInvocation, InPath, OutPath,
528-
CacheDir, dependencyTracker))
530+
CacheDir, dependencyTracker,
531+
/*ShouldSerializeDeps*/true))
529532
return std::make_error_code(std::errc::invalid_argument);
530533
}
531534
}
@@ -557,10 +560,15 @@ ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
557560

558561
auto &FS = *Ctx.SourceMgr.getFileSystem();
559562
auto &Diags = Ctx.Diags;
563+
// FIXME: We don't really want to ignore dependencies here, but we have to
564+
// identify which ones are important, and make them relocatable
565+
// (SDK-relative) if we want to ship the built swiftmodules to another
566+
// machine. Just leave them out for now.
560567
return buildSwiftModuleFromSwiftInterface(FS, Diags, /*DiagLoc*/SourceLoc(),
561568
SubInvocation, InPath, OutPath,
562569
/*CachePath*/"",
563-
/*OuterTracker*/nullptr);
570+
/*OuterTracker*/nullptr,
571+
/*ShouldSerializeDeps*/false);
564572
}
565573

566574
/// Diagnose any scoped imports in \p imports, i.e. those with a non-empty

test/ParseableInterface/SmokeTest.swiftinterface

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// RUN: %target-swift-ide-test -print-module -module-to-print SmokeTest -I %t -source-filename x -print-interface > %t/SmokeTest.txt
1515
// RUN: %FileCheck %s < %t/SmokeTest.txt
1616
// RUN: %FileCheck -check-prefix NEGATIVE %s < %t/SmokeTest.txt
17+
// RUN: llvm-bcanalyzer -dump %t/SmokeTest.swiftmodule | not grep FILE_DEPENDENCY
1718

1819
// CHECK-LABEL: public class TestClass
1920
public class TestClass {

0 commit comments

Comments
 (0)