Files
swift-mirror/test/SILOptimizer/sil_combine_apply_unit.sil
2025-01-13 16:57:36 -08:00

179 lines
8.4 KiB
Plaintext

// RUN: %target-sil-opt \
// RUN: -test-runner %s \
// RUN: -module-name Swift \
// RUN: -enable-sil-verify-all \
// RUN: | %FileCheck %s
import Builtin
enum Optional<T> {
case some(T)
case none
}
protocol Error {}
class C {}
struct Input {}
struct Output {}
enum Nunca {}
sil @borrowMaybeC : $@convention(thin) (@guaranteed Optional<C>) -> ()
sil @borrowMaybeC2 : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> ()
sil @borrowMaybeCThrowing : $@convention(thin) (@guaranteed Optional<C>) -> (@error Error)
sil @borrowMaybeC2Throwing : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> (@error Error)
sil @rdar127452206_callee : $@convention(thin) @Sendable @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output>
// CHECK-LABEL: sil @rdar127452206 : {{.*}} {
// CHECK: bb0([[INPUT:%[^,]+]] :
// CHECK: [[OUTPUT:%[^,]+]] = alloc_stack $Output
// CHECK: [[NUNCA:%[^,]+]] = alloc_stack $Nunca
// CHECK: [[OUTPUT_AS_OUTPUT:%[^,]+]] = unchecked_addr_cast [[OUTPUT]]
// CHECK: [[NUNCA_AS_NUNCA:%[^,]+]] = unchecked_addr_cast [[NUNCA]]
// CHECK: [[INPUT_AS_INPUT:%[^,]+]] = unchecked_addr_cast [[INPUT]]
// CHECK: apply [nothrow] {{%[^,]+}}([[OUTPUT_AS_OUTPUT]], [[NUNCA_AS_NUNCA]], [[INPUT_AS_INPUT]])
// CHECK-LABEL: } // end sil function 'rdar127452206'
sil @rdar127452206 : $@convention(thin) (@in Input) -> () {
entry(%input : $*Input):
%output = alloc_stack $Output
%nunca = alloc_stack $Nunca
%callee = function_ref @rdar127452206_callee : $@convention(thin) @Sendable @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output>
%convert = convert_function %callee : $@convention(thin) @Sendable @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output> to $@convention(thin) @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output> // user: %216
specify_test "sil_combine_visit_instruction @instruction[4]"
apply [nothrow] %convert(%output, %nunca, %input) : $@convention(thin) @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output>
dealloc_stack %nunca : $*Nunca
dealloc_stack %output : $*Output
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: sil [ossa] @convert_function__to_optional__owned_as_guaranteed__1 : {{.*}} {
// CHECK: bb0([[C:%[^,]+]] :
// CHECK: [[BORROW_MAYBE_C:%[^,]+]] = function_ref @borrowMaybeC
// CHECK: [[B:%[^,]+]] = begin_borrow [[C]]
// CHECK: [[MAYBE_B:%[^,]+]] = unchecked_ref_cast [[B]] to $Optional<C>
// CHECK: apply [[BORROW_MAYBE_C]]([[MAYBE_B]])
// CHECK: end_borrow [[B]]
// CHECK: destroy_value [[C]]
// CHECK-LABEL: } // end sil function 'convert_function__to_optional__owned_as_guaranteed__1'
sil [ossa] @convert_function__to_optional__owned_as_guaranteed__1 : $@convention(thin) (@owned C) -> () {
entry(%c : @owned $C):
%borrowMaybeC = function_ref @borrowMaybeC : $@convention(thin) (@guaranteed Optional<C>) -> ()
%borrowC = convert_function %borrowMaybeC to $@convention(thin) (@guaranteed C) -> ()
%void = apply %borrowC(%c) : $@convention(thin) (@guaranteed C) -> ()
specify_test "sil_combine_visit_instruction %void"
destroy_value %c
%retval = tuple ()
return %retval
}
// CHECK-LABEL: sil [ossa] @convert_function__to_optional__owned_as_guaranteed__2 : {{.*}} {
// CHECK: bb0(
// CHECK-SAME: [[C:%[^,]+]] :
// CHECK-SAME: [[C2:%[^,]+]] :
// CHECK-SAME: ):
// CHECK: [[BORROW_MAYBE_C2:%[^,]+]] = function_ref @borrowMaybeC2
// CHECK: [[B:%[^,]+]] = begin_borrow [[C]]
// CHECK: [[MAYBE_B:%[^,]+]] = unchecked_ref_cast [[B]] to $Optional<C>
// CHECK: [[B2:%[^,]+]] = begin_borrow [[C2]]
// CHECK: [[MAYBE_B2:%[^,]+]] = unchecked_ref_cast [[B2]] to $Optional<C>
// CHECK: apply [[BORROW_MAYBE_C2]]([[MAYBE_B]], [[MAYBE_B2]])
// CHECK: end_borrow [[B]]
// CHECK: end_borrow [[B2]]
// CHECK: destroy_value [[C]]
// CHECK: destroy_value [[C2]]
// CHECK-LABEL: } // end sil function 'convert_function__to_optional__owned_as_guaranteed__2'
sil [ossa] @convert_function__to_optional__owned_as_guaranteed__2 : $@convention(thin) (@owned C, @owned C) -> () {
entry(%c : @owned $C, %c2 : @owned $C):
%borrowMaybeC2 = function_ref @borrowMaybeC2 : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> ()
%borrowC2 = convert_function %borrowMaybeC2 to $@convention(thin) (@guaranteed C, @guaranteed C) -> ()
%void = apply %borrowC2(%c, %c2) : $@convention(thin) (@guaranteed C, @guaranteed C) -> ()
specify_test "sil_combine_visit_instruction %void"
destroy_value %c
destroy_value %c2
%retval = tuple ()
return %retval
}
// CHECK-LABEL: sil [ossa] @convert_function__to_optional__owned_as_guaranteed__3 : {{.*}} {
// CHECK: bb0([[C:%[^,]+]] :
// CHECK: [[BORROW_MAYBE_C:%[^,]+]] = function_ref @borrowMaybeCThrowing
// CHECK: [[B:%[^,]+]] = begin_borrow [[C]]
// CHECK: [[MAYBE_B:%[^,]+]] = unchecked_ref_cast [[B]] to $Optional<C>
// CHECK: try_apply [[BORROW_MAYBE_C]]([[MAYBE_B]])
// CHECK: normal [[SUCCESS:bb[0-9]+]]
// CHECK: error [[FAILURE:bb[0-9]+]]
// CHECK: [[SUCCESS]]
// CHECK: end_borrow [[B]]
// CHECK: destroy_value [[C]]
// CHECK: [[FAILURE]]([[ERROR:%[^,]+]] :
// CHECK: end_borrow [[B]]
// CHECK: destroy_value [[C]]
// CHECK: throw [[ERROR]]
// CHECK-LABEL: } // end sil function 'convert_function__to_optional__owned_as_guaranteed__3'
sil [ossa] @convert_function__to_optional__owned_as_guaranteed__3 : $@convention(thin) (@owned C) -> (@error Error) {
entry(%c : @owned $C):
%borrowMaybeC = function_ref @borrowMaybeCThrowing : $@convention(thin) (@guaranteed Optional<C>) -> (@error Error)
%borrowC = convert_function %borrowMaybeC to $@convention(thin) (@guaranteed C) -> (@error Error)
specify_test "sil_combine_visit_instruction @instruction"
try_apply %borrowC(%c) : $@convention(thin) (@guaranteed C) -> (@error Error),
normal success,
error failure
success(%void : $()):
destroy_value %c
%retval = tuple ()
return %retval
failure(%error : @owned $Error):
destroy_value %c
throw %error
}
// CHECK-LABEL: sil [ossa] @convert_function__to_optional__owned_as_guaranteed__4 : {{.*}} {
// CHECK: bb0(
// CHECK-SAME: [[C:%[^,]+]] :
// CHECK-SAME: [[C2:%[^,]+]] :
// CHECK-SAME: ):
// CHECK: [[BORROW_MAYBE_C2:%[^,]+]] = function_ref @borrowMaybeC2Throwing
// CHECK: [[B:%[^,]+]] = begin_borrow [[C]]
// CHECK: [[MAYBE_B:%[^,]+]] = unchecked_ref_cast [[B]] to $Optional<C>
// CHECK: [[B2:%[^,]+]] = begin_borrow [[C2]]
// CHECK: [[MAYBE_B2:%[^,]+]] = unchecked_ref_cast [[B2]] to $Optional<C>
// CHECK: try_apply [[BORROW_MAYBE_C2]]([[MAYBE_B]], [[MAYBE_B2]])
// CHECK: normal [[SUCCESS:bb[0-9]+]]
// CHECK: error [[FAILURE:bb[0-9]+]]
// CHECK: [[SUCCESS]]
// CHECK: end_borrow [[B]]
// CHECK: end_borrow [[B2]]
// CHECK: destroy_value [[C]]
// CHECK: destroy_value [[C2]]
// CHECK: [[FAILURE]]([[ERROR:%[^,]+]] :
// CHECK: end_borrow [[B]]
// CHECK: end_borrow [[B2]]
// CHECK: destroy_value [[C]]
// CHECK: destroy_value [[C2]]
// CHECK: throw [[ERROR]]
// CHECK-LABEL: } // end sil function 'convert_function__to_optional__owned_as_guaranteed__4'
sil [ossa] @convert_function__to_optional__owned_as_guaranteed__4 : $@convention(thin) (@owned C, @owned C) -> (@error Error) {
entry(%c : @owned $C, %c2 : @owned $C):
%borrowMaybeC2 = function_ref @borrowMaybeC2Throwing : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> (@error Error)
%borrowC2 = convert_function %borrowMaybeC2 to $@convention(thin) (@guaranteed C, @guaranteed C) -> (@error Error)
specify_test "sil_combine_visit_instruction @instruction"
try_apply %borrowC2(%c, %c2) : $@convention(thin) (@guaranteed C, @guaranteed C) -> (@error Error),
normal success,
error failure
success(%void : $()):
destroy_value %c
destroy_value %c2
%retval = tuple ()
return %retval
failure(%error : @owned $Error):
destroy_value %c
destroy_value %c2
throw %error
}