Skip to content

Commit 1909b12

Browse files
committed
[SIL] Distributed: Remove logic related to ad-hoc requirements from SILFunction
Ad-hoc requirements are now obsolete by making `remoteCall`, `record{Argument, ReturnType}`, `decodeNextArgument` protocols requirements and injecting witness tables for `SerializationRequirement` conformances during IRGen.
1 parent 4d4c80b commit 1909b12

File tree

14 files changed

+13
-112
lines changed

14 files changed

+13
-112
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,6 @@ class SILFunction
264264
/// @_dynamicReplacement(for:) function.
265265
SILFunction *ReplacedFunction = nullptr;
266266

267-
/// This SILFunction REFerences an ad-hoc protocol requirement witness in
268-
/// order to keep it alive, such that it main be obtained in IRGen. Without
269-
/// this explicit reference, the witness would seem not-used, and not be
270-
/// accessible for IRGen.
271-
///
272-
/// Specifically, one such case is the DistributedTargetInvocationDecoder's
273-
/// 'decodeNextArgument' which must be retained, as it is only used from IRGen
274-
/// and such, appears as-if unused in SIL and would get optimized away.
275-
// TODO: Consider making this a general "references adhoc functions" and make it an array?
276-
SILFunction *RefAdHocRequirementFunction = nullptr;
277-
278267
Identifier ObjCReplacementFor;
279268

280269
/// The head of a single-linked list of currently alive BasicBlockBitfield.
@@ -596,27 +585,6 @@ class SILFunction
596585
ReplacedFunction = nullptr;
597586
}
598587

599-
SILFunction *getReferencedAdHocRequirementWitnessFunction() const {
600-
return RefAdHocRequirementFunction;
601-
}
602-
// Marks that this `SILFunction` uses the passed in ad-hoc protocol
603-
// requirement witness `f` and therefore must retain it explicitly,
604-
// otherwise we might not be able to get a reference to it.
605-
void setReferencedAdHocRequirementWitnessFunction(SILFunction *f) {
606-
assert(RefAdHocRequirementFunction == nullptr && "already set");
607-
608-
if (f == nullptr)
609-
return;
610-
RefAdHocRequirementFunction = f;
611-
RefAdHocRequirementFunction->incrementRefCount();
612-
}
613-
void dropReferencedAdHocRequirementWitnessFunction() {
614-
if (!RefAdHocRequirementFunction)
615-
return;
616-
RefAdHocRequirementFunction->decrementRefCount();
617-
RefAdHocRequirementFunction = nullptr;
618-
}
619-
620588
bool hasObjCReplacement() const {
621589
return !ObjCReplacementFor.empty();
622590
}

lib/SIL/IR/SILFunction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ void SILFunction::createSnapshot(int id) {
278278
newSnapshot->DeclCtxt = DeclCtxt;
279279
newSnapshot->Profiler = Profiler;
280280
newSnapshot->ReplacedFunction = ReplacedFunction;
281-
newSnapshot->RefAdHocRequirementFunction = RefAdHocRequirementFunction;
282281
newSnapshot->ObjCReplacementFor = ObjCReplacementFor;
283282
newSnapshot->SemanticsAttrSet = SemanticsAttrSet;
284283
newSnapshot->SpecializeAttrSet = SpecializeAttrSet;

lib/SIL/IR/SILFunctionBuilder.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,6 @@ void SILFunctionBuilder::addFunctionAttributes(
274274

275275
F->setDynamicallyReplacedFunction(replacedFunc);
276276
}
277-
} else if (constant.isDistributedThunk()) {
278-
auto decodeFuncDecl =
279-
getAssociatedDistributedInvocationDecoderDecodeNextArgumentFunction(
280-
decl);
281-
assert(decodeFuncDecl && "decodeNextArgument function not found!");
282-
283-
auto decodeRef = SILDeclRef(decodeFuncDecl);
284-
auto *adHocFunc = getOrCreateDeclaration(decodeFuncDecl, decodeRef);
285-
F->setReferencedAdHocRequirementWitnessFunction(adHocFunc);
286277
}
287278
}
288279

