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
空の型セットを検出したい
Search
nobishii
May 18, 2021
Programming
240
0
Share
空の型セットを検出したい
https://andpad.connpass.com/event/212051/
nobishii
May 18, 2021
More Decks by nobishii
See All by nobishii
introduction to type sets
nobishino
1
2.1k
Other Decks in Programming
See All in Programming
おれのAgentic Coding 2026/03
tsukasagr
1
130
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
1.7k
RSAが破られる前に知っておきたい 耐量子計算機暗号(PQC)入門 / Intro to PQC: Preparing for the Post-RSA Era
mackey0225
3
120
我々はなぜ「層」を分けるのか〜「関心の分離」と「抽象化」で手に入れる変更に強いシンプルな設計〜 #phperkaigi / PHPerKaigi 2026
shogogg
2
810
PHPで TLSのプロトコルを実装してみる
higaki_program
0
740
Java 21/25 Virtual Threads 소개
debop
0
330
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
180
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
150
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.3k
安いハードウェアでVulkan
fadis
1
920
PHP でエミュレータを自作して Ubuntu を動かそう
m3m0r7
PRO
2
170
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
270
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
40
2.3k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
310
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Deep Space Network (abreviated)
tonyrice
0
110
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.2k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
320
Java REST API Framework Comparison - PWX 2021
mraible
34
9.2k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
Amusing Abliteration
ianozsvald
1
150
Raft: Consensus for Rubyists
vanstee
141
7.4k
Context Engineering - Making Every Token Count
addyosmani
9
800
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
370
Transcript
空の型セットを検出したい https://andpad.connpass.com/event/212051/ 2021/05/19(水) @shino_nobishii
自己紹介 - Nobishii(のびしー) @shino_nobishii - Go言語経験 2020年2月〜 - 静的解析初心者 -
Go言語仕様書の知識が少しあります
目次 - 背景: 型パラメータと型制約と型セット - 型セットの具体例 - 問題: 空の型セット -
Underlying type - サンプルコード: Underlying typeが自分自身かどうかを判定する - 参考資料
型セットってなんだ? いきなり知らないものが出てき たけど...
背景 - 型パラメータ(ジェネリクス) Proposal: accepted - 型制約をinterfaceとして記述する - 型セットProposal: acceptedではないけどacceptされそうな状況
- 型制約の記述方法を改善するもの - 全ての型は、型セットを持つ - 「型Tがinterface Iを実装する」は「型TがIの型セットに属する」と同じ意味になる
型セットの具体例
underlying typeってなんだ? また知らないものが出てきたけ ど... 少し後で出てきます!
空の型セット問題: これを実装する型は存在しない! https://github.com/golang/go/issues/45346 より引用
結論:コンパイラで空の型セットはチェックされない 我々は諦めない。 コンパイラも使わず、コードを実行もせずに 型セットの性質を調べる、そんな手段を見つ けさえすればいいのだ。 あるいは夢物語かもしれないが ...
静的解析で型セットを調べる - 「空の型セット」の検出を一般的に解決するのは難しい - 特定の場合なら解決できる - その一つが”underlying type”に関係するパターン - 静的解析を使う
型セットの具体例
underlying typeとは
underlying typeとは - ~Tは、「underlying typeがTである ような全ての型」の集合 - ~int は{int ,
MyInt, MyMyInt, …} - ~MyInt は {} (空集合) - underlying typeがMyIntになるよう な型は存在しないから - intの特徴: underlying typeが自分 自身
判定方法 - ~SomeTypeをParseする(※今日は行いません) - SomeTypeのunderlying typeがSomeTypeに等しいかどうか調べる - 使う関数: - (*types.Package).Scope()
*types.Scope - パッケージレベルで宣言されたモノを取得 - (*types.Scope).Lookup(name string) types.Object - Scopeから名前で検索 - (types.Type).Underlying() types.Type - ある型のunderlying typeを返す
Underlying typeが自分自身かどうかを判定する - サンプルコードをきれいに貼れなかったのでGitHubで説明します - https://github.com/nobishino/studyast/blob/main/main.go#L40
参考資料 - Go公式資料 - Type Parameters Proposal 型パラメータ(ジェネリクス)に関するProposal(accepted) - https://github.com/golang/go/issues/45346
型セットに関するProposal - その他資料 - Go の "Type Sets" proposal を読む - underlying types by DQNEOさん - 発表アーカイブ動画 - 勇者さま一行のイラストは いらすとや様からお借りしました