Skip to content

Commit 614deb6

Browse files
committed
[ParseableInterface] Pass prebuilt cache path down to sub-invocations
Otherwise, the top-level compilation gets the benefit of the prebuilt cache path, but the sub-invocations for swiftinterfaces that /do/ need to be compiled do not.
1 parent 7562137 commit 614deb6

File tree

7 files changed

+46
-13
lines changed

7 files changed

+46
-13
lines changed

include/swift/Frontend/ParseableInterfaceSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
106106
/// testing purposes.
107107
static bool buildSwiftModuleFromSwiftInterface(ASTContext &Ctx,
108108
StringRef CacheDir,
109+
StringRef PrebuiltCacheDir,
109110
StringRef ModuleName,
110111
StringRef InPath,
111112
StringRef OutPath);

lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ static std::string getCacheHash(ASTContext &Ctx,
131131

132132
static CompilerInvocation
133133
createInvocationForBuildingFromInterface(ASTContext &Ctx, StringRef ModuleName,
134-
StringRef CacheDir) {
134+
StringRef CacheDir,
135+
StringRef PrebuiltCacheDir) {
135136
auto &SearchPathOpts = Ctx.SearchPathOpts;
136137
auto &LangOpts = Ctx.LangOpts;
137138

@@ -145,8 +146,10 @@ createInvocationForBuildingFromInterface(ASTContext &Ctx, StringRef ModuleName,
145146
SubInvocation.setInputKind(InputFileKind::SwiftModuleInterface);
146147
SubInvocation.setRuntimeResourcePath(SearchPathOpts.RuntimeResourcePath);
147148
SubInvocation.setTargetTriple(LangOpts.Target);
148-
SubInvocation.setClangModuleCachePath(CacheDir);
149+
149150
SubInvocation.setModuleName(ModuleName);
151+
SubInvocation.setClangModuleCachePath(CacheDir);
152+
SubInvocation.getFrontendOptions().PrebuiltModuleCachePath = PrebuiltCacheDir;
150153

151154
// Inhibit warnings from the SubInvocation since we are assuming the user
152155
// is not in a position to fix them.
@@ -514,7 +517,7 @@ std::error_code ParseableInterfaceModuleLoader::findModuleFilesInDirectory(
514517
// emit the .swiftmodule.
515518
CompilerInvocation SubInvocation =
516519
createInvocationForBuildingFromInterface(Ctx, ModuleID.first.str(),
517-
CacheDir);
520+
CacheDir, PrebuiltCacheDir);
518521
computeCachedOutputPath(Ctx, SubInvocation, InPath, OutPath);
519522

520523
// Evaluate if we need to run this sub-invocation, and if so run it.
@@ -546,10 +549,11 @@ std::error_code ParseableInterfaceModuleLoader::findModuleFilesInDirectory(
546549

547550
bool
548551
ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
549-
ASTContext &Ctx, StringRef CacheDir, StringRef ModuleName,
550-
StringRef InPath, StringRef OutPath) {
552+
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
553+
StringRef ModuleName, StringRef InPath, StringRef OutPath) {
551554
CompilerInvocation SubInvocation =
552-
createInvocationForBuildingFromInterface(Ctx, ModuleName, CacheDir);
555+
createInvocationForBuildingFromInterface(Ctx, ModuleName, CacheDir,
556+
PrebuiltCacheDir);
553557

554558
auto &FS = *Ctx.SourceMgr.getFileSystem();
555559
auto &Diags = Ctx.Diags;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,14 @@ static bool precompileBridgingHeader(CompilerInvocation &Invocation,
561561

562562
static bool buildModuleFromParseableInterface(CompilerInvocation &Invocation,
563563
CompilerInstance &Instance) {
564-
const auto &InputsAndOutputs =
565-
Invocation.getFrontendOptions().InputsAndOutputs;
566-
assert(InputsAndOutputs.hasSingleInput());
567-
StringRef InputPath = InputsAndOutputs.getFilenameOfFirstInput();
564+
const FrontendOptions &FEOpts = Invocation.getFrontendOptions();
565+
assert(FEOpts.InputsAndOutputs.hasSingleInput());
566+
StringRef InputPath = FEOpts.InputsAndOutputs.getFilenameOfFirstInput();
567+
StringRef PrebuiltCachePath = FEOpts.PrebuiltModuleCachePath;
568568
return ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
569569
Instance.getASTContext(), Invocation.getClangModuleCachePath(),
570-
Invocation.getModuleName(), InputPath, Invocation.getOutputFilename());
570+
PrebuiltCachePath, Invocation.getModuleName(), InputPath,
571+
Invocation.getOutputFilename());
571572
}
572573

573574
static bool compileLLVMIR(CompilerInvocation &Invocation,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -parse-stdlib -module-name LibExporter
3+
4+
@_exported import Lib

test/ParseableInterface/ModuleCache/prebuilt-module-cache-archs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// RUN: %empty-directory(%t/prebuilt-cache/Lib.swiftmodule)
1717
// RUN: sed -e 's/FromInterface/FromPrebuilt/g' %S/Inputs/prebuilt-module-cache/Lib.swiftinterface | %target-swift-frontend -parse-stdlib -module-cache-path %t/MCP -emit-module-path %t/prebuilt-cache/Lib.swiftmodule/%target-swiftmodule-name - -module-name Lib
1818
// RUN: not %target-swift-frontend -typecheck -enable-parseable-module-interface -parse-stdlib -module-cache-path %t/MCP -sdk %t/include -I %t/include/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT %s
19-
// RUN: ls %t/MCP | grep -v swiftmodule
19+
// RUN: ls %t/MCP | not grep swiftmodule
2020

2121
// What if the module is invalid?
2222
// RUN: rm %t/prebuilt-cache/Lib.swiftmodule/%target-swiftmodule-name && touch %t/prebuilt-cache/Lib.swiftmodule/%target-swiftmodule-name
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// Baseline check: if the module is not in the prebuilt cache, build it
4+
// normally.
5+
// RUN: %empty-directory(%t/prebuilt-cache)
6+
// RUN: not %target-swift-frontend -typecheck -enable-parseable-module-interface -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
7+
8+
// Do a manual prebuild, and see if it gets picked up.
9+
// RUN: %empty-directory(%t/MCP)
10+
// RUN: sed -e 's/FromInterface/FromPrebuilt/g' %S/Inputs/prebuilt-module-cache/Lib.swiftinterface | %target-swift-frontend -parse-stdlib -module-cache-path %t/MCP -emit-module-path %t/prebuilt-cache/Lib.swiftmodule - -module-name Lib
11+
// RUN: not %target-swift-frontend -typecheck -enable-parseable-module-interface -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT %s
12+
// RUN: ls %t/MCP | grep -v LibExporter | not grep swiftmodule
13+
14+
// What if the module is invalid?
15+
// RUN: rm %t/prebuilt-cache/Lib.swiftmodule && touch %t/prebuilt-cache/Lib.swiftmodule
16+
// RUN: not %target-swift-frontend -typecheck -enable-parseable-module-interface -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs/ -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
17+
18+
import LibExporter
19+
20+
struct X {}
21+
let _: X = Lib.testValue
22+
// FROM-INTERFACE: [[@LINE-1]]:16: error: cannot convert value of type 'FromInterface' to specified type 'X'
23+
// FROM-PREBUILT: [[@LINE-2]]:16: error: cannot convert value of type 'FromPrebuilt' to specified type 'X'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// RUN: %empty-directory(%t/MCP)
1414
// RUN: sed -e 's/FromInterface/FromPrebuilt/g' %S/Inputs/prebuilt-module-cache/Lib.swiftinterface | %target-swift-frontend -parse-stdlib -module-cache-path %t/MCP -emit-module-path %t/prebuilt-cache/Lib.swiftmodule - -module-name Lib
1515
// RUN: not %target-swift-frontend -typecheck -enable-parseable-module-interface -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT %s
16-
// RUN: ls %t/MCP | grep -v swiftmodule
16+
// RUN: ls %t/MCP | not grep swiftmodule
1717

1818
// Try some variations on the detection that the search path is in the SDK:
1919
// RUN: not %target-swift-frontend -typecheck -enable-parseable-module-interface -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT %s

0 commit comments

Comments
 (0)