mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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).
This commit is contained in:
@@ -9532,34 +9532,6 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
|
||||
}
|
||||
}
|
||||
|
||||
// Delay solving member constraint for unapplied methods
|
||||
// where the base type has a conditional Sendable conformance
|
||||
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
|
||||
if (isPartialApplication(memberLocator)) {
|
||||
auto sendableProtocol = Context.getProtocol(KnownProtocolKind::Sendable);
|
||||
auto baseConformance = DC->getParentModule()->lookupConformance(
|
||||
instanceTy, sendableProtocol);
|
||||
|
||||
if (llvm::any_of(
|
||||
baseConformance.getConditionalRequirements(),
|
||||
[&](const auto &req) {
|
||||
if (req.getKind() != RequirementKind::Conformance)
|
||||
return false;
|
||||
|
||||
if (auto protocolTy =
|
||||
req.getSecondType()->template getAs<ProtocolType>()) {
|
||||
return req.getFirstType()->hasTypeVariable() &&
|
||||
protocolTy->getDecl()->isSpecificProtocol(
|
||||
KnownProtocolKind::Sendable);
|
||||
}
|
||||
return false;
|
||||
})) {
|
||||
result.OverallResult = MemberLookupResult::Unsolved;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Okay, start building up the result list.
|
||||
result.OverallResult = MemberLookupResult::HasResults;
|
||||
|
||||
@@ -10078,6 +10050,46 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
|
||||
return OverloadChoice(baseTy, cand, functionRefKind);
|
||||
};
|
||||
|
||||
// Delay solving member constraint for unapplied methods
|
||||
// where the base type has a conditional Sendable conformance
|
||||
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
|
||||
auto shouldCheckSendabilityOfBase = [&]() {
|
||||
// Static members are always sendable because they only capture
|
||||
// metatypes which are Sendable.
|
||||
if (baseObjTy->is<AnyMetatypeType>())
|
||||
return false;
|
||||
|
||||
return isPartialApplication(memberLocator) &&
|
||||
llvm::any_of(lookup, [&](const auto &result) {
|
||||
return isa_and_nonnull<FuncDecl>(result.getValueDecl());
|
||||
});
|
||||
};
|
||||
|
||||
if (shouldCheckSendabilityOfBase()) {
|
||||
auto sendableProtocol = Context.getProtocol(KnownProtocolKind::Sendable);
|
||||
auto baseConformance = DC->getParentModule()->lookupConformance(
|
||||
instanceTy, sendableProtocol);
|
||||
|
||||
if (llvm::any_of(
|
||||
baseConformance.getConditionalRequirements(),
|
||||
[&](const auto &req) {
|
||||
if (req.getKind() != RequirementKind::Conformance)
|
||||
return false;
|
||||
|
||||
if (auto protocolTy =
|
||||
req.getSecondType()->template getAs<ProtocolType>()) {
|
||||
return req.getFirstType()->hasTypeVariable() &&
|
||||
protocolTy->getDecl()->isSpecificProtocol(
|
||||
KnownProtocolKind::Sendable);
|
||||
}
|
||||
return false;
|
||||
})) {
|
||||
result.OverallResult = MemberLookupResult::Unsolved;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add all results from this lookup.
|
||||
for (auto result : lookup)
|
||||
addChoice(getOverloadChoice(result.getValueDecl(),
|
||||
|
||||
Reference in New Issue
Block a user