Skip to content

Commit c7e3af8

Browse files
committed
[Distributed] Handle composite types in SerializationRequirement
1 parent 12932c7 commit c7e3af8

File tree

7 files changed

+541
-169
lines changed

7 files changed

+541
-169
lines changed

include/swift/AST/DistributedDecl.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ class DeclContext;
3131
class FuncDecl;
3232
class NominalTypeDecl;
3333

34-
/// Determine the distributed actor transport type for the given actor.
34+
/// Determine the `ActorSystem` type for the given actor.
3535
Type getDistributedActorSystemType(NominalTypeDecl *actor);
3636

37-
/// Determine the distributed actor identity type for the given actor.
37+
/// Determine the `ID` type for the given actor.
3838
Type getDistributedActorIDType(NominalTypeDecl *actor);
3939

4040
Type getDistributedActorSystemSerializationRequirementType(
4141
NominalTypeDecl *system);
4242

43+
Type getDistributedActorSystemActorIDRequirementType(
44+
NominalTypeDecl *system);
45+
4346
/// Determine the serialization requirement for the given actor, actor system
4447
/// or other type that has the SerializationRequirement associated type.
45-
Type getDistributedSerializationRequirementType(NominalTypeDecl *nominal);
48+
Type getDistributedSerializationRequirementType(NominalTypeDecl *actor);
4649

4750
/// Get the specific protocols that the `SerializationRequirement` specifies,
4851
/// and all parameters / return types of distributed targets must conform to.
@@ -54,17 +57,29 @@ Type getDistributedSerializationRequirementType(NominalTypeDecl *nominal);
5457
llvm::SmallPtrSet<ProtocolDecl *, 2>
5558
getDistributedSerializationRequirementProtocols(NominalTypeDecl *decl);
5659

60+
/// Desugar and flatten the `SerializationRequirement` type into a set of
61+
/// specific protocol declarations.
5762
llvm::SmallPtrSet<ProtocolDecl *, 2>
5863
flattenDistributedSerializationTypeToRequiredProtocols(
5964
TypeBase *serializationRequirement);
6065

6166
/// Check if the `allRequirements` represent *exactly* the
6267
/// `Encodable & Decodable` (also known as `Codable`) requirement.
68+
///
6369
/// If so, we can emit slightly nicer diagnostics.
6470
bool checkDistributedSerializationRequirementIsExactlyCodable(
6571
ASTContext &C,
6672
const llvm::SmallPtrSetImpl<ProtocolDecl *> &allRequirements);
6773

74+
/// Get the `SerializationRequirement`, explode it into the specific
75+
/// protocol requirements and insert them into `requirements`.
76+
///
77+
/// Returns false if failed to get the protocol decls.
78+
bool
79+
getDistributedActorSystemSerializationRequirements(
80+
NominalTypeDecl *systemDecl,
81+
llvm::SmallPtrSetImpl<ProtocolDecl *> &requirementProtos);
82+
6883
/// Given any set of generic requirements, locate those which are about the
6984
/// `SerializationRequirement`. Those need to be applied in the parameter and
7085
/// return type checking of distributed targets.

include/swift/AST/TypeCheckRequests.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,25 @@ class GetDistributedActorSystemPropertyRequest :
10731073
bool isCached() const { return true; }
10741074
};
10751075

1076+
/// Obtain the constructor of the RemoteCallTarget type.
1077+
class GetDistributedRemoteCallTargetInitFunctionRequest :
1078+
public SimpleRequest<GetDistributedRemoteCallTargetInitFunctionRequest,
1079+
ConstructorDecl *(NominalTypeDecl *),
1080+
RequestFlags::Cached> {
1081+
public:
1082+
using SimpleRequest::SimpleRequest;
1083+
1084+
private:
1085+
friend SimpleRequest;
1086+
1087+
ConstructorDecl *evaluate(Evaluator &evaluator,
1088+
NominalTypeDecl *nominal) const;
1089+
1090+
public:
1091+
// Caching
1092+
bool isCached() const { return true; }
1093+
};
1094+
10761095
/// Obtain the 'id' property of a 'distributed actor'.
10771096
class GetDistributedActorIDPropertyRequest :
10781097
public SimpleRequest<GetDistributedActorIDPropertyRequest,

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,14 @@ SWIFT_REQUEST(TypeChecker, IsDistributedActorRequest, bool(NominalTypeDecl *),
108108
SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemRemoteCallFunctionRequest,
109109
AbstractFunctionDecl *(NominalTypeDecl *, bool),
110110
Cached, NoLocationInfo)
111-
SWIFT_REQUEST(TypeChecker, GetDistributedActorIDPropertyRequest, VarDecl *(NominalTypeDecl *),
111+
SWIFT_REQUEST(TypeChecker, GetDistributedActorIDPropertyRequest,
112+
VarDecl *(NominalTypeDecl *),
113+
Cached, NoLocationInfo)
114+
SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemPropertyRequest,
115+
VarDecl *(NominalTypeDecl *),
112116
Cached, NoLocationInfo)
113-
SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemPropertyRequest, VarDecl *(NominalTypeDecl *),
117+
SWIFT_REQUEST(TypeChecker, GetDistributedRemoteCallTargetInitFunctionRequest,
118+
ConstructorDecl *(NominalTypeDecl *),
114119
Cached, NoLocationInfo)
115120
SWIFT_REQUEST(TypeChecker, GetDistributedActorInvocationDecoderRequest,
116121
NominalTypeDecl *(NominalTypeDecl *),

0 commit comments

Comments
 (0)