docs(phase29aa): add P0 CFG-aware design and link from 29z

This commit is contained in:
2025-12-27 15:38:18 +09:00
parent a916066631
commit b895f67e07
5 changed files with 147 additions and 5 deletions

View File

@ -1,6 +1,12 @@
# Self Current Task — Now (main)
## Current Focus: Phase 29z P0RC insertion minimal
## Current Focus: Phase 29aa P0RC insertion safety expansion, design-first
**2025-12-27: Phase 29aa P0 Readydesign-first**
- 目的: rc_insertion を CFG-aware に拡張するための設計を固定誤release防止
- 内容: RcPlan解析→挿入の二段階設計、PHI/loop/early-exit の危険パターン整理、release安全条件の契約
- P1 最小ターゲット: Return 終端 cleanup の RcPlan 経由化Branch/Jump は禁止継続)
- 入口: `docs/development/current/main/phases/phase-29aa/P0-RC_INSERTION_CFG_AWARE_DESIGN-INSTRUCTIONS.md`
**2025-12-27: Phase 29z P1 完了**
- `src/mir/passes/rc_insertion.rs`: `Store` 上書き + `Store null`explicit drop+ Return終端cleanup の最小 release 挿入単一block・安全ガード

View File

@ -68,6 +68,11 @@ Related:
- 入口: `docs/development/current/main/phases/phase-29z/README.md`
- 指示書: `docs/development/current/main/phases/phase-29z/P0-RC_INSERTION_MINIMAL-INSTRUCTIONS.md`
- **Phase 29aaP0 design-first: RC insertion safety expansionCFG-aware**
- 目的: rc_insertion を CFG-aware に拡張する前提設計を固定誤release防止
- P0最小成果: RcPlanblock/edge構造、PHI/loop/early-exit 危険パターン整理、release安全条件の契約
- 入口: `docs/development/current/main/phases/phase-29aa/README.md`
- **Phase 29xplanned, post self-host: De-Rust runtime for LLVM execution**
- 目的: LLVM 実行経路のランタイム依存を段階的に Rust から切り離す脱Rust
- 前提: self-host ラインが安定し、VM/LLVM conformancePhase 285が十分に固まっていること。

View File

@ -0,0 +1,109 @@
# Phase 29aa P0: RC insertion safety expansion — CFG-aware design
**Date**: 2025-12-27
**Status**: Ready (design-first)
**Scope**: `src/mir/passes/rc_insertion.rs` を CFG-aware に拡張するための設計。Branch/Jump/PHI/loop/early-exit を安全に扱う前提を固める。
**SSOT**: `docs/development/current/main/phases/phase-29y/20-RC-INSERTION-SSOT.md`
---
## 目的
- Phase 29z の「単一block限定」実装を、誤releaseを起こさない形で次段へ進める。
- “SSA last-use で drop する” を禁止したまま、CFG-aware の設計を確定する。
- 解析→挿入を二段階に分離し、後続の安全条件・Fail-Fast を明文化する。
## 非目的
- 既定挙動変更feature `rc-insertion-minimal` 以外は no-op 維持)
- SSA last-use ベースの drop
- いきなり全ケース実装
---
## 設計タスクP0
### 1) RcPlan のデータ構造案block/edge
**目的**: Stage A (分析) が Stage B (挿入) に渡す、最小かつ安全な「release 予定表」を決める。
提案:
```text
RcPlan
- block_sites: Vec<BlockPlan>
- edge_sites: Vec<EdgePlan>
BlockPlan
- block_id: BlockId
- drops: Vec<DropSite>
EdgePlan
- from: BlockId
- to: BlockId
- drops: Vec<DropSite>
DropSite
- kind: DropKind // Overwrite | ExplicitNull | ScopeEnd(ReturnOnly)
- value_id: ValueId
- binding_id: BindingId
- at: DropPoint // BeforeInstr(index) | BeforeTerminator
- proof: ProofTag // SafeCurrentValue | ExplicitNull | Overwrite
```
方針:
- **block_sites** は “局所で安全が確定できる release” のみを置く。
- **edge_sites** は “スコープが閉じる edge” の cleanup を載せるが、P1 では Return 専用に限定する。
- Stage B は `DropSite``proof``kind` を必ず検査し、未対応のものは Fail-Fast する。
### 2) PHI/loop/early-exit の危険パターンFail-Fast 方針)
Fail-Fast 原則: **安全条件を証明できない場合は release を挿入しない**。必要なら debug_assert/diagnostic を出す。
危険パターン(例):
- PHI 入力値を release してしまうbinding の current value と一致しない)
- loop back-edge が絡む binding を loop body 終端で release する
- early-exitreturn/break/continueで閉じるスコープが曖昧なまま cleanup を入れる
- edge ごとにスコープ閉鎖が異なるのに、block 終端で一括 release する
Fail-Fast ポリシー:
- `binding current value` との一致が証明できない DropSite は **計画に載せない**
- `edge cleanup` は「閉じるスコープが確定した edge」に限定し、未確定なら no-op + 診断opt-inのみ
### 3) 安全に release できる条件(契約)
**契約**: release できるのは “binding が保持している current value” のみ。
許可条件:
- `x = <new>` の直前に、`x`**旧値** を releaseOverwrite
- `x = null` の直前に、`x`**旧値** を releaseExplicitNull
- **Return 終端**で閉じる binding scope の current value を releaseScopeEnd/ReturnOnly
禁止条件:
- SSA last-use を根拠に release
- PHI の入力値current value と一致しない限り禁止)
- loop/edge のスコープ閉鎖が確定していない cleanup
### 4) 次P1の最小実装ターゲット1つだけ
**P1 でやること**: Return 終端の cleanup を RcPlan 経由で行うBranch/Jump は引き続き禁止)。
- Stage A: Return 終端の scope end だけを `BlockPlan` に載せる
- Stage B: `DropSite(kind=ScopeEnd(ReturnOnly))` のみ挿入
- Branch/Jump/PHI/loop/early-exit は **no-op + Fail-Fast guard** を維持
---
## ドキュメント更新(必須)
- `docs/development/current/main/phases/phase-29z/README.md` に次フェーズ入口と残課題の分類を追記
- `docs/development/current/main/10-Now.md` の Current Focus を Phase 29aa P0 に更新
- `docs/development/current/main/30-Backlog.md` に Phase 29aa を追加最小3項目
---
## 受け入れ基準
- docs-onlyコード変更なし
- quick 154/154 PASS 維持(確認のみ)
- 「安全に release できる条件」が契約として明文化されている

