|
| 1 | +// RUN: %target-swift-frontend -Xllvm -sil-print-types -module-name=dynamic_self_cast -emit-silgen %s | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: objc_interop |
| 4 | + |
| 5 | +public class SelfCasts { |
| 6 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC02toD0yACXDACFZ : $@convention(method) (@guaranteed SelfCasts, @thick SelfCasts.Type) -> @owned SelfCasts { |
| 7 | + // CHECK: unconditional_checked_cast {{.*}} : $SelfCasts to @dynamic_self SelfCasts |
| 8 | + // CHECK: } |
| 9 | + public static func toSelf(_ s: SelfCasts) -> Self { |
| 10 | + return s as! Self |
| 11 | + } |
| 12 | + |
| 13 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC09genericToD0yACXDxlFZ : $@convention(method) <T> (@in_guaranteed T, @thick SelfCasts.Type) -> @owned SelfCasts { |
| 14 | + // CHECK: unconditional_checked_cast_addr T in {{.*}} : $*T to @dynamic_self SelfCasts in {{.*}} : $*SelfCasts |
| 15 | + // CHECK: } |
| 16 | + public static func genericToSelf<T>(_ s: T) -> Self { |
| 17 | + return s as! Self |
| 18 | + } |
| 19 | + |
| 20 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC014classGenericToD0yACXDxRlzClFZ : $@convention(method) <T where T : AnyObject> (@guaranteed T, @thick SelfCasts.Type) -> @owned SelfCasts { |
| 21 | + // CHECK: unconditional_checked_cast {{.*}} : $T to @dynamic_self SelfCasts |
| 22 | + // CHECK: } |
| 23 | + public static func classGenericToSelf<T : AnyObject>(_ s: T) -> Self { |
| 24 | + return s as! Self |
| 25 | + } |
| 26 | + |
| 27 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC011genericFromD0xylFZ : $@convention(method) <T> (@thick SelfCasts.Type) -> @out T { |
| 28 | + // CHECK: unconditional_checked_cast_addr @dynamic_self SelfCasts in {{.*}} : $*SelfCasts to T in {{.*}} : $*T |
| 29 | + // CHECK: } |
| 30 | + public static func genericFromSelf<T>() -> T { |
| 31 | + let s = Self() |
| 32 | + return s as! T |
| 33 | + } |
| 34 | + |
| 35 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC016classGenericFromD0xyRlzClFZ : $@convention(method) <T where T : AnyObject> (@thick SelfCasts.Type) -> @owned T |
| 36 | + // CHECK: unconditional_checked_cast_addr @dynamic_self SelfCasts in {{.*}} : $*SelfCasts to T in {{.*}} : $*T |
| 37 | + // CHECK: } |
| 38 | + public static func classGenericFromSelf<T : AnyObject>() -> T { |
| 39 | + let s = Self() |
| 40 | + return s as! T |
| 41 | + } |
| 42 | + |
| 43 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC02toD11ConditionalyACXDSgACFZ : $@convention(method) (@guaranteed SelfCasts, @thick SelfCasts.Type) -> @owned Optional<SelfCasts> { |
| 44 | + // CHECK: checked_cast_br SelfCasts in {{.*}} : $SelfCasts to @dynamic_self SelfCasts |
| 45 | + // CHECK: } |
| 46 | + public static func toSelfConditional(_ s: SelfCasts) -> Self? { |
| 47 | + return s as? Self |
| 48 | + } |
| 49 | + |
| 50 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC09genericToD11ConditionalyACXDSgxlFZ : $@convention(method) <T> (@in_guaranteed T, @thick SelfCasts.Type) -> @owned Optional<SelfCasts> { |
| 51 | + // CHECK: checked_cast_addr_br take_always T in {{.*}} : $*T to @dynamic_self SelfCasts in {{.*}} : $*SelfCasts |
| 52 | + // CHECK: } |
| 53 | + public static func genericToSelfConditional<T>(_ s: T) -> Self? { |
| 54 | + return s as? Self |
| 55 | + } |
| 56 | + |
| 57 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC014classGenericToD11ConditionalyACXDSgxRlzClFZ : $@convention(method) <T where T : AnyObject> (@guaranteed T, @thick SelfCasts.Type) -> @owned Optional<SelfCasts> { |
| 58 | + // CHECK: checked_cast_br T in {{.*}} : $T to @dynamic_self SelfCasts |
| 59 | + // CHECK: } |
| 60 | + public static func classGenericToSelfConditional<T : AnyObject>(_ s: T) -> Self? { |
| 61 | + return s as? Self |
| 62 | + } |
| 63 | + |
| 64 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC011genericFromD11ConditionalxSgylFZ : $@convention(method) <T> (@thick SelfCasts.Type) -> @out Optional<T> { |
| 65 | + // CHECK: checked_cast_addr_br take_always @dynamic_self SelfCasts in {{.*}} : $*SelfCasts to T in {{.*}} : $*T |
| 66 | + // CHECK: } |
| 67 | + public static func genericFromSelfConditional<T>() -> T? { |
| 68 | + let s = Self() |
| 69 | + return s as? T |
| 70 | + } |
| 71 | + |
| 72 | + // CHECK-LABEL: sil [ossa] @$s17dynamic_self_cast9SelfCastsC016classGenericFromD11ConditionalxSgyRlzClFZ : $@convention(method) <T where T : AnyObject> (@thick SelfCasts.Type) -> @owned Optional<T> { |
| 73 | + // CHECK: checked_cast_addr_br take_always @dynamic_self SelfCasts in {{.*}} : $*SelfCasts to T in {{.*}} : $*T |
| 74 | + // CHECK: } |
| 75 | + public static func classGenericFromSelfConditional<T : AnyObject>() -> T? { |
| 76 | + let s = Self() |
| 77 | + return s as? T |
| 78 | + } |
| 79 | + |
| 80 | + public required init() {} |
| 81 | +} |
| 82 | + |
0 commit comments