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
270
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
Built Our Own Background Agent at LayerX #aidevex_findy
layerx
PRO
9
3.8k
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.4k
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
120
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
190
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
260
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
120
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
490
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
190
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
0
180
AIエージェントで 変わるAndroid開発環境
takahirom
2
740
メールのエイリアス機能を履き違えない
isshinfunada
0
160
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
0
120
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
190
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
620
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
240
Measuring & Analyzing Core Web Vitals
bluesmoon
9
930
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
510
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
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さん - 発表アーカイブ動画 - 勇者さま一行のイラストは いらすとや様からお借りしました