// RUN: %target-sil-opt %s // REQUIRES: concurrency // This test ensures that the SILVerifier does not enforce that concurrent // functions must have non-box parameters in raw SIL. sil_stage raw import Builtin func f(_: @escaping @Sendable () -> ()) @_hasMissingDesignatedInitializers class F { func useConcurrent(_: @escaping @Sendable () -> ()) init() } enum FakeOptional { case none case some(T) } struct Int { var _value: Builtin.Int64 } class Klass {} //////////////////// // Loadable Type // //////////////////// sil @$s37concurrentfunction_capturediagnostics1fyyyyJcF : $@convention(thin) (@guaranteed @Sendable @callee_guaranteed () -> ()) -> () sil @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %5 sil @$s37concurrentfunction_capturediagnostics20testCaseTrivialValueyyFyyJcfU_ : $@convention(thin) @Sendable (@guaranteed { var Int }) -> () // user: %10 // testCaseTrivialValue() sil hidden [ossa] @$s37concurrentfunction_capturediagnostics20testCaseTrivialValueyyF : $@convention(thin) () -> () { bb0: %0 = alloc_box ${ var Int }, var, name "i" // users: %34, %8, %1 %1 = project_box %0 : ${ var Int }, 0 // users: %30, %26, %18, %9, %6 %2 = integer_literal $Builtin.IntLiteral, 17 // user: %5 %3 = metatype $@thin Int.Type // user: %5 // function_ref Int.init(_builtinIntegerLiteral:) %4 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %5 %5 = apply %4(%2, %3) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %6 store %5 to [trivial] %1 : $*Int // id: %6 // function_ref closure #1 in testCaseTrivialValue() %7 = function_ref @$s37concurrentfunction_capturediagnostics20testCaseTrivialValueyyFyyJcfU_ : $@convention(thin) @Sendable (@guaranteed { var Int }) -> () // user: %10 %8 = copy_value %0 : ${ var Int } // user: %10 mark_function_escape %1 : $*Int // id: %9 %10 = partial_apply [callee_guaranteed] %7(%8) : $@convention(thin) @Sendable (@guaranteed { var Int }) -> () // users: %13, %12 // function_ref f(_:) %11 = function_ref @$s37concurrentfunction_capturediagnostics1fyyyyJcF : $@convention(thin) (@guaranteed @Sendable @callee_guaranteed () -> ()) -> () // user: %12 %12 = apply %11(%10) : $@convention(thin) (@guaranteed @Sendable @callee_guaranteed () -> ()) -> () destroy_value %10 : $@Sendable @callee_guaranteed () -> () // id: %13 destroy_value %0 : ${ var Int } %35 = tuple () // user: %36 return %35 : $() // id: %36 } // end sil function '$s37concurrentfunction_capturediagnostics20testCaseTrivialValueyyF' ///////////////////////////////////////// // Address Only Type Success (For Now) // ///////////////////////////////////////// protocol MyProt { var i: Int { get set } var k: FakeOptional { get set } } sil @$s37concurrentfunction_capturediagnostics1FCACycfC : $@convention(method) (@thick F.Type) -> @owned F // user: %5 sil @$s37concurrentfunction_capturediagnostics20testCaseAddressOnly21iyx_tAA6MyProtRzlFyyJcfU_ : $@convention(thin) @Sendable <τ_0_0 where τ_0_0 : MyProt> (@guaranteed <τ_0_0 where τ_0_0 : MyProt> { var τ_0_0 } <τ_0_0>) -> () // user: %15 sil @$s37concurrentfunction_capturediagnostics1FC13useConcurrentyyyyJcF : $@convention(method) (@guaranteed @Sendable @callee_guaranteed () -> (), @guaranteed F) -> () // user: %19 sil @$s37concurrentfunction_capturediagnostics17inoutUserOptKlassyyAA0F0CSgzF : $@convention(thin) (@inout FakeOptional) -> () // user: %29 sil @$s37concurrentfunction_capturediagnostics1FCfD : $@convention(method) (@owned F) -> () // This is address only so we shouldn't crash. sil hidden [ossa] @$s37concurrentfunction_capturediagnostics20testCaseAddressOnly21iyx_tAA6MyProtRzlF : $@convention(thin) (@in_guaranteed T) -> () { bb0(%0 : $*T): debug_value %0 : $*T, let, name "i", argno 1, expr op_deref // id: %1 %2 = alloc_stack $F, var, name "f2" // users: %34, %33, %7 %3 = metatype $@thick F.Type // user: %5 // function_ref F.__allocating_init() %4 = function_ref @$s37concurrentfunction_capturediagnostics1FCACycfC : $@convention(method) (@thick F.Type) -> @owned F // user: %5 %5 = apply %4(%3) : $@convention(method) (@thick F.Type) -> @owned F // users: %6, %7 %6 = copy_value %5 : $F // users: %11, %12 store %5 to [init] %2 : $*F // id: %7 %8 = alloc_box $<τ_0_0 where τ_0_0 : MyProt> { var τ_0_0 } , var, name "i2" // users: %32, %14, %9 %9 = project_box %8 : $<τ_0_0 where τ_0_0 : MyProt> { var τ_0_0 } , 0 // users: %24, %10 copy_addr %0 to [init] %9 : $*T // id: %10 %11 = copy_value %6 : $F // users: %23, %18 destroy_value %6 : $F // id: %12 // function_ref closure #1 in testCaseAddressOnly2(i:) %13 = function_ref @$s37concurrentfunction_capturediagnostics20testCaseAddressOnly21iyx_tAA6MyProtRzlFyyJcfU_ : $@convention(thin) @Sendable <τ_0_0 where τ_0_0 : MyProt> (@guaranteed <τ_0_0 where τ_0_0 : MyProt> { var τ_0_0 } <τ_0_0>) -> () // user: %15 %14 = copy_value %8 : $<τ_0_0 where τ_0_0 : MyProt> { var τ_0_0 } // user: %15 %15 = partial_apply [callee_guaranteed] %13(%14) : $@convention(thin) @Sendable <τ_0_0 where τ_0_0 : MyProt> (@guaranteed <τ_0_0 where τ_0_0 : MyProt> { var τ_0_0 } <τ_0_0>) -> () // users: %17, %22 // function_ref F.useConcurrent(_:) %16 = function_ref @$s37concurrentfunction_capturediagnostics1FC13useConcurrentyyyyJcF : $@convention(method) (@guaranteed @Sendable @callee_guaranteed () -> (), @guaranteed F) -> () // user: %19 %17 = begin_borrow %15 : $@Sendable @callee_guaranteed () -> () // users: %20, %19 %18 = begin_borrow %11 : $F // users: %21, %19 %19 = apply %16(%17, %18) : $@convention(method) (@guaranteed @Sendable @callee_guaranteed () -> (), @guaranteed F) -> () end_borrow %17 : $@Sendable @callee_guaranteed () -> () // id: %20 end_borrow %18 : $F // id: %21 destroy_value %15 : $@Sendable @callee_guaranteed () -> () // id: %22 destroy_value %11 : $F // id: %23 %24 = begin_access [modify] [dynamic] %9 : $*T // users: %31, %26 %25 = witness_method $T, #MyProt.k!modify : (inout Self) -> () -> () : $@yield_once @convention(witness_method: MyProt) <τ_0_0 where τ_0_0 : MyProt> (@inout τ_0_0) -> @yields @inout FakeOptional // user: %26 (%26, %27) = begin_apply %25(%24) : $@yield_once @convention(witness_method: MyProt) <τ_0_0 where τ_0_0 : MyProt> (@inout τ_0_0) -> @yields @inout FakeOptional // users: %29, %30 // function_ref inoutUserOptKlass(_:) %28 = function_ref @$s37concurrentfunction_capturediagnostics17inoutUserOptKlassyyAA0F0CSgzF : $@convention(thin) (@inout FakeOptional) -> () // user: %29 %29 = apply %28(%26) : $@convention(thin) (@inout FakeOptional) -> () end_apply %27 as $() // id: %30 end_access %24 : $*T // id: %31 destroy_value %8 : $<τ_0_0 where τ_0_0 : MyProt> { var τ_0_0 } // id: %32 destroy_addr %2 : $*F // id: %33 dealloc_stack %2 : $*F // id: %34 %35 = tuple () // user: %36 return %35 : $() // id: %36 } // end sil function '$s37concurrentfunction_capturediagnostics20testCaseAddressOnly21iyx_tAA6MyProtRzlF' sil_vtable [serialized] F { #F.useConcurrent: (F) -> (@escaping @Sendable () -> ()) -> () : @$s37concurrentfunction_capturediagnostics1FC13useConcurrentyyyyJcF // F.useConcurrent(_:) #F.init!allocator: (F.Type) -> () -> F : @$s37concurrentfunction_capturediagnostics1FCACycfC // F.__allocating_init() #F.deinit!deallocator: @$s37concurrentfunction_capturediagnostics1FCfD // F.__deallocating_deinit }