docs(phase29al): effect classification ssot

This commit is contained in:
2025-12-29 16:16:53 +09:00
parent 77b488b256
commit 786d2f5720
8 changed files with 182 additions and 5 deletions

View File

@ -48,6 +48,9 @@ CorePlan を骨格→特徴→合成で説明する SSOT を追加し、Freeze t
**2025-12-29: Phase 29al P1 COMPLETE (post-phi final form SSOT, docs-only)**
join 値PHI相当の最終表現layout/mapping/pred分類/verifyを 1 枚 SSOT として固定。
**2025-12-29: Phase 29al P2 COMPLETE (effect classification SSOT, docs-only)**
effect 分類Pure/Mut/Io/Controlと “許される変形” の最小法典を SSOT 化。
**2025-12-29: Phase 29aj P10 COMPLETE (single_planner unified shape)**
single_planner を全パターンで planner-first → extractor フォールバックの共通形に統一(挙動不変)。

View File

@ -2,10 +2,14 @@
## Current Focus: Phase 29alCorePlan composition hardening / docs-first
Next: Phase 29al P2effect classification SSOT
Next: Phase 29al P3ExitKind/cleanup と effect の接続: design only
運用ルール: integration filter で phase143_* は回さないJoinIR 回帰は phase29ae pack のみ)
運用ルール: phase286_pattern9_* は legacy pack (SKIP) を使う
**2025-12-29: Phase 29al P2 完了**
- 目的: effect 分類と “許される変形” の最小法典を SSOT 化(仕様不変)
- SSOT: `docs/development/current/main/design/effect-classification-ssot.md`
**2025-12-29: Phase 29al P1 完了**
- 目的: join 値PHI相当の最終表現と局所 verify を SSOT 化(仕様不変)
- SSOT: `docs/development/current/main/design/post-phi-final-form-ssot.md`

View File

@ -31,8 +31,8 @@ Related:
- **Phase 29alcandidate: CorePlan composition hardening (docs-first)**
- 入口: `docs/development/current/main/phases/phase-29al/README.md`
- 状況: P0/P1 ✅ 完了docs-only
- Next: P2effect classification SSOT
- 状況: P0/P1/P2 ✅ 完了docs-only
- Next: P3ExitKind/cleanup と effect の接続: design only
- **Phase 29aicandidate: Plan/Frag single-plannerFacts SSOT**
- 入口: `docs/development/current/main/phases/phase-29ai/README.md`

View File

@ -0,0 +1,98 @@
---
Status: SSOT
Scope: MIR/PlanFrag の effect 分類と「許される変形」法典(最適化/RC挿入/観測の安全領域)
Related:
- docs/development/current/main/design/planfrag-ssot-registry.md
- docs/development/current/main/design/coreplan-skeleton-feature-model.md
- docs/development/current/main/design/joinir-plan-frag-ssot.md
- src/mir/effect.rs
- src/mir/instruction/methods.rs
---
# Effect Classification SSOT
目的: “後段の最適化/パスが何をして良いか” を effect で固定し、JoinIR/PlanFrag/CorePlan/RC insertion/観測が相互に壊さないようにする。
この SSOT は「新しい最適化を増やす」ためではなく、**安全境界を先に定義**するためにある。
## 1. SSOT: primary categories
MIR の一次分類primary categoryは次の 4 つ。
- `Pure`: 副作用なしCSE/DCE/再順序の候補になり得る)
- `Mut`: 状態変化heap 書き込み、所有権/RC 操作、alloc など)
- `Io`: 外部効果I/O、FFI、global、debug/log、panic 等)
- `Control`: 制御効果exit/panic/throw/branch など、実行の流れに影響)
SSOT 実装:
- `src/mir/effect.rs``EffectMask::primary_category()`
## 2. SSOT: effect は “命令の意味” に属する
effect は、最適化や lowerer の都合で付け替えてはいけない。
- SSOT 実装: `MirInstruction::effects()``src/mir/instruction/methods.rs`
- 禁止: “扱いやすいから” という理由で PURE に偽装すること
## 3. PlanFrag/CorePlan の責務effect に関する境界)
### 3.1 CorePlan の effect 語彙
`CoreEffectPlan` の語彙は最小で、`MethodCall` には `EffectMask` を必ず持つ。
- 参照: `src/mir/builder/control_flow/plan/mod.rs``CoreEffectPlan`
SSOT ルール:
- `MethodCall.effects`**正しい effect** を持つ(少なくとも PURE/MUT/IO/CONTROL の一次分類が破綻しない)
- `BinOp/Compare/Const` は PUREただし panic/throw の可能性を表現する場合は Io/Control に寄せるのを別フェーズで検討)
### 3.2 JoinIR/PlanFrag の “観測” は effect ではなく運用で隔離
strict/dev のタグ観測は release 挙動を変えないことが最優先。
MIR 内に観測命令を挿入する場合は Io/Debug として扱い、最適化で消されない/動かないことを前提にする。
## 4. “許される変形” の最小法典
ここでは **SSOT の最小**のみを書く(詳細な最適化仕様は別ドキュメントで追加)。
### 4.1 DCEdead code elimination
- 削除してよい: `effects().is_pure()` かつ dst が未使用
- 削除してはいけない: 非 pureMut/Io/Controlを含む命令
実装参照:
- `src/mir/passes/dce.rs`
### 4.2 CSEcommon subexpression elimination
- 候補: `effects().is_pure()` の命令のみ(同一オペランド・同一 op
実装参照:
- `src/mir/passes/cse.rs`
### 4.3 再順序reordering
SSOT 最小ルール:
- `Io` は再順序禁止(外部観測が変わる)
- `Control` は再順序禁止CFG/exit に影響)
- `Mut` は原則再順序禁止alias/依存がないことを証明できない限り)
- `Pure` は再順序可能だが、`Control` を跨いだ移動はしない(別途 “basic block 内限定” 等で運用)
## 5. RC insertion と effect
RC insertion は “後から追加される Mut” を注入するパス。
SSOT ルール(最小):
- `ReleaseStrong` / `RetainStrong` は Mutwriteとして扱う
- DCE で消さない
- Controlreturn/exit周辺の順序は保持するcleanup の意味論固定)
参照(実装/フェーズ):
- `src/mir/passes/rc_insertion.rs`
## 6. Next
次に固めると強い補助 SSOT:
- “effect と ExitKind/cleanup” の関係unwind を含む設計)
- “panic/throw” の effect 付与Pure/Io/Control の境界を明文化)

