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
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
140
Grafana Dashboard as Code using Grafana Foundation SDK
matts966
3
290
Static Analysis in Go
matts966
0
3.2k
Phics
matts966
0
93
Other Decks in Programming
See All in Programming
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
140
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
190
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
190
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
780
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
210
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
210
AIで効率化できた業務・日常
ochtum
0
160
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
5
860
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.6k
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
460
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Skip the Path - Find Your Career Trail
mkilby
1
160
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
240
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
330
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Documentation Writing (for coders)
carmenintech
77
5.4k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
170
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
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