Skip to content

Commit 4e89f73

Browse files
committed
RequirementMachine: Allow markConflicting() on already-conflicting frozen rules
1 parent a8190d8 commit 4e89f73

File tree

3 files changed

+42
-53
lines changed

3 files changed

+42
-53
lines changed

lib/AST/RequirementMachine/Rule.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ class Rule final {
198198
}
199199

200200
void markConflicting() {
201+
// It's okay to mark a rule as conflicting multiple times.
202+
if (Conflicting)
203+
return;
204+
201205
assert(!Frozen);
202-
// It's okay to mark a rule as conflicting multiple times, but it must not
203-
// be a permanent rule.
204206
assert(!Permanent && "Permanent rule should not conflict with anything");
205207
Conflicting = true;
206208
}

test/decl/protocol/req/associated_type_inference_fixed_type.swift

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on
22

33
protocol P1 where A == Never {
44
associatedtype A
@@ -41,8 +41,7 @@ protocol P5b: P5a where A == Self {}
4141
struct S5<X>: P5b {} // OK, A := S5<X>
4242

4343

44-
protocol P6 where A == Never { // expected-error {{same-type constraint type 'Never' does not conform to required protocol 'P6'}}
45-
// expected-error@+2 {{same-type constraint type 'Never' does not conform to required protocol 'P6'}}
44+
protocol P6 where A == Never { // expected-error {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A : P6'}}
4645
// expected-note@+1 {{protocol requires nested type 'A}}
4746
associatedtype A: P6
4847
}
@@ -51,8 +50,7 @@ struct S6: P6 {} // expected-error {{type 'S6' does not conform to protocol 'P6'
5150
protocol P7a where A == Never {
5251
associatedtype A
5352
}
54-
// expected-error@+2 {{'Self.A' cannot be equal to both 'Bool' and 'Never'}}
55-
// expected-note@+1 {{same-type constraint 'Self.A' == 'Never' implied here}}
53+
// expected-error@+1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Bool'}}
5654
protocol P7b: P7a where A == Bool {}
5755
struct S7: P7b {}
5856

@@ -315,13 +313,11 @@ protocol P28c where A == Never {
315313
associatedtype A
316314
}
317315
protocol Q28a: P28a, P28b {}
318-
// expected-error@-1 {{'Self.A' cannot be equal to both 'Bool' and 'Int'}}
319-
// expected-note@-2 {{same-type constraint 'Self.A' == 'Int' implied here}}
316+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Bool' and 'Self.A == Int'}}
320317
protocol Q28b: P28a, P28b, P28c {}
321-
// expected-error@-1 {{'Self.A' cannot be equal to both 'Bool' and 'Int'}}
322-
// expected-error@-2 {{'Self.A' cannot be equal to both 'Never' and 'Int'}}
323-
// expected-note@-3 {{same-type constraint 'Self.A' == 'Int' implied here}}
324-
// expected-note@-4 {{same-type constraint 'Self.A' == 'Int' implied here}}
318+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Bool'}}
319+
// expected-error@-2 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
320+
// expected-error@-3 {{no type for 'Self.A' can satisfy both 'Self.A == Bool' and 'Self.A == Int'}}
325321
do {
326322
struct Conformer1: Q28a {}
327323
// expected-error@-1 {{'P28b' requires the types 'Conformer1.A' (aka 'Int') and 'Bool' be equivalent}}
@@ -349,11 +345,9 @@ protocol P29c where A == B {
349345
associatedtype B // expected-note {{protocol requires nested type 'B'; do you want to add it?}}
350346
}
351347
protocol Q29a: P29a, P29b, P29c {}
352-
// expected-error@-1 {{'Self.B' cannot be equal to both 'Never' and 'Int'}}
353-
// expected-note@-2 {{same-type constraint 'Self.A' == 'Int' implied here}}
348+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
354349
protocol Q29b: P29c, P29a, P29b {}
355-
// expected-error@-1 {{'Self.B' cannot be equal to both 'Never' and 'Int'}}
356-
// expected-note@-2 {{same-type constraint 'Self.A' == 'Int' implied here}}
350+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
357351
do {
358352
struct Conformer1: Q29a {}
359353
// expected-error@-1 {{'P29b' requires the types 'Conformer1.B' (aka 'Int') and 'Never' be equivalent}}
@@ -378,8 +372,7 @@ protocol P30c where A == B {
378372
associatedtype B // expected-note {{protocol requires nested type 'B'; do you want to add it?}}
379373
}
380374
protocol Q30: P30c, P30a, P30b {}
381-
// expected-error@-1 {{'Self.A' cannot be equal to both 'Never' and 'Int'}}
382-
// expected-note@-2 {{same-type constraint 'Self.A' == 'Int' implied here}}
375+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
383376
do {
384377
struct Conformer: Q30 {}
385378
// expected-error@-1 {{type 'Conformer' does not conform to protocol 'P30a'}}
@@ -398,8 +391,7 @@ protocol P31c where B == A {
398391
associatedtype B // expected-note {{protocol requires nested type 'B'; do you want to add it?}}
399392
}
400393
protocol Q31: P31c, P31a, P31b {}
401-
// expected-error@-1 {{'Self.B' cannot be equal to both 'Never' and 'Int'}}
402-
// expected-note@-2 {{same-type constraint 'Self.B' == 'Int' implied here}}
394+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
403395
do {
404396
struct Conformer: Q31 {}
405397
// expected-error@-1 {{type 'Conformer' does not conform to protocol 'P31a'}}
@@ -424,10 +416,12 @@ protocol P32e where A == B {
424416
associatedtype B // expected-note {{protocol requires nested type 'B'; do you want to add it?}}
425417
}
426418
protocol Q32: P32e, P32a, P32b, P32c, P32d {}
427-
// expected-error@-1 {{'Self.B' cannot be equal to both 'Never' and 'Int'}}
428-
// expected-error@-2 {{'Self.B' cannot be equal to both '()' and 'Int'}}
429-
// expected-error@-3 {{'Self.A' cannot be equal to both 'Bool' and 'Int'}}
430-
// expected-note@-4 3 {{same-type constraint 'Self.A' == 'Int' implied here}}
419+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == ()'}}
420+
// expected-error@-2 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Bool'}}
421+
// expected-error@-3 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
422+
// expected-error@-4 {{no type for 'Self.A' can satisfy both 'Self.A == Bool' and 'Self.A == Int'}}
423+
// expected-error@-5 {{no type for 'Self.A' can satisfy both 'Self.A == ()' and 'Self.A == Int'}}
424+
// expected-error@-6 {{no type for 'Self.A' can satisfy both 'Self.A == ()' and 'Self.A == Bool'}}
431425
do {
432426
struct Conformer: Q32 {}
433427
// expected-error@-1 {{type 'Conformer' does not conform to protocol 'P32a'}}

test/decl/protocol/req/associated_type_inference_fixed_type_experimental_inference.swift

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference
2-
// RUN: not %target-swift-frontend -typecheck -enable-experimental-associated-type-inference -dump-type-witness-systems %s 2>&1 | %FileCheck %s
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on
2+
// RUN: not %target-swift-frontend -typecheck -enable-experimental-associated-type-inference -dump-type-witness-systems -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on %s 2>&1 | %FileCheck %s
33

44
protocol P1 where A == Never {
55
associatedtype A
@@ -60,8 +60,7 @@ protocol P5b: P5a where A == Self {}
6060
struct S5<X>: P5b {} // OK, A := S5<X>
6161

6262

63-
protocol P6 where A == Never { // expected-error {{same-type constraint type 'Never' does not conform to required protocol 'P6'}}
64-
// expected-error@+2 {{same-type constraint type 'Never' does not conform to required protocol 'P6'}}
63+
protocol P6 where A == Never { // expected-error {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A : P6'}}
6564
// expected-note@+1 {{protocol requires nested type 'A}}
6665
associatedtype A: P6
6766
}
@@ -73,8 +72,7 @@ struct S6: P6 {} // expected-error {{type 'S6' does not conform to protocol 'P6'
7372
protocol P7a where A == Never {
7473
associatedtype A
7574
}
76-
// expected-error@+2 {{'Self.A' cannot be equal to both 'Bool' and 'Never'}}
77-
// expected-note@+1 {{same-type constraint 'Self.A' == 'Never' implied here}}
75+
// expected-error@+1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Bool'}}
7876
protocol P7b: P7a where A == Bool {}
7977
// CHECK-LABEL: Abstract type witness system for conformance of S7 to P7a: {
8078
// CHECK-NEXT: A => Never,
@@ -106,10 +104,9 @@ protocol P9b: P9a {
106104
// CHECK-NEXT: A => Never,
107105
// CHECK-NEXT: }
108106
struct S9a: P9b {}
109-
// expected-error@+3 {{type 'S9b' does not conform to protocol 'P9a'}}
110-
// expected-error@+2 {{'P9a' requires the types 'S9b.A' (aka 'Bool') and 'Never' be equivalent}}
111-
// expected-note@+1 {{requirement specified as 'Self.A' == 'Never' [with Self = S9b]}}
112-
struct S9b: P9b {
107+
// expected-error@+2 {{type 'S9b' does not conform to protocol 'P9a'}}
108+
// expected-error@+1 {{'P9a' requires the types 'S9b.A' (aka 'Bool') and 'Never' be equivalent}}
109+
struct S9b: P9b { // expected-note {{requirement specified as 'Self.A' == 'Never' [with Self = S9b]}}
113110
typealias A = Bool
114111
}
115112
struct S9c: P9b { // OK, S9c.A does not contradict Self.A == Never.
@@ -445,13 +442,11 @@ protocol P28c where A == Never {
445442
associatedtype A
446443
}
447444
protocol Q28a: P28a, P28b {}
448-
// expected-error@-1 {{'Self.A' cannot be equal to both 'Bool' and 'Int'}}
449-
// expected-note@-2 {{same-type constraint 'Self.A' == 'Int' implied here}}
445+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Bool' and 'Self.A == Int'}}
450446
protocol Q28b: P28a, P28b, P28c {}
451-
// expected-error@-1 {{'Self.A' cannot be equal to both 'Bool' and 'Int'}}
452-
// expected-error@-2 {{'Self.A' cannot be equal to both 'Never' and 'Int'}}
453-
// expected-note@-3 {{same-type constraint 'Self.A' == 'Int' implied here}}
454-
// expected-note@-4 {{same-type constraint 'Self.A' == 'Int' implied here}}
447+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Bool'}}
448+
// expected-error@-2 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
449+
// expected-error@-3 {{no type for 'Self.A' can satisfy both 'Self.A == Bool' and 'Self.A == Int'}}
455450
do {
456451
// CHECK-LABEL: Abstract type witness system for conformance of Conformer1 to P28a: {
457452
// CHECK-NEXT: A => (ambiguous),
@@ -481,11 +476,9 @@ protocol P29c where A == B {
481476
associatedtype B // expected-note {{protocol requires nested type 'B'; do you want to add it?}}
482477
}
483478
protocol Q29a: P29a, P29b, P29c {}
484-
// expected-error@-1 {{'Self.B' cannot be equal to both 'Never' and 'Int'}}
485-
// expected-note@-2 {{same-type constraint 'Self.A' == 'Int' implied here}}
479+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
486480
protocol Q29b: P29c, P29a, P29b {}
487-
// expected-error@-1 {{'Self.B' cannot be equal to both 'Never' and 'Int'}}
488-
// expected-note@-2 {{same-type constraint 'Self.A' == 'Int' implied here}}
481+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
489482
do {
490483
// CHECK-LABEL: Abstract type witness system for conformance of Conformer1 to P29a: {
491484
// CHECK-NEXT: A => (ambiguous), [[EQUIV_CLASS:0x[0-9a-f]+]]
@@ -517,8 +510,7 @@ protocol P30c where A == B {
517510
associatedtype B // expected-note {{protocol requires nested type 'B'; do you want to add it?}}
518511
}
519512
protocol Q30: P30c, P30a, P30b {}
520-
// expected-error@-1 {{'Self.A' cannot be equal to both 'Never' and 'Int'}}
521-
// expected-note@-2 {{same-type constraint 'Self.A' == 'Int' implied here}}
513+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
522514
do {
523515
// CHECK-LABEL: Abstract type witness system for conformance of Conformer to P30c: {
524516
// CHECK-NEXT: A => (ambiguous), [[EQUIV_CLASS:0x[0-9a-f]+]]
@@ -541,8 +533,7 @@ protocol P31c where B == A {
541533
associatedtype B // expected-note {{protocol requires nested type 'B'; do you want to add it?}}
542534
}
543535
protocol Q31: P31c, P31a, P31b {}
544-
// expected-error@-1 {{'Self.B' cannot be equal to both 'Never' and 'Int'}}
545-
// expected-note@-2 {{same-type constraint 'Self.B' == 'Int' implied here}}
536+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
546537
do {
547538
// CHECK-LABEL: Abstract type witness system for conformance of Conformer to P31c: {
548539
// CHECK-NEXT: A => (ambiguous), [[EQUIV_CLASS:0x[0-9a-f]+]]
@@ -571,10 +562,12 @@ protocol P32e where A == B {
571562
associatedtype B // expected-note {{protocol requires nested type 'B'; do you want to add it?}}
572563
}
573564
protocol Q32: P32e, P32a, P32b, P32c, P32d {}
574-
// expected-error@-1 {{'Self.B' cannot be equal to both 'Never' and 'Int'}}
575-
// expected-error@-2 {{'Self.B' cannot be equal to both '()' and 'Int'}}
576-
// expected-error@-3 {{'Self.A' cannot be equal to both 'Bool' and 'Int'}}
577-
// expected-note@-4 3 {{same-type constraint 'Self.A' == 'Int' implied here}}
565+
// expected-error@-1 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == ()'}}
566+
// expected-error@-2 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Int'}}
567+
// expected-error@-3 {{no type for 'Self.A' can satisfy both 'Self.A == Never' and 'Self.A == Bool'}}
568+
// expected-error@-4 {{no type for 'Self.A' can satisfy both 'Self.A == ()' and 'Self.A == Bool'}}
569+
// expected-error@-5 {{no type for 'Self.A' can satisfy both 'Self.A == ()' and 'Self.A == Int'}}
570+
// expected-error@-6 {{no type for 'Self.A' can satisfy both 'Self.A == Bool' and 'Self.A == Int'}}
578571
do {
579572
// CHECK-LABEL: Abstract type witness system for conformance of Conformer to P32e: {
580573
// CHECK-NEXT: A => (ambiguous), [[EQUIV_CLASS:0x[0-9a-f]+]]

0 commit comments

Comments
 (0)