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.8k
型推論ハンズオン
ソース:
https://gist.github.com/omochi/3fac9ec60771f7d7182d1a9976e3c0b2
omochimetaru
September 28, 2019
Tweet
Share
More Decks by omochimetaru
See All by omochimetaru
型推論のちょっと深い話
omochi
1
400
Swiftの型推論を学ぼう | Let's Learn About Type Inference in Swift
omochi
4
5.6k
[スクリプト] Swiftの型推論を学ぼう
omochi
2
350
Swift6のprotocol
omochi
6
1.2k
SwiftSyntaxをうまく使おう
omochi
2
310
今から使えるSwiftとC++の新しいinterop手法
omochi
0
400
CSFixとラベルマッチ
omochi
0
370
Swiftのmodifyアクセサとコルーチン
omochi
0
700
Swiftのオーバーロード選択のスコア規則12種類
omochi
3
350
Other Decks in Programming
See All in Programming
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.4k
イベント駆動で成長して委員会
happymana
1
320
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
ヤプリ新卒SREの オンボーディング
masaki12
0
130
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Jakarta EE meets AI
ivargrimstad
0
600
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
880
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Navigating Team Friction
lara
183
14k
Teambox: Starting and Learning
jrom
133
8.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
What's new in Ruby 2.0
geeforr
343
31k
Agile that works and the tools we love
rasmusluckow
327
21k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Unsuck your backbone
ammeep
668
57k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Docker and Python
trallard
40
3.1k
Become a Pro
speakerdeck
PRO
25
5k
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