Unify condition lowering logic across Pattern 2/4 with trait-based API. New infrastructure: - condition_lowering_box.rs: ConditionLoweringBox trait + ConditionContext (293 lines) - ExprLowerer implements ConditionLoweringBox trait (+51 lines) Pattern migrations: - Pattern 2 (loop_with_break_minimal.rs): Use trait API - Pattern 4 (loop_with_continue_minimal.rs): Use trait API Benefits: - Unified condition lowering interface - Extensible for future lowering strategies - Clean API boundary between patterns and lowering logic - Zero code duplication Test results: 911/911 PASS (+2 new tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
3.2 KiB
3.2 KiB
Phase 233: loop_update_summary テスト刷新
目的: deprecated な analyze_loop_updates() 依存の期待値を捨てて、Phase 219 で本番化した analyze_loop_updates_from_ast() に合わせてユニットテストを組み直すよ。ロジック本体は既に AST ベースで動いているので、テスト側の追随だけを行うフェーズだよ。
1. 旧 API (analyze_loop_updates) の前提
- 入力: carrier 名リストだけ(RHS や AST 構造を見ない)。
- ヒューリスティック: すべて AccumulationLike 扱い(名前ベースの Counter 推定は撤廃済み)。
- テストで見ていたもの:
test_analyze_single_counter/test_analyze_mixed: 名前だけで Counter/Accumulation を判断する期待。test_is_simple_if_sum_pattern_*: deprecated wrapper で組んだ summary をそのままis_simple_if_sum_patternに渡していた。
- 問題: 本番 if-sum ラインは AST ベースに移行済みのため、これらのテストは現実の入力と乖離して FAIL していた。
2. 新 API (analyze_loop_updates_from_ast) の前提
- 入力: carrier 名リスト + ループ body の AST。
- 処理:
extract_assigned_variablesで実際に LHS に現れた変数だけを対象にする。find_assignment_rhsで RHS を拾い、classify_update_kind_from_rhsで CounterLike / AccumulationLike を決定。- ループインデックスっぽい名前(i/j/k/idx/index/pos/n)だけは Counter 扱いに固定。
- 実運用:
- PatternPipelineContext から if-sum 判定に使われる唯一の経路。
- Phantom carrier 解消(Phase 219)の一環として既に配線済み。
3. テストケースの扱い(棚卸し結果)
test_analyze_single_counter→ AST ベースに組み直す- ループ body に
i = i + 1を置き、has_single_counter()が真になることだけを確認。
- ループ body に
test_analyze_accumulation→ AST ベースに置き換えsum = sum + iのような RHS を与え、非 index 名が AccumulationLike になることを確認。
test_analyze_mixed→ Counter + Accumulation の AST で再構成i = i + 1とsum = sum + iの 2 本で、counter=1 / accumulation=1 を確認。
test_is_simple_if_sum_pattern_basic→ if-body に accumulator 更新を置いた AST で検証if (cond) { sum = sum + i }+i = i + 1の組み合わせで true を確認。
test_is_simple_if_sum_pattern_with_count→ accumulator 2 本の AST で検証sum/count両方が AccumulationLike になり、2 本まで許容する条件を確認。
- 旧 wrapper への期待は残さず、どうしても残す場合は
#[ignore]で歴史テストにする方針。
4. 期待する着地
- ユニットテストは
analyze_loop_updates_from_ast()を直接呼ぶ形に揃える。 is_simple_if_sum_patternは AST 由来の summary を入力として検証するだけにする(パターン検出ロジック本体の契約をテスト)。- Phase 232 時点の FAIL(4 件)は、テスト刷新で 0 件にする。***
Status: Active
Scope: ループ更新サマリ / テストリフレッシュ(JoinIR/ExprLowerer ライン)