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
Matts966
September 24, 2019
Programming
0
160
nilarg
Prevent nil pointer dereferences when calling function in Go.
Matts966
September 24, 2019
Tweet
Share
More Decks by Matts966
See All by Matts966
OSS分散ベクトル検索エンジンValdと最新の取り組み
matts966
0
78
Grafana Dashboard as Code using Grafana Foundation SDK
matts966
3
160
Static Analysis in Go
matts966
0
3.1k
Phics
matts966
0
80
Other Decks in Programming
See All in Programming
Vue 3.6 時代のリアクティビティ最前線 〜Vapor/alien-signals の実践とパフォーマンス最適化〜
hiranuma
2
350
マンガアプリViewerの大画面対応を考える
kk__777
0
440
オープンソースソフトウェアへの解像度🔬
utam0k
18
3.2k
Module Proxyのマニアックな話 / Niche Topics in Module Proxy
kuro_kurorrr
0
480
オンデバイスAIとXcode
ryodeveloper
0
370
Ktorで簡単AIアプリケーション
tsukakei
0
120
エンジニアインターン「Treasure」とHonoの2年、そして未来へ / Our Journey with Hono Two Years at Treasure and Beyond
carta_engineering
0
470
AI駆動開発カンファレンスAutumn2025 _AI駆動開発にはAI駆動品質保証
autifyhq
0
100
CSC305 Lecture 11
javiergs
PRO
0
320
品質ワークショップをやってみた
nealle
0
830
モテるデスク環境
mozumasu
3
1.4k
CSC509 Lecture 08
javiergs
PRO
0
270
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
Statistics for Hackers
jakevdp
799
220k
Six Lessons from altMBA
skipperchong
29
4k
Into the Great Unknown - MozCon
thekraken
40
2.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
2
220
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.7k
We Have a Design System, Now What?
morganepeng
54
7.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.7k
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