Skip to content

Allow unavailable conformances to non-Sendaable protocols during contraction #59235

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: 6 additions & 2 deletions lib/AST/RequirementMachine/ConcreteContraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,16 @@ Optional<Type> ConcreteContraction::substTypeParameterRec(
auto *proto = assocType->getProtocol();
auto *module = proto->getParentModule();

bool allowUnavailable =
!proto->isSpecificProtocol(KnownProtocolKind::Sendable);
// The 'Sendable' protocol does not declare any associated types, so the
// 'allowMissing' value here is actually irrelevant.
auto conformance = ((*substBaseType)->isTypeParameter()
? ProtocolConformanceRef(proto)
: module->lookupConformance(
*substBaseType, proto,
/*allowMissing=*/false,
/*allowUnavailable=*/false));
allowUnavailable));

// The base type doesn't conform, in which case the requirement remains
// unsubstituted.
Expand Down Expand Up @@ -391,9 +393,11 @@ ConcreteContraction::substRequirement(const Requirement &req) const {
if (ConcreteTypes.count(stripBoundDependentMemberTypes(firstType)) > 0)
allowMissing = true;

bool allowUnavailable =
!proto->isSpecificProtocol(KnownProtocolKind::Sendable);
if (!substFirstType->isTypeParameter() &&
!module->lookupConformance(substFirstType, proto,
allowMissing, /*allowUnavailable=*/false)) {
allowMissing, allowUnavailable)) {
// 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
4 changes: 3 additions & 1 deletion test/Generics/superclass_constraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,7 @@ extension Animal: Pony { }

public struct AnimalWrapper<Friend: Animal> { }

// CHECK: Generic signature: <Friend where Friend : Animal, Friend : Pony>
// FIXME: Generic signature: <Friend where Friend : Animal, Friend : Pony>
// Generic signature: <Friend where Friend : Animal>
extension AnimalWrapper: Pony where Friend: Pony { }
// expected-warning@-1{{redundant conformance constraint 'Animal' : 'Pony'}}
17 changes: 17 additions & 0 deletions test/decl/protocol/unavailable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-typecheck-verify-swift

protocol P { }

struct X { }

@available(*, unavailable)
extension X: P { }

struct Y<T: P> { }

@available(*, unavailable)
extension Y {
// Okay, because the unavailable conformance is used within an
// unavailable context.
init() where T == X { }
}