Skip to content

Commit b49fc4f

Browse files
authored
Merge pull request #41013 from slavapestov/gsb-rqm-cycle-hack
GSB/RequirementMachine: Remove unsound cycle-breaking hack
2 parents e7ae1f4 + 7393c9c commit b49fc4f

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5209,12 +5209,6 @@ class GenericSignatureBuilder::InferRequirementsWalker : public TypeWalker {
52095209
// Infer from generic nominal types.
52105210
auto decl = ty->getAnyNominal();
52115211
if (!decl) return Action::Continue;
5212-
5213-
// FIXME: The GSB and the request evaluator both detect a cycle here if we
5214-
// force a recursive generic signature. We should look into moving cycle
5215-
// detection into the generic signature request(s) - see rdar://55263708
5216-
if (!decl->hasComputedGenericSignature())
5217-
return Action::Continue;
52185212

52195213
auto genericSig = decl->getGenericSignature();
52205214
if (!genericSig)

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,6 @@ struct InferRequirementsWalker : public TypeWalker {
292292
auto decl = ty->getAnyNominal();
293293
if (!decl) return Action::Continue;
294294

295-
// FIXME: The GSB and the request evaluator both detect a cycle here if we
296-
// force a recursive generic signature. We should look into moving cycle
297-
// detection into the generic signature request(s) - see rdar://55263708
298-
if (!decl->hasComputedGenericSignature())
299-
return Action::Continue;
300-
301295
auto genericSig = decl->getGenericSignature();
302296
if (!genericSig)
303297
return Action::Continue;

test/Generics/generic_types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class Top {}
230230
class Bottom<T : Bottom<Top>> {}
231231
// expected-error@-1 {{'Bottom' requires that 'Top' inherit from 'Bottom<Top>'}}
232232
// expected-note@-2 {{requirement specified as 'T' : 'Bottom<Top>' [with T = Top]}}
233-
// expected-error@-3 {{generic class 'Bottom' has self-referential generic requirements}}
233+
// expected-error@-3 4{{generic class 'Bottom' has self-referential generic requirements}}
234234
// expected-note@-4 {{while resolving type 'Bottom<Top>'}}
235235
// expected-note@-5 {{through reference here}}
236236

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=on
2+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
3+
4+
protocol P1 {}
5+
6+
protocol P2 {}
7+
8+
protocol IteratorProtocol {
9+
associatedtype Element
10+
11+
func next() -> Element?
12+
}
13+
14+
// CHECK: requirement_inference_funny_order.(file).LocalArray@
15+
// CHECK: Generic signature: <Element where Element : P1>
16+
17+
// CHECK: ExtensionDecl line={{[0-9]+}} base=LocalArray
18+
// CHECK: Generic signature: <Element where Element : P1, Element : P2>
19+
extension LocalArray where Element : P2 {
20+
static func ==(lhs: Self, rhs: Self) -> Bool {}
21+
}
22+
23+
struct LocalArray<Element : P1>: IteratorProtocol {
24+
func next() -> Element? {}
25+
}

test/decl/protocol/req/recursion.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extension SomeProtocol where T == Optional<T> { } // expected-error{{same-type c
1010

1111
class X<T> where T == X { // expected-error{{same-type constraint 'T' == 'X<T>' is recursive}}
1212
// expected-error@-1{{same-type requirement makes generic parameter 'T' non-generic}}
13+
// expected-error@-2 3{{generic class 'X' has self-referential generic requirements}}
1314
var type: T { return Swift.type(of: self) } // expected-error{{cannot convert return expression of type 'X<T>.Type' to return type 'T'}}
1415
}
1516

@@ -44,7 +45,7 @@ public protocol P {
4445
}
4546

4647
public struct S<A: P> where A.T == S<A> {
47-
// expected-error@-1 {{generic struct 'S' has self-referential generic requirements}}
48+
// expected-error@-1 4{{generic struct 'S' has self-referential generic requirements}}
4849
// expected-note@-2 {{while resolving type 'S<A>'}}
4950
func f(a: A.T) {
5051
g(a: id(t: a)) // `a` has error type which is diagnosed as circular reference
@@ -70,7 +71,7 @@ protocol PI {
7071
}
7172

7273
struct SI<A: PI> : I where A : I, A.T == SI<A> {
73-
// expected-error@-1 {{generic struct 'SI' has self-referential generic requirements}}
74+
// expected-error@-1 4{{generic struct 'SI' has self-referential generic requirements}}
7475
// expected-note@-2 {{while resolving type 'SI<A>'}}
7576
func ggg<T : I>(t: T.Type) -> T {
7677
return T()
@@ -98,7 +99,9 @@ struct S5<A: PI> : I where A : I, A.T == S4<A> { }
9899

99100
// Used to hit ArchetypeBuilder assertions
100101
struct SU<A: P> where A.T == SU {
102+
// expected-error@-1 3{{generic struct 'SU' has self-referential generic requirements}}
101103
}
102104

103105
struct SIU<A: PI> : I where A : I, A.T == SIU {
106+
// expected-error@-1 3{{generic struct 'SIU' has self-referential generic requirements}}
104107
}

validation-test/compiler_crashers_2_fixed/0064-rdar27627862.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// RUN: %target-swift-frontend %s -emit-ir
1+
// RUN: %target-typecheck-verify-swift
22

33
enum Term<S> where S: Sequence, S.Iterator.Element == Term {
4+
// expected-error@-1 3{{generic enum 'Term' has self-referential generic requirements}}
45
case Cons(head: String, tail: S)
56
}
67

0 commit comments

Comments
 (0)