Files
hakorune/CURRENT_TASK.md

249 lines
20 KiB
Markdown
Raw Normal View History

feat(hako_check): Phase 153 - Dead code detection revival (JoinIR version) Implement comprehensive dead code detection for hako_check with JoinIR integration, following Phase 133/134/152 box-based modularity pattern. ## Key Achievements 1. **Comprehensive Inventory** (`phase153_hako_check_inventory.md`): - Documented current hako_check architecture (872 lines) - Analyzed existing HC011/HC012 rules - Confirmed JoinIR-only pipeline (Phase 124) - Identified Phase 153 opportunities 2. **DeadCodeAnalyzerBox** (`rule_dead_code.hako`): - Unified HC019 rule (570+ lines) - Method-level + box-level dead code detection - DFS reachability from entrypoints - Text-based analysis (no MIR JSON dependency for MVP) - Heuristic-based false positive reduction 3. **CLI Integration** (`cli.hako`): - Added `--dead-code` flag for comprehensive mode - Added `--rules dead_code` for selective execution - Compatible with --format (text/json-lsp/dot) 4. **Test Infrastructure**: - HC019_dead_code test directory (ng/ok/expected.json) - `hako_check_deadcode_smoke.sh` with 4 test cases ## Technical Details - **Input**: Analysis IR (MapBox with methods/calls/boxes/entrypoints) - **Output**: HC019 diagnostics - **Algorithm**: Graph-based DFS reachability - **Pattern**: Box-based modular architecture - **No ENV vars**: CLI flags only ## Files Modified - NEW: docs/development/current/main/phase153_hako_check_inventory.md - NEW: tools/hako_check/rules/rule_dead_code.hako - MOD: tools/hako_check/cli.hako - NEW: tools/hako_check/tests/HC019_dead_code/ - NEW: tools/hako_check_deadcode_smoke.sh - MOD: CURRENT_TASK.md ## Next Steps - Phase 154+: MIR CFG integration for block-level detection - Phase 160+: Integration with .hako JoinIR/MIR migration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 14:19:48 +09:00
# Current Task
このファイルは「いま何に集中しているか」と「次にやる候補」だけを書く軽量ビューに戻すよ。
過去フェーズの詳細ログは `docs/development/current/main/10-Now.md` と各 `phase-XX*.md` に残してあるので、履歴はそちらを見てね。
---
## 🎯 今フォーカスしているテーマ
### 1. JoinIR ループ基盤 → JsonParser / Trim への適用
- 現状
- LoopBuilder は完全削除済み。ループは JoinIR Pattern14while / break / ifPHI / continueで統一。
- LoopExit / ExitLine / Boundary / Header PHI のラインは代表ケースPattern14で安定。
- LoopConditionScopeBoxPhase 170Dはバグ修正済みで、
- ループ条件に出てくる変数を `LoopParam / OuterLocal / LoopBodyLocal` に分類
- 関数パラメータや外側ローカル(例: `s`, `pos`, `len`)は正しく OuterLocal と判定できるようになった。
- 直近の目的
- JsonParserBox / Trim 系ループを、Pattern14 + LoopConditionScopeBox の上にどこまで安全に載せられるかを再観測する。
- LoopBodyLocal を条件に含むパターンTrim の `ch` などを、Pattern5 でどう扱うか設計する。
- 次にやる候補
- [x] Phase 171A: LoopConditionScope 修正版で JsonParser / Trim ループの再インベントリ ✅
→ どのループが Pattern14 内に入り、どれが LoopBodyLocal 条件で弾かれているかを整理。
- [x] Phase 171B: Pattern5A のターゲット決定 ✅
→ Trim の leading whitespace ループを代表として選定。
- [x] Phase 171C-1: LoopBodyCarrierPromoter スケルトン実装 ✅
→ API 定義PromotionRequest → PromotionResult、基本検出ロジック。
- [x] Phase 171C-2: Trim パターン昇格ロジック実装 ✅
`find_definition_in_body()`, `is_substring_method_call()`, `extract_equality_literals()` 実装。
`TrimPatternInfo` で検出結果を返す。10 unit tests。
- [x] Phase 171C-3: Pattern 2/4 ルーティングとの統合 ✅
→ routing.rs で LoopBodyCarrierPromoter を呼び出し、昇格可能なら Pattern2 へルート。
- [x] Phase 171C-4: CarrierInfo への統合 ✅ (2025-12-07)
`CarrierInfo::merge_from()` で昇格後のキャリアをマージ。
`TrimPatternInfo::to_carrier_info()` で変換ヘルパ実装。
→ Pattern2/4 lowerer で `Promoted` ブランチをマージに更新。7 unit tests。
- [x] Phase 171C-5: TrimLoopHelper 設計 ✅ (2025-12-07)
`TrimLoopHelper` struct で Trim 専用ロジックを一箇所に集約。
`CarrierInfo::trim_helper()` アクセサ追加。4 unit tests。
- [x] Phase 171impl-Trim: Trim 用 JoinIR 生成 ✅ (2025-12-08)
`CarrierInfo::trim_helper()` を使って bool carrier の初期化・更新・exit PHI を生成。
- [x] Phase 172-Trim-impl: Trim 用 MIR 生成 ✅ (2025-12-08)
→ Pattern2 で Trim パターンの JoinIR→MIR lowering 実装完了。
→ emit_whitespace_check(), extract_substring_args() ヘルパ追加。
feat(joinir): Phase 173 - JsonParser P5 expansion with _skip_whitespace - Task 173-1: JsonParser loop inventory recheck - Observed 6 loops: _trim (2 loops, already working), _skip_whitespace, _parse_string, _parse_array, _unescape_string - Created comprehensive observation report with Trim similarity ratings - Discovered that JsonParser._trim already uses P5 pipeline successfully - Task 173-2: Selected _skip_whitespace as Trim-equivalent pattern - Perfect structural match with Trim (100% identical) - Independent helper method, easy to test - Frequently used in JsonParser (7 call sites) - Task 173-3: Design doc for P5 pipeline extension to JsonParser - Confirmed existing TrimLoopHelper works without modification - No charAt() support needed (_skip_whitespace uses substring()) - Documented data flow and risk analysis - Task 173-4: Successfully converted _skip_whitespace to JoinIR - Created test case: local_tests/test_jsonparser_skip_whitespace.hako - Added routing whitelist: JsonParserTest._skip_whitespace/3 - Pattern detection SUCCESS: * LoopBodyLocal 'ch' detected * Carrier promotion to 'is_ch_match' * Trim pattern recognized * JoinIR generation successful - Verified P5 pipeline works for both static box methods and helper methods - Task 173-5: Documentation updates - phase173-jsonparser-loop-recheck.md: Loop observation report - phase173-jsonparser-p5-design.md: P5 extension design - phase173-jsonparser-p5-impl.md: Implementation results - CURRENT_TASK.md: Phase 173 completion record Key achievement: Proven that Trim P5 pipeline is fully generic - works for both TrimTest (static box method) and JsonParser (helper method). LoopBodyLocal carrier promotion is production-ready for Trim-like patterns. Changes: - src/mir/builder/control_flow/joinir/routing.rs: Add JsonParserTest whitelist - docs/development/current/main/*173*.md: 3 new documentation files - CURRENT_TASK.md: Phase 173 completion entry
2025-12-08 10:13:34 +09:00
- [x] Phase 173: JsonParser P5 展開 ✅ (2025-12-08)
→ Task 173-1: JsonParser 代表ループの再チェック_skip_whitespace 選定)。
→ Task 173-2: 「Trim と同型」なループを 1 本選定_skip_whitespace 確定)。
→ Task 173-3: Trim 用 P5 パイプラインを JsonParser 用にも開放する設計(設計ドキュメント作成)。
→ Task 173-4: 1 本だけ実際に JoinIR で通す_skip_whitespace Pattern detection 成功)。
→ Task 173-5: ドキュメント更新phase173-jsonparser-p5-impl.md + CURRENT_TASK
**成果**: Trim パイプラインが JsonParser でも機能することを実証、P5 の汎用性が完全証明された。
- [x] Phase 200: JoinIR パイプライン Cleanup (Part 1) ✅ (2025-12-08)
→ Task 200-1: Pattern × Box マトリクス表をドキュメント化loop_pattern_space.md に追加)。
→ Task 200-2: JoinInlineBoundaryBuilder 導入Pattern2 で試験導入、Builder パターンで構築統一化)。
→ Task 200-3: JoinIRVerifier 追加LoopHeader PHI / ExitLine 契約のデバッグ検証)。
→ Task 200-4: CURRENT_TASK/overview 微修正Phase 200 内容を反映)。
- [x] Phase 201: JoinInlineBoundaryBuilder Pattern3/4 展開 ✅ (2025-12-08)
→ Task 201-1: Pattern2 の Builder 使用パターンを正として固める(設計ドキュメント作成)。
→ Task 201-2: Pattern3 を Builder に載せ替え(フィールド直書き排除)。
→ Task 201-3: Pattern4 を Builder に載せ替えcontinue/Trim 特例対応)。
→ Task 201-4: 共通ルールチェック & unit test 拡張2つの新テスト追加
→ Task 201-5: ドキュメント更新overview + CURRENT_TASK
**成果**: 全パターンP1/P2/P3/P4で Builder 統一完了、フィールド直書き完全排除、挙動不変(テスト全 PASS
feat(joinir): Phase 174 - JsonParser complex loop P5 extension design - Task 174-1: Complex loop inventory (_parse_string/_parse_array/_parse_object) - Analyzed remaining JsonParser loops for P5 expansion potential - Identified _parse_string as most Trim-like structure (99% similarity) - Documented complexity scores and minimization potential - Task 174-2: Selected _parse_string as next P5 target (closest to Trim) - Reason: LoopBodyLocal 'ch' usage matches Trim pattern exactly - Structure: loop(pos < len) + substring + char comparison + break - Minimization: Remove escape/buffer/continue → identical to Trim - Task 174-3: Design doc for P5B extension (TrimLoopHelper reuse strategy) - File: docs/development/current/main/phase174-jsonparser-p5b-design.md - Strategy: Reuse existing TrimLoopHelper without modifications - Proven: Pattern applies to any character comparison, not just whitespace - Task 174-4: Minimal PoC (_parse_string without escape) successful - Test: local_tests/test_jsonparser_parse_string_min.hako - Result: [pattern2/trim] Safe Trim pattern detected ✅ - Detection: Trim with literals=['"'] (quote instead of whitespace) - Routing: Added whitelist entries for JsonParserStringTest methods - Task 174-5: Documentation updates - Updated CURRENT_TASK.md with Phase 174 summary - Updated joinir-architecture-overview.md with P5 generality proof - Created phase174-jsonparser-loop-inventory-2.md (detailed analysis) - Created phase174-jsonparser-p5b-design.md (implementation strategy) Success Criteria Met: ✅ _parse_string minimized version runs on P5 pipeline ✅ TrimLoopHelper works with '"' (non-whitespace character) ✅ Proven: Trim pattern is character-comparison-generic, not whitespace-specific ✅ Two new design docs (inventory + design) ✅ Phase 175+ roadmap established (multi-carrier, escape sequences) Technical Achievement: The P5 Trim pipeline successfully handled a quote-detection loop with zero code changes, proving the architecture's generality beyond whitespace trimming.
2025-12-08 13:08:44 +09:00
- [x] Phase 174: JsonParser 複雑ループ P5 拡張設計1本め ✅ (2025-12-08)
→ Task 174-1: 残り JsonParser ループの再チェック_parse_string/_parse_array/_parse_object 分析)。
→ Task 174-2: 「次に攻める1本」を決定_parse_string 選定、Trim に最も近い構造)。
→ Task 174-3: 箱の再利用 vs 追加を決定TrimLoopHelper 再利用可能、最小化版で検証)。
→ Task 174-4: 小さな PoC を 1 本動かす_parse_string 最小化版で P5 パイプライン成功)。
→ Task 174-5: ドキュメント更新phase174-jsonparser-p5b-design.md + CURRENT_TASK
**成果**: Trim P5 パイプラインが `_parse_string` 最小化版でも機能することを実証。
文字比較対象が `"\""`(終端クォート)でも Trim と同じ昇格パターンで動作確認。
feat(joinir): Phase 175 - P5 multi-carrier architecture validation Task 175-1: Analyzed _parse_string carrier candidates - Identified 3 carriers: pos (position), result (buffer), is_ch_match (promoted) - Categorized as: required carriers (pos, result), promoted carrier (is_ch_match) Task 175-2: Validated existing boxes support multi-carrier - CarrierInfo: Vec<CarrierData> supports arbitrary carriers ✅ - LoopUpdateAnalyzer: Loops over all carriers ✅ - ExitMeta: Vec<(String, ValueId)> supports all exit bindings ✅ - ExitLineReconnector: Reconnects all carriers to variable_map ✅ - No code changes needed - architecture already supports it! Task 175-3: PoC test revealed Pattern2 limitation - Test: test_jsonparser_parse_string_min2.hako (pos + result carriers) - CarrierInfo detected 3 carriers correctly (pos, result, is_ch_match) - variable_map contains all carriers at pattern2_start - BUT: Pattern2's Trim optimization only emits pos carrier in MIR - MIR shows result stays as empty string (no loop update emitted) - Root cause: Trim pattern focuses on position-only optimization Task 175-4: Documentation updates - Created: phase175-multicarrier-design.md (comprehensive analysis) - Updated: CURRENT_TASK.md (Phase 175 completion) - Updated: routing.rs (added JsonParserStringTest2 whitelist) Key Finding: - Architecture is sound ✅ - all boxes support multi-carrier - Pattern2 implementation gap ❌ - Trim optimization ignores non-position carriers - Phase 176 scope: Extend Pattern2 to emit all carrier updates Next: Phase 176 for escape sequence handling and full multi-carrier emission
2025-12-08 13:34:43 +09:00
- [x] Phase 175: P5 複数キャリア対応_parse_string 向け) ✅ (2025-12-08)
→ Task 175-1: _parse_string のキャリア候補を洗い出すpos, result, is_ch_match の 3 キャリア特定)。
→ Task 175-2: CarrierInfo / ExitMeta に複数キャリアを載せる設計を固める(既存箱がすべて複数対応済みと確認)。
→ Task 175-3: 小さい PoC で 2 キャリアだけ通してみるMIR 検証で Pattern2 の制約を特定)。
→ Task 175-4: CURRENT_TASK / joinir-architecture-overview 更新。
**成果**: P5 アーキテクチャが複数キャリアに対応済みであることを確認。
CarrierInfo は 3 キャリア検出済みpos, result, is_ch_match
Pattern2 実装が Trim 最適化により `pos` のみ emit する制約を発見Phase 176 改善対象)。
feat(joinir): Phase 176 Pattern2 multi-carrier lowering complete Task 176-1: Pattern2 limitation investigation - Identified 10 limitation points where only position carrier was handled - Added TODO markers for Phase 176-2/3 implementation - Created phase176-pattern2-limitations.md documentation Task 176-2: CarrierUpdateLowerer helper implementation - Implemented emit_carrier_update() helper function - Supports CounterLike and AccumulationLike UpdateExpr patterns - Added 6 unit tests (all passing) - Fail-Fast error handling for carrier/variable not found Task 176-3: Pattern2 lowerer multi-carrier extension - Extended header PHI generation for all carriers - Implemented loop update for all carriers using emit_carrier_update() - Extended ExitLine/ExitMeta construction for all carriers - Updated function call/jump args to include all carriers - 9/10 tests passing (1 pre-existing test issue) Task 176-4: E2E testing and bug fixes - Fixed Trim pattern loop_var_name overwrite bug (pattern2_with_break.rs) - Fixed InstructionRewriter latch_incoming mapping bug - All E2E tests passing (RC=0): pos + result dual-carrier loops work - test_jsonparser_parse_string_min2.hako verified Task 176-5: Documentation updates - Created phase176-completion-report.md - Updated phase175-multicarrier-design.md with completion status - Updated joinir-architecture-overview.md roadmap - Updated CURRENT_TASK.md with Phase 176 completion + Phase 177 TODO - Updated loop_pattern_space.md F-axis (multi-carrier support complete) Technical achievements: - Pattern2 now handles single/multiple carriers uniformly - CarrierInfo architecture proven to work end-to-end - Two critical bugs fixed (loop_var overwrite, latch_incoming mapping) - No regressions in existing tests Next: Phase 177 - Apply to JsonParser _parse_string full implementation
2025-12-08 15:17:53 +09:00
- [x] Phase 176: Pattern2 multi-carrier lowering ✅ (2025-12-08)
→ Task 176-1: 制限ポイント特定10箇所の TODO マーク)
→ Task 176-2: CarrierUpdateLowerer ヘルパ実装6 unit tests
→ Task 176-3: ヘッダ PHI / ループ更新 / ExitLine を全キャリア対応に拡張
→ Task 176-4: E2E テスト成功2キャリア: pos + result
→ Task 176-5: ドキュメント更新
**成果**: Pattern2 が複数キャリアに完全対応。CarrierInfo に載っている全キャリアの UpdateExpr を MIR に emit。
**バグ修正**: Trim pattern の loop_var_name 上書き問題、InstructionRewriter の latch_incoming 設定問題。
- 今後 1〜2 フェーズの TODOJoinIR 周りのサマリ)
- [x] **Phase 177: Multi-carrier PHI 接続修正** ✅ (2025-12-08)
- Task 177-STRUCT-1: CarrierVar に join_id 追加
- Task 177-STRUCT-2: carrier_order で順序保持LoopHeaderPhiInfo
- **成果**: Int テスト成功sum=3、index mismatch 問題解決
- [x] **Phase 178: LoopUpdateAnalyzer string 検出** ✅ (2025-12-08)
- Task 178-1: UpdateRhs 拡張StringLiteral, Other 追加)
- Task 178-2: analyze_rhs 分岐拡張string/method call 検出)
- Task 178-3: Pattern2/4 can_lower で string 拒否Fail-Fast
- Task 178-4: Legacy fallback コメント修正LoopBuilder 削除済み反映)
- **成果**: String loop は明示的エラー、numeric loop は正常動作維持
- **注意**: グローバルテスト 79 件失敗は Phase 178 以前からの既知問題(別途対応)
- [x] **Phase 180: Trim/P5 サブモジュール化** ✅ (2025-12-08)
- Task 180-1: 設計ドキュメント作成phase180-trim-module-design.md
- Task 180-2: TrimLoopLowerer スケルトン実装try_lower_trim_like_loop 骨格)
- Task 180-3: Pattern2 リファクタリング(~160 行の Trim ロジックを TrimLoopLowerer に委譲)
- Task 180-4: Pattern4 分析Trim 検出のみで lowering なし、スキップ)
- Task 180-5: ドキュメント更新joinir-architecture-overview.md + CURRENT_TASK.md
- **成果**: Pattern2 から Trim 専用ロジックを完全分離、-135 行の削減
- **TrimLoopLowerer**: LoopConditionScopeBox + LoopBodyCarrierPromoter 統合
- **再利用性向上**: Pattern2/4/未来パターンすべてで同じ Trim lowering を利用可能
- **テスト**: cargo build --release SUCCESS (0 errors, warnings のみ)
- [x] **Phase 181: JsonParser ループ空間の再インベントリ** ✅ (2025-12-08)
- Task 181-1: JsonParserBox 内の全 11 ループを LoopPatternSpace の軸A〜Fで分類
- Task 181-2: 各ループの Pattern14 + P5 へのマッピング_parse_number/_atoi/_match_literal 等は P2/P1 で対応可能)
- Task 181-3: `_skip_whitespace` / `_trim*` / `_parse_string` 最小版 など、既に JoinIR/P5 経路で動作しているケースを確認
- Task 181-4: 残りループの優先度と難易度を整理_parse_array/_parse_object/_unescape_string は後続 Phase で対応)
- **成果**: JsonParser の全ループが「形としては P1P4(+P5) で表現可能」であることを確認。
ループ形の追加は不要で、複雑さは BoolExprLowerer / ContinueBranchNormalizer / TrimLoopLowerer 側で吸収する方針を確定。
- [x] **Phase 179-B: Generic Pattern Framework** ✅ (2025-12-08)
- Task 179-B-1: 設計ドキュメント作成phase179-generic-pattern-framework.md
- Task 179-B-2: PatternPipelineContext 実装pattern_pipeline.rs
- Task 179-B-3: Pattern 1 統一168→149行, 11%削減)
- Task 179-B-4: Pattern 3 統一168→149行, 11%削減)
- Task 179-B-5: Pattern 2 統一517→509行, 1.5%削減)
- Task 179-B-6: Pattern 4 統一422→414行, 1.9%削減)
- Task 179-B-7: テスト・ドキュメント更新(全代表ケース PASS
- **成果**: 全パターンP1/P2/P3/P4で PatternPipelineContext 統一、
前処理ロジック一本化、挙動不変(テスト全 PASS
- **設計原則**: Pure analysis container解析のみ、emission なし)、
Analyzer-only dependencies、Pattern-specific variantsOption<T>)。
- **注意**: Pattern 2/4 の複雑ロジックTrim, carrier 解析)は inline 維持。
将来 Phase 180+ で Trim module 化予定。
- [x] **Phase 181: JsonParser 残りループ設計調査** ✅ (2025-12-08)
- Task 181-1: 全11ループの再チェックPattern × Box マトリクス作成)
- Task 181-2: ブロック分析LoopConditionScopeBox 制約との照合)
- Task 181-3: ロードマップ作成phase181-jsonparser-loop-roadmap.md
- **成果**: 全ループが「LoopParam/OuterLocal のみ」という制約を満たし、理論的に全対応可能
- **発見**: ブロックされるループは存在しないTrim は昇格パターンで対応済み)
- **優先度**: P2 Break3個: _parse_number/_atoi/_atof_loop> P1 Simple1個: _match_literal> P4 Continue3個: _parse_array/_parse_object/_unescape_string
- [x] **Phase 182: JsonParser P1/P2 パターン検証** ✅ (2025-12-08)
- Task 182-1: 設計ドキュメント作成phase182-simple-loops-design.md
- Task 182-2: Routing whitelist 更新_parse_number/2, _atoi/1, _match_literal/3 追加)
- Task 182-3: Pattern routing 確認NYASH_JOINIR_STRUCTURE_ONLY=1 tracing
- Task 182-5: 代表テスト作成・実行
- ✅ Pattern1: phase182_p1_match_literal.hako PASS
- ✅ Pattern2: phase182_p2_break_integer.hako PASS
- Task 182-6: ドキュメント更新joinir-architecture-overview.md, CURRENT_TASK.md
- **成果**: P1/P2 パターンの基本動作確認完了整数演算・early return で動作実証)
- **ブロッカー発見**:
1. LoopBodyLocal 変数処理(`ch`, `digit_pos`, `pos`
- 現状: Trim 専用の carrier 昇格を試みてエラー
- 必要: P1/P2 で純粋なローカル変数(昇格不要)として扱う仕組み
2. 文字列連結フィルタPhase 178
- 現状: `num_str = num_str + ch` を保守的に reject
- 必要: JsonParser 向けに段階的有効化
- **次ステップ**: Phase 183 で LoopBodyLocal 処理と string ops 対応
feat(joinir): Phase 183 LoopBodyLocal role separation Implements role-based separation of LoopBodyLocal variables to prevent inappropriate Trim promotion for body-only local variables. ## Changes ### Task 183-1: Design Documentation - Created `phase183-loopbodylocal-role-separation.md` with role taxonomy: - Condition LoopBodyLocal: Used in loop conditions → Trim promotion target - Body-only LoopBodyLocal: Only in body → No promotion needed - Documented architectural approach and implementation strategy ### Task 183-2: Implementation - Added `TrimLoopLowerer::is_var_used_in_condition()` helper - Recursively checks if variable appears in condition AST - Handles BinaryOp, UnaryOp, MethodCall node types - Updated `try_lower_trim_like_loop()` to filter condition LoopBodyLocal - Only processes LoopBodyLocal that appear in break conditions - Skips body-only LoopBodyLocal (returns Ok(None) early) - Added 5 unit tests for variable detection logic ### Task 183-3: Test Files - Created `phase183_body_only_loopbodylocal.hako` - Demonstrates body-only LoopBodyLocal (`temp`) not triggering Trim - Verified trace output: "No LoopBodyLocal detected, skipping Trim lowering" - Created additional test files (phase183_p1_match_literal, phase183_p2_atoi, phase183_p2_parse_number) ### Task 183-4: Documentation Updates - Updated `joinir-architecture-overview.md` with Phase 183 results - Updated `CURRENT_TASK.md` with Phase 183 completion status ## Results ✅ LoopBodyLocal role separation complete ✅ Body-only LoopBodyLocal skips Trim promotion ✅ 5 unit tests passing ✅ Trace verification successful ## Next Steps (Phase 184+) - Body-local variable MIR lowering support - String concatenation filter relaxation - Full _parse_number/_atoi implementation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-08 23:14:10 +09:00
- [x] **Phase 183: LoopBodyLocal 役割分離** ✅ (2025-12-08)
- Task 183-1: 設計メモ作成phase183-loopbodylocal-role-separation.md
- LoopBodyLocal を 2 カテゴリに分類設計Condition vs Body-only
- Trim promotion は条件に出てくる変数のみ対象
- body-only local は昇格スキップ
- Task 183-2: LoopBodyLocal 役割分離実装
- TrimLoopLowerer に `is_var_used_in_condition()` ヘルパー追加
- 条件で使われていない LoopBodyLocal を Trim 昇格対象から除外
- 5 unit testsvariable detection, binary op, method call, nested
- Task 183-3: 代表ループテスト作成
- `phase183_body_only_loopbodylocal.hako`: body-only LoopBodyLocal デモ
- トレース確認: `[TrimLoopLowerer] No LoopBodyLocal detected, skipping Trim lowering`
- Task 183-4: ドキュメント更新joinir-architecture-overview.md, CURRENT_TASK.md
- **成果**: LoopBodyLocal 役割分離完了、body-only 変数は Trim promotion されない
- **残課題**: body-local 変数の MIR lowering 対応Phase 184+ で対応予定)
- **発見**: Pattern1 実行問題別途対応必要、Phase 183 スコープ外)
- [ ] Phase 184+: Body-local 変数 MIR lowering + String ops 有効化
- body-local 変数(`local temp` in loop bodyの MIR 生成対応
- String concat フィルタの段階的緩和
- _parse_number, _atoi 完全実装
- [ ] Phase 183+: JsonParser 中級パターン実装
- _parse_array, _parse_object P4 Continue, MethodCall 複数対応)
- _parse_string 完全版 P2/P4, string concat + escape
- [ ] Phase 184+: JsonParser 高級パターン実装
- _unescape_string P4 Continue, 複雑キャリア + flatten
feat(phase131): LLVM backend re-enable & PHI ordering bug discovery Phase 131: JoinIR → LLVM individual fixes (minimal scope) ## Modifications ### 1. LLVM Backend Re-enable ✅ - Built with --features llvm to enable real LLVM execution - Verified Python/llvmlite environment (llvmlite 0.45.1) - Fixed llvmlite deprecated API: removed llvm.initialize() call - Successfully moved from Mock backend to real LLVM harness execution ### 2. PHI Instruction Ordering Bug Discovery ⚠️ - Discovered critical bug: PHI nodes placed AFTER terminator instructions - LLVM IR constraint: PHI must be at block start, before any non-PHI - Root cause: finalize_phis() in llvm_builder.py emits PHIs after block termination - Affects all 6 tests with control flow merges ### 3. ConsoleBox LLVM Integration ⚠️ - Confirmed ConsoleBox not registered in Rust VM environment - Deferred to Phase 132 (prerequisite issue) ## Results Modified files: - src/llvm_py/llvm_builder.py: Removed deprecated llvm.initialize() - docs/development/current/main/phase130_joinir_llvm_baseline.md: Added Phase 131 results - CURRENT_TASK.md: Added Phase 131 completion report Test results: - ✅ peek_expr_block.hako: LLVM execution success (Result: 1) - ❌ 6/7 tests: PHI ordering bug (requires Phase 132 refactoring) ## Success Criteria - ✅ LLVM backend minimal re-enable (1/7 test passing) - ⚠️ PHI ordering bug discovered and documented - ⚠️ ConsoleBox integration deferred to Phase 132 ## Phase 132 Handoff Priority 1: Fix PHI instruction ordering bug (finalize_phis() refactoring) Priority 2: Resolve ConsoleBox registration issue Priority 3: Enable remaining test cases for LLVM 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 11:04:29 +09:00
---
### 2. SelfHost depth2 / MIR JSON v0 / JoinIR Analyzer ライン
feat(phase131): LLVM backend re-enable & PHI ordering bug discovery Phase 131: JoinIR → LLVM individual fixes (minimal scope) ## Modifications ### 1. LLVM Backend Re-enable ✅ - Built with --features llvm to enable real LLVM execution - Verified Python/llvmlite environment (llvmlite 0.45.1) - Fixed llvmlite deprecated API: removed llvm.initialize() call - Successfully moved from Mock backend to real LLVM harness execution ### 2. PHI Instruction Ordering Bug Discovery ⚠️ - Discovered critical bug: PHI nodes placed AFTER terminator instructions - LLVM IR constraint: PHI must be at block start, before any non-PHI - Root cause: finalize_phis() in llvm_builder.py emits PHIs after block termination - Affects all 6 tests with control flow merges ### 3. ConsoleBox LLVM Integration ⚠️ - Confirmed ConsoleBox not registered in Rust VM environment - Deferred to Phase 132 (prerequisite issue) ## Results Modified files: - src/llvm_py/llvm_builder.py: Removed deprecated llvm.initialize() - docs/development/current/main/phase130_joinir_llvm_baseline.md: Added Phase 131 results - CURRENT_TASK.md: Added Phase 131 completion report Test results: - ✅ peek_expr_block.hako: LLVM execution success (Result: 1) - ❌ 6/7 tests: PHI ordering bug (requires Phase 132 refactoring) ## Success Criteria - ✅ LLVM backend minimal re-enable (1/7 test passing) - ⚠️ PHI ordering bug discovered and documented - ⚠️ ConsoleBox integration deferred to Phase 132 ## Phase 132 Handoff Priority 1: Fix PHI instruction ordering bug (finalize_phis() refactoring) Priority 2: Resolve ConsoleBox registration issue Priority 3: Enable remaining test cases for LLVM 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 11:04:29 +09:00
- 現状
- `.hako` から Program JSON v0 / MIR JSON を読み込む準備は整備済みPhase 160 系)。
- JsonParserBox / JsonParserBox.ProgramJSONBox / JsonParserBox.JsonParserBox 自体は箱として実装されている。
- MIR/JoinIR Analyzer Box 群MirAnalyzerBox, JoinIrAnalyzerBoxは基盤実装済み。
- 直近の目的
- JoinIR ループ基盤が安定した前提で、「selfhost depth2 の最小ループ」がどこまで回るかを再確認する。
- JsonParserBox 側のループ制約Pattern14 + 将来 Pattern5と、Analyzer Box の入力形式を揃える。
- 次にやる候補
- [ ] Phase 161続き: MirAnalyzerBox / JoinIrAnalyzerBox に対する代表ケースの再実行
loop パターンが JoinIR 統一後も正しく認識できているか確認)。
- [ ] Phase 166続き: Program JSON v0 / MIR JSON v1 を `.hako` 側で安全にパースできるか確認
JsonParserBox のループ制約と衝突しないかをチェック)。
feat(llvm): Phase 134-A - mir_call.py unified 設計完成 681行の giant ファイルを機能別に分割し、箱化モジュール化を達成。 Changes: - NEW: src/llvm_py/mir_call_compat.py (120 lines) - JSON v0/v1 互換層を一元管理 - normalize_callee(), detect_format_version() - NEW: src/llvm_py/instructions/mir_call/ (7 files) - __init__.py: Canonical Dispatcher (lower_mir_call) - global_call.py: Global関数呼び出し (90 lines) - method_call.py: Boxメソッド呼び出し (175 lines) - constructor_call.py: Boxコンストラクタ (122 lines) - closure_call.py: Closure生成 (87 lines) - value_call.py: 動的関数値呼び出し (112 lines) - extern_call.py: 外部C ABI呼び出し (135 lines) - ARCHIVE: mir_call.py → mir_call_legacy.py Technical Achievements: ✅ mir_call.py: 681行 → 分割(各 80-175行、責務 明確) ✅ Phase 133 ConsoleLlvmBridge パターンを継承 ✅ NYASH_MIR_UNIFIED_CALL フラグ完全廃止 ✅ legacy dispatcher 削除(NotImplementedError 根治) ✅ JSON v0/v1 互換層を mir_call_compat.py に一元化 ✅ Fail-Fast 原則確立 ✅ テスト: 全 mir_call 関連テスト PASS Design Principles Inherited: - Phase 133 ConsoleLlvmBridge 箱化パターン継承 - Each module has clear responsibility - mir_call_compat.py で Phase 124+ v0削除が容易 - テスト分割で保守性大幅向上 Next Phase: Phase 134-B - StringBox bridge 分離(boxcall.py:130-282) Phase 134-C - CollectionBox bridge 分離(boxcall.py:325-375) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 12:06:34 +09:00
---
### 3. hako_check / MIR CFG / JoinIR 解析ライン
feat(llvm): Phase 134-A - mir_call.py unified 設計完成 681行の giant ファイルを機能別に分割し、箱化モジュール化を達成。 Changes: - NEW: src/llvm_py/mir_call_compat.py (120 lines) - JSON v0/v1 互換層を一元管理 - normalize_callee(), detect_format_version() - NEW: src/llvm_py/instructions/mir_call/ (7 files) - __init__.py: Canonical Dispatcher (lower_mir_call) - global_call.py: Global関数呼び出し (90 lines) - method_call.py: Boxメソッド呼び出し (175 lines) - constructor_call.py: Boxコンストラクタ (122 lines) - closure_call.py: Closure生成 (87 lines) - value_call.py: 動的関数値呼び出し (112 lines) - extern_call.py: 外部C ABI呼び出し (135 lines) - ARCHIVE: mir_call.py → mir_call_legacy.py Technical Achievements: ✅ mir_call.py: 681行 → 分割(各 80-175行、責務 明確) ✅ Phase 133 ConsoleLlvmBridge パターンを継承 ✅ NYASH_MIR_UNIFIED_CALL フラグ完全廃止 ✅ legacy dispatcher 削除(NotImplementedError 根治) ✅ JSON v0/v1 互換層を mir_call_compat.py に一元化 ✅ Fail-Fast 原則確立 ✅ テスト: 全 mir_call 関連テスト PASS Design Principles Inherited: - Phase 133 ConsoleLlvmBridge 箱化パターン継承 - Each module has clear responsibility - mir_call_compat.py で Phase 124+ v0削除が容易 - テスト分割で保守性大幅向上 Next Phase: Phase 134-B - StringBox bridge 分離(boxcall.py:130-282) Phase 134-C - CollectionBox bridge 分離(boxcall.py:325-375) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 12:06:34 +09:00
- 現状
- HC019 / HC020DeadCode / DeadBlocksなど、hako_check 側の Box は JoinIR/MIR CFG を読む経路に統一済み。
- JsonParserBox による JSON パーサー共通ライブラリ化も進行中Phase 170172
- 直近の目的
- JoinIR / MIR ラインの変更Pattern14, ExitLine, Boundary, ConditionScopeが hako_check に与える影響を最小に保ちつつ、
解析結果の精度を維持する。
- 次にやる候補
- [ ] Phase 155+ の MIR JSON v1 統合ラインを、最新の JoinIR/Loop 仕様に追随させるかどうかの判断。
(今のところブロッカーではないので優先度は中〜低)
feat(llvm): Phase 134-A - mir_call.py unified 設計完成 681行の giant ファイルを機能別に分割し、箱化モジュール化を達成。 Changes: - NEW: src/llvm_py/mir_call_compat.py (120 lines) - JSON v0/v1 互換層を一元管理 - normalize_callee(), detect_format_version() - NEW: src/llvm_py/instructions/mir_call/ (7 files) - __init__.py: Canonical Dispatcher (lower_mir_call) - global_call.py: Global関数呼び出し (90 lines) - method_call.py: Boxメソッド呼び出し (175 lines) - constructor_call.py: Boxコンストラクタ (122 lines) - closure_call.py: Closure生成 (87 lines) - value_call.py: 動的関数値呼び出し (112 lines) - extern_call.py: 外部C ABI呼び出し (135 lines) - ARCHIVE: mir_call.py → mir_call_legacy.py Technical Achievements: ✅ mir_call.py: 681行 → 分割(各 80-175行、責務 明確) ✅ Phase 133 ConsoleLlvmBridge パターンを継承 ✅ NYASH_MIR_UNIFIED_CALL フラグ完全廃止 ✅ legacy dispatcher 削除(NotImplementedError 根治) ✅ JSON v0/v1 互換層を mir_call_compat.py に一元化 ✅ Fail-Fast 原則確立 ✅ テスト: 全 mir_call 関連テスト PASS Design Principles Inherited: - Phase 133 ConsoleLlvmBridge 箱化パターン継承 - Each module has clear responsibility - mir_call_compat.py で Phase 124+ v0削除が容易 - テスト分割で保守性大幅向上 Next Phase: Phase 134-B - StringBox bridge 分離(boxcall.py:130-282) Phase 134-C - CollectionBox bridge 分離(boxcall.py:325-375) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 12:06:34 +09:00
---
## ✅ 最近完了した主なフェーズ(抜粋)
ここは「今の作業に強く関係する直近フェーズ」だけをざっくり残すよ。詳細は各 phase ドキュメントを参照。
- **Phase 3316/20/21**: Loop header PHI / ExitLine / Boundary の SSOT 化
→ ループ変数の現在値と exit 値が header PHI / ExitLine 経由で一貫して伝播するようになった。
- **Phase 3318/19/20**: Pattern4continue・elsecontinue 正規化・carrier フィルタリング
→ continue 含みのループPattern4が JoinIR 統一ラインの中で動作。
`ContinueBranchNormalizer` / `LoopUpdateAnalyzer` / `CarrierInfo` ラインが安定。
- **Phase 165**: JoinIR ループ Pattern14 代表ケースの完全検証
→ loop_min_while / joinir_min_loop / loop_if_phi / loop_continue_pattern4 で
`[joinir/freeze]` と SSAundef を全排除。
- **Phase 170D (BugFix)**: LoopConditionScopeBox 実装&パラメータ誤分類バグ修正
→ ループ条件の変数スコープ分類LoopParam / OuterLocal / LoopBodyLocalが安定。
JsonParserBox の `s`, `pos`, `len` など関数パラメータが正しく OuterLocal と見なされるようになった。
- **Phase 168169**: BoolExprLowerer / condition_to_joinir 強化
`_trim` / `_skip_whitespace` の OR chain / AND / NOT を JoinIR/MIR に正しく落とせるようになった。
(ただし LoopBodyLocal 条件をどう扱うかは Pattern5 設計の領域として切り出し済み)
---
docs(phase170-d): Phase 170-D-impl-4 Completion - Tests and Documentation ## Summary Completed Phase 170-D-impl-4: Comprehensive documentation and test verification for LoopConditionScopeBox infrastructure. All four implementation phases (1-4) now complete with full modular Box-based architecture and thorough test coverage. ## Changes ### New Documentation - **phase170-d-impl-design.md** (1,356 lines): Comprehensive design document - Architecture overview and modular components - Detailed implementation summary for all 4 phases - Test results and verification procedures - Architecture decisions (Box Theory, Fail-Fast, Conservative Classification) - Future work for Phase 170-D-E and Phase 171+ ### Updated Documentation - **CURRENT_TASK.md**: Added Phase 170-D completion section - Full status overview - Completed work breakdown - Test verification results - Commit history - Architecture summary ## Implementation Status ### Phase 170-D-impl Complete Summary **Phase 170-D-impl-1** ✅ - LoopConditionScopeBox skeleton (220 lines) - CondVarScope enum and data structures - Public API design **Phase 170-D-impl-2** ✅ - Minimal analysis logic (317 lines) - Pure functions: extract_all_variables, is_outer_scope_variable - 12 comprehensive unit tests **Phase 170-D-impl-3** ✅ - Pattern 2/4 integration - Fail-Fast validation checks - 4 integration tests in loop_with_break_minimal.rs **Phase 170-D-impl-4** ✅ - Design documentation - Test verification and results - Architecture guide ### Module Structure ``` src/mir/loop_pattern_detection/ ├── mod.rs (201 lines) ├── loop_condition_scope.rs (220 lines) └── condition_var_analyzer.rs (317 lines) Total: 738 lines ``` ### Test Results ✅ Unit Tests: 16 total (12 in condition_var_analyzer + 4 in loop_with_break_minimal) ✅ Integration Tests: 2 verified (Pattern 2 accept/reject cases) ✅ Build: cargo build --release (0 errors, 50 warnings) ✅ Verification: NYASH_JOINIR_STRUCTURE_ONLY=1 tests pass ## Architecture Highlights - **Box Theory**: Clear separation of LoopConditionScopeBox (orchestration) and condition_var_analyzer (pure functions) - **Fail-Fast**: Early error detection before JoinIR generation - **Conservative Classification**: Defaults to LoopBodyLocal for unknown variables - **Reusable**: Pure functions independent and composition-friendly ## Future Work Phase 170-D-E: Advanced Patterns (Pattern 5+) - Support loop-body-local variables in conditions - Expanded scope heuristics - Selective pattern detection Phase 171: Condition Environment Integration - Tighter coupling with condition_to_joinir - Enhanced variable mapping 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-07 21:43:08 +09:00
## 📌 このファイルの運用方針
docs(phase170-d): Phase 170-D-impl-4 Completion - Tests and Documentation ## Summary Completed Phase 170-D-impl-4: Comprehensive documentation and test verification for LoopConditionScopeBox infrastructure. All four implementation phases (1-4) now complete with full modular Box-based architecture and thorough test coverage. ## Changes ### New Documentation - **phase170-d-impl-design.md** (1,356 lines): Comprehensive design document - Architecture overview and modular components - Detailed implementation summary for all 4 phases - Test results and verification procedures - Architecture decisions (Box Theory, Fail-Fast, Conservative Classification) - Future work for Phase 170-D-E and Phase 171+ ### Updated Documentation - **CURRENT_TASK.md**: Added Phase 170-D completion section - Full status overview - Completed work breakdown - Test verification results - Commit history - Architecture summary ## Implementation Status ### Phase 170-D-impl Complete Summary **Phase 170-D-impl-1** ✅ - LoopConditionScopeBox skeleton (220 lines) - CondVarScope enum and data structures - Public API design **Phase 170-D-impl-2** ✅ - Minimal analysis logic (317 lines) - Pure functions: extract_all_variables, is_outer_scope_variable - 12 comprehensive unit tests **Phase 170-D-impl-3** ✅ - Pattern 2/4 integration - Fail-Fast validation checks - 4 integration tests in loop_with_break_minimal.rs **Phase 170-D-impl-4** ✅ - Design documentation - Test verification and results - Architecture guide ### Module Structure ``` src/mir/loop_pattern_detection/ ├── mod.rs (201 lines) ├── loop_condition_scope.rs (220 lines) └── condition_var_analyzer.rs (317 lines) Total: 738 lines ``` ### Test Results ✅ Unit Tests: 16 total (12 in condition_var_analyzer + 4 in loop_with_break_minimal) ✅ Integration Tests: 2 verified (Pattern 2 accept/reject cases) ✅ Build: cargo build --release (0 errors, 50 warnings) ✅ Verification: NYASH_JOINIR_STRUCTURE_ONLY=1 tests pass ## Architecture Highlights - **Box Theory**: Clear separation of LoopConditionScopeBox (orchestration) and condition_var_analyzer (pure functions) - **Fail-Fast**: Early error detection before JoinIR generation - **Conservative Classification**: Defaults to LoopBodyLocal for unknown variables - **Reusable**: Pure functions independent and composition-friendly ## Future Work Phase 170-D-E: Advanced Patterns (Pattern 5+) - Support loop-body-local variables in conditions - Expanded scope heuristics - Selective pattern detection Phase 171: Condition Environment Integration - Tighter coupling with condition_to_joinir - Enhanced variable mapping 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-07 21:43:08 +09:00
- CURRENT_TASK.md には「直近 1〜2 週間で触っているライン」と「次にやる候補」だけを書く。
- フェーズごとの詳細ログ・長文の議事録・実装メモは:
- `docs/development/current/main/10-Now.md`
- `docs/development/current/main/phaseXX*.md`
に移し、このファイルからはリンクまたは簡単な要約だけに留める。
- もし CURRENT_TASK がまた肥大化してきたら、
古いセクションを phase ドキュメント側に逃して、このファイルを再度「現在地サマリ」に戻す。