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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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.2k
型システムを知りたい人のための型検査器作成入門
mame
15
5.4k
TRICK 2025 Results
mame
0
5.8k
Writing Ruby Scripts with TypeProf
mame
1
1.6k
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.9k
error_highlight: User-friendly Error Diagnostics
mame
0
72
Other Decks in Programming
See All in Programming
「AI時代、配布するPythonコードをどう守るか: 難読化の実験と判断軸」 #PyconJP2026
pkshadeck
PRO
2
180
Webプラットフォームで議論されているセキュリティ課題 / Security issues being discussed on Web Platforms
petamoriken
0
220
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
1.1k
スマート反転とウェブアクセシビリティ
camiha
0
140
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
55
36k
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
690
What We Talk About When We Talk About XP
m_seki
2
390
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
0
460
高専キャリア LT 発表内容
crysta1221
6
5.6k
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.5k
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
3
2.7k
Seeing Through Serverless: Observability for AWS Lambda with ADOT and CloudWatch Application Signals
seike460
PRO
1
120
Featured
See All Featured
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
290
It's Worth the Effort
3n
188
29k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
600
Marketing to machines
jonoalderson
1
5.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
260
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
Building Applications with DynamoDB
mza
96
7.2k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
810
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
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の互換インターフェイスを作ったら最低限いけるはず