Skip to content

[Swift/Macros] Update for serialization change in Swift #7003

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
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
58 changes: 32 additions & 26 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
getFrameworkSearchPaths(), framework_search_paths,
.Path);

std::vector<swift::PluginSearchOption::Value> plugin_search_options;
std::vector<swift::PluginSearchOption> plugin_search_options;
llvm::StringSet<> known_plugin_search_paths;
llvm::StringSet<> known_external_plugin_search_paths;
llvm::StringSet<> known_compiler_plugin_library_paths;
Expand Down Expand Up @@ -1311,8 +1311,10 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
return false;
};

// Discover, rewrite, and unique compiler plugin paths.
for (auto path : extended_validation_info.getPluginSearchPaths()) {
for (auto &opt : extended_validation_info.getPluginSearchOptions()) {
switch (opt.first) {
case swift::PluginSearchOption::Kind::PluginPath: {
StringRef path = opt.second;
// System plugins shipping with the compiler.
// Rewrite them to go through an ABI-compatible swift-plugin-server.
if (known_plugin_search_paths.insert(path).second) {
Expand All @@ -1327,13 +1329,13 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
server});
}
}
continue;
}
for (auto path :
extended_validation_info.getExternalPluginSearchPaths()) {
case swift::PluginSearchOption::Kind::ExternalPluginPath: {
// Sandboxed system plugins shipping with some compiler.
// Keep the original plugin server path, it needs to be ABI
// compatible with the version of SwiftSyntax used by the plugin.
auto plugin_server = path.split('#');
auto plugin_server = opt.second.split('#');
llvm::StringRef plugin = plugin_server.first;
std::string server = get_plugin_server(
plugin, [&]() { return plugin_server.second.str(); });
Expand All @@ -1344,18 +1346,22 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
plugin_search_options.emplace_back(
swift::PluginSearchOption::ExternalPluginPath{plugin.str(),
server});
continue;
}

for (auto dylib :
extended_validation_info.getCompilerPluginLibraryPaths()) {
case swift::PluginSearchOption::Kind::LoadPluginLibrary: {
// Compiler plugin libraries.
StringRef dylib = opt.second;
if (known_compiler_plugin_library_paths.insert(dylib).second)
if (exists(dylib)) {
// We never want to directly load any plugins, since a crash in
// the plugin would bring down LLDB. Here, we assume that the
// correct plugin server for a direct compiler plugin is the one
// from the SDK the compiler was building for. This is just a
// heuristic.
// This works because the Swift compiler enforces
// '-load-plugin-library' dylibs to be named
// libModuleName.[dylib|so|dll] just like
// '-external-plugin-path'.
llvm::SmallString<0> dir(dylib);
llvm::sys::path::remove_filename(dir);
std::string server = get_plugin_server(dir, [&]() {
Expand All @@ -1364,34 +1370,34 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
if (server.empty())
continue;

// FIXME: The Swift compiler expects external plugins
// to be named libModuleName.[dylib|so|dll]. This
// means this our translation attempts only work for
// macro libraries following this convention. cf.
// PluginLoader::lookupExternalLibraryPluginByModuleName().
plugin_search_options.emplace_back(
swift::PluginSearchOption::ExternalPluginPath{dir.str().str(),
server});
swift::PluginSearchOption::ExternalPluginPath{
dir.str().str(), server});
}
continue;
}

for (auto path :
extended_validation_info.getCompilerPluginExecutablePaths()) {
case swift::PluginSearchOption::Kind::LoadPluginExecutable: {
// Compiler plugin executables.
auto plugin_modules = path.split('#');
auto plugin_modules = opt.second.split('#');
llvm::StringRef plugin = plugin_modules.first;
llvm::StringRef modules_list = plugin_modules.second;
llvm::SmallVector<llvm::StringRef, 0> modules;
modules_list.split(modules, ",");
std::vector<std::string> modules_vec;
for (auto m : modules)
modules_vec.push_back(m.str());
if (known_compiler_plugin_executable_paths.insert(path).second)
if (known_compiler_plugin_executable_paths.insert(opt.second)
.second)
if (exists(plugin))
plugin_search_options.emplace_back(
swift::PluginSearchOption::LoadPluginExecutable{plugin.str(),
modules_vec});
swift::PluginSearchOption::LoadPluginExecutable{
plugin.str(), modules_vec});
continue;
}
}
llvm_unreachable("unhandled plugin search option kind");
}

return true;
};

Expand Down Expand Up @@ -2018,7 +2024,7 @@ static void ProcessModule(
ModuleSP module_sp, std::string m_description,
bool discover_implicit_search_paths, bool use_all_compiler_flags,
Target &target, llvm::Triple triple,
std::vector<swift::PluginSearchOption::Value> &plugin_search_options,
std::vector<swift::PluginSearchOption> &plugin_search_options,
std::vector<std::string> &module_search_paths,
std::vector<std::pair<std::string, bool>> &framework_search_paths,
std::vector<std::string> &extra_clang_args) {
Expand Down Expand Up @@ -2164,7 +2170,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(

LLDB_SCOPED_TIMER();
std::string m_description = "SwiftASTContextForExpressions";
std::vector<swift::PluginSearchOption::Value> plugin_search_options;
std::vector<swift::PluginSearchOption> plugin_search_options;
std::vector<std::string> module_search_paths;
std::vector<std::pair<std::string, bool>> framework_search_paths;
TargetSP target_sp = typeref_typesystem.GetTargetWP().lock();
Expand Down Expand Up @@ -4629,7 +4635,7 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
bool use_all_compiler_flags = target_sp->GetUseAllCompilerFlags();
unsigned num_images = module_list.GetSize();
for (size_t mi = 0; mi != num_images; ++mi) {
std::vector<swift::PluginSearchOption::Value> plugin_search_options;
std::vector<swift::PluginSearchOption> plugin_search_options;
std::vector<std::string> module_search_paths;
std::vector<std::pair<std::string, bool>> framework_search_paths;
std::vector<std::string> extra_clang_args;
Expand Down