2626#include " swift/AST/Type.h"
2727#include " swift/AST/Evaluator.h"
2828#include " swift/AST/Pattern.h"
29+ #include " swift/AST/PluginRegistry.h"
2930#include " swift/AST/ProtocolConformance.h"
3031#include " swift/AST/SimpleRequest.h"
3132#include " swift/AST/SourceFile.h"
@@ -49,8 +50,6 @@ struct ExternalMacroDefinition;
4950class ClosureExpr ;
5051class GenericParamList ;
5152class LabeledStmt ;
52- class LoadedExecutablePlugin ;
53- class LoadedLibraryPlugin ;
5453class MacroDefinition ;
5554class PrecedenceGroupDecl ;
5655class PropertyWrapperInitializerInfo ;
@@ -3999,41 +3998,20 @@ class ExpandSynthesizedMemberMacroRequest
39993998 bool isCached () const { return true ; }
40003999};
40014000
4002- // / Load a plugin module with the given name.
4003- // /
4004- // /
4001+ // / Represent a loaded plugin either an in-process library or an executable.
40054002class LoadedCompilerPlugin {
4006- enum class PluginKind : uint8_t {
4007- None,
4008- InProcess,
4009- Executable,
4010- };
4011- PluginKind kind;
4012- void *ptr;
4013-
4014- LoadedCompilerPlugin (PluginKind kind, void *ptr) : kind(kind), ptr(ptr) {
4015- assert (ptr != nullptr || kind == PluginKind::None);
4016- }
4003+ llvm::PointerUnion<LoadedLibraryPlugin *, LoadedExecutablePlugin *> ptr;
40174004
40184005public:
4019- LoadedCompilerPlugin (std::nullptr_t ) : kind(PluginKind::None), ptr(nullptr ) {}
4020-
4021- static LoadedCompilerPlugin inProcess (LoadedLibraryPlugin *ptr) {
4022- return {PluginKind::InProcess, ptr};
4023- }
4024- static LoadedCompilerPlugin executable (LoadedExecutablePlugin *ptr) {
4025- return {PluginKind::Executable, ptr};
4026- }
4006+ LoadedCompilerPlugin (std::nullptr_t ) : ptr(nullptr ) {}
4007+ LoadedCompilerPlugin (LoadedLibraryPlugin *ptr) : ptr(ptr){};
4008+ LoadedCompilerPlugin (LoadedExecutablePlugin *ptr) : ptr(ptr){};
40274009
4028- LoadedLibraryPlugin *getAsInProcessPlugin () const {
4029- return kind == PluginKind::InProcess
4030- ? static_cast <LoadedLibraryPlugin *>(ptr)
4031- : nullptr ;
4010+ LoadedLibraryPlugin *getAsLibraryPlugin () const {
4011+ return ptr.dyn_cast <LoadedLibraryPlugin *>();
40324012 }
40334013 LoadedExecutablePlugin *getAsExecutablePlugin () const {
4034- return kind == PluginKind::Executable
4035- ? static_cast <LoadedExecutablePlugin *>(ptr)
4036- : nullptr ;
4014+ return ptr.dyn_cast <LoadedExecutablePlugin *>();
40374015 }
40384016};
40394017
0 commit comments