AST: Expand defaults in InheritedProtocolsRequest::evaluate()

This commit is contained in:
Slava Pestov
2024-02-21 08:42:46 -05:00
parent 80b5eca9e8
commit bd06653ee9
3 changed files with 28 additions and 5 deletions

View File

@@ -3290,7 +3290,34 @@ InheritedProtocolsRequest::evaluate(Evaluator &evaluator,
inherited.insert(proto);
}
// FIXME: Apply inverses
// Apply inverses.
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
bool skipInverses = false;
// ... except for these protocols, so that Copyable does not have to
// inherit ~Copyable, etc.
if (auto kp = PD->getKnownProtocolKind()) {
switch (*kp) {
case KnownProtocolKind::Sendable:
case KnownProtocolKind::Copyable:
case KnownProtocolKind::Escapable:
skipInverses = true;
break;
default:
break;
}
}
if (!skipInverses) {
for (auto ip : InvertibleProtocolSet::full()) {
// Unless the user wrote ~P in the syntactic inheritance clause, the
// semantic inherited list includes P.
if (!inverses.contains(ip))
inherited.insert(ctx.getProtocol(getKnownProtocolKind(ip)));
}
}
}
}
return ctx.AllocateCopy(inherited.getArrayRef());

View File

@@ -2,8 +2,6 @@
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-requirement-machine-reuse 2>&1 | %FileCheck %s
// XFAIL: noncopyable_generics
// CHECK-LABEL: .NonEmptyProtocol@
// CHECK-NEXT: Requirement signature: <Self where Self : Collection, Self.[NonEmptyProtocol]C : Collection, Self.[Sequence]Element == Self.[NonEmptyProtocol]C.[Sequence]Element, Self.[Collection]Index == Self.[NonEmptyProtocol]C.[Collection]Index>

View File

@@ -2,8 +2,6 @@
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-requirement-machine-reuse 2>&1 | %FileCheck %s
// XFAIL: noncopyable_generics
// CHECK-LABEL: .NonEmptyProtocol@
// CHECK-NEXT: Requirement signature: <Self where Self : Collection, Self.[NonEmptyProtocol]C : Collection, Self.[Sequence]Element == Self.[NonEmptyProtocol]C.[Sequence]Element, Self.[Collection]Index == Self.[NonEmptyProtocol]C.[Collection]Index>