Files
swift-mirror/test/SILOptimizer/capture_promotion_generic_context.sil
Erik Eckstein 7cceaff5f3 SIL: don't print operand types in textual SIL
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.
2024-11-21 18:49:52 +01:00

127 lines
6.8 KiB
Plaintext

// RUN: %target-swift-frontend -Xllvm -sil-print-types -emit-sil -O -Xllvm -sil-fso-enable-generics=false %s | %FileCheck %s
sil_stage raw
import Builtin
import Swift
typealias Int = Builtin.Int32
// rdar://problem/28945854: When a nongeneric closure was formed inside a
// generic function, the capture promotion pass would erroneously try to
// apply the generic caller's substitutions to the nongeneric callee, violating
// invariants.
// CHECK-LABEL: sil @$s14promotable_boxTf2i_n : $@convention(thin) (Builtin.Int32) -> Builtin.Int32
// CHECK: bb0([[INPUT:%.*]] :
// CHECk-NEXT: return [[INPUT]]
// CHECK: } // end sil function '$s14promotable_boxTf2i_n'
sil [ossa] @promotable_box : $@convention(thin) (@guaranteed <τ_0_0> { var τ_0_0 } <Int>) -> Int {
entry(%b : @guaranteed $<τ_0_0> { var τ_0_0 } <Int>):
%a = project_box %b : $<τ_0_0> { var τ_0_0 } <Int>, 0
%v = load [trivial] %a : $*Int
return %v : $Int
}
// CHECK-LABEL: sil {{.*}}@call_promotable_box_from_generic :
// CHECK: [[F:%.*]] = function_ref @$s14promotable_boxTf2i_n
// CHECK: partial_apply [callee_guaranteed] [[F]](
// CHECK: } // end sil function 'call_promotable_box_from_generic'
sil [ossa] @call_promotable_box_from_generic : $@convention(thin) <T> (@in_guaranteed T, Int) -> @owned @callee_guaranteed () -> Int {
entry(%0 : $*T, %1 : $Int):
%f = function_ref @promotable_box : $@convention(thin) (@guaranteed <τ_0_0> { var τ_0_0 } <Int>) -> Int
%b = alloc_box $<τ_0_0> { var τ_0_0 } <Int>
%a = project_box %b : $<τ_0_0> { var τ_0_0 } <Int>, 0
store %1 to [trivial] %a : $*Int
%k = partial_apply [callee_guaranteed] %f(%b) : $@convention(thin) (@guaranteed <τ_0_0> { var τ_0_0 } <Int>) -> Int
return %k : $@callee_guaranteed () -> Int
}
protocol P {}
// CHECK-LABEL: sil {{.*}}@$s22generic_promotable_boxTf2ni_n : $@convention(thin) <T> (@in_guaranteed T, Builtin.Int32) -> Builtin.Int32
// CHECK: bb0(%0 : $*T, %1 : $Builtin.Int32):
// CHECK-NEXT: return %1 : $Builtin.Int32
// CHECK: } // end sil function '$s22generic_promotable_boxTf2ni_n'
sil [ossa] @generic_promotable_box : $@convention(thin) <T> (@in_guaranteed T, @guaranteed <τ_0_0> { var τ_0_0 } <Int>) -> Int {
entry(%0 : $*T, %b : @guaranteed $<τ_0_0> { var τ_0_0 } <Int>):
%a = project_box %b : $<τ_0_0> { var τ_0_0 } <Int>, 0
%v = load [trivial] %a : $*Int
return %v : $Int
}
// CHECK-LABEL: sil {{.*}}@call_generic_promotable_box_from_different_generic :
// CHECK: bb0(%0 : $*T, %1 : $*U, %2 : $Builtin.Int32):
// CHECK: [[F:%.*]] = function_ref @$s22generic_promotable_boxTf2ni_n : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Builtin.Int32) -> Builtin.Int32
// CHECK-NEXT: [[CLOSURE:%.*]] = partial_apply [callee_guaranteed] [[F]]<U>(%2)
// CHECK-NEXT: return [[CLOSURE]]
// CHECK: } // end sil function 'call_generic_promotable_box_from_different_generic'
sil [ossa] @call_generic_promotable_box_from_different_generic : $@convention(thin) <T, U: P> (@in_guaranteed T, @in_guaranteed U, Int) -> @owned @callee_guaranteed (@in_guaranteed U) -> Int {
entry(%0 : $*T, %1 : $*U, %2 : $Int):
%f = function_ref @generic_promotable_box : $@convention(thin) <V> (@in_guaranteed V, @guaranteed <τ_0_0> { var τ_0_0 } <Int>) -> Int
%b = alloc_box $<τ_0_0> { var τ_0_0 } <Int>
%a = project_box %b : $<τ_0_0> { var τ_0_0 } <Int>, 0
store %2 to [trivial] %a : $*Int
%k = partial_apply [callee_guaranteed] %f<U>(%b) : $@convention(thin) <V> (@in_guaranteed V, @guaranteed <τ_0_0> { var τ_0_0 } <Int>) -> Int
return %k : $@callee_guaranteed (@in_guaranteed U) -> Int
}
enum E<X> {
case None
case Some(X)
}
struct R<T> {
}
// Check that the capture promotion took place and the function now
// take argument of a type E<(R<T>) -> Builtin.Int32>, which used
// to be a slot inside a box.
//
// CHECK-LABEL: sil {{.*}}@$s23generic_promotable_box2Tf2nnni_n : $@convention(thin) <T> (@in_guaranteed R<T>, @in_guaranteed Builtin.Int32, @guaranteed E<(R<T>) -> Builtin.Int32>) -> @out Builtin.Int32 {
// CHECK: bb0(%0 : $*Builtin.Int32, %1 : $*R<T>, %2 : $*Builtin.Int32, %3 : $E<(R<T>) -> Builtin.Int32>):
// CHECK-NOT: project_box
// CHECK: switch_enum %3 : $E<(R<T>) -> Builtin.Int32>
// CHECK-NOT: project_box
// CHECK: } // end sil function '$s23generic_promotable_box2Tf2nnni_n'
sil [ossa] @generic_promotable_box2 : $@convention(thin) <T> (@in_guaranteed R<T>, @in_guaranteed Int, @guaranteed <τ_0_0> { var E<(R<τ_0_0>) -> Int> } <T>) -> @out Int {
entry(%result : $*Int, %0: $*R<T>, %1 : $*Int, %b : @guaranteed $<τ_0_0> { var E< (R<τ_0_0>)->Int > } <T>):
%a = project_box %b : $<τ_0_0> { var E<(R<τ_0_0>)->Int> } <T>, 0
%e = load_borrow %a : $*E<(R<T>)->Int>
switch_enum %e : $E<(R<T>)->Int>, case #E.Some!enumelt : bb1, default bb2
bb1(%f : @guaranteed $@callee_guaranteed @substituted <A, B> (@in_guaranteed A) -> @out B for <R<T>, Int>):
apply %f(%result, %0) : $@callee_guaranteed @substituted <A, B> (@in_guaranteed A) -> @out B for <R<T>, Int>
end_borrow %e : $E<(R<T>)->Int>
br exit
bb2:
end_borrow %e : $E<(R<T>)->Int>
copy_addr %1 to %result : $*Int
br exit
exit:
%r = tuple ()
return %r : $()
}
// Check that alloc_box was eliminated and a specialized version of the
// closure is invoked.
// CHECK-LABEL: sil {{.*}}@call_generic_promotable_box_from_different_generic2 :
// CHECK: bb0(%0 : $*R<T>, %1 : $*E<(R<U>) -> Builtin.Int32>, %2 : $*Builtin.Int32):
// CHECK: [[F:%.*]] = function_ref @$s23generic_promotable_box2Tf2nnni_n : $@convention(thin) <τ_0_0> (@in_guaranteed R<τ_0_0>, @in_guaranteed Builtin.Int32, @guaranteed E<(R<τ_0_0>) -> Builtin.Int32>) -> @out Builtin.Int32
// CHECK: %4 = load %1 : $*E<(R<U>) -> Builtin.Int32>
// CHECK-NEXT: [[CLOSURE:%.*]] = partial_apply [callee_guaranteed] [[F]]<U>(%2, %4)
// CHECK-NEXT: retain_value %4
// CHECK-NEXT: return [[CLOSURE]]
// CHECK: } // end sil function 'call_generic_promotable_box_from_different_generic2'
sil [ossa] @call_generic_promotable_box_from_different_generic2 : $@convention(thin) <T, U: P> (@in_guaranteed R<T>, @in_guaranteed E<(R<U>)->Int>, @in Int) -> @owned @callee_guaranteed (@in_guaranteed R<U>) -> @out Int {
entry(%0 : $*R<T>, %1 : $*E<(R<U>)->Int>, %2 : $*Int):
%f = function_ref @generic_promotable_box2 : $@convention(thin) <V> (@in_guaranteed R<V>, @in_guaranteed Int, @guaranteed <τ_0_0> { var E<(R<τ_0_0>)->Int> } <V>) -> @out Int
%b = alloc_box $<τ_0_0> { var E<(R<τ_0_0>)->Int> } <U>
%a = project_box %b : $<τ_0_0> { var E<(R<τ_0_0>)->Int> } <U>, 0
copy_addr %1 to [init] %a : $*E<(R<U>)->Int>
%k = partial_apply [callee_guaranteed] %f<U>(%2, %b) : $@convention(thin) <V> (@in_guaranteed R<V>, @in_guaranteed Int, @guaranteed <τ_0_0> { var E<(R<τ_0_0>)->Int> } <V>) -> @out Int
return %k : $@callee_guaranteed (@in_guaranteed R<U>) -> @out Int
}