File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1293,6 +1293,10 @@ optimizeBridgedCasts(SILInstruction *Inst,
1293
1293
!source.getStructOrBoundGenericStruct ()))
1294
1294
return nullptr ;
1295
1295
1296
+ // Casts involving non-bound generic types cannot be optimized.
1297
+ if (source->hasArchetype () || target->hasArchetype ())
1298
+ return nullptr ;
1299
+
1296
1300
auto BridgedTargetTy = getCastFromObjC (M, source, target);
1297
1301
if (!BridgedTargetTy)
1298
1302
return nullptr ;
Original file line number Diff line number Diff line change @@ -620,6 +620,44 @@ public func testCondCastSwiftToNSSetString() -> NSSet? {
620
620
return setOpt
621
621
}
622
622
623
+ // Casts involving generics cannot be optimized.
624
+
625
+ // CHECK-LABEL: sil [noinline] @_TF21bridged_casts_folding25testForcedCastFromGenericurFq_CSo8NSString
626
+ // CHECK: unconditional_checked
627
+ // CHECK: return
628
+ @inline ( never)
629
+ public func testForcedCastFromGeneric< T> ( x: T ) -> NSString {
630
+ var set : NSString = x as! NSString
631
+ return set
632
+ }
633
+
634
+ // CHECK-LABEL: sil [noinline] @_TF21bridged_casts_folding23testForcedCastToGenericurFq_q_
635
+ // CHECK: unconditional_checked
636
+ // CHECK: return
637
+ @inline ( never)
638
+ public func testForcedCastToGeneric< T> ( x: T ) -> T {
639
+ var set : T = nsString as! T
640
+ return set
641
+ }
642
+
643
+ // CHECK-LABEL: sil [noinline] @_TF21bridged_casts_folding23testCondCastFromGenericurFq_GSqCSo8NSString_
644
+ // CHECK: checked_cast_addr_br
645
+ // CHECK: return
646
+ @inline ( never)
647
+ public func testCondCastFromGeneric< T> ( x: T ) -> NSString ? {
648
+ var setOpt : NSString ? = x as? NSString
649
+ return setOpt
650
+ }
651
+
652
+ // CHECK-LABEL: sil [noinline] @_TF21bridged_casts_folding21testCondCastToGenericurFq_GSqq__
653
+ // CHECK: checked_cast_addr_br
654
+ // CHECK: return
655
+ @inline ( never)
656
+ public func testCondCastToGeneric< T> ( x: T ) -> T ? {
657
+ var setOpt : T ? = nsString as? T
658
+ return setOpt
659
+ }
660
+
623
661
624
662
// Run-time tests
625
663
You can’t perform that action at this time.
0 commit comments