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
Yusuke Endoh
August 31, 2024
Programming
0
63
TypeProf進捗
@ RubyKaigi 2024 followup
https://rhc.connpass.com/event/320709/
Yusuke Endoh
August 31, 2024
Tweet
Share
More Decks by Yusuke Endoh
See All by Yusuke Endoh
型システムを知りたい人のための型検査器作成入門
mame
15
4.5k
TRICK 2025 Results
mame
0
4.4k
Writing Ruby Scripts with TypeProf
mame
1
900
An Invitation to TRICK: How to write weird Ruby programs
mame
1
1k
12年前の『型システム入門』翻訳の思い出話
mame
14
2.4k
Good first issues of TypeProf
mame
4
8.3k
Revisiting TypeProf - IDE support as a primary feature
mame
1
2.8k
error_highlight: User-friendly Error Diagnostics
mame
0
36
TRICK 2022 Results
mame
0
76
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
290
Microsoft Orleans, Daprのアクターモデルを使い効率的に開発、デプロイを行うためのSekibanの試行錯誤 / Sekiban: Exploring Efficient Development and Deployment with Microsoft Orleans and Dapr Actor Models
tomohisa
0
220
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
100
速いWebフレームワークを作る
yusukebe
3
1.5k
Testing Trophyは叫ばない
toms74209200
0
110
A Gopher's Guide to Vibe Coding
danicat
0
200
MCPで実現するAIエージェント駆動のNext.jsアプリデバッグ手法
nyatinte
7
1k
Kiroの仕様駆動開発から見えてきたAIコーディングとの正しい付き合い方
clshinji
1
180
サイトを作ったらNFCタグキーホルダーを爆速で作れ!
yuukis
0
750
FindyにおけるTakumi活用と脆弱性管理のこれから
rvirus0817
0
350
TDD 実践ミニトーク
contour_gara
1
270
AHC051解法紹介
eijirou
0
640
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
A designer walks into a library…
pauljervisheath
207
24k
Six Lessons from altMBA
skipperchong
28
4k
Making the Leap to Tech Lead
cromwellryan
134
9.5k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
What's in a price? How to price your products and services
michaelherold
246
12k
Designing for humans not robots
tammielis
253
25k
Producing Creativity
orderedlist
PRO
347
40k
4 Signs Your Business is Dying
shpigford
184
22k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
570
Scaling GitHub
holman
463
140k
The Invisible Side of Design
smashingmag
301
51k
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の互換インターフェイスを作ったら最低限いけるはず