Skip to content

Commit 971537c

Browse files
authored
Merge pull request #38462 from slavapestov/requirement-machine-tests
RequirementMachine: Add a test that used to fail with the GSB
2 parents 4aaee48 + 91b81cb commit 971537c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public protocol P {
2+
associatedtype A: P
3+
}
4+
5+
public func bar<T: P>(from: T) {}
6+
7+
@inlinable public func foo<T, U>(from: T, to: U) where T == T.A, U : P, U.A == T {
8+
bar(from: from)
9+
}

test/Generics/conditional_requirement_inference.swift

Lines changed: 1 addition & 1 deletion
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=on
22
// RUN: not %target-swift-frontend -typecheck -debug-generic-signatures -requirement-machine=on %s 2>&1 | %FileCheck %s
33

44

test/Generics/rdar79564324.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %S/Inputs/rdar79564324_other.swift -emit-module-path %t/rdar79564324_other.swiftmodule -requirement-machine=on -debug-requirement-machine 2>&1 | %FileCheck %s
3+
// RUN: %target-swift-frontend -emit-silgen %s -I %t -requirement-machine=on
4+
5+
import rdar79564324_other
6+
7+
public func test<T : P>(_ t: T) where T == T.A {
8+
foo(from: t, to: t)
9+
}
10+
11+
// foo(from:to:) has minimal signature <T, U where T == T.A, U : P, T.A == U.A>.
12+
//
13+
// The GSB had trouble re-building after deserialization because of the two
14+
// requirements 'T == T.A' and 'T.A == U.A'.
15+
//
16+
// What should happen is that these two imply that 'T == U.A', and 'U : P'
17+
// implies the existence of 'U.A' and thus the conformance of T to P.
18+
//
19+
// Instead what happens is that 'T == T.A' and 'T.A == U.A' both get delayed
20+
// because T does not yet have a nested type A, so it gets stuck.
21+
//
22+
// The rewrite system handles this correctly though:
23+
24+
// CHECK-LABEL: Requirement machine for <τ_0_0, τ_0_1 where τ_0_0 == τ_0_0.A, τ_0_1 : P, τ_0_0.A == τ_0_1.A>
25+
// CHECK-NEXT: Rewrite system: {
26+
// CHECK-NEXT: - [P].A => [P:A]
27+
// CHECK-NEXT: - [P:A].[P] => [P:A]
28+
// CHECK-NEXT: - τ_0_0.[P:A] => τ_0_0
29+
// CHECK-NEXT: - τ_0_1.[P] => τ_0_1
30+
// CHECK-NEXT: - τ_0_1.[P:A] => τ_0_0
31+
// CHECK-NEXT: - [P:A].A => [P:A].[P:A]
32+
// CHECK-NEXT: - τ_0_0.[P] => τ_0_0
33+
// CHECK-NEXT: - τ_0_1.A => τ_0_0
34+
// CHECK-NEXT: - τ_0_0.A => τ_0_0
35+
// CHECK-NEXT: }
36+
// CHECK-NEXT: Equivalence class map: {
37+
// CHECK-NEXT: [P:A] => { conforms_to: [P] }
38+
// CHECK-NEXT: τ_0_0 => { conforms_to: [P] }
39+
// CHECK-NEXT: τ_0_1 => { conforms_to: [P] }
40+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)