Skip to content

Commit 2e16273

Browse files
committed
[Distributed] Adhoc witness methods must work with non final class
1 parent ea225d5 commit 2e16273

15 files changed

+593
-256
lines changed

include/swift/AST/Decl.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5557,6 +5557,19 @@ class ProtocolDecl final : public NominalTypeDecl {
55575557
EffectKind kind) const;
55585558
bool hasPolymorphicEffect(EffectKind kind) const;
55595559

5560+
/// Returns `true` if this protocol contains requirements which have known
5561+
/// 'ad-hoc' requirements. For example, the protocol contains an associated
5562+
/// type which is used to constrain generic types of some of its members.
5563+
///
5564+
/// Currently the only instance of such requirement is
5565+
/// 'SerializationRequirement' in the 'Distributed' module's protocols.
5566+
bool hasMembersWithAdHocRequirements() const {
5567+
return isSpecificProtocol(KnownProtocolKind::DistributedActorSystem) ||
5568+
isSpecificProtocol(KnownProtocolKind::DistributedTargetInvocationEncoder) ||
5569+
isSpecificProtocol(KnownProtocolKind::DistributedTargetInvocationDecoder) ||
5570+
isSpecificProtocol(KnownProtocolKind::DistributedTargetInvocationResultHandler);
5571+
}
5572+
55605573
/// Determine whether this is a "marker" protocol, meaning that is indicates
55615574
/// semantics but has no corresponding witness table.
55625575
bool isMarkerProtocol() const;
@@ -7960,7 +7973,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
79607973
/// Determines whether this function is a 'remoteCall' function,
79617974
/// which is used as ad-hoc protocol requirement by the
79627975
/// 'DistributedActorSystem' protocol.
7963-
bool isDistributedActorSystemRemoteCall(bool isVoidReturn) const;
7976+
bool isDistributedActorSystemRemoteCall(bool isVoidReturn, bool allowRequirement) const;
79647977

79657978
/// Determines whether this function is a 'makeInvocationEncoder' function,
79667979
/// which is used as ad-hoc protocol requirement by the
@@ -7970,42 +7983,42 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
79707983
/// Determines if this function is a 'recordGenericSubstitution' function,
79717984
/// which is used as ad-hoc protocol requirement by the
79727985
/// 'DistributedTargetInvocationEncoder' protocol.
7973-
bool isDistributedTargetInvocationEncoderRecordGenericSubstitution() const;
7986+
bool isDistributedTargetInvocationEncoderRecordGenericSubstitution(bool allowRequirement) const;
79747987

79757988
/// Determines if this function is a 'recordArgument' function,
79767989
/// which is used as ad-hoc protocol requirement by the
79777990
/// 'DistributedTargetInvocationEncoder' protocol.
7978-
bool isDistributedTargetInvocationEncoderRecordArgument() const;
7991+
bool isDistributedTargetInvocationEncoderRecordArgument(bool allowRequirement) const;
79797992

79807993
/// Determines if this function is a 'recordReturnType' function,
79817994
/// which is used as ad-hoc protocol requirement by the
79827995
/// 'DistributedTargetInvocationEncoder' protocol.
7983-
bool isDistributedTargetInvocationEncoderRecordReturnType() const;
7996+
bool isDistributedTargetInvocationEncoderRecordReturnType(bool allowRequirement) const;
79847997

79857998
/// Determines if this function is a 'recordErrorType' function,
79867999
/// which is used as ad-hoc protocol requirement by the
79878000
/// 'DistributedTargetInvocationEncoder' protocol.
7988-
bool isDistributedTargetInvocationEncoderRecordErrorType() const;
8001+
bool isDistributedTargetInvocationEncoderRecordErrorType(bool allowRequirement) const;
79898002

79908003
/// Determines if this function is a 'decodeNextArgument' function,
79918004
/// which is used as ad-hoc protocol requirement by the
79928005
/// 'DistributedTargetInvocationDecoder' protocol.
7993-
bool isDistributedTargetInvocationDecoderDecodeNextArgument() const;
8006+
bool isDistributedTargetInvocationDecoderDecodeNextArgument(bool allowRequirement) const;
79948007

79958008
/// Determines if this function is a 'onReturn' function,
79968009
/// which is used as ad-hoc protocol requirement by the
79978010
/// 'DistributedTargetInvocationResultHandler' protocol.
7998-
bool isDistributedTargetInvocationResultHandlerOnReturn() const;
8011+
bool isDistributedTargetInvocationResultHandlerOnReturn(bool allowRequirement) const;
79998012

80008013
/// Determines whether this declaration is a witness to a
80018014
/// protocol requirement with ad-hoc `SerializationRequirement`
80028015
/// conformance.
8003-
bool isDistributedWitnessWithAdHocSerializationRequirement() const {
8004-
return isDistributedActorSystemRemoteCall(/*isVoidResult=*/false) ||
8005-
isDistributedTargetInvocationEncoderRecordArgument() ||
8006-
isDistributedTargetInvocationEncoderRecordReturnType() ||
8007-
isDistributedTargetInvocationDecoderDecodeNextArgument() ||
8008-
isDistributedTargetInvocationResultHandlerOnReturn();
8016+
bool isDistributedWitnessWithAdHocSerializationRequirement(bool allowRequirement) const {
8017+
return isDistributedActorSystemRemoteCall(/*isVoidResult=*/false, allowRequirement) ||
8018+
isDistributedTargetInvocationEncoderRecordArgument(allowRequirement) ||
8019+
isDistributedTargetInvocationEncoderRecordReturnType(allowRequirement) ||
8020+
isDistributedTargetInvocationDecoderDecodeNextArgument(allowRequirement) ||
8021+
isDistributedTargetInvocationResultHandlerOnReturn(allowRequirement);
80098022
}
80108023

80118024
/// For a method of a class, checks whether it will require a new entry in the

include/swift/AST/DistributedDecl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ getDistributedSerializationRequirements(
148148
ProtocolDecl *protocol,
149149
llvm::SmallPtrSetImpl<ProtocolDecl *> &requirementProtos);
150150

151+
void injectAdHocDistributedSerializationRequirementForWitnessThunk(
152+
const ValueDecl *requirementDecl, const FuncDecl *witnessDecl,
153+
SmallVectorImpl<Requirement> &Requirements);
154+
151155
/// Retrieve the declaration of DistributedActorSystem.remoteCall(Void)(...).
152156
///
153157
/// \param actorOrSystem distributed actor or actor system to get the

include/swift/AST/RequirementEnvironment.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ class RequirementEnvironment {
103103
ClassDecl *covariantSelf,
104104
RootProtocolConformance *conformance);
105105

106+
RequirementEnvironment(DeclContext *conformanceDC,
107+
ValueDecl *reqDecl,
108+
GenericSignature reqSig,
109+
ProtocolDecl *proto,
110+
ClassDecl *covariantSelf,
111+
RootProtocolConformance *conformance);
112+
106113
/// Retrieve the generic signature of the requirement.
107114
GenericSignature getRequirementSignature() const {
108115
return reqSig;

include/swift/AST/Witness.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class Witness {
180180

181181
/// Retrieve the witness thunk generic signature.
182182
GenericSignature getWitnessThunkSignature() const {
183+
// TODO: find what creates/sets that
183184
if (auto *storedWitness = storage.dyn_cast<StoredWitness *>())
184185
return storedWitness->witnessThunkSig;
185186
return nullptr;

0 commit comments

Comments
 (0)