View File

@ -212,6 +212,8 @@ MIR → [VM: MirInterpreter]
- **JoinIR Architecture Overview**: [joinir-architecture-overview.md](./joinir-architecture-overview.md) - 全体アーキテクチャのSSOT
- **JoinIR Design Map**: [joinir-design-map.md](./joinir-design-map.md) - 実装導線の地図
- **Phase 286 README**: [../phases/phase-286/README.md](../phases/phase-286/README.md) - フェーズ進捗
- Post-PHI final form: `docs/development/current/main/design/post-phi-final-form-ssot.md`
- Effect classification: `docs/development/current/main/design/effect-classification-ssot.md`
---

View File

@ -28,3 +28,4 @@ Scope: JoinIR plan/frag 導線(仕様不変)
- Pattern6/7 contracts: `docs/development/current/main/design/pattern6-7-contracts.md`
- CorePlan Skeleton/Feature model: `docs/development/current/main/design/coreplan-skeleton-feature-model.md`
- Post-PHI final form SSOT: `docs/development/current/main/design/post-phi-final-form-ssot.md`
- Effect classification SSOT: `docs/development/current/main/design/effect-classification-ssot.md`

View File

@ -0,0 +1,63 @@
---
Status: Active
Scope: docs-first仕様不変
Related:
- docs/development/current/main/phases/phase-29al/README.md
- docs/development/current/main/design/effect-classification-ssot.md
- src/mir/effect.rs
---
# Phase 29al P2: Effect classification SSOTdocs-first
Date: 2025-12-29
Status: Ready for execution
Scope: effect 分類と最小の変形規約を SSOT 化する(仕様不変)
## Objective
- “どの変形が許されるか” を effect で固定し、JoinIR/PlanFrag/CorePlan/最適化/RC insertion が相互に壊さない境界を作る
- 実装者が `PURE` を都合で付け替える事故を防ぐSSOT + 参照導線)
## Non-goals
- 新しい最適化の追加
- 既存の effect 実装変更(コードは触らない)
- 新 env var 追加
- release 挙動/ログの変更
## Steps
### Step 1: effect SSOT を design に追加
Add:
- `docs/development/current/main/design/effect-classification-ssot.md`
Must include:
- primary categoriesPure/Mut/Io/Control
- PlanFrag/CorePlan の effect 境界(`CoreEffectPlan::MethodCall.effects` 等)
- “許される変形” の最小法典DCE/CSE/再順序)
- RC insertion と effect の扱い(削除禁止・順序保持)
### Step 2: 参照導線を追加
Update:
- `docs/development/current/main/design/planfrag-ssot-registry.md`
- 必要なら `docs/development/current/main/design/joinir-plan-frag-ssot.md` に関連リンク
### Step 3: Phase 入口と運用を更新
Update:
- `docs/development/current/main/phases/phase-29al/README.md`
- `docs/development/current/main/10-Now.md`
- `docs/development/current/main/30-Backlog.md`
- `CURRENT_TASK.md`
## Verification
- docs-only のため必須なし
- 任意: `./tools/smokes/v2/profiles/integration/joinir/phase29ae_regression_pack_vm.sh`
## Commit
- `git add -A && git commit -m "docs(phase29al): effect classification ssot"`

View File

@ -24,8 +24,14 @@ Goal: “pattern が重なる/増殖する” を設計で根治し、JoinIR/Pla
- 指示書: `docs/development/current/main/phases/phase-29al/P1-POST-PHI-FINAL-FORM-SSOT-INSTRUCTIONS.md`
- SSOT: `docs/development/current/main/design/post-phi-final-form-ssot.md`
## P2: effect classification SSOTdocs-first
- ねらい: effect 分類と “許される変形” を SSOT 化し、最適化/RC insertion/観測が相互に壊さない境界を固定する
- 指示書: `docs/development/current/main/phases/phase-29al/P2-EFFECT-CLASSIFICATION-SSOT-INSTRUCTIONS.md`
- SSOT: `docs/development/current/main/design/effect-classification-ssot.md`
## Next (planned)
### P2: effect classification SSOT
### P3: ExitKind/cleanup と effect の接続design only
- ねらい: pure/control/rc/observability などの効果分類と、許される変形(最適化/RC挿入/DCEを法典化する
- ねらい: unwind を含む将来拡張のために、cleanup と effect の順序条件を SSOT 化する