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
0
210
空の型セットを検出したい
https://andpad.connpass.com/event/212051/
nobishii
May 18, 2021
Tweet
Share
More Decks by nobishii
See All by nobishii
introduction to type sets
nobishino
1
1.9k
Other Decks in Programming
See All in Programming
Rubyのパフォーマンスプロファイリングの改善 / Enhancing performance profiling for Ruby
osyoyu
1
410
データカタログ運用物語 〜令和6年夏の理想と現実〜
kuro_kurorrr
0
110
初心者がおさえておきたいAWS CDKのベストプラクティス 2024
konokenj
15
7.3k
さきがけから振り返るアーキテクチャ刷新 / Reflecting on the Architectural Renewal from the Vanguard
nrslib
2
780
12年前の『型システム入門』翻訳の思い出話
mame
11
1.2k
CSC307 Lecture 10
javiergs
PRO
0
310
3 Effective Rules for Success with Signals in Angular
manfredsteyer
PRO
0
120
ドメイン駆動設計の実践
masuda220
PRO
19
5.2k
スクラムマスターって孤独じゃないですか?
yoshitaroyoyo
1
140
AWS初心者ってどうやってAWSを学ぶ?〜アプリエンジニアがやってよかったアーキテクチャ学習方法〜
yamanashi_ren01
0
190
Polarsの成長: v0.14からv1.0までの変遷と今後の展望
zerebom
1
350
GraphQL はいいぞ! ~Laravel で学ぶ GraphQL 入門~
azuki
1
160
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
36
13k
We Have a Design System, Now What?
morganepeng
46
7k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
78
15k
Into the Great Unknown - MozCon
thekraken
20
1.3k
WebSockets: Embracing the real-time Web
robhawkes
59
7.2k
KATA
mclloyd
20
13k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
26
1.6k
Agile that works and the tools we love
rasmusluckow
325
20k
Mobile First: as difficult as doing things right
swwweet
219
8.8k
Learning to Love Humans: Emotional Interface Design
aarron
269
39k
Scaling GitHub
holman
458
140k
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さん - 発表アーカイブ動画 - 勇者さま一行のイラストは いらすとや様からお借りしました