10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " swift/AST/ProtocolConformance.h"
13
14
#include " swift/SILOptimizer/PassManager/Passes.h"
14
15
#include " swift/SILOptimizer/PassManager/Transforms.h"
15
16
#include " swift/SIL/SILModule.h"
@@ -104,6 +105,7 @@ class SILLinker : public SILModuleTransform {
104
105
SILLinkage::HiddenExternal);
105
106
linkUsedFunctionByName (" swift_createDefaultExecutors" ,
106
107
SILLinkage::HiddenExternal);
108
+ linkEmbeddedRuntimeWitnessTable ();
107
109
}
108
110
109
111
void linkEmbeddedRuntimeFunctionByName (StringRef name,
@@ -122,6 +124,27 @@ class SILLinker : public SILModuleTransform {
122
124
linkUsedFunctionByName (name, SILLinkage::PublicExternal);
123
125
}
124
126
127
+ void linkEmbeddedRuntimeWitnessTable () {
128
+ SILModule &M = *getModule ();
129
+
130
+ auto *mainActor = M.getASTContext ().getMainActorDecl ();
131
+ if (mainActor) {
132
+ for (auto *PC : mainActor->getAllConformances ()) {
133
+ auto *ProtoDecl = PC->getProtocol ();
134
+ auto name = ProtoDecl->getName ();
135
+ if (name.str () == " Actor" ) {
136
+ auto &e = llvm::errs ();
137
+ e << " Found MainActor: Actor conformance\n " ;
138
+ if (auto *WT = M.lookUpWitnessTable (PC)) {
139
+ WT = M.getSILLoader ()->lookupWitnessTable (WT);
140
+ e << " Looked up MainActor: Actor witness table\n " ;
141
+ WT->setLinkage (SILLinkage::Public);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+
125
148
SILFunction *linkUsedFunctionByName (StringRef name,
126
149
std::optional<SILLinkage> Linkage) {
127
150
SILModule &M = *getModule ();
@@ -160,7 +183,7 @@ class SILLinker : public SILModuleTransform {
160
183
// linked global variable.
161
184
if (GV->isDefinition ())
162
185
GV->setLinkage (SILLinkage::Public);
163
-
186
+
164
187
return GV;
165
188
}
166
189
0 commit comments