Skip to content

Commit a7e958e

Browse files
committed
Link.cpp: load MainActor: Actor WT for Embedded Swift
1 parent b554839 commit a7e958e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lib/SILOptimizer/UtilityPasses/Link.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/AST/ProtocolConformance.h"
1314
#include "swift/SILOptimizer/PassManager/Passes.h"
1415
#include "swift/SILOptimizer/PassManager/Transforms.h"
1516
#include "swift/SIL/SILModule.h"
@@ -104,6 +105,7 @@ class SILLinker : public SILModuleTransform {
104105
SILLinkage::HiddenExternal);
105106
linkUsedFunctionByName("swift_createDefaultExecutors",
106107
SILLinkage::HiddenExternal);
108+
linkEmbeddedRuntimeWitnessTable();
107109
}
108110

109111
void linkEmbeddedRuntimeFunctionByName(StringRef name,
@@ -122,6 +124,27 @@ class SILLinker : public SILModuleTransform {
122124
linkUsedFunctionByName(name, SILLinkage::PublicExternal);
123125
}
124126

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+
125148
SILFunction *linkUsedFunctionByName(StringRef name,
126149
std::optional<SILLinkage> Linkage) {
127150
SILModule &M = *getModule();
@@ -160,7 +183,7 @@ class SILLinker : public SILModuleTransform {
160183
// linked global variable.
161184
if (GV->isDefinition())
162185
GV->setLinkage(SILLinkage::Public);
163-
186+
164187
return GV;
165188
}
166189

0 commit comments

Comments
 (0)