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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
nobishii
May 18, 2021
Programming
280
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
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.5k
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
6.4k
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
240
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
420
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
190
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
260
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
140
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.8k
Foundry Localでエージェント開発
seosoft
0
180
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
150
業務時間外もAIに働いてもらう話
colorful12
3
10k
Featured
See All Featured
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
600
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
420
Paper Plane
katiecoart
PRO
3
53k
WENDY [Excerpt]
tessaabrams
13
39k
Optimising Largest Contentful Paint
csswizardry
37
4k
Why Our Code Smells
bkeepers
PRO
340
58k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
310
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
540
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
202
76k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
270
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さん - 発表アーカイブ動画 - 勇者さま一行のイラストは いらすとや様からお借りしました