Skip to content

Commit b18e865

Browse files
[Caching] Fix typecheck swiftinterface with prefix map
SwiftVerifyEmittedModuleInterface job is configured to be built within the SubInvocation and it needs to inherit the caching replay prefix map in order to load macro plugin library correctly. rdar://158692095
1 parent 900be48 commit b18e865

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
588588
StringRef CacheDir, StringRef PrebuiltCacheDir,
589589
StringRef BackupInterfaceDir, StringRef ModuleName, StringRef InPath,
590590
StringRef OutPath, StringRef ABIOutputPath,
591+
ArrayRef<std::pair<std::string, std::string>> replayPrefixMap,
591592
bool SerializeDependencyHashes, bool TrackSystemDependencies,
592593
ModuleInterfaceLoaderOptions Opts,
593594
RequireOSSAModules_t RequireOSSAModules,
@@ -675,7 +676,9 @@ struct InterfaceSubContextDelegateImpl : InterfaceSubContextDelegate {
675676
const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts,
676677
ModuleInterfaceLoaderOptions LoaderOpts, bool buildModuleCacheDirIfAbsent,
677678
StringRef moduleCachePath, StringRef prebuiltCachePath,
678-
StringRef backupModuleInterfaceDir, bool serializeDependencyHashes,
679+
StringRef backupModuleInterfaceDir,
680+
ArrayRef<std::pair<std::string, std::string>> replayPrefixMap,
681+
bool serializeDependencyHashes,
679682
bool trackSystemDependencies, RequireOSSAModules_t requireOSSAModules);
680683

681684
template<typename ...ArgTypes>

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
238238
.PrebuiltModuleCachePath,
239239
workerCompilerInvocation->getFrontendOptions()
240240
.BackupModuleInterfaceDir,
241+
workerCompilerInvocation->getFrontendOptions().CacheReplayPrefixMap,
241242
workerCompilerInvocation->getFrontendOptions()
242243
.SerializeModuleInterfaceDependencyHashes,
243244
workerCompilerInvocation->getFrontendOptions()

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ bool CompilerInstance::setUpModuleLoaders() {
897897
LoaderOpts,
898898
/*buildModuleCacheDirIfAbsent*/ false, ClangModuleCachePath,
899899
FEOpts.PrebuiltModuleCachePath, FEOpts.BackupModuleInterfaceDir,
900+
FEOpts.CacheReplayPrefixMap,
900901
FEOpts.SerializeModuleInterfaceDependencyHashes,
901902
FEOpts.shouldTrackSystemDependencies(),
902903
RequireOSSAModules_t(Invocation.getSILOptions()));

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ class ModuleInterfaceLoaderImpl {
11291129
ctx.SourceMgr, &ctx.Diags, ctx.SearchPathOpts, ctx.LangOpts,
11301130
ctx.ClangImporterOpts, ctx.CASOpts, Opts,
11311131
/*buildModuleCacheDirIfAbsent*/ true, cacheDir, prebuiltCacheDir,
1132-
backupInterfaceDir,
1132+
backupInterfaceDir, /*replayPrefixMap=*/{},
11331133
/*serializeDependencyHashes*/ false, trackSystemDependencies,
11341134
requiresOSSAModules);
11351135

