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
210
Swift6のprotocol
omochi
4
910
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
Elm Form Validation
bkuhlmann
0
520
障害対応を起点としたもっといい開発と運用のサイクル作りのためにできること / Hatena Enginner Seminar #29
polamjag
0
420
Going beyond Apache Parquet's default settings
xhochy
0
140
Scalable Customer Journey Orchestration (CJO)
lewuathe
0
450
Domain-Driven Transformation
hschwentner
2
1.5k
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
170
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
1.1k
見た目から始める生産性向上
ikumatadokoro
10
1.5k
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
2
210
Goのmultiple errorsについて (2024年4月版)
syumai
4
1.2k
Ruby on Fails - effective error handling with Rails conventions
talyssonoc
0
200
From Spring Boot 2 to Spring Boot 3 with Java 21 and Jakarta EE
ivargrimstad
0
810
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
14
8.4k
From Idea to $5000 a Month in 5 Months
shpigford
378
45k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Infographics Made Easy
chrislema
238
18k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
41
4.4k
Code Reviewing Like a Champion
maltzj
515
39k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
126
32k
YesSQL, Process and Tooling at Scale
rocio
165
13k
GitHub's CSS Performance
jonrohan
1025
450k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
21
1.6k
Into the Great Unknown - MozCon
thekraken
15
1k
How GitHub (no longer) Works
holman
305
140k
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