lib/SIL/IR/SILModule.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ SILModule::~SILModule() {
154154
for (SILFunction &F : *this) {
155155
F.dropAllReferences();
156156
F.dropDynamicallyReplacedFunction();
157-
F.dropReferencedAdHocRequirementWitnessFunction();
158157
F.clearSpecializeAttrs();
159158
}
160159

@@ -492,7 +491,6 @@ void SILModule::eraseFunction(SILFunction *F) {
492491
// (References are not needed anymore.)
493492
F->clear();
494493
F->dropDynamicallyReplacedFunction();
495-
F->dropReferencedAdHocRequirementWitnessFunction();
496494
// Drop references for any _specialize(target:) functions.
497495
F->clearSpecializeAttrs();
498496
}

lib/SIL/IR/SILPrinter.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,12 +3394,6 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
33943394
OS << "\"] ";
33953395
}
33963396

3397-
if (auto *usedFunc = getReferencedAdHocRequirementWitnessFunction()) {
3398-
OS << "[ref_adhoc_requirement_witness \"";
3399-
OS << usedFunc->getName();
3400-
OS << "\"] ";
3401-
}
3402-
34033397
if (hasObjCReplacement()) {
34043398
OS << "[objc_replacement_for \"";
34053399
OS << getObjCReplacement().str();

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ static bool parseDeclSILOptional(
675675
UseStackForPackMetadata_t *useStackForPackMetadata,
676676
bool *hasUnsafeNonEscapableResult, IsExactSelfClass_t *isExactSelfClass,
677677
SILFunction **dynamicallyReplacedFunction,
678-
SILFunction **usedAdHocRequirementWitness, Identifier *objCReplacementFor,
678+
Identifier *objCReplacementFor,
679679
SILFunction::Purpose *specialPurpose, Inline_t *inlineStrategy,
680680
OptimizationMode *optimizationMode, PerformanceConstraints *perfConstraints,
681681
bool *isPerformanceConstraint,
@@ -825,26 +825,6 @@ static bool parseDeclSILOptional(
825825
*dynamicallyReplacedFunction = Func;
826826
SP.P.consumeToken(tok::string_literal);
827827

828-
SP.P.parseToken(tok::r_square, diag::expected_in_attribute_list);
829-
continue;
830-
} else if (usedAdHocRequirementWitness && SP.P.Tok.getText() == "ref_adhoc_requirement_witness") {
831-
SP.P.consumeToken(tok::identifier);
832-
if (SP.P.Tok.getKind() != tok::string_literal) {
833-
SP.P.diagnose(SP.P.Tok, diag::expected_in_attribute_list);
834-
return true;
835-
}
836-
// Drop the double quotes.
837-
StringRef witnessFunc = SP.P.Tok.getText().drop_front().drop_back();
838-
SILFunction *Func = M.lookUpFunction(witnessFunc.str());
839-
if (!Func) {
840-
Identifier Id = SP.P.Context.getIdentifier(witnessFunc);
841-
SP.P.diagnose(SP.P.Tok, diag::sil_adhoc_requirement_witness_func_not_found,
842-
Id);
843-
return true;
844-
}
845-
*usedAdHocRequirementWitness = Func;
846-
SP.P.consumeToken(tok::string_literal);
847-
848828
SP.P.parseToken(tok::r_square, diag::expected_in_attribute_list);
849829
continue;
850830
} else if (objCReplacementFor &&
@@ -7061,7 +7041,6 @@ bool SILParserState::parseDeclSIL(Parser &P) {
70617041
ValueDecl *ClangDecl = nullptr;
70627042
EffectsKind MRK = EffectsKind::Unspecified;
70637043
SILFunction *DynamicallyReplacedFunction = nullptr;
7064-
SILFunction *AdHocWitnessFunction = nullptr;
70657044
Identifier objCReplacementFor;
70667045
if (parseSILLinkage(FnLinkage, P) ||
70677046
parseDeclSILOptional(
@@ -7070,7 +7049,7 @@ bool SILParserState::parseDeclSIL(Parser &P) {
70707049
&isRuntimeAccessible, &forceEnableLexicalLifetimes,
70717050
&useStackForPackMetadata, &hasUnsafeNonEscapableResult,
70727051
&isExactSelfClass, &DynamicallyReplacedFunction,
7073-
&AdHocWitnessFunction, &objCReplacementFor, &specialPurpose,
7052+
&objCReplacementFor, &specialPurpose,
70747053
&inlineStrategy, &optimizationMode, &perfConstr,
70757054
&isPerformanceConstraint, &markedAsUsed,
70767055
&section, nullptr, &isWeakImported, &needStackProtection,
@@ -7116,8 +7095,6 @@ bool SILParserState::parseDeclSIL(Parser &P) {
71167095
FunctionState.F->setIsExactSelfClass(isExactSelfClass);
71177096
FunctionState.F->setDynamicallyReplacedFunction(
71187097
DynamicallyReplacedFunction);
7119-
FunctionState.F->setReferencedAdHocRequirementWitnessFunction(
7120-
AdHocWitnessFunction);
71217098
if (!objCReplacementFor.empty())
71227099
FunctionState.F->setObjCReplacement(objCReplacementFor);
71237100
FunctionState.F->setSpecialPurpose(specialPurpose);
@@ -7327,7 +7304,7 @@ bool SILParserState::parseSILGlobal(Parser &P) {
73277304
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
73287305
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
73297306
nullptr,
7330-
nullptr, nullptr, nullptr, nullptr, nullptr, &isLet,
7307+
nullptr, nullptr, nullptr, nullptr, &isLet,
73317308
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
73327309
nullptr, nullptr, State, M) ||
73337310
P.parseToken(tok::at_sign, diag::expected_sil_value_name) ||
@@ -7381,7 +7358,7 @@ bool SILParserState::parseSILProperty(Parser &P) {
73817358
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
73827359
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
73837360
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7384-
nullptr, nullptr, nullptr, SP, M))
7361+
nullptr, nullptr, SP, M))
73857362
return true;
73867363

73877364
ValueDecl *VD;
@@ -7451,7 +7428,7 @@ bool SILParserState::parseSILVTable(Parser &P) {
74517428
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
74527429
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
74537430
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7454-
nullptr, nullptr, nullptr, VTableState, M))
7431+
nullptr, nullptr, VTableState, M))
74557432
return true;
74567433

74577434
// Parse the class name.
@@ -7562,7 +7539,7 @@ bool SILParserState::parseSILMoveOnlyDeinit(Parser &parser) {
75627539
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
75637540
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
75647541
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7565-
nullptr, nullptr, nullptr, moveOnlyDeinitTableState, M))
7542+
nullptr, nullptr, moveOnlyDeinitTableState, M))
75667543
return true;
75677544

