mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
These were added in https://github.com/swiftlang/swift/pull/81375 (and several other follow-up PRs because we missed a few places) and are no longer needed.
135 lines
6.1 KiB
Plaintext
135 lines
6.1 KiB
Plaintext
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-cpu %s -DINT=i%target-ptrsize
|
|
|
|
// REQUIRES: CPU=i386 || CPU=x86_64
|
|
|
|
sil_stage canonical
|
|
|
|
protocol DefCon {
|
|
init()
|
|
}
|
|
|
|
|
|
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @defcon(ptr noalias sret({{.*}}) %0, ptr %1, ptr %T, ptr %T.DefCon) {{.*}} {
|
|
sil @defcon : $@convention(thin) <T: DefCon> (@thick T.Type) -> @out T {
|
|
entry(%0: $*T, %1: $@thick T.Type):
|
|
|
|
// CHECK-x86_64: [[WITNESS_GEP:%.*]] = getelementptr inbounds ptr, ptr %T.DefCon, i32 1
|
|
// CHECK-i386: [[WITNESS_GEP:%.*]] = getelementptr inbounds ptr, ptr %T.DefCon, i32 1
|
|
// CHECK-i386: [[WITNESS:%.*]] = load ptr, ptr [[WITNESS_GEP]], align 4
|
|
// CHECK-x86_64: [[WITNESS:%.*]] = load ptr, ptr [[WITNESS_GEP]], align 8
|
|
// CHECK: call swiftcc void [[WITNESS]]
|
|
%m = witness_method $T, #DefCon.init!allocator : $@convention(witness_method: DefCon) <U: DefCon> (@thick U.Type) -> @out U
|
|
%z = apply %m<T>(%0, %1) : $@convention(witness_method: DefCon) <V: DefCon> (@thick V.Type) -> @out V
|
|
return %z : $()
|
|
}
|
|
|
|
// rdar://24141848
|
|
protocol Base {
|
|
func foo()
|
|
}
|
|
protocol Derived : Base {}
|
|
struct ImplementsDerived : Derived {
|
|
func foo() {}
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @testInheritedConformance
|
|
sil @testInheritedConformance : $@convention(thin) (@in ImplementsDerived) -> () {
|
|
entry(%0: $*ImplementsDerived):
|
|
// CHECK: [[WITNESS:%.*]] = load ptr, ptr getelementptr inbounds (ptr, ptr @"$s14witness_method17ImplementsDerivedVAA4BaseAAWP", i32 1)
|
|
// CHECK: call swiftcc void [[WITNESS]]
|
|
%m = witness_method $ImplementsDerived, #Base.foo : $@convention(witness_method: Base) <U: Base> (@in_guaranteed U) -> ()
|
|
%z = apply %m<ImplementsDerived>(%0) : $@convention(witness_method: Base) <V: Base> (@in_guaranteed V) -> ()
|
|
return %z : $()
|
|
}
|
|
|
|
|
|
// Make sure a witness_method call with a generic Self type uses the correct
|
|
// calling convention.
|
|
|
|
protocol Synergy {
|
|
associatedtype LowHangingFruit
|
|
|
|
func actionItem() -> LowHangingFruit
|
|
}
|
|
|
|
struct SyncUp<Deliverable> : Synergy {
|
|
let d: Deliverable
|
|
|
|
func actionItem() -> Deliverable {
|
|
return d
|
|
}
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @testGenericWitnessMethod(ptr noalias sret({{.*}}) %0, ptr noalias %1, ptr %T)
|
|
// CHECK: entry:
|
|
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s14witness_method6SyncUpVMa"([[INT]] 255, ptr %T)
|
|
// CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
|
|
// CHECK: [[WTABLE:%.*]] = call ptr @swift_getWitnessTable(
|
|
// CHECK: [[WITNESS_ADDR:%.*]] = getelementptr inbounds ptr, ptr [[WTABLE]], i32 2
|
|
// CHECK: [[WITNESS_FN:%.*]] = load ptr, ptr [[WITNESS_ADDR]]
|
|
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @swift_checkMetadataState([[INT]] 0, ptr [[METADATA]])
|
|
// CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
|
|
// CHECK: call swiftcc void [[WITNESS_FN]](ptr noalias sret({{.*}}) %0, ptr noalias swiftself %1, ptr [[METADATA]], ptr [[WTABLE]])
|
|
// CHECK: ret void
|
|
|
|
sil @testGenericWitnessMethod : $@convention(thin) <T> (@in SyncUp<T>) -> @out T {
|
|
entry(%ret : $*T, %self : $*SyncUp<T>):
|
|
%m = witness_method $SyncUp<T>, #Synergy.actionItem : $@convention(witness_method: Synergy) <U: Synergy> (@in_guaranteed U) -> @out U.LowHangingFruit
|
|
%z = apply %m<SyncUp<T>>(%ret, %self) : $@convention(witness_method: Synergy) <U: Synergy> (@in_guaranteed U) -> @out U.LowHangingFruit
|
|
return %z : $()
|
|
}
|
|
|
|
protocol Pivot {}
|
|
|
|
protocol Strategy {
|
|
associatedtype GrowthHack : Pivot
|
|
|
|
func disrupt() -> GrowthHack
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @testArchetypeWitnessMethod(ptr noalias sret({{.*}}) %0, ptr noalias %1, ptr %T, ptr %T.Strategy)
|
|
// CHECK: entry:
|
|
// CHECK: [[WITNESS_ADDR:%.*]] = getelementptr inbounds ptr, ptr %T.Strategy, i32 3
|
|
// CHECK: [[WITNESS_FN:%.*]] = load ptr, ptr [[WITNESS_ADDR]]
|
|
// CHECK: call swiftcc void [[WITNESS_FN]](ptr noalias sret({{.*}}) %0, ptr noalias swiftself %1, ptr %T, ptr %T.Strategy)
|
|
// CHECK: ret void
|
|
|
|
sil @testArchetypeWitnessMethod : $@convention(thin) <T : Strategy> (@in T) -> @out T.GrowthHack {
|
|
entry(%ret : $*T.GrowthHack, %self : $*T):
|
|
%m = witness_method $T, #Strategy.disrupt : $@convention(witness_method: Strategy) <U: Strategy> (@in_guaranteed U) -> @out U.GrowthHack
|
|
%z = apply %m<T>(%ret, %self) : $@convention(witness_method: Strategy) <U: Strategy> (@in_guaranteed U) -> @out U.GrowthHack
|
|
return %z : $()
|
|
}
|
|
|
|
// Class-constrained archetype witness method.
|
|
struct ToVideo : Pivot {}
|
|
|
|
class TPSReport<CoverSheet> : Strategy {
|
|
typealias GrowthHack = ToVideo
|
|
|
|
func disrupt() -> GrowthHack
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @classArchetypeWitnessMethod(ptr noalias swiftself captures(none) dereferenceable({{4|8}}) %0, ptr %Self, ptr %SelfWitnessTable)
|
|
|
|
sil @classArchetypeWitnessMethod : $@convention(witness_method: Strategy) <T><CoverSheet where T : TPSReport<CoverSheet>> (@in_guaranteed T) -> () {
|
|
entry(%self : $*T):
|
|
%z = tuple ()
|
|
return %z : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @testClassArchetypeWitnessMethod(ptr noalias sret({{.*}}) captures(none) %0, ptr noalias captures(none) dereferenceable({{4|8}}) %1, ptr %T, ptr %CoverSheet)
|
|
// CHECK: entry:
|
|
// CHECK: [[WITNESS_FN:%.*]] = load ptr, ptr getelementptr inbounds (ptr, ptr @"$s14witness_method9TPSReportCyxGAA8StrategyAAWP", i32 3)
|
|
// CHECK: call swiftcc void [[WITNESS_FN]](ptr noalias sret({{.*}}) %0, ptr noalias swiftself %1, ptr %T, ptr @"$s14witness_method9TPSReportCyxGAA8StrategyAAWP")
|
|
// CHECK: ret void
|
|
|
|
sil @testClassArchetypeWitnessMethod : $@convention(thin) <T><CoverSheet where T : TPSReport<CoverSheet>> (@in_guaranteed T) -> (@out T.GrowthHack) {
|
|
entry(%ret : $*T.GrowthHack, %self : $*T):
|
|
%m = witness_method $T, #Strategy.disrupt : $@convention(witness_method: Strategy) <U: Strategy> (@in_guaranteed U) -> @out U.GrowthHack
|
|
%z = apply %m<T>(%ret, %self) : $@convention(witness_method: Strategy) <U: Strategy> (@in_guaranteed U) -> @out U.GrowthHack
|
|
return %z : $()
|
|
}
|
|
|
|
sil_vtable TPSReport {}
|