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
bootcamp2025_バックエンド研修_WebAPIサーバ作成.pdf
geniee_inc
0
140
Leading Effective Engineering Teams in the AI Era
addyosmani
7
670
Swift Concurrency 年表クイズ
omochi
2
130
モテるデスク環境
mozumasu
3
1.4k
ALL CODE BASE ARE BELONG TO STUDY
uzulla
28
6.8k
品質ワークショップをやってみた
nealle
0
650
AI Agent 時代的開發者生存指南
eddie
4
2.2k
Towards Transactional Buffering of CDC Events @ Flink Forward 2025 Barcelona Spain
hpgrahsl
0
120
When Dependencies Fail: Building Antifragile Applications in a Fragile World
selcukusta
0
110
マンガアプリViewerの大画面対応を考える
kk__777
0
410
AI駆動で0→1をやって見えた光と伸びしろ
passion0102
1
890
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
200
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
640
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.2k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
The Invisible Side of Design
smashingmag
302
51k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
Thoughts on Productivity
jonyablonski
71
4.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
The Cult of Friendly URLs
andyhume
79
6.6k
Why Our Code Smells
bkeepers
PRO
340
57k
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