feat(joinir): Phase 47-A-IMPL - P3 Normalized infrastructure

Implement Pattern3 (if-sum) Normalized infrastructure, extending existing P2
StepSchedule and ShapeGuard systems.

Key changes:

1. StepSchedule generalization (P2 → P2/P3):
   - Renamed: pattern2_step_schedule.rs → step_schedule.rs
   - Extended StepKind enum with P3 variants:
     - IfCond (if condition in body)
     - ThenUpdates (carrier updates in then branch)
     - ElseUpdates (carrier updates in else branch)
   - Added pattern3_if_sum_schedule() function
   - Added unit test: test_pattern3_if_sum_schedule()
   - Updated module references (mod.rs, loop_with_break_minimal.rs)

2. ShapeGuard extension:
   - Added Pattern3IfSumMinimal variant to NormalizedDevShape
   - Added is_pattern3_if_sum_minimal() detector (placeholder)
   - Updated shape detector table
   - Extended capability_for_shape() mapping

3. Bridge integration:
   - bridge.rs: Added P3 shape handling in normalize_for_shape()
   - normalized.rs: Added P3 roundtrip match (uses P2 temporarily)

4. P2/P3 separation:
   - loop_with_break_minimal.rs: Added panic for P3 steps in P2 lowering
   - Clear boundary enforcement (P2 lowerer rejects P3 steps)

5. Documentation:
   - CURRENT_TASK.md: Phase 47-A-IMPL status
   - phase47-norm-p3-design.md: Implementation status section

Benefits:
- Reuses 90% of P2 infrastructure (ConditionEnv, CarrierInfo, ExitLine)
- Clean P2/P3 separation via StepKind
- Pure additive changes (no P2 behavioral changes)
- Ready for Phase 47-A-LOWERING (full P3 Normalized implementation)

Tests: 938/938 PASS (+1 from step_schedule unit test)
- All existing P1/P2 tests pass (no regressions)
- P3 test uses Structured path temporarily (proper lowering in next phase)

Next phase: Implement full P3 Normalized→MIR(direct) lowering
This commit is contained in:
nyash-codex
2025-12-12 05:23:18 +09:00
parent 42ecd7a7e7
commit c3a26e705e
8 changed files with 107 additions and 12 deletions

View File

@ -155,6 +155,27 @@ loop(i < arr.length()) {
Complex P3 patterns from selfhost compiler (deferred to later phase).
## Implementation Status
**Phase 47-A-PREP** (✅ Complete, commit 42ecd7a7):
- Fixture added: `pattern3_if_sum_minimal` in `normalized/fixtures.rs`
- Test stub added: `test_normalized_pattern3_if_sum_minimal_runner_dev_switch_matches_structured`
- Basic infrastructure for P3 development mode testing
**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)
**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)
## Implementation Strategy
### Phase 47-A: Minimal sum_count (dev-only)