Skip to content

Instantly share code, notes, and snippets.

@kntkymt
Last active December 4, 2023 12:41
Show Gist options
  • Save kntkymt/d24f5003691e8c50be5f4d572bc8a7f3 to your computer and use it in GitHub Desktop.
Save kntkymt/d24f5003691e8c50be5f4d572bc8a7f3 to your computer and use it in GitHub Desktop.
Objective-C async function SIL
sil_stage canonical
import Builtin
import Swift
import SwiftShims
import Foundation
@_hasStorage @_hasInitialValue @MainActor let myClass: MyClass { get }
// myClass
sil_global hidden [let] @$s4main7myClassSo02MyC0Cvp : $MyClass
// main
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
// function_ref async_Main
%2 = function_ref @async_Main : $@convention(thin) @async () -> () // user: %8
%3 = integer_literal $Builtin.Int64, 2048 // user: %4
%4 = struct $Int (%3 : $Builtin.Int64) // user: %10
%5 = metatype $@thick ().Type // user: %6
%6 = init_existential_metatype %5 : $@thick ().Type, $@thick any Any.Type // user: %10
// function_ref thunk for @escaping @convention(thin) @async () -> ()
%7 = function_ref @$sIetH_yts5Error_pIegHrzo_TR : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) // user: %8
%8 = partial_apply [callee_guaranteed] %7(%2) : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) // user: %9
%9 = convert_function %8 : $@async @callee_guaranteed () -> (@out (), @error any Error) to $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()> // user: %10
%10 = builtin "createAsyncTask"<()>(%4 : $Int, %6 : $@thick any Any.Type, %9 : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer) // user: %11
%11 = tuple_extract %10 : $(Builtin.NativeObject, Builtin.RawPointer), 0 // user: %13
// function_ref swift_job_run
%12 = function_ref @swift_job_run : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> () // user: %18
%13 = builtin "convertTaskToJob"(%11 : $Builtin.NativeObject) : $Builtin.Job // user: %14
%14 = struct $UnownedJob (%13 : $Builtin.Job) // user: %18
// function_ref swift_task_getMainExecutor
%15 = function_ref @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor // user: %16
%16 = apply %15() : $@convention(thin) () -> Builtin.Executor // user: %17
%17 = struct $UnownedSerialExecutor (%16 : $Builtin.Executor) // user: %18
%18 = apply %12(%14, %17) : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
// function_ref swift_task_asyncMainDrainQueue
%19 = function_ref @swift_task_asyncMainDrainQueue : $@convention(thin) () -> Never // user: %20
%20 = apply %19() : $@convention(thin) () -> Never
unreachable // id: %21
} // end sil function 'main'
// async_Main
sil hidden @async_Main : $@convention(thin) @async () -> () {
bb0:
// function_ref swift_task_getMainExecutor
%0 = function_ref @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor // user: %1
%1 = apply %0() : $@convention(thin) () -> Builtin.Executor // user: %2
%2 = enum $Optional<Builtin.Executor>, #Optional.some!enumelt, %1 : $Builtin.Executor // user: %23
alloc_global @$s4main7myClassSo02MyC0Cvp // id: %3
%4 = global_addr @$s4main7myClassSo02MyC0Cvp : $*MyClass // users: %10, %8
%5 = metatype $@thick MyClass.Type // user: %7
// function_ref MyClass.__allocating_init()
%6 = function_ref @$sSo7MyClassCABycfC : $@convention(method) (@thick MyClass.Type) -> @owned MyClass // user: %7
%7 = apply %6(%5) : $@convention(method) (@thick MyClass.Type) -> @owned MyClass // user: %8
store %7 to %4 : $*MyClass // id: %8
%9 = alloc_stack $() // users: %24, %12
%10 = load %4 : $*MyClass // users: %11, %20
%11 = objc_method %10 : $MyClass, #MyClass.handleVoid!foreign : (MyClass) -> () async -> (), $@convention(objc_method) (Optional<@convention(block) () -> ()>, MyClass) -> () // user: %20
%12 = get_async_continuation_addr (), %9 : $*() // users: %22, %13
%13 = struct $UnsafeContinuation<(), Never> (%12 : $Builtin.RawUnsafeContinuation) // user: %16
%14 = alloc_stack $@block_storage UnsafeContinuation<(), Never> // users: %21, %18, %15
%15 = project_block_storage %14 : $*@block_storage UnsafeContinuation<(), Never> // user: %16
store %13 to %15 : $*UnsafeContinuation<(), Never> // id: %16
// function_ref @objc completion handler block implementation for @escaping @callee_unowned @convention(block) () -> () with result type ()
%17 = function_ref @$sIeyB_ytTz_ : $@convention(c) (@inout_aliasable @block_storage UnsafeContinuation<(), Never>) -> () // user: %18
%18 = init_block_storage_header %14 : $*@block_storage UnsafeContinuation<(), Never>, invoke %17 : $@convention(c) (@inout_aliasable @block_storage UnsafeContinuation<(), Never>) -> (), type $@convention(block) () -> () // user: %19
%19 = enum $Optional<@convention(block) () -> ()>, #Optional.some!enumelt, %18 : $@convention(block) () -> () // user: %20
%20 = apply %11(%19, %10) : $@convention(objc_method) (Optional<@convention(block) () -> ()>, MyClass) -> ()
dealloc_stack %14 : $*@block_storage UnsafeContinuation<(), Never> // id: %21
await_async_continuation %12 : $Builtin.RawUnsafeContinuation, resume bb1 // id: %22
bb1: // Preds: bb0
hop_to_executor %2 : $Optional<Builtin.Executor> // id: %23
dealloc_stack %9 : $*() // id: %24
%25 = integer_literal $Builtin.Int32, 0 // user: %26
%26 = struct $Int32 (%25 : $Builtin.Int32) // user: %28
// function_ref exit
%27 = function_ref @exit : $@convention(c) (Int32) -> Never // user: %28
%28 = apply %27(%26) : $@convention(c) (Int32) -> Never
unreachable // id: %29
} // end sil function 'async_Main'
// thunk for @escaping @convention(thin) @async () -> ()
sil shared [transparent] [reabstraction_thunk] @$sIetH_yts5Error_pIegHrzo_TR : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) {
// %1 // user: %2
bb0(%0 : $*(), %1 : $@convention(thin) @async () -> ()):
%2 = apply %1() : $@convention(thin) @async () -> ()
%3 = tuple () // user: %4
return %3 : $() // id: %4
} // end sil function '$sIetH_yts5Error_pIegHrzo_TR'
// swift_job_run
sil [available 12.0.0] @swift_job_run : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
// swift_task_getMainExecutor
sil [available 12.0.0] @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor
// swift_task_asyncMainDrainQueue
sil [available 12.0.0] @swift_task_asyncMainDrainQueue : $@convention(thin) () -> Never
// MyClass.__allocating_init()
sil shared @$sSo7MyClassCABycfC : $@convention(method) (@thick MyClass.Type) -> @owned MyClass {
// %0 "$metatype" // user: %1
bb0(%0 : $@thick MyClass.Type):
%1 = thick_to_objc_metatype %0 : $@thick MyClass.Type to $@objc_metatype MyClass.Type // user: %2
%2 = alloc_ref_dynamic [objc] %1 : $@objc_metatype MyClass.Type, $MyClass // user: %4
// function_ref @nonobjc MyClass.init()
%3 = function_ref @$sSo7MyClassCABycfcTO : $@convention(method) (@owned MyClass) -> @owned MyClass // user: %4
%4 = apply %3(%2) : $@convention(method) (@owned MyClass) -> @owned MyClass // user: %5
return %4 : $MyClass // id: %5
} // end sil function '$sSo7MyClassCABycfC'
// @objc completion handler block implementation for @escaping @callee_unowned @convention(block) () -> () with result type ()
sil shared [transparent] [thunk] @$sIeyB_ytTz_ : $@convention(c) (@inout_aliasable @block_storage UnsafeContinuation<(), Never>) -> () {
// %0 // user: %1
bb0(%0 : $*@block_storage UnsafeContinuation<(), Never>):
%1 = project_block_storage %0 : $*@block_storage UnsafeContinuation<(), Never> // user: %2
%2 = load %1 : $*UnsafeContinuation<(), Never> // user: %5
%3 = alloc_stack $() // users: %6, %5
// function_ref _resumeUnsafeContinuation<A>(_:_:)
%4 = function_ref @$ss25_resumeUnsafeContinuationyySccyxs5NeverOG_xntlF : $@convention(thin) <τ_0_0> (UnsafeContinuation<τ_0_0, Never>, @in τ_0_0) -> () // user: %5
%5 = apply %4<()>(%2, %3) : $@convention(thin) <τ_0_0> (UnsafeContinuation<τ_0_0, Never>, @in τ_0_0) -> ()
dealloc_stack %3 : $*() // id: %6
return undef : $() // id: %7
} // end sil function '$sIeyB_ytTz_'
// _resumeUnsafeContinuation<A>(_:_:)
sil shared [available 12.0.0] @$ss25_resumeUnsafeContinuationyySccyxs5NeverOG_xntlF : $@convention(thin) <T> (UnsafeContinuation<T, Never>, @in T) -> () {
// %0 // user: %3
// %1 // user: %3
bb0(%0 : $UnsafeContinuation<T, Never>, %1 : $*T):
// function_ref UnsafeContinuation.resume<>(returning:)
%2 = function_ref @$sScc6resume9returningyxn_ts5NeverORs_rlF : $@convention(method) <τ_0_0, τ_0_1 where τ_0_1 == Never> (@in τ_0_0, UnsafeContinuation<τ_0_0, Never>) -> () // user: %3
%3 = apply %2<T, Never>(%1, %0) : $@convention(method) <τ_0_0, τ_0_1 where τ_0_1 == Never> (@in τ_0_0, UnsafeContinuation<τ_0_0, Never>) -> ()
%4 = tuple () // user: %5
return %4 : $() // id: %5
} // end sil function '$ss25_resumeUnsafeContinuationyySccyxs5NeverOG_xntlF'
// exit
// clang name: exit
sil [clang exit] @exit : $@convention(c) (Int32) -> Never
// @nonobjc MyClass.init()
sil shared [thunk] @$sSo7MyClassCABycfcTO : $@convention(method) (@owned MyClass) -> @owned MyClass {
// %0 "self" // users: %2, %1
bb0(%0 : $MyClass):
%1 = objc_method %0 : $MyClass, #MyClass.init!initializer.foreign : (MyClass.Type) -> () -> MyClass, $@convention(objc_method) (@owned MyClass) -> @owned MyClass // user: %2
%2 = apply %1(%0) : $@convention(objc_method) (@owned MyClass) -> @owned MyClass // user: %3
return %2 : $MyClass // id: %3
} // end sil function '$sSo7MyClassCABycfcTO'
// UnsafeContinuation.resume<>(returning:)
sil shared [available 12.0.0] @$sScc6resume9returningyxn_ts5NeverORs_rlF : $@convention(method) <T, E where E == Never> (@in T, UnsafeContinuation<T, Never>) -> () {
// %0 // user: %3
// %1 // user: %2
bb0(%0 : $*T, %1 : $UnsafeContinuation<T, Never>):
%2 = struct_extract %1 : $UnsafeContinuation<T, Never>, #UnsafeContinuation.context // user: %3
%3 = builtin "resumeNonThrowingContinuationReturning"<T>(%2 : $Builtin.RawUnsafeContinuation, %0 : $*T) : $()
%4 = tuple () // user: %5
return %4 : $() // id: %5
} // end sil function '$sScc6resume9returningyxn_ts5NeverORs_rlF'
// Mappings from '#fileID' to '#filePath':
// 'main/main.swift' => 'main.swift'
sil_stage raw
import Builtin
import Swift
import SwiftShims
@_hasStorage @_hasInitialValue @MainActor let myClass: MyClass { get }
// myClass
sil_global hidden [let] @$s4main7myClassSo02MyC0Cvp : $MyClass
// main
sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
// function_ref async_Main
%2 = function_ref @async_Main : $@convention(thin) @async () -> () // user: %8
%3 = integer_literal $Builtin.Int64, 2048 // user: %4
%4 = struct $Int (%3 : $Builtin.Int64) // user: %10
%5 = metatype $@thick ().Type // user: %6
%6 = init_existential_metatype %5 : $@thick ().Type, $@thick any Any.Type // user: %10
// function_ref thunk for @escaping @convention(thin) @async () -> ()
%7 = function_ref @$sIetH_yts5Error_pIegHrzo_TR : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) // user: %8
%8 = partial_apply [callee_guaranteed] %7(%2) : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) // user: %9
%9 = convert_function %8 : $@async @callee_guaranteed () -> (@out (), @error any Error) to $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()> // user: %10
%10 = builtin "createAsyncTask"<()>(%4 : $Int, %6 : $@thick any Any.Type, %9 : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer) // user: %11
(%11, %12) = destructure_tuple %10 : $(Builtin.NativeObject, Builtin.RawPointer) // user: %14
// function_ref swift_job_run
%13 = function_ref @swift_job_run : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> () // user: %19
%14 = builtin "convertTaskToJob"(%11 : $Builtin.NativeObject) : $Builtin.Job // user: %15
%15 = struct $UnownedJob (%14 : $Builtin.Job) // user: %19
// function_ref swift_task_getMainExecutor
%16 = function_ref @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor // user: %17
%17 = apply %16() : $@convention(thin) () -> Builtin.Executor // user: %18
%18 = struct $UnownedSerialExecutor (%17 : $Builtin.Executor) // user: %19
%19 = apply %13(%15, %18) : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
// function_ref swift_task_asyncMainDrainQueue
%20 = function_ref @swift_task_asyncMainDrainQueue : $@convention(thin) () -> Never // user: %21
%21 = apply %20() : $@convention(thin) () -> Never
unreachable // id: %22
} // end sil function 'main'
// async_Main
sil hidden [ossa] @async_Main : $@convention(thin) @async () -> () {
bb0:
// function_ref swift_task_getMainExecutor
%0 = function_ref @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor // user: %1
%1 = apply %0() : $@convention(thin) () -> Builtin.Executor // user: %2
%2 = enum $Optional<Builtin.Executor>, #Optional.some!enumelt, %1 : $Builtin.Executor // user: %24
alloc_global @$s4main7myClassSo02MyC0Cvp // id: %3
%4 = global_addr @$s4main7myClassSo02MyC0Cvp : $*MyClass // users: %10, %8
%5 = metatype $@thick MyClass.Type // user: %7
// function_ref MyClass.__allocating_init()
%6 = function_ref @$sSo7MyClassCABycfC : $@convention(method) (@thick MyClass.Type) -> @owned MyClass // user: %7
%7 = apply %6(%5) : $@convention(method) (@thick MyClass.Type) -> @owned MyClass // user: %8
store %7 to [init] %4 : $*MyClass // id: %8
%9 = alloc_stack $() // users: %26, %25, %12
%10 = load_borrow %4 : $*MyClass // users: %22, %20, %11
%11 = objc_method %10 : $MyClass, #MyClass.handleVoid!foreign : (MyClass) -> () async -> (), $@convention(objc_method) (Optional<@convention(block) () -> ()>, MyClass) -> () // user: %20
%12 = get_async_continuation_addr (), %9 : $*() // users: %23, %13
%13 = struct $UnsafeContinuation<(), Never> (%12 : $Builtin.RawUnsafeContinuation) // user: %16
%14 = alloc_stack $@block_storage UnsafeContinuation<(), Never> // users: %21, %18, %15
%15 = project_block_storage %14 : $*@block_storage UnsafeContinuation<(), Never> // user: %16
store %13 to [trivial] %15 : $*UnsafeContinuation<(), Never> // id: %16
// function_ref @objc completion handler block implementation for @escaping @callee_unowned @convention(block) () -> () with result type ()
%17 = function_ref @$sIeyB_ytTz_ : $@convention(c) (@inout_aliasable @block_storage UnsafeContinuation<(), Never>) -> () // user: %18
%18 = init_block_storage_header %14 : $*@block_storage UnsafeContinuation<(), Never>, invoke %17 : $@convention(c) (@inout_aliasable @block_storage UnsafeContinuation<(), Never>) -> (), type $@convention(block) () -> () // user: %19
%19 = enum $Optional<@convention(block) () -> ()>, #Optional.some!enumelt, %18 : $@convention(block) () -> () // user: %20
%20 = apply %11(%19, %10) : $@convention(objc_method) (Optional<@convention(block) () -> ()>, MyClass) -> ()
dealloc_stack %14 : $*@block_storage UnsafeContinuation<(), Never> // id: %21
end_borrow %10 : $MyClass // id: %22
await_async_continuation %12 : $Builtin.RawUnsafeContinuation, resume bb1 // id: %23
bb1: // Preds: bb0
hop_to_executor %2 : $Optional<Builtin.Executor> // id: %24
%25 = load [trivial] %9 : $*()
dealloc_stack %9 : $*() // id: %26
%27 = integer_literal $Builtin.Int32, 0 // user: %28
%28 = struct $Int32 (%27 : $Builtin.Int32) // user: %30
// function_ref exit
%29 = function_ref @exit : $@convention(c) (Int32) -> Never // user: %30
%30 = apply %29(%28) : $@convention(c) (Int32) -> Never
unreachable // id: %31
} // end sil function 'async_Main'
// thunk for @escaping @convention(thin) @async () -> ()
sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sIetH_yts5Error_pIegHrzo_TR : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) {
// %1 // user: %2
bb0(%0 : $*(), %1 : $@convention(thin) @async () -> ()):
%2 = apply %1() : $@convention(thin) @async () -> ()
%3 = tuple () // user: %4
return %3 : $() // id: %4
} // end sil function '$sIetH_yts5Error_pIegHrzo_TR'
// swift_job_run
sil [available 12.0.0] @swift_job_run : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
// swift_task_getMainExecutor
sil [available 12.0.0] @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor
// swift_task_asyncMainDrainQueue
sil [available 12.0.0] @swift_task_asyncMainDrainQueue : $@convention(thin) () -> Never
// MyClass.__allocating_init()
sil shared [serialized] [ossa] @$sSo7MyClassCABycfC : $@convention(method) (@thick MyClass.Type) -> @owned MyClass {
// %0 "$metatype" // user: %1
bb0(%0 : $@thick MyClass.Type):
%1 = thick_to_objc_metatype %0 : $@thick MyClass.Type to $@objc_metatype MyClass.Type // user: %2
%2 = alloc_ref_dynamic [objc] %1 : $@objc_metatype MyClass.Type, $MyClass // user: %4
// function_ref @nonobjc MyClass.init()
%3 = function_ref @$sSo7MyClassCABycfcTO : $@convention(method) (@owned MyClass) -> @owned MyClass // user: %4
%4 = apply %3(%2) : $@convention(method) (@owned MyClass) -> @owned MyClass // user: %5
return %4 : $MyClass // id: %5
} // end sil function '$sSo7MyClassCABycfC'
// @objc completion handler block implementation for @escaping @callee_unowned @convention(block) () -> () with result type ()
sil shared [transparent] [serialized] [thunk] [ossa] @$sIeyB_ytTz_ : $@convention(c) (@inout_aliasable @block_storage UnsafeContinuation<(), Never>) -> () {
// %0 // user: %1
bb0(%0 : $*@block_storage UnsafeContinuation<(), Never>):
%1 = project_block_storage %0 : $*@block_storage UnsafeContinuation<(), Never> // user: %2
%2 = load [trivial] %1 : $*UnsafeContinuation<(), Never> // user: %5
%3 = alloc_stack $() // users: %6, %5
// function_ref _resumeUnsafeContinuation<A>(_:_:)
%4 = function_ref @$ss25_resumeUnsafeContinuationyySccyxs5NeverOG_xntlF : $@convention(thin) <τ_0_0> (UnsafeContinuation<τ_0_0, Never>, @in τ_0_0) -> () // user: %5
%5 = apply %4<()>(%2, %3) : $@convention(thin) <τ_0_0> (UnsafeContinuation<τ_0_0, Never>, @in τ_0_0) -> ()
dealloc_stack %3 : $*() // id: %6
return undef : $() // id: %7
} // end sil function '$sIeyB_ytTz_'
// _resumeUnsafeContinuation<A>(_:_:)
sil hidden_external [serialized] [available 12.0.0] @$ss25_resumeUnsafeContinuationyySccyxs5NeverOG_xntlF : $@convention(thin) <τ_0_0> (UnsafeContinuation<τ_0_0, Never>, @in τ_0_0) -> ()
// exit
// clang name: exit
sil [serialized] [clang exit] @exit : $@convention(c) (Int32) -> Never
// @nonobjc MyClass.init()
sil shared [serialized] [thunk] [ossa] @$sSo7MyClassCABycfcTO : $@convention(method) (@owned MyClass) -> @owned MyClass {
// %0 "self" // users: %2, %1
bb0(%0 : @owned $MyClass):
%1 = objc_method %0 : $MyClass, #MyClass.init!initializer.foreign : (MyClass.Type) -> () -> MyClass, $@convention(objc_method) (@owned MyClass) -> @owned MyClass // user: %2
%2 = apply %1(%0) : $@convention(objc_method) (@owned MyClass) -> @owned MyClass // user: %3
return %2 : $MyClass // id: %3
} // end sil function '$sSo7MyClassCABycfcTO'
// Mappings from '#fileID' to '#filePath':
// 'main/main.swift' => 'main.swift'
ソース
```swift
extension MyClass {
func handleVoidManual() async {
await withUnsafeContinuation { continuation in
self.handleVoid {
continuation.resume(returning: ())
}
}
}
}
let myClass = MyClass()
await myClass.handleVoidManual()
SIL
sil_stage canonical
import Builtin
import Swift
import SwiftShims
import Foundation
extension MyClass {
func handleVoidManual() async
}
@_hasStorage @_hasInitialValue @MainActor let myClass: MyClass { get }
// myClass
sil_global hidden [let] @$s4main7myClassSo02MyC0Cvp : $MyClass
// main
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
// function_ref async_Main
%2 = function_ref @async_Main : $@convention(thin) @async () -> () // user: %8
%3 = integer_literal $Builtin.Int64, 2048 // user: %4
%4 = struct $Int (%3 : $Builtin.Int64) // user: %10
%5 = metatype $@thick ().Type // user: %6
%6 = init_existential_metatype %5 : $@thick ().Type, $@thick any Any.Type // user: %10
// function_ref thunk for @escaping @convention(thin) @async () -> ()
%7 = function_ref @$sIetH_yts5Error_pIegHrzo_TR : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) // user: %8
%8 = partial_apply [callee_guaranteed] %7(%2) : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) // user: %9
%9 = convert_function %8 : $@async @callee_guaranteed () -> (@out (), @error any Error) to $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()> // user: %10
%10 = builtin "createAsyncTask"<()>(%4 : $Int, %6 : $@thick any Any.Type, %9 : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer) // user: %11
%11 = tuple_extract %10 : $(Builtin.NativeObject, Builtin.RawPointer), 0 // user: %13
// function_ref swift_job_run
%12 = function_ref @swift_job_run : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> () // user: %18
%13 = builtin "convertTaskToJob"(%11 : $Builtin.NativeObject) : $Builtin.Job // user: %14
%14 = struct $UnownedJob (%13 : $Builtin.Job) // user: %18
// function_ref swift_task_getMainExecutor
%15 = function_ref @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor // user: %16
%16 = apply %15() : $@convention(thin) () -> Builtin.Executor // user: %17
%17 = struct $UnownedSerialExecutor (%16 : $Builtin.Executor) // user: %18
%18 = apply %12(%14, %17) : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
// function_ref swift_task_asyncMainDrainQueue
%19 = function_ref @swift_task_asyncMainDrainQueue : $@convention(thin) () -> Never // user: %20
%20 = apply %19() : $@convention(thin) () -> Never
unreachable // id: %21
} // end sil function 'main'
// async_Main
sil hidden @async_Main : $@convention(thin) @async () -> () {
bb0:
// function_ref swift_task_getMainExecutor
%0 = function_ref @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor // user: %1
%1 = apply %0() : $@convention(thin) () -> Builtin.Executor // user: %2
%2 = enum $Optional<Builtin.Executor>, #Optional.some!enumelt, %1 : $Builtin.Executor // user: %12
alloc_global @$s4main7myClassSo02MyC0Cvp // id: %3
%4 = global_addr @$s4main7myClassSo02MyC0Cvp : $*MyClass // users: %9, %8
%5 = metatype $@thick MyClass.Type // user: %7
// function_ref MyClass.__allocating_init()
%6 = function_ref @$sSo7MyClassCABycfC : $@convention(method) (@thick MyClass.Type) -> @owned MyClass // user: %7
%7 = apply %6(%5) : $@convention(method) (@thick MyClass.Type) -> @owned MyClass // user: %8
store %7 to %4 : $*MyClass // id: %8
%9 = load %4 : $*MyClass // user: %11
// function_ref MyClass.handleVoidManual()
%10 = function_ref @$sSo7MyClassC4mainE16handleVoidManualyyYaF : $@convention(method) @async (@guaranteed MyClass) -> () // user: %11
%11 = apply %10(%9) : $@convention(method) @async (@guaranteed MyClass) -> ()
hop_to_executor %2 : $Optional<Builtin.Executor> // id: %12
%13 = integer_literal $Builtin.Int32, 0 // user: %14
%14 = struct $Int32 (%13 : $Builtin.Int32) // user: %16
// function_ref exit
%15 = function_ref @exit : $@convention(c) (Int32) -> Never // user: %16
%16 = apply %15(%14) : $@convention(c) (Int32) -> Never
unreachable // id: %17
} // end sil function 'async_Main'
// thunk for @escaping @convention(thin) @async () -> ()
sil shared [transparent] [reabstraction_thunk] @$sIetH_yts5Error_pIegHrzo_TR : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error) {
// %1 // user: %2
bb0(%0 : $*(), %1 : $@convention(thin) @async () -> ()):
%2 = apply %1() : $@convention(thin) @async () -> ()
%3 = tuple () // user: %4
return %3 : $() // id: %4
} // end sil function '$sIetH_yts5Error_pIegHrzo_TR'
// swift_job_run
sil [available 12.0.0] @swift_job_run : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
// swift_task_getMainExecutor
sil [available 12.0.0] @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor
// swift_task_asyncMainDrainQueue
sil [available 12.0.0] @swift_task_asyncMainDrainQueue : $@convention(thin) () -> Never
// MyClass.handleVoidManual()
sil hidden @$sSo7MyClassC4mainE16handleVoidManualyyYaF : $@convention(method) @async (@guaranteed MyClass) -> () {
// %0 "self" // users: %13, %8, %7, %6, %1
bb0(%0 : $MyClass):
debug_value %0 : $MyClass, let, name "self", argno 1, implicit // id: %1
%2 = enum $Optional<Builtin.Executor>, #Optional.none!enumelt // users: %11, %3
hop_to_executor %2 : $Optional<Builtin.Executor> // id: %3
%4 = alloc_stack $() // users: %14, %10
// function_ref closure #1 in MyClass.handleVoidManual()
%5 = function_ref @$sSo7MyClassC4mainE16handleVoidManualyyYaFySccyyts5NeverOGXEfU_ : $@convention(thin) @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>, @guaranteed MyClass) -> () for <()> // user: %7
strong_retain %0 : $MyClass // id: %6
%7 = partial_apply [callee_guaranteed] [on_stack] %5(%0) : $@convention(thin) @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>, @guaranteed MyClass) -> () for <()> // users: %8, %12
%8 = mark_dependence %7 : $@noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <()> on %0 : $MyClass // user: %10
// function_ref withUnsafeContinuation<A>(_:)
%9 = function_ref @$ss22withUnsafeContinuationyxySccyxs5NeverOGXEYalF : $@convention(thin) @async <τ_0_0> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <τ_0_0>) -> @out τ_0_0 // user: %10
%10 = apply %9<()>(%4, %8) : $@convention(thin) @async <τ_0_0> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <τ_0_0>) -> @out τ_0_0
hop_to_executor %2 : $Optional<Builtin.Executor> // id: %11
dealloc_stack %7 : $@noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <()> // id: %12
strong_release %0 : $MyClass // id: %13
dealloc_stack %4 : $*() // id: %14
%15 = tuple () // user: %16
return %15 : $() // id: %16
} // end sil function '$sSo7MyClassC4mainE16handleVoidManualyyYaF'
// closure #1 in MyClass.handleVoidManual()
sil private @$sSo7MyClassC4mainE16handleVoidManualyyYaFySccyyts5NeverOGXEfU_ : $@convention(thin) @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>, @guaranteed MyClass) -> () for <()> {
// %0 "continuation" // users: %5, %2
// %1 "self" // users: %16, %15, %3
bb0(%0 : $UnsafeContinuation<(), Never>, %1 : @closureCapture $MyClass):
debug_value %0 : $UnsafeContinuation<(), Never>, let, name "continuation", argno 1 // id: %2
debug_value %1 : $MyClass, let, name "self", argno 2, implicit // id: %3
// function_ref closure #1 in closure #1 in MyClass.handleVoidManual()
%4 = function_ref @$sSo7MyClassC4mainE16handleVoidManualyyYaFySccyyts5NeverOGXEfU_yycfU_ : $@convention(thin) (UnsafeContinuation<(), Never>) -> () // user: %5
%5 = partial_apply [callee_guaranteed] %4(%0) : $@convention(thin) (UnsafeContinuation<(), Never>) -> () // user: %8
%6 = alloc_stack $@block_storage @callee_guaranteed () -> () // users: %14, %10, %7
%7 = project_block_storage %6 : $*@block_storage @callee_guaranteed () -> () // users: %8, %13
store %5 to %7 : $*@callee_guaranteed () -> () // id: %8
// function_ref thunk for @escaping @callee_guaranteed () -> ()
%9 = function_ref @$sIeg_IeyB_TR : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed () -> ()) -> () // user: %10
%10 = init_block_storage_header %6 : $*@block_storage @callee_guaranteed () -> (), invoke %9 : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed () -> ()) -> (), type $@convention(block) () -> () // user: %11
%11 = copy_block %10 : $@convention(block) () -> () // user: %12
%12 = enum $Optional<@convention(block) () -> ()>, #Optional.some!enumelt, %11 : $@convention(block) () -> () // users: %17, %16
destroy_addr %7 : $*@callee_guaranteed () -> () // id: %13
dealloc_stack %6 : $*@block_storage @callee_guaranteed () -> () // id: %14
%15 = objc_method %1 : $MyClass, #MyClass.handleVoid!foreign : (MyClass) -> ((() -> ())?) -> (), $@convention(objc_method) (Optional<@convention(block) () -> ()>, MyClass) -> () // user: %16
%16 = apply %15(%12, %1) : $@convention(objc_method) (Optional<@convention(block) () -> ()>, MyClass) -> ()
release_value %12 : $Optional<@convention(block) () -> ()> // id: %17
%18 = tuple () // user: %19
return %18 : $() // id: %19
} // end sil function '$sSo7MyClassC4mainE16handleVoidManualyyYaFySccyyts5NeverOGXEfU_'
// closure #1 in closure #1 in MyClass.handleVoidManual()
sil private @$sSo7MyClassC4mainE16handleVoidManualyyYaFySccyyts5NeverOGXEfU_yycfU_ : $@convention(thin) (UnsafeContinuation<(), Never>) -> () {
// %0 "continuation" // users: %6, %1
bb0(%0 : @closureCapture $UnsafeContinuation<(), Never>):
debug_value %0 : $UnsafeContinuation<(), Never>, let, name "continuation", argno 1 // id: %1
%2 = tuple () // user: %4
%3 = alloc_stack $() // users: %4, %7, %6
store %2 to %3 : $*() // id: %4
// function_ref UnsafeContinuation.resume<>(returning:)
%5 = function_ref @$sScc6resume9returningyxn_ts5NeverORs_rlF : $@convention(method) <τ_0_0, τ_0_1 where τ_0_1 == Never> (@in τ_0_0, UnsafeContinuation<τ_0_0, Never>) -> () // user: %6
%6 = apply %5<(), Never>(%3, %0) : $@convention(method) <τ_0_0, τ_0_1 where τ_0_1 == Never> (@in τ_0_0, UnsafeContinuation<τ_0_0, Never>) -> ()
dealloc_stack %3 : $*() // id: %7
%8 = tuple () // user: %9
return %8 : $() // id: %9
} // end sil function '$sSo7MyClassC4mainE16handleVoidManualyyYaFySccyyts5NeverOGXEfU_yycfU_'
// UnsafeContinuation.resume<>(returning:)
sil shared [available 12.0.0] @$sScc6resume9returningyxn_ts5NeverORs_rlF : $@convention(method) <T, E where E == Never> (@in T, UnsafeContinuation<T, Never>) -> () {
// %0 // user: %3
// %1 // user: %2
bb0(%0 : $*T, %1 : $UnsafeContinuation<T, Never>):
%2 = struct_extract %1 : $UnsafeContinuation<T, Never>, #UnsafeContinuation.context // user: %3
%3 = builtin "resumeNonThrowingContinuationReturning"<T>(%2 : $Builtin.RawUnsafeContinuation, %0 : $*T) : $()
%4 = tuple () // user: %5
return %4 : $() // id: %5
} // end sil function '$sScc6resume9returningyxn_ts5NeverORs_rlF'
// thunk for @escaping @callee_guaranteed () -> ()
sil shared [transparent] [reabstraction_thunk] @$sIeg_IeyB_TR : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed () -> ()) -> () {
// %0 // user: %1
bb0(%0 : $*@block_storage @callee_guaranteed () -> ()):
%1 = project_block_storage %0 : $*@block_storage @callee_guaranteed () -> () // user: %2
%2 = load %1 : $*@callee_guaranteed () -> () // users: %6, %4, %3
strong_retain %2 : $@callee_guaranteed () -> () // id: %3
%4 = apply %2() : $@callee_guaranteed () -> ()
%5 = tuple () // user: %7
strong_release %2 : $@callee_guaranteed () -> () // id: %6
return %5 : $() // id: %7
} // end sil function '$sIeg_IeyB_TR'
// withUnsafeContinuation<A>(_:)
sil shared [available 12.0.0] @$ss22withUnsafeContinuationyxySccyxs5NeverOGXEYalF : $@convention(thin) @async <T> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <T>) -> @out T {
// %0 // user: %3
// %1 // user: %4
bb0(%0 : $*T, %1 : $@noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <T>):
// function_ref closure #1 in withUnsafeContinuation<A>(_:)
%2 = function_ref @$ss22withUnsafeContinuationyxySccyxs5NeverOGXEYalFyBcXEfU_ : $@convention(thin) <τ_0_0> (Builtin.RawUnsafeContinuation, @guaranteed @noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <τ_0_0>) -> () // user: %4
%3 = get_async_continuation_addr T, %0 : $*T // users: %5, %4
%4 = apply %2<T>(%3, %1) : $@convention(thin) <τ_0_0> (Builtin.RawUnsafeContinuation, @guaranteed @noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <τ_0_0>) -> ()
await_async_continuation %3 : $Builtin.RawUnsafeContinuation, resume bb1 // id: %5
bb1: // Preds: bb0
%6 = tuple () // user: %7
return %6 : $() // id: %7
} // end sil function '$ss22withUnsafeContinuationyxySccyxs5NeverOGXEYalF'
// MyClass.__allocating_init()
sil shared @$sSo7MyClassCABycfC : $@convention(method) (@thick MyClass.Type) -> @owned MyClass {
// %0 "$metatype" // user: %1
bb0(%0 : $@thick MyClass.Type):
%1 = thick_to_objc_metatype %0 : $@thick MyClass.Type to $@objc_metatype MyClass.Type // user: %2
%2 = alloc_ref_dynamic [objc] %1 : $@objc_metatype MyClass.Type, $MyClass // user: %4
// function_ref @nonobjc MyClass.init()
%3 = function_ref @$sSo7MyClassCABycfcTO : $@convention(method) (@owned MyClass) -> @owned MyClass // user: %4
%4 = apply %3(%2) : $@convention(method) (@owned MyClass) -> @owned MyClass // user: %5
return %4 : $MyClass // id: %5
} // end sil function '$sSo7MyClassCABycfC'
// exit
// clang name: exit
sil [clang exit] @exit : $@convention(c) (Int32) -> Never
// @nonobjc MyClass.init()
sil shared [thunk] @$sSo7MyClassCABycfcTO : $@convention(method) (@owned MyClass) -> @owned MyClass {
// %0 "self" // users: %2, %1
bb0(%0 : $MyClass):
%1 = objc_method %0 : $MyClass, #MyClass.init!initializer.foreign : (MyClass.Type) -> () -> MyClass, $@convention(objc_method) (@owned MyClass) -> @owned MyClass // user: %2
%2 = apply %1(%0) : $@convention(objc_method) (@owned MyClass) -> @owned MyClass // user: %3
return %2 : $MyClass // id: %3
} // end sil function '$sSo7MyClassCABycfcTO'
// closure #1 in withUnsafeContinuation<A>(_:)
sil shared @$ss22withUnsafeContinuationyxySccyxs5NeverOGXEYalFyBcXEfU_ : $@convention(thin) <T> (Builtin.RawUnsafeContinuation, @guaranteed @noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <T>) -> () {
// %0 // user: %4
// %1 // user: %5
bb0(%0 : $Builtin.RawUnsafeContinuation, %1 : @closureCapture $@noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <T>):
%2 = metatype $@thin UnsafeContinuation<T, Never>.Type // user: %4
// function_ref UnsafeContinuation.init(_:)
%3 = function_ref @$sSccySccyxq_GBccfC : $@convention(method) <τ_0_0, τ_0_1 where τ_0_1 : Error> (Builtin.RawUnsafeContinuation, @thin UnsafeContinuation<τ_0_0, τ_0_1>.Type) -> UnsafeContinuation<τ_0_0, τ_0_1> // user: %4
%4 = apply %3<T, Never>(%0, %2) : $@convention(method) <τ_0_0, τ_0_1 where τ_0_1 : Error> (Builtin.RawUnsafeContinuation, @thin UnsafeContinuation<τ_0_0, τ_0_1>.Type) -> UnsafeContinuation<τ_0_0, τ_0_1> // user: %5
%5 = apply %1(%4) : $@noescape @callee_guaranteed @substituted <τ_0_0> (UnsafeContinuation<τ_0_0, Never>) -> () for <T>
%6 = tuple () // user: %7
return %6 : $() // id: %7
} // end sil function '$ss22withUnsafeContinuationyxySccyxs5NeverOGXEYalFyBcXEfU_'
// UnsafeContinuation.init(_:)
sil shared [available 12.0.0] @$sSccySccyxq_GBccfC : $@convention(method) <T, E where E : Error> (Builtin.RawUnsafeContinuation, @thin UnsafeContinuation<T, E>.Type) -> UnsafeContinuation<T, E> {
// %0 // user: %2
bb0(%0 : $Builtin.RawUnsafeContinuation, %1 : $@thin UnsafeContinuation<T, E>.Type):
%2 = struct $UnsafeContinuation<T, E> (%0 : $Builtin.RawUnsafeContinuation) // user: %3
return %2 : $UnsafeContinuation<T, E> // id: %3
} // end sil function '$sSccySccyxq_GBccfC'
// Mappings from '#fileID' to '#filePath':
// 'main/main.swift' => 'main.swift'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment