Skip to content

Commit b5e538d

Browse files
authored
Merge pull request #9422 from jckarter/remove-self-return-workarounds
Remove workarounds for 31725007 from KeyPathImplementation test.
2 parents 62e8028 + 63c8123 commit b5e538d

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

test/stdlib/KeyPathImplementation.swift

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,9 @@ struct TestKeyPathBuilder {
210210
}
211211
}
212212

213-
// FIXME: Should return Self, but the closure specializer doesn't like that.
214-
// rdar://problem/31725007
215213
extension AnyKeyPath {
216214
static func build(capacityInBytes: Int,
217-
withBuilder: (inout TestKeyPathBuilder) -> Void) -> AnyKeyPath {
215+
withBuilder: (inout TestKeyPathBuilder) -> Void) -> Self {
218216
return _create(capacityInBytes: capacityInBytes) {
219217
var builder = TestKeyPathBuilder(buffer: $0)
220218
withBuilder(&builder)
@@ -228,25 +226,25 @@ keyPathImpl.test("struct components") {
228226
.build(capacityInBytes: 8) {
229227
$0.addHeader(trivial: true, hasReferencePrefix: false)
230228
$0.addStructComponent(offset: S<String>.x_offset)
231-
} as! WritableKeyPath<S<String>, Int>
229+
}
232230

233231
let s_y = WritableKeyPath<S<String>, LifetimeTracked?>
234232
.build(capacityInBytes: 8) {
235233
$0.addHeader(trivial: true, hasReferencePrefix: false)
236234
$0.addStructComponent(offset: S<String>.y_offset)
237-
} as! WritableKeyPath<S<String>, LifetimeTracked?>
235+
}
238236

239237
let s_z = WritableKeyPath<S<String>, String>
240238
.build(capacityInBytes: 8) {
241239
$0.addHeader(trivial: true, hasReferencePrefix: false)
242240
$0.addStructComponent(offset: S<String>.z_offset)
243-
} as! WritableKeyPath<S<String>, String>
241+
}
244242

245243
let s_p = WritableKeyPath<S<String>, Point>
246244
.build(capacityInBytes: 8) {
247245
$0.addHeader(trivial: true, hasReferencePrefix: false)
248246
$0.addStructComponent(offset: S<String>.p_offset)
249-
} as! WritableKeyPath<S<String>, Point>
247+
}
250248

251249
let twoComponentSize = 12 + MemoryLayout<Int>.size
252250
let s_p_x = WritableKeyPath<S<String>, Double>
@@ -255,15 +253,15 @@ keyPathImpl.test("struct components") {
255253
$0.addStructComponent(offset: S<String>.p_offset)
256254
$0.addType(Point.self)
257255
$0.addStructComponent(offset: Point.x_offset)
258-
} as! WritableKeyPath<S<String>, Double>
256+
}
259257

260258
let s_p_y = WritableKeyPath<S<String>, Double>
261259
.build(capacityInBytes: twoComponentSize) {
262260
$0.addHeader(trivial: true, hasReferencePrefix: false)
263261
$0.addStructComponent(offset: S<String>.p_offset)
264262
$0.addType(Point.self)
265263
$0.addStructComponent(offset: Point.y_offset)
266-
} as! WritableKeyPath<S<String>, Double>
264+
}
267265

268266

269267
// \("") forces the string to be computed at runtime (and therefore allocated)
@@ -336,19 +334,19 @@ keyPathImpl.test("class components") {
336334
.build(capacityInBytes: 8) {
337335
$0.addHeader(trivial: true, hasReferencePrefix: false)
338336
$0.addClassComponent(offset: C<String>.x_offset)
339-
} as! ReferenceWritableKeyPath<C<String>, Int>
337+
}
340338

341339
let c_y = ReferenceWritableKeyPath<C<String>, LifetimeTracked?>
342340
.build(capacityInBytes: 8) {
343341
$0.addHeader(trivial: true, hasReferencePrefix: false)
344342
$0.addClassComponent(offset: C<String>.y_offset)
345-
} as! ReferenceWritableKeyPath<C<String>, LifetimeTracked?>
343+
}
346344

347345
let c_z = ReferenceWritableKeyPath<C<String>, String>
348346
.build(capacityInBytes: 8) {
349347
$0.addHeader(trivial: true, hasReferencePrefix: false)
350348
$0.addClassComponent(offset: C<String>.z_offset)
351-
} as! ReferenceWritableKeyPath<C<String>, String>
349+
}
352350

353351
let c = C(x: 679, y: nil, z: "buffalo\("")")
354352
let value = c
@@ -402,7 +400,7 @@ keyPathImpl.test("reference prefix") {
402400
endsReferencePrefix: true)
403401
$0.addType(C<String>.self)
404402
$0.addClassComponent(offset: C<String>.x_offset)
405-
} as! ReferenceWritableKeyPath<S<String>, Int>
403+
}
406404

407405
let s_c_y = ReferenceWritableKeyPath<S<String>, LifetimeTracked?>
408406
.build(capacityInBytes: 12 + MemoryLayout<Int>.size) {
@@ -411,7 +409,7 @@ keyPathImpl.test("reference prefix") {
411409
endsReferencePrefix: true)
412410
$0.addType(C<String>.self)
413411
$0.addClassComponent(offset: C<String>.y_offset)
414-
} as! ReferenceWritableKeyPath<S<String>, LifetimeTracked?>
412+
}
415413

416414
let s_c_z = ReferenceWritableKeyPath<S<String>, String>
417415
.build(capacityInBytes: 12 + MemoryLayout<Int>.size) {
@@ -420,7 +418,7 @@ keyPathImpl.test("reference prefix") {
420418
endsReferencePrefix: true)
421419
$0.addType(C<String>.self)
422420
$0.addClassComponent(offset: C<String>.z_offset)
423-
} as! ReferenceWritableKeyPath<S<String>, String>
421+
}
424422

425423
let c = C(x: 679, y: nil, z: "buffalo\("")")
426424
let value = S(x: 1738, y: nil, z: "bottles of beer\("")",
@@ -490,14 +488,14 @@ keyPathImpl.test("overflowed offsets") {
490488
$0.addHeader(trivial: true, hasReferencePrefix: false)
491489
$0.addStructComponent(offset: S<String>.p_offset,
492490
forceOverflow: true)
493-
} as! WritableKeyPath<S<String>, Point>
491+
}
494492

495493
let c_z = ReferenceWritableKeyPath<C<String>, String>
496494
.build(capacityInBytes: 12) {
497495
$0.addHeader(trivial: true, hasReferencePrefix: false)
498496
$0.addClassComponent(offset: C<String>.z_offset,
499497
forceOverflow: true)
500-
} as! ReferenceWritableKeyPath<C<String>, String>
498+
}
501499

502500
let c = C(x: 679, y: LifetimeTracked(42), z: "buffalo\("")")
503501
var sValue = S(x: 1738, y: LifetimeTracked(43),
@@ -532,7 +530,7 @@ keyPathImpl.test("equality") {
532530
$0.addType(Point.self)
533531
// Point.x
534532
$0.addStructComponent(offset: Point.x_offset)
535-
} as! ReferenceWritableKeyPath<S<S<String>>, Double>
533+
}
536534

537535
expectEqual(s_c_z_p_x, s_c_z_p_x)
538536
expectEqual(s_c_z_p_x.hashValue, s_c_z_p_x.hashValue)
@@ -553,7 +551,7 @@ keyPathImpl.test("equality") {
553551
$0.addType(Point.self)
554552
// Point.x
555553
$0.addStructComponent(offset: Point.x_offset)
556-
} as! ReferenceWritableKeyPath<S<S<String>>, Double>
554+
}
557555

558556
expectEqual(s_c_z_p_x, s_c_z_p_x_2)
559557
expectEqual(s_c_z_p_x.hashValue, s_c_z_p_x_2.hashValue)
@@ -581,7 +579,7 @@ keyPathImpl.test("equality") {
581579
// Point.x
582580
$0.addStructComponent(offset: Point.x_offset,
583581
forceOverflow: true)
584-
} as! ReferenceWritableKeyPath<S<S<String>>, Double>
582+
}
585583

586584
expectEqual(s_c_z_p_x, s_c_z_p_x_3)
587585
expectEqual(s_c_z_p_x.hashValue, s_c_z_p_x_3.hashValue)
@@ -605,7 +603,7 @@ keyPathImpl.test("equality") {
605603
$0.addType(Point.self)
606604
// Point.y
607605
$0.addStructComponent(offset: Point.y_offset)
608-
} as! ReferenceWritableKeyPath<S<S<String>>, Double>
606+
}
609607

