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
0
170
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
100
Grafana Dashboard as Code using Grafana Foundation SDK
matts966
3
240
Static Analysis in Go
matts966
0
3.1k
Phics
matts966
0
82
Other Decks in Programming
See All in Programming
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
850
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
810
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.8k
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
130
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
260
Oxlintはいいぞ
yug1224
5
1.4k
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
320
Rails Girls Tokyo 18th GMO Pepabo Sponsor Talk
yutokyokutyo
0
120
生成AIを活用したソフトウェア開発ライフサイクル変革の現在値
hiroyukimori
PRO
0
120
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
AIに仕事を丸投げしたら、本当に楽になれるのか
dip_tech
PRO
0
120
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
200
Featured
See All Featured
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
950
Discover your Explorer Soul
emna__ayadi
2
1.1k
Music & Morning Musume
bryan
47
7.1k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
230
How to make the Groovebox
asonas
2
2k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Into the Great Unknown - MozCon
thekraken
40
2.3k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
62
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
140
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
30 Presentation Tips
portentint
PRO
1
230
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