Skip to content

Commit 901cdaf

Browse files
committed
RequirementMachine: Relax assertions in verifyRewriteSystem()
We don't care as much about rules with weird shapes as long as they're LHS- or RHS-simplified, since the new minimal conformances algorithm no longer relies on certain invariants. Fixes rdar://problem/94746399.
1 parent d3b7aab commit 901cdaf

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,21 @@ void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
549549

550550
if (index != lhs.size() - 1) {
551551
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Layout);
552-
ASSERT_RULE(!symbol.hasSubstitutions());
552+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Superclass);
553+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::ConcreteType);
554+
}
555+
556+
if (!rule.isLHSSimplified() &&
557+
index != lhs.size() - 1) {
558+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::ConcreteConformance);
553559
}
554560

555561
if (index != 0) {
556562
ASSERT_RULE(symbol.getKind() != Symbol::Kind::GenericParam);
557563
}
558564

559-
if (index != 0 && index != lhs.size() - 1) {
565+
if (!rule.isLHSSimplified() &&
566+
index != 0 && index != lhs.size() - 1) {
560567
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Protocol);
561568
}
562569
}
@@ -585,13 +592,29 @@ void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
585592
}
586593

587594
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Layout);
588-
ASSERT_RULE(!symbol.hasSubstitutions());
595+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Superclass);
596+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::ConcreteType);
597+
598+
// Completion can introduce a rule of the form
599+
//
600+
// (T.[P] => T.[concrete: C : P])
601+
//
602+
// Such rules are immediately simplified away. Otherwise, we should
603+
// never see a symbol with substitutions (concrete type, superclass,
604+
// concrete conformance) on the right hand side of a rule.
605+
if (!(rule.isRHSSimplified() &&
606+
index == rhs.size() - 1)) {
607+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Superclass);
608+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::ConcreteType);
609+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::ConcreteConformance);
610+
}
589611

590612
if (index != 0) {
591613
ASSERT_RULE(symbol.getKind() != Symbol::Kind::GenericParam);
592614
}
593615

594-
if (index != 0 && !rule.isRHSSimplified()) {
616+
if (!rule.isRHSSimplified() &&
617+
index != 0) {
595618
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Protocol);
596619
}
597620
}

test/Generics/rdar9474639.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
2+
3+
// CHECK-LABEL: .P1@
4+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.[P1]T.[P2]T, Self.[P1]T : P2>
5+
protocol P1 {
6+
associatedtype T: P2 where T.T == Self
7+
}
8+
9+
// CHECK-LABEL: .P2@
10+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.[P2]T.[P1]T, Self.[P2]T : P1>
11+
protocol P2 {
12+
associatedtype T: P1 where T.T == Self
13+
}
14+
15+
class SomeClass {}
16+
17+
// CHECK-LABEL: .P3@
18+
// CHECK-NEXT: Requirement signature: <Self where Self : P2, Self.[P2]T : SomeClass>
19+
protocol P3: P2 where T: SomeClass {}
20+
21+
protocol P4 {
22+
associatedtype T
23+
}
24+
25+
// CHECK-LABEL: .foo@
26+
// CHECK-NEXT: Generic signature: <T where T : P4, T.[P4]T : P1, T.[P4]T.[P1]T : P3>
27+
func foo<T: P4>(_: T) where T.T: P1, T.T.T: P3 {}

0 commit comments

Comments
 (0)