Skip to content

[ModuleInterface] Pass -Rmodule-interface-rebuild to sub-invocation #24737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/swift/Frontend/ParseableInterfaceModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
static bool buildSwiftModuleFromSwiftInterface(
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
StringRef ModuleName, StringRef InPath, StringRef OutPath,
bool SerializeDependencyHashes, bool TrackSystemDependencies);
bool SerializeDependencyHashes, bool TrackSystemDependencies,
bool RemarkOnRebuildFromInterface);
};

/// Extract the specified-or-defaulted -module-cache-path that winds up in
Expand Down
18 changes: 14 additions & 4 deletions lib/Frontend/ParseableInterfaceModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class swift::ParseableInterfaceBuilder {
const StringRef prebuiltCachePath;
const bool serializeDependencyHashes;
const bool trackSystemDependencies;
const bool remarkOnRebuildFromInterface;
const SourceLoc diagnosticLoc;
DependencyTracker *const dependencyTracker;
CompilerInvocation subInvocation;
Expand Down Expand Up @@ -350,7 +351,12 @@ class swift::ParseableInterfaceBuilder {
// Tell the subinvocation to serialize dependency hashes if asked to do so.
auto &frontendOpts = subInvocation.getFrontendOptions();
frontendOpts.SerializeModuleInterfaceDependencyHashes =
serializeDependencyHashes;
serializeDependencyHashes;

// Tell the subinvocation to remark on rebuilds from an interface if asked
// to do so.
frontendOpts.RemarkOnRebuildFromModuleInterface =
remarkOnRebuildFromInterface;
}

bool extractSwiftInterfaceVersionAndArgs(
Expand Down Expand Up @@ -473,13 +479,15 @@ class swift::ParseableInterfaceBuilder {
StringRef prebuiltCachePath,
bool serializeDependencyHashes = false,
bool trackSystemDependencies = false,
bool remarkOnRebuildFromInterface = false,
SourceLoc diagnosticLoc = SourceLoc(),
DependencyTracker *tracker = nullptr)
: ctx(ctx), fs(*ctx.SourceMgr.getFileSystem()), diags(ctx.Diags),
interfacePath(interfacePath), moduleName(moduleName),
moduleCachePath(moduleCachePath), prebuiltCachePath(prebuiltCachePath),
serializeDependencyHashes(serializeDependencyHashes),
trackSystemDependencies(trackSystemDependencies),
remarkOnRebuildFromInterface(remarkOnRebuildFromInterface),
diagnosticLoc(diagnosticLoc), dependencyTracker(tracker) {
configureSubInvocation();
}
Expand Down Expand Up @@ -1230,7 +1238,7 @@ class ParseableInterfaceModuleLoaderImpl {
ParseableInterfaceBuilder builder(
ctx, interfacePath, moduleName, cacheDir, prebuiltCacheDir,
/*serializeDependencyHashes*/false, trackSystemDependencies,
diagnosticLoc, dependencyTracker);
remarkOnRebuildFromInterface, diagnosticLoc, dependencyTracker);
auto &subInvocation = builder.getSubInvocation();

// Compute the output path if we're loading or emitting a cached module.
Expand Down Expand Up @@ -1367,11 +1375,13 @@ std::error_code ParseableInterfaceModuleLoader::findModuleFilesInDirectory(
bool ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
StringRef ModuleName, StringRef InPath, StringRef OutPath,
bool SerializeDependencyHashes, bool TrackSystemDependencies) {
bool SerializeDependencyHashes, bool TrackSystemDependencies,
bool RemarkOnRebuildFromInterface) {
ParseableInterfaceBuilder builder(Ctx, InPath, ModuleName,
CacheDir, PrebuiltCacheDir,
SerializeDependencyHashes,
TrackSystemDependencies);
TrackSystemDependencies,
RemarkOnRebuildFromInterface);
// FIXME: We really only want to serialize 'important' dependencies here, if
// we want to ship the built swiftmodules to another machine.
return builder.buildSwiftModule(OutPath, /*shouldSerializeDeps*/true,
Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ static bool buildModuleFromParseableInterface(CompilerInvocation &Invocation,
PrebuiltCachePath, Invocation.getModuleName(), InputPath,
Invocation.getOutputFilename(),
FEOpts.SerializeModuleInterfaceDependencyHashes,
FEOpts.TrackSystemDeps);
FEOpts.TrackSystemDeps, FEOpts.RemarkOnRebuildFromModuleInterface);
}

static bool compileLLVMIR(CompilerInvocation &Invocation,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/Build)
// RUN: %empty-directory(%t/ModuleCache)

// 1. Create a module called InnerModule, and put its interface into the build dir.
// 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

// 2. Build the .swiftinterface to a .swiftmodule, which will have a dependency on the interface
// RUN: %target-swift-frontend -compile-module-from-interface -o %t/Build/InnerModule.swiftmodule %t/Build/InnerModule.swiftinterface

// 3. Touch the interface so the module becomes out of date.
// RUN: touch %t/Build/InnerModule.swiftinterface

// 4. Create a module called OuterModule that imports InnerModule, and put its interface into the build dir.
// RUN: echo 'import InnerModule' | %target-swift-frontend - -emit-module -o %t/Build/OuterModule.swiftmodule -module-name OuterModule -I %t/Build

// 5. Build this file, and expect that InnerModule is out of date
// RUN: %target-swift-frontend -typecheck %s -I %t/Build -Rmodule-interface-rebuild -module-cache-path %t/ModuleCache 2>&1 | %FileCheck %s

import OuterModule

// CHECK: rebuilding module 'InnerModule' from interface '{{.*}}/Build/InnerModule.swiftinterface'
// CHECK: compiled module is out of date: '{{.*}}/Build/InnerModule.swiftmodule'
// CHECK: dependency is out of date: '{{.*}}/Build/InnerModule.swiftinterface'