Skip to content

Commit bd06653

Browse files
committedFeb 24, 2024
AST: Expand defaults in InheritedProtocolsRequest::evaluate()
1 parent 80b5eca commit bd06653

3 files changed

+28
-5
lines changed
 

‎lib/AST/NameLookup.cpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -3290,7 +3290,34 @@ InheritedProtocolsRequest::evaluate(Evaluator &evaluator,
32903290
inherited.insert(proto);
32913291
}
32923292

3293-
// FIXME: Apply inverses
3293+
// Apply inverses.
3294+
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
3295+
bool skipInverses = false;
3296+
3297+
// ... except for these protocols, so that Copyable does not have to
3298+
// inherit ~Copyable, etc.
3299+
if (auto kp = PD->getKnownProtocolKind()) {
3300+
switch (*kp) {
3301+
case KnownProtocolKind::Sendable:
3302+
case KnownProtocolKind::Copyable:
3303+
case KnownProtocolKind::Escapable:
3304+
skipInverses = true;
3305+
break;
3306+
3307+
default:
3308+
break;
3309+
}
3310+
}
3311+
3312+
if (!skipInverses) {
3313+
for (auto ip : InvertibleProtocolSet::full()) {
3314+
// Unless the user wrote ~P in the syntactic inheritance clause, the
3315+
// semantic inherited list includes P.
3316+
if (!inverses.contains(ip))
3317+
inherited.insert(ctx.getProtocol(getKnownProtocolKind(ip)));
3318+
}
3319+
}
3320+
}
32943321
}
32953322

32963323
return ctx.AllocateCopy(inherited.getArrayRef());

‎test/Generics/interdependent_protocol_conformance_example_4.swift

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
33
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-requirement-machine-reuse 2>&1 | %FileCheck %s
44

5-
// XFAIL: noncopyable_generics
6-
75
// CHECK-LABEL: .NonEmptyProtocol@
86
// 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>
97

‎test/Generics/interdependent_protocol_conformance_example_5.swift

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
33
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-requirement-machine-reuse 2>&1 | %FileCheck %s
44

5-
// XFAIL: noncopyable_generics
6-
75
// CHECK-LABEL: .NonEmptyProtocol@
86
// 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>
97

0 commit comments

Comments
 (0)