Files
swift-mirror/test/SILOptimizer/capture_promotion.swift
Michael Gottesman 3236bc26fa [region-isolation] Refactor out the stubify dead function if no longer used functionality from move only checker into its own pass and put it before region based isolation.
I am doing this since region based isolation hit the same issue that the move
checker did. So it makes sense to refactor the functionality into its own pass
and move it into a helper pass that runs before both.

It is very conservative and only stubifies functions that the specialization
passes explicitly mark as this being ok to be done to.
2024-03-01 13:11:07 -08:00

35 lines
1023 B
Swift

// RUN: %target-swift-frontend %s -emit-sil -o - | %FileCheck %s
class Foo {
func foo() -> Int {
return 1
}
}
class Bar {
}
struct Baz {
var bar = Bar()
var x = 42
}
// CHECK: sil hidden @$s17capture_promotion05test_a1_B0SiycyF
func test_capture_promotion() -> () -> Int {
var x : Int = 1; x = 1
var y : Foo = Foo(); y = Foo()
var z : Baz = Baz(); z = Baz()
// CHECK-NOT: alloc_box
// CHECK: [[CLOSURE0_PROMOTE0:%.*]] = function_ref @$s17capture_promotion05test_a1_B0SiycyFSiycfU_Tf2iii_n
// CHECK: partial_apply [callee_guaranteed] [[CLOSURE0_PROMOTE0]]({{%[0-9]*}}, {{%[0-9]*}}, {{%[0-9]*}})
return { x + y.foo() + z.x }
}
// CHECK: sil private @$s17capture_promotion05test_a1_B0SiycyFSiycfU_Tf2iii_n : $@convention(thin) (Int, @guaranteed Foo, @guaranteed Baz) -> Int
// CHECK: sil private [_semantics "sil.optimizer.delete_if_unused"] @$s17capture_promotion05test_a1_B0SiycyFSiycfU_ : $@convention(thin) (@guaranteed { var Int }, @guaranteed { var Foo }, @guaranteed { var Baz }) -> Int {