blob: 88d23535cafd7fe8d288f5f8b0de38dbaa88775f [file] [log] [blame]
// RUN: %target-sil-opt -enable-sil-verify-all %s -capture-prop | FileCheck %s
// Check the CapturePropagation specialized the reabstraction thunk.
sil_stage raw
import Builtin
import Swift
sil @capture_helper_2 : $@convention(thin) (Int32) -> ()
// CHECK-LABEL: test_capture_propagation
// CHECK: %[[FR:[0-9]+]] = function_ref @_TTSf3cpfr24_TF8capturep6helperFSiT__n___TTRXFo_dSi_dT__XFo_iSi_dT__ : $@convention(thin) (@in Int32) -> ()
// CHECK: partial_apply %[[FR]]() : $@convention(thin) (@in Int32) -> ()
sil private @test_capture_propagation : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $Int32 // users: %3, %9, %10
%1 = integer_literal $Builtin.Int32, 3 // user: %2
%2 = struct $Int32 (%1 : $Builtin.Int32) // user: %3
store %2 to %0 : $*Int32 // id: %3
// function_ref capturep.helper (Swift.Int32) -> ()
%4 = function_ref @_TF8capturep6helperFSiT_ : $@convention(thin) (Int32) -> () // user: %5
%5 = thin_to_thick_function %4 : $@convention(thin) (Int32) -> () to $@callee_owned (Int32) -> () // user: %7
// function_ref reabstraction thunk helper from @callee_owned (@unowned Swift.Int32) -> (@unowned ()) to @callee_owned (@in Swift.Int32) -> (@unowned ())
%6 = function_ref @_TTRXFo_dSi_dT__XFo_iSi_dT__ : $@convention(thin) (@in Int32, @owned @callee_owned (Int32) -> ()) -> () // user: %7
%7 = partial_apply %6(%5) : $@convention(thin) (@in Int32, @owned @callee_owned (Int32) -> ()) -> () // user: %9
// function_ref specialization <Swift.Int32> of capturep.generic <A>(A, (A) -> ()) -> ()
%8 = function_ref @_TTSgSi___TF8capturep7genericU__FTQ_FQ_T__T_ : $@convention(thin) (@in Int32, @owned @callee_owned (@in Int32) -> ()) -> () // user: %9
%9 = apply %8(%0, %7) : $@convention(thin) (@in Int32, @owned @callee_owned (@in Int32) -> ()) -> ()
%11 = thin_to_thick_function %4 : $@convention(thin) (Int32) -> () to $@callee_owned (Int32) -> () // user: %7
%12 = function_ref @bad_thunk : $@convention(thin) (@in Int32, @owned @callee_owned (Int32) -> ()) -> ()
%13 = partial_apply %12(%11) : $@convention(thin) (@in Int32, @owned @callee_owned (Int32) -> ()) -> () // user: %9
%14 = apply %8(%0, %13) : $@convention(thin) (@in Int32, @owned @callee_owned (@in Int32) -> ()) -> ()
dealloc_stack %0 : $*Int32 // id: %10
%15 = tuple () // user: %12
return %15 : $() // id: %12
}
// capturep.helper (Swift.Int32) -> ()
sil @_TF8capturep6helperFSiT_ : $@convention(thin) (Int32) -> () {
bb0(%0 : $Int32):
%1 = tuple () // user: %2
return %1 : $() // id: %2
}
sil @bad_thunk : $@convention(thin) (@in Int32, @owned @callee_owned (Int32) -> ()) -> ()
// reabstraction thunk helper from @callee_owned (@unowned Swift.Int32) -> (@unowned ()) to @callee_owned (@in Swift.Int32) -> (@unowned ())
sil shared [transparent] @_TTRXFo_dSi_dT__XFo_iSi_dT__ : $@convention(thin) (@in Int32, @owned @callee_owned (Int32) -> ()) -> () {
bb0(%0 : $*Int32, %1 : $@callee_owned (Int32) -> ()):
%2 = load %0 : $*Int32 // user: %3
%3 = apply %1(%2) : $@callee_owned (Int32) -> () // user: %4
return %3 : $() // id: %4
}
// specialization <Swift.Int32> of capturep.generic <A>(A, (A) -> ()) -> ()
sil shared [noinline] @_TTSgSi___TF8capturep7genericU__FTQ_FQ_T__T_ : $@convention(thin) (@in Int32, @owned @callee_owned (@in Int32) -> ()) -> () {
bb0(%0 : $*Int32, %1 : $@callee_owned (@in Int32) -> ()):
%2 = alloc_stack $Int32 // users: %4, %5, %6
%3 = load %0 : $*Int32 // user: %4
store %3 to %2 : $*Int32 // id: %4
%5 = apply %1(%2) : $@callee_owned (@in Int32) -> ()
dealloc_stack %2 : $*Int32 // id: %6
%7 = tuple () // user: %8
return %7 : $() // id: %8
}
/*
// reabstraction thunk helper from @callee_owned (@unowned Swift.Int32) -> (@unowned ()) to @callee_owned (@in Swift.Int32) -> (@unowned ())
sil shared [transparent] @_TTRXFo_dSi_dT__XFo_iSi_dT__ : $@convention(thin) (@in Int32, @owned @callee_owned (Int32) -> ()) -> () {
bb0(%0 : $*Int32, %1 : $@callee_owned (Int32) -> ()):
%2 = load %0 : $*Int32 // user: %3
%3 = apply %1(%2) : $@callee_owned (Int32) -> () // user: %4
return %3 : $() // id: %4
}
*/
sil @_TFtest_capture_propagation2_closure : $@convention(thin) (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> () {
bb0(%0 : $Builtin.Int32, %1 : $Builtin.FPIEEE32, %2 : $Builtin.RawPointer, %3 : $*Builtin.Word):
%9999 = tuple()
return %9999 : $()
}
sil_global [fragile] @globalinit_33_06E7F1D906492AE070936A9B58CBAE1C_token8 : $Builtin.Word
sil @test_capture_propagation2_caller : $@convention(thin) () -> () {
%0 = integer_literal $Builtin.Int32, 0
%1 = float_literal $Builtin.FPIEEE32, 0
%2 = string_literal utf8 "123"
%3 = global_addr @globalinit_33_06E7F1D906492AE070936A9B58CBAE1C_token8 : $*Builtin.Word
%4 = function_ref @_TFtest_capture_propagation2_closure : $@convention(thin) (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> ()
%5 = thin_to_thick_function %4 : $@convention(thin) (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> () to $@callee_owned (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> ()
%6 = function_ref @test_capture_propagation2_callee : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
%7 = function_ref @test_capture_propagation2_thunk : $@convention(thin) (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word, @owned @callee_owned (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> ()) -> ()
%8 = partial_apply %7(%0, %1, %2, %3, %5) : $@convention(thin) (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word, @owned @callee_owned (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> ()) -> ()
apply %6(%8) : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
%9999 = tuple()
return %9999 : $()
}
sil shared @test_capture_propagation2_thunk : $@convention(thin) (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word, @owned @callee_owned (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> ()) -> () {
bb0(%0 : $Builtin.Int32, %1 : $Builtin.FPIEEE32, %2 : $Builtin.RawPointer, %3 : $*Builtin.Word, %4 : $@callee_owned (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> ()):
apply %4(%0, %1, %2, %3) : $@callee_owned (Builtin.Int32, Builtin.FPIEEE32, Builtin.RawPointer, @in Builtin.Word) -> ()
%9999 = tuple()
return %9999 : $()
}
sil shared @test_capture_propagation2_callee : $@convention(thin) (@owned @callee_owned () -> ()) -> () {
bb0(%0 : $@callee_owned () -> ()):
apply %0() : $@callee_owned () -> ()
%9999 = tuple()
return %9999 : $()
}