blob: 40b3e2504f0fd067638c15851502e567d4abb6ca [file] [log] [blame]
// RUN: %target-sil-opt -enable-sil-verify-all %s -devirtualizer -enable-library-evolution | %FileCheck %s
sil_stage canonical
import Builtin
import Swift
import SwiftShims
public protocol P { }
public protocol Q : P { }
extension Int : P, Q { }
public protocol ResilientProtocol {
func defaultA()
}
sil @defaultA : $@convention(witness_method: ResilientProtocol) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> () {
bb0(%0 : $*Self):
%result = tuple ()
return %result : $()
}
sil_default_witness_table ResilientProtocol {
method #ResilientProtocol.defaultA!1: @defaultA
}
struct ConformingStruct : ResilientProtocol {
func defaultA()
}
sil_witness_table ConformingStruct : ResilientProtocol module protocol_resilience {
method #ResilientProtocol.defaultA!1: @defaultA
}
struct ConformingGenericStruct<T> : ResilientProtocol {
func defaultA()
}
sil_witness_table <T> ConformingGenericStruct<T> : ResilientProtocol module protocol_resilience {
method #ResilientProtocol.defaultA!1: @defaultA
}
public protocol ResilientProtocolWithGeneric {
func defaultB<T: Q>(_: T)
}
sil @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <Self where Self : ResilientProtocolWithGeneric><T where T : P> (@in T, @in_guaranteed Self) -> () {
bb0(%0 : $*T, %1 : $*Self):
%result = tuple ()
return %result : $()
}
sil_default_witness_table ResilientProtocolWithGeneric {
method #ResilientProtocolWithGeneric.defaultB!1: @defaultB
}
extension ConformingGenericStruct : ResilientProtocolWithGeneric {
func defaultB<T>(_: T)
}
sil_witness_table <T> ConformingGenericStruct<T> : ResilientProtocolWithGeneric module protocol_resilience {
method #ResilientProtocolWithGeneric.defaultB!1: @defaultB
}
// CHECK-LABEL: sil hidden [ossa] @test_devirt_of_default_witness_method : $@convention(thin) (@in_guaranteed ConformingStruct) -> ()
// CHECK: bb0(%0 : $*ConformingStruct):
// CHECK: [[FN:%.*]] = function_ref @defaultA : $@convention(witness_method: ResilientProtocol) <τ_0_0 where τ_0_0 : ResilientProtocol> (@in_guaranteed τ_0_0) -> ()
// CHECK-NEXT: [[RESULT:%.*]] = apply [[FN]]<ConformingStruct>(%0) : $@convention(witness_method: ResilientProtocol) <τ_0_0 where τ_0_0 : ResilientProtocol> (@in_guaranteed τ_0_0)
// CHECK-NEXT: return [[RESULT]] : $()
sil hidden [ossa] @test_devirt_of_default_witness_method : $@convention(thin) (@in_guaranteed ConformingStruct) -> () {
bb0(%0 : $*ConformingStruct):
%fn = witness_method $ConformingStruct, #ResilientProtocol.defaultA!1 : $@convention(witness_method: ResilientProtocol) <T where T : ResilientProtocol> (@in_guaranteed T) -> ()
%result = apply %fn<ConformingStruct>(%0) : $@convention(witness_method: ResilientProtocol) <T where T : ResilientProtocol> (@in_guaranteed T) -> ()
return %result : $()
}
// CHECK-LABEL: sil hidden [ossa] @test_devirt_of_generic_default_witness_method : $@convention(thin) (@in_guaranteed ConformingGenericStruct<Int>) -> ()
// CHECK: bb0(%0 : $*ConformingGenericStruct<Int>):
// CHECK: [[FN:%.*]] = function_ref @defaultA : $@convention(witness_method: ResilientProtocol) <τ_0_0 where τ_0_0 : ResilientProtocol> (@in_guaranteed τ_0_0) -> ()
// CHECK-NEXT: [[RESULT:%.*]] = apply [[FN]]<ConformingGenericStruct<Int>>(%0) : $@convention(witness_method: ResilientProtocol) <τ_0_0 where τ_0_0 : ResilientProtocol> (@in_guaranteed τ_0_0)
// CHECK-NEXT: return [[RESULT]] : $()
sil hidden [ossa] @test_devirt_of_generic_default_witness_method : $@convention(thin) (@in_guaranteed ConformingGenericStruct<Int>) -> () {
bb0(%0 : $*ConformingGenericStruct<Int>):
%fn = witness_method $ConformingGenericStruct<Int>, #ResilientProtocol.defaultA!1 : $@convention(witness_method: ResilientProtocol) <T where T : ResilientProtocol> (@in_guaranteed T) -> ()
%result = apply %fn<ConformingGenericStruct<Int>>(%0) : $@convention(witness_method: ResilientProtocol) <T where T : ResilientProtocol> (@in_guaranteed T) -> ()
return %result : $()
}
// CHECK-LABEL: test_devirt_of_inner_generic_default_witness_method
// CHECK: bb0(%0 : $*ConformingGenericStruct<Int>, %1 : $*Int):
// CHECK: [[FN:%[0-9]+]] = function_ref @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : P> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
// CHECK: [[RESULT:%[0-9]+]] = apply [[FN]]<ConformingGenericStruct<Int>, Int>(%1, %0) : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : P> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
// CHECK: return [[RESULT]] : $()
// CHECK: }
sil hidden [ossa] @test_devirt_of_inner_generic_default_witness_method : $@convention(thin) (@in_guaranteed ConformingGenericStruct<Int>, @in Int) -> () {
bb0(%0 : $*ConformingGenericStruct<Int>, %1 : $*Int):
%fn = witness_method $ConformingGenericStruct<Int>, #ResilientProtocolWithGeneric.defaultB!1 : $@convention(witness_method: ResilientProtocolWithGeneric) <T where T : ResilientProtocolWithGeneric><U where U : Q> (@in U, @in_guaranteed T) -> ()
%result = apply %fn<ConformingGenericStruct<Int>, Int>(%1, %0) : $@convention(witness_method: ResilientProtocolWithGeneric) <T where T : ResilientProtocolWithGeneric><U where U : Q> (@in U, @in_guaranteed T) -> ()
return %result : $()
}