610608
expectNotEqual(s_c_z_p_x, s_c_z_p_y)
611609
expectNotEqual(s_c_z_p_y, s_c_z_p_x)
@@ -623,7 +621,7 @@ keyPathImpl.test("equality") {
623621
$0.addType(S<String>.self)
624622
// S<String>.p
625623
$0.addStructComponent(offset: S<String>.p_offset)
626-
} as! ReferenceWritableKeyPath<S<S<String>>, Point>
624+
}
627625

628626
expectNotEqual(s_c_z_p_x, s_c_z_p)
629627
expectNotEqual(s_c_z_p, s_c_z_p_x)
@@ -643,7 +641,7 @@ keyPathImpl.test("equality") {
643641
$0.addType(Point.self)
644642
// Point.x
645643
$0.addStructComponent(offset: Point.x_offset)
646-
} as! KeyPath<S<S<String>>, Double>
644+
}
647645

648646
expectNotEqual(s_c_z_p_x, s_c_z_p_x_readonly)
649647
expectNotEqual(s_c_z_p_x_readonly, s_c_z_p_x)
@@ -657,7 +655,7 @@ keyPathImpl.test("equality") {
657655
$0.addType(Point.self)
658656
// Point.y
659657
$0.addStructComponent(offset: Point.y_offset)
660-
} as! KeyPath<S<S<String>>, Double>
658+
}
661659

662660
expectNotEqual(s_p_y_readonly, s_c_z_p_x_readonly)
663661
expectNotEqual(s_c_z_p_x_readonly, s_p_y_readonly)
@@ -673,7 +671,7 @@ keyPathImpl.test("equality") {
673671
$0.addType(Oroborous.self)
674672
// O.o
675673
$0.addClassComponent(offset: classHeaderSize)
676-
} as! ReferenceWritableKeyPath<Oroborous, Oroborous>
674+
}
677675

678676
// Different reference prefix length
679677
let o_o_o_o_rp1 = ReferenceWritableKeyPath<Oroborous, Oroborous>
@@ -688,7 +686,7 @@ keyPathImpl.test("equality") {
688686
$0.addType(Oroborous.self)
689687
// O.o
690688
$0.addClassComponent(offset: classHeaderSize)
691-
} as! ReferenceWritableKeyPath<Oroborous, Oroborous>
689+
}
692690
let o_o_o_o_rp2 = ReferenceWritableKeyPath<Oroborous, Oroborous>
693691
.build(capacityInBytes: 16 + 2*MemoryLayout<Int>.size) {
694692
$0.addHeader(trivial: true, hasReferencePrefix: true)
@@ -701,7 +699,7 @@ keyPathImpl.test("equality") {
701699
$0.addType(Oroborous.self)
702700
// O.o
703701
$0.addClassComponent(offset: classHeaderSize)
704-
} as! ReferenceWritableKeyPath<Oroborous, Oroborous>
702+
}
705703
let o_o_o_o_rp2_2 = ReferenceWritableKeyPath<Oroborous, Oroborous>
706704
.build(capacityInBytes: 16 + 2*MemoryLayout<Int>.size) {
707705
$0.addHeader(trivial: true, hasReferencePrefix: true)
@@ -714,7 +712,7 @@ keyPathImpl.test("equality") {
714712
$0.addType(Oroborous.self)
715713
// O.o
716714
$0.addClassComponent(offset: classHeaderSize)
717-
} as! ReferenceWritableKeyPath<Oroborous, Oroborous>
715+
}
718716

719717
expectNotEqual(o_o_o_o, o_o_o_o_rp1)
720718
expectNotEqual(o_o_o_o_rp1, o_o_o_o)
@@ -738,7 +736,7 @@ keyPathImpl.test("equality") {
738736
$0.addType(Oroborous.self)
739737
// O.o
740738
$0.addClassComponent(offset: classHeaderSize)
741-
} as! ReferenceWritableKeyPath<Oroborous, Oroborous>
739+
}
742740

