Skip to content

Commit 072a43e

Browse files
committed
[AST] Distributed: De-duplicate methods that retrieve types from distributed system
1 parent 9fe7da9 commit 072a43e

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

lib/AST/DistributedDecl.cpp

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -166,65 +166,46 @@ Type swift::getDistributedActorIDType(NominalTypeDecl *actor) {
166166
return getAssociatedTypeOfDistributedSystemOfActor(actor, C.Id_ActorID);
167167
}
168168

169-
Type swift::getDistributedActorSystemActorIDType(NominalTypeDecl *system) {
170-
assert(!system->isDistributedActor());
171-
auto &ctx = system->getASTContext();
169+
static Type getTypeWitnessByName(NominalTypeDecl *type, ProtocolDecl *protocol,
170+
Identifier member) {
171+
if (!protocol)
172+
return ErrorType::get(type->getASTContext());
172173

173-
auto DAS = ctx.getDistributedActorSystemDecl();
174-
if (!DAS)
174+
auto module = type->getParentModule();
175+
Type selfType = type->getSelfInterfaceType();
176+
auto conformance = module->lookupConformance(selfType, protocol);
177+
if (!conformance || conformance.isInvalid())
175178
return Type();
179+
return conformance.getTypeWitnessByName(selfType, member);
180+
}
176181

177-
// Dig out the serialization requirement type.
178-
auto module = system->getParentModule();
179-
Type selfType = system->getSelfInterfaceType();
180-
auto conformance = module->lookupConformance(selfType, DAS);
181-
return conformance.getTypeWitnessByName(selfType, ctx.Id_ActorID);
182+
Type swift::getDistributedActorSystemActorIDType(NominalTypeDecl *system) {
183+
assert(!system->isDistributedActor());
184+
auto &ctx = system->getASTContext();
185+
return getTypeWitnessByName(system, ctx.getDistributedActorSystemDecl(),
186+
ctx.Id_ActorID);
182187
}
183188

184189
Type swift::getDistributedActorSystemResultHandlerType(
185190
NominalTypeDecl *system) {
186191
assert(!system->isDistributedActor());
187192
auto &ctx = system->getASTContext();
188-
189-
auto DAS = ctx.getDistributedActorSystemDecl();
190-
if (!DAS)
191-
return Type();
192-
193-
// Dig out the serialization requirement type.
194-
auto module = system->getParentModule();
195-
Type selfType = system->getSelfInterfaceType();
196-
auto conformance = module->lookupConformance(selfType, DAS);
197-
return conformance.getTypeWitnessByName(selfType, ctx.Id_ResultHandler);
193+
return getTypeWitnessByName(system, ctx.getDistributedActorSystemDecl(),
194+
ctx.Id_ResultHandler);
198195
}
199196

200197
Type swift::getDistributedActorSystemInvocationEncoderType(NominalTypeDecl *system) {
201198
assert(!system->isDistributedActor());
202199
auto &ctx = system->getASTContext();
203-
204-
auto DAS = ctx.getDistributedActorSystemDecl();
205-
if (!DAS)
206-
return Type();
207-
208-
// Dig out the serialization requirement type.
209-
auto module = system->getParentModule();
210-
Type selfType = system->getSelfInterfaceType();
211-
auto conformance = module->lookupConformance(selfType, DAS);
212-
return conformance.getTypeWitnessByName(selfType, ctx.Id_InvocationEncoder);
200+
return getTypeWitnessByName(system, ctx.getDistributedActorSystemDecl(),
201+
ctx.Id_InvocationEncoder);
213202
}
214203

215204
Type swift::getDistributedActorSystemInvocationDecoderType(NominalTypeDecl *system) {
216205
assert(!system->isDistributedActor());
217206
auto &ctx = system->getASTContext();
218-
219-
auto DAS = ctx.getDistributedActorSystemDecl();
220-
if (!DAS)
221-
return Type();
222-
223-
// Dig out the serialization requirement type.
224-
auto module = system->getParentModule();
225-
Type selfType = system->getSelfInterfaceType();
226-
auto conformance = module->lookupConformance(selfType, DAS);
227-
return conformance.getTypeWitnessByName(selfType, ctx.Id_InvocationDecoder);
207+
return getTypeWitnessByName(system, ctx.getDistributedActorSystemDecl(),
208+
ctx.Id_InvocationDecoder);
228209
}
229210

230211
Type swift::getDistributedSerializationRequirementType(

0 commit comments

Comments
 (0)