@@ -1501,16 +1501,17 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
15011501
const ClangImporterOptions &ClangOpts, const CASOptions &CASOpts,
15021502
StringRef CacheDir, StringRef PrebuiltCacheDir,
15031503
StringRef BackupInterfaceDir, StringRef ModuleName, StringRef InPath,
1504-
StringRef OutPath, StringRef ABIOutputPath, bool SerializeDependencyHashes,
1505-
bool TrackSystemDependencies, ModuleInterfaceLoaderOptions LoaderOpts,
1506-
RequireOSSAModules_t RequireOSSAModules,
1507-
bool silenceInterfaceDiagnostics) {
1504+
StringRef OutPath, StringRef ABIOutputPath,
1505+
ArrayRef<std::pair<std::string, std::string>> replayPrefixMap,
1506+
bool SerializeDependencyHashes, bool TrackSystemDependencies,
1507+
ModuleInterfaceLoaderOptions LoaderOpts,
1508+
RequireOSSAModules_t RequireOSSAModules, bool silenceInterfaceDiagnostics) {
15081509
InterfaceSubContextDelegateImpl astDelegate(
1509-
SourceMgr, &Diags, SearchPathOpts, LangOpts, ClangOpts, CASOpts, LoaderOpts,
1510+
SourceMgr, &Diags, SearchPathOpts, LangOpts, ClangOpts, CASOpts,
1511+
LoaderOpts,
15101512
/*CreateCacheDirIfAbsent*/ true, CacheDir, PrebuiltCacheDir,
1511-
BackupInterfaceDir,
1512-
SerializeDependencyHashes, TrackSystemDependencies,
1513-
RequireOSSAModules);
1513+
BackupInterfaceDir, replayPrefixMap, SerializeDependencyHashes,
1514+
TrackSystemDependencies, RequireOSSAModules);
15141515
ImplicitModuleInterfaceBuilder builder(SourceMgr, &Diags, astDelegate, InPath,
15151516
SearchPathOpts.getSDKPath(),
15161517
SearchPathOpts.getSysRoot(),
@@ -1885,6 +1886,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18851886
ModuleInterfaceLoaderOptions LoaderOpts, bool buildModuleCacheDirIfAbsent,
18861887
StringRef moduleCachePath, StringRef prebuiltCachePath,
18871888
StringRef backupModuleInterfaceDir,
1889+
ArrayRef<std::pair<std::string, std::string>> replayPrefixMap,
18881890
bool serializeDependencyHashes, bool trackSystemDependencies,
18891891
RequireOSSAModules_t requireOSSAModules)
18901892
: SM(SM), Diags(Diags), ArgSaver(Allocator) {
@@ -1933,6 +1935,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
19331935
genericSubInvocation.getLangOptions().EnableAppExtensionRestrictions = true;
19341936
GenericArgs.push_back("-application-extension");
19351937
}
1938+
SubFEOpts.CacheReplayPrefixMap = replayPrefixMap;
19361939

19371940
// Pass down -explicit-swift-module-map-file
19381941
StringRef explicitSwiftModuleMap = searchPathOpts.ExplicitSwiftModuleMapPath;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,10 @@ static bool buildModuleFromInterface(CompilerInstance &Instance) {
388388
Invocation.getClangImporterOptions(), Invocation.getCASOptions(),
389389
Invocation.getClangModuleCachePath(), PrebuiltCachePath,
390390
FEOpts.BackupModuleInterfaceDir, Invocation.getModuleName(), InputPath,
391-
Invocation.getOutputFilename(), ABIPath,
391+
Invocation.getOutputFilename(), ABIPath, FEOpts.CacheReplayPrefixMap,
392392
FEOpts.SerializeModuleInterfaceDependencyHashes,
393393
FEOpts.shouldTrackSystemDependencies(), LoaderOpts,
394-
RequireOSSAModules_t(Invocation.getSILOptions()),
395-
IgnoreAdjacentModules);
394+
RequireOSSAModules_t(Invocation.getSILOptions()), IgnoreAdjacentModules);
396395
}
397396

