Skip to content

Instantly share code, notes, and snippets.

@freddi-kit
Last active March 24, 2020 04:41
Show Gist options
  • Save freddi-kit/741719f49f29ca81e817bfa0c509e02c to your computer and use it in GitHub Desktop.
Save freddi-kit/741719f49f29ca81e817bfa0c509e02c to your computer and use it in GitHub Desktop.
import Foundation
class SomeCallable {
var completion: () -> Void = { }
func call(completion: @escaping () -> Void) {
// Do something
self.completion = completion
}
}
class SomeClass {
var value: Int = 1
}
class SomeVCMock {
let callable = SomeCallable()
func viewDidLoad() {
let some = SomeClass()
callable.call { [some] in
some.value = 0
}
}
}
%2 = metatype $@thick SomeClass.Type // user: %4
// function_ref SomeClass.__allocating_init()
%3 = function_ref @$s12swiftCapture9SomeClassCACycfC : $@convention(method) (@thick SomeClass.Type) -> @owned SomeClass // user: %4
- %4 = apply %3(%2) : $@convention(method) (@thick SomeClass.Type) -> @owned SomeClass // users: %17, %16, %12, %11, %9, %8, %5
+ %4 = apply %3(%2) : $@convention(method) (@thick SomeClass.Type) -> @owned SomeClass // users: %14, %10, %9, %5
debug_value %4 : $SomeClass, let, name "some" // id: %5
%6 = ref_element_addr %0 : $SomeVCMock, #SomeVCMock.callable // user: %7
- %7 = load %6 : $*SomeCallable // users: %13, %14
- strong_retain %4 : $SomeClass // id: %8
- debug_value %4 : $SomeClass, let, name "some" // id: %9
+ %7 = load %6 : $*SomeCallable // users: %11, %12
// function_ref closure #1 in SomeVCMock.viewDidLoad()
- %10 = function_ref @$s12swiftCapture10SomeVCMockC11viewDidLoadyyFyycfU_ : $@convention(thin) (@guaranteed SomeClass) -> () // user: %12
- strong_retain %4 : $SomeClass // id: %11
- %12 = partial_apply [callee_guaranteed] %10(%4) : $@convention(thin) (@guaranteed SomeClass) -> () // users: %15, %14
- %13 = class_method %7 : $SomeCallable, #SomeCallable.call!1 : (SomeCallable) -> (@escaping () -> ()) -> (), $@convention(method) (@guaranteed @callee_guaranteed () -> (), @guaranteed SomeCallable) -> () // user: %14
- %14 = apply %13(%12, %7) : $@convention(method) (@guaranteed @callee_guaranteed () -> (), @guaranteed SomeCallable) -> ()
- strong_release %12 : $@callee_guaranteed () -> () // id: %15
- strong_release %4 : $SomeClass // id: %16
- strong_release %4 : $SomeClass // id: %17
- %18 = tuple () // user: %19
- return %18 : $() // id: %19
+ %8 = function_ref @$s12swiftCapture10SomeVCMockC11viewDidLoadyyFyycfU_ : $@convention(thin) (@guaranteed SomeClass) -> () // user: %10
+ strong_retain %4 : $SomeClass // id: %9
+ %10 = partial_apply [callee_guaranteed] %8(%4) : $@convention(thin) (@guaranteed SomeClass) -> () // users: %13, %12
+ %11 = class_method %7 : $SomeCallable, #SomeCallable.call!1 : (SomeCallable) -> (@escaping () -> ()) -> (), $@convention(method) (@guaranteed @callee_guaranteed () -> (), @guaranteed SomeCallable) -> () // user: %12
+ %12 = apply %11(%10, %7) : $@convention(method) (@guaranteed @callee_guaranteed () -> (), @guaranteed SomeCallable) -> ()
+ strong_release %10 : $@callee_guaranteed () -> () // id: %13
+ strong_release %4 : $SomeClass // id: %14
+ %15 = tuple () // user: %16
+ return %15 : $() // id: %16
} // end sil function '$s12swiftCapture10SomeVCMockC11viewDidLoadyyF'
import Foundation
class SomeCallable {
var completion: () -> Void = { }
func call(completion: @escaping () -> Void) {
// Do something
self.completion = completion
}
}
class SomeClass {
var value: Int = 1
}
class SomeVCMock {
let callable = SomeCallable()
func viewDidLoad() {
let some = SomeClass()
callable.call {
some.value = 0
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment