Skip to content

Commit 7291732

Browse files
committed
Add linkWitnessTable to SILModule, use in Link.cpp
1 parent a7e958e commit 7291732

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

include/swift/SIL/SILModule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,11 @@ class SILModule {
867867
/// Returns true if linking succeeded, false otherwise.
868868
bool linkFunction(SILFunction *F, LinkingMode LinkMode);
869869

870+
/// Attempt to deserialize witness table for protocol conformance \p PC.
871+
///
872+
/// Returns true if linking succeeded, false otherwise.
873+
bool linkWitnessTable(ProtocolConformance *PC, LinkingMode LinkMode);
874+
870875
/// Check if a given function exists in any of the modules.
871876
/// i.e. it can be linked by linkFunction.
872877
bool hasFunction(StringRef Name);

lib/SIL/IR/SILModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ bool SILModule::linkFunction(SILFunction *F, SILModule::LinkingMode Mode) {
433433
return SILLinkerVisitor(*this, Mode).processFunction(F);
434434
}
435435

436+
bool SILModule::linkWitnessTable(ProtocolConformance *PC, SILModule::LinkingMode Mode) {
437+
return SILLinkerVisitor(*this, Mode).processConformance(ProtocolConformanceRef(PC));
438+
}
439+
436440
bool SILModule::hasFunction(StringRef Name) {
437441
if (lookUpFunction(Name))
438442
return true;

lib/SILOptimizer/UtilityPasses/Link.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class SILLinker : public SILModuleTransform {
105105
SILLinkage::HiddenExternal);
106106
linkUsedFunctionByName("swift_createDefaultExecutors",
107107
SILLinkage::HiddenExternal);
108-
linkEmbeddedRuntimeWitnessTable();
108+
linkEmbeddedRuntimeWitnessTables();
109109
}
110110

111111
void linkEmbeddedRuntimeFunctionByName(StringRef name,
@@ -124,20 +124,16 @@ class SILLinker : public SILModuleTransform {
124124
linkUsedFunctionByName(name, SILLinkage::PublicExternal);
125125
}
126126

127-
void linkEmbeddedRuntimeWitnessTable() {
127+
void linkEmbeddedRuntimeWitnessTables() {
128128
SILModule &M = *getModule();
129129

130130
auto *mainActor = M.getASTContext().getMainActorDecl();
131131
if (mainActor) {
132132
for (auto *PC : mainActor->getAllConformances()) {
133133
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";
134+
if (ProtoDecl->getName().str() == "Actor") {
135+
M.linkWitnessTable(PC, SILModule::LinkingMode::LinkAll);
138136
if (auto *WT = M.lookUpWitnessTable(PC)) {
139-
WT = M.getSILLoader()->lookupWitnessTable(WT);
140-
e << "Looked up MainActor: Actor witness table\n";
141137
WT->setLinkage(SILLinkage::Public);
142138
}
143139
}

0 commit comments

Comments
 (0)