Skip to content

Commit bacabc1

Browse files
committed
Distributed: Some cleanups
1 parent 2269c80 commit bacabc1

File tree

2 files changed

+21
-47
lines changed

2 files changed

+21
-47
lines changed

lib/AST/DistributedDecl.cpp

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,16 @@ swift::getDistributedSerializationRequirements(
340340
if (existentialRequirementTy->isAny())
341341
return true; // we're done here, any means there are no requirements
342342

343-
if (!existentialRequirementTy->isExistentialType()) {
344-
// SerializationRequirement must be an existential type
345-
return false;
346-
}
347-
348343
ExistentialType *serialReqType = existentialRequirementTy
349-
->castTo<ExistentialType>();
344+
->getAs<ExistentialType>();
350345
if (!serialReqType || serialReqType->hasError()) {
351346
return false;
352347
}
353348

354-
auto desugaredTy = serialReqType->getConstraintType()->getDesugaredType();
349+
auto desugaredTy = serialReqType->getConstraintType();
355350
auto flattenedRequirements =
356351
flattenDistributedSerializationTypeToRequiredProtocols(
357-
desugaredTy);
352+
desugaredTy.getPointer());
358353
for (auto p : flattenedRequirements) {
359354
requirementProtos.insert(p);
360355
}
@@ -565,25 +560,19 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
565560

