Skip to content

Instantly share code, notes, and snippets.

@ezura
Created November 16, 2019 06:46
Show Gist options
  • Save ezura/f967209a5f7cb80290f17bbfa6f24bfe to your computer and use it in GitHub Desktop.
Save ezura/f967209a5f7cb80290f17bbfa6f24bfe to your computer and use it in GitHub Desktop.
import Foundation
func f() {
unowned var unownedValue: NSDate?
unownedValue = NSDate()
}
sil_stage canonical
import Builtin
import Swift
import SwiftShims
import Foundation
func f()
// main
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
%2 = integer_literal $Builtin.Int32, 0 // user: %3
%3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4
return %3 : $Int32 // id: %4
} // end sil function 'main'
// f()
sil hidden @$s5test11fyyF : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $@sil_unowned Optional<NSDate>, var, name "unownedValue" // users: %13, %12, %3, %8
%1 = metatype $@thin Optional<NSDate>.Type
%2 = enum $Optional<NSDate>, #Optional.none!enumelt // user: %3
store_unowned %2 to [initialization] %0 : $*@sil_unowned Optional<NSDate> // id: %3
%4 = metatype $@thick NSDate.Type // user: %6
// function_ref NSDate.__allocating_init()
%5 = function_ref @$sSo6NSDateCABycfC : $@convention(method) (@thick NSDate.Type) -> @owned NSDate // user: %6
%6 = apply %5(%4) : $@convention(method) (@thick NSDate.Type) -> @owned NSDate // user: %7
%7 = unchecked_ref_cast %6 : $NSDate to $Optional<NSDate> // users: %10, %9
%8 = begin_access [modify] [static] %0 : $*@sil_unowned Optional<NSDate> // users: %11, %9
store_unowned %7 to %8 : $*@sil_unowned Optional<NSDate> // id: %9
release_value %7 : $Optional<NSDate> // id: %10
end_access %8 : $*@sil_unowned Optional<NSDate> // id: %11
destroy_addr %0 : $*@sil_unowned Optional<NSDate> // id: %12
dealloc_stack %0 : $*@sil_unowned Optional<NSDate> // id: %13
%14 = tuple () // user: %15
return %14 : $() // id: %15
} // end sil function '$s5test11fyyF'
// NSDate.__allocating_init()
sil shared [serializable] @$sSo6NSDateCABycfC : $@convention(method) (@thick NSDate.Type) -> @owned NSDate {
// %0 // user: %1
bb0(%0 : $@thick NSDate.Type):
%1 = thick_to_objc_metatype %0 : $@thick NSDate.Type to $@objc_metatype NSDate.Type // user: %2
%2 = alloc_ref_dynamic [objc] %1 : $@objc_metatype NSDate.Type, $NSDate // user: %4
// function_ref @nonobjc NSDate.init()
%3 = function_ref @$sSo6NSDateCABycfcTO : $@convention(method) (@owned NSDate) -> @owned NSDate // user: %4
%4 = apply %3(%2) : $@convention(method) (@owned NSDate) -> @owned NSDate // user: %5
return %4 : $NSDate // id: %5
} // end sil function '$sSo6NSDateCABycfC'
// @nonobjc NSDate.init()
sil shared [serializable] [thunk] @$sSo6NSDateCABycfcTO : $@convention(method) (@owned NSDate) -> @owned NSDate {
// %0 // users: %2, %1
bb0(%0 : $NSDate):
%1 = objc_method %0 : $NSDate, #NSDate.init!initializer.1.foreign : (NSDate.Type) -> () -> NSDate, $@convention(objc_method) (@owned NSDate) -> @owned NSDate // user: %2
%2 = apply %1(%0) : $@convention(objc_method) (@owned NSDate) -> @owned NSDate // user: %3
return %2 : $NSDate // id: %3
} // end sil function '$sSo6NSDateCABycfcTO'
import Foundation
func f() {
weak var weakValue: NSDate?
weakValue = NSDate()
}
sil_stage canonical
import Builtin
import Swift
import SwiftShims
import Foundation
func f() -> NSDate
// main
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
%2 = integer_literal $Builtin.Int32, 0 // user: %3
%3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4
return %3 : $Int32 // id: %4
} // end sil function 'main'
// f()
sil hidden @$s5test21fSo6NSDateCyF : $@convention(thin) () -> @owned NSDate {
bb0:
%0 = alloc_stack $@sil_unowned Optional<NSDate>, var, name "unownedValue" // users: %27, %26, %3
%1 = metatype $@thin Optional<NSDate>.Type
%2 = enum $Optional<NSDate>, #Optional.none!enumelt // user: %3
store_unowned %2 to [initialization] %0 : $*@sil_unowned Optional<NSDate> // id: %3
%4 = alloc_stack $@sil_weak Optional<NSDate>, var, name "weakValue" // users: %25, %24, %7, %18
%5 = metatype $@thin Optional<NSDate>.Type
%6 = enum $Optional<NSDate>, #Optional.none!enumelt // user: %7
store_weak %6 to [initialization] %4 : $*@sil_weak Optional<NSDate> // id: %7
%8 = alloc_stack $Optional<NSDate>, var, name "strongValue" // users: %11, %23, %22
%9 = metatype $@thin Optional<NSDate>.Type
%10 = enum $Optional<NSDate>, #Optional.none!enumelt // user: %11
store %10 to %8 : $*Optional<NSDate> // id: %11
%12 = metatype $@thick NSDate.Type // user: %14
// function_ref NSDate.__allocating_init()
%13 = function_ref @$sSo6NSDateCABycfC : $@convention(method) (@thick NSDate.Type) -> @owned NSDate // user: %14
%14 = apply %13(%12) : $@convention(method) (@thick NSDate.Type) -> @owned NSDate // users: %28, %17, %16, %15
debug_value %14 : $NSDate, let, name "nsDate" // id: %15
strong_retain %14 : $NSDate // id: %16
%17 = enum $Optional<NSDate>, #Optional.some!enumelt.1, %14 : $NSDate // users: %20, %19
%18 = begin_access [modify] [static] %4 : $*@sil_weak Optional<NSDate> // users: %21, %19
store_weak %17 to %18 : $*@sil_weak Optional<NSDate> // id: %19
release_value %17 : $Optional<NSDate> // id: %20
end_access %18 : $*@sil_weak Optional<NSDate> // id: %21
destroy_addr %8 : $*Optional<NSDate> // id: %22
dealloc_stack %8 : $*Optional<NSDate> // id: %23
destroy_addr %4 : $*@sil_weak Optional<NSDate> // id: %24
dealloc_stack %4 : $*@sil_weak Optional<NSDate> // id: %25
destroy_addr %0 : $*@sil_unowned Optional<NSDate> // id: %26
dealloc_stack %0 : $*@sil_unowned Optional<NSDate> // id: %27
return %14 : $NSDate // id: %28
} // end sil function '$s5test21fSo6NSDateCyF'
// NSDate.__allocating_init()
sil shared [serializable] @$sSo6NSDateCABycfC : $@convention(method) (@thick NSDate.Type) -> @owned NSDate {
// %0 // user: %1
bb0(%0 : $@thick NSDate.Type):
%1 = thick_to_objc_metatype %0 : $@thick NSDate.Type to $@objc_metatype NSDate.Type // user: %2
%2 = alloc_ref_dynamic [objc] %1 : $@objc_metatype NSDate.Type, $NSDate // user: %4
// function_ref @nonobjc NSDate.init()
%3 = function_ref @$sSo6NSDateCABycfcTO : $@convention(method) (@owned NSDate) -> @owned NSDate // user: %4
%4 = apply %3(%2) : $@convention(method) (@owned NSDate) -> @owned NSDate // user: %5
return %4 : $NSDate // id: %5
} // end sil function '$sSo6NSDateCABycfC'
// @nonobjc NSDate.init()
sil shared [serializable] [thunk] @$sSo6NSDateCABycfcTO : $@convention(method) (@owned NSDate) -> @owned NSDate {
// %0 // users: %2, %1
bb0(%0 : $NSDate):
%1 = objc_method %0 : $NSDate, #NSDate.init!initializer.1.foreign : (NSDate.Type) -> () -> NSDate, $@convention(objc_method) (@owned NSDate) -> @owned NSDate // user: %2
%2 = apply %1(%0) : $@convention(objc_method) (@owned NSDate) -> @owned NSDate // user: %3
return %2 : $NSDate // id: %3
} // end sil function '$sSo6NSDateCABycfcTO'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment