feat(joinir): Phase 184 - Body-local MIR Lowering Infrastructure
Phase 184 implements the foundation for body-local variable support in update expressions, completing the three-box architecture: LoopBodyLocalEnv (storage), UpdateEnv (composition), and CarrierUpdateEmitter (emission). ## Implementation Summary ### Task 184-1: Design Document - Created phase184-body-local-mir-lowering.md - Two-Environment System design (ConditionEnv + LoopBodyLocalEnv) - Box-First design principles documented ### Task 184-2: LoopBodyLocalEnv Implementation - New file: src/mir/join_ir/lowering/loop_body_local_env.rs (216 lines) - Storage box for body-local variable name → ValueId mappings - BTreeMap for deterministic ordering (PHI consistency) - 7 unit tests: empty env, single/multiple locals, get/contains, iteration ### Task 184-3: UpdateEnv Implementation - New file: src/mir/join_ir/lowering/update_env.rs (237 lines) - Composition box for unified variable resolution - Priority order: ConditionEnv (condition vars) → LoopBodyLocalEnv (body-local) - 8 unit tests: priority, fallback, not found, combined lookup ### Task 184-4: CarrierUpdateEmitter Integration - Modified: src/mir/join_ir/lowering/carrier_update_emitter.rs - Added emit_carrier_update_with_env() (UpdateEnv version) - Kept emit_carrier_update() for backward compatibility - 4 new unit tests: body-local variable, priority, not found, const update - Total 10 tests PASS (6 existing + 4 new) ### Task 184-5: Representative Test Cases - apps/tests/phase184_body_local_update.hako (Pattern1 baseline) - apps/tests/phase184_body_local_with_break.hako (Pattern2, Phase 185 target) ### Task 184-6: Documentation Updates - Updated: docs/development/current/main/joinir-architecture-overview.md - Updated: CURRENT_TASK.md (Phase 184 completion record) ## Test Results All 25 unit tests PASS: - LoopBodyLocalEnv: 7 tests - UpdateEnv: 8 tests - CarrierUpdateEmitter: 10 tests (6 existing + 4 new) Build: ✅ Success (0 errors) ## Design Constraints Following 箱理論 (Box Theory) principles: - Single Responsibility: Each box has one clear purpose - Deterministic: BTreeMap ensures consistent ordering - Conservative: Pattern5 (Trim) integration deferred to Phase 185 - Fail-Fast: Explicit errors for unsupported patterns ## Scope Limitation Phase 184 provides the **infrastructure only**: - ✅ Storage box (LoopBodyLocalEnv) - ✅ Composition box (UpdateEnv) - ✅ Emission support (CarrierUpdateEmitter) - ❌ Pattern2/4 integration (requires body-local collection, Phase 185) ## Next Steps Phase 185: Pattern2/4 Integration - Integrate LoopBodyLocalEnv into Pattern2/4 lowerers - Add body-local variable collection from loop body AST - Enable full E2E body-local variable support in update expressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -169,6 +169,23 @@ JoinIR ラインで守るべきルールを先に書いておくよ:
|
||||
- else-continue を then-continue へ正規化し、Select ベースの continue を簡潔にする。
|
||||
- ループ本体で実際に更新されるキャリアだけを抽出(Pattern 4 で不要キャリアを排除)。
|
||||
|
||||
- **LoopBodyLocalEnv / UpdateEnv / CarrierUpdateEmitter(Phase 184)**
|
||||
- ファイル:
|
||||
- `src/mir/join_ir/lowering/loop_body_local_env.rs`
|
||||
- `src/mir/join_ir/lowering/update_env.rs`
|
||||
- `src/mir/join_ir/lowering/carrier_update_emitter.rs`
|
||||
- 責務:
|
||||
- **LoopBodyLocalEnv**: ループ本体で宣言された body-local 変数の名前→ValueId マッピングを管理(箱化設計)。
|
||||
- **UpdateEnv**: 条件変数(ConditionEnv)と body-local 変数(LoopBodyLocalEnv)を統合した変数解決層。
|
||||
- Priority order: 1. Condition variables(高優先度) → 2. Body-local variables(フォールバック)
|
||||
- **CarrierUpdateEmitter**: UpdateExpr を JoinIR 命令に変換する際、UpdateEnv を使用して body-local 変数をサポート。
|
||||
- `emit_carrier_update_with_env()`: UpdateEnv 版(Phase 184 新規)
|
||||
- `emit_carrier_update()`: ConditionEnv 版(後方互換)
|
||||
- 設計原則:
|
||||
- **箱理論**: 各 Box が単一責任を持ち、境界明確。
|
||||
- **決定性**: BTreeMap 使用で一貫した順序保証(PHI 生成の決定性)。
|
||||
- **保守的**: Pattern5 (Trim) は対象外、Phase 185 で統合予定。
|
||||
|
||||
### 2.3 キャリア / Exit / Boundary ライン
|
||||
|
||||
- **CarrierInfo / LoopUpdateAnalyzer**
|
||||
|
||||
Reference in New Issue
Block a user