Created
February 12, 2016 05:48
-
-
Save ukitaka/f8514677f33ff125b567 to your computer and use it in GitHub Desktop.
NSDate(timeIntervalSince1970: 0) == 0 がコンパイルエラーにならない件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ swiftc -emit-silgen -sdk $(xcrun --show-sdk-path --sdk macosx) date.swift > date.sil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sil_stage raw | |
import Builtin | |
import Swift | |
import SwiftShims | |
// date.b : Swift.Bool | |
sil_global [let] @_Tv4date1bSb : $Bool | |
// main | |
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> Int32 { | |
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<UnsafeMutablePointer<Int8>>): | |
// function_ref Swift._didEnterMain (Swift.Int32, argv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>) -> () | |
%2 = function_ref @_TFSs13_didEnterMainFTVSs5Int324argvGVSs20UnsafeMutablePointerGS0_VSs4Int8___T_ : $@convention(thin) (Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> () // user: %3 | |
%3 = apply %2(%0, %1) : $@convention(thin) (Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> () | |
%4 = global_addr @_Tv4date1bSb : $*Bool // user: %22 | |
// function_ref static ObjectiveC.== infix (__ObjC.NSObject, __ObjC.NSObject) -> Swift.Bool | |
%5 = function_ref @_TZF10ObjectiveCoi2eeFTCSo8NSObjectS0__Sb : $@convention(thin) (@owned NSObject, @owned NSObject) -> Bool // user: %21 | |
// function_ref __ObjC.NSDate.__allocating_init (__ObjC.NSDate.Type)(timeIntervalSince1970 : Swift.Double) -> __ObjC.NSDate | |
%6 = function_ref @_TFCSo6NSDateCfMS_FT21timeIntervalSince1970Sd_S_ : $@convention(thin) (Double, @thick NSDate.Type) -> @owned NSDate // user: %12 | |
%7 = metatype $@thick NSDate.Type // user: %12 | |
// function_ref Swift.Double.init (Swift.Double.Type)(_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Double | |
%8 = function_ref @_TFSdCfMSdFT22_builtinIntegerLiteralBi2048__Sd : $@convention(thin) (Builtin.Int2048, @thin Double.Type) -> Double // user: %11 | |
%9 = metatype $@thin Double.Type // user: %11 | |
%10 = integer_literal $Builtin.Int2048, 0 // user: %11 | |
%11 = apply %8(%10, %9) : $@convention(thin) (Builtin.Int2048, @thin Double.Type) -> Double // user: %12 | |
%12 = apply %6(%11, %7) : $@convention(thin) (Double, @thick NSDate.Type) -> @owned NSDate // user: %13 | |
%13 = upcast %12 : $NSDate to $NSObject // user: %21 | |
// function_ref ext.Foundation.Swift.Int._bridgeToObjectiveC (Swift.Int)() -> __ObjC.NSNumber | |
%14 = function_ref @_TFE10FoundationSi19_bridgeToObjectiveCfSiFT_CSo8NSNumber : $@convention(method) (Int) -> @owned NSNumber // user: %19 | |
// function_ref Swift.Int.init (Swift.Int.Type)(_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Int | |
%15 = function_ref @_TFSiCfMSiFT22_builtinIntegerLiteralBi2048__Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %18 | |
%16 = metatype $@thin Int.Type // user: %18 | |
%17 = integer_literal $Builtin.Int2048, 0 // user: %18 | |
%18 = apply %15(%17, %16) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %19 | |
%19 = apply %14(%18) : $@convention(method) (Int) -> @owned NSNumber // user: %20 | |
%20 = upcast %19 : $NSNumber to $NSObject // user: %21 | |
%21 = apply %5(%13, %20) : $@convention(thin) (@owned NSObject, @owned NSObject) -> Bool // user: %22 | |
store %21 to %4 : $*Bool // id: %22 | |
%23 = integer_literal $Builtin.Int32, 0 // user: %24 | |
%24 = struct $Int32 (%23 : $Builtin.Int32) // user: %25 | |
return %24 : $Int32 // id: %25 | |
} | |
// Swift._didEnterMain (Swift.Int32, argv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>) -> () | |
sil [transparent] [fragile] @_TFSs13_didEnterMainFTVSs5Int324argvGVSs20UnsafeMutablePointerGS0_VSs4Int8___T_ : $@convention(thin) (Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> () | |
// static ObjectiveC.== infix (__ObjC.NSObject, __ObjC.NSObject) -> Swift.Bool | |
sil @_TZF10ObjectiveCoi2eeFTCSo8NSObjectS0__Sb : $@convention(thin) (@owned NSObject, @owned NSObject) -> Bool | |
// __ObjC.NSDate.__allocating_init (__ObjC.NSDate.Type)(timeIntervalSince1970 : Swift.Double) -> __ObjC.NSDate | |
sil shared @_TFCSo6NSDateCfMS_FT21timeIntervalSince1970Sd_S_ : $@convention(thin) (Double, @thick NSDate.Type) -> @owned NSDate { | |
bb0(%0 : $Double, %1 : $@thick NSDate.Type): | |
%2 = thick_to_objc_metatype %1 : $@thick NSDate.Type to $@objc_metatype NSDate.Type // user: %3 | |
%3 = alloc_ref_dynamic [objc] %2 : $@objc_metatype NSDate.Type, $NSDate // user: %5 | |
// function_ref @nonobjc __ObjC.NSDate.init (__ObjC.NSDate.Type)(timeIntervalSince1970 : Swift.Double) -> __ObjC.NSDate | |
%4 = function_ref @_TTOFCSo6NSDatecfMS_FT21timeIntervalSince1970Sd_S_ : $@convention(method) (Double, @owned NSDate) -> @owned NSDate // user: %5 | |
%5 = apply %4(%0, %3) : $@convention(method) (Double, @owned NSDate) -> @owned NSDate // user: %6 | |
return %5 : $NSDate // id: %6 | |
} | |
// Swift.Double.init (Swift.Double.Type)(_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Double | |
sil [transparent] [fragile] @_TFSdCfMSdFT22_builtinIntegerLiteralBi2048__Sd : $@convention(thin) (Builtin.Int2048, @thin Double.Type) -> Double | |
// ext.Foundation.Swift.Int._bridgeToObjectiveC (Swift.Int)() -> __ObjC.NSNumber | |
sil [_semantics "convertToObjectiveC"] @_TFE10FoundationSi19_bridgeToObjectiveCfSiFT_CSo8NSNumber : $@convention(method) (Int) -> @owned NSNumber | |
// Swift.Int.init (Swift.Int.Type)(_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Int | |
sil [transparent] [fragile] @_TFSiCfMSiFT22_builtinIntegerLiteralBi2048__Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int | |
// @nonobjc __ObjC.NSDate.init (__ObjC.NSDate.Type)(timeIntervalSince1970 : Swift.Double) -> __ObjC.NSDate | |
sil shared @_TTOFCSo6NSDatecfMS_FT21timeIntervalSince1970Sd_S_ : $@convention(method) (Double, @owned NSDate) -> @owned NSDate { | |
bb0(%0 : $Double, %1 : $NSDate): | |
%2 = class_method [volatile] %1 : $NSDate, #NSDate.init!initializer.1.foreign : NSDate.Type -> (timeIntervalSince1970: Double) -> NSDate , $@convention(objc_method) (Double, @owned NSDate) -> @owned NSDate // user: %3 | |
%3 = apply %2(%0, %1) : $@convention(objc_method) (Double, @owned NSDate) -> @owned NSDate // user: %4 | |
return %3 : $NSDate // id: %4 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let b: Bool = NSDate(timeIntervalSince1970: 0) == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
結論
0がNSNumberに変換されて
に適用される。