@@ -38,6 +38,15 @@ struct GetID<C: RandomAccessCollection, ID> {
38
38
}
39
39
}
40
40
41
+ struct GetInt < C: RandomAccessCollection > {
42
+ var getInt : ( C . Element ) -> Int
43
+
44
+ @inline ( __always)
45
+ init ( keyPath: KeyPath < C . Element , Int > , i: Int ) {
46
+ getInt = { $0 [ keyPath: keyPath] + i }
47
+ }
48
+ }
49
+
41
50
// CHECK-LABEL: sil {{.*}} @$s4test0A6SimpleyyySiAA3StrVXEXEF :
42
51
// CHECK-NOT: keypath
43
52
// CHECK-LABEL: } // end sil function '$s4test0A6SimpleyyySiAA3StrVXEXEF'
@@ -68,6 +77,17 @@ func testGenericEscapingClosure() -> GetID<[Str], Int> {
68
77
GetID ( id: \. i)
69
78
}
70
79
80
+ // CHECK-LABEL: sil {{.*}} @$s4test0A22KeypathWithNonConstInt1iAA03GetF0VySayAA3StrVGGSi_tF :
81
+ // CHECK-NOT: keypath
82
+ // CHECK: [[C:%.*]] = function_ref @[[SPECIALIZED_CLOSURE2:.*]] : $@convention(thin) (@in_guaranteed Str, Int) -> Int
83
+ // CHECK-NEXT: partial_apply [callee_guaranteed] [[C]](%0) : $@convention(thin) (@in_guaranteed Str, Int) -> Int
84
+ // CHECK-NOT: keypath
85
+ // CHECK-LABEL: } // end sil function '$s4test0A22KeypathWithNonConstInt1iAA03GetF0VySayAA3StrVGGSi_tF'
86
+ @inline ( never)
87
+ func testKeypathWithNonConstInt( i: Int ) -> GetInt < [ Str ] > {
88
+ GetInt ( keyPath: \. j, i: i)
89
+ }
90
+
71
91
// CHECK-LABEL: sil {{.*}} @$s4test0A7GenericyyyxAA6GenStrVyxGXEXElF :
72
92
// CHECK: keypath
73
93
// CHECK: keypath
@@ -91,6 +111,10 @@ public func _opaqueIdentity<T>(_ x: T) -> T {
91
111
// CHECK-NOT: keypath
92
112
// CHECK: } // end sil function '[[SPECIALIZED_CLOSURE]]'
93
113
114
+ // CHECK: sil shared {{.*}}@[[SPECIALIZED_CLOSURE2]] :
115
+ // CHECK-NOT: keypath
116
+ // CHECK: } // end sil function '[[SPECIALIZED_CLOSURE2]]'
117
+
94
118
func calltests( ) {
95
119
// CHECK-OUTPUT-LABEL: testSimple:
96
120
print ( " testSimple: " )
@@ -130,6 +154,12 @@ func calltests() {
130
154
131
155
// CHECK-OUTPUT-NEXT: 27
132
156
print ( testGenericEscapingClosure ( ) . getID ( Str ( ) ) )
157
+
158
+ // CHECK-OUTPUT-LABEL: testKeypathWithNonConstInt:
159
+ print ( " testKeypathWithNonConstInt: " )
160
+
161
+ // CHECK-OUTPUT-NEXT: 38
162
+ print ( testKeypathWithNonConstInt ( i: 10 ) . getInt ( Str ( ) ) )
133
163
}
134
164
135
165
calltests ( )
0 commit comments