Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
nilarg
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
160
Grafana Dashboard as Code using Grafana Foundation SDK
matts966
3
350
Static Analysis in Go
matts966
0
3.2k
Phics
matts966
0
99
Other Decks in Programming
See All in Programming
FreeBSDでZabbixを動かす
kenkino
0
340
AWSに止められる覚悟してますか?
morizo_1984
2
480
スマート反転とウェブアクセシビリティ
camiha
0
220
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
140
The Rails Doctrine Decade
koic
2
410
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.6k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Intent as Code
shoppingjaws
6
1.1k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
340
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
270
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
570
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
990
Featured
See All Featured
Leo the Paperboy
mayatellez
10
2.3k
Into the Great Unknown - MozCon
thekraken
41
2.7k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
310
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
Darren the Foodie - Storyboard
khoart
PRO
4
4k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
530
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
240
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Accessibility Awareness
sabderemane
1
220
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