Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TypeProf進捗
Search
Yusuke Endoh
August 31, 2024
Programming
0
74
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.8k
TRICK 2025 Results
mame
0
4.8k
Writing Ruby Scripts with TypeProf
mame
1
1k
An Invitation to TRICK: How to write weird Ruby programs
mame
1
1.2k
12年前の『型システム入門』翻訳の思い出話
mame
14
2.5k
Good first issues of TypeProf
mame
4
8.9k
Revisiting TypeProf - IDE support as a primary feature
mame
1
3.1k
error_highlight: User-friendly Error Diagnostics
mame
0
42
TRICK 2022 Results
mame
0
81
Other Decks in Programming
See All in Programming
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
450
AWS CDKの推しポイントN選
akihisaikeda
1
240
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
2
220
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
210
手が足りない!兼業データエンジニアに必要だったアーキテクチャと立ち回り
zinkosuke
0
650
20 years of Symfony, what's next?
fabpot
2
350
組み合わせ爆発にのまれない - 責務分割 x テスト
halhorn
1
150
AIコーディングエージェント(Gemini)
kondai24
0
210
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
420
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
3.1k
Integrating WordPress and Symfony
alexandresalome
0
150
認証・認可の基本を学ぼう前編
kouyuume
0
200
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Documentation Writing (for coders)
carmenintech
76
5.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Code Reviewing Like a Champion
maltzj
527
40k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Raft: Consensus for Rubyists
vanstee
141
7.2k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
For a Future-Friendly Web
brad_frost
180
10k
Side Projects
sachag
455
43k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.8k
The Language of Interfaces
destraynor
162
25k
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の互換インターフェイスを作ったら最低限いけるはず