|
| 1 | +// RUN: rm -rf %t |
| 2 | +// RUN: mkdir %t |
| 3 | +// RUN: %target-swift-frontend -emit-module -enable-resilience -module-name resilient_class -o %t %S/../Inputs/resilient_class.swift |
| 4 | +// RUN: %target-swift-frontend -use-native-super-method -enable-resilience -parse-sil -parse-as-library -emit-ir -I %t %s | FileCheck %s |
| 5 | + |
| 6 | +sil_stage canonical |
| 7 | + |
| 8 | +import Builtin |
| 9 | +import Swift |
| 10 | +import SwiftShims |
| 11 | +import resilient_class |
| 12 | + |
| 13 | +public class ChildToResilientParent : ResilientOutsideParent { |
| 14 | + public override func method() |
| 15 | + public override class func classMethod() |
| 16 | + deinit |
| 17 | + override init() |
| 18 | +} |
| 19 | + |
| 20 | +public class ChildToFixedParent : OutsideParent { |
| 21 | + public override func method() |
| 22 | + public override class func classMethod() |
| 23 | + deinit |
| 24 | + override init() |
| 25 | +} |
| 26 | + |
| 27 | +public extension ResilientOutsideChild { |
| 28 | + public func callSuperMethod() |
| 29 | + public class func callSuperClassMethod() |
| 30 | +} |
| 31 | + |
| 32 | +// resilient_class.ResilientOutsideParent.method () -> () |
| 33 | +sil @_TFC15resilient_class22ResilientOutsideParent6methodfT_T_ : $@convention(method) (@guaranteed ResilientOutsideParent) -> () |
| 34 | + |
| 35 | +// static resilient_class.ResilientOutsideParent.classMethod () -> () |
| 36 | +sil @_TZFC15resilient_class22ResilientOutsideParent11classMethodfT_T_ : $@convention(thin) (@thick ResilientOutsideParent.Type) -> () |
| 37 | + |
| 38 | +// super.ChildToResilientParent.method () -> () |
| 39 | +sil @_TFC5super22ChildToResilientParent6methodfT_T_ : $@convention(method) (@guaranteed ChildToResilientParent) -> () { |
| 40 | +// %0 |
| 41 | +bb0(%0 : $ChildToResilientParent): |
| 42 | + debug_value %0 : $ChildToResilientParent, let, name "self", argno 1 |
| 43 | + strong_retain %0 : $ChildToResilientParent |
| 44 | + %3 = upcast %0 : $ChildToResilientParent to $ResilientOutsideParent |
| 45 | + %4 = super_method %0 : $ChildToResilientParent, #ResilientOutsideParent.method!1 : ResilientOutsideParent -> () -> () , $@convention(method) (@guaranteed ResilientOutsideParent) -> () |
| 46 | + %5 = apply %4(%3) : $@convention(method) (@guaranteed ResilientOutsideParent) -> () |
| 47 | + strong_release %3 : $ResilientOutsideParent |
| 48 | + %7 = tuple () |
| 49 | + return %7 : $() |
| 50 | +} |
| 51 | + |
| 52 | +// ChildToResilientParent is in our resilience domain - can load the superclass's metadata directly. |
| 53 | +// CHECK-LABEL: define void @_TFC5super22ChildToResilientParent6methodfT_T_(%C5super22ChildToResilientParent*) |
| 54 | +// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class22ResilientOutsideParent() |
| 55 | +// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%C15resilient_class22ResilientOutsideParent*)** |
| 56 | +// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%C15resilient_class22ResilientOutsideParent*)*, void (%C15resilient_class22ResilientOutsideParent*)** [[OPAQUE_SUPER_METADATA]] |
| 57 | +// CHECK: [[FN_PTR:%[0-9]+]] = load void (%C15resilient_class22ResilientOutsideParent*)*, void (%C15resilient_class22ResilientOutsideParent*)** [[VTABLE_SLOT]] |
| 58 | +// CHECK: call void |
| 59 | + |
| 60 | +// static super.ChildToResilientParent.classMethod () -> () |
| 61 | +sil @_TZFC5super22ChildToResilientParent11classMethodfT_T_ : $@convention(thin) (@thick ChildToResilientParent.Type) -> () { |
| 62 | +bb0(%0 : $@thick ChildToResilientParent.Type): |
| 63 | + debug_value %0 : $@thick ChildToResilientParent.Type, let, name "self", argno 1 |
| 64 | + %2 = upcast %0 : $@thick ChildToResilientParent.Type to $@thick ResilientOutsideParent.Type |
| 65 | + %3 = super_method %0 : $@thick ChildToResilientParent.Type, #ResilientOutsideParent.classMethod!1 : ResilientOutsideParent.Type -> () -> () , $@convention(thin) (@thick ResilientOutsideParent.Type) -> () |
| 66 | + %4 = apply %3(%2) : $@convention(thin) (@thick ResilientOutsideParent.Type) -> () |
| 67 | + %5 = tuple () |
| 68 | + return %5 : $() |
| 69 | +} |
| 70 | + |
| 71 | +// ChildToResilientParent is in our resilience domain - can load the superclass's metadata directly. |
| 72 | +// CHECK-LABEL: define void @_TZFC5super22ChildToResilientParent11classMethodfT_T_(%swift.type*) |
| 73 | +// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class22ResilientOutsideParent() |
| 74 | +// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)** |
| 75 | +// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]] |
| 76 | +// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]] |
| 77 | +// CHECK: call void |
| 78 | + |
| 79 | +// resilient_class.OutsideParent.method () -> () |
| 80 | +sil @_TFC15resilient_class13OutsideParent6methodfT_T_ : $@convention(method) (@guaranteed OutsideParent) -> () |
| 81 | + |
| 82 | +// static resilient_class.OutsideParent.classMethod () -> () |
| 83 | +sil @_TZFC15resilient_class13OutsideParent11classMethodfT_T_ : $@convention(thin) (@thick OutsideParent.Type) -> () |
| 84 | + |
| 85 | +// super.ChildToFixedParent.method () -> () |
| 86 | +sil @_TFC5super18ChildToFixedParent6methodfT_T_ : $@convention(method) (@guaranteed ChildToFixedParent) -> () { |
| 87 | +// %0 |
| 88 | +bb0(%0 : $ChildToFixedParent): |
| 89 | + debug_value %0 : $ChildToFixedParent, let, name "self", argno 1 |
| 90 | + strong_retain %0 : $ChildToFixedParent |
| 91 | + %3 = upcast %0 : $ChildToFixedParent to $OutsideParent |
| 92 | + %4 = super_method %0 : $ChildToFixedParent, #OutsideParent.method!1 : OutsideParent -> () -> () , $@convention(method) (@guaranteed OutsideParent) -> () |
| 93 | + %5 = apply %4(%3) : $@convention(method) (@guaranteed OutsideParent) -> () |
| 94 | + strong_release %3 : $OutsideParent |
| 95 | + %7 = tuple () |
| 96 | + return %7 : $() |
| 97 | +} |
| 98 | + |
| 99 | +// CHECK-LABEL: define void @_TFC5super18ChildToFixedParent6methodfT_T_(%C5super18ChildToFixedParent*) |
| 100 | +// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class13OutsideParent() |
| 101 | +// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%C15resilient_class13OutsideParent*)** |
| 102 | +// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%C15resilient_class13OutsideParent*)*, void (%C15resilient_class13OutsideParent*)** [[OPAQUE_SUPER_METADATA]] |
| 103 | +// CHECK: [[FN_PTR:%[0-9]+]] = load void (%C15resilient_class13OutsideParent*)*, void (%C15resilient_class13OutsideParent*)** [[VTABLE_SLOT]] |
| 104 | +// CHECK: call void |
| 105 | + |
| 106 | +// static super.ChildToFixedParent.classMethod () -> () |
| 107 | +sil @_TZFC5super18ChildToFixedParent11classMethodfT_T_ : $@convention(thin) (@thick ChildToFixedParent.Type) -> () { |
| 108 | +// %0 |
| 109 | +bb0(%0 : $@thick ChildToFixedParent.Type): |
| 110 | + debug_value %0 : $@thick ChildToFixedParent.Type, let, name "self", argno 1 |
| 111 | + %2 = upcast %0 : $@thick ChildToFixedParent.Type to $@thick OutsideParent.Type |
| 112 | + %3 = super_method %0 : $@thick ChildToFixedParent.Type, #OutsideParent.classMethod!1 : OutsideParent.Type -> () -> () , $@convention(thin) (@thick OutsideParent.Type) -> () |
| 113 | + %4 = apply %3(%2) : $@convention(thin) (@thick OutsideParent.Type) -> () |
| 114 | + %5 = tuple () |
| 115 | + return %5 : $() |
| 116 | +} |
| 117 | + |
| 118 | +// ChildToFixedParent is in our resilience domain - load super metadata directly. |
| 119 | +// CHECK-LABEL: define void @_TZFC5super18ChildToFixedParent11classMethodfT_T_(%swift.type*) |
| 120 | +// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class13OutsideParent() |
| 121 | +// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)** |
| 122 | +// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]] |
| 123 | +// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]] |
| 124 | +// CHECK: call void |
| 125 | + |
| 126 | +// ext.super.resilient_class.ResilientOutsideChild.callSuperMethod () -> () |
| 127 | +sil @_TFE5superC15resilient_class21ResilientOutsideChild15callSuperMethodfT_T_ : $@convention(method) (@guaranteed ResilientOutsideChild) -> () { |
| 128 | +// %0 |
| 129 | +bb0(%0 : $ResilientOutsideChild): |
| 130 | + debug_value %0 : $ResilientOutsideChild, let, name "self", argno 1 |
| 131 | + strong_retain %0 : $ResilientOutsideChild |
| 132 | + %3 = upcast %0 : $ResilientOutsideChild to $ResilientOutsideParent |
| 133 | + %4 = super_method %0 : $ResilientOutsideChild, #ResilientOutsideParent.method!1 : ResilientOutsideParent -> () -> () , $@convention(method) (@guaranteed ResilientOutsideParent) -> () |
| 134 | + %5 = apply %4(%3) : $@convention(method) (@guaranteed ResilientOutsideParent) -> () |
| 135 | + strong_release %3 : $ResilientOutsideParent |
| 136 | + %7 = tuple () |
| 137 | + return %7 : $() |
| 138 | +} |
| 139 | + |
| 140 | +// Extending a resilient class - load super metadata indirectly. |
| 141 | +// CHECK-LABEL: define void @_TFE5superC15resilient_class21ResilientOutsideChild15callSuperMethodfT_T_(%C15resilient_class21ResilientOutsideChild*) |
| 142 | +// CHECK: [[METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class21ResilientOutsideChild() |
| 143 | +// CHECK: [[OPAQUE_METADATA:%[0-9]+]] = bitcast %swift.type* [[METADATA]] to %swift.type** |
| 144 | +// CHECK: [[SUPER_METADATA_PTR:%[0-9]+]] = getelementptr inbounds %swift.type*, %swift.type** [[OPAQUE_METADATA]], i32 1 |
| 145 | +// CHECK: [[SUPER_METADATA:%[0-9]+]] = load %swift.type*, %swift.type** [[SUPER_METADATA_PTR]] |
| 146 | +// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%C15resilient_class22ResilientOutsideParent*)** |
| 147 | +// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%C15resilient_class22ResilientOutsideParent*)*, void (%C15resilient_class22ResilientOutsideParent*)** [[OPAQUE_SUPER_METADATA]] |
| 148 | +// CHECK: [[FN_PTR:%[0-9]+]] = load void (%C15resilient_class22ResilientOutsideParent*)*, void (%C15resilient_class22ResilientOutsideParent*)** [[VTABLE_SLOT]] |
| 149 | +// CHECK: call void |
| 150 | + |
| 151 | +// static ext.super.resilient_class.ResilientOutsideChild.callSuperClassMethod () -> () |
| 152 | +sil @_TZFE5superC15resilient_class21ResilientOutsideChild20callSuperClassMethodfT_T_ : $@convention(thin) (@thick ResilientOutsideChild.Type) -> () { |
| 153 | +// %0 |
| 154 | +bb0(%0 : $@thick ResilientOutsideChild.Type): |
| 155 | + debug_value %0 : $@thick ResilientOutsideChild.Type, let, name "self", argno 1 |
| 156 | + %2 = upcast %0 : $@thick ResilientOutsideChild.Type to $@thick ResilientOutsideParent.Type |
| 157 | + %3 = super_method %0 : $@thick ResilientOutsideChild.Type, #ResilientOutsideParent.classMethod!1 : ResilientOutsideParent.Type -> () -> () , $@convention(thin) (@thick ResilientOutsideParent.Type) -> () |
| 158 | + %4 = apply %3(%2) : $@convention(thin) (@thick ResilientOutsideParent.Type) -> () |
| 159 | + %5 = tuple () |
| 160 | + return %5 : $() |
| 161 | +} |
| 162 | + |
| 163 | +// Extending a resilient class - load super metadata indirectly. |
| 164 | +// CHECK-LABEL: define void @_TZFE5superC15resilient_class21ResilientOutsideChild20callSuperClassMethodfT_T_(%swift.type*) |
| 165 | +// CHECK: [[METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class21ResilientOutsideChild() |
| 166 | +// CHECK: [[OPAQUE_METADATA:%[0-9]+]] = bitcast %swift.type* [[METADATA]] to %swift.type** |
| 167 | +// CHECK: [[SUPER_METADATA_PTR:%[0-9]+]] = getelementptr inbounds %swift.type*, %swift.type** [[OPAQUE_METADATA]], i32 1 |
| 168 | +// CHECK: [[SUPER_METADATA:%[0-9]+]] = load %swift.type*, %swift.type** [[SUPER_METADATA_PTR]] |
| 169 | +// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)** |
| 170 | +// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]] |
| 171 | +// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]] |
| 172 | +// CHECK: call void |
| 173 | + |
| 174 | +sil_vtable ChildToResilientParent { |
| 175 | + #ResilientOutsideParent.method!1: _TFC5super22ChildToResilientParent6methodfT_T_ // super.ChildToResilientParent.method () -> () |
| 176 | + #ResilientOutsideParent.classMethod!1: _TZFC5super22ChildToResilientParent11classMethodfT_T_ // static super.ChildToResilientParent.classMethod () -> () |
| 177 | +} |
| 178 | + |
| 179 | +sil_vtable ChildToFixedParent { |
| 180 | + #OutsideParent.method!1: _TFC5super18ChildToFixedParent6methodfT_T_ // super.ChildToFixedParent.method () -> () |
| 181 | + #OutsideParent.classMethod!1: _TZFC5super18ChildToFixedParent11classMethodfT_T_ // static super.ChildToFixedParent.classMethod () -> () |
| 182 | +} |
| 183 | + |
0 commit comments