From d8f606a6ad8c055647bdfdbc23422e9e243ad95a Mon Sep 17 00:00:00 2001 From: tomoaki Date: Mon, 29 Dec 2025 10:21:10 +0900 Subject: [PATCH] docs(phase29ai): add P13 memoize planner call instructions --- docs/development/current/main/10-Now.md | 2 +- docs/development/current/main/30-Backlog.md | 2 +- ...ZE-FACTS-IN_SINGLE_PLANNER-INSTRUCTIONS.md | 68 +++++++++++++++++++ .../current/main/phases/phase-29ai/README.md | 5 ++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 docs/development/current/main/phases/phase-29ai/P13-PLANNER-MEMOIZE-FACTS-IN_SINGLE_PLANNER-INSTRUCTIONS.md diff --git a/docs/development/current/main/10-Now.md b/docs/development/current/main/10-Now.md index c7408bd3..32e2d726 100644 --- a/docs/development/current/main/10-Now.md +++ b/docs/development/current/main/10-Now.md @@ -2,7 +2,7 @@ ## Current Focus: Phase 29ai(Plan/Frag single-planner) -Next: `docs/development/current/main/phases/phase-29ai/P12-FACTS-PATTERN2-LOOPBODYLOCAL-PROMOTION-INSTRUCTIONS.md` +Next: `docs/development/current/main/phases/phase-29ai/P13-PLANNER-MEMOIZE-FACTS-IN_SINGLE_PLANNER-INSTRUCTIONS.md` **2025-12-29: Phase 29ai P11 完了** ✅ - 目的: Pattern2 break subset を Facts→Planner に吸収し、single_planner で planner-first を開始(仕様不変) diff --git a/docs/development/current/main/30-Backlog.md b/docs/development/current/main/30-Backlog.md index cc03cbf1..971d3c2f 100644 --- a/docs/development/current/main/30-Backlog.md +++ b/docs/development/current/main/30-Backlog.md @@ -19,7 +19,7 @@ Related: - **Phase 29ai(candidate): Plan/Frag single-planner(Facts SSOT)** - 入口: `docs/development/current/main/phases/phase-29ai/README.md` - - Next: `docs/development/current/main/phases/phase-29ai/P12-FACTS-PATTERN2-LOOPBODYLOCAL-PROMOTION-INSTRUCTIONS.md` + - Next: `docs/development/current/main/phases/phase-29ai/P13-PLANNER-MEMOIZE-FACTS-IN_SINGLE_PLANNER-INSTRUCTIONS.md` - **Phase 29ae P1(✅ COMPLETE): JoinIR Regression Pack (SSOT固定)** - 入口: `docs/development/current/main/phases/phase-29ae/README.md` diff --git a/docs/development/current/main/phases/phase-29ai/P13-PLANNER-MEMOIZE-FACTS-IN_SINGLE_PLANNER-INSTRUCTIONS.md b/docs/development/current/main/phases/phase-29ai/P13-PLANNER-MEMOIZE-FACTS-IN_SINGLE_PLANNER-INSTRUCTIONS.md new file mode 100644 index 00000000..cfa4a9cc --- /dev/null +++ b/docs/development/current/main/phases/phase-29ai/P13-PLANNER-MEMOIZE-FACTS-IN_SINGLE_PLANNER-INSTRUCTIONS.md @@ -0,0 +1,68 @@ +# Phase 29ai P13: Memoize Facts in single_planner(SSOT, 仕様不変) + +Date: 2025-12-29 +Status: Ready for execution +Scope: `single_planner` 内で Facts/Planner 呼び出しを 1 回に集約し、Pattern6/7/2 の planner-first で二重スキャンをなくす +Goal: “入口は一本” を保ったまま、Facts/Planner の実行コストと揺れを抑えて SSOT を強化する + +## Objective + +現状 `src/mir/builder/control_flow/plan/single_planner/rules.rs` は Pattern6/7/2 の各 rule で +`planner::build_plan(ctx.condition, ctx.body)` を個別に呼び出している。 + +P13 では `try_build_domain_plan()` の先頭で planner を 1 回だけ実行して結果を memoize し、各 rule ではその結果を参照する。 +これにより: +- Facts 抽出が 1 回に収束(LoopBodyLocal facts のような scan を二重実行しない) +- 観測差分を増やさず(planner `Ok(None)` でログ無し)に、planner-first の骨格を強くできる + +## Non-goals + +- planner の適用範囲拡張(機能追加) +- Freeze を実行経路で増やす(P13 は `Ok(None)` 運用を維持) +- 既存ログ/エラー文字列の変更 +- ルール順序の変更(PLAN_EXTRACTORS SSOT) + +## Implementation Steps + +### Step 1: planner を 1 回だけ呼ぶ + +ファイル: +- `src/mir/builder/control_flow/plan/single_planner/rules.rs` + +変更: +- `try_build_domain_plan()` 冒頭で以下を 1 回だけ実行し、`planner_opt: Option` を得る: + - `let planner_opt = planner::build_plan(ctx.condition, ctx.body).map_err(|f| f.to_string())?;` + +注意: +- `planner_opt` が `Some` の場合でも、各 rule で “採用できる型” 以外なら採用しない(現状の挙動を維持)。 + +### Step 2: Pattern6/7/2 は memoized planner 結果を見る + +方針: +- Pattern6: + - `planner_opt` が `Some(DomainPlan::ScanWithInit(_))` のときだけ採用 + - それ以外は legacy Pattern6 extractor +- Pattern7: + - `planner_opt` が `Some(DomainPlan::SplitScan(_))` のときだけ採用 + - それ以外は legacy Pattern7 extractor +- Pattern2: + - `planner_opt` が `Some(DomainPlan::Pattern2Break(_))` のときだけ採用 + - それ以外は legacy Pattern2 extractor + +### Step 3: 既存の debug ログ規約を維持 + +現状の方針を維持: +- planner `Ok(None)` では新規ログを出さない +- 採用時は既存の pattern 名ログを維持 + +### Step 4: SSOT verification + +- `cargo build --release` +- `./tools/smokes/v2/run.sh --profile quick` +- `./tools/smokes/v2/profiles/integration/joinir/phase29ae_regression_pack_vm.sh` + +## Notes + +P13 は「構造的に SSOT を強くする」ための最小整備で、挙動は変えない。 +次に Pattern2 LoopBodyLocal promotion を Plan 系へ吸収する(P14+)ときの土台になる。 + diff --git a/docs/development/current/main/phases/phase-29ai/README.md b/docs/development/current/main/phases/phase-29ai/README.md index 4e52446d..1f776425 100644 --- a/docs/development/current/main/phases/phase-29ai/README.md +++ b/docs/development/current/main/phases/phase-29ai/README.md @@ -75,6 +75,11 @@ Goal: pattern 名による分岐を外部APIから消し、Facts(事実)→ - 指示書: `docs/development/current/main/phases/phase-29ai/P12-FACTS-PATTERN2-LOOPBODYLOCAL-PROMOTION-INSTRUCTIONS.md` - ねらい: Pattern2 の “LoopBodyLocal promotion” を Facts として仕様化し、planner/emitter が二重に解析しない形へ寄せる(既定挙動は不変) +## P13: Memoize Facts in single_planner(SSOT) + +- 指示書: `docs/development/current/main/phases/phase-29ai/P13-PLANNER-MEMOIZE-FACTS-IN_SINGLE_PLANNER-INSTRUCTIONS.md` +- ねらい: planner 呼び出しを 1 回に収束し、Pattern6/7/2 の planner-first が二重に Facts を走らせないようにする(仕様不変) + ## Verification (SSOT) - `cargo build --release`