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
75
Grafana Dashboard as Code using Grafana Foundation SDK
matts966
3
150
Static Analysis in Go
matts966
0
3.1k
Phics
matts966
0
80
Other Decks in Programming
See All in Programming
GraphQL×Railsアプリのデータベース負荷分散 - 月間3,000万人利用サービスを無停止で
koxya
1
1k
Web Components で実現する Hotwire とフロントエンドフレームワークの橋渡し / Bridging with Web Components
da1chi
3
1.5k
Conquering Massive Traffic Spikes in Ruby Applications with Pitchfork
riseshia
0
140
Web フロントエンドエンジニアに開かれる AI Agent プロダクト開発 - Vercel AI SDK を観察して AI Agent と仲良くなろう! #FEC余熱NIGHT
izumin5210
2
310
2分台で1500examples完走!爆速CIを支える環境構築術 - Kaigi on Rails 2025
falcon8823
3
2.8k
AccessorySetupKitで実現するシームレスなペアリング体験 / Seamless pairing with AccessorySetupKit
nekowen
0
210
開発生産性を上げるための生成AI活用術
starfish719
1
130
2025年版 サーバーレス Web アプリケーションの作り方
hayatow
23
25k
階層構造を表現するデータ構造とリファクタリング 〜1年で10倍成長したプロダクトの変化と課題〜
yuhisatoxxx
3
860
CSC509 Lecture 03
javiergs
PRO
0
320
Learn CPU architecture with Assembly
akkeylab
1
1.3k
AIエージェント時代における TypeScriptスキーマ駆動開発の新たな役割
bicstone
4
1.3k
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
19
1.2k
How to Ace a Technical Interview
jacobian
280
23k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
Statistics for Hackers
jakevdp
799
220k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Automating Front-end Workflow
addyosmani
1371
200k
The Invisible Side of Design
smashingmag
301
51k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Why Our Code Smells
bkeepers
PRO
339
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