Skip to content

Commit 706985d

Browse files
committed
[Macros] Update plugin search options serialization
Previously plugin search options were serialized for each option kind. Instead serialize them in the order specified.
1 parent 457c55b commit 706985d

File tree

8 files changed

+92
-138
lines changed

8 files changed

+92
-138
lines changed

include/swift/Serialization/SerializationOptions.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SERIALIZATION_SERIALIZATIONOPTIONS_H
1414
#define SWIFT_SERIALIZATION_SERIALIZATIONOPTIONS_H
1515

16+
#include "swift/AST/SearchPathOptions.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Basic/PathRemapper.h"
1819
#include "llvm/Support/VersionTuple.h"
@@ -43,10 +44,7 @@ namespace swift {
4344
StringRef ModuleLinkName;
4445
StringRef ModuleInterface;
4546
std::vector<std::string> ExtraClangOptions;
46-
std::vector<std::string> PluginSearchPaths;
47-
std::vector<std::string> ExternalPluginSearchPaths;
48-
std::vector<std::string> CompilerPluginLibraryPaths;
49-
std::vector<std::string> CompilerPluginExecutablePaths;
47+
std::vector<swift::PluginSearchOption::Value> PluginSearchOptions;
5048

5149
/// Path prefixes that should be rewritten in debug info.
5250
PathRemapper DebuggingOptionsPrefixMap;

include/swift/Serialization/Validation.h

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ struct ValidationInfo {
111111
class ExtendedValidationInfo {
112112
SmallVector<StringRef, 4> ExtraClangImporterOpts;
113113

114-
SmallVector<StringRef, 1> PluginSearchPaths;
115-
SmallVector<StringRef, 1> ExternalPluginSearchPaths;
116-
SmallVector<StringRef, 1> CompilerPluginLibraryPaths;
117-
SmallVector<StringRef, 1> CompilerPluginExecutablePaths;
114+
SmallVector<std::pair<StringRef, StringRef>, 2> PluginSearchOptions;
118115

119116
std::string SDKPath;
120117
StringRef ModuleABIName;
@@ -149,32 +146,11 @@ class ExtendedValidationInfo {
149146
ExtraClangImporterOpts.push_back(option);
150147
}
151148

152-
ArrayRef<StringRef> getPluginSearchPaths() const {
153-
return PluginSearchPaths;
149+
ArrayRef<std::pair<StringRef, StringRef>> getPluginSearchOptions() const {
150+
return PluginSearchOptions;
154151
}
155-
void addPluginSearchPath(StringRef path) {
156-
PluginSearchPaths.push_back(path);
157-
}
158-
159-
ArrayRef<StringRef> getExternalPluginSearchPaths() const {
160-
return ExternalPluginSearchPaths;
161-
}
162-
void addExternalPluginSearchPath(StringRef path) {
163-
ExternalPluginSearchPaths.push_back(path);
164-
}
165-
166-
ArrayRef<StringRef> getCompilerPluginLibraryPaths() const {
167-
return CompilerPluginLibraryPaths;
168-
}
169-
void addCompilerPluginLibraryPath(StringRef path) {
170-
CompilerPluginLibraryPaths.push_back(path);
171-
}
172-
173-
ArrayRef<StringRef> getCompilerPluginExecutablePaths() const {
174-
return CompilerPluginExecutablePaths;
175-
}
176-
void addCompilerPluginExecutablePath(StringRef path) {
177-
CompilerPluginExecutablePaths.push_back(path);
152+
void addPluginSearchOption(const std::pair<StringRef, StringRef> &opt) {
153+
PluginSearchOptions.push_back(opt);
178154
}
179155

180156
bool isSIB() const { return Bits.IsSIB; }

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -209,36 +209,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
209209
serializationOpts.ExtraClangOptions = getClangImporterOptions().ExtraArgs;
210210
}
211211

212-
// FIXME: Preserve the order of these options.
213-
for (auto &elem : getSearchPathOptions().PluginSearchOpts) {
214-
// '-plugin-path' options.
215-
if (auto *arg = elem.dyn_cast<PluginSearchOption::PluginPath>()) {
216-
serializationOpts.PluginSearchPaths.push_back(arg->SearchPath);
217-
continue;
218-
}
219-
220-
// '-external-plugin-path' options.
221-
if (auto *arg = elem.dyn_cast<PluginSearchOption::ExternalPluginPath>()) {
222-
serializationOpts.ExternalPluginSearchPaths.push_back(
223-
arg->SearchPath + "#" + arg->ServerPath);
224-
continue;
225-
}
226-
227-
// '-load-plugin-library' options.
228-
if (auto *arg = elem.dyn_cast<PluginSearchOption::LoadPluginLibrary>()) {
229-
serializationOpts.CompilerPluginLibraryPaths.push_back(arg->LibraryPath);
230-
continue;
231-
}
232-
233-
// '-load-plugin-executable' options.
234-
if (auto *arg = elem.dyn_cast<PluginSearchOption::LoadPluginExecutable>()) {
235-
std::string optStr = arg->ExecutablePath + "#";
236-
llvm::interleave(
237-
arg->ModuleNames, [&](auto &name) { optStr += name; },
238-
[&]() { optStr += ","; });
239-
serializationOpts.CompilerPluginExecutablePaths.push_back(optStr);
240-
}
241-
}
212+
serializationOpts.PluginSearchOptions =
213+
getSearchPathOptions().PluginSearchOpts;
242214

243215
serializationOpts.DisableCrossModuleIncrementalInfo =
244216
opts.DisableCrossModuleIncrementalBuild;

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,27 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
126126
case options_block::XCC:
127127
extendedInfo.addExtraClangImporterOption(blobData);
128128
break;
129-
case options_block::PLUGIN_SEARCH_PATH:
130-
extendedInfo.addPluginSearchPath(blobData);
131-
break;
132-
case options_block::EXTERNAL_SEARCH_PLUGIN_PATH:
133-
extendedInfo.addExternalPluginSearchPath(blobData);
134-
break;
135-
case options_block::COMPILER_PLUGIN_LIBRARY_PATH:
136-
extendedInfo.addCompilerPluginLibraryPath(blobData);
137-
break;
138-
case options_block::COMPILER_PLUGIN_EXECUTABLE_PATH:
139-
extendedInfo.addCompilerPluginExecutablePath(blobData);
129+
case options_block::PLUGIN_SEARCH_OPTION: {
130+
unsigned optKind;
131+
StringRef optStr;
132+
options_block::ResilienceStrategyLayout::readRecord(scratch, optKind);
133+
switch (PluginSearchOptionKind(optKind)) {
134+
case PluginSearchOptionKind::PluginPath:
135+
optStr = "-plugin-path";
136+
break;
137+
case PluginSearchOptionKind::ExternalPluginPath:
138+
optStr = "-external-plugin-path";
139+
break;
140+
case PluginSearchOptionKind::LoadPluginLibrary:
141+
optStr = "-load-plugin-library";
142+
break;
143+
case PluginSearchOptionKind::LoadPluginExecutable:
144+
optStr = "-load-plugin-executable";
145+
break;
146+
}
147+
extendedInfo.addPluginSearchOption({optStr, blobData});
140148
break;
149+
}
141150
case options_block::IS_SIB:
142151
bool IsSIB;
143152
options_block::IsSIBLayout::readRecord(scratch, IsSIB);

lib/Serialization/ModuleFormat.h

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 792; // removed select_value
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 793; // PluginSearchOption
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -651,6 +651,16 @@ enum class MacroIntroducedDeclNameKind : uint8_t {
651651
};
652652
using MacroIntroducedDeclNameKindField = BCFixed<4>;
653653

654+
// These IDs must \em not be renumbered or reordered without incrementing
655+
// the module version.
656+
enum class PluginSearchOptionKind : uint8_t {
657+
PluginPath,
658+
ExternalPluginPath,
659+
LoadPluginLibrary,
660+
LoadPluginExecutable,
661+
};
662+
using PluginSearchOptionKindField = BCFixed<3>;
663+
654664
// Encodes a VersionTuple:
655665
//
656666
// Major
@@ -884,10 +894,7 @@ namespace options_block {
884894
IS_CONCURRENCY_CHECKED,
885895
MODULE_PACKAGE_NAME,
886896
MODULE_EXPORT_AS_NAME,
887-
PLUGIN_SEARCH_PATH,
888-
EXTERNAL_SEARCH_PLUGIN_PATH,
889-
COMPILER_PLUGIN_LIBRARY_PATH,
890-
COMPILER_PLUGIN_EXECUTABLE_PATH,
897+
PLUGIN_SEARCH_OPTION,
891898
HAS_CXX_INTEROPERABILITY_ENABLED,
892899
};
893900

@@ -901,24 +908,10 @@ namespace options_block {
901908
BCBlob // -Xcc flag, as string
902909
>;
903910

904-
using PluginSearchPathLayout = BCRecordLayout<
905-
PLUGIN_SEARCH_PATH,
906-
BCBlob // -plugin-path value
907-
>;
908-
909-
using ExternalPluginSearchPathLayout = BCRecordLayout<
910-
EXTERNAL_SEARCH_PLUGIN_PATH,
911-
BCBlob // -external-plugin-path value
912-
>;
913-
914-
using CompilerPluginLibraryPathLayout = BCRecordLayout<
915-
COMPILER_PLUGIN_LIBRARY_PATH,
916-
BCBlob // -load-plugin-library value
917-
>;
918-
919-
using CompilerPluginExecutablePathLayout = BCRecordLayout<
920-
COMPILER_PLUGIN_EXECUTABLE_PATH,
921-
BCBlob // -load-plugin-executable value
911+
using PluginSearchOptionLayout = BCRecordLayout<
912+
PLUGIN_SEARCH_OPTION,
913+
PluginSearchOptionKindField, // kind
914+
BCBlob // option value string
922915
>;
923916

924917
using IsSIBLayout = BCRecordLayout<

lib/Serialization/Serialization.cpp

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,7 @@ void Serializer::writeBlockInfoBlock() {
846846
BLOCK_RECORD(options_block, HAS_CXX_INTEROPERABILITY_ENABLED);
847847
BLOCK_RECORD(options_block, MODULE_PACKAGE_NAME);
848848
BLOCK_RECORD(options_block, MODULE_EXPORT_AS_NAME);
849-
BLOCK_RECORD(options_block, PLUGIN_SEARCH_PATH);
850-
BLOCK_RECORD(options_block, EXTERNAL_SEARCH_PLUGIN_PATH);
851-
BLOCK_RECORD(options_block, COMPILER_PLUGIN_LIBRARY_PATH);
852-
BLOCK_RECORD(options_block, COMPILER_PLUGIN_EXECUTABLE_PATH);
849+
BLOCK_RECORD(options_block, PLUGIN_SEARCH_OPTION);
853850

854851
BLOCK(INPUT_BLOCK);
855852
BLOCK_RECORD(input_block, IMPORTED_MODULE);
@@ -1138,27 +1135,41 @@ void Serializer::writeHeader(const SerializationOptions &options) {
11381135
}
11391136

11401137
// Macro plugins
1141-
options_block::PluginSearchPathLayout PluginSearchPath(Out);
1142-
for (auto Arg : options.PluginSearchPaths) {
1143-
PluginSearchPath.emit(ScratchRecord, Arg);
1144-
}
1145-
1146-
options_block::ExternalPluginSearchPathLayout
1147-
ExternalPluginSearchPath(Out);
1148-
for (auto Arg : options.ExternalPluginSearchPaths) {
1149-
ExternalPluginSearchPath.emit(ScratchRecord, Arg);
1150-
}
1151-
1152-
options_block::CompilerPluginLibraryPathLayout
1153-
CompilerPluginLibraryPath(Out);
1154-
for (auto Arg : options.CompilerPluginLibraryPaths) {
1155-
CompilerPluginLibraryPath.emit(ScratchRecord, Arg);
1156-
}
1157-
1158-
options_block::CompilerPluginExecutablePathLayout
1159-
CompilerPluginExecutablePath(Out);
1160-
for (auto Arg : options.CompilerPluginExecutablePaths) {
1161-
CompilerPluginExecutablePath.emit(ScratchRecord, Arg);
1138+
options_block::PluginSearchOptionLayout PluginSearchOpt(Out);
1139+
for (auto &elem : options.PluginSearchOptions) {
1140+
if (auto *opt = elem.dyn_cast<PluginSearchOption::PluginPath>()) {
1141+
PluginSearchOpt.emit(ScratchRecord,
1142+
uint8_t(PluginSearchOptionKind::PluginPath),
1143+
opt->SearchPath);
1144+
continue;
1145+
}
1146+
if (auto *opt =
1147+
elem.dyn_cast<PluginSearchOption::ExternalPluginPath>()) {
1148+
PluginSearchOpt.emit(
1149+
ScratchRecord,
1150+
uint8_t(PluginSearchOptionKind::ExternalPluginPath),
1151+
opt->SearchPath + "#" + opt->ServerPath);
1152+
continue;
1153+
}
1154+
if (auto *opt =
1155+
elem.dyn_cast<PluginSearchOption::LoadPluginLibrary>()) {
1156+
PluginSearchOpt.emit(
1157+
ScratchRecord,
1158+
uint8_t(PluginSearchOptionKind::LoadPluginLibrary),
1159+
opt->LibraryPath);
1160+
continue;
1161+
}
1162+
if (auto *opt =
1163+
elem.dyn_cast<PluginSearchOption::LoadPluginExecutable>()) {
1164+
std::string optStr = opt->ExecutablePath + "#";
1165+
llvm::interleave(
1166+
opt->ModuleNames, [&](auto &name) { optStr += name; },
1167+
[&]() { optStr += ","; });
1168+
PluginSearchOpt.emit(
1169+
ScratchRecord,
1170+
uint8_t(PluginSearchOptionKind::LoadPluginExecutable), optStr);
1171+
continue;
1172+
}
11621173
}
11631174
}
11641175
}

test/Macros/serialize_plugin_search_paths.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin
1212

1313
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out | %FileCheck %s
14-
// CHECK: - Macro Search Paths:
15-
// CHECK: -plugin-path: {{.*}}plugins
16-
// CHECK: -plugin-path: {{.*}}plugins
17-
// CHECK: -plugin-path: {{.*}}plugins
18-
// CHECK: -external-plugin-path: {{.*}}plugins#{{.*}}swift-plugin-server
19-
// CHECK: -load-plugin-library: {{.*}}MacroDefinition.{{dylib|so|dll}}
20-
// CHECK: -load-plugin-executable: {{.*}}mock-plugin#TestPlugin
14+
// CHECK: - Plugin Search Options:
15+
// CHECK: -plugin-path {{.*}}plugins
16+
// CHECK: -external-plugin-path {{.*}}plugins#{{.*}}swift-plugin-server
17+
// CHECK: -load-plugin-library {{.*}}MacroDefinition.{{dylib|so|dll}}
18+
// CHECK: -load-plugin-executable {{.*}}mock-plugin#TestPlugin
19+
// CHECK: -plugin-path {{.*}}plugins
20+
// CHECK: -plugin-path {{.*}}plugins

tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,10 @@ static bool validateModule(
8989
llvm::outs() << ", system=" << (searchPath.IsSystem ? "true" : "false")
9090
<< "\n";
9191
}
92-
llvm::outs() << "- Macro Search Paths:\n";
93-
for (auto path : extendedInfo.getPluginSearchPaths())
94-
llvm::outs() << " -plugin-path: " << path << "\n";
95-
for (auto path : extendedInfo.getExternalPluginSearchPaths())
96-
llvm::outs() << " -external-plugin-path: " << path << "\n";
97-
for (auto path : extendedInfo.getCompilerPluginLibraryPaths())
98-
llvm::outs() << " -load-plugin-library: " << path << "\n";
99-
for (auto path : extendedInfo.getCompilerPluginExecutablePaths())
100-
llvm::outs() << " -load-plugin-executable: " << path << "\n";
92+
llvm::outs() << "- Plugin Search Options:\n";
93+
for (auto opt : extendedInfo.getPluginSearchOptions()) {
94+
llvm::outs() << " " << opt.first << " " << opt.second << "\n";
95+
}
10196
}
10297

10398
return true;

0 commit comments

Comments
 (0)