566561
// --- Check requirement: conforms_to: Act DistributedActor
567562
auto actorReq = requirements[0];
568-
auto distActorTy = C.getProtocol(KnownProtocolKind::DistributedActor)
569-
->getInterfaceType()
570-
->getMetatypeInstanceType();
571563
if (actorReq.getKind() != RequirementKind::Conformance) {
572564
return false;
573565
}
574-
if (!actorReq.getSecondType()->isEqual(distActorTy)) {
566+
if (!actorReq.getProtocolDecl()->isSpecificProtocol(KnownProtocolKind::DistributedActor)) {
575567
return false;
576568
}
577569

578570
// --- Check requirement: conforms_to: Err Error
579571
auto errorReq = requirements[1];
580-
auto errorTy = C.getProtocol(KnownProtocolKind::Error)
581-
->getInterfaceType()
582-
->getMetatypeInstanceType();
583572
if (errorReq.getKind() != RequirementKind::Conformance) {
584573
return false;
585574
}
586-
if (!errorReq.getSecondType()->isEqual(errorTy)) {
575+
if (!errorReq.getProtocolDecl()->isSpecificProtocol(KnownProtocolKind::Error)) {
587576
return false;
588577
}
589578

@@ -598,10 +587,9 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
598587
assert(ResParam && "Non void function, yet no Res generic parameter found");
599588
if (auto func = dyn_cast<FuncDecl>(this)) {
600589
auto resultType = func->mapTypeIntoContext(func->getResultInterfaceType())
601-
->getMetatypeInstanceType()
602-
->getDesugaredType();
590+
->getMetatypeInstanceType();
603591
auto resultParamType = func->mapTypeIntoContext(
604-
ResParam->getInterfaceType()->getMetatypeInstanceType());
592+
ResParam->getDeclaredInterfaceType());
605593
// The result of the function must be the `Res` generic argument.
606594
if (!resultType->isEqual(resultParamType)) {
607595
return false;
@@ -797,12 +785,10 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
797785

798786
// the <Value> of the RemoteCallArgument<Value>
799787
auto remoteCallArgValueGenericTy =
800-
mapTypeIntoContext(argGenericParams[0]->getInterfaceType())
801-
->getDesugaredType()
802-
->getMetatypeInstanceType();
788+
mapTypeIntoContext(argGenericParams[0]->getDeclaredInterfaceType());
803789
// expected (the <Value> from the recordArgument<Value>)
804790
auto expectedGenericParamTy = mapTypeIntoContext(
805-
ArgumentParam->getInterfaceType()->getMetatypeInstanceType());
791+
ArgumentParam->getDeclaredInterfaceType());
806792

807793
if (!remoteCallArgValueGenericTy->isEqual(expectedGenericParamTy)) {
808794
return false;
@@ -932,11 +918,10 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
932918
// ...
933919

934920
auto resultType = func->mapTypeIntoContext(argumentParam->getInterfaceType())
935-
->getMetatypeInstanceType()
936-
->getDesugaredType();
921+
->getMetatypeInstanceType();
937922

938923
auto resultParamType = func->mapTypeIntoContext(
939-
ArgumentParam->getInterfaceType()->getMetatypeInstanceType());
924+
ArgumentParam->getDeclaredInterfaceType());
940925

941926
// The result of the function must be the `Res` generic argument.
942927
if (!resultType->isEqual(resultParamType)) {
@@ -1046,13 +1031,10 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
10461031

10471032
// --- Check requirement: conforms_to: Err Error
10481033
auto errorReq = requirements[0];
1049-
auto errorTy = C.getProtocol(KnownProtocolKind::Error)
1050-
->getInterfaceType()
1051-
->getMetatypeInstanceType();
10521034
if (errorReq.getKind() != RequirementKind::Conformance) {
10531035
return false;
10541036
}
1055-
if (!errorReq.getSecondType()->isEqual(errorTy)) {
1037+
if (!errorReq.getProtocolDecl()->isSpecificProtocol(KnownProtocolKind::Error)) {
10561038
return false;
10571039
}
10581040

@@ -1139,10 +1121,9 @@ AbstractFunctionDecl::isDistributedTargetInvocationDecoderDecodeNextArgument() c
11391121
// --- Check: Argument: SerializationRequirement
11401122
GenericTypeParamDecl *ArgumentParam = genericParams->getParams()[0];
11411123
auto resultType = func->mapTypeIntoContext(func->getResultInterfaceType())
1142-
->getMetatypeInstanceType()
1143-
->getDesugaredType();
1124+
->getMetatypeInstanceType();
11441125
auto resultParamType = func->mapTypeIntoContext(
1145-
ArgumentParam->getInterfaceType()->getMetatypeInstanceType());
1126+
ArgumentParam->getDeclaredInterfaceType());
11461127
// The result of the function must be the `Res` generic argument.
11471128
if (!resultType->isEqual(resultParamType)) {
11481129
return false;
@@ -1237,11 +1218,10 @@ AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const
12371218
// === Check generic parameters in detail
12381219
// --- Check: Argument: SerializationRequirement
12391220
GenericTypeParamDecl *ArgumentParam = genericParams->getParams()[0];
1240-
auto argumentType = func->mapTypeIntoContext(valueParam->getInterfaceType())
1241-
->getMetatypeInstanceType()
1242-
->getDesugaredType();
1221+
auto argumentType = func->mapTypeIntoContext(
1222+
valueParam->getInterfaceType()->getMetatypeInstanceType());
12431223
auto resultParamType = func->mapTypeIntoContext(
1244-
ArgumentParam->getInterfaceType()->getMetatypeInstanceType());
1224+
ArgumentParam->getDeclaredInterfaceType());
12451225
// The result of the function must be the `Res` generic argument.
12461226
if (!argumentType->isEqual(resultParamType)) {
12471227
return false;
@@ -1269,7 +1249,6 @@ swift::extractDistributedSerializationRequirements(
12691249
auto DA = C.getDistributedActorDecl();
12701250
auto daSerializationReqAssocType =
12711251
DA->getAssociatedType(C.Id_SerializationRequirement);
1272-
auto daSystemSerializationReqTy = daSerializationReqAssocType->getInterfaceType();
12731252

12741253
for (auto req : allRequirements) {
12751254
if (req.getSecondType()->isAny()) {
@@ -1280,21 +1259,17 @@ swift::extractDistributedSerializationRequirements(
12801259

12811260
if (auto dependentMemberType =
12821261
req.getFirstType()->castTo<DependentMemberType>()) {
1283-
auto dependentTy =
1284-
dependentMemberType->getAssocType()->getInterfaceType();
1285-
1286-
if (dependentTy->isEqual(daSystemSerializationReqTy)) {
1262+
if (dependentMemberType->getAssocType() == daSerializationReqAssocType) {
12871263
auto requirementProto = req.getSecondType();
12881264
if (auto proto = dyn_cast_or_null<ProtocolDecl>(
12891265
requirementProto->getAnyNominal())) {
12901266
serializationReqs.insert(proto);
12911267
} else {
12921268
auto serialReqType = requirementProto->castTo<ExistentialType>()
1293-
->getConstraintType()
1294-
->getDesugaredType();
1269+
->getConstraintType();
12951270
auto flattenedRequirements =
12961271
flattenDistributedSerializationTypeToRequiredProtocols(
1297-
serialReqType);
1272+
serialReqType.getPointer());
12981273
for (auto p : flattenedRequirements) {
12991274
serializationReqs.insert(p);
13001275
}

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,7 @@ GetDistributedActorArgumentDecodingMethodRequest::evaluate(Evaluator &evaluator,
887887
continue;
888888

889889
auto paramTy = genericParamList->getParams()[0]
890-
->getInterfaceType()
891-
->getMetatypeInstanceType();
890+
->getDeclaredInterfaceType();
892891

893892
// `decodeNextArgument` should return its generic parameter value
894893
if (!FD->getResultInterfaceType()->isEqual(paramTy))

0 commit comments

Comments
 (0)