View File

@ -0,0 +1,19 @@
# Phase 29aa: RC insertion safety expansionCFG-aware design
Status: P0 Ready (design-first)
Scope: Phase 29z の単一block限定実装から、誤releaseを起こさない形で CFG-aware に拡張するための設計を固める。
Entry:
- SSOT: `docs/development/current/main/phases/phase-29y/20-RC-INSERTION-SSOT.md`
- 指示書: `docs/development/current/main/phases/phase-29aa/P0-RC_INSERTION_CFG_AWARE_DESIGN-INSTRUCTIONS.md`
Non-goals:
- 既定挙動変更feature `rc-insertion-minimal` 以外は no-op 維持)
- SSA last-use を根拠にした drop
- いきなり全ケース実装(設計+最小プロトタイプを優先)
Deliverables (P0):
- RcPlan解析→挿入の二段階設計
- PHI/loop/early-exit の危険パターン整理と Fail-Fast 方針
- release 安全条件の契約
- P1 で実装する最小ターゲットを 1 個に絞る

View File

@ -19,7 +19,10 @@ Progress:
- P1: explicit dropStore nullを最小対応
- P2: closeoutReturn終端のcleanup追加、残課題を整理
Next Steps持ち越し事項:
- null 伝搬の精度向上copy以外の伝搬パターンを段階的に追加
- block終端cleanupの拡張: Return以外Branch/Jumpで安全に扱えるかの設計
- PHI/loop/early-exit の安全な cleanup 設計(誤 release 防止)
Next Phase:
- Phase 29aa P0: `docs/development/current/main/phases/phase-29aa/P0-RC_INSERTION_CFG_AWARE_DESIGN-INSTRUCTIONS.md`
Residuals分類:
- Design: CFG-aware RcPlanblock/edge 単位)の契約と Fail-Fast 方針、PHI/loop/early-exit の危険パターン整理、Branch/Jump 終端 cleanup 設計
- Implementation: rc_insertion の解析→挿入二段階分離、null 伝搬の精度向上copy以外の伝搬パターン追加、Return 終端 cleanup の RcPlan 経由化
- Verification: quick 154/154 PASS 維持既定OFF+ `rc_insertion_selfcheck` opt-in 確認