@@ -38,6 +38,15 @@ struct GetID<C: RandomAccessCollection, ID> {
3838 }
3939}
4040
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+
4150// CHECK-LABEL: sil {{.*}} @$s4test0A6SimpleyyySiAA3StrVXEXEF :
4251// CHECK-NOT: keypath
4352// CHECK-LABEL: } // end sil function '$s4test0A6SimpleyyySiAA3StrVXEXEF'
@@ -68,6 +77,17 @@ func testGenericEscapingClosure() -> GetID<[Str], Int> {
6877 GetID ( id: \. i)
6978}
7079
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+
7191// CHECK-LABEL: sil {{.*}} @$s4test0A7GenericyyyxAA6GenStrVyxGXEXElF :
7292// CHECK: keypath
7393// CHECK: keypath
@@ -91,6 +111,10 @@ public func _opaqueIdentity<T>(_ x: T) -> T {
91111// CHECK-NOT: keypath
92112// CHECK: } // end sil function '[[SPECIALIZED_CLOSURE]]'
93113
114+ // CHECK: sil shared {{.*}}@[[SPECIALIZED_CLOSURE2]] :
115+ // CHECK-NOT: keypath
116+ // CHECK: } // end sil function '[[SPECIALIZED_CLOSURE2]]'
117+
94118func calltests( ) {
95119 // CHECK-OUTPUT-LABEL: testSimple:
96120 print ( " testSimple: " )
@@ -130,6 +154,12 @@ func calltests() {
130154
131155 // CHECK-OUTPUT-NEXT: 27
132156 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 ( ) ) )
133163}
134164
135165calltests ( )
0 commit comments