Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
型推論ハンズオン
Search
omochimetaru
September 28, 2019
Programming
4
2.6k
型推論ハンズオン
ソース:
https://gist.github.com/omochi/3fac9ec60771f7d7182d1a9976e3c0b2
omochimetaru
September 28, 2019
Tweet
Share
More Decks by omochimetaru
See All by omochimetaru
Swiftの型推論を学ぼう | Let's Learn About Type Inference in Swift
omochi
3
4.1k
[スクリプト] Swiftの型推論を学ぼう
omochi
1
210
Swift6のprotocol
omochi
4
920
SwiftSyntaxをうまく使おう
omochi
2
250
今から使えるSwiftとC++の新しいinterop手法
omochi
0
330
CSFixとラベルマッチ
omochi
0
320
Swiftのmodifyアクセサとコルーチン
omochi
0
590
Swiftのオーバーロード選択のスコア規則12種類
omochi
3
270
SILを読もう
omochi
2
640
Other Decks in Programming
See All in Programming
SIMD Parallel Programming with the Vector API
josepaumard
0
250
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
6
2k
GitLab CI/CD で C#/WPFアプリケーションのテストとインストーラーのビルド・デプロイを自動化する
hacarus
0
550
MicrosoftのPlatform Engineeringガイドを読んで実際になにかやってみた
ymd65536
1
540
Next.js App Router
quramy
13
2.2k
Node.js v22 で変わること
yosuke_furukawa
PRO
12
4.1k
チーム立ち上げにAWSを活用したらClaudeさんに褒められた話
mkdev10
1
170
slow types ってなんだろう?
karad
0
200
Ruby on Fails - effective error handling with Rails conventions
talyssonoc
0
250
Apache Hive 4 on Treasure Data
ryukobayashi
1
470
2024 コーディング研修
ckazu
1
560
VS Code をプロダクトにどう取り込むか
onomax
1
800
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
26
2.3k
Being A Developer After 40
akosma
67
580k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
0
79
No one is an island. Learnings from fostering a developers community.
thoeni
16
2.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
221
21k
Product Roadmaps are Hard
iamctodd
45
9.8k
Web development in the modern age
philhawksworth
203
10k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
Into the Great Unknown - MozCon
thekraken
15
1.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
104
6.7k
Transcript
ܕਪϋϯζΦϯ @omochimetaru swiftc߹॓ 2019/09/28 1
՝ • ৯͍ঢ়ଶͷܕਪثΛͤ͞·͠ΐ͏ɻ • ϦϙδτϦ: https://github.com/omochi/ SwiftTypeInferenceHandsOn • ϒϥϯνquizɻmasterݟͳ͍Ͱʂ 2
৯͍Օॴ • ίϝϯτͰ<QXX hint="..." />ͱͳ͍ͬͯΔ ͱ͜ΖʹίʔυΛॻ͘ɻXX൪߸ɻ • <QͰݕࡧ͍ͯͩ͘͠͞ɻ • ൪߸ॱʹऔΓΉ͜ͱΛఆ͍ͯ͠·͢ɻ
• ه͚ͩͰࡁΉΑ͏ʹͳͬͯ·͢ɻطଘ෦ͷ আෆཁͰ͢ɻ 3
ςετίʔυ • ͢Δͱςετ͕શ෦௨ΔΑ͏ʹͳΓ·͢ɻ • ͨͩ͠ɺղ͍ͯςετ௨ա͕૿͑ͳ͍ ͋Γ·͢ɻ • ඞཁʹԠͯࣗ͡ͰςετΛՃ͠Α͏ɻ 4
ܕਪثͷ • ܕదɻ • ҉มͷਪʹରԠɻ • ܕڧ੍(type coerce)Λ࣮ɻ • ղൺֱ,
ղબΛະ࣮ɻ 5
ઃܭ 6
ํ • ίʔυͷσβΠϯΛ͋ΔఔຊՈswiftίϯύΠ ϥʹدͤͯ͋Δɻ • ࣮࣌ಡղͱநग़Λ͠ͳ͕Β࡞ͬͨɻ • ϑΝΠϧ໊ɺܕ໊ɺ໊͕ؔ͋Δఔಉ͡ɻ 7
ύοέʔδ - SwiftcBasic: ϢʔςΟϦςΟ - SwiftcType: ܕ - SwiftcAST: ύʔαʔͱAST
- SwiftcSema: ܕਪɺ৯͍͚ͩ͜͜ɻ - SwiftcTest: ςετ༻ͷϢʔςΟϦςΟ 8
Semaৄࡉ - Constraint: ੍ - Conversion: ม - ConstraintSystem: ੍Λղ͘Ϟδϡʔϧ
- CSApply: ܕਪ݁ՌʹΑΔASTͷม - CSBinding: ܕมͷׂԾઆͷੜ - CSGen: ੍ͷੜ - CSMatch: ܕͷϚον - CSSimplify: ੍ͷ؆ - CSSolve: ୳ࡧ - CSStep: ୳ࡧͷεςοϓ - TypeChecker: ιʔεશମΛܕνΣοΫ͢Δɻ 9
TypeCheckerͱConstraintSystem • ConstraintSystem(CS)1ͭͷࣜΛղ͘Ϟ δϡʔϧ • TypeChecker͕ߏจʹԠͯ͡CSΛىಈ͢Δ 10
ྫ: ೖจ • ೖจͷӈลࣜͳͷͰCSͰղ͚Δɻ • ೖͷ֓೦ࠨลจͷྖҬͳͷͰCSͷର ֎ɻ • CSʹσϦήʔτ͕͋ΓɺTypeChecker͕ೖ จͷѻ͍Λೖ͢Δɻ
(typeCheckVariableDecl) 11
ศརͳϝιου - ASTNode.dump() - ConstraintSystem.dump() - (͍Ζ͍Ζͳܕ).description 12
՝ͷऔΓΈํͷྫ • ৯͍෦ͰͲΜͳॲཧΛ͍ͯ͠Δͷ͔ղੳ͢ Δɻ • ϒϨʔΫϙΠϯτΛష͔ͬͯΒςετΛൃՐ͠ ͯɺಥೖաఔΛௐΔɻ • ͦ͜ͰԿΛ͖͔͢ߟ͑Δɻ •
ຊՈίϯύΠϥͷ֘ՕॴΛݟֶͯͿɻ 13
ຊՈίϯύΠϥͷղੳ 14
Ϗϧυ $ utils/update-checkout --scheme master $ utils/build-script --xcode --debug --skip-build-benchmarks
15
Xcode • build/Xcode-DebugAssert/swift-macosx- x86_64/Swift.xcodeproj • swift࣮ߦϑΝΠϧͷschemeΛ࡞Δ 16
σόοΨΛ͏ • schemeͷઃఆ: Debug Process As: root, Launch: Wait for
executable to be launched • Ϗϧυͨ͠swiftʹύεΛ௨͢ • XcodeΛRun͔ͯ͠ΒλʔϛφϧͰ࣮ߦ 17
swiftcͷ࣮ߦ • $ swiftc -dump-ast -Xfrontend -debug- constraints 01.swift 18
Ԡ༻՝ • ରԠ͢ΔswiftcͷίʔυΛಡΜͰΈ·͠ΐ͏ɻ • ܕਪثʹػೳΛՃ͠Α͏ɻ • ՌΛൃද͠Α͏ɻ 19