Skip to content

Commit 089596a

Browse files
xedinktoso
authored andcommitted
[TypeChecker] Allow missing requirements on Res generic parameter of DistributedActorSystem.remoteCall
Conformance requirement between on `Res` and `SerializationRequirement` of `DistributedActorSystem.remoteCall` are not expressible at the moment but they are verified by Sema so it's okay to omit them here and lookup dynamically during IRGen.
1 parent 40704ac commit 089596a

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,13 +1195,52 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
11951195
}
11961196
bool requiresNonSendable = false;
11971197
if (!solution || solution->Fixes.size()) {
1198-
/// If the *only* problems are that `@Sendable` attributes are missing,
1199-
/// allow the match in some circumstances.
1200-
requiresNonSendable = solution
1201-
&& llvm::all_of(solution->Fixes, [](constraints::ConstraintFix *fix) {
1202-
return fix->getKind() == constraints::FixKind::AddSendableAttribute;
1203-
});
1204-
if (!requiresNonSendable)
1198+
auto isMatchedAllowed = [&](const constraints::Solution &solution) {
1199+
/// If the *only* problems are that `@Sendable` attributes are missing,
1200+
/// allow the match in some circumstances.
1201+
if (llvm::all_of(solution.Fixes, [](constraints::ConstraintFix *fix) {
1202+
return fix->getKind() ==
1203+
constraints::FixKind::AddSendableAttribute;
1204+
}))
1205+
return true;
1206+
1207+
auto *funcDecl = dyn_cast<AbstractFunctionDecl>(req);
1208+
// Conformance requirement between on `Res` and `SerializationRequirement`
1209+
// of `DistributedActorSystem.remoteCall` are not expressible at the moment
1210+
// but they are verified by Sema so it's okay to omit them here and lookup
1211+
// dynamically during IRGen.
1212+
if (funcDecl && funcDecl->isDistributedActorSystemRemoteCallRequirement(
1213+
/*withResult=*/true)) {
1214+
if (llvm::all_of(solution.Fixes, [&witness](constraints::ConstraintFix
1215+
*fix) {
1216+
auto conformance = dyn_cast<MissingConformance>(fix);
1217+
if (!conformance)
1218+
return false;
1219+
1220+
auto *locator = fix->getLocator();
1221+
auto requirement = locator->getLastElementAs<
1222+
LocatorPathElt::TypeParameterRequirement>();
1223+
if (!requirement)
1224+
return false;
1225+
1226+
auto signature =
1227+
locator->findLast<LocatorPathElt::OpenedGeneric>()
1228+
->getSignature();
1229+
1230+
auto subject =
1231+
signature.getRequirements()[requirement->getIndex()]
1232+
.getFirstType();
1233+
// `Res` is the result type so we can check against that.
1234+
return subject->isEqual(
1235+
cast<FuncDecl>(witness)->getResultInterfaceType());
1236+
}))
1237+
return true;
1238+
}
1239+
// In all other cases - disallow the match.
1240+
return false;
1241+
};
1242+
1243+
if (!solution || !isMatchedAllowed(*solution))
12051244
return RequirementMatch(witness, MatchKind::TypeConflict,
12061245
witnessType);
12071246
}

0 commit comments

Comments
 (0)