Commit Graph

3 Commits

Author SHA1 Message Date
d2972c1437 feat(joinir): Phase 92完了 - ConditionalStep + body-local変数サポート
## Phase 92全体の成果

**Phase 92 P0-P2**: ConditionalStep JoinIR生成とbody-local変数サポート
- ConditionalStep(条件付きキャリア更新)のJoinIR生成実装
- Body-local変数(ch等)の条件式での参照サポート
- 変数解決優先度: ConditionEnv → LoopBodyLocalEnv

**Phase 92 P3**: BodyLocalPolicyBox + 安全ガード
- BodyLocalPolicyDecision実装(Accept/Reject判定)
- BodyLocalSlot + DualValueRewriter(JoinIR/MIR二重書き込み)
- Fail-Fast契約(Cannot promote LoopBodyLocal検出)

**Phase 92 P4**: E2E固定+回帰最小化 (本コミット)
- Unit test 3本追加(body-local変数解決検証)
- Integration smoke追加(phase92_pattern2_baseline.sh、2ケースPASS)
- P4-E2E-PLAN.md、P4-COMPLETION.md作成

## 主要な実装

### ConditionalStep(条件付きキャリア更新)
- `conditional_step_emitter.rs`: JoinIR Select命令生成
- `loop_with_break_minimal.rs`: ConditionalStep検出と統合
- `loop_with_continue_minimal.rs`: Pattern4対応

### Body-local変数サポート
- `condition_lowerer.rs`: body-local変数解決機能
  - `lower_condition_to_joinir`: body_local_env パラメータ追加
  - 変数解決優先度実装(ConditionEnv優先)
  - Unit test 3本追加: 変数解決/優先度/エラー
- `header_break_lowering.rs`: break条件でbody-local変数参照
- 7ファイルで後方互換ラッパー(lower_condition_to_joinir_no_body_locals)

### Body-local Policy & Safety
- `body_local_policy.rs`: BodyLocalPolicyDecision(Accept/Reject)
- `body_local_slot.rs`: JoinIR/MIR二重書き込み
- `dual_value_rewriter.rs`: ValueId書き換えヘルパー

## テスト体制

### Unit Tests (+3)
- `test_body_local_variable_resolution`: body-local変数解決
- `test_variable_resolution_priority`: 変数解決優先度(ConditionEnv優先)
- `test_undefined_variable_error`: 未定義変数エラー
- 全7テストPASS(cargo test --release condition_lowerer::tests)

### Integration Smoke (+1)
- `phase92_pattern2_baseline.sh`:
  - Case A: loop_min_while.hako (Pattern2 baseline)
  - Case B: phase92_conditional_step_minimal.hako (条件付きインクリメント)
  - 両ケースPASS、integration profileで発見可能

### 退行確認
-  既存Pattern2Breakテスト正常(退行なし)
-  Phase 135 smoke正常(MIR検証PASS)

## アーキテクチャ設計

### 変数解決メカニズム
```rust
// Priority 1: ConditionEnv (loop params, captured)
if let Some(value_id) = env.get(name) { return Ok(value_id); }
// Priority 2: LoopBodyLocalEnv (body-local like `ch`)
if let Some(body_env) = body_local_env {
    if let Some(value_id) = body_env.get(name) { return Ok(value_id); }
}
```

### Fail-Fast契約
- Delta equality check (conditional_step_emitter.rs)
- Variable resolution error messages (ConditionEnv)
- Body-local promotion rejection (BodyLocalPolicyDecision::Reject)

## ドキュメント

- `P4-E2E-PLAN.md`: 3レベルテスト戦略(Level 1-2完了、Level 3延期)
- `P4-COMPLETION.md`: Phase 92完了報告
- `README.md`: Phase 92全体のまとめ

## 将来の拡張(Phase 92スコープ外)

- Body-local promotionシステム拡張
- P5bパターン認識の汎化(flagベース条件サポート)
- 完全なP5b E2Eテスト(body-local promotion実装後)

🎯 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-16 21:37:07 +09:00
7e03cb6425 docs(phase-91): Update Phase 91 README with Step 2 completion status
### Updates

#### 1. Status Section
- Updated Status to reflect all completed steps (1, 2-A/B/D, 2-E)
- Documented parity verification success

