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
TypeProf進捗
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yusuke Endoh
August 31, 2024
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TypeProf進捗
@ RubyKaigi 2024 followup
https://rhc.connpass.com/event/320709/
Yusuke Endoh
August 31, 2024
More Decks by Yusuke Endoh
See All by Yusuke Endoh
Practical TypeProf: Lessons from Analyzing Optcarrot
mame
1
3.1k
型システムを知りたい人のための型検査器作成入門
mame
15
5.4k
TRICK 2025 Results
mame
0
5.7k
Writing Ruby Scripts with TypeProf
mame
1
1.5k
An Invitation to TRICK: How to write weird Ruby programs
mame
1
1.4k
12年前の『型システム入門』翻訳の思い出話
mame
14
2.8k
Good first issues of TypeProf
mame
4
10k
Revisiting TypeProf - IDE support as a primary feature
mame
1
3.8k
error_highlight: User-friendly Error Diagnostics
mame
0
69
Other Decks in Programming
See All in Programming
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
460
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
170
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
200
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
420
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.8k
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
1
180
yield再入門 #phpcon
o0h
PRO
0
930
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
470
テーブルをDELETEした
yuzneri
0
130
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
240
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
250
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
660
Featured
See All Featured
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.3k
Designing Experiences People Love
moore
143
24k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Building Applications with DynamoDB
mza
96
7.2k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
210
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
41k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
330
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Transcript
TypeProf進捗 Yusuke Endoh (@mame) RubyKaigi 2024 followup
復習: TypeProf • 型注釈を必須としない Rubyの型解析・エディタ支援ツール • データフロー解析に基づく • RBSがあれば読み込む •
RubyKaigiの発表:貢献を呼び掛けた • "Good first issues of TypeProf" • パッチの書き方、テストの仕方などを説明した 5.ti| 1 + "str" TypeError Do you mean: 5 .times
みんなありがとう • 100+ pull requests 0 2 4 6 8
10 12 14 16 18 20 PR数 ※数え間違えてたらごめんなさい
進捗 • ruby/ruby の lib/**/*.rb の全ファイルが ほぼ 解析できた • ただし
• lib/ruby_vm/rjitだけは除く(パターンマッチ……) • 解析時間は要改善(850ファイルで8分、1ファイル平均0.6秒) • lib/reline/line_editor.rb 1つが数分くらいかかるので要調査 • ファイルごとに解析してる(相互作用によるバグは絶対まだまだある) • false positiveも気にしてない(これから潰し方を考えていく)
むずかしくて面白い問題 • 次のコードを解析するとTypeProfが無限ループ • lib/resolv.rbから簡略化して得た例 @a = @b[0] @b =
"x" + @a
無限ループの仕組み (1) • 解析の初期状態 • @a: untyped • @b: untyped
@a = @b[0] @b = "x" + @a
無限ループの仕組み (2) • 現在の状態 • @a: untyped, @b: untyped •
1行目の解析 • レシーバの@bはuntyped • @aはuntypedのまま • 新しい状態 • @a: untyped, @b: untyped @a = @b[0] @b = "x" + @a
無限ループの仕組み (2) • 現在の状態 • @a: untyped, @b: untyped •
2行目の解析 • String#+: (String) -> String • @bはuntyped(何にでもマッチ)なので@aはStringになる • 新しい状態 • @a: untyped, @b: String @a = @b[0] @b = "x" + @a
無限ループの仕組み (4) • 現在の状態 • @a: untyped, @b: String •
1行目の(再)解析 • レシーバの型が変わったので再解析が発生する • String#[]: (Integer) -> String? • @aはString?になる • 新しい状態 • @a: String?, @b: String @a = @b[0] @b = "x" + @a
無限ループの仕組み (5) • 現在の状態 • @a: String?, @b: String •
2行目の(再)解析 • 引数の型が変わったので再解析が発生する • String#+: (String) -> String • @aはString? なのでマッチしない!ので@bはuntypedになる • 新しい状態 • @a: String?, @b: untyped @a = @b[0] @b = "x" + @a
無限ループの仕組み (6) • 現在の状態 • @a: String?, @b: untyped •
1行目の(再)解析 • レシーバの型が変わったので再解析が発生する • レシーバの@bがuntypedなので、@aはuntypedにもどる • 新しい状態 • @a: untyped, @b: untyped → 初期状態! @a = @b[0] @b = "x" + @a
無限ループの仕組み: まとめ • 解析状態の更新がループしてしまっていた • @a: untyped, @b: untyped •
@a: untyped, @b: String • @a: String?, @b: String • @a: String?, @b: untyped • @a: untyped, @b: untyped
暫定対応:引数マッチの処理を変更した • String#+: (String) -> String に String? を渡す場合 •
旧:String? はマッチしないのでuntypedを返す • 新:String? は String にマッチすることにする • 警告は出す(TODO) • これで一旦 lib/**/*.rb を全パスした(rjit除く)
完全ではなかった • この資料を作りながら考えてたら 刺さるシナリオが作れてしまった ## update: test.rbs class C def
foo: (C) -> C def bar: -> Integer end ## update: test.rb def check c = C.new @a = @b.bar @b = c.foo(@a) end
問題の整理 • 一度マッチしたメソッド呼び出しは外れてほしくない • 考えられる直し方 • 保守的な案:untypedは何にもマッチしないことにする • "x" +
untyped が String にならなくなる • TypeScript の any から大きく違う意味になる • 雑な案:引数の数さえあってれば常にマッチすることにする • "x" + 1 は String を返すと推論する(型エラーは出す) • 1 + 1 が (Complex | Rational | Integer | Float) になるのはちょっと不幸 • 鋭意検討中です
まとまらないまとめ • TypeProf鋭意開発中です • 進捗と現状 • Rubyの全文法対応までたぶんあと少し • いろんなコードに適用して問題洗い出し・対応中 •
Ruby 3.4.0にはTypeProf v2をバンドルしたい • パターンマッチ構文のサポートと TypeProf v1の互換インターフェイスを作ったら最低限いけるはず