Skip to content

Commit 5cb98bf

Browse files
author
Harlan Haskins
authored
[ModuleInterface] Pass -Rmodule-interface-rebuild to sub-invocation (#24737)
Previously, we wouldn't pass this flag to sub-invocations, which means that if we had to fall back and recompile a transitive import, we wouldn't get a remark. rdar://50729662
1 parent cfc2dda commit 5cb98bf

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

include/swift/Frontend/ParseableInterfaceModuleLoader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
167167
static bool buildSwiftModuleFromSwiftInterface(
168168
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
169169
StringRef ModuleName, StringRef InPath, StringRef OutPath,
170-
bool SerializeDependencyHashes, bool TrackSystemDependencies);
170+
bool SerializeDependencyHashes, bool TrackSystemDependencies,
171+
bool RemarkOnRebuildFromInterface);
171172
};
172173

173174
/// Extract the specified-or-defaulted -module-cache-path that winds up in

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ class swift::ParseableInterfaceBuilder {
289289
const StringRef prebuiltCachePath;
290290
const bool serializeDependencyHashes;
291291
const bool trackSystemDependencies;
292+
const bool remarkOnRebuildFromInterface;
292293
const SourceLoc diagnosticLoc;
293294
DependencyTracker *const dependencyTracker;
294295
CompilerInvocation subInvocation;
@@ -350,7 +351,12 @@ class swift::ParseableInterfaceBuilder {
350351
// Tell the subinvocation to serialize dependency hashes if asked to do so.
351352
auto &frontendOpts = subInvocation.getFrontendOptions();
352353
frontendOpts.SerializeModuleInterfaceDependencyHashes =
353-
serializeDependencyHashes;
354+
serializeDependencyHashes;
355+
356+
// Tell the subinvocation to remark on rebuilds from an interface if asked
357+
// to do so.
358+
frontendOpts.RemarkOnRebuildFromModuleInterface =
359+
remarkOnRebuildFromInterface;
354360
}
355361

356362
bool extractSwiftInterfaceVersionAndArgs(
@@ -473,13 +479,15 @@ class swift::ParseableInterfaceBuilder {
473479
StringRef prebuiltCachePath,
474480
bool serializeDependencyHashes = false,
475481
bool trackSystemDependencies = false,
482+
bool remarkOnRebuildFromInterface = false,
476483
SourceLoc diagnosticLoc = SourceLoc(),
477484
DependencyTracker *tracker = nullptr)
478485
: ctx(ctx), fs(*ctx.SourceMgr.getFileSystem()), diags(ctx.Diags),
479486
interfacePath(interfacePath), moduleName(moduleName),
480487
moduleCachePath(moduleCachePath), prebuiltCachePath(prebuiltCachePath),
481488
serializeDependencyHashes(serializeDependencyHashes),
482489
trackSystemDependencies(trackSystemDependencies),
490+
remarkOnRebuildFromInterface(remarkOnRebuildFromInterface),
483491
diagnosticLoc(diagnosticLoc), dependencyTracker(tracker) {
484492
configureSubInvocation();
485493
}
@@ -1230,7 +1238,7 @@ class ParseableInterfaceModuleLoaderImpl {
12301238
ParseableInterfaceBuilder builder(
12311239
ctx, interfacePath, moduleName, cacheDir, prebuiltCacheDir,
12321240
/*serializeDependencyHashes*/false, trackSystemDependencies,
1233-
diagnosticLoc, dependencyTracker);
1241+
remarkOnRebuildFromInterface, diagnosticLoc, dependencyTracker);
12341242
auto &subInvocation = builder.getSubInvocation();
12351243

12361244
// Compute the output path if we're loading or emitting a cached module.
@@ -1367,11 +1375,13 @@ std::error_code ParseableInterfaceModuleLoader::findModuleFilesInDirectory(
13671375
bool ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
13681376
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
13691377
StringRef ModuleName, StringRef InPath, StringRef OutPath,
1370-
bool SerializeDependencyHashes, bool TrackSystemDependencies) {
1378+
bool SerializeDependencyHashes, bool TrackSystemDependencies,
1379+
bool RemarkOnRebuildFromInterface) {
13711380
ParseableInterfaceBuilder builder(Ctx, InPath, ModuleName,
13721381
CacheDir, PrebuiltCacheDir,
13731382
SerializeDependencyHashes,
1374-
TrackSystemDependencies);
1383+
TrackSystemDependencies,
1384+
RemarkOnRebuildFromInterface);
13751385
// FIXME: We really only want to serialize 'important' dependencies here, if
13761386
// we want to ship the built swiftmodules to another machine.
13771387
return builder.buildSwiftModule(OutPath, /*shouldSerializeDeps*/true,

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ static bool buildModuleFromParseableInterface(CompilerInvocation &Invocation,
602602
PrebuiltCachePath, Invocation.getModuleName(), InputPath,
603603
Invocation.getOutputFilename(),
604604
FEOpts.SerializeModuleInterfaceDependencyHashes,
605-
FEOpts.TrackSystemDeps);
605+
FEOpts.TrackSystemDeps, FEOpts.RemarkOnRebuildFromModuleInterface);
606606
}
607607

608608
static bool compileLLVMIR(CompilerInvocation &Invocation,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/Build)
3+
// RUN: %empty-directory(%t/ModuleCache)
4+
5+
// 1. Create a module called InnerModule, and put its interface into the build dir.
6+
// RUN: echo 'public func inInnerModule() {}' | %target-swift-frontend - -typecheck -emit-module-interface-path %t/Build/InnerModule.swiftinterface -enable-library-evolution -swift-version 5 -module-name InnerModule
7+
8+
// 2. Build the .swiftinterface to a .swiftmodule, which will have a dependency on the interface
9+
// RUN: %target-swift-frontend -compile-module-from-interface -o %t/Build/InnerModule.swiftmodule %t/Build/InnerModule.swiftinterface
10+
11+
// 3. Touch the interface so the module becomes out of date.
12+
// RUN: touch %t/Build/InnerModule.swiftinterface
13+
14+
// 4. Create a module called OuterModule that imports InnerModule, and put its interface into the build dir.
15+
// RUN: echo 'import InnerModule' | %target-swift-frontend - -emit-module -o %t/Build/OuterModule.swiftmodule -module-name OuterModule -I %t/Build
16+
17+
// 5. Build this file, and expect that InnerModule is out of date
18+
// RUN: %target-swift-frontend -typecheck %s -I %t/Build -Rmodule-interface-rebuild -module-cache-path %t/ModuleCache 2>&1 | %FileCheck %s
19+
20+
import OuterModule
21+
22+
// CHECK: rebuilding module 'InnerModule' from interface '{{.*}}/Build/InnerModule.swiftinterface'
23+
// CHECK: compiled module is out of date: '{{.*}}/Build/InnerModule.swiftmodule'
24+
// CHECK: dependency is out of date: '{{.*}}/Build/InnerModule.swiftinterface'

0 commit comments

Comments
 (0)