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:
nyash-codex
2025-12-12 06:06:39 +09:00
parent 99bdf93dfe
commit 4ecb6435d3
4 changed files with 469 additions and 34 deletions

View File

@ -8,6 +8,33 @@
---
## 0. 読み方ガイドReader's Guide
このファイルは情報量が多いので、「何を知りたいか」で読む場所を分けると楽だよ:
- **不変条件だけ押さえたいとき**
- セクション `1. 不変条件Invariants` を読む。
- JoinIR 全体で絶対に守るルールValueId 領域 / PHI 契約 / FailFastがここにまとまっている。
- **箱ごとの責務と流れを掴みたいとき**
- セクション `2. 主な箱と責務` を読む。
- LoopPattern / Pattern lowerer / ConditionEnv / ExitLine / Boundary など、構造箱・判定箱・生成箱の入口がここ。
- **Normalized JoinIRJoinIR→JoinIR 正規化)を知りたいとき**
- セクション `3. JoinIR 第1章基盤完成サマリ`
小節 `3.13.3`Structured vs Normalized の関係)を読む。
- 詳細な完成サマリは `PHASE_43_245B_NORMALIZED_COMPLETION.md` にまとまっているので、そちらも合わせて参照してね。
- **JsonParser/selfhost のループ状況を見たいとき**
- セクション `7. JoinIR 第1章基盤完成サマリ` 内の JsonParser/selfhost 表と、
`phase181-jsonparser-loop-roadmap.md` を見る。
- **各 Phase ごとの細かい経緯・ログが欲しいとき**
- `docs/development/current/main/phase*-*.md` 系の Phase ドキュメントを読む。
- 本ファイルの `3.x` にある Phase ロードマップは「索引」としての位置づけで、詳細は各 Phase doc 側が SSOT だよ。
---
## 1. 不変条件Invariants
JoinIR ラインで守るべきルールを先に書いておくよ:
@ -1357,9 +1384,9 @@ JsonParser _skip_whitespace / _atoi / _parse_number が**すべて canonical Nor
- `bridge.rs`: コメント更新Phase 41 → Phase 46
- `normalized_joinir_min.rs`: canonical set 検証テスト追加
**テスト**: 937/937 PASS
**テスト**: 938/938 PASS
### 3.24 Phase 47-NORM-P3 Normalized P3 (If-Sum) Support 🏗️ DESIGN + MINIMAL DEV (2025-12-12)
### 3.24 Phase 47-NORM-P3 Normalized P3 (If-Sum) Support 🏗️ DESIGN + MINIMAL DEV + DIRECT (2025-12-12)
**設計詳細**: [phase47-norm-p3-design.md](./phase47-norm-p3-design.md)
@ -1370,13 +1397,39 @@ Pattern3 (if-sum) ループを Normalized JoinIR に対応させる。P2 と同
**Key difference**: P3 は **conditional carrier updates**if 内でのみキャリア更新vs P2 の unconditional updates before break
**Phase 47-A**: Minimal sum_countdev-only 正規化・第1ステップ
- ✅ AST ベース if-sum lowerer`loop_with_if_phi_if_sum.rs`)で `phase212_if_sum_min.hako` 相当の Structured JoinModule を生成
- ✅ AST ベース if-sum lowerer`loop_with_if_phi_if_sum.rs`)で `phase212_if_sum_min.hako` 相当の Structured JoinModule3 関数構成)を生成
- ✅ Normalized dev ランナー経路で Structured→Normalized→Structured roundtrip を通し、JoinIR Runner の実行結果が一致することをテストで固定
`build_pattern3_if_sum_min_structured_for_normalized_dev` + `normalized_pattern3_if_sum_minimal_runner_dev_switch_matches_structured`
- StepScheduleBox 拡張`IfCond` / `ThenUpdates` / `ElseUpdates`と direct Normalized→MIR ブリッジ適用は次フェーズの実装タスクPhase 47-A/B 継続)
- StepScheduleBox を汎用化し、P3 用 StepKind`IfCond` / `ThenUpdates` / `ElseUpdates`を追加
- ✅ shape_guard に `Pattern3IfSumMinimal` を追加し、構造ベースで P3 最小 if-sum 形状を検出
- ✅ `normalize_pattern3_if_sum_minimal` を通じて P3 最小ケースを Normalized→MIR(direct) パイプラインに載せ、P1/P2 と同じ direct ブリッジで実行結果一致を確認dev-only
**Phase 47-B**: array_filter (dev-only, body-local + method calls)
**Phase 47-C**: Canonical promotion (P3 minimal → canonical)
**スコープ外**: P4 (continue) 対応NORM-P4 フェーズで実施、Complex P3 patterns後続フェーズ
### 3.25 Phase 48-NORM-P4 Normalized P4 (Continue) Design 📋 DESIGN PHASE (2025-12-12)
**設計詳細**: [phase48-norm-p4-design.md](./phase48-norm-p4-design.md)
P4 (continue) will use the **same `loop_step(env, k_exit)` skeleton** as P1/P2/P3.
**Key insight**: `continue` = immediate `TailCallFn(loop_step, env', k_exit)` (skip to next iteration early), not a new instruction.
**Target loops** (JsonParser):
- ◎ _parse_array (skip whitespace) - PRIMARY (Phase 48-A)
- ○ _parse_object (skip whitespace) - Extended
- △ _unescape_string, _parse_string - Later
**Infrastructure reuse**: 95%+ of P2/P3 Normalized code works for P4
- Same: EnvLayout, ConditionEnv, CarrierInfo, ExitLine, JpInst
- New: `ContinueCheck` step kind in StepScheduleBox
**Phase 48 doc is SSOT** for P4 Normalized design.
**Implementation phases**:
- Phase 48-A: Minimal continue (dev-only)
- Phase 48-B: Extended patterns (multi-carrier)
- Phase 48-C: Canonical promotion