75687545
// Parse the class name.
@@ -8049,7 +8026,7 @@ bool SILParserState::parseSILWitnessTable(Parser &P) {
80498026
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
80508027
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
80518028
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
8052-
nullptr, nullptr, nullptr, WitnessState, M))
8029+
nullptr, nullptr, WitnessState, M))
80538030
return true;
80548031

80558032
// Parse the protocol conformance.

lib/SILOptimizer/Analysis/CallerAnalysis.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ CallerAnalysis::FunctionInfo::FunctionInfo(SILFunction *f)
3535
// final/visibility/etc.
3636
mayHaveIndirectCallers(
3737
f->getDynamicallyReplacedFunction() ||
38-
f->getReferencedAdHocRequirementWitnessFunction() ||
3938
canBeCalledIndirectly(f->getRepresentation())),
4039
mayHaveExternalCallers(f->isPossiblyUsedExternally() ||
4140
f->isAvailableExternally()) {}

lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ bool FunctionSignatureTransform::run(bool hasCaller) {
668668
hasCaller |= FSOOptimizeIfNotCalled;
669669

670670
if (!hasCaller && (F->getDynamicallyReplacedFunction() ||
671-
F->getReferencedAdHocRequirementWitnessFunction() ||
672671
canBeCalledIndirectly(F->getRepresentation()))) {
673672
LLVM_DEBUG(llvm::dbgs() << " function has no caller -> abort\n");
674673
return false;

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ class DeadFunctionAndGlobalElimination {
110110
if (F->isDynamicallyReplaceable())
111111
return true;
112112

113-
if (F->getReferencedAdHocRequirementWitnessFunction())
114-
return true;
115-
116113
// Don't remove pre-specialized functions. We need to preserver the
117114
// pre-specialization specifications from other modules.
118115
if (F->hasPrespecialization())
@@ -343,9 +340,6 @@ class DeadFunctionAndGlobalElimination {
343340
if (auto *replacedFn = F->getDynamicallyReplacedFunction())
344341
ensureAlive(replacedFn);
345342

346-
if (auto *adHocWitness = F->getReferencedAdHocRequirementWitnessFunction())
347-
ensureAlive(adHocWitness);
348-
349343
// First scan all instructions of the function.
350344
for (SILBasicBlock &BB : *F) {
351345
for (SILInstruction &I : BB) {

lib/Serialization/DeserializeSIL.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
538538
ModuleID parentModuleID;
539539
TypeID funcTyID;
540540
IdentifierID replacedFunctionID;
541-
IdentifierID usedAdHocWitnessFunctionID;
542541
GenericSignatureID genericSigID;
543542
unsigned rawLinkage, isTransparent, isSerialized, isThunk,
544543
isWithoutActuallyEscapingThunk, specialPurpose, inlineStrategy,
@@ -554,7 +553,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
554553
numAttrs, hasQualifiedOwnership, isWeakImported,
555554
LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass,
556555
isDistributed, isRuntimeAccessible, forceEnableLexicalLifetimes, funcTyID,
557-
replacedFunctionID, usedAdHocWitnessFunctionID, genericSigID,
556+
replacedFunctionID, genericSigID,
558557
clangNodeOwnerID, parentModuleID, SemanticsIDs);
559558

560559
if (funcTyID == 0)
@@ -583,13 +582,6 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
583582
replacedObjectiveCFunc = MF->getIdentifier(replacedFunctionID);
584583
}
585584

586-
SILFunction *usedAdHocWitnessFunction = nullptr;
587-
if (usedAdHocWitnessFunctionID) {
588-
auto usedAdHocWitnessFunctionStr =
589-
MF->getIdentifier(usedAdHocWitnessFunctionID).str();
590-
usedAdHocWitnessFunction = getFuncForReference(usedAdHocWitnessFunctionStr);
591-
}
592-
593585
auto linkageOpt = fromStableSILLinkage(rawLinkage);
594586
if (!linkageOpt) {
595587
LLVM_DEBUG(llvm::dbgs() << "invalid linkage code " << rawLinkage
@@ -708,8 +700,6 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
708700
fn->setDynamicallyReplacedFunction(replacedFunction);
709701
if (!replacedObjectiveCFunc.empty())
710702
fn->setObjCReplacement(replacedObjectiveCFunc);
711-
if (usedAdHocWitnessFunction)
712-
fn->setReferencedAdHocRequirementWitnessFunction(usedAdHocWitnessFunction);
713703
if (clangNodeOwner)
714704
fn->setClangNodeOwner(clangNodeOwner);
715705
for (auto ID : SemanticsIDs) {
@@ -3385,7 +3375,6 @@ bool SILDeserializer::hasSILFunction(StringRef Name,
33853375
ModuleID parentModuleID;
33863376
TypeID funcTyID;
33873377
IdentifierID replacedFunctionID;
3388-
IdentifierID usedAdHocWitnessFunctionID;
33893378
GenericSignatureID genericSigID;
33903379
unsigned rawLinkage, isTransparent, isSerialized, isThunk,
33913380
isWithoutActuallyEscapingThunk, isGlobal, inlineStrategy,
@@ -3401,7 +3390,7 @@ bool SILDeserializer::hasSILFunction(StringRef Name,
34013390
numSpecAttrs, hasQualifiedOwnership, isWeakImported,
34023391
LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass,
34033392
isDistributed, isRuntimeAccessible, forceEnableLexicalLifetimes, funcTyID,
3404-
replacedFunctionID, usedAdHocWitnessFunctionID, genericSigID,
3393+
replacedFunctionID, genericSigID,
34053394
clangOwnerID, parentModuleID, SemanticsIDs);
34063395
auto linkage = fromStableSILLinkage(rawLinkage);
34073396
if (!linkage) {

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 850; // MarkDependenceKind
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 851; // Drop ad-hoc requirement refs from SILFunctionLayout
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

lib/Serialization/SILFormat.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ namespace sil_block {
312312
BCFixed<1>, // are lexical lifetimes force-enabled
313313
TypeIDField, // SILFunctionType
314314
DeclIDField, // SILFunction name or 0 (replaced function)
315-
DeclIDField, // SILFunction name or 0 (used ad-hoc requirement witness function)
316315
GenericSignatureIDField,
317316
DeclIDField, // ClangNode owner
318317
ModuleIDField, // Parent ModuleDecl *

lib/Serialization/SerializeSIL.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,6 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
483483
S.addUniquedStringRef(F.getObjCReplacement().str());
484484
}
485485

486-
IdentifierID usedAdHocWitnessFunctionID = 0;
487-
if (auto *fun = F.getReferencedAdHocRequirementWitnessFunction()) {
488-
addReferencedSILFunction(fun, true);
489-
usedAdHocWitnessFunctionID = S.addUniquedStringRef(fun->getName());
490-
}
491-
492486
unsigned numAttrs = NoBody ? 0 : F.getSpecializeAttrs().size();
493487

494488
auto resilience = F.getModule().getSwiftModule()->getResilienceStrategy();
@@ -522,7 +516,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
522516
(unsigned)F.isExactSelfClass(), (unsigned)F.isDistributed(),
523517
(unsigned)F.isRuntimeAccessible(),
524518
(unsigned)F.forceEnableLexicalLifetimes(), FnID, replacedFunctionID,
525-
usedAdHocWitnessFunctionID, genericSigID, clangNodeOwnerID,
519+
genericSigID, clangNodeOwnerID,
526520
parentModuleID, SemanticsIDs);
527521

528522
F.visitArgEffects(

test/Distributed/SIL/distributed_thunk.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ distributed actor DA {
99
}
1010

1111
extension DA {
12-
// CHECK-LABEL: sil hidden [thunk] [distributed] [ref_adhoc_requirement_witness "$s11Distributed29LocalTestingInvocationDecoderC18decodeNextArgumentxyKSeRzSERzlF"] [ossa] @$s17distributed_thunk2DAC1fyyYaKFTE : $@convention(method) @async (@guaranteed DA) -> @error any Error {
12+
// CHECK-LABEL: sil hidden [thunk] [distributed] [ossa] @$s17distributed_thunk2DAC1fyyYaKFTE : $@convention(method) @async (@guaranteed DA) -> @error any Error {
1313
// CHECK: function_ref @swift_distributed_actor_is_remote
1414

1515
// Call the actor function
@@ -65,7 +65,7 @@ protocol Server2: DistributedActor {
6565
}
6666

6767
extension Server2 where ActorSystem == LocalTestingDistributedActorSystem {
68-
// CHECK-LABEL: sil hidden [thunk] [distributed] [ref_adhoc_requirement_witness "$s11Distributed29LocalTestingInvocationDecoderC18decodeNextArgumentxyKSeRzSERzlF"] [ossa] @$s17distributed_thunk7Server2PAA11Distributed012LocalTestingD11ActorSystemC0gH0RtzrlE8sayHelloyyYaKFTE
68+
// CHECK-LABEL: sil hidden [thunk] [distributed] [ossa] @$s17distributed_thunk7Server2PAA11Distributed012LocalTestingD11ActorSystemC0gH0RtzrlE8sayHelloyyYaKFTE
6969
// CHECK-NOT: return
7070
// CHECK: function_ref @swift_distributed_actor_is_remote
7171
distributed func sayHello() { /* default impl */ }

0 commit comments

Comments
 (0)