Skip to content

Commit b02f9c7

Browse files
committed
[Distributed] ad-hoc req for decodeNextArgument & onReturns
fixup
1 parent 1caa0b1 commit b02f9c7

15 files changed

+436
-76
lines changed

include/swift/AST/ASTContext.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,22 +688,32 @@ class ASTContext final {
688688
FuncDecl *getRecordGenericSubstitutionOnDistributedInvocationEncoder(
689689
NominalTypeDecl *nominal) const;
690690

691-
// Retrieve the declaration of DistributedInvocationEncoder.recordArgument(_:).
691+
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordArgument(_:).
692692
//
693693
// \param nominal optionally provide a 'NominalTypeDecl' from which the
694694
// function decl shall be extracted. This is useful to avoid witness calls
695695
// through the protocol which is looked up when nominal is null.
696696
AbstractFunctionDecl *getRecordArgumentOnDistributedInvocationEncoder(
697697
NominalTypeDecl *nominal) const;
698698

699-
// Retrieve the declaration of DistributedInvocationEncoder.recordReturnType(_:).
699+
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordReturnType(_:).
700700
AbstractFunctionDecl *getRecordReturnTypeOnDistributedInvocationEncoder(
701701
NominalTypeDecl *nominal) const;
702702

703-
// Retrieve the declaration of DistributedInvocationEncoder.recordErrorType(_:).
703+
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordErrorType(_:).
704704
AbstractFunctionDecl *getRecordErrorTypeOnDistributedInvocationEncoder(
705705
NominalTypeDecl *nominal) const;
706706

707+
// Retrieve the declaration of
708+
// DistributedTargetInvocationDecoder.getDecodeNextArgumentOnDistributedInvocationDecoder(_:).
709+
AbstractFunctionDecl *getDecodeNextArgumentOnDistributedInvocationDecoder(
710+
NominalTypeDecl *nominal) const;
711+
712+
// Retrieve the declaration of
713+
// getOnReturnOnDistributedTargetInvocationResultHandler.onReturn(_:).
714+
AbstractFunctionDecl *getOnReturnOnDistributedTargetInvocationResultHandler(
715+
NominalTypeDecl *nominal) const;
716+
707717
// Retrieve the declaration of DistributedInvocationEncoder.doneRecording().
708718
//
709719
// \param nominal optionally provide a 'NominalTypeDecl' from which the

include/swift/AST/Decl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6437,6 +6437,16 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64376437
/// 'DistributedTargetInvocationEncoder' protocol.
64386438
bool isDistributedTargetInvocationEncoderRecordErrorType() const;
64396439

6440+
/// Determines if this function is a 'decodeNextArgument' function,
6441+
/// which is used as ad-hoc protocol requirement by the
6442+
/// 'DistributedTargetInvocationDecoder' protocol.
6443+
bool isDistributedTargetInvocationDecoderDecodeNextArgument() const;
6444+
6445+
/// Determines if this function is a 'onReturn' function,
6446+
/// which is used as ad-hoc protocol requirement by the
6447+
/// 'DistributedTargetInvocationResultHandler' protocol.
6448+
bool isDistributedTargetInvocationResultHandlerOnReturn() const;
6449+
64406450
/// For a method of a class, checks whether it will require a new entry in the
64416451
/// vtable.
64426452
bool needsNewVTableEntry() const;

include/swift/AST/DistributedDecl.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ bool checkDistributedSerializationRequirementIsExactlyCodable(
8080
/// Get the `SerializationRequirement`, explode it into the specific
8181
/// protocol requirements and insert them into `requirements`.
8282
///
83+
/// The passed `protocol` must be conformed to by the `decl`, e.g. a specific
84+
/// actor system implementation and the `DistributedActorSystem` protocol,
85+
/// or any of the specific encoder/decoder and the respective
86+
/// Distributed...Encoder/Decoder protocol etc.
87+
///
8388
/// Returns false if failed to get the protocol decls.
8489
bool
85-
getDistributedActorSystemSerializationRequirements(
86-
NominalTypeDecl *systemDecl,
90+
getDistributedSerializationRequirements(
91+
NominalTypeDecl *decl,
8792
ProtocolDecl *protocol,
8893
llvm::SmallPtrSetImpl<ProtocolDecl *> &requirementProtos);
8994

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ IDENTIFIER(invocation)
276276
IDENTIFIER(invocationDecoder)
277277
IDENTIFIER(makeInvocationEncoder)
278278
IDENTIFIER(on)
279+
IDENTIFIER(onReturn)
279280
IDENTIFIER(recordArgument)
280281
IDENTIFIER(recordErrorType)
281282
IDENTIFIER(recordGenericSubstitution)

include/swift/AST/TypeCheckRequests.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,42 @@ class GetDistributedTargetInvocationEncoderRecordErrorTypeFunctionRequest :
11091109
bool isCached() const { return true; }
11101110
};
11111111

1112+
/// Obtain the 'decodeNextArgument' function of a 'DistributedTargetInvocationDecoder'.
1113+
class GetDistributedTargetInvocationDecoderDecodeNextArgumentFunctionRequest :
1114+
public SimpleRequest<GetDistributedTargetInvocationDecoderDecodeNextArgumentFunctionRequest,
1115+
AbstractFunctionDecl *(NominalTypeDecl *),
1116+
RequestFlags::Cached> {
1117+
public:
1118+
using SimpleRequest::SimpleRequest;
1119+
1120+
private:
1121+
friend SimpleRequest;
1122+
1123+
AbstractFunctionDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *encoder) const;
1124+
1125+
public:
1126+
// Caching
1127+
bool isCached() const { return true; }
1128+
};
1129+
1130+
/// Obtain the 'onReturn' function of a 'DistributedTargetInvocationResultHandler'.
1131+
class GetDistributedTargetInvocationResultHandlerOnReturnFunctionRequest :
1132+
public SimpleRequest<GetDistributedTargetInvocationResultHandlerOnReturnFunctionRequest,
1133+
AbstractFunctionDecl *(NominalTypeDecl *),
1134+
RequestFlags::Cached> {
1135+
public:
1136+
using SimpleRequest::SimpleRequest;
1137+
1138+
private:
1139+
friend SimpleRequest;
1140+
1141+
AbstractFunctionDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *encoder) const;
1142+
1143+
public:
1144+
// Caching
1145+
bool isCached() const { return true; }
1146+
};
1147+
11121148
/// Obtain the 'actorSystem' property of a 'distributed actor'.
11131149
class GetDistributedActorSystemPropertyRequest :
11141150
public SimpleRequest<GetDistributedActorSystemPropertyRequest,

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ SWIFT_REQUEST(TypeChecker, GetDistributedTargetInvocationEncoderRecordReturnType
117117
SWIFT_REQUEST(TypeChecker, GetDistributedTargetInvocationEncoderRecordErrorTypeFunctionRequest,
118118
AbstractFunctionDecl *(NominalTypeDecl *),
119119
Cached, NoLocationInfo)
120+
SWIFT_REQUEST(TypeChecker, GetDistributedTargetInvocationDecoderDecodeNextArgumentFunctionRequest,
121+
AbstractFunctionDecl *(NominalTypeDecl *),
122+
Cached, NoLocationInfo)
123+
SWIFT_REQUEST(TypeChecker, GetDistributedTargetInvocationResultHandlerOnReturnFunctionRequest,
124+
AbstractFunctionDecl *(NominalTypeDecl *),
125+
Cached, NoLocationInfo)
120126
SWIFT_REQUEST(TypeChecker, GetDistributedActorIDPropertyRequest,
121127
VarDecl *(NominalTypeDecl *),
122128
Cached, NoLocationInfo)

lib/AST/ASTContext.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,22 @@ AbstractFunctionDecl *ASTContext::getRecordErrorTypeOnDistributedInvocationEncod
13821382
nullptr);
13831383
}
13841384

1385+
AbstractFunctionDecl *ASTContext::getDecodeNextArgumentOnDistributedInvocationDecoder(
1386+
NominalTypeDecl *nominal) const {
1387+
return evaluateOrDefault(
1388+
nominal->getASTContext().evaluator,
1389+
GetDistributedTargetInvocationDecoderDecodeNextArgumentFunctionRequest{nominal},
1390+
nullptr);
1391+
}
1392+
1393+
AbstractFunctionDecl *ASTContext::getOnReturnOnDistributedTargetInvocationResultHandler(
1394+
NominalTypeDecl *nominal) const {
1395+
return evaluateOrDefault(
1396+
nominal->getASTContext().evaluator,
1397+
GetDistributedTargetInvocationResultHandlerOnReturnFunctionRequest{nominal},
1398+
nullptr);
1399+
}
1400+
13851401
FuncDecl *ASTContext::getDoneRecordingOnDistributedInvocationEncoder(
13861402
NominalTypeDecl *nominal) const {
13871403
for (auto result : nominal->lookupDirect(Id_doneRecording)) {

0 commit comments

Comments
 (0)