// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types -module-name subclass_existentials -Xllvm -sil-full-demangle -parse-as-library -primary-file %s -verify | %FileCheck %s // RUN: %target-swift-emit-ir -module-name subclass_existentials -parse-as-library -primary-file %s // Note: we pass -verify above to ensure there are no spurious // compiler warnings relating to casts. protocol Q {} class Base : Q { required init(classInit: ()) {} func classSelfReturn() -> Self { return self } static func classSelfReturn() -> Self { return self.init(classInit: ()) } } protocol P { init(protocolInit: ()) func protocolSelfReturn() -> Self static func protocolSelfReturn() -> Self } class Derived : Base, P { required init(protocolInit: ()) { super.init(classInit: ()) } required init(classInit: ()) { super.init(classInit: ()) } func protocolSelfReturn() -> Self { return self } static func protocolSelfReturn() -> Self { return self.init(classInit: ()) } } protocol R {} // CHECK-LABEL: sil hidden [ossa] @$s21subclass_existentials11conversions8baseAndP7derived0fE1R0dE5PType0F4Type0fE5RTypeyAA1P_AA4BaseCySiGXc_AA7DerivedCAA1R_ANXcAaI_ALXcXpANmAaO_ANXcXptF : $@convention(thin) (@guaranteed any Base & P, @guaranteed Derived, @guaranteed any Derived & R, @thick any (Base & P).Type, @thick Derived.Type, @thick any (Derived & R).Type) -> () { // CHECK: bb0([[ARG0:%.*]] : @guaranteed $any Base & P, func conversions( baseAndP: Base & P, derived: Derived, derivedAndR: Derived & R, baseAndPType: (Base & P).Type, derivedType: Derived.Type, derivedAndRType: (Derived & R).Type) { // Values // CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[ARG0]] : $any Base & P // CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]] // CHECK: [[BASE:%.*]] = upcast [[REF]] : $@opened("{{.*}}", any Base & P) Self to $Base // CHECK: destroy_value [[BASE]] : $Base let _: Base = baseAndP // CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[ARG0]] : $any Base & P // CHECK: [[RESULT:%.*]] = alloc_stack $any P // CHECK: [[RESULT_PAYLOAD:%.*]] = init_existential_addr [[RESULT]] : $*any P, $@opened("{{.*}}", any Base & P) Self // CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]] // CHECK: store [[REF]] to [init] [[RESULT_PAYLOAD]] // CHECK: destroy_addr [[RESULT]] : $*any P // CHECK: dealloc_stack [[RESULT]] : $*any P let _: P = baseAndP // CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[ARG0]] : $any Base & P // CHECK: [[RESULT:%.*]] = alloc_stack $any Q // CHECK: [[RESULT_PAYLOAD:%.*]] = init_existential_addr [[RESULT]] : $*any Q, $@opened("{{.*}}", any Base & P) Self // CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]] // CHECK: store [[REF]] to [init] [[RESULT_PAYLOAD]] // CHECK: destroy_addr [[RESULT]] : $*any Q // CHECK: dealloc_stack [[RESULT]] : $*any Q let _: Q = baseAndP // CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[ARG2:%.*]] : $any Derived & R // CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]] // CHECK: [[RESULT:%.*]] = init_existential_ref [[REF]] : $@opened("{{.*}}", any Derived & R) Self : $@opened("{{.*}}", any Derived & R) Self, $any Base & P // CHECK: destroy_value [[RESULT]] let _: Base & P = derivedAndR // Metatypes // CHECK: [[PAYLOAD:%.*]] = open_existential_metatype %3 : $@thick any (Base & P).Type to $@thick (@opened("{{.*}}", any Base & P) Self).Type // CHECK: [[RESULT:%.*]] = upcast [[PAYLOAD]] : $@thick (@opened("{{.*}}", any Base & P) Self).Type to $@thick Base.Type let _: Base.Type = baseAndPType // CHECK: [[PAYLOAD:%.*]] = open_existential_metatype %3 : $@thick any (Base & P).Type to $@thick (@opened("{{.*}}", any Base & P) Self).Type // CHECK: [[RESULT:%.*]] = init_existential_metatype [[PAYLOAD]] : $@thick (@opened("{{.*}}", any Base & P) Self).Type, $@thick any P.Type let _: P.Type = baseAndPType // CHECK: [[PAYLOAD:%.*]] = open_existential_metatype %3 : $@thick any (Base & P).Type to $@thick (@opened("{{.*}}", any Base & P) Self).Type // CHECK: [[RESULT:%.*]] = init_existential_metatype [[PAYLOAD]] : $@thick (@opened("{{.*}}", any Base & P) Self).Type, $@thick any Q.Type let _: Q.Type = baseAndPType // CHECK: [[RESULT:%.*]] = init_existential_metatype %4 : $@thick Derived.Type, $@thick any (Base & P).Type let _: (Base & P).Type = derivedType // CHECK: [[PAYLOAD:%.*]] = open_existential_metatype %5 : $@thick any (Derived & R).Type to $@thick (@opened("{{.*}}", any Derived & R) Self).Type // CHECK: [[RESULT:%.*]] = init_existential_metatype [[PAYLOAD]] : $@thick (@opened("{{.*}}", any Derived & R) Self).Type, $@thick any (Base & P).Type let _: (Base & P).Type = derivedAndRType // CHECK: return } // CHECK-LABEL: sil hidden [ossa] @$s21subclass_existentials11methodCalls8baseAndP0eF5PTypeyAA1P_AA4BaseCySiGXc_AaE_AHXcXptF : $@convention(thin) (@guaranteed any Base & P, @thick any (Base & P).Type) -> () { func methodCalls( baseAndP: Base & P, baseAndPType: (Base & P).Type) { // CHECK: bb0([[ARG0:%.*]] : @guaranteed $any Base & P, // CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[ARG0]] : $any Base & P to $@opened("{{.*}}", any Base & P) Self // CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]] : $@opened("{{.*}}", any Base & P) Self // CHECK: [[CLASS_REF:%.*]] = upcast [[REF]] : $@opened("{{.*}}", any Base & P) Self to $Base // CHECK: [[METHOD:%.*]] = class_method [[CLASS_REF]] : $Base, #Base.classSelfReturn : (Base) -> () -> @dynamic_self Base, $@convention(method) <τ_0_0> (@guaranteed Base<τ_0_0>) -> @owned Base<τ_0_0> // CHECK: [[RESULT_CLASS_REF:%.*]] = apply [[METHOD]]([[CLASS_REF]]) : $@convention(method) <τ_0_0> (@guaranteed Base<τ_0_0>) -> @owned Base<τ_0_0> // CHECK: destroy_value [[CLASS_REF]] : $Base // CHECK: [[RESULT_REF:%.*]] = unchecked_ref_cast [[RESULT_CLASS_REF]] : $Base to $@opened("{{.*}}", any Base & P) Self // CHECK: [[RESULT:%.*]] = init_existential_ref [[RESULT_REF]] : $@opened("{{.*}}", any Base & P) Self, $any Base & P // CHECK: destroy_value [[RESULT]] : $any Base & P let _: Base & P = baseAndP.classSelfReturn() // CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[ARG0]] : $any Base & P to $@opened("{{.*}}", any Base & P) Self // CHECK: [[SELF_BOX:%.*]] = alloc_stack $@opened("{{.*}}", any Base & P) Self // CHECK: [[SB:%.*]] = store_borrow [[PAYLOAD]] to [[SELF_BOX]] : $*@opened("{{.*}}", any Base & P) Self // CHECK: [[METHOD:%.*]] = witness_method $@opened("{{.*}}", any Base & P) Self, #P.protocolSelfReturn : (Self) -> () -> Self, [[PAYLOAD]] : $@opened("{{.*}}", any Base & P) Self : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0 // CHECK: [[RESULT_BOX:%.*]] = alloc_box // CHECK: [[RESULT_LIFETIME:%[^,]+]] = begin_borrow [lexical] [[RESULT_BOX]] // CHECK: [[RESULT_BUF:%.*]] = project_box [[RESULT_LIFETIME]] // CHECK: apply [[METHOD]]<@opened("{{.*}}", any Base & P) Self>([[RESULT_BUF]], [[SB]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0 // end_borrow [[SB]] // CHECK: dealloc_stack [[SELF_BOX]] : $*@opened("{{.*}}", any Base & P) Self // CHECK: [[RESULT_REF:%.*]] = load [take] [[RESULT_BUF]] : $*@opened("{{.*}}", any Base & P) Self // CHECK: [[RESULT:%.*]] = init_existential_ref [[RESULT_REF]] : $@opened("{{.*}}", any Base & P) Self : $@opened("{{.*}}", any Base & P) Self, $any Base & P // CHECK: destroy_value [[RESULT]] : $any Base & P // CHECK: end_borrow [[RESULT_LIFETIME]] // CHECK: dealloc_box [[RESULT_BOX]] let _: Base & P = baseAndP.protocolSelfReturn() // CHECK: [[METATYPE:%.*]] = open_existential_metatype %1 : $@thick any (Base & P).Type to $@thick (@opened("{{.*}}", any Base & P) Self).Type // CHECK: [[METATYPE_REF:%.*]] = upcast [[METATYPE]] : $@thick (@opened("{{.*}}", any Base & P) Self).Type to $@thick Base.Type // CHECK: [[METHOD:%.*]] = function_ref @$s21subclass_existentials4BaseC15classSelfReturnACyxGXDyFZ : $@convention(method) <τ_0_0> (@thick Base<τ_0_0>.Type) -> @owned Base<τ_0_0> // CHECK: [[RESULT_REF2:%.*]] = apply [[METHOD]]([[METATYPE_REF]]) // CHECK: [[RESULT_REF:%.*]] = unchecked_ref_cast [[RESULT_REF2]] : $Base to $@opened("{{.*}}", any Base & P) Self // CHECK: [[RESULT:%.*]] = init_existential_ref [[RESULT_REF]] : $@opened("{{.*}}", any Base & P) Self : $@opened("{{.*}}", any Base & P) Self, $any Base & P // CHECK: destroy_value [[RESULT]] let _: Base & P = baseAndPType.classSelfReturn() // CHECK: [[METATYPE:%.*]] = open_existential_metatype %1 : $@thick any (Base & P).Type to $@thick (@opened("{{.*}}", any Base & P) Self).Type // CHECK: [[METHOD:%.*]] = witness_method $@opened("{{.*}}", any Base & P) Self, #P.protocolSelfReturn : (Self.Type) -> () -> Self, [[METATYPE]] : $@thick (@opened("{{.*}}", any Base & P) Self).Type : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@thick τ_0_0.Type) -> @out τ_0_0 // CHECK: [[RESULT_BOX:%.*]] = alloc_box // CHECK: [[RESULT_LIFETIME:%[^,]+]] = begin_borrow [lexical] [[RESULT_BOX]] // CHECK: [[RESULT_BUF:%.*]] = project_box // CHECK: apply [[METHOD]]<@opened("{{.*}}", any Base & P) Self>([[RESULT_BUF]], [[METATYPE]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@thick τ_0_0.Type) -> @out τ_0_0 // CHECK: [[RESULT_REF:%.*]] = load [take] [[RESULT_BUF]] : $*@opened("{{.*}}", any Base & P) Self // CHECK: [[RESULT_VALUE:%.*]] = init_existential_ref [[RESULT_REF]] : $@opened("{{.*}}", any Base & P) Self : $@opened("{{.*}}", any Base & P) Self, $any Base & P // CHECK: destroy_value [[RESULT_VALUE]] // CHECK: end_borrow [[RESULT_LIFETIME]] // CHECK: dealloc_box [[RESULT_BOX]] let _: Base & P = baseAndPType.protocolSelfReturn() // Partial applications let _: () -> (Base & P) = baseAndP.classSelfReturn let _: () -> (Base & P) = baseAndP.protocolSelfReturn let _: () -> (Base & P) = baseAndPType.classSelfReturn let _: () -> (Base & P) = baseAndPType.protocolSelfReturn let _: (()) -> (Base & P) = baseAndPType.init(classInit:) let _: (()) -> (Base & P) = baseAndPType.init(protocolInit:) // CHECK: return // CHECK-NEXT: } } // CHECK-LABEL: sil hidden [ossa] @$s21subclass_existentials29methodCallsOnProtocolMetatypeyyF : $@convention(thin) () -> () { // CHECK: metatype $@thin (any Base & P).Type // CHECK: function_ref @$[[THUNK1_NAME:[_a-zA-Z0-9]+]] // CHECK: } // end sil function '$s21subclass_existentials29methodCallsOnProtocolMetatypeyyF' // // CHECK: sil private [ossa] @$[[THUNK1_NAME]] : $@convention(thin) (@guaranteed any Base & P) -> @owned @callee_guaranteed () -> @owned any Base & P { // CHECK: bb0(%0 : @guaranteed $any Base & P): // CHECK: [[THUNK2:%[0-9]+]] = function_ref @$[[THUNK2_NAME:[_a-zA-Z0-9]+]] // CHECK: [[SELF_COPY:%[0-9]+]] = copy_value %0 // CHECK: [[RESULT:%[0-9]+]] = partial_apply [callee_guaranteed] [[THUNK2]]([[SELF_COPY]]) // CHECK: return [[RESULT]] // CHECK: } // end sil function '$[[THUNK1_NAME]]' // // CHECK: sil private [ossa] @$[[THUNK2_NAME]] : $@convention(thin) (@guaranteed any Base & P) -> @owned any Base & P { // CHECK: bb0(%0 : @closureCapture @guaranteed $any Base & P): // CHECK: [[OPENED:%[0-9]+]] = open_existential_ref %0 : $any Base & P to $[[OPENED_TY:@opened\("[-A-F0-9]+", any Base & P\) Self]] // CHECK: [[OPENED_COPY:%[0-9]+]] = copy_value [[OPENED]] // CHECK: [[CLASS:%[0-9]+]] = upcast [[OPENED_COPY]] : $[[OPENED_TY]] to $Base // CHECK: [[METHOD:%[0-9]+]] = class_method [[CLASS]] : $Base, #Base.classSelfReturn // CHECK: [[RESULT:%[0-9]+]] = apply [[METHOD]]([[CLASS]]) : $@convention(method) <τ_0_0> (@guaranteed Base<τ_0_0>) -> @owned Base<τ_0_0> // CHECK: destroy_value [[CLASS]] // CHECK: [[TO_OPENED:%[0-9]+]] = unchecked_ref_cast [[RESULT]] : $Base to $[[OPENED_TY]] // CHECK: [[ERASED:%[0-9]+]] = init_existential_ref [[TO_OPENED]] : $[[OPENED_TY]] // CHECK: return [[ERASED]] // CHECK: } // end sil function '$[[THUNK2_NAME]]' func methodCallsOnProtocolMetatype() { let _ = (Base & P).classSelfReturn } protocol PropertyP { var p: PropertyP & PropertyC { get set } subscript(key: Int) -> Int { get set } } class PropertyC { var c: PropertyP & PropertyC { get { return self as! PropertyP & PropertyC } set { } } subscript(key: (Int, Int)) -> Int { get { return 0 } set { } } } // CHECK-LABEL: sil hidden [ossa] @$s21subclass_existentials16propertyAccessesyyAA9PropertyP_AA0E1CCXcF : $@convention(thin) (@guaranteed any PropertyC & PropertyP) -> () { func propertyAccesses(_ x: PropertyP & PropertyC) { var xx = x xx.p.p = x xx.c.c = x propertyAccesses(xx.p) propertyAccesses(xx.c) _ = xx[1] xx[1] = 1 xx[1] += 1 _ = xx[(1, 2)] xx[(1, 2)] = 1 xx[(1, 2)] += 1 } // CHECK-LABEL: sil hidden [ossa] @$s21subclass_existentials19functionConversions15returnsBaseAndP0efG5PType0E7Derived0eI4Type0eiG1R0eiG5RTypeyAA1P_AA0F0CySiGXcyc_AaI_ALXcXpycAA0I0CycANmycAA1R_ANXcycAaO_ANXcXpyctF : $@convention(thin) (@guaranteed @callee_guaranteed () -> @owned any Base & P, @guaranteed @callee_guaranteed () -> @thick any (Base & P).Type, @guaranteed @callee_guaranteed () -> @owned Derived, @guaranteed @callee_guaranteed () -> @thick Derived.Type, @guaranteed @callee_guaranteed () -> @owned any Derived & R, @guaranteed @callee_guaranteed () -> @thick any (Derived & R).Type) -> () { func functionConversions( returnsBaseAndP: @escaping () -> (Base & P), returnsBaseAndPType: @escaping () -> (Base & P).Type, returnsDerived: @escaping () -> Derived, returnsDerivedType: @escaping () -> Derived.Type, returnsDerivedAndR: @escaping () -> Derived & R, returnsDerivedAndRType: @escaping () -> (Derived & R).Type) { let _: () -> Base = returnsBaseAndP let _: () -> Base.Type = returnsBaseAndPType let _: () -> P = returnsBaseAndP let _: () -> P.Type = returnsBaseAndPType let _: () -> (Base & P) = returnsDerived let _: () -> (Base & P).Type = returnsDerivedType let _: () -> Base = returnsDerivedAndR let _: () -> Base.Type = returnsDerivedAndRType let _: () -> (Base & P) = returnsDerivedAndR let _: () -> (Base & P).Type = returnsDerivedAndRType let _: () -> P = returnsDerivedAndR let _: () -> P.Type = returnsDerivedAndRType // CHECK: return % // CHECK-NEXT: } } // CHECK-LABEL: sil hidden [ossa] @$s21subclass_existentials9downcasts8baseAndP7derived0dE5PType0F4TypeyAA1P_AA4BaseCySiGXc_AA7DerivedCAaG_AJXcXpALmtF : $@convention(thin) (@guaranteed any Base & P, @guaranteed Derived, @thick any (Base & P).Type, @thick Derived.Type) -> () { func downcasts( baseAndP: Base & P, derived: Derived, baseAndPType: (Base & P).Type, derivedType: Derived.Type) { // CHECK: bb0([[ARG0:%.*]] : @guaranteed $any Base & P, [[ARG1:%.*]] : @guaranteed $Derived, [[ARG2:%.*]] : $@thick any (Base & P).Type, [[ARG3:%.*]] : $@thick Derived.Type): // CHECK: [[COPIED:%.*]] = copy_value [[ARG0]] : $any Base & P // CHECK-NEXT: checked_cast_br any Base & P in [[COPIED]] : $any Base & P to Derived let _ = baseAndP as? Derived // CHECK: [[COPIED:%.*]] = copy_value [[ARG0]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [[COPIED]] : $any Base & P to Derived let _ = baseAndP as! Derived // CHECK: [[COPIED:%.*]] = copy_value [[ARG0]] : $any Base & P // CHECK-NEXT: checked_cast_br [prohibit_isolated_conformances] any Base & P in [[COPIED]] : $any Base & P to any Derived & R let _ = baseAndP as? (Derived & R) // CHECK: [[COPIED:%.*]] = copy_value [[ARG0]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [prohibit_isolated_conformances] [[COPIED]] : $any Base & P to any Derived & R let _ = baseAndP as! (Derived & R) // CHECK: checked_cast_br [prohibit_isolated_conformances] Derived.Type in %3 : $@thick Derived.Type to any (Derived & R).Type let _ = derivedType as? (Derived & R).Type // CHECK: unconditional_checked_cast [prohibit_isolated_conformances] %3 : $@thick Derived.Type to any (Derived & R).Type let _ = derivedType as! (Derived & R).Type // CHECK: checked_cast_br any (Base & P).Type in %2 : $@thick any (Base & P).Type to Derived.Type let _ = baseAndPType as? Derived.Type // CHECK: unconditional_checked_cast %2 : $@thick any (Base & P).Type to Derived.Type let _ = baseAndPType as! Derived.Type // CHECK: checked_cast_br [prohibit_isolated_conformances] any (Base & P).Type in %2 : $@thick any (Base & P).Type to any (Derived & R).Type let _ = baseAndPType as? (Derived & R).Type // CHECK: unconditional_checked_cast [prohibit_isolated_conformances] %2 : $@thick any (Base & P).Type to any (Derived & R).Type let _ = baseAndPType as! (Derived & R).Type // CHECK: return // CHECK-NEXT: } } // CHECK-LABEL: sil hidden [ossa] @$s21subclass_existentials16archetypeUpcasts9baseTAndP0E7IntAndP7derivedyq__q0_q1_tAA4BaseCyxGRb_AA1PR_AGySiGRb0_AaIR0_AA7DerivedCRb1_r2_lF : $@convention(thin) , BaseTAndP : P, BaseIntAndP : Base, BaseIntAndP : P, DerivedT : Derived> (@guaranteed BaseTAndP, @guaranteed BaseIntAndP, @guaranteed DerivedT) -> () { func archetypeUpcasts & P, BaseIntAndP : Base & P, DerivedT : Derived>( baseTAndP: BaseTAndP, baseIntAndP : BaseIntAndP, derived : DerivedT) { // CHECK: bb0([[ARG0:%.*]] : @guaranteed $BaseTAndP, [[ARG1:%.*]] : @guaranteed $BaseIntAndP, [[ARG2:%.*]] : @guaranteed $DerivedT) // CHECK: [[COPIED:%.*]] = copy_value [[ARG0]] : $BaseTAndP // CHECK-NEXT: init_existential_ref [[COPIED]] : $BaseTAndP : $BaseTAndP, $any Base & P let _: Base & P = baseTAndP // CHECK: [[COPIED:%.*]] = copy_value [[ARG1]] : $BaseIntAndP // CHECK-NEXT: init_existential_ref [[COPIED]] : $BaseIntAndP : $BaseIntAndP, $any Base & P let _: Base & P = baseIntAndP // CHECK: [[COPIED:%.*]] = copy_value [[ARG2]] : $DerivedT // CHECK-NEXT: init_existential_ref [[COPIED]] : $DerivedT : $DerivedT, $any Base & P let _: Base & P = derived // CHECK: return // CHECK-NEXT: } } // CHECK-LABEL: sil hidden [ossa] @$s21subclass_existentials18archetypeDowncasts1s1t2pt5baseT0F3Int0f6TAndP_C00fg5AndP_C008derived_C00ji2R_C00fH10P_concrete0fgi2P_K0yx_q_q0_q1_q2_q3_q4_q5_AA1R_AA7DerivedCXcAA1P_AA4BaseCyq_GXcAaQ_ASySiGXctAaQR0_ATRb1_AURb2_ATRb3_AaQR3_AURb4_AaQR4_APRb5_r6_lF : $@convention(thin) , BaseInt : Base, BaseTAndP : Base, BaseTAndP : P, BaseIntAndP : Base, BaseIntAndP : P, DerivedT : Derived> (@in_guaranteed S, @in_guaranteed T, @in_guaranteed PT, @guaranteed BaseT, @guaranteed BaseInt, @guaranteed BaseTAndP, @guaranteed BaseIntAndP, @guaranteed DerivedT, @guaranteed any Derived & R, @guaranteed any Base & P, @guaranteed any Base & P) -> () { func archetypeDowncasts, BaseInt : Base, BaseTAndP : Base & P, BaseIntAndP : Base & P, DerivedT : Derived>( s: S, t: T, pt: PT, baseT : BaseT, baseInt : BaseInt, baseTAndP_archetype: BaseTAndP, baseIntAndP_archetype : BaseIntAndP, derived_archetype : DerivedT, derivedAndR_archetype : Derived & R, baseTAndP_concrete: Base & P, baseIntAndP_concrete: Base & P) { // CHECK: ([[ARG0:%.*]] : $*S, [[ARG1:%.*]] : $*T, [[ARG2:%.*]] : $*PT, [[ARG3:%.*]] : @guaranteed $BaseT, [[ARG4:%.*]] : @guaranteed $BaseInt, [[ARG5:%.*]] : @guaranteed $BaseTAndP, [[ARG6:%.*]] : @guaranteed $BaseIntAndP, [[ARG7:%.*]] : @guaranteed $DerivedT, [[ARG8:%.*]] : @guaranteed $any Derived & R, [[ARG9:%.*]] : @guaranteed $any Base & P, [[ARG10:%.*]] : @guaranteed $any Base & P) // CHECK: [[COPY:%.*]] = alloc_stack $S // CHECK-NEXT: copy_addr %0 to [init] [[COPY]] : $*S // CHECK-NEXT: [[RESULT:%.*]] = alloc_stack $any Base & P // CHECK-NEXT: checked_cast_addr_br [prohibit_isolated_conformances] take_always S in [[COPY]] : $*S to any Base & P in [[RESULT]] : $*any Base & P let _ = s as? (Base & P) // CHECK: [[COPY:%.*]] = alloc_stack $S // CHECK-NEXT: copy_addr [[ARG0]] to [init] [[COPY]] : $*S // CHECK-NEXT: [[RESULT:%.*]] = alloc_stack $any Base & P // CHECK-NEXT: unconditional_checked_cast_addr [prohibit_isolated_conformances] S in [[COPY]] : $*S to any Base & P in [[RESULT]] : $*any Base & P let _ = s as! (Base & P) // CHECK: [[COPY:%.*]] = alloc_stack $S // CHECK-NEXT: copy_addr [[ARG0]] to [init] [[COPY]] : $*S // CHECK-NEXT: [[RESULT:%.*]] = alloc_stack $any Base & P // CHECK-NEXT: checked_cast_addr_br [prohibit_isolated_conformances] take_always S in [[COPY]] : $*S to any Base & P in [[RESULT]] : $*any Base & P let _ = s as? (Base & P) // CHECK: [[COPY:%.*]] = alloc_stack $S // CHECK-NEXT: copy_addr [[ARG0]] to [init] [[COPY]] : $*S // CHECK-NEXT: [[RESULT:%.*]] = alloc_stack $any Base & P // CHECK-NEXT: unconditional_checked_cast_addr [prohibit_isolated_conformances] S in [[COPY]] : $*S to any Base & P in [[RESULT]] : $*any Base & P let _ = s as! (Base & P) // CHECK: [[COPIED:%.*]] = copy_value [[ARG5]] : $BaseTAndP // CHECK-NEXT: checked_cast_br [prohibit_isolated_conformances] BaseTAndP in [[COPIED]] : $BaseTAndP to any Derived & R let _ = baseTAndP_archetype as? (Derived & R) // CHECK: [[COPIED:%.*]] = copy_value [[ARG5]] : $BaseTAndP // CHECK-NEXT: unconditional_checked_cast [prohibit_isolated_conformances] [[COPIED]] : $BaseTAndP to any Derived & R let _ = baseTAndP_archetype as! (Derived & R) // CHECK: [[COPIED:%.*]] = copy_value [[ARG9]] : $any Base & P // CHECK-NEXT: [[COPY:%.*]] = alloc_stack $any Base & P // CHECK-NEXT: store [[COPIED]] to [init] [[COPY]] : $*any Base & P // CHECK-NEXT: [[RESULT:%.*]] = alloc_stack $Optional // CHECK-NEXT: [[PAYLOAD:%.*]] = init_enum_data_addr [[RESULT]] : $*Optional, #Optional.some // CHECK-NEXT: checked_cast_addr_br take_always any Base & P in [[COPY]] : $*any Base & P to S in [[PAYLOAD]] : $*S let _ = baseTAndP_concrete as? S // CHECK: [[COPY:%.*]] = alloc_stack $any Base & P // CHECK-NEXT: [[COPIED:%.*]] = copy_value [[ARG9]] : $any Base & P // CHECK-NEXT: store [[COPIED]] to [init] [[COPY]] : $*any Base & P // CHECK-NEXT: [[RESULT:%.*]] = alloc_stack $S // CHECK-NEXT: unconditional_checked_cast_addr any Base & P in [[COPY]] : $*any Base & P to S in [[RESULT]] : $*S let _ = baseTAndP_concrete as! S // CHECK: [[COPIED:%.*]] = copy_value [[ARG9]] : $any Base & P // CHECK-NEXT: checked_cast_br any Base & P in [[COPIED]] : $any Base & P to BaseT let _ = baseTAndP_concrete as? BaseT // CHECK: [[COPIED:%.*]] = copy_value [[ARG9]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [[COPIED]] : $any Base & P to BaseT let _ = baseTAndP_concrete as! BaseT // CHECK: [[COPIED:%.*]] = copy_value [[ARG9]] : $any Base & P // CHECK-NEXT: checked_cast_br any Base & P in [[COPIED]] : $any Base & P to BaseInt let _ = baseTAndP_concrete as? BaseInt // CHECK: [[COPIED:%.*]] = copy_value [[ARG9]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [[COPIED]] : $any Base & P to BaseInt let _ = baseTAndP_concrete as! BaseInt // CHECK: [[COPIED:%.*]] = copy_value [[ARG9]] : $any Base & P // CHECK-NEXT: checked_cast_br any Base & P in [[COPIED]] : $any Base & P to BaseTAndP let _ = baseTAndP_concrete as? BaseTAndP // CHECK: [[COPIED:%.*]] = copy_value [[ARG9]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [[COPIED]] : $any Base & P to BaseTAndP let _ = baseTAndP_concrete as! BaseTAndP // CHECK: [[COPIED:%.*]] = copy_value [[ARG6]] : $BaseIntAndP // CHECK-NEXT: checked_cast_br [prohibit_isolated_conformances] BaseIntAndP in [[COPIED]] : $BaseIntAndP to any Derived & R let _ = baseIntAndP_archetype as? (Derived & R) // CHECK: [[COPIED:%.*]] = copy_value [[ARG6]] : $BaseIntAndP // CHECK-NEXT: unconditional_checked_cast [prohibit_isolated_conformances] [[COPIED]] : $BaseIntAndP to any Derived & R let _ = baseIntAndP_archetype as! (Derived & R) // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: [[COPY:%.*]] = alloc_stack $any Base & P // CHECK-NEXT: store [[COPIED]] to [init] [[COPY]] : $*any Base & P // CHECK-NEXT: [[RESULT:%.*]] = alloc_stack $Optional // CHECK-NEXT: [[PAYLOAD:%.*]] = init_enum_data_addr [[RESULT]] : $*Optional, #Optional.some // CHECK-NEXT: checked_cast_addr_br take_always any Base & P in [[COPY]] : $*any Base & P to S in [[PAYLOAD]] : $*S let _ = baseIntAndP_concrete as? S // CHECK: [[COPY:%.*]] = alloc_stack $any Base & P // CHECK-NEXT: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: store [[COPIED]] to [init] [[COPY]] : $*any Base & P // CHECK-NEXT: [[RESULT:%.*]] = alloc_stack $S // CHECK-NEXT: unconditional_checked_cast_addr any Base & P in [[COPY]] : $*any Base & P to S in [[RESULT]] : $*S let _ = baseIntAndP_concrete as! S // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: checked_cast_br any Base & P in [[COPIED]] : $any Base & P to DerivedT let _ = baseIntAndP_concrete as? DerivedT // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [[COPIED]] : $any Base & P to DerivedT let _ = baseIntAndP_concrete as! DerivedT // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: checked_cast_br any Base & P in [[COPIED]] : $any Base & P to BaseT let _ = baseIntAndP_concrete as? BaseT // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [[COPIED]] : $any Base & P to BaseT let _ = baseIntAndP_concrete as! BaseT // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: checked_cast_br any Base & P in [[COPIED]] : $any Base & P to BaseInt let _ = baseIntAndP_concrete as? BaseInt // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [[COPIED]] : $any Base & P to BaseInt let _ = baseIntAndP_concrete as! BaseInt // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: checked_cast_br any Base & P in [[COPIED]] : $any Base & P to BaseTAndP let _ = baseIntAndP_concrete as? BaseTAndP // CHECK: [[COPIED:%.*]] = copy_value [[ARG10]] : $any Base & P // CHECK-NEXT: unconditional_checked_cast [[COPIED]] : $any Base & P to BaseTAndP let _ = baseIntAndP_concrete as! BaseTAndP // CHECK: return // CHECK-NEXT: } }