Skip to content

Commit d586ffe

Browse files
committed
[CSSimplify] InferSendableFromCaptures: Narrow member lookup delaying
Avoid delaying if: - Base is a metatype because static methods are always Sendable (because metatype is Sendable) - Lookup doesn't have any methods (properties are un-affected by the inference changes).
1 parent a823212 commit d586ffe

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9532,34 +9532,6 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
95329532
}
95339533
}
95349534

9535-
// Delay solving member constraint for unapplied methods
9536-
// where the base type has a conditional Sendable conformance
9537-
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
9538-
if (isPartialApplication(memberLocator)) {
9539-
auto sendableProtocol = Context.getProtocol(KnownProtocolKind::Sendable);
9540-
auto baseConformance = DC->getParentModule()->lookupConformance(
9541-
instanceTy, sendableProtocol);
9542-
9543-
if (llvm::any_of(
9544-
baseConformance.getConditionalRequirements(),
9545-
[&](const auto &req) {
9546-
if (req.getKind() != RequirementKind::Conformance)
9547-
return false;
9548-
9549-
if (auto protocolTy =
9550-
req.getSecondType()->template getAs<ProtocolType>()) {
9551-
return req.getFirstType()->hasTypeVariable() &&
9552-
protocolTy->getDecl()->isSpecificProtocol(
9553-
KnownProtocolKind::Sendable);
9554-
}
9555-
return false;
9556-
})) {
9557-
result.OverallResult = MemberLookupResult::Unsolved;
9558-
return result;
9559-
}
9560-
}
9561-
}
9562-
95639535
// Okay, start building up the result list.
95649536
result.OverallResult = MemberLookupResult::HasResults;
95659537

@@ -10078,6 +10050,46 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
1007810050
return OverloadChoice(baseTy, cand, functionRefKind);
1007910051
};
1008010052

10053+
// Delay solving member constraint for unapplied methods
10054+
// where the base type has a conditional Sendable conformance
10055+
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
10056+
auto shouldCheckSendabilityOfBase = [&]() {
10057+
// Static members are always sendable because they only capture
10058+
// metatypes which are Sendable.
10059+
if (baseObjTy->is<AnyMetatypeType>())
10060+
return false;
10061+
10062+
return isPartialApplication(memberLocator) &&
10063+
llvm::any_of(lookup, [&](const auto &result) {
10064+
return isa_and_nonnull<FuncDecl>(result.getValueDecl());
10065+
});
10066+
};
10067+
10068+
if (shouldCheckSendabilityOfBase()) {
10069+
auto sendableProtocol = Context.getProtocol(KnownProtocolKind::Sendable);
10070+
auto baseConformance = DC->getParentModule()->lookupConformance(
10071+
instanceTy, sendableProtocol);
10072+
10073+
if (llvm::any_of(
10074+
baseConformance.getConditionalRequirements(),
10075+
[&](const auto &req) {
10076+
if (req.getKind() != RequirementKind::Conformance)
10077+
return false;
10078+
10079+
if (auto protocolTy =
10080+
req.getSecondType()->template getAs<ProtocolType>()) {
10081+
return req.getFirstType()->hasTypeVariable() &&
10082+
protocolTy->getDecl()->isSpecificProtocol(
10083+
KnownProtocolKind::Sendable);
10084+
}
10085+
return false;
10086+
})) {
10087+
result.OverallResult = MemberLookupResult::Unsolved;
10088+
return result;
10089+
}
10090+
}
10091+
}
10092+
1008110093
// Add all results from this lookup.
1008210094
for (auto result : lookup)
1008310095
addChoice(getOverloadChoice(result.getValueDecl(),

0 commit comments

Comments
 (0)