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
4k
[スクリプト] Swiftの型推論を学ぼう
omochi
1
200
Swift6のprotocol
omochi
4
910
SwiftSyntaxをうまく使おう
omochi
2
250
今から使えるSwiftとC++の新しいinterop手法
omochi
0
330
CSFixとラベルマッチ
omochi
0
310
Swiftのmodifyアクセサとコルーチン
omochi
0
590
Swiftのオーバーロード選択のスコア規則12種類
omochi
3
270
SILを読もう
omochi
2
640
Other Decks in Programming
See All in Programming
Let's learn code review
riofujimon
2
610
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
330
TCAとKMPを用いた新規動画配信アプリ 「ABEMA Live」の設計
tomu28
2
130
Polars入門
daikikatsuragawa
1
190
Git Lint
bkuhlmann
4
760
Ruby Pattern Matching
bkuhlmann
0
930
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
6
1.8k
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
680
Exploring the Implementation of “t.Run”, “t.Parallel”, and “t.Cleanup”
akarin
1
140
AWS CDKコントリビュートTIPS / aws-cdk-contribution-tips
gotok365
4
420
Try creating your own orderedmap
kazamori
1
250
ServerAction で Progressive Enhancement はどこまで頑張れるか? / progressive-enhancement-with-server-action
takefumiyoshii
6
460
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
21
1.6k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
358
22k
We Have a Design System, Now What?
morganepeng
43
6.8k
Gamification - CAS2011
davidbonilla
77
4.6k
Facilitating Awesome Meetings
lara
43
5.6k
Testing 201, or: Great Expectations
jmmastey
30
6.4k
How to train your dragon (web standard)
notwaldorf
75
5.2k
Visualization
eitanlees
137
14k
Agile that works and the tools we love
rasmusluckow
325
20k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
20
1.8k
Product Roadmaps are Hard
iamctodd
45
9.8k
[RailsConf 2023] Rails as a piece of cake
palkan
28
4k
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