#### 2. Completion Status Section (NEW)
- Added dedicated section for Phase 91 Step 2 completion
- Listed all deliverables with checkmarks
- Documented test results: 1062/1062 PASS

#### 3. Next Steps
- Clarified Phase 92 lowering requirements
- Updated timeline expectations

#### 4. Test Fixture Fix
- Fixed syntax error in test_pattern5b_escape_minimal.hako
  (field declarations: changed `console: ConsoleBox` to `console ConsoleBox`)

### Context

Phase 91 Step 2 is now fully complete:
-  AST recognizer (detect_escape_skip_pattern)
-  Canonicalizer integration (UpdateKind::ConditionalStep)
-  Unit tests (test_escape_skip_pattern_recognition)
-  Parity verification (strict mode green)

Ready for Phase 92 lowering implementation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-16 14:55:40 +09:00
9e3b258046 feat(phase-91): JoinIR Selfhost depth-2 advancement - Pattern P5b design & planning
## Overview
Analyzed 34 loops across selfhost codebase to identify JoinIR coverage gaps.
Current readiness: 47% (16/30 loops). Next frontier: Pattern P5b (Escape Handling).

## Current Status
- Phase 91 planning document: Complete
  - Loop inventory across 6 key files
  - Priority ranking: P5b (escape) > P5 (guard) > P6 (nested)
  - Effort estimates and ROI analysis

- Pattern P5b Design: Complete
  - Problem statement (variable-step carriers)
  - Pattern definition with Skeleton layout
  - Recognition algorithm (8-step detection)
  - Capability taxonomy (P5b-specific guards)
  - Lowering strategy (Phase 92 preview)

- Test fixture: Created
  - Minimal escape sequence parser
  - JSON string with backslash escape

- Loop Canonicalizer extended
  - Capability table updated with P5b entries
  - Fail-Fast criteria documented
  - Implementation checklist added

## Key Findings

### Loop Readiness Matrix
| Category | Count | JoinIR Status |
|----------|-------|--------------|
| Pattern 1 (simple bounded) | 16 |  Ready |
| Pattern 2 (with break) | 1 | ⚠️ Partial |
| **Pattern P5b (escape seq)** | ~3 |  NEW |
| Pattern P5 (guard-bounded) | ~2 |  Deferred |
| Pattern P6 (nested loops) | ~8 |  Deferred |

### Top Candidates
1. **P5b**: json_loader.hako:30 (8 lines, high reuse)
   - Effort: 2-3 days (recognition)
   - Impact: Unlocks all escape parsers

2. **P5**: mini_vm_core.hako:541 (204 lines, monolithic)
   - Effort: 1-2 weeks
   - Impact: Major JSON optimization

3. **P6**: seam_inspector.hako:76 (7+ nesting)
   - Effort: 2-3 weeks
   - Impact: Demonstrates nested composition

## Phase 91 Strategy
**Recognition-only phase** (no lowering in P1):
- Step 1: Design & planning 
- Step 2: Canonicalizer implementation (detect_escape_pattern)
- Step 3: Unit tests + parity verification
- Step 4: Lowering deferred to Phase 92

## Files Added
- docs/development/current/main/phases/phase-91/README.md - Full analysis & planning
- docs/development/current/main/design/pattern-p5b-escape-design.md - Technical design
- tools/selfhost/test_pattern5b_escape_minimal.hako - Test fixture

## Files Modified
- docs/development/current/main/design/loop-canonicalizer.md
  - Capability table extended with P5b entries
  - Pattern P5b full section added
  - Implementation checklist updated

## Acceptance Criteria (Phase 91 Step 1)
-  Loop inventory complete (34 loops across 6 files)
-  Pattern P5b design document ready
-  Test fixture created
-  Capability taxonomy extended
-  Implementation deferred (Step 2+)

## References
- JoinIR Architecture: joinir-architecture-overview.md
- Phase 91 Plan: phases/phase-91/README.md
- P5b Design: design/pattern-p5b-escape-design.md

Next: Implement detect_escape_pattern() recognition in Phase 91 Step 2

🤖 Generated with Claude Code

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-16 14:22:36 +09:00