Skip to content

Allow missing Sendable conformances when type parametesr are made concrete #42270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/AST/RequirementMachine/ConcreteContraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ Optional<Type> ConcreteContraction::substTypeParameter(

auto conformance = ((*substBaseType)->isTypeParameter()
? ProtocolConformanceRef(proto)
: module->lookupConformance(*substBaseType, proto));
: module->lookupConformance(*substBaseType, proto,
/*allowMissing=*/true));

// The base type doesn't conform, in which case the requirement remains
// unsubstituted.
Expand Down Expand Up @@ -363,7 +364,8 @@ ConcreteContraction::substRequirement(const Requirement &req) const {
auto *proto = req.getProtocolDecl();
auto *module = proto->getParentModule();
if (!substFirstType->isTypeParameter() &&
!module->lookupConformance(substFirstType, proto)) {
!module->lookupConformance(substFirstType, proto,
/*allowMissing=*/true)) {
// Handle the case of <T where T : P, T : C> where C is a class and
// C does not conform to P by leaving the conformance requirement
// unsubstituted.
Expand Down Expand Up @@ -664,4 +666,4 @@ bool swift::rewriting::performConcreteContraction(
ConcreteContraction concreteContraction(debug);
return concreteContraction.performConcreteContraction(
requirements, result, errors);
}
}
3 changes: 2 additions & 1 deletion lib/AST/RequirementMachine/ConcreteTypeWitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
auto *module = proto->getParentModule();

auto conformance = module->lookupConformance(concreteType,
const_cast<ProtocolDecl *>(proto));
const_cast<ProtocolDecl *>(proto),
/*allowMissing=*/true);
if (conformance.isInvalid()) {
// For superclass rules, it is totally fine to have a signature like:
//
Expand Down
3 changes: 2 additions & 1 deletion lib/AST/RequirementMachine/RequirementLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
// Check if the subject type actually conforms.
auto *protoDecl = constraintType->castTo<ProtocolType>()->getDecl();
auto *module = protoDecl->getParentModule();
auto conformance = module->lookupConformance(subjectType, protoDecl);
auto conformance = module->lookupConformance(
subjectType, protoDecl, /*allowMissing=*/true);
if (conformance.isInvalid()) {
errors.push_back(RequirementError::forInvalidRequirementSubject(
{RequirementKind::Conformance, subjectType, constraintType}, loc));
Expand Down
26 changes: 26 additions & 0 deletions test/Concurrency/sendable_conformance_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,29 @@ extension SendableExtSub: @unchecked Sendable {}
// Still want to know about same-class redundancy
class MultiConformance: @unchecked Sendable {} // expected-note {{'MultiConformance' declares conformance to protocol 'Sendable' here}}
extension MultiConformance: @unchecked Sendable {} // expected-error {{redundant conformance of 'MultiConformance' to protocol 'Sendable'}}

// rdar://91174106 - allow missing Sendable conformances when extending a
// type generically.
// FIXME: Should warn because of missing Sendable, but currently is silent
// because we aren't checking conformance availability here yet.
struct X<T: Sendable> { }
enum Y {}
extension X where T == Y {}

protocol P2 {
associatedtype A: Sendable
}

enum Y2: P2, P3 {
typealias A = Y
}

struct X2<T: P2> { }
extension X2 where T == Y2 { }

protocol P3 {
associatedtype A
}

struct X3<T: P3> where T.A: Sendable { }
extension X3 where T == Y2 { }