743741
expectNotEqual(o_o_o, o_o_o_o)
744742
expectNotEqual(o_o_o_o, o_o_o)
@@ -749,12 +747,12 @@ keyPathImpl.test("appending") {
749747
.build(capacityInBytes: 8) {
750748
$0.addHeader(trivial: true, hasReferencePrefix: false)
751749
$0.addStructComponent(offset: S<String>.p_offset)
752-
} as! WritableKeyPath<S<String>, Point>
750+
}
753751
let p_y = WritableKeyPath<Point, Double>
754752
.build(capacityInBytes: 8) {
755753
$0.addHeader(trivial: true, hasReferencePrefix: false)
756754
$0.addStructComponent(offset: Point.y_offset)
757-
} as! WritableKeyPath<Point, Double>
755+
}
758756

759757
let s_p_y = s_p.appending(path: p_y)
760758

@@ -779,7 +777,7 @@ keyPathImpl.test("appending") {
779777
$0.addStructComponent(offset: S<String>.p_offset)
780778
$0.addType(Point.self)
781779
$0.addStructComponent(offset: Point.y_offset)
782-
} as! WritableKeyPath<S<String>, Double>
780+
}
783781
expectEqual(s_p_y, s_p_y_manual)
784782
expectEqual(s_p_y_manual, s_p_y)
785783
expectEqual(s_p_y.hashValue, s_p_y_manual.hashValue)
@@ -788,7 +786,7 @@ keyPathImpl.test("appending") {
788786
.build(capacityInBytes: 8) {
789787
$0.addHeader(trivial: true, hasReferencePrefix: false)
790788
$0.addClassComponent(offset: C<S<String>>.z_offset)
791-
} as! ReferenceWritableKeyPath<C<S<String>>, S<String>>
789+
}
792790

793791
let value2 = C(x: 17, y: LifetimeTracked(38), z: value)
794792

@@ -808,7 +806,7 @@ keyPathImpl.test("appending") {
808806
$0.addStructComponent(offset: S<String>.p_offset)
809807
$0.addType(Point.self)
810808
$0.addStructComponent(offset: Point.y_offset)
811-
} as! ReferenceWritableKeyPath<C<S<String>>, Double>
809+
}
812810

813811
expectEqual(c_z_p_y, c_z_p_y_manual)
814812
expectEqual(c_z_p_y_manual, c_z_p_y)
@@ -818,7 +816,7 @@ keyPathImpl.test("appending") {
818816
.build(capacityInBytes: 8) {
819817
$0.addHeader(trivial: true, hasReferencePrefix: false)
820818
$0.addStructComponent(offset: S<S<String>>.c_offset)
821-
} as! WritableKeyPath<S<S<String>>, C<S<String>>>
819+
}
822820

823821
let s_c_z_p_y = s_c.appending(path: c_z_p_y)
824822

@@ -840,7 +838,7 @@ keyPathImpl.test("appending") {
840838
$0.addStructComponent(offset: S<String>.p_offset)
841839
$0.addType(Point.self)
842840
$0.addStructComponent(offset: Point.y_offset)
843-
} as! ReferenceWritableKeyPath<S<S<String>>, Double>
841+
}
844842

845843
expectEqual(s_c_z_p_y, s_c_z_p_y_manual)
846844
expectEqual(s_c_z_p_y_manual, s_c_z_p_y)
@@ -854,7 +852,7 @@ keyPathImpl.test("appending") {
854852
endsReferencePrefix: true)
855853
$0.addType(Crate<S<S<String>>>.self)
856854
$0.addClassComponent(offset: Crate<S<S<String>>>.value_offset)
857-
} as! ReferenceWritableKeyPath<CP, S<S<String>>>
855+
}
858856

859857
let cratePair_left_value_c_z_p_y
860858
= cratePair_left_value.appending(path: s_c_z_p_y)
@@ -884,7 +882,7 @@ keyPathImpl.test("appending") {
884882
$0.addStructComponent(offset: S<String>.p_offset)
885883
$0.addType(Point.self)
886884
$0.addStructComponent(offset: Point.y_offset)
887-
} as! ReferenceWritableKeyPath<CP, Double>
885+
}
888886
expectEqual(cratePair_left_value_c_z_p_y,
889887
cratePair_left_value_c_z_p_y_manual)
890888
expectEqual(cratePair_left_value_c_z_p_y_manual,

0 commit comments

Comments
 (0)