mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The new instruction is needed for opaque values mode to allow values to be extracted from tuples containing packs which will appear for example as function arguments.
78 lines
4.2 KiB
Plaintext
78 lines
4.2 KiB
Plaintext
// RUN: %target-sil-opt -enable-sil-verify-all -enable-sil-opaque-values -inline %s | %FileCheck %s
|
|
|
|
// Check cloning of instructions that are only legal in opaque values mode.
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
struct WeakBox<T : AnyObject> {
|
|
weak var t: T?
|
|
}
|
|
|
|
// CHECK-LABEL: sil [ossa] @strong_copy_weak_value_caller : {{.*}} {
|
|
// CHECK: bb0([[INSTANCE:%[^,]+]] :
|
|
// CHECK: [[WEAK_OPTIONAL:%[^,]+]] = struct_extract [[INSTANCE]]
|
|
// CHECK: [[STRONG_OPTIONAL:%[^,]+]] = strong_copy_weak_value [[WEAK_OPTIONAL]]
|
|
// CHECK: return [[STRONG_OPTIONAL]]
|
|
// CHECK-LABEL: } // end sil function 'strong_copy_weak_value_caller'
|
|
sil [ossa] @strong_copy_weak_value_caller : $@convention(thin) <T where T : AnyObject> (@in_guaranteed WeakBox<T>) -> @owned Optional<T> {
|
|
bb0(%instance : @guaranteed $WeakBox<T>):
|
|
%callee = function_ref @strong_copy_weak_value : $@convention(thin) <T where T : AnyObject> (@in_guaranteed WeakBox<T>) -> @owned Optional<T>
|
|
%retval = apply %callee<T>(%instance) : $@convention(thin) <T where T : AnyObject> (@in_guaranteed WeakBox<T>) -> @owned Optional<T>
|
|
return %retval : $Optional<T>
|
|
}
|
|
|
|
sil [always_inline] [ossa] @strong_copy_weak_value : $@convention(thin) <T where T : AnyObject> (@in_guaranteed WeakBox<T>) -> @owned Optional<T> {
|
|
bb0(%instance : @guaranteed $WeakBox<T>):
|
|
%weak_optional = struct_extract %instance : $WeakBox<T>, #WeakBox.t
|
|
%strong_optional = strong_copy_weak_value %weak_optional : $@sil_weak Optional<T>
|
|
return %strong_optional : $Optional<T>
|
|
}
|
|
|
|
// CHECK-LABEL: sil [ossa] @tuple_pack_extract_caller : {{.*}} {
|
|
// CHECK: bb0([[TUPLE:%[^,]+]] :
|
|
// CHECK: [[ZERO:%[^,]+]] = integer_literal
|
|
// CHECK: [[INDEX:%[^,]+]] = dynamic_pack_index [[ZERO]]
|
|
// CHECK: open_pack_element [[INDEX]] of <each U_1> at <Pack{repeat each T}>, shape $each U_1, uuid [[UUID:"[A-F0-9\-]+"]]
|
|
// CHECK: tuple_pack_extract [[INDEX]] of [[TUPLE]] : $(repeat each T) as $@pack_element([[UUID]]) each U_1
|
|
// CHECK-LABEL: } // end sil function 'tuple_pack_extract_caller'
|
|
sil [ossa] @tuple_pack_extract_caller : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
|
|
entry(%tuple : @guaranteed $(repeat each T)):
|
|
%callee = function_ref @tuple_pack_extract : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> ()
|
|
%retval = apply %callee<Pack{repeat each T}>(%tuple) : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> ()
|
|
return %retval : $()
|
|
}
|
|
|
|
sil [always_inline] [ossa] @tuple_pack_extract : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
|
|
entry(%tuple : @guaranteed $(repeat each T)):
|
|
%zero = integer_literal $Builtin.Word, 0
|
|
%index = dynamic_pack_index %zero of $Pack{repeat each T}
|
|
%opened = open_pack_element %index of <each U_1> at <Pack{repeat each T}>, shape $U_1, uuid "00000000-0000-0000-0000-000000000000"
|
|
%elt = tuple_pack_extract %index of %tuple : $(repeat each T) as $@pack_element("00000000-0000-0000-0000-000000000000") U_1
|
|
%retval = tuple ()
|
|
return %retval : $()
|
|
}
|
|
|
|
// CHECK-LABEL: sil [ossa] @weak_copy_value_caller : {{.*}} {
|
|
// CHECK: bb0([[STRONG_OPTIONAL:%[^,]+]] :
|
|
// CHECK: [[WEAK_OPTIONAL:%[^,]+]] = weak_copy_value [[STRONG_OPTIONAL]]
|
|
// CHECK: destroy_value [[STRONG_OPTIONAL]]
|
|
// CHECK: [[RETVAL:%[^,]+]] = struct $WeakBox<T> ([[WEAK_OPTIONAL]] :
|
|
// CHECK: return [[RETVAL]]
|
|
// CHECK-LABEL: } // end sil function 'weak_copy_value_caller'
|
|
sil [ossa] @weak_copy_value_caller : $@convention(thin) <T where T : AnyObject> (@owned Optional<T>) -> @out WeakBox<T> {
|
|
bb0(%value : @owned $Optional<T>):
|
|
%callee = function_ref @weak_copy_value : $@convention(thin) <T where T : AnyObject> (@owned Optional<T>) -> @out WeakBox<T>
|
|
%retval = apply %callee<T>(%value) : $@convention(thin) <T where T : AnyObject> (@owned Optional<T>) -> @out WeakBox<T>
|
|
return %retval : $WeakBox<T>
|
|
}
|
|
|
|
sil [always_inline] [ossa] @weak_copy_value : $@convention(thin) <T where T : AnyObject> (@owned Optional<T>) -> @out WeakBox<T> {
|
|
bb0(%value : @owned $Optional<T>):
|
|
%weak_value = weak_copy_value %value : $Optional<T>
|
|
destroy_value %value : $Optional<T>
|
|
%retval = struct $WeakBox<T> (%weak_value : $@sil_weak Optional<T>)
|
|
return %retval : $WeakBox<T>
|
|
}
|
|
|