Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b190dd

Browse files
authored
Merge pull request swiftlang#7011 from rintaro/5.9-macros-serialization-pluginopts
[Swift 5.9][Swift/Macros] Update for serialization change in Swift
2 parents 9087763 + 9786298 commit 5b190dd

File tree

1 file changed

+85
-79
lines changed

1 file changed

+85
-79
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

+85-79
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
12201220
getFrameworkSearchPaths(), framework_search_paths,
12211221
.Path);
12221222

1223-
std::vector<swift::PluginSearchOption::Value> plugin_search_options;
1223+
std::vector<swift::PluginSearchOption> plugin_search_options;
12241224
llvm::StringSet<> known_plugin_search_paths;
12251225
llvm::StringSet<> known_external_plugin_search_paths;
12261226
llvm::StringSet<> known_compiler_plugin_library_paths;
@@ -1311,87 +1311,93 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13111311
return false;
13121312
};
13131313

1314-
// Discover, rewrite, and unique compiler plugin paths.
1315-
for (auto path : extended_validation_info.getPluginSearchPaths()) {
1316-
// System plugins shipping with the compiler.
1317-
// Rewrite them to go through an ABI-compatible swift-plugin-server.
1318-
if (known_plugin_search_paths.insert(path).second) {
1319-
if (known_external_plugin_search_paths.insert(path).second) {
1320-
std::string server = get_plugin_server(
1321-
path, [&]() { return GetPluginServer(path); });
1322-
if (server.empty())
1323-
continue;
1324-
if (exists(path))
1325-
plugin_search_options.emplace_back(
1326-
swift::PluginSearchOption::ExternalPluginPath{path.str(),
1327-
server});
1314+
for (auto &opt : extended_validation_info.getPluginSearchOptions()) {
1315+
switch (opt.first) {
1316+
case swift::PluginSearchOption::Kind::PluginPath: {
1317+
StringRef path = opt.second;
1318+
// System plugins shipping with the compiler.
1319+
// Rewrite them to go through an ABI-compatible swift-plugin-server.
1320+
if (known_plugin_search_paths.insert(path).second) {
1321+
if (known_external_plugin_search_paths.insert(path).second) {
1322+
std::string server = get_plugin_server(
1323+
path, [&]() { return GetPluginServer(path); });
1324+
if (server.empty())
1325+
continue;
1326+
if (exists(path))
1327+
plugin_search_options.emplace_back(
1328+
swift::PluginSearchOption::ExternalPluginPath{path.str(),
1329+
server});
1330+
}
13281331
}
1332+
continue;
13291333
}
1330-
}
1331-
for (auto path :
1332-
extended_validation_info.getExternalPluginSearchPaths()) {
1333-
// Sandboxed system plugins shipping with some compiler.
1334-
// Keep the original plugin server path, it needs to be ABI
1335-
// compatible with the version of SwiftSyntax used by the plugin.
1336-
auto plugin_server = path.split('#');
1337-
llvm::StringRef plugin = plugin_server.first;
1338-
std::string server = get_plugin_server(
1339-
plugin, [&]() { return plugin_server.second.str(); });
1340-
if (server.empty())
1334+
case swift::PluginSearchOption::Kind::ExternalPluginPath: {
1335+
// Sandboxed system plugins shipping with some compiler.
1336+
// Keep the original plugin server path, it needs to be ABI
1337+
// compatible with the version of SwiftSyntax used by the plugin.
1338+
auto plugin_server = opt.second.split('#');
1339+
llvm::StringRef plugin = plugin_server.first;
1340+
std::string server = get_plugin_server(
1341+
plugin, [&]() { return plugin_server.second.str(); });
1342+
if (server.empty())
1343+
continue;
1344+
if (known_external_plugin_search_paths.insert(plugin).second)
1345+
if (exists(plugin))
1346+
plugin_search_options.emplace_back(
1347+
swift::PluginSearchOption::ExternalPluginPath{plugin.str(),
1348+
server});
13411349
continue;
1342-
if (known_external_plugin_search_paths.insert(plugin).second)
1343-
if (exists(plugin))
1344-
plugin_search_options.emplace_back(
1345-
swift::PluginSearchOption::ExternalPluginPath{plugin.str(),
1346-
server});
1347-
}
1350+
}
1351+
case swift::PluginSearchOption::Kind::LoadPluginLibrary: {
1352+
// Compiler plugin libraries.
1353+
StringRef dylib = opt.second;
1354+
if (known_compiler_plugin_library_paths.insert(dylib).second)
1355+
if (exists(dylib)) {
1356+
// We never want to directly load any plugins, since a crash in
1357+
// the plugin would bring down LLDB. Here, we assume that the
1358+
// correct plugin server for a direct compiler plugin is the one
1359+
// from the SDK the compiler was building for. This is just a
1360+
// heuristic.
1361+
// This works because the Swift compiler enforces
1362+
// '-load-plugin-library' dylibs to be named
1363+
// libModuleName.[dylib|so|dll] just like
1364+
// '-external-plugin-path'.
1365+
llvm::SmallString<0> dir(dylib);
1366+
llvm::sys::path::remove_filename(dir);
1367+
std::string server = get_plugin_server(dir, [&]() {
1368+
return GetPluginServerForSDK(invocation.getSDKPath());
1369+
});
1370+
if (server.empty())
1371+
continue;
13481372

1349-
for (auto dylib :
1350-
extended_validation_info.getCompilerPluginLibraryPaths()) {
1351-
// Compiler plugin libraries.
1352-
if (known_compiler_plugin_library_paths.insert(dylib).second)
1353-
if (exists(dylib)) {
1354-
// We never want to directly load any plugins, since a crash in
1355-
// the plugin would bring down LLDB. Here, we assume that the
1356-
// correct plugin server for a direct compiler plugin is the one
1357-
// from the SDK the compiler was building for. This is just a
1358-
// heuristic.
1359-
llvm::SmallString<0> dir(dylib);
1360-
llvm::sys::path::remove_filename(dir);
1361-
std::string server = get_plugin_server(dir, [&]() {
1362-
return GetPluginServerForSDK(invocation.getSDKPath());
1363-
});
1364-
if (server.empty())
1365-
continue;
1366-
1367-
// FIXME: The Swift compiler expects external plugins
1368-
// to be named libModuleName.[dylib|so|dll]. This
1369-
// means this our translation attempts only work for
1370-
// macro libraries following this convention. cf.
1371-
// PluginLoader::lookupExternalLibraryPluginByModuleName().
1372-
plugin_search_options.emplace_back(
1373-
swift::PluginSearchOption::ExternalPluginPath{dir.str().str(),
1374-
server});
1375-
}
1373+
plugin_search_options.emplace_back(
1374+
swift::PluginSearchOption::ExternalPluginPath{
1375+
dir.str().str(), server});
1376+
}
1377+
continue;
1378+
}
1379+
case swift::PluginSearchOption::Kind::LoadPluginExecutable: {
1380+
// Compiler plugin executables.
1381+
auto plugin_modules = opt.second.split('#');
1382+
llvm::StringRef plugin = plugin_modules.first;
1383+
llvm::StringRef modules_list = plugin_modules.second;
1384+
llvm::SmallVector<llvm::StringRef, 0> modules;
1385+
modules_list.split(modules, ",");
1386+
std::vector<std::string> modules_vec;
1387+
for (auto m : modules)
1388+
modules_vec.push_back(m.str());
1389+
if (known_compiler_plugin_executable_paths.insert(opt.second)
1390+
.second)
1391+
if (exists(plugin))
1392+
plugin_search_options.emplace_back(
1393+
swift::PluginSearchOption::LoadPluginExecutable{
1394+
plugin.str(), modules_vec});
1395+
continue;
1396+
}
1397+
}
1398+
llvm_unreachable("unhandled plugin search option kind");
13761399
}
13771400

1378-
for (auto path :
1379-
extended_validation_info.getCompilerPluginExecutablePaths()) {
1380-
// Compiler plugin executables.
1381-
auto plugin_modules = path.split('#');
1382-
llvm::StringRef plugin = plugin_modules.first;
1383-
llvm::StringRef modules_list = plugin_modules.second;
1384-
llvm::SmallVector<llvm::StringRef, 0> modules;
1385-
modules_list.split(modules, ",");
1386-
std::vector<std::string> modules_vec;
1387-
for (auto m : modules)
1388-
modules_vec.push_back(m.str());
1389-
if (known_compiler_plugin_executable_paths.insert(path).second)
1390-
if (exists(plugin))
1391-
plugin_search_options.emplace_back(
1392-
swift::PluginSearchOption::LoadPluginExecutable{plugin.str(),
1393-
modules_vec});
1394-
}
13951401
return true;
13961402
};
13971403

@@ -2018,7 +2024,7 @@ static void ProcessModule(
20182024
ModuleSP module_sp, std::string m_description,
20192025
bool discover_implicit_search_paths, bool use_all_compiler_flags,
20202026
Target &target, llvm::Triple triple,
2021-
std::vector<swift::PluginSearchOption::Value> &plugin_search_options,
2027+
std::vector<swift::PluginSearchOption> &plugin_search_options,
20222028
std::vector<std::string> &module_search_paths,
20232029
std::vector<std::pair<std::string, bool>> &framework_search_paths,
20242030
std::vector<std::string> &extra_clang_args) {
@@ -2164,7 +2170,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
21642170

21652171
LLDB_SCOPED_TIMER();
21662172
std::string m_description = "SwiftASTContextForExpressions";
2167-
std::vector<swift::PluginSearchOption::Value> plugin_search_options;
2173+
std::vector<swift::PluginSearchOption> plugin_search_options;
21682174
std::vector<std::string> module_search_paths;
21692175
std::vector<std::pair<std::string, bool>> framework_search_paths;
21702176
TargetSP target_sp = typeref_typesystem.GetTargetWP().lock();
@@ -4629,7 +4635,7 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
46294635
bool use_all_compiler_flags = target_sp->GetUseAllCompilerFlags();
46304636
unsigned num_images = module_list.GetSize();
46314637
for (size_t mi = 0; mi != num_images; ++mi) {
4632-
std::vector<swift::PluginSearchOption::Value> plugin_search_options;
4638+
std::vector<swift::PluginSearchOption> plugin_search_options;
46334639
std::vector<std::string> module_search_paths;
46344640
std::vector<std::pair<std::string, bool>> framework_search_paths;
46354641
std::vector<std::string> extra_clang_args;

0 commit comments

Comments
 (0)