docs(joinir): Phase 48 - Normalized P4 (Continue) design
Complete design documentation for Pattern4 (continue) Normalized support,
extending unified Normalized infrastructure to all 4 loop patterns.
Design documents:
- phase48-norm-p4-design.md: Complete P4 Normalized design (380 lines)
- Key insight: continue = immediate TailCallFn(loop_step, ...) (no new instruction!)
- Infrastructure reuse: 95%+ from P2/P3 (only ContinueCheck step kind new)
- Target loops prioritized:
- ◎ _parse_array (skip whitespace) - PRIMARY (Phase 48-A)
- ○ _parse_object (skip whitespace) - Extended
- △ _unescape_string, _parse_string - Later
- Control flow: ContinueCheck before Updates (skip processing early)
- Same EnvLayout/ConditionEnv/CarrierInfo/ExitLine as P2/P3
- Implementation strategy: dev-only → canonical (proven approach)
Architecture:
- Unified Normalized for P1/P2/P3/P4 (all patterns same pipeline)
- P4 uses loop_step(env, k_exit) skeleton (same as P2/P3)
- continue semantics: TailCallFn = skip to next iteration (CPS natural fit)
Benefits:
- 95% infrastructure reuse from P2/P3
- No new JpInst needed (continue = existing TailCallFn)
- Incremental rollout (dev → canonical)
- Clear semantic: continue = immediate recursion
Implementation roadmap:
- Phase 48-A: Minimal continue (dev-only)
- Phase 48-B: Extended patterns (multi-carrier)
- Phase 48-C: Canonical promotion
Updates:
- joinir-architecture-overview.md: Added Phase 48 section
- CURRENT_TASK.md: Phase 48 entry (Design Complete)
- phase47-norm-p3-design.md: Minor formatting
Status: Design phase complete (doc-only, no implementation yet)
Next: Phase 48-A implementation (when requested)
This commit is contained in:
@ -165,38 +165,36 @@ Complex P3 patterns from selfhost compiler (deferred to later phase).
|
||||
**Phase 47-A-IMPL** (✅ Complete, 2025-12-12):
|
||||
- ✅ StepSchedule renamed and extended: `pattern2_step_schedule.rs` → `step_schedule.rs`
|
||||
- ✅ P3 StepKind added: `IfCond`, `ThenUpdates`, `ElseUpdates`
|
||||
- ✅ Pattern2 lowering separation: P3 steps panic in P2 lowering (clean boundary)
|
||||
- ✅ ShapeGuard: `Pattern3IfSumMinimal` detection added (placeholder stub)
|
||||
- ✅ Normalized bridge: P3 shape handling in `normalize_for_shape()` and roundtrip
|
||||
- ✅ 938/938 tests PASS (no regressions)
|
||||
- ⏳ TODO: Full P3 Normalized lowering (Phase 47-A-LOWERING)
|
||||
- ✅ Pattern2 lowering separation: P3 steps panic in P2 lowering(責務境界を明確化)
|
||||
- ✅ ShapeGuard: `Pattern3IfSumMinimal` detection added(構造ベース検出)
|
||||
- ✅ Normalized bridge: `normalize_pattern3_if_sum_minimal` を通じて P3 最小ケースを Normalized→MIR(direct) パイプラインに統合
|
||||
- ✅ Runner / VM tests: P3 minimal について Structured 経路と Normalized→MIR(direct) 経路が一致することを dev-only スイートで確認
|
||||
- ✅ 938/938 tests PASS(退行なし)
|
||||
|
||||
**Next Phase** (Phase 47-A-LOWERING):
|
||||
- Implement `lower_pattern3_if_sum_minimal()` fully
|
||||
- Generate Normalized JpInst for P3 structure (If branching, conditional updates)
|
||||
- Test VM output comparison (Normalized vs Structured)
|
||||
**Next Phase**(Phase 47-B 以降):
|
||||
- array_filter など body-local + method call を含む P3 ループへの適用
|
||||
- multi-carrier if-sum(sum + count)や JsonParser 由来 P3 への拡張
|
||||
- Canonical 昇格(P3 minimal を dev-only から常時 Normalized 経路へ)
|
||||
|
||||
## Implementation Strategy
|
||||
|
||||
### Phase 47-A: Minimal sum_count (dev-only)
|
||||
### Phase 47-A: Minimal sum_count (dev-only, 実装済みの範囲)
|
||||
|
||||
**Goal**: Prove P3 can use Normalized infrastructure with minimal additions.
|
||||
|
||||
**Steps**:
|
||||
1. **ShapeGuard**: Add `Pattern3IfSumMinimal` shape
|
||||
2. **StepScheduleBox**: Add `ConditionalUpdate` step kind
|
||||
3. **Normalized lowering**:
|
||||
- Generate `If` JpInst for body if-statement
|
||||
- Emit carrier updates in then/else branches
|
||||
4. **Test**: Verify Structured→Normalized→MIR(direct) matches Structured→MIR
|
||||
**実装済みステップ**:
|
||||
1. **ShapeGuard**: `Pattern3IfSumMinimal` shape 追加
|
||||
- Compare + Select + tail call を持つ 3 関数構成の P3 if-sum 最小パターンを検出。
|
||||
2. **StepScheduleBox**: P3 用 StepKind 追加
|
||||
- `IfCond` / `ThenUpdates` / `ElseUpdates` を `step_schedule.rs` に導入し、P2/P3 共通の箱として再利用。
|
||||
3. **Normalized lowering(minimal)**:
|
||||
- `normalize_pattern3_if_sum_minimal` により、P3 最小ケースを P2 と同じ器の NormalizedModule に変換し、direct ブリッジで扱える形に整備。
|
||||
4. **Tests**:
|
||||
- Runner 経路: `normalized_pattern3_if_sum_minimal_runner_dev_switch_matches_structured`
|
||||
- Normalization 経路: `test_phase47a_pattern3_if_sum_minimal_normalization`(shape + normalize 成功)
|
||||
- (詳細な VM Bridge 比較は Phase 47-B 以降で拡張していく)
|
||||
|
||||
**Expected additions**:
|
||||
- `shape_guard.rs`: +1 shape variant
|
||||
- `pattern2_step_schedule.rs`: Rename to `step_schedule.rs`, add P3 support
|
||||
- `normalized_bridge/direct.rs`: Handle `If` JpInst with carrier updates
|
||||
- `tests/normalized_joinir_min.rs`: +1 P3 test
|
||||
|
||||
**Dev fixture**: `phase212_if_sum_min.hako` → `jsonparser_if_sum_minimal`
|
||||
**Dev fixture**: `apps/tests/phase212_if_sum_min.hako`(最小 if-sum パターン)
|
||||
|
||||
### Phase 47-B: array_filter (dev-only)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user