Skip to content

Commit 48db739

Browse files
committed
[Distributed] Record generic substitution types for invocation
1 parent cb27114 commit 48db739

21 files changed

+380
-353
lines changed

include/swift/AST/ASTContext.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,15 @@ class ASTContext final {
679679
FuncDecl *getMakeInvocationEncoderOnDistributedActorSystem(
680680
NominalTypeDecl *actorOrSystem) const;
681681

682+
// Retrieve the declaration of
683+
// DistributedInvocationEncoder.recordGenericSubstitution(_:).
684+
//
685+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
686+
// function decl shall be extracted. This is useful to avoid witness calls
687+
// through the protocol which is looked up when nominal is null.
688+
FuncDecl *getRecordGenericSubstitutionOnDistributedInvocationEncoder(
689+
NominalTypeDecl *nominal) const;
690+
682691
// Retrieve the declaration of DistributedInvocationEncoder.recordArgument(_:).
683692
//
684693
// \param nominal optionally provide a 'NominalTypeDecl' from which the
@@ -1342,6 +1351,12 @@ class ASTContext final {
13421351
/// alternative specified via the -entry-point-function-name frontend flag.
13431352
std::string getEntryPointFunctionName() const;
13441353

1354+
/// Find the type of SerializationRequirement on the passed nominal.
1355+
///
1356+
/// This type exists as a typealias/associatedtype on all distributed actors,
1357+
/// actor systems, and related serialization types.
1358+
Type getDistributedSerializationRequirementType(NominalTypeDecl *);
1359+
13451360
/// Find the concrete invocation decoder associated with the given actor.
13461361
NominalTypeDecl *
13471362
getDistributedActorInvocationDecoder(NominalTypeDecl *);

include/swift/SIL/SILFunction.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,15 @@ class SILFunction
461461
ReplacedFunction->incrementRefCount();
462462
}
463463

464+
SILFunction *getDistributedRecordArgumentFunction() const {
465+
return ReplacedFunction;
466+
}
467+
void setDistributedRecordArgumentFunction(SILFunction *f) {
468+
if (f == nullptr)
469+
return;
470+
f->incrementRefCount();
471+
}
472+
464473
/// This function should only be called when SILFunctions are bulk deleted.
465474
void dropDynamicallyReplacedFunction() {
466475
if (!ReplacedFunction)

lib/AST/ASTContext.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,38 @@ FuncDecl *ASTContext::getMakeInvocationEncoderOnDistributedActorSystem(
13261326
return nullptr;
13271327
}
13281328

1329+
FuncDecl *
1330+
ASTContext::getRecordGenericSubstitutionOnDistributedInvocationEncoder(
1331+
NominalTypeDecl *nominal) const {
1332+
for (auto result : nominal->lookupDirect(Id_recordGenericSubstitution)) {
1333+
auto *fd = dyn_cast<FuncDecl>(result);
1334+
if (!fd)
1335+
continue;
1336+
if (fd->getParameters()->size() != 1)
1337+
continue;
1338+
if (fd->hasAsync())
1339+
continue;
1340+
if (!fd->hasThrows())
1341+
continue;
1342+
// TODO(distributed): more checks
1343+
1344+
auto genericParamList = fd->getGenericParams();
1345+
1346+
// A single generic parameter.
1347+
if (genericParamList->size() != 1)
1348+
continue;
1349+
1350+
// No requirements on the generic parameter
1351+
if (fd->getGenericRequirements().size() != 0)
1352+
continue;
1353+
1354+
if (fd->getResultInterfaceType()->isVoid())
1355+
return fd;
1356+
}
1357+
1358+
return nullptr;
1359+
}
1360+
13291361
FuncDecl *ASTContext::getRecordArgumentOnDistributedInvocationEncoder(
13301362
NominalTypeDecl *nominal) const {
13311363
for (auto result : nominal->lookupDirect(Id_recordArgument)) {

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5528,6 +5528,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
55285528
if (term->isFunctionExiting()) {
55295529
require(state.Stack.empty(),
55305530
"return with stack allocs that haven't been deallocated");
5531+
if (!state.ActiveOps.empty()) {
5532+
for (auto op : state.ActiveOps) {
5533+
op->dump();
5534+
}
5535+
}
55315536
require(state.ActiveOps.empty(),
55325537
"return with operations still active");
55335538
require(!state.GotAsyncContinuation,

0 commit comments

Comments
 (0)