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
3.1k
4
Share
型推論ハンズオン
ソース:
https://gist.github.com/omochi/3fac9ec60771f7d7182d1a9976e3c0b2
omochimetaru
September 28, 2019
More Decks by omochimetaru
See All by omochimetaru
Swift Concurrency 年表クイズ
omochi
3
300
型推論のちょっと深い話
omochi
1
540
Swiftの型推論を学ぼう | Let's Learn About Type Inference in Swift
omochi
4
11k
[スクリプト] Swiftの型推論を学ぼう
omochi
2
520
Swift6のprotocol
omochi
6
1.4k
SwiftSyntaxをうまく使おう
omochi
2
420
今から使えるSwiftとC++の新しいinterop手法
omochi
0
510
CSFixとラベルマッチ
omochi
0
470
Swiftのmodifyアクセサとコルーチン
omochi
0
920
Other Decks in Programming
See All in Programming
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
380
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
1.1k
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
620
Migrations : C'est une question d'hygiène !
vinceamstoutz
0
2.2k
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
130
AIエージェントと協働するCLI開発 — BunとOpenClawで学んだこと
yoshikouki
1
220
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
1.3k
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
290
今さら聞けないCancellationToken
htkym
0
200
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.7k
RTSPクライアントを自作してみた話
simotin13
0
290
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
270
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
300
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
580
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
GraphQLとの向き合い方2022年版
quramy
50
15k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
590
Deep Space Network (abreviated)
tonyrice
0
150
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
820
It's Worth the Effort
3n
188
29k
Music & Morning Musume
bryan
47
7.2k
Facilitating Awesome Meetings
lara
57
6.9k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
370
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