398397
static bool compileLLVMIR(CompilerInstance &Instance) {

test/CAS/macro_plugin_external.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474

7575
// RUN: %target-swift-frontend \
7676
// RUN: -emit-module -o %t/Macro.swiftmodule -cache-compile-job -cas-path %t/cas \
77+
// RUN: -emit-module-interface-path %t/Macro.swiftinterface \
7778
// RUN: -swift-version 5 -disable-implicit-swift-modules -O \
7879
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
7980
// RUN: -module-name MyApp -explicit-swift-module-map-file @%t/map2.casid -Rmacro-loading -Rcache-compile-job \
@@ -89,6 +90,7 @@
8990
/// Cache hit has no macro-loading remarks because no macro is actually loaded and the path might not be correct due to different mapping.
9091
// RUN: %target-swift-frontend \
9192
// RUN: -emit-module -o %t/Macro.swiftmodule -cache-compile-job -cas-path %t/cas \
93+
// RUN: -emit-module-interface-path %t/Macro.swiftinterface \
9294
// RUN: -swift-version 5 -disable-implicit-swift-modules -O \
9395
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
9496
// RUN: -module-name MyApp -explicit-swift-module-map-file @%t/map2.casid -Rmacro-loading -Rcache-compile-job \
@@ -100,15 +102,37 @@
100102
// RUN: touch %t/plugins/%target-library-name(MacroDefinition)
101103
// RUN: %target-swift-frontend \
102104
// RUN: -emit-module -o %t/Macro.swiftmodule -cache-compile-job -cas-path %t/cas \
105+
// RUN: -emit-module-interface-path %t/Macro.swiftinterface \
103106
// RUN: -swift-version 5 -disable-implicit-swift-modules -O \
104107
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
105108
// RUN: -module-name MyApp -explicit-swift-module-map-file @%t/map2.casid -Rmacro-loading -Rcache-compile-job -cache-disable-replay \
106109
// RUN: /^test/macro.swift @%t/MyApp2.cmd -cache-replay-prefix-map /^test %t -cache-replay-prefix-map /^bin %swift-bin-dir
107110

111+
/// Typecheck swift interface with macro plugin.
112+
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
113+
// RUN: %target-swift-frontend \
114+
// RUN: -emit-module -o %t/Macro.swiftmodule -cache-compile-job -cas-path %t/cas \
115+
// RUN: -emit-module-interface-path %t/Macro.swiftinterface \
116+
// RUN: -swift-version 5 -disable-implicit-swift-modules -O \
117+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
118+
// RUN: -module-name MyApp -explicit-swift-module-map-file @%t/map2.casid -Rmacro-loading -Rcache-compile-job -cache-disable-replay \
119+
// RUN: /^test/macro.swift @%t/MyApp2.cmd -cache-replay-prefix-map /^test %t -cache-replay-prefix-map /^bin %swift-bin-dir > %t/keys.json
120+
// RUN: %{python} %S/Inputs/ExtractOutputKey.py %t/keys.json /^test/macro.swift > %t/key
121+
122+
// RUN: %target-swift-frontend \
123+
// RUN: -typecheck-module-from-interface %t/Macro.swiftinterface \
124+
// RUN: -cache-compile-job -cas-path %t/cas \
125+
// RUN: -swift-version 5 -disable-implicit-swift-modules -O \
126+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
127+
// RUN: -module-name MyApp -explicit-swift-module-map-file @%t/map2.casid -Rmacro-loading -Rcache-compile-job -cache-disable-replay \
128+
// RUN: @%t/MyApp2.cmd -cache-replay-prefix-map /^test %t -cache-replay-prefix-map /^bin %swift-bin-dir \
129+
// RUN: -input-file-key @%t/key
130+
108131
/// Change the dylib content, this will fail the build.
109132
// RUN: echo " " >> %t/plugins/%target-library-name(MacroDefinition)
110133
// RUN: not %target-swift-frontend \
111134
// RUN: -emit-module -o %t/Macro.swiftmodule -cache-compile-job -cas-path %t/cas \
135+
// RUN: -emit-module-interface-path %t/Macro.swiftinterface \
112136
// RUN: -swift-version 5 -disable-implicit-swift-modules -O \
113137
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
114138
// RUN: -module-name MyApp -explicit-swift-module-map-file @%t/map2.casid -Rmacro-loading -Rcache-compile-job -cache-disable-replay \
@@ -120,9 +144,9 @@ func test() {}
120144

121145
//--- macro.swift
122146
@attached(extension, conformances: P, names: named(requirement))
123-
macro DelegatedConformance() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceViaExtensionMacro")
147+
public macro DelegatedConformance() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceViaExtensionMacro")
124148

125-
protocol P {
149+
public protocol P {
126150
static func requirement()
127151
}
128152

0 commit comments

Comments
 (0)