mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Type annotations for instruction operands are omitted, e.g. ``` %3 = struct $S(%1, %2) ``` Operand types are redundant anyway and were only used for sanity checking in the SIL parser. But: operand types _are_ printed if the definition of the operand value was not printed yet. This happens: * if the block with the definition appears after the block where the operand's instruction is located * if a block or instruction is printed in isolation, e.g. in a debugger The old behavior can be restored with `-Xllvm -sil-print-types`. This option is added to many existing test files which check for operand types in their check-lines.
73 lines
3.8 KiB
Swift
73 lines
3.8 KiB
Swift
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types -parse-as-library %s | %FileCheck %s
|
|
|
|
func use<T>(_: T) {}
|
|
|
|
func escape(_ f: () -> ()) {}
|
|
|
|
protocol P {}
|
|
class C: P {}
|
|
struct S {}
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s26guaranteed_closure_context0A9_capturesyyF
|
|
func guaranteed_captures() {
|
|
// CHECK: [[MUTABLE_TRIVIAL_BOX:%.*]] = alloc_box ${ var S }
|
|
// CHECK: [[MUTABLE_TRIVIAL_BOX_BORROW:%[^,]+]] = begin_borrow [var_decl] [[MUTABLE_TRIVIAL_BOX]]
|
|
var mutableTrivial = S()
|
|
// CHECK: [[MUTABLE_RETAINABLE_BOX:%.*]] = alloc_box ${ var C }
|
|
// CHECK: [[MUTABLE_RETAINABLE_BOX_LIFETIME:%[^,]+]] = begin_borrow [lexical] [var_decl] [[MUTABLE_RETAINABLE_BOX]]
|
|
var mutableRetainable = C()
|
|
// CHECK: [[MUTABLE_ADDRESS_ONLY_BOX:%.*]] = alloc_box ${ var any P }
|
|
// CHECK: [[MUTABLE_ADDRESS_ONLY_BOX_LIFETIME:%[^,]+]] = begin_borrow [lexical] [var_decl] [[MUTABLE_ADDRESS_ONLY_BOX]]
|
|
var mutableAddressOnly: P = C()
|
|
|
|
// CHECK: [[IMMUTABLE_TRIVIAL:%.*]] = apply {{.*}} -> S
|
|
// CHECK: [[MV_IMMUTABLE_TRIVIAL:%.*]] = move_value [var_decl] [[IMMUTABLE_TRIVIAL]] : $S
|
|
|
|
let immutableTrivial = S()
|
|
// CHECK: [[IMMUTABLE_RETAINABLE:%.*]] = apply {{.*}} -> @owned C
|
|
// CHECK: [[B_IMMUTABLE_RETAINABLE:%.*]] = move_value [lexical] [var_decl] [[IMMUTABLE_RETAINABLE]] : $C
|
|
let immutableRetainable = C()
|
|
// CHECK: [[IMMUTABLE_ADDRESS_ONLY:%.*]] = alloc_stack [lexical] [var_decl] $any P
|
|
let immutableAddressOnly: P = C()
|
|
|
|
func captureEverything() {
|
|
use((mutableTrivial, mutableRetainable, mutableAddressOnly,
|
|
immutableTrivial, immutableRetainable, immutableAddressOnly))
|
|
}
|
|
|
|
// CHECK-NOT: copy_value [[MUTABLE_TRIVIAL_BOX]]
|
|
// CHECK-NOT: copy_value [[MUTABLE_RETAINABLE_BOX_LIFETIME]]
|
|
// CHECK-NOT: copy_value [[MUTABLE_ADDRESS_ONLY_BOX_LIFETIME]]
|
|
// CHECK-NOT: copy_value [[IMMUTABLE_RETAINABLE]]
|
|
|
|
// CHECK: [[B_IMMUTABLE_RETAINABLE_BORROW:%.*]] = begin_borrow [[B_IMMUTABLE_RETAINABLE]] : $C
|
|
// CHECK: [[FN:%.*]] = function_ref [[FN_NAME:@\$s26guaranteed_closure_context0A9_capturesyyF17captureEverythingL_yyF]]
|
|
// CHECK: apply [[FN]]([[MUTABLE_TRIVIAL_BOX_BORROW]], [[MUTABLE_RETAINABLE_BOX_LIFETIME]], [[MUTABLE_ADDRESS_ONLY_BOX_LIFETIME]], [[MV_IMMUTABLE_TRIVIAL]], [[B_IMMUTABLE_RETAINABLE_BORROW]], [[IMMUTABLE_ADDRESS_ONLY]])
|
|
captureEverything()
|
|
|
|
// CHECK-NOT: copy_value [[MUTABLE_TRIVIAL_BOX]]
|
|
// CHECK-NOT: copy_value [[MUTABLE_RETAINABLE_BOX_LIFETIME]]
|
|
// CHECK-NOT: copy_value [[MUTABLE_ADDRESS_ONLY_BOX_LIFETIME]]
|
|
// CHECK-NOT: copy_value [[IMMUTABLE_RETAINABLE]]
|
|
|
|
// -- partial_apply still takes ownership of its arguments.
|
|
// CHECK: [[FN:%.*]] = function_ref [[FN_NAME]]
|
|
// CHECK: [[MUTABLE_TRIVIAL_BOX_COPY:%.*]] = copy_value [[MUTABLE_TRIVIAL_BOX_BORROW]]
|
|
// CHECK: [[MUTABLE_RETAINABLE_BOX_COPY:%.*]] = copy_value [[MUTABLE_RETAINABLE_BOX_LIFETIME]]
|
|
// CHECK: [[MUTABLE_ADDRESS_ONLY_BOX_COPY:%.*]] = copy_value [[MUTABLE_ADDRESS_ONLY_BOX_LIFETIME]]
|
|
// CHECK: [[IMMUTABLE_RETAINABLE_COPY:%.*]] = copy_value [[B_IMMUTABLE_RETAINABLE]]
|
|
// CHECK: [[IMMUTABLE_ADDRESS:%.*]] = alloc_stack $any P
|
|
// CHECK: [[CLOSURE:%.*]] = partial_apply {{.*}}([[MUTABLE_TRIVIAL_BOX_COPY]], [[MUTABLE_RETAINABLE_BOX_COPY]], [[MUTABLE_ADDRESS_ONLY_BOX_COPY]], [[MV_IMMUTABLE_TRIVIAL]], [[IMMUTABLE_RETAINABLE_COPY]], [[IMMUTABLE_ADDRESS]])
|
|
// CHECK: [[CONVERT:%.*]] = convert_escape_to_noescape [not_guaranteed] [[CLOSURE]]
|
|
// CHECK: apply {{.*}}[[CONVERT]]
|
|
|
|
// CHECK-NOT: copy_value [[MUTABLE_TRIVIAL_BOX_BORROW]]
|
|
// CHECK-NOT: copy_value [[MUTABLE_RETAINABLE_BOX_LIFETIME]]
|
|
// CHECK-NOT: copy_value [[MUTABLE_ADDRESS_ONLY_BOX_LIFETIME]]
|
|
// CHECK-NOT: copy_value [[IMMUTABLE_RETAINABLE]]
|
|
|
|
escape(captureEverything)
|
|
}
|
|
|
|
// CHECK: sil private [ossa] [[FN_NAME]] : $@convention(thin) (@guaranteed { var S }, @guaranteed { var C }, @guaranteed { var any P }, S, @guaranteed C, @in_guaranteed any P)
|