Last active
June 3, 2018 02:24
-
-
Save YutoMizutani/7b606504fda7d7c8064d7e502f4a146f to your computer and use it in GitHub Desktop.
class func v. static func in Swift4 ref: https://qiita.com/YutoMizutani/items/040d8af5bfc38d9f1fac
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
class Main { | |
class func say() { | |
print("Hello, world!!") | |
} | |
} | |
Main.say() |
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
diff ./sil/final-class-func.sil ./sil/static-func.sil | |
diff ./sil/final-class-func.sil ./sil/open-class-func.sil | |
diff ./sil/final-class-func.sil ./sil/public-class-func.sil | |
diff ./sil/final-class-func.sil ./sil/internal-class-func.sil | |
diff ./sil/final-class-func.sil ./sil/fileprivate-class-func.sil | |
diff ./sil/final-class-func.sil ./sil/private-class-func.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
$ swiftc -v | |
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1) | |
Target: x86_64-apple-darwin17.5.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
class Main { | |
class func say() { | |
print("Hello, world!!") | |
} | |
} | |
Main.say() |
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
class Main { | |
init() { | |
Main.say() | |
} | |
<foo> class func say() { | |
print("Hello, world!!") | |
} | |
} | |
let _ = Main() |
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
xcrun swiftc -wmo -O ./final-class-func.swift | |
xcrun swiftc -wmo -O ./static-func.swift | |
xcrun swiftc -wmo -O ./open-func.swift | |
xcrun swiftc -wmo -O ./public-class-func.swift | |
xcrun swiftc -wmo -O ./internal-class-func.swift | |
xcrun swiftc -wmo -O ./fileprivate-class-func.swift | |
xcrun swiftc -wmo -O ./private-class-func.swift |
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
class Main { | |
static func say() { | |
print("Hello, world!!") | |
} | |
} | |
Main.say() |
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 class-func.swift > class-func.sil | |
$ swiftc -emit-silgen static-func.swift > static-func.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
diff class-func.sil static-func.sil | |
@@ -7,8 +7,9 @@ import SwiftShims | |
// main | |
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { | |
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): | |
- %2 = metatype $@thick Main.Type // users: %4, %3 | |
- %3 = class_method %2 : $@thick Main.Type, #Main.say!1 : (Main.Type) -> () -> (), $@convention(method) (@thick Main.Type) -> () // user: %4 | |
+ %2 = metatype $@thick Main.Type // user: %4 | |
+ // function_ref static Main.say() | |
+ %3 = function_ref @_T04main4MainC3sayyyFZ : $@convention(method) (@thick Main.Type) -> () // user: %4 | |
%4 = apply %3(%2) : $@convention(method) (@thick Main.Type) -> () | |
%5 = integer_literal $Builtin.Int32, 0 // user: %6 | |
%6 = struct $Int32 (%5 : $Builtin.Int32) // user: %7 | |
@@ -117,7 +118,6 @@ bb0(%0 : $Main): | |
} // end sil function '_T04main4MainCACycfc' | |
sil_vtable Main { | |
- #Main.say!1: (Main.Type) -> () -> () : _T04main4MainC3sayyyFZ // static Main.say() | |
#Main.init!initializer.1: (Main.Type) -> () -> Main : _T04main4MainCACycfc // Main.init() | |
#Main.deinit!deallocator: _T04main4MainCfD // Main.__deallocating_deinit | |
} |
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-assembly class-func.swift > class-func.s | |
$ swiftc -emit-assembly static-func.swift > static-func.s |
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
diff class-func.s static-func.s | |
@@ -385,7 +385,7 @@ l___unnamed_4: | |
__T04main4MainCMn: | |
.long l___unnamed_3-__T04main4MainCMn | |
.long 0 | |
- .long 12 | |
+ .long 11 | |
.long (l___unnamed_4-__T04main4MainCMn)-12 | |
.long (l_get_field_types_Main-__T04main4MainCMn)-16 | |
.long 0 | |
@@ -397,10 +397,8 @@ __T04main4MainCMn: | |
.short 4 | |
.long 0 | |
.long 10 | |
- .long 2 | |
- .long (__T04main4MainC3sayyyFZ-__T04main4MainCMn)-56 | |
- .long 0 | |
- .long (__T04main4MainCACycfc-__T04main4MainCMn)-64 | |
+ .long 1 | |
+ .long (__T04main4MainCACycfc-__T04main4MainCMn)-56 | |
.long 1 | |
.zerofill __DATA,__bss,__T04main4MainCML,8,3 | |
@@ -419,11 +417,10 @@ __T04main4MainCMf: | |
.long 16 | |
.short 7 | |
.short 0 | |
- .long 112 | |
+ .long 104 | |
.long 16 | |
.quad __T04main4MainCMn | |
.quad 0 | |
- .quad __T04main4MainC3sayyyFZ | |
.quad __T04main4MainCACycfc | |
.section __TEXT,__swift3_typeref,regular,no_dead_strip |
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
class Main { | |
final class func say() { | |
print("Hello, world!!") | |
} | |
} | |
Main.say() |
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
class Main { | |
static func say() { | |
print("Hello, world!!") | |
} | |
} | |
Main.say() |
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 final-class-func.swift > final-class-func.sil | |
$ swiftc -emit-silgen static-func.swift > static-func.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
class Main { | |
final class func say() { | |
print("Hello, world!!") | |
} | |
} | |
Main.say() |
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 -wmo -O final-class-func.swift > ./sil/final-class-func.sil | |
swiftc -emit-silgen -wmo -O static-func.swift > ./sil/static-func.sil | |
swiftc -emit-silgen -wmo -O open-class-func.swift > ./sil/open-class-func.sil | |
swiftc -emit-silgen -wmo -O public-class-func.swift > ./sil/public-class-func.sil | |
swiftc -emit-silgen -wmo -O internal-class-func.swift > ./sil/internal-class-func.sil | |
swiftc -emit-silgen -wmo -O fileprivate-class-func.swift > ./sil/fileprivate-class-func.sil | |
swiftc -emit-silgen -wmo -O private-class-func.swift > ./sil/private-class-func.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
sed -n 43p ./sil/final-class-func.sil | |
sed -n 43p ./sil/static-func.sil | |
sed -n 43p ./sil/open-class-func.sil | |
sed -n 43p ./sil/public-class-func.sil | |
sed -n 43p ./sil/internal-class-func.sil | |
sed -n 43p ./sil/fileprivate-class-func.sil | |
sed -n 43p ./sil/private-class-func.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
class Main { | |
static func say() { | |
print("Hello, world!!") | |
} | |
} | |
Main.say() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment