mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The goals here are four-fold:
- provide cleaner internal abstractions
- avoid IR bloat from extra bitcasts
- avoid recomputing function-type lowering information
- allow more information to be propagated from the function
access site (e.g. class_method) to the call site
Use this framework immediately for class and protocol methods.
217 lines
13 KiB
Plaintext
217 lines
13 KiB
Plaintext
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-module -enable-resilience -I %t -module-name resilient_struct -o %t %S/../Inputs/resilient_struct.swift
|
|
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-module -enable-resilience -I %t -module-name resilient_class -o %t %S/../Inputs/resilient_class.swift
|
|
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -enable-resilience -parse-sil -parse-as-library -emit-ir -I %t %s | %FileCheck %s
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
import Swift
|
|
import SwiftShims
|
|
import resilient_class
|
|
|
|
public class ChildToResilientParent : ResilientOutsideParent {
|
|
public override func method()
|
|
public override class func classMethod()
|
|
deinit
|
|
override init()
|
|
}
|
|
|
|
public class ChildToFixedParent : OutsideParent {
|
|
public override func method()
|
|
public override class func classMethod()
|
|
deinit
|
|
override init()
|
|
}
|
|
|
|
public extension ResilientOutsideChild {
|
|
public func callSuperMethod()
|
|
public class func callSuperClassMethod()
|
|
}
|
|
|
|
// resilient_class.ResilientOutsideParent.method () -> ()
|
|
sil @_T015resilient_class22ResilientOutsideParentC6methodyyF : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
|
|
|
|
// static resilient_class.ResilientOutsideParent.classMethod () -> ()
|
|
sil @_T015resilient_class22ResilientOutsideParentC0B6MethodyyFZ : $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
|
|
|
|
// super.ChildToResilientParent.method () -> ()
|
|
sil @_T05super22ChildToResilientParentC6methodyyF : $@convention(method) (@guaranteed ChildToResilientParent) -> () {
|
|
// %0
|
|
bb0(%0 : $ChildToResilientParent):
|
|
debug_value %0 : $ChildToResilientParent, let, name "self", argno 1
|
|
strong_retain %0 : $ChildToResilientParent
|
|
%3 = upcast %0 : $ChildToResilientParent to $ResilientOutsideParent
|
|
%4 = super_method %0 : $ChildToResilientParent, #ResilientOutsideParent.method!1 : (ResilientOutsideParent) -> () -> (), $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
|
|
%5 = apply %4(%3) : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
|
|
strong_release %3 : $ResilientOutsideParent
|
|
%7 = tuple ()
|
|
return %7 : $()
|
|
}
|
|
|
|
// ChildToResilientParent is in our resilience domain - can load the superclass's metadata directly.
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @_T05super22ChildToResilientParentC6methodyyF(%T5super22ChildToResilientParentC* swiftself)
|
|
// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_T015resilient_class22ResilientOutsideParentCMa()
|
|
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%T15resilient_class22ResilientOutsideParentC*)**
|
|
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%T15resilient_class22ResilientOutsideParentC*)*, void (%T15resilient_class22ResilientOutsideParentC*)** [[OPAQUE_SUPER_METADATA]]
|
|
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%T15resilient_class22ResilientOutsideParentC*)*, void (%T15resilient_class22ResilientOutsideParentC*)** [[VTABLE_SLOT]]
|
|
// CHECK: call void
|
|
|
|
// static super.ChildToResilientParent.classMethod () -> ()
|
|
sil @_T05super22ChildToResilientParentC11classMethodyyFZ : $@convention(method) (@thick ChildToResilientParent.Type) -> () {
|
|
bb0(%0 : $@thick ChildToResilientParent.Type):
|
|
debug_value %0 : $@thick ChildToResilientParent.Type, let, name "self", argno 1
|
|
%2 = upcast %0 : $@thick ChildToResilientParent.Type to $@thick ResilientOutsideParent.Type
|
|
%3 = super_method %0 : $@thick ChildToResilientParent.Type, #ResilientOutsideParent.classMethod!1 : (ResilientOutsideParent.Type) -> () -> (), $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
|
|
%4 = apply %3(%2) : $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
|
|
%5 = tuple ()
|
|
return %5 : $()
|
|
}
|
|
|
|
// ChildToResilientParent is in our resilience domain - can load the superclass's metadata directly.
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @_T05super22ChildToResilientParentC11classMethodyyFZ(%swift.type* swiftself)
|
|
// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_T015resilient_class22ResilientOutsideParentCMa()
|
|
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)**
|
|
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]]
|
|
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]]
|
|
// CHECK: call swiftcc void
|
|
|
|
// resilient_class.OutsideParent.method () -> ()
|
|
sil @_T015resilient_class13OutsideParentC6methodyyF : $@convention(method) (@guaranteed OutsideParent) -> ()
|
|
|
|
// static resilient_class.OutsideParent.classMethod () -> ()
|
|
sil @_T015resilient_class13OutsideParentC0B6MethodyyFZ : $@convention(thin) (@thick OutsideParent.Type) -> ()
|
|
|
|
// super.ChildToFixedParent.method () -> ()
|
|
sil @_T05super18ChildToFixedParentC6methodyyF : $@convention(method) (@guaranteed ChildToFixedParent) -> () {
|
|
// %0
|
|
bb0(%0 : $ChildToFixedParent):
|
|
debug_value %0 : $ChildToFixedParent, let, name "self", argno 1
|
|
strong_retain %0 : $ChildToFixedParent
|
|
%3 = upcast %0 : $ChildToFixedParent to $OutsideParent
|
|
%4 = super_method %0 : $ChildToFixedParent, #OutsideParent.method!1 : (OutsideParent) -> () -> (), $@convention(method) (@guaranteed OutsideParent) -> ()
|
|
%5 = apply %4(%3) : $@convention(method) (@guaranteed OutsideParent) -> ()
|
|
strong_release %3 : $OutsideParent
|
|
%7 = tuple ()
|
|
return %7 : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @_T05super18ChildToFixedParentC6methodyyF(%T5super18ChildToFixedParentC* swiftself)
|
|
// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_T015resilient_class13OutsideParentCMa()
|
|
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%T15resilient_class13OutsideParentC*)**
|
|
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%T15resilient_class13OutsideParentC*)*, void (%T15resilient_class13OutsideParentC*)** [[OPAQUE_SUPER_METADATA]]
|
|
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%T15resilient_class13OutsideParentC*)*, void (%T15resilient_class13OutsideParentC*)** [[VTABLE_SLOT]]
|
|
// CHECK: call swiftcc void
|
|
|
|
// static super.ChildToFixedParent.classMethod () -> ()
|
|
sil @_T05super18ChildToFixedParentC11classMethodyyFZ : $@convention(method) (@thick ChildToFixedParent.Type) -> () {
|
|
// %0
|
|
bb0(%0 : $@thick ChildToFixedParent.Type):
|
|
debug_value %0 : $@thick ChildToFixedParent.Type, let, name "self", argno 1
|
|
%2 = upcast %0 : $@thick ChildToFixedParent.Type to $@thick OutsideParent.Type
|
|
%3 = super_method %0 : $@thick ChildToFixedParent.Type, #OutsideParent.classMethod!1 : (OutsideParent.Type) -> () -> (), $@convention(method) (@thick OutsideParent.Type) -> ()
|
|
%4 = apply %3(%2) : $@convention(method) (@thick OutsideParent.Type) -> ()
|
|
%5 = tuple ()
|
|
return %5 : $()
|
|
}
|
|
|
|
// ChildToFixedParent is in our resilience domain - load super metadata directly.
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @_T05super18ChildToFixedParentC11classMethodyyFZ(%swift.type* swiftself)
|
|
// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_T015resilient_class13OutsideParentCMa()
|
|
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)**
|
|
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]]
|
|
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]]
|
|
// CHECK: call swiftcc void
|
|
|
|
// ext.super.resilient_class.ResilientOutsideChild.callSuperMethod () -> ()
|
|
sil @_T015resilient_class21ResilientOutsideChildC5superE15callSuperMethodyyF : $@convention(method) (@guaranteed ResilientOutsideChild) -> () {
|
|
// %0
|
|
bb0(%0 : $ResilientOutsideChild):
|
|
debug_value %0 : $ResilientOutsideChild, let, name "self", argno 1
|
|
strong_retain %0 : $ResilientOutsideChild
|
|
%3 = upcast %0 : $ResilientOutsideChild to $ResilientOutsideParent
|
|
%4 = super_method %0 : $ResilientOutsideChild, #ResilientOutsideParent.method!1 : (ResilientOutsideParent) -> () -> (), $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
|
|
%5 = apply %4(%3) : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
|
|
strong_release %3 : $ResilientOutsideParent
|
|
%7 = tuple ()
|
|
return %7 : $()
|
|
}
|
|
|
|
// Extending a resilient class - load super metadata indirectly.
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @_T015resilient_class21ResilientOutsideChildC5superE15callSuperMethodyyF(%T15resilient_class21ResilientOutsideChildC* swiftself)
|
|
// CHECK: [[METADATA:%[0-9]+]] = call %swift.type* @_T015resilient_class21ResilientOutsideChildCMa()
|
|
// CHECK: [[OPAQUE_METADATA:%[0-9]+]] = bitcast %swift.type* [[METADATA]] to %swift.type**
|
|
// CHECK: [[SUPER_METADATA_PTR:%[0-9]+]] = getelementptr inbounds %swift.type*, %swift.type** [[OPAQUE_METADATA]], i32 1
|
|
// CHECK: [[SUPER_METADATA:%[0-9]+]] = load %swift.type*, %swift.type** [[SUPER_METADATA_PTR]]
|
|
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%T15resilient_class22ResilientOutsideParentC*)**
|
|
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%T15resilient_class22ResilientOutsideParentC*)*, void (%T15resilient_class22ResilientOutsideParentC*)** [[OPAQUE_SUPER_METADATA]]
|
|
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%T15resilient_class22ResilientOutsideParentC*)*, void (%T15resilient_class22ResilientOutsideParentC*)** [[VTABLE_SLOT]]
|
|
// CHECK: call void
|
|
|
|
// static ext.super.resilient_class.ResilientOutsideChild.callSuperClassMethod () -> ()
|
|
sil @_T015resilient_class21ResilientOutsideChildC5superE20callSuperClassMethodyyFZ : $@convention(method) (@thick ResilientOutsideChild.Type) -> () {
|
|
// %0
|
|
bb0(%0 : $@thick ResilientOutsideChild.Type):
|
|
debug_value %0 : $@thick ResilientOutsideChild.Type, let, name "self", argno 1
|
|
%2 = upcast %0 : $@thick ResilientOutsideChild.Type to $@thick ResilientOutsideParent.Type
|
|
%3 = super_method %0 : $@thick ResilientOutsideChild.Type, #ResilientOutsideParent.classMethod!1 : (ResilientOutsideParent.Type) -> () -> (), $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
|
|
%4 = apply %3(%2) : $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
|
|
%5 = tuple ()
|
|
return %5 : $()
|
|
}
|
|
|
|
// Extending a resilient class - load super metadata indirectly.
|
|
// CHECK-LABEL: define{{( protected)?}} swiftcc void @_T015resilient_class21ResilientOutsideChildC5superE20callSuperClassMethodyyFZ(%swift.type* swiftself)
|
|
// CHECK: [[METADATA:%[0-9]+]] = call %swift.type* @_T015resilient_class21ResilientOutsideChildCMa()
|
|
// CHECK: [[OPAQUE_METADATA:%[0-9]+]] = bitcast %swift.type* [[METADATA]] to %swift.type**
|
|
// CHECK: [[SUPER_METADATA_PTR:%[0-9]+]] = getelementptr inbounds %swift.type*, %swift.type** [[OPAQUE_METADATA]], i32 1
|
|
// CHECK: [[SUPER_METADATA:%[0-9]+]] = load %swift.type*, %swift.type** [[SUPER_METADATA_PTR]]
|
|
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)**
|
|
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]]
|
|
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]]
|
|
// CHECK: call swiftcc void
|
|
|
|
sil_vtable ChildToResilientParent {
|
|
#ResilientOutsideParent.method!1: _T05super22ChildToResilientParentC6methodyyF // super.ChildToResilientParent.method () -> ()
|
|
#ResilientOutsideParent.classMethod!1: _T05super22ChildToResilientParentC11classMethodyyFZ // static super.ChildToResilientParent.classMethod () -> ()
|
|
}
|
|
|
|
sil_vtable ChildToFixedParent {
|
|
#OutsideParent.method!1: _T05super18ChildToFixedParentC6methodyyF // super.ChildToFixedParent.method () -> ()
|
|
#OutsideParent.classMethod!1: _T05super18ChildToFixedParentC11classMethodyyFZ // static super.ChildToFixedParent.classMethod () -> ()
|
|
}
|
|
|
|
protocol Proto {
|
|
}
|
|
|
|
public class Base<T: Proto> {
|
|
func Method() { }
|
|
}
|
|
|
|
struct Str : Proto {
|
|
}
|
|
|
|
public class Derived : Base<Str> {
|
|
override func Method()
|
|
}
|
|
|
|
sil_vtable Base {
|
|
}
|
|
|
|
sil_vtable Derived {
|
|
}
|
|
|
|
// CHECK-LABEL: define{{.*}} @test_super_method_of_generic_base
|
|
// CHECK: [[METADATA:%[0-9]+]] = call %swift.type* @_T05super4BaseCyAA3StrVGMa()
|
|
// CHECK: [[BASEMETADATA:%[0-9]+]] = bitcast %swift.type* [[METADATA]] to void (%T5super4BaseC*)**
|
|
// CHECK: [[GEP:%[0-9]+]] = getelementptr inbounds void (%T5super4BaseC*)*, void (%T5super4BaseC*)** [[BASEMETADATA]]
|
|
// CHECK: [[SUPERMT:%[0-9]+]] = load void (%T5super4BaseC*)*, void (%T5super4BaseC*)** [[GEP]]
|
|
// CHECK: ret void
|
|
sil @test_super_method_of_generic_base : $@convention(method) (@guaranteed Derived) -> () {
|
|
bb0(%0 : $Derived):
|
|
%4 = super_method %0 : $Derived, #Base.Method!1 : <T where T : Proto> (Base<T>) -> () -> () , $@convention(method) <τ_0_0 where τ_0_0 : Proto> (@guaranteed Base<τ_0_0>) -> ()
|
|
%7 = tuple ()
|
|
return %7 : $()
|
|
}
|
|
|