Phase 61: structural if-sum+break lowering (dev-only)
This commit is contained in:
56
docs/development/current/main/PHASE_61_SUMMARY.md
Normal file
56
docs/development/current/main/PHASE_61_SUMMARY.md
Normal file
@ -0,0 +1,56 @@
|
||||
# Phase 61 Summary: IF-SUM + BREAK (dev-only, structural)
|
||||
|
||||
## Goal
|
||||
|
||||
Phase 61 は「Break(P2) に P3 固有ロジックを混ぜない」を達成しつつ、selfhost の `if-sum + break` 形状を **by-name なし**で JoinIR Frontend に載せる。
|
||||
|
||||
## Problem (Phase 61 前)
|
||||
|
||||
- `break_pattern.rs`(Break/P2 箱)の param-order 決定で、`selfhost_if_sum_p3*` を名指しして P3 helper を優先する案は、
|
||||
- 責務混線(Break 箱が P3(if-sum) の意味論まで背負う)
|
||||
- dev-only でも撤去困難な by-name 分岐になりやすい
|
||||
という理由で採用しない。
|
||||
|
||||
## Solution (Phase 61)
|
||||
|
||||
### 1) Break(P2) を構造ベースに戻す
|
||||
|
||||
- `src/mir/join_ir/frontend/ast_lowerer/loop_patterns/break_pattern.rs`
|
||||
- Break(P2) の ownership 経路は `plan_to_p2_inputs_with_relay` のみを使用し、P3 専用分岐を排除する。
|
||||
|
||||
### 2) 新箱 `if_sum_break_pattern` を追加(dev-only)
|
||||
|
||||
- `src/mir/join_ir/frontend/ast_lowerer/loop_patterns/if_sum_break_pattern.rs`
|
||||
- 対象: `break-if + update-if + counter-update + return Var+Var`
|
||||
- 検出は構造のみ(by-name なし)。
|
||||
- lowering は Select ベースで `sum`/`count` を更新し、exit では `sum + count` を 1 値にして `k_exit` に渡す。
|
||||
|
||||
### 3) Ownership を SSOT に使う(param order / carriers)
|
||||
|
||||
- `OwnershipAnalyzer` → `plan_to_p3_inputs_with_relay` で carriers/captures を得る。
|
||||
- Fail-Fast: carriers が Return の 2 変数と一致しない場合は拒否(canonical P3 群との混線防止)。
|
||||
- relay は単一hopのみ許可(multi-hop は Fail-Fast 維持)。
|
||||
|
||||
## Fail-Fast Contract
|
||||
|
||||
- Return が `Var + Var` 以外なら対象外。
|
||||
- loop body が `[break-if, update-if, counter-update]` の最小形状から外れるなら対象外。
|
||||
- counter update が `i = i + 1` 形で検出できないなら Err。
|
||||
- relay_path.len() > 1 は Err。
|
||||
- carriers != return vars は Err。
|
||||
|
||||
## Tests
|
||||
|
||||
- `tests/normalized_joinir_min.rs`
|
||||
- selfhost P3 fixture を Program(JSON v0) として解析し、relay_writes→carriers 変換が成立することを固定。
|
||||
- selfhost P3(NormalizedDev 経路)については stdout/exit + 期待値(意味論)で固定し、比較テスト依存を避ける。
|
||||
|
||||
## Notes (Reproducibility)
|
||||
|
||||
- `docs/private` は submodule のため、fixture JSON を参照する場合は **submodule 側で追跡されていること**を前提とする。
|
||||
- 未追跡のままローカルだけで存在すると、clean checkout で `include_str!` が壊れる。
|
||||
|
||||
## Next Candidates
|
||||
|
||||
- Phase 62: P3(if-sum) の「本番 MIR→JoinIR ルート」へ OwnershipPlan を渡す設計(AST-based ownership 解析の接続点を設計 → dev-only で段階接続)。
|
||||
- Phase 63+: multi-hop / merge relay の意味論設計(Fail-Fast を解除する前に SSOT と不変条件を明文化)。
|
||||
@ -138,8 +138,11 @@ pub struct OwnershipPlan {
|
||||
- **Phase 57**: OwnershipAnalyzer implementation (dev-only)
|
||||
- **Phase 58**: P2 plumbing (dev-only)
|
||||
- **Phase 59**: P3 plumbing (dev-only)
|
||||
- **Phase 60**: Cleanup dev heuristics
|
||||
- **Phase 61**: Canonical promotion decision
|
||||
- **Phase 60**: Single-hop relay threading for fixtures (dev-only)
|
||||
- **Phase 61**: P3 側の接続点を決めて段階接続(dev-only)
|
||||
- まずは fixtures ルート(Program(JSON v0))で、if-sum+break を別箱として構造的に接続する
|
||||
- 詳細: `docs/development/current/main/PHASE_61_SUMMARY.md`
|
||||
- MIR→JoinIR の本番ルート(`pattern3_with_if_phi.rs`)へ寄せるのは別フェーズで設計→接続
|
||||
|
||||
## Module Boundary
|
||||
|
||||
@ -244,6 +247,13 @@ loop {
|
||||
|
||||
### Implementation Details
|
||||
|
||||
**Input JSON Compatibility**:
|
||||
- テスト用の簡易スキーマ: top-level `functions` + stmt/expr の `kind` を解釈
|
||||
- Program(JSON v0): top-level `defs` + stmt/expr の `type` を解釈
|
||||
- `Local` は JSON v0 で「新規束縛」と「rebind/update」が混在し得るため、
|
||||
解析では「scope chain で既に定義済みなら write / 未定義なら define」として扱う(dev-only 前提)。
|
||||
- Note: `docs/private` は submodule のため、fixture JSON を参照する場合は submodule 側で追跡されていることを前提とする。
|
||||
|
||||
**Body-Local Ownership Rule**:
|
||||
```rust
|
||||
// Example: local in if/block → enclosing loop owns it
|
||||
@ -267,5 +277,9 @@ loop {
|
||||
## Status
|
||||
|
||||
- ✅ Phase 56: Design + interface skeleton completed
|
||||
- ✅ Phase 57: Analyzer implemented (dev-only, not connected to lowering yet)
|
||||
- ⏳ Phase 58+: Plumbing integration pending
|
||||
- ✅ Phase 57: Analyzer implemented (dev-only)
|
||||
- ✅ Phase 58-59: plan_to_lowering helpers (P2/P3) with Fail-Fast relay
|
||||
- ✅ Phase 60 (dev-only): single-hop relay threading for P2 fixtures
|
||||
- `plan_to_p2_inputs_with_relay` promotes relay_writes to carriers (relay_path.len()<=1 only)
|
||||
- Frontend Break(P2) lowering uses ownership-with-relay; legacy path preserved for comparison
|
||||
- P3 stays analysis-only; real threading is Phase 61+
|
||||
|
||||
Reference in New Issue
Block a user