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
nilarg
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Matts966
September 24, 2019
Programming
170
0
Share
nilarg
Prevent nil pointer dereferences when calling function in Go.
Matts966
September 24, 2019
More Decks by Matts966
See All by Matts966
OSS分散ベクトル検索エンジンValdと最新の取り組み
matts966
0
120
Grafana Dashboard as Code using Grafana Foundation SDK
matts966
3
270
Static Analysis in Go
matts966
0
3.1k
Phics
matts966
0
87
Other Decks in Programming
See All in Programming
サプライチェーン攻撃対策「層を重ねて落ちない壁」を10日間で組み上げた話 #TechLeadConf2026
kashewnuts
1
220
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
170
AI時代になぜ書くのか
mutsumix
0
220
Liberating Ruby's Parser from Lexer Hacks
ydah
2
2.6k
JAWS-UG横浜 #100 祝・第100回スペシャルAWS は VPC レスの時代へ
maroon1st
0
220
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
740
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
180
AIを導入する前にやるべきこと
negima
2
340
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
140
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
540
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
140
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.8k
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
540
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.4k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
350
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1k
Facilitating Awesome Meetings
lara
57
6.8k
Exploring anti-patterns in Rails
aemeredith
3
350
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.7k
Un-Boring Meetings
codingconduct
0
280
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
Transcript
nil safety in Go nil safety in Go nil safety
in Go
nil safety? nil safety? Kotlin Go val user: User? =
getUser() val mail: String = user.Email // Compile Error val mail: String = user?.Email // OK var user *User mail := user.Email // Runtime Error if user != nil { mail := user.Email // OK } nil safety in Go
@tenntenn さんの より 『ソースコードを堪能せよ』 nil safety in Go
nil safety in Go
nil safety in Go
nilness nilness 関数内部のブロックを⾛査し、値がnil である か、nil でないか、unknow かを記録していく 同時にnil の値に対して危険な操作をしている箇 所を検出していく
SSA 、AST ともに関数を⼀つの単位として⾛査す る そのため他の関数呼び出しは別の処理が必要 であり、⾒逃されていた nil safety in Go
nilarg nilarg 全関数を⾛査して、nil になりうる型の引数に対 して、nil チェックせずに危険な操作をしていな いか確認 危険な操作を検知したら、該当の関数と引数を記 録 関数内部で関数を呼んでおり、その呼び出しが危
険な場合、再帰的に呼び出し元の関数も危険 そのため危険な関数リストを、リストの更新 がなくなるまで無限ループで更新 その後、実際に危険な関数をnil を引数として呼 び出している箇所を検出 nil safety in Go
Future Work Future Work LSP に組み込めば、関数がnil でpanic することを プログラマが意識できるのでは? 無名関数の変数など、静的解析で分からない部分
までは調べられない 引数が複数ある場合、偽陽性の可能性 go vet 本体に⼊れてもらいたい… SSA ⽣成周りにバグがありそうなのでデバッグ nil safety in Go
引数が複数ある場合、偽陽性の可 引数が複数ある場合、偽陽性の可 能性 能性 func doOptional(do bool, f func()) {
if do { f() } } nil safety in Go
links links @tenntenn さんの資料 つくったもの nilarg http://bit.ly/enjoysrc https://github.com/Matts966/refsafe https://github.com/Matts966/genelizer https://github.com/Matts966/nilarg
https://go- review.googlesource.com/c/tools/+/1953 nil safety in Go