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
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
100
Other Decks in Programming
See All in Programming
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
カツオ、ご期待ください
suneo3476
0
190
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
170
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
160
ActionController meets Protocol Buffers
sorah
0
520
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
290
The Rails Doctrine Decade
koic
2
590
ジョジョの世界をXRで再現する
mofurune
0
160
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
Railsバージョンを4倍にした話
optim
0
350
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
6.3k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
800
The browser strikes back
jonoalderson
0
1.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
540
HDC tutorial
michielstock
2
960
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
480
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
How to train your dragon (web standard)
notwaldorf
96
6.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
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