@@ -210,11 +210,9 @@ struct TestKeyPathBuilder {
210
210
}
211
211
}
212
212
213
- // FIXME: Should return Self, but the closure specializer doesn't like that.
214
- // rdar://problem/31725007
215
213
extension AnyKeyPath {
216
214
static func build( capacityInBytes: Int ,
217
- withBuilder: ( inout TestKeyPathBuilder ) -> Void ) -> AnyKeyPath {
215
+ withBuilder: ( inout TestKeyPathBuilder ) -> Void ) -> Self {
218
216
return _create ( capacityInBytes: capacityInBytes) {
219
217
var builder = TestKeyPathBuilder ( buffer: $0)
220
218
withBuilder ( & builder)
@@ -228,25 +226,25 @@ keyPathImpl.test("struct components") {
228
226
. build ( capacityInBytes: 8 ) {
229
227
$0. addHeader ( trivial: true , hasReferencePrefix: false )
230
228
$0. addStructComponent ( offset: S< String> . x_offset)
231
- } as! WritableKeyPath < S < String > , Int >
229
+ }
232
230
233
231
let s_y = WritableKeyPath < S < String > , LifetimeTracked ? >
234
232
. build ( capacityInBytes: 8 ) {
235
233
$0. addHeader ( trivial: true , hasReferencePrefix: false )
236
234
$0. addStructComponent ( offset: S< String> . y_offset)
237
- } as! WritableKeyPath < S < String > , LifetimeTracked ? >
235
+ }
238
236
239
237
let s_z = WritableKeyPath < S < String > , String >
240
238
. build ( capacityInBytes: 8 ) {
241
239
$0. addHeader ( trivial: true , hasReferencePrefix: false )
242
240
$0. addStructComponent ( offset: S< String> . z_offset)
243
- } as! WritableKeyPath < S < String > , String >
241
+ }
244
242
245
243
let s_p = WritableKeyPath < S < String > , Point >
246
244
. build ( capacityInBytes: 8 ) {
247
245
$0. addHeader ( trivial: true , hasReferencePrefix: false )
248
246
$0. addStructComponent ( offset: S< String> . p_offset)
249
- } as! WritableKeyPath < S < String > , Point >
247
+ }
250
248
251
249
let twoComponentSize = 12 + MemoryLayout< Int> . size
252
250
let s_p_x = WritableKeyPath < S < String > , Double >
@@ -255,15 +253,15 @@ keyPathImpl.test("struct components") {
255
253
$0. addStructComponent ( offset: S< String> . p_offset)
256
254
$0. addType ( Point . self)
257
255
$0. addStructComponent ( offset: Point . x_offset)
258
- } as! WritableKeyPath < S < String > , Double >
256
+ }
259
257
260
258
let s_p_y = WritableKeyPath < S < String > , Double >
261
259
. build ( capacityInBytes: twoComponentSize) {
262
260
$0. addHeader ( trivial: true , hasReferencePrefix: false )
263
261
$0. addStructComponent ( offset: S< String> . p_offset)
264
262
$0. addType ( Point . self)
265
263
$0. addStructComponent ( offset: Point . y_offset)
266
- } as! WritableKeyPath < S < String > , Double >
264
+ }
267
265
268
266
269
267
// \("") forces the string to be computed at runtime (and therefore allocated)
@@ -336,19 +334,19 @@ keyPathImpl.test("class components") {
336
334
. build ( capacityInBytes: 8 ) {
337
335
$0. addHeader ( trivial: true , hasReferencePrefix: false )
338
336
$0. addClassComponent ( offset: C< String> . x_offset)
339
- } as! ReferenceWritableKeyPath < C < String > , Int >
337
+ }
340
338
341
339
let c_y = ReferenceWritableKeyPath < C < String > , LifetimeTracked ? >
342
340
. build ( capacityInBytes: 8 ) {
343
341
$0. addHeader ( trivial: true , hasReferencePrefix: false )
344
342
$0. addClassComponent ( offset: C< String> . y_offset)
345
- } as! ReferenceWritableKeyPath < C < String > , LifetimeTracked ? >
343
+ }
346
344
347
345
let c_z = ReferenceWritableKeyPath < C < String > , String >
348
346
. build ( capacityInBytes: 8 ) {
349
347
$0. addHeader ( trivial: true , hasReferencePrefix: false )
350
348
$0. addClassComponent ( offset: C< String> . z_offset)
351
- } as! ReferenceWritableKeyPath < C < String > , String >
349
+ }
352
350
353
351
let c = C ( x: 679 , y: nil , z: " buffalo \( " " ) " )
354
352
let value = c
@@ -402,7 +400,7 @@ keyPathImpl.test("reference prefix") {
402
400
endsReferencePrefix: true )
403
401
$0. addType ( C< String> . self )
404
402
$0. addClassComponent ( offset: C< String> . x_offset)
405
- } as! ReferenceWritableKeyPath < S < String > , Int >
403
+ }
406
404
407
405
let s_c_y = ReferenceWritableKeyPath < S < String > , LifetimeTracked ? >
408
406
. build ( capacityInBytes: 12 + MemoryLayout< Int> . size) {
@@ -411,7 +409,7 @@ keyPathImpl.test("reference prefix") {
411
409
endsReferencePrefix: true )
412
410
$0. addType ( C< String> . self )
413
411
$0. addClassComponent ( offset: C< String> . y_offset)
414
- } as! ReferenceWritableKeyPath < S < String > , LifetimeTracked ? >
412
+ }
415
413
416
414
let s_c_z = ReferenceWritableKeyPath < S < String > , String >
417
415
. build ( capacityInBytes: 12 + MemoryLayout< Int> . size) {
@@ -420,7 +418,7 @@ keyPathImpl.test("reference prefix") {
420
418
endsReferencePrefix: true )
421
419
$0. addType ( C< String> . self )
422
420
$0. addClassComponent ( offset: C< String> . z_offset)
423
- } as! ReferenceWritableKeyPath < S < String > , String >
421
+ }
424
422
425
423
let c = C ( x: 679 , y: nil , z: " buffalo \( " " ) " )
426
424
let value = S ( x: 1738 , y: nil , z: " bottles of beer \( " " ) " ,
@@ -490,14 +488,14 @@ keyPathImpl.test("overflowed offsets") {
490
488
$0. addHeader ( trivial: true , hasReferencePrefix: false )
491
489
$0. addStructComponent ( offset: S< String> . p_offset,
492
490
forceOverflow: true )
493
- } as! WritableKeyPath < S < String > , Point >
491
+ }
494
492
495
493
let c_z = ReferenceWritableKeyPath < C < String > , String >
496
494
. build ( capacityInBytes: 12 ) {
497
495
$0. addHeader ( trivial: true , hasReferencePrefix: false )
498
496
$0. addClassComponent ( offset: C< String> . z_offset,
499
497
forceOverflow: true )
500
- } as! ReferenceWritableKeyPath < C < String > , String >
498
+ }
501
499
502
500
let c = C ( x: 679 , y: LifetimeTracked ( 42 ) , z: " buffalo \( " " ) " )
503
501
var sValue = S ( x: 1738 , y: LifetimeTracked ( 43 ) ,
@@ -532,7 +530,7 @@ keyPathImpl.test("equality") {
532
530
$0. addType ( Point . self)
533
531
// Point.x
534
532
$0. addStructComponent ( offset: Point . x_offset)
535
- } as! ReferenceWritableKeyPath < S < S < String > > , Double >
533
+ }
536
534
537
535
expectEqual ( s_c_z_p_x, s_c_z_p_x)
538
536
expectEqual ( s_c_z_p_x. hashValue, s_c_z_p_x. hashValue)
@@ -553,7 +551,7 @@ keyPathImpl.test("equality") {
553
551
$0. addType ( Point . self)
554
552
// Point.x
555
553
$0. addStructComponent ( offset: Point . x_offset)
556
- } as! ReferenceWritableKeyPath < S < S < String > > , Double >
554
+ }
557
555
558
556
expectEqual ( s_c_z_p_x, s_c_z_p_x_2)
559
557
expectEqual ( s_c_z_p_x. hashValue, s_c_z_p_x_2. hashValue)
@@ -581,7 +579,7 @@ keyPathImpl.test("equality") {
581
579
// Point.x
582
580
$0. addStructComponent ( offset: Point . x_offset,
583
581
forceOverflow: true )
584
- } as! ReferenceWritableKeyPath < S < S < String > > , Double >
582
+ }
585
583
586
584
expectEqual ( s_c_z_p_x, s_c_z_p_x_3)
587
585
expectEqual ( s_c_z_p_x. hashValue, s_c_z_p_x_3. hashValue)
@@ -605,7 +603,7 @@ keyPathImpl.test("equality") {
605
603
$0. addType ( Point . self)
606
604
// Point.y
607
605
$0. addStructComponent ( offset: Point . y_offset)
608
- } as! ReferenceWritableKeyPath < S < S < String > > , Double >
606
+ }
609
607
610
608
expectNotEqual ( s_c_z_p_x, s_c_z_p_y)
611
609
expectNotEqual ( s_c_z_p_y, s_c_z_p_x)
@@ -623,7 +621,7 @@ keyPathImpl.test("equality") {
623
621
$0. addType ( S< String> . self )
624
622
// S<String>.p
625
623
$0. addStructComponent ( offset: S< String> . p_offset)
626
- } as! ReferenceWritableKeyPath < S < S < String > > , Point >
624
+ }
627
625
628
626
expectNotEqual ( s_c_z_p_x, s_c_z_p)
629
627
expectNotEqual ( s_c_z_p, s_c_z_p_x)
@@ -643,7 +641,7 @@ keyPathImpl.test("equality") {
643
641
$0. addType ( Point . self)
644
642
// Point.x
645
643
$0. addStructComponent ( offset: Point . x_offset)
646
- } as! KeyPath < S < S < String > > , Double >
644
+ }
647
645
648
646
expectNotEqual ( s_c_z_p_x, s_c_z_p_x_readonly)
649
647
expectNotEqual ( s_c_z_p_x_readonly, s_c_z_p_x)
@@ -657,7 +655,7 @@ keyPathImpl.test("equality") {
657
655
$0. addType ( Point . self)
658
656
// Point.y
659
657
$0. addStructComponent ( offset: Point . y_offset)
660
- } as! KeyPath < S < S < String > > , Double >
658
+ }
661
659
662
660
expectNotEqual ( s_p_y_readonly, s_c_z_p_x_readonly)
663
661
expectNotEqual ( s_c_z_p_x_readonly, s_p_y_readonly)
@@ -673,7 +671,7 @@ keyPathImpl.test("equality") {
673
671
$0. addType ( Oroborous . self)
674
672
// O.o
675
673
$0. addClassComponent ( offset: classHeaderSize)
676
- } as! ReferenceWritableKeyPath < Oroborous , Oroborous >
674
+ }
677
675
678
676
// Different reference prefix length
679
677
let o_o_o_o_rp1 = ReferenceWritableKeyPath < Oroborous , Oroborous >
@@ -688,7 +686,7 @@ keyPathImpl.test("equality") {
688
686
$0. addType ( Oroborous . self)
689
687
// O.o
690
688
$0. addClassComponent ( offset: classHeaderSize)
691
- } as! ReferenceWritableKeyPath < Oroborous , Oroborous >
689
+ }
692
690
let o_o_o_o_rp2 = ReferenceWritableKeyPath < Oroborous , Oroborous >
693
691
. build ( capacityInBytes: 16 + 2 * MemoryLayout< Int> . size) {
694
692
$0. addHeader ( trivial: true , hasReferencePrefix: true )
@@ -701,7 +699,7 @@ keyPathImpl.test("equality") {
701
699
$0. addType ( Oroborous . self)
702
700
// O.o
703
701
$0. addClassComponent ( offset: classHeaderSize)
704
- } as! ReferenceWritableKeyPath < Oroborous , Oroborous >
702
+ }
705
703
let o_o_o_o_rp2_2 = ReferenceWritableKeyPath < Oroborous , Oroborous >
706
704
. build ( capacityInBytes: 16 + 2 * MemoryLayout< Int> . size) {
707
705
$0. addHeader ( trivial: true , hasReferencePrefix: true )
@@ -714,7 +712,7 @@ keyPathImpl.test("equality") {
714
712
$0. addType ( Oroborous . self)
715
713
// O.o
716
714
$0. addClassComponent ( offset: classHeaderSize)
717
- } as! ReferenceWritableKeyPath < Oroborous , Oroborous >
715
+ }
718
716
719
717
expectNotEqual ( o_o_o_o, o_o_o_o_rp1)
720
718
expectNotEqual ( o_o_o_o_rp1, o_o_o_o)
@@ -738,7 +736,7 @@ keyPathImpl.test("equality") {
738
736
$0. addType ( Oroborous . self)
739
737
// O.o
740
738
$0. addClassComponent ( offset: classHeaderSize)
741
- } as! ReferenceWritableKeyPath < Oroborous , Oroborous >
739
+ }
742
740
743
741
expectNotEqual ( o_o_o, o_o_o_o)
744
742
expectNotEqual ( o_o_o_o, o_o_o)
@@ -749,12 +747,12 @@ keyPathImpl.test("appending") {
749
747
. build ( capacityInBytes: 8 ) {
750
748
$0. addHeader ( trivial: true , hasReferencePrefix: false )
751
749
$0. addStructComponent ( offset: S< String> . p_offset)
752
- } as! WritableKeyPath < S < String > , Point >
750
+ }
753
751
let p_y = WritableKeyPath < Point , Double >
754
752
. build ( capacityInBytes: 8 ) {
755
753
$0. addHeader ( trivial: true , hasReferencePrefix: false )
756
754
$0. addStructComponent ( offset: Point . y_offset)
757
- } as! WritableKeyPath < Point , Double >
755
+ }
758
756
759
757
let s_p_y = s_p. appending ( path: p_y)
760
758
@@ -779,7 +777,7 @@ keyPathImpl.test("appending") {
779
777
$0. addStructComponent ( offset: S< String> . p_offset)
780
778
$0. addType ( Point . self)
781
779
$0. addStructComponent ( offset: Point . y_offset)
782
- } as! WritableKeyPath < S < String > , Double >
780
+ }
783
781
expectEqual ( s_p_y, s_p_y_manual)
784
782
expectEqual ( s_p_y_manual, s_p_y)
785
783
expectEqual ( s_p_y. hashValue, s_p_y_manual. hashValue)
@@ -788,7 +786,7 @@ keyPathImpl.test("appending") {
788
786
. build ( capacityInBytes: 8 ) {
789
787
$0. addHeader ( trivial: true , hasReferencePrefix: false )
790
788
$0. addClassComponent ( offset: C< S< String>>. z_offset)
791
- } as! ReferenceWritableKeyPath < C < S < String > > , S < String > >
789
+ }
792
790
793
791
let value2 = C ( x: 17 , y: LifetimeTracked ( 38 ) , z: value)
794
792
@@ -808,7 +806,7 @@ keyPathImpl.test("appending") {
808
806
$0. addStructComponent ( offset: S< String> . p_offset)
809
807
$0. addType ( Point . self)
810
808
$0. addStructComponent ( offset: Point . y_offset)
811
- } as! ReferenceWritableKeyPath < C < S < String > > , Double >
809
+ }
812
810
813
811
expectEqual ( c_z_p_y, c_z_p_y_manual)
814
812
expectEqual ( c_z_p_y_manual, c_z_p_y)
@@ -818,7 +816,7 @@ keyPathImpl.test("appending") {
818
816
. build ( capacityInBytes: 8 ) {
819
817
$0. addHeader ( trivial: true , hasReferencePrefix: false )
820
818
$0. addStructComponent ( offset: S< S< String>>. c_offset)
821
- } as! WritableKeyPath < S < S < String > > , C < S < String > > >
819
+ }
822
820
823
821
let s_c_z_p_y = s_c. appending ( path: c_z_p_y)
824
822
@@ -840,7 +838,7 @@ keyPathImpl.test("appending") {
840
838
$0. addStructComponent ( offset: S< String> . p_offset)
841
839
$0. addType ( Point . self)
842
840
$0. addStructComponent ( offset: Point . y_offset)
843
- } as! ReferenceWritableKeyPath < S < S < String > > , Double >
841
+ }
844
842
845
843
expectEqual ( s_c_z_p_y, s_c_z_p_y_manual)
846
844
expectEqual ( s_c_z_p_y_manual, s_c_z_p_y)
@@ -854,7 +852,7 @@ keyPathImpl.test("appending") {
854
852
endsReferencePrefix: true )
855
853
$0. addType ( Crate< S< S< String>>> . self )
856
854
$0. addClassComponent ( offset: Crate< S< S< String>>> . value_offset)
857
- } as! ReferenceWritableKeyPath < CP , S < S < String > > >
855
+ }
858
856
859
857
let cratePair_left_value_c_z_p_y
860
858
= cratePair_left_value. appending ( path: s_c_z_p_y)
@@ -884,7 +882,7 @@ keyPathImpl.test("appending") {
884
882
$0. addStructComponent ( offset: S< String> . p_offset)
885
883
$0. addType ( Point . self)
886
884
$0. addStructComponent ( offset: Point . y_offset)
887
- } as! ReferenceWritableKeyPath < CP , Double >
885
+ }
888
886
expectEqual ( cratePair_left_value_c_z_p_y,
889
887
cratePair_left_value_c_z_p_y_manual)
890
888
expectEqual ( cratePair_left_value_c_z_p_y_manual,
0 commit comments