feat(joinir): Phase 46 - P2-Mid canonical Normalized promotion
Promote P2-Mid patterns (_atoi real, _parse_number real) to canonical
Normalized→MIR(direct) route, completing P2 line transition.
Canonical set expansion (Phase 41 → Phase 46):
- P2-Core: Pattern2Mini, skip_ws mini/real, atoi mini
- P2-Mid: atoi real, parse_number real (NEW)
All JsonParser P2 loops (_skip_whitespace, _atoi, _parse_number) now
canonical Normalized - Structured→MIR is legacy/comparison-only.
Key changes:
- shape_guard.rs: Expanded is_canonical_shape() (+2 patterns)
- JsonparserAtoiReal
- JsonparserParseNumberReal
- Made NormalizedDevShape enum public
- bridge.rs: Updated canonical routing comments (Phase 41 → 46)
- normalized.rs: Made shape_guard module public
- normalized_joinir_min.rs: Added Phase 46 canonical verification test
- phase46-norm-canon-p2-mid.md: Complete design documentation
Out of scope (deferred):
- P3/P4 Normalized support → NORM-P3/NORM-P4 phases
- Selfhost complex loops → separate phases
Benefits:
- Clear P2 boundary: All JsonParser P2 = Normalized canonical
- Infrastructure validation: Phase 43/245B proven production-ready
- Simplified mental model: P2 = Normalized-first, P3/P4 = future
Tests: 937/937 PASS (lib), 20/20 PASS (normalized_dev feature)
Phase 46 test: test_phase46_canonical_set_includes_p2_mid ✅
This commit is contained in:
@ -1106,6 +1106,28 @@ Normalized JoinIR では、制御構造を次の 3 要素だけで表現する
|
||||
これにより、現在 JoinIR 層で苦労している「PHI 配線」「exit_bindings/jump_args 整合性」「評価順のねじれ」は、
|
||||
Normalized JoinIR 側では「Env フィールドの更新順」と「どの継続を呼ぶか」に還元される想定だよ。
|
||||
|
||||
#### 3.2.1 P1〜P4 と Normalized ループ形
|
||||
|
||||
Normalized JoinIR のゴールは、「P1〜P4 すべてのループを同じループ骨格(`loop_step(env, k_exit)` + 継続)で表現する」ことだよ:
|
||||
|
||||
- P1 Simple:
|
||||
- `loop_step(env, k_exit)` だけを持つ最小形(break/continue なし)。
|
||||
- 条件が false になったら `k_exit(env)` に TailCall、true なら body を 1 ステップ進めて再び `loop_step` を呼ぶ。
|
||||
- P2 Break:
|
||||
- P1 の形に「body 後の break 判定」と `k_exit(env)` への分岐が加わったもの。
|
||||
- break/continue/return 自体はすべて継続呼び出し(`TailCallKont` / `TailCallFn`)として表現され、型レベルでは P1 の上位互換。
|
||||
- P3 If‑PHI:
|
||||
- ループ本体に `if_branch(env, k_then, k_else)` + join 継続を挟んだ形として表現し、PHI は「Env のフィールド更新順+ join 継続」で表す。
|
||||
- P4 Continue:
|
||||
- `continue` は「更新後に `loop_step(env', k_exit)` へ TailCall」するだけの構造として扱い、break/return と同じく継続レベルで閉じる。
|
||||
|
||||
設計としては **Normalized IR の型と不変条件は P1〜P4 で共通**で、違いは Structured 層からどのように `loop_step` / 継続を合成するか(`LoopCpsSynthesizer` 側の分岐)だけに閉じ込める前提だよ。
|
||||
|
||||
- Phase 26‑H / 28–43 では、まず P1/P2(特に JsonParser の P2-Core/P2-Mid)だけを Normalized に載せて設計を固定した。
|
||||
- P3/P4 の Normalized 対応は今後のフェーズ(NORM‑P3 / NORM‑P4 ライン)で、上の骨格に揃える形で段階的に進める。
|
||||
|
||||
この方針により、「先に P1/P2 だけ Normalized を実装しても、後から P3/P4 を同じ器に寄せられる」ことを文書上で保証しておく。
|
||||
|
||||
### 3.3 Normalized JoinIR 導入のメリットと初期コスト
|
||||
|
||||
Normalized JoinIR を 1 段挟むと、開発の手触りがどう変わるかをここでまとめておくよ。
|
||||
@ -1315,3 +1337,24 @@ Normalized JoinIR を 1 段挟むと、開発の手触りがどう変わるか
|
||||
- ✅ **Canonical-first routing**: P2-Core canonical shapes は mode 無視で常に Normalized→MIR(direct)
|
||||
- ✅ **Mode-based 分岐統一**: bridge/runner の pattern matching で一貫した挙動
|
||||
- ✅ **既存挙動完全保持**: 937/937 tests PASS
|
||||
|
||||
### 3.23 Phase 46-NORM-CANON-P2-MID – Normalized Canonical P2-Mid 昇格 ✅ COMPLETE (2025-12-12)
|
||||
|
||||
**設計詳細**: [phase46-norm-canon-p2-mid.md](./phase46-norm-canon-p2-mid.md)
|
||||
|
||||
P2-Mid パターン(_atoi real, _parse_number real)を canonical Normalized→MIR(direct) ルートに昇格。
|
||||
|
||||
**Canonical set 拡張(Phase 46)**:
|
||||
- P2-Core: Pattern2Mini, skip_ws mini/real, atoi mini
|
||||
- **P2-Mid: atoi real, parse_number real** (NEW)
|
||||
|
||||
JsonParser _skip_whitespace / _atoi / _parse_number が**すべて canonical Normalized** に。Structured→MIR は P2 ラインにおいてレガシー/比較用途のみ。
|
||||
|
||||
**スコープ外**: P3/P4 Normalized 対応(NORM-P3/NORM-P4 フェーズで実施)。
|
||||
|
||||
**変更ファイル**:
|
||||
- `shape_guard.rs`: `is_canonical_shape()` 拡張(+2 パターン)
|
||||
- `bridge.rs`: コメント更新(Phase 41 → Phase 46)
|
||||
- `normalized_joinir_min.rs`: canonical set 検証テスト追加
|
||||
|
||||
**テスト**: 937/937 PASS
|
||||
|
||||
Reference in New Issue
Block a user