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
空の型セットを検出したい
Search
nobishii
May 18, 2021
Programming
290
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
空の型セットを検出したい
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.2k
Other Decks in Programming
See All in Programming
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
150
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
1k
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
ActionController meets Protocol Buffers
sorah
0
520
The Rails Doctrine Decade
koic
2
590
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
A Modern Web Designer's Workflow
chriscoyier
699
190k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Building the Perfect Custom Keyboard
takai
2
910
So, you think you're a good person
axbom
PRO
2
2.2k
The browser strikes back
jonoalderson
0
1.8k
A Soul's Torment
seathinner
8
3.8k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Testing 201, or: Great Expectations
jmmastey
46
8.3k
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さん - 発表アーカイブ動画 - 勇者さま一行のイラストは いらすとや様からお借りしました