Skip to content

[5.9][Macros] Update plugin search options serialization #66724

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
Show file tree
Hide file tree
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
21 changes: 13 additions & 8 deletions include/swift/AST/PluginLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class ASTContext;
/// * Load plugins resolving VFS paths
/// * Track plugin dependencies
class PluginLoader {
public:
struct PluginEntry {
StringRef libraryPath;
StringRef executablePath;
};

private:
/// Plugin registry. Lazily populated by get/setRegistry().
/// NOTE: Do not reference this directly. Use getRegistry().
PluginRegistry *Registry = nullptr;
Expand All @@ -38,16 +45,15 @@ class PluginLoader {
ASTContext &Ctx;
DependencyTracker *DepTracker;

/// Map a module name to an executable plugin path that provides the module.
llvm::DenseMap<swift::Identifier, llvm::StringRef> ExecutablePluginPaths;
/// Map a module name to an plugin entry that provides the module.
llvm::Optional<llvm::DenseMap<swift::Identifier, PluginEntry>> PluginMap;

void createModuleToExecutablePluginMap();
/// Get or lazily create and populate 'PluginMap'.
llvm::DenseMap<swift::Identifier, PluginEntry> &getPluginMap();

public:
PluginLoader(ASTContext &Ctx, DependencyTracker *DepTracker)
: Ctx(Ctx), DepTracker(DepTracker) {
createModuleToExecutablePluginMap();
}
: Ctx(Ctx), DepTracker(DepTracker) {}

void setRegistry(PluginRegistry *newValue);
PluginRegistry *getRegistry();
Expand All @@ -63,8 +69,7 @@ class PluginLoader {
/// 'loadExecutablePlugin()'.
/// * (libPath: some, execPath: some) - load the executable path by
/// 'loadExecutablePlugin()' and let the plugin load the libPath via IPC.
std::pair<std::string, std::string>
lookupPluginByModuleName(Identifier moduleName);
const PluginEntry &lookupPluginByModuleName(Identifier moduleName);

/// Load the specified dylib plugin path resolving the path with the
/// current VFS. If it fails to load the plugin, a diagnostic is emitted, and
Expand Down
96 changes: 76 additions & 20 deletions include/swift/AST/SearchPathOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#define SWIFT_AST_SEARCHPATHOPTIONS_H

#include "swift/Basic/ArrayRefView.h"
#include "swift/Basic/ExternalUnion.h"
#include "swift/Basic/PathRemapper.h"
#include "swift/Basic/TaggedUnion.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringMap.h"
Expand Down Expand Up @@ -187,25 +187,81 @@ struct ExternalPluginSearchPathAndServerPath {
std::string ServerPath;
};

namespace PluginSearchOption {
struct LoadPluginLibrary {
std::string LibraryPath;
};
struct LoadPluginExecutable {
std::string ExecutablePath;
std::vector<std::string> ModuleNames;
};
struct PluginPath {
std::string SearchPath;
};
struct ExternalPluginPath {
std::string SearchPath;
std::string ServerPath;
};
class PluginSearchOption {
public:
struct LoadPluginLibrary {
std::string LibraryPath;
};
struct LoadPluginExecutable {
std::string ExecutablePath;
std::vector<std::string> ModuleNames;
};
struct PluginPath {
std::string SearchPath;
};
struct ExternalPluginPath {
std::string SearchPath;
std::string ServerPath;
};

enum class Kind : uint8_t {
LoadPluginLibrary,
LoadPluginExecutable,
PluginPath,
ExternalPluginPath,
};

using Value = TaggedUnion<LoadPluginLibrary, LoadPluginExecutable, PluginPath,
ExternalPluginPath>;
} // namespace PluginSearchOption
private:
using Members = ExternalUnionMembers<LoadPluginLibrary, LoadPluginExecutable,
PluginPath, ExternalPluginPath>;
static Members::Index getIndexForKind(Kind kind) {
switch (kind) {
case Kind::LoadPluginLibrary:
return Members::indexOf<LoadPluginLibrary>();
case Kind::LoadPluginExecutable:
return Members::indexOf<LoadPluginExecutable>();
case Kind::PluginPath:
return Members::indexOf<PluginPath>();
case Kind::ExternalPluginPath:
return Members::indexOf<ExternalPluginPath>();
}
};
using Storage = ExternalUnion<Kind, Members, getIndexForKind>;

Kind kind;
Storage storage;

public:
PluginSearchOption(const LoadPluginLibrary &v)
: kind(Kind::LoadPluginLibrary) {
storage.emplace<LoadPluginLibrary>(kind, v);
}
PluginSearchOption(const LoadPluginExecutable &v)
: kind(Kind::LoadPluginExecutable) {
storage.emplace<LoadPluginExecutable>(kind, v);
}
PluginSearchOption(const PluginPath &v) : kind(Kind::PluginPath) {
storage.emplace<PluginPath>(kind, v);
}
PluginSearchOption(const ExternalPluginPath &v)
: kind(Kind::ExternalPluginPath) {
storage.emplace<ExternalPluginPath>(kind, v);
}

Kind getKind() const { return kind; }

template <typename T>
const T *dyn_cast() const {
if (Members::indexOf<T>() != getIndexForKind(kind))
return nullptr;
return &storage.get<T>(kind);
}

template <typename T>
const T &get() const {
return storage.get<T>(kind);
}
};

/// Options for controlling search path behavior.
class SearchPathOptions {
Expand Down Expand Up @@ -383,7 +439,7 @@ class SearchPathOptions {
std::vector<std::string> RuntimeLibraryPaths;

/// Plugin search path options.
std::vector<PluginSearchOption::Value> PluginSearchOpts;
std::vector<PluginSearchOption> PluginSearchOpts;

/// Don't look in for compiler-provided modules.
bool SkipRuntimeLibraryImportPaths = false;
Expand Down
6 changes: 2 additions & 4 deletions include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef SWIFT_SERIALIZATION_SERIALIZATIONOPTIONS_H
#define SWIFT_SERIALIZATION_SERIALIZATIONOPTIONS_H

#include "swift/AST/SearchPathOptions.h"
#include "swift/Basic/LLVM.h"
#include "swift/Basic/PathRemapper.h"
#include "llvm/Support/VersionTuple.h"
Expand Down Expand Up @@ -43,10 +44,7 @@ namespace swift {
StringRef ModuleLinkName;
StringRef ModuleInterface;
std::vector<std::string> ExtraClangOptions;
std::vector<std::string> PluginSearchPaths;
std::vector<std::string> ExternalPluginSearchPaths;
std::vector<std::string> CompilerPluginLibraryPaths;
std::vector<std::string> CompilerPluginExecutablePaths;
std::vector<swift::PluginSearchOption> PluginSearchOptions;

/// Path prefixes that should be rewritten in debug info.
PathRemapper DebuggingOptionsPrefixMap;
Expand Down
37 changes: 8 additions & 29 deletions include/swift/Serialization/Validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ struct ValidationInfo {
class ExtendedValidationInfo {
SmallVector<StringRef, 4> ExtraClangImporterOpts;

SmallVector<StringRef, 1> PluginSearchPaths;
SmallVector<StringRef, 1> ExternalPluginSearchPaths;
SmallVector<StringRef, 1> CompilerPluginLibraryPaths;
SmallVector<StringRef, 1> CompilerPluginExecutablePaths;
SmallVector<std::pair<PluginSearchOption::Kind, StringRef>, 2>
PluginSearchOptions;

std::string SDKPath;
StringRef ModuleABIName;
Expand Down Expand Up @@ -149,32 +147,13 @@ class ExtendedValidationInfo {
ExtraClangImporterOpts.push_back(option);
}

ArrayRef<StringRef> getPluginSearchPaths() const {
return PluginSearchPaths;
ArrayRef<std::pair<PluginSearchOption::Kind, StringRef>>
getPluginSearchOptions() const {
return PluginSearchOptions;
}
void addPluginSearchPath(StringRef path) {
PluginSearchPaths.push_back(path);
}

ArrayRef<StringRef> getExternalPluginSearchPaths() const {
return ExternalPluginSearchPaths;
}
void addExternalPluginSearchPath(StringRef path) {
ExternalPluginSearchPaths.push_back(path);
}

ArrayRef<StringRef> getCompilerPluginLibraryPaths() const {
return CompilerPluginLibraryPaths;
}
void addCompilerPluginLibraryPath(StringRef path) {
CompilerPluginLibraryPaths.push_back(path);
}

ArrayRef<StringRef> getCompilerPluginExecutablePaths() const {
return CompilerPluginExecutablePaths;
}
void addCompilerPluginExecutablePath(StringRef path) {
CompilerPluginExecutablePaths.push_back(path);
void addPluginSearchOption(
const std::pair<PluginSearchOption::Kind, StringRef> &opt) {
PluginSearchOptions.push_back(opt);
}

bool isSIB() const { return Bits.IsSIB; }
Expand Down
Loading