実装ファイルの tree-shaking 誤削除を修正 + tags.json スキーマ自動移行#36
Merged
Conversation
ファイルごとの「実装先の型名」一覧を tags.json に持てるようにする (#21 の器)。旧 v1 は library update を促すエラーで弾く。 この時点では登録側は常に空を書き込む。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
クラス外の修飾付き定義 (X<...>::method) の修飾側と、明示的特殊化 (template <> struct T<...>) の主テンプレート名を「実装先の型名」として 登録時に記録し、tags.json の implements に保存する (#21)。 演算子オーバーロードだけの実装ファイルでも実装先が残るのが要点。 show -v に Implements 表示を追加。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
必要ファイルが定義する型を実装先に持つファイル (演算子オーバーロード等、 識別子に現れない依存) を implements の逆引きで必要集合へ加え、 増えなくなるまで -M の必要集合と交互に更新する (#21)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
Issue 番号や時系列 (「従来通り」等) に依存するコメントを、コードだけで 理解できる現在形の記述へ書き換える。inventory のモジュールコメントに 実装ファイル逆引きの問い合わせを追記。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
宣言と演算子実装が分かれたライブラリの縮小再現。実装消失は undefined reference としてリンクで顕在化するため、リンク・実行まで 通して検証する。修正前のコードで FAILED になることを確認済み。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
📝 WalkthroughWalkthroughAdds implementation-target type-name tracking ( ChangesImplements tracking, tree-shaking, and schema migration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Bundle as commands::bundle::run
participant Migrate as cmd_library::auto_migrate
participant Inventory as bundle::inventory
participant Tags as library::tags::Tags
Bundle->>Migrate: auto_migrate(&store)
Migrate->>Tags: Tags::load(each library)
Tags-->>Migrate: Ok or SchemaMismatch
Migrate->>Migrate: reregister mismatched libraries
Bundle->>Inventory: dependency_headers(used)
Inventory-->>Bundle: dependency_headers set
loop until stable
Bundle->>Inventory: implementation_files(needed, present)
Inventory->>Inventory: compute needed type names from defines
Inventory->>Inventory: filter present files by implements
Inventory-->>Bundle: implementation headers
Bundle->>Bundle: expand dependency_headers
end
Bundle->>Bundle: render bundle with needed headers
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
update は登録内容を丸ごと作り直すため、tags.json からは登録パス (std ならコンパイラ集合) しか使わない。これらは全スキーマバージョンに 存在するので、スキーマ検証をせずに読み出す MigrationSource を導入し、 「スキーマ不一致は update で再生成」というエラー案内が実際に機能する ようにする。旧実装では update 自体が同じエラーで倒れ、案内が詰みに なっていた。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
add-std は登録を作り直すため、既存 std の tags.json からは認識コンパイラ 集合しか使わない。update と同様に MigrationSource で検証せずに読み、 スキーマの合わない登録があっても集合を引き継いで再登録できるようにする。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
schema_version 不一致を anyhow の文字列エラーから SchemaMismatch 型へ 変更し、呼び出し側が downcast で判別できるようにする。tags.json は ライブラリ実体から再生成できるキャッシュなので、この判別を足がかりに 各コマンドが自動移行や寛容表示で回復できるようにするための土台。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
tags.json はライブラリ実体から再生成できるキャッシュであり、スキーマ 形式の変化は risundle 側の都合なので、バンドル前に schema_version が 現行と合わない登録をライブラリ実体から黙って作り直す (std の初回自動 登録と同じ発想)。ユーザーに update を要求せず、アップグレード後の初回 バンドルだけ数秒伸びる形にする。 update_one から再登録の中核を reregister として切り出し、auto_migrate と 共有する。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
list と show は読み取りコマンドなので、スキーマ不一致でもエラーにせず、 状態も書き換えない (バンドル時の自動移行に任せる)。list は全バージョン 共通の ID・種別・パスだけを MigrationSource から読む。show は詳細を 読める場合はそのまま出し、読めない場合は基本情報と update 案内を出す。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
schema_version 不一致時の各コマンドの挙動 (バンドル時の自動移行、 update/add-std の回復、list/show の寛容読み) を tags.json 節に追記。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
- MigrationSource の doc を実際の利用箇所 (update/add-std/自動移行/list/show) に合わせて更新 (旧: library update のみと記載) - auto_migrate の分岐を「現行/旧スキーマ/破損」の 3 分岐へ整理しコメント付与 - auto_migrate が schema 不一致以外のエラーを伝播することのテストを追加 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
スキーマ耐性の方針 (移行/救出再登録/寛容読み) が各コマンドに散っていた 問題に対し、共通の土台概念を明確にする。MigrationSource を 「スキーマ非依存の登録の中核」を表す Registration へ改名し、種別判定 (compilers の有無) を Registration::kind_label に一元化。commands 側で 重複していた kind_label 自由関数を廃止する。動作は不変。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
tags_entry が (files, implements, key) の 3-tuple を返し
#[allow(clippy::type_complexity)] を要していた点を、per-file の
FileTags { defines, implements } を返す file_tags に置き換える。
定義/実装先を持たないファイルは空スライスになり (従来の None と同義)、
defined_identifiers/implement_targets の 2 ヘルパを畳んで呼び出しを直截にする。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
…tion コードから読み取りにくい設計判断 (なぜ) を 2 節追記: - 実装ファイルを「実装先の型名」で引く理由と、素朴な代替案を退けた経緯 - tags.json のスキーマ変化を黙って吸収する非対称の原則 (ユーザーの内容変更は確認、risundle の形式変更は自動移行) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
テスト名やモジュール doc・直後の assert から自明な説明コメントを削除する (実装コードの rationale コメントは維持)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
実在しない AC Library もどきのファイル構成 (atcoder/modint_impl.hpp 等。 ACL はヘッダーオンリーで implements が生じない) を、宣言と実装が分かれた 架空の行列ライブラリに差し替え、implements が発生する構造を正しく示す。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwiopnwyFnRbSUyNoFLWAZ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21
概要
宣言と実装が別ファイルに分かれたライブラリで、演算子オーバーロード等が tree-shaking で誤って消えるバグ (#21) を修正します。あわせて必要になった tags.json のスキーマ更新 (v1 → v2) を、ユーザー操作なしで吸収する仕組みを入れます。
背景 (#21)
現行の依存検出は「ユーザーコードに現れる識別子」を手がかりに逆引きします。しかし
f * gのような演算子の使用は識別子として現れないため、operator*=の実装だけを置いたファイルが「未使用」と誤判定されて消え、バンドル後に undefined reference になります (Nyaan's Library の FPS で発生)。この症状は宣言がクラス本体側に残るためコンパイルは通り、リンク時にしか顕在化しません。変更内容
#21: 実装ファイルの保持
X<...>::method) の型名や明示的特殊化の主テンプレート名を「実装先の型名」として tags.json に記録する (implementsフィールド、schema v2)。スキーマ更新の自動吸収
tags.json はライブラリ実体から再生成できるキャッシュなので、スキーマ不一致は risundle 側の都合と捉え、ユーザー操作を要求しません。
bundle: 不一致の登録をライブラリ実体から自動で作り直してから続行。update/add-std: スキーマ非依存の中核 (Registration) だけを読み、旧スキーマからでも回復。list/show: 読み取りに徹し、エラーにも移行にもせず読める情報だけ表示。原則は「ユーザーの内容変更 (ハッシュ不一致) は確認させ、risundle の形式変更 (スキーマ不一致) は黙って直す」という非対称です。
設計・ドキュメント
Registration型を導入し、種別判定を一元化。Inventoryの逆引きをFileTagsレコードに整理。テスト
補足
commands/library.rsに同居している既存の層の課題は、本 PR 以前からあるもので、別途 ライブラリ登録の処理を、あるべき層へ整理する #40 で対応します。Summary by CodeRabbit
New Features
Bug Fixes
Documentation