docs(phase93): Phase 93 P0完了記録 & ドキュメント整理
## 追加 - docs/development/current/main/phases/phase-93/README.md - Phase 93 P0 (ConditionOnly Derived Slot) 完了記録 - 実装内容・テスト結果の詳細 ## 更新 - CURRENT_TASK.md: Phase 93 P0完了に伴う更新 - 10-Now.md: 現在の進捗状況更新 - 30-Backlog.md: Phase 92/93関連タスク整理 - phase-91/92関連ドキュメント: historical化・要約化 ## 削減 - 735行削減(historical化により詳細をREADMEに集約) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
146
CURRENT_TASK.md
146
CURRENT_TASK.md
@ -1,143 +1,7 @@
|
|||||||
# Current Task
|
# CURRENT_TASK (moved)
|
||||||
|
|
||||||
このファイルは「いま何に集中しているか」と「次にやり得る候補」だけを書く軽量ビューだよ。
|
Status: SSOT
|
||||||
詳細は `docs/development/current/main/` 以下の各 Phase 文書と、JoinIR の SSOT である
|
Scope: Repo root の旧リンク互換。現行の入口は `docs/development/current/main/10-Now.md`。
|
||||||
`docs/development/current/main/joinir-architecture-overview.md` を参照してね。
|
|
||||||
|
|
||||||
最終更新: 2025-12-16
|
- Now: `docs/development/current/main/10-Now.md`
|
||||||
|
- Backlog: `docs/development/current/main/30-Backlog.md`
|
||||||
過去ログ(肥大化した旧 CURRENT_TASK)はここに退避したよ:
|
|
||||||
- `docs/development/current/main/CURRENT_TASK_ARCHIVE_2025-12-13.md`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 今の状態(Phase 74–90 まで到達)
|
|
||||||
|
|
||||||
- Scope/BindingId の段階移行(dev-only)は Pattern2/3/4 まで配線済み(dual-path 維持)。
|
|
||||||
- Pattern2 の promoted carriers(DigitPos/Trim)について ExitLine 契約(ConditionOnly を exit PHI から除外)を E2E で固定済み。
|
|
||||||
- debug flag SSOT / DebugOutputBox 移行 / error tags 集約 / carrier init builder まで整備済み。
|
|
||||||
- **LLVM exe line SSOT 確立**: `tools/build_llvm.sh` を使用した .hako → executable パイプライン標準化完了。
|
|
||||||
- **LLVM AOT(Python llvmlite)ループ復旧**: `apps/tests/loop_min_while.hako` が EMIT/LINK/RUN まで到達(Phase 131-3..10)。
|
|
||||||
- Case C(`loop(true)` + break/continue)は Phase 131-11 で Pattern/shape guard を整備し、Phase 132-P2 で LLVM EXE まで parity(`Result: 3`)を確認。
|
|
||||||
- **Phase 132 完了**: ループ exit 値(exit PHI / boundary)の VM/LLVM parity を根治。
|
|
||||||
- JoinIR/Boundary: exit 値を境界に明示的に渡す
|
|
||||||
- LLVM Python: PHI を落とす/上書きする経路を除去(PHI SSOT を保護)
|
|
||||||
- JoinIR merge: exit PHI dst の allocator を function-level に統一(ValueId 衝突を排除)
|
|
||||||
- debug-only: Exit PHI collision を早期検出する verifier を追加(LLVM 実行時に壊れる前に Fail-Fast)
|
|
||||||
- **Phase 133 完了**: Promoted carrier の `join_id` 解決(Trim)を SSOT に寄せて根治(smoke は compile-only)。
|
|
||||||
- **Phase 134 完了**: Plugin loader best-effort loading(決定的順序 + failure 集約 + 継続)を導入。
|
|
||||||
- **Phase 135 完了**: ConditionLoweringBox allocator SSOT(P0: 根治修正 + P1: contract_checks Fail-Fast 強化)。
|
|
||||||
- **Phase 136 完了**: MirBuilder Context SSOT 化(+ ValueId allocator 掃討)。
|
|
||||||
- **Phase 137-141 完了**: Loop Canonicalizer(前処理 SSOT)を実装・箱化・型安全化・統合・ドキュメントまで完了(既定挙動は不変)。
|
|
||||||
- **Phase 91 完了**: P5b escape(recognition + parity)まで完了。
|
|
||||||
- **Phase 92 進行中**: P5b escape の lowering(ConditionalStep emitter 箱化まで完了)。
|
|
||||||
- **Phase 88 完了**: continue + 可変ステップ(i=i+const 差分)を dev-only fixture で固定、StepCalculator Box 抽出。
|
|
||||||
- **Phase 89 完了**: P0(ContinueReturn detector)+ P1(lowering 実装)完了。
|
|
||||||
- **Phase 90 完了**: ParseStringComposite + `Null` literal + ContinueReturn(同一値の複数 return-if)を dev-only fixture で固定。
|
|
||||||
- `cargo test --release --lib` は PASS を維持(993 passed、退行なし)。
|
|
||||||
|
|
||||||
参照:
|
|
||||||
- `docs/development/current/main/10-Now.md`
|
|
||||||
- `docs/development/current/main/phase86-90-loop-frontends-summary.md`
|
|
||||||
- `docs/development/current/main/phase73-scope-manager-design.md`
|
|
||||||
- `docs/development/current/main/phase80-bindingid-p3p4-plan.md`
|
|
||||||
- `docs/development/current/main/phase81-pattern2-exitline-contract.md`
|
|
||||||
- `docs/development/current/main/phase78-85-boxification-feedback.md`
|
|
||||||
- `docs/development/current/main/phase87-selfhost-llvm-exe-line.md`
|
|
||||||
- `docs/development/current/main/phase131-2-box-resolution-map.md`
|
|
||||||
- `docs/development/current/main/phase131-3-llvm-lowering-inventory.md`
|
|
||||||
- `docs/development/current/main/phase131-5-taglink-fix-summary.md`
|
|
||||||
- `docs/development/current/main/phases/phase-132/README.md`
|
|
||||||
- `docs/development/current/main/investigations/phase132-llvm-exit-phi-wrong-result.md`
|
|
||||||
- `docs/development/current/main/investigations/phase132-case-c-llvm-exe.md`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 次の指示書(優先順位)
|
|
||||||
|
|
||||||
### P0: Phase 92 P2(P5b E2E を 1 本通す)
|
|
||||||
|
|
||||||
**状態**: ✅ P1 完了、P2 へ
|
|
||||||
|
|
||||||
**目的**: `ConditionalStep` を Pattern2 lowering で実際に使い、`test_pattern5b_escape_minimal.hako` を E2E(まずは VM)で通す。
|
|
||||||
|
|
||||||
SSOT:
|
|
||||||
- `docs/development/current/main/design/loop-canonicalizer.md`
|
|
||||||
実装:
|
|
||||||
- `src/mir/loop_canonicalizer/mod.rs`
|
|
||||||
(SSOT入口)
|
|
||||||
- `src/mir/builder/control_flow/joinir/routing.rs`(`choose_pattern_kind`)
|
|
||||||
Phase 記録:
|
|
||||||
- `docs/development/current/main/phases/phase-92/README.md`
|
|
||||||
|
|
||||||
**次に触るSSOT**:
|
|
||||||
- Loop系の設計: `docs/development/current/main/joinir-architecture-overview.md`
|
|
||||||
|
|
||||||
注意:
|
|
||||||
- 既定挙動は変えない(dev-only で観測→段階投入)
|
|
||||||
- 新しい環境変数は増やさない(`joinir_dev_enabled()` の範囲で観測する)
|
|
||||||
|
|
||||||
### P1: JoinIR / Selfhost depth-2 の前進(Phase 91 - 設計完了)
|
|
||||||
|
|
||||||
**状態**: ✅ **Phase 91 計画完了** → 次は実装フェーズ
|
|
||||||
|
|
||||||
**目的**: Selfhost コンパイラの未対応ループを JoinIR 対象に拡大
|
|
||||||
|
|
||||||
**成果(Phase 91 Step 1)**:
|
|
||||||
- ✅ ループ在庫分析: 34ループ across 6ファイル(47% JoinIR対応)
|
|
||||||
- ✅ Pattern P5b (Escape Handling) デザイン完成
|
|
||||||
- ✅ テストフィクスチャ作成 (`test_pattern5b_escape_minimal.hako`)
|
|
||||||
- ✅ Capability 拡張(P5b専用タグ)
|
|
||||||
|
|
||||||
**優先順位**:
|
|
||||||
1. **P5b (Escape Handling)** - `json_loader.hako:30` (8行)
|
|
||||||
- Effort: 2-3日
|
|
||||||
- Impact: JSON/CSV パーサー全般を JoinIR 対応可能に
|
|
||||||
- Status: 設計完了、実装待ち
|
|
||||||
|
|
||||||
2. **P5 (Guard-Bounded)** - `mini_vm_core.hako:541` (204行)
|
|
||||||
- Effort: 1-2週
|
|
||||||
- Impact: 大規模ループ最適化(guard counter除去)
|
|
||||||
- Status: 分析完了、設計待ち
|
|
||||||
|
|
||||||
3. **P6 (Nested Loops)** - `seam_inspector.hako:76` (7+ levels)
|
|
||||||
- Effort: 2-3週
|
|
||||||
- Impact: 深い入れ子対応(将来)
|
|
||||||
- Status: 候補識別完了
|
|
||||||
|
|
||||||
**次に触るSSOT**:
|
|
||||||
- Phase 91 詳細計画: `docs/development/current/main/phases/phase-91/README.md`
|
|
||||||
- P5b デザイン: `docs/development/current/main/design/pattern-p5b-escape-design.md`
|
|
||||||
- Loop Canonicalizer: `docs/development/current/main/design/loop-canonicalizer.md`
|
|
||||||
|
|
||||||
**Phase 91 Step 2 (次)**: Canonicalizer 実装
|
|
||||||
1. `detect_escape_pattern()` 関数追加
|
|
||||||
2. Unit tests (P5b 認識)
|
|
||||||
3. Parity verification (strict mode)
|
|
||||||
4. Documentation 更新
|
|
||||||
|
|
||||||
受け入れ基準:
|
|
||||||
- ✅ P5b パターン認識で `decision.chosen == Pattern5bEscape`
|
|
||||||
- ✅ `missing_caps == []`(すべての capability 充足)
|
|
||||||
- ✅ `HAKO_JOINIR_STRICT=1` で parity green
|
|
||||||
- ✅ 既存テスト退行なし
|
|
||||||
|
|
||||||
### P2: Ownership/Relay runtime 対応の再開(Phase 92 候補)
|
|
||||||
|
|
||||||
目的:
|
|
||||||
- multihop/merge relay を “runtime でも” 受理できるところまで契約を伸ばす(Fail-Fast の段階解除)。
|
|
||||||
|
|
||||||
受け入れ基準:
|
|
||||||
- dev-only 既定OFF のまま、既存ラインを壊さない。
|
|
||||||
|
|
||||||
### Done: Phase 86–90(Loop frontends)
|
|
||||||
|
|
||||||
- まとめ(SSOT): `docs/development/current/main/phase86-90-loop-frontends-summary.md`
|
|
||||||
- MirBuilder の入口(Context 分割): `src/mir/builder/README.md` + `docs/development/current/main/01-JoinIR-Selfhost-INDEX.md`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## すぐ走らせる確認コマンド
|
|
||||||
|
|
||||||
- `cargo test --release --lib`
|
|
||||||
- `NYASH_JOINIR_NORMALIZED_DEV_RUN=1 cargo test --features normalized_dev --test normalized_joinir_min -- --nocapture`
|
|
||||||
|
|||||||
@ -43,6 +43,8 @@ JoinIR の箱構造と責務、ループ/if の lowering パターンを把握
|
|||||||
5. Loop Canonicalizer(設計 SSOT)
|
5. Loop Canonicalizer(設計 SSOT)
|
||||||
- `docs/development/current/main/design/loop-canonicalizer.md`
|
- `docs/development/current/main/design/loop-canonicalizer.md`
|
||||||
- 実装(Phase 137-2): `src/mir/loop_canonicalizer/mod.rs`
|
- 実装(Phase 137-2): `src/mir/loop_canonicalizer/mod.rs`
|
||||||
|
6. Phase 93: ConditionOnly Derived Slot(Trim / body-local)
|
||||||
|
- `docs/development/current/main/phases/phase-93/README.md`
|
||||||
6. MIR Builder(Context 分割の入口)
|
6. MIR Builder(Context 分割の入口)
|
||||||
- `src/mir/builder/README.md`
|
- `src/mir/builder/README.md`
|
||||||
7. Scope/BindingId(shadowing・束縛同一性の段階移行)
|
7. Scope/BindingId(shadowing・束縛同一性の段階移行)
|
||||||
|
|||||||
@ -36,8 +36,18 @@
|
|||||||
|
|
||||||
## 2025‑12‑16:Phase 92(短報)
|
## 2025‑12‑16:Phase 92(短報)
|
||||||
|
|
||||||
- P5b escape の lowering を進行中。P1 で `ConditionalStep` emitter を箱化して、Pattern2 本体の肥大化を防いだ。
|
- Phase 92(ConditionalStep / P5b escape の lowering 基盤)は完了。
|
||||||
- Phase 記録: `docs/development/current/main/phases/phase-92/README.md`
|
- 条件付き更新(`ConditionalStep`)のJoinIR表現 + Pattern2 側の委譲(emitter 箱化)
|
||||||
|
- 条件式での body-local 参照(`ConditionEnv → LoopBodyLocalEnv`)+ 最小E2E smoke 固定
|
||||||
|
- Phase 記録(SSOT入口): `docs/development/current/main/phases/phase-92/README.md`
|
||||||
|
- 残: P5b の “完全E2E” は body-local promotion 拡張後(スコープ外で保留)
|
||||||
|
|
||||||
|
## 2025‑12‑16:Phase 93(短報)
|
||||||
|
|
||||||
|
- Trim の `is_ch_match` など「ConditionOnly(PHIで運ばない派生値)」を Derived Slot として毎イテレーション再計算できるようにした。
|
||||||
|
- SSOT: `ConditionOnlyRecipe`(運搬禁止)+ `ConditionOnlyEmitter`
|
||||||
|
- schedule: `body-init → derived → break` を評価順SSOTとして強制
|
||||||
|
- Phase 記録(入口): `docs/development/current/main/phases/phase-93/README.md`
|
||||||
|
|
||||||
## 2025‑12‑14:現状サマリ
|
## 2025‑12‑14:現状サマリ
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +1,27 @@
|
|||||||
# Self Current Task — Backlog (main)
|
# Self Current Task — Backlog (main)
|
||||||
|
|
||||||
直近のループ前線(Phase 86–90, dev-only fixtures)は完了し、状況は `docs/development/current/main/10-Now.md` と
|
Status: Active
|
||||||
`docs/development/current/main/phase86-90-loop-frontends-summary.md` に集約したよ。
|
Scope: 「次にやる候補」を短く列挙するメモ。現状は `docs/development/current/main/10-Now.md` を入口にする。
|
||||||
|
Related:
|
||||||
|
- `docs/development/current/main/10-Now.md`
|
||||||
|
- `docs/development/current/main/DOCS_LAYOUT.md`
|
||||||
|
|
||||||
設計検討(docs-only, まだ未決定):
|
## 直近(JoinIR/selfhost)
|
||||||
- Loop Canonicalizer / LoopSkeleton(組み合わせ爆発を抑える前処理パス)
|
|
||||||
- Loop Corpus Extractor(実コード抽出→差分検知で fixture 化を支援)
|
|
||||||
|
|
||||||
短期(JoinIR/selfhost ライン 第3章 - LLVM統合)
|
- **P5b “完全E2E”**(escape skip の実ループを end-to-end で固定)
|
||||||
- ✅ Phase 130: JoinIR → LLVM ベースライン確立(完了 2025-12-04)
|
- 現状: 認識(Phase 91)+ lowering基盤(Phase 92)は完了、promotion が未整備で E2E を保留
|
||||||
- 🎯 **Phase 131: JoinIR→LLVM 個別修正ライン**(次の最優先タスク)
|
- 入口: `docs/development/current/main/phases/phase-92/README.md`
|
||||||
- 優先度1: LLVM Backend有効化(`--features llvm` ビルド、実LLVM実行)
|
- **制御の再帰合成(docs-only → dev-only段階投入)**
|
||||||
- 優先度2: ConsoleBox問題解決(Rust VM登録問題の根治)
|
- ねらい: `loop/if` ネストの “構造” を SSOT(ControlTree/StepTree)で表せるようにする
|
||||||
- 優先度3: LLVM IR生成確認(MIR → LLVM lowering実装状況調査)
|
- 注意: canonicalizer は観測/構造SSOTまで(ValueId/PHI配線は Normalized 側へ)
|
||||||
- selfhost Stage‑3 代表パスの LLVM 実行(7テストケースを実LLVM経由で検証)
|
- 入口: `docs/development/current/main/design/loop-canonicalizer.md`
|
||||||
|
|
||||||
完了済み(JoinIR/selfhost ライン 第2章)
|
## 中期(ループ在庫の残り)
|
||||||
- ✅ selfhost Stage‑3 代表パスの安定化(Phase 120完了)
|
|
||||||
- ✅ `hako_check` ラインの JoinIR 統合(Phase 121-124完了)
|
|
||||||
- ✅ CURRENT_TASK / Phase docs 更新完了
|
|
||||||
|
|
||||||
中期
|
- **P5(guard-bounded)**: 大型ループを “小粒度” に割ってから取り込む(分割 or 新契約)
|
||||||
- VInvoke(vector)戻り型の正道化(toml 記述 or NyRT 期待フラグ)。
|
- **P6(nested loops)**: capability guard で Fail-Fast 維持しつつ、解禁時の契約を先に固定
|
||||||
- wasm/Web デモライン: JoinIR ベースの軽量ランタイム検証。
|
|
||||||
|
|
||||||
周辺
|
## ドキュメント運用
|
||||||
- Ny ツール側(selfhost-compiler / hako_check / 各種 CLI)のログ・エラー体験を、Ring0/ConsoleService 上で整える。
|
|
||||||
- docs 更新(言語ガイド + JoinIR ガイドに selfhost 代表フローを追記)。
|
- 重複が出たら「設計 SSOT(design)」に集約し、Phaseログ(phases)は “何をやったか/検証したか” に限定する
|
||||||
|
- 調査ログ(investigations)は結論を SSOT に反映してから Historical 化する
|
||||||
|
|||||||
@ -106,6 +106,7 @@ flowchart LR
|
|||||||
- Trace(JoinIR ルートの統一トレース): [`src/mir/builder/control_flow/joinir/trace.rs`](../../../../../src/mir/builder/control_flow/joinir/trace.rs)
|
- Trace(JoinIR ルートの統一トレース): [`src/mir/builder/control_flow/joinir/trace.rs`](../../../../../src/mir/builder/control_flow/joinir/trace.rs)
|
||||||
- Error tags(SSOT): [`src/mir/join_ir/lowering/error_tags.rs`](../../../../../src/mir/join_ir/lowering/error_tags.rs)
|
- Error tags(SSOT): [`src/mir/join_ir/lowering/error_tags.rs`](../../../../../src/mir/join_ir/lowering/error_tags.rs)
|
||||||
- Loop Canonicalizer(前処理 SSOT): [`src/mir/loop_canonicalizer/mod.rs`](../../../../../src/mir/loop_canonicalizer/mod.rs)
|
- Loop Canonicalizer(前処理 SSOT): [`src/mir/loop_canonicalizer/mod.rs`](../../../../../src/mir/loop_canonicalizer/mod.rs)
|
||||||
|
- ConditionOnly Derived Slot(Phase 93): [`src/mir/join_ir/lowering/common/condition_only_emitter.rs`](../../../../../src/mir/join_ir/lowering/common/condition_only_emitter.rs)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -441,115 +441,19 @@ loop(p < len) {
|
|||||||
|
|
||||||
## 対象ループ 2: Pattern P5b - Escape Sequence Handling(Phase 91 新規)
|
## 対象ループ 2: Pattern P5b - Escape Sequence Handling(Phase 91 新規)
|
||||||
|
|
||||||
### 目的
|
### 目的(要約)
|
||||||
|
|
||||||
エスケープシーケンス対応ループを JoinIR 対象に拡大する。JSON/CSV パーサーの文字列処理で共通パターン。
|
エスケープ処理を含む文字列走査ループ(例: JSON/CSV の `\\`)を、**パターン増殖なし**で段階的に JoinIR に取り込む。
|
||||||
|
|
||||||
### 対象ファイル
|
この系は「常に `+1` の通常進行」と「条件が真のときだけ追加で `+1`(合計 `+2` 相当)」が混ざるため、Canonicalizer 側では
|
||||||
|
`UpdateKind::ConditionalStep { cond, then_delta, else_delta }` として表現し、下流の lowerer 選択は **`Pattern2Break`(exit contract 優先)**に寄せる。
|
||||||
|
|
||||||
`tools/selfhost/test_pattern5b_escape_minimal.hako`
|
### SSOT(詳細はここへ集約)
|
||||||
|
|
||||||
```hako
|
- **設計 SSOT**: `docs/development/current/main/design/pattern-p5b-escape-design.md`
|
||||||
loop(i < n) {
|
- **Phaseログ(認識)**: `docs/development/current/main/phases/phase-91/README.md`
|
||||||
local ch = s.substring(i, i+1)
|
- **Phaseログ(lowering/条件式対応)**: `docs/development/current/main/phases/phase-92/README.md`
|
||||||
|
- **fixture**: `tools/selfhost/test_pattern5b_escape_minimal.hako`
|
||||||
if ch == "\"" { break } // String boundary
|
|
||||||
|
|
||||||
if ch == "\\" {
|
|
||||||
i = i + 1 // Skip escape character (conditional +2 total)
|
|
||||||
ch = s.substring(i, i+1) // Read escaped character
|
|
||||||
}
|
|
||||||
|
|
||||||
out = out + ch // Process character
|
|
||||||
i = i + 1 // Standard increment
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Pattern P5b の特徴
|
|
||||||
|
|
||||||
| 特性 | 説明 |
|
|
||||||
|-----|------|
|
|
||||||
| **Header** | `loop(i < n)` - Bounded loop on string length |
|
|
||||||
| **Escape Check** | `if ch == escape_char { i = i + escape_delta }` |
|
|
||||||
| **Normal Increment** | `i = i + 1` (always +1) |
|
|
||||||
| **Accumulator** | `out = out + char` - String append pattern |
|
|
||||||
| **Boundary** | `if ch == boundary { break }` - String terminator |
|
|
||||||
| **Carriers** | Position (`i`), Accumulator (`out`) |
|
|
||||||
| **Deltas** | normal_delta=1, escape_delta=2 (or variable) |
|
|
||||||
|
|
||||||
### 必要 Capability (P5b 拡張)
|
|
||||||
|
|
||||||
- ✅ `ConstStepIncrement` (normal: i = i + 1)
|
|
||||||
- ✅ `SingleBreakPoint` (boundary check only)
|
|
||||||
- ✅ `NoSideEffectInHeader` (i < n は pure)
|
|
||||||
- ✅ `OuterLocalCondition` (i, n は外側定義)
|
|
||||||
- ✅ **`ConstEscapeDelta`** (escape: i = i + 2, etc.) - **P5b 専用**
|
|
||||||
- ✅ **`SingleEscapeCheck`** (one escape pattern only) - **P5b 専用**
|
|
||||||
- ✅ **`ClearBoundaryCondition`** (explicit boundary detection) - **P5b 専用**
|
|
||||||
|
|
||||||
### Fail-Fast 基準 (P5b 非対応のケース)
|
|
||||||
|
|
||||||
以下のいずれかに該当する場合、Fail-Fast:
|
|
||||||
|
|
||||||
1. **複数エスケープチェック**: `if ch == "\\" ... if ch2 == "'" ...`
|
|
||||||
- 理由: `CAP_MISSING_SINGLE_ESCAPE_CHECK`
|
|
||||||
|
|
||||||
2. **可変ステップ**: `i = i + var` (定数でない)
|
|
||||||
- 理由: `CAP_MISSING_CONST_ESCAPE_DELTA`
|
|
||||||
|
|
||||||
3. **無条件に近いループ**: `loop(true)` without clear boundary
|
|
||||||
- 理由: `CAP_MISSING_CLEAR_BOUNDARY_CONDITION`
|
|
||||||
|
|
||||||
4. **複数 break 点**: String boundary + escape processing で exit
|
|
||||||
- 理由: `CAP_MISSING_SINGLE_BREAK`
|
|
||||||
|
|
||||||
### 認識アルゴリズム (高レベル)
|
|
||||||
|
|
||||||
```
|
|
||||||
1. Header carrier 抽出: loop(i < n) から i を取得
|
|
||||||
2. Escape check block 発見: if ch == "\" { ... }
|
|
||||||
3. Escape delta 抽出: i = i + const
|
|
||||||
4. Accumulator パターン発見: out = out + ch
|
|
||||||
5. Normal increment 抽出: i = i + 1 (escape if block 外)
|
|
||||||
6. Boundary check 発見: if ch == "\"" { break }
|
|
||||||
7. LoopSkeleton 構築
|
|
||||||
- carriers: [i (dual deltas), out (append)]
|
|
||||||
- exits: has_break=true
|
|
||||||
8. RoutingDecision: Pattern5bEscape
|
|
||||||
```
|
|
||||||
|
|
||||||
### 実装予定 (Phase 91)
|
|
||||||
|
|
||||||
**Step 1** (このドキュメント):
|
|
||||||
- [ ] Pattern P5b 設計書完成 ✅
|
|
||||||
- [ ] テストフィクスチャ作成 ✅
|
|
||||||
- [ ] Capability 定義追加 ✅
|
|
||||||
|
|
||||||
**Step 2** (Phase 91 本実装):
|
|
||||||
- [ ] `detect_escape_pattern()` in Canonicalizer
|
|
||||||
- [ ] Unit tests (P5b recognition)
|
|
||||||
- [ ] Parity verification (strict mode)
|
|
||||||
- [ ] Documentation update
|
|
||||||
|
|
||||||
**Step 3** (Phase 92 lowering):
|
|
||||||
- [ ] Pattern5bEscape lowerer 実装
|
|
||||||
- [ ] E2E test with escape fixture
|
|
||||||
- [ ] VM/LLVM parity verification
|
|
||||||
|
|
||||||
### 受け入れ基準 (Phase 91)
|
|
||||||
|
|
||||||
1. ✅ Canonicalizer が escape pattern を認識
|
|
||||||
2. ✅ RoutingDecision.chosen == Pattern5bEscape
|
|
||||||
3. ✅ missing_caps == [] (すべての capability 満たす)
|
|
||||||
4. ✅ Strict parity green (`HAKO_JOINIR_STRICT=1`)
|
|
||||||
5. ✅ 既存テスト退行なし
|
|
||||||
6. ❌ Lowering は Step 3 へ (Phase 91 では recognition のみ)
|
|
||||||
|
|
||||||
### References
|
|
||||||
|
|
||||||
- **P5b 詳細設計**: `docs/development/current/main/design/pattern-p5b-escape-design.md`
|
|
||||||
- **テストフィクスチャ**: `tools/selfhost/test_pattern5b_escape_minimal.hako`
|
|
||||||
- **Phase 91 計画**: `docs/development/current/main/phases/phase-91/README.md`
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -218,8 +218,8 @@ If any of these are detected, Pattern P5b is rejected:
|
|||||||
4. **Find process block**: `out = out + ch`
|
4. **Find process block**: `out = out + ch`
|
||||||
5. **Find normal increment**: `i = i + 1` after if
|
5. **Find normal increment**: `i = i + 1` after if
|
||||||
6. **Find break condition**: `if ch == "\"" { break }`
|
6. **Find break condition**: `if ch == "\"" { break }`
|
||||||
7. **Build ExitContract** with both deltas
|
7. **Build LoopSkeleton**: `UpdateKind::ConditionalStep { cond, then_delta, else_delta }` を構築
|
||||||
8. **Build RoutingDecision**: Pattern5bEscape if all present
|
8. **Build RoutingDecision**: `chosen = Pattern2Break`(exit contract 優先)。P5b 固有の構造情報は `notes` に載せる
|
||||||
|
|
||||||
### Pseudo-Code
|
### Pseudo-Code
|
||||||
|
|
||||||
@ -305,8 +305,12 @@ LoopSkeleton {
|
|||||||
carriers: vec![
|
carriers: vec![
|
||||||
CarrierSlot {
|
CarrierSlot {
|
||||||
name: "i",
|
name: "i",
|
||||||
deltas: [1, 2], // [normal, escape]
|
update_kind: UpdateKind::ConditionalStep {
|
||||||
// ... other fields
|
cond: (ch == "\\"),
|
||||||
|
then_delta: 2,
|
||||||
|
else_delta: 1,
|
||||||
|
},
|
||||||
|
// ... other fields(role など)
|
||||||
},
|
},
|
||||||
CarrierSlot {
|
CarrierSlot {
|
||||||
name: "out",
|
name: "out",
|
||||||
@ -328,7 +332,7 @@ LoopSkeleton {
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
RoutingDecision {
|
RoutingDecision {
|
||||||
chosen: Pattern5bEscape,
|
chosen: Pattern2Break,
|
||||||
missing_caps: vec![],
|
missing_caps: vec![],
|
||||||
notes: vec![
|
notes: vec![
|
||||||
"escape_char: \\",
|
"escape_char: \\",
|
||||||
|
|||||||
@ -9,13 +9,14 @@
|
|||||||
|
|
||||||
## Executive Summary
|
## Executive Summary
|
||||||
|
|
||||||
**Current JoinIR Readiness**: 47% (16/30 loops in selfhost code)
|
**Inventory snapshot**: 47% (16/30 loops in selfhost code)
|
||||||
|
この数値は Phase 91 開始時点の棚卸しメモで、Phase 91 自体では「P5b の認識(canonicalizer)まで」を完了した。
|
||||||
|
|
||||||
| Category | Count | Status | Effort |
|
| Category | Count | Status | Effort |
|
||||||
|----------|-------|--------|--------|
|
|----------|-------|--------|--------|
|
||||||
| Pattern 1 (simple bounded) | 16 | ✅ Ready | None |
|
| Pattern 1 (simple bounded) | 16 | ✅ Ready | None |
|
||||||
| Pattern 2 (with break) | 1 | ⚠️ Partial | Low |
|
| Pattern 2 (with break) | 1 | ⚠️ Partial | Low |
|
||||||
| Pattern P5b (escape handling) | ~3 | ❌ Blocked | Medium |
|
| Pattern P5b (escape handling) | ~3 | ✅ Recognized (canonicalizer) | Medium |
|
||||||
| Pattern P5 (guard-bounded) | ~2 | ❌ Blocked | High |
|
| Pattern P5 (guard-bounded) | ~2 | ❌ Blocked | High |
|
||||||
| Pattern P6 (nested loops) | ~8 | ❌ Blocked | Very High |
|
| Pattern P6 (nested loops) | ~8 | ❌ Blocked | Very High |
|
||||||
|
|
||||||
@ -32,7 +33,7 @@
|
|||||||
|
|
||||||
#### File: `apps/selfhost-vm/json_loader.hako` (3 loops)
|
#### File: `apps/selfhost-vm/json_loader.hako` (3 loops)
|
||||||
- Lines 16-22: ✅ Pattern 1 (simple bounded)
|
- Lines 16-22: ✅ Pattern 1 (simple bounded)
|
||||||
- **Lines 30-37**: ❌ Pattern P5b **CANDIDATE** (escape sequence handling)
|
- **Lines 30-37**: ✅ Pattern P5b (escape skip; canonicalizer recognizes)
|
||||||
- Lines 43-48: ✅ Pattern 1 (simple bounded)
|
- Lines 43-48: ✅ Pattern 1 (simple bounded)
|
||||||
|
|
||||||
#### File: `apps/selfhost-vm/boxes/mini_vm_core.hako` (9 loops)
|
#### File: `apps/selfhost-vm/boxes/mini_vm_core.hako` (9 loops)
|
||||||
@ -222,197 +223,12 @@ This would make each sub-loop Pattern 1-compatible immediately.
|
|||||||
|
|
||||||
## Design: Pattern P5b (Escape Sequence Handling)
|
## Design: Pattern P5b (Escape Sequence Handling)
|
||||||
|
|
||||||
### Motivation
|
Pattern P5b の詳細設計は重複を避けるため、設計 SSOT に集約する。
|
||||||
|
|
||||||
String parsing commonly requires escape sequence handling:
|
- **設計 SSOT**: `docs/development/current/main/design/pattern-p5b-escape-design.md`
|
||||||
- Double quotes: `"text with \" escaped quote"`
|
- **Canonicalizer SSOT(語彙/境界)**: `docs/development/current/main/design/loop-canonicalizer.md`
|
||||||
- Backslashes: `"path\\with\\backslashes"`
|
|
||||||
- Newlines: `"text with \n newline"`
|
|
||||||
|
|
||||||
Current loops handle this with conditional increment:
|
この Phase 91 README は「在庫分析 + 実装完了の記録」に徹し、アルゴリズム本文や疑似コードは上記 SSOT を参照する。
|
||||||
```rust
|
|
||||||
if ch == "\\" {
|
|
||||||
i = i + 1 // Skip escape character itself
|
|
||||||
ch = next_char
|
|
||||||
}
|
|
||||||
i = i + 1 // Always advance
|
|
||||||
```
|
|
||||||
|
|
||||||
This variable-step pattern is **not JoinIR-compatible** because:
|
|
||||||
- Loop increment is conditional (sometimes +1, sometimes +2)
|
|
||||||
- Canonicalizer expects constant-delta carriers
|
|
||||||
- Lowering expects uniform update rules
|
|
||||||
|
|
||||||
### Solution: Pattern P5b Definition
|
|
||||||
|
|
||||||
#### Header Requirement
|
|
||||||
```
|
|
||||||
loop(i < n) // Bounded loop on string length
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Escape Check Requirement
|
|
||||||
```
|
|
||||||
if ch == "\\" {
|
|
||||||
i = i + delta_skip // Skip character (typically +1, +2, or variable)
|
|
||||||
// Optional: consume escape character
|
|
||||||
ch = s.substring(i, i+1)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### After-Escape Requirement
|
|
||||||
```
|
|
||||||
// Standard character processing
|
|
||||||
out = out + ch
|
|
||||||
i = i + delta_normal // Standard increment (typically +1)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Skeleton Structure
|
|
||||||
```
|
|
||||||
LoopSkeleton {
|
|
||||||
steps: [
|
|
||||||
HeaderCond(i < n),
|
|
||||||
Body(escape_check_stmts),
|
|
||||||
Body(process_char_stmts),
|
|
||||||
Update(i = i + normal_delta, maybe(i = i + skip_delta))
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Carrier Configuration
|
|
||||||
- **Primary Carrier**: Loop variable (`i`)
|
|
||||||
- `delta_normal`: +1 (standard case)
|
|
||||||
- `delta_escape`: +1 or +2 (skip escape)
|
|
||||||
- **Secondary Carrier**: Accumulator (`out`)
|
|
||||||
- Pattern: `out = out + value`
|
|
||||||
|
|
||||||
#### ExitContract
|
|
||||||
```
|
|
||||||
ExitContract {
|
|
||||||
has_break: true, // Break on quote detection
|
|
||||||
has_continue: false,
|
|
||||||
has_return: false,
|
|
||||||
carriers: vec![
|
|
||||||
CarrierInfo { name: "i", deltas: [+1, +2] },
|
|
||||||
CarrierInfo { name: "out", pattern: Append }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Routing Decision
|
|
||||||
```
|
|
||||||
RoutingDecision {
|
|
||||||
chosen: Pattern5bEscape,
|
|
||||||
structure_notes: ["escape_handling", "variable_step"],
|
|
||||||
missing_caps: [] // All required capabilities present
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Recognition Algorithm
|
|
||||||
|
|
||||||
#### AST Inspection Steps
|
|
||||||
|
|
||||||
1. **Find escape check**:
|
|
||||||
- Pattern: `if ch == "\\" { ... }`
|
|
||||||
- Extract: Escape character constant
|
|
||||||
- Extract: Increment inside if block
|
|
||||||
|
|
||||||
2. **Extract skip delta**:
|
|
||||||
- Pattern: `i = i + <const>`
|
|
||||||
- Calculate: `skip_delta = <const>`
|
|
||||||
|
|
||||||
3. **Find normal increment**:
|
|
||||||
- Pattern: `i = i + <const>` (after escape if block)
|
|
||||||
- Calculate: `normal_delta = <const>`
|
|
||||||
|
|
||||||
4. **Validate break condition**:
|
|
||||||
- Pattern: `if <char> == "<quote>" { break }`
|
|
||||||
- Required for string boundary detection
|
|
||||||
|
|
||||||
5. **Build LoopSkeleton**:
|
|
||||||
- Carriers: `[{name: "i", deltas: [normal, skip]}, ...]`
|
|
||||||
- ExitContract: `has_break=true`
|
|
||||||
- RoutingDecision: `chosen=Pattern5bEscape`
|
|
||||||
|
|
||||||
### Implementation Plan
|
|
||||||
|
|
||||||
#### Canonicalizer Extension (`src/mir/loop_canonicalizer/canonicalizer.rs`)
|
|
||||||
|
|
||||||
Add `detect_escape_pattern()` recognition:
|
|
||||||
```rust
|
|
||||||
fn detect_escape_pattern(
|
|
||||||
loop_expr: &Expr,
|
|
||||||
carriers: &[String]
|
|
||||||
) -> Option<EscapePatternInfo> {
|
|
||||||
// Step 1-5 as above
|
|
||||||
// Return: { escape_char, skip_delta, normal_delta, carrier_name }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Priority: Call before `detect_skip_whitespace_pattern()` (more specific pattern first)
|
|
||||||
|
|
||||||
#### Pattern Recognizer Wrapper (`src/mir/loop_canonicalizer/pattern_recognizer.rs`)
|
|
||||||
|
|
||||||
Expose `detect_escape_pattern()`:
|
|
||||||
```rust
|
|
||||||
pub fn try_extract_escape_pattern(
|
|
||||||
loop_expr: &Expr
|
|
||||||
) -> Option<(String, i64, i64)> { // (carrier, normal_delta, skip_delta)
|
|
||||||
// Delegate to canonicalizer detection
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Test Fixture (`tools/selfhost/test_pattern5b_escape_minimal.hako`)
|
|
||||||
|
|
||||||
Minimal reproducible example:
|
|
||||||
```nyash
|
|
||||||
// Minimal escape sequence parser
|
|
||||||
local s = "\\"hello\\" world"
|
|
||||||
local n = s.length()
|
|
||||||
local i = 0
|
|
||||||
local out = ""
|
|
||||||
|
|
||||||
loop(i < n) {
|
|
||||||
local ch = s.substring(i, i+1)
|
|
||||||
|
|
||||||
if ch == "\"" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if ch == "\\" {
|
|
||||||
i = i + 1 // Skip escape character
|
|
||||||
if i < n {
|
|
||||||
ch = s.substring(i, i+1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out = out + ch
|
|
||||||
i = i + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
print(out) // Should print: hello" world
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Files to Modify (Phase 91)
|
|
||||||
|
|
||||||
### New Files
|
|
||||||
1. `docs/development/current/main/phases/phase-91/README.md` ← You are here
|
|
||||||
2. `docs/development/current/main/design/pattern-p5b-escape-design.md` (new - detailed design)
|
|
||||||
3. `tools/selfhost/test_pattern5b_escape_minimal.hako` (new - test fixture)
|
|
||||||
|
|
||||||
### Modified Files
|
|
||||||
1. `docs/development/current/main/design/loop-canonicalizer.md`
|
|
||||||
- Add Pattern P5b to capability matrix
|
|
||||||
- Add recognition algorithm
|
|
||||||
- Add routing decision table
|
|
||||||
|
|
||||||
2. (Phase 91 Step 2+) `src/mir/loop_canonicalizer/canonicalizer.rs`
|
|
||||||
- Add `detect_escape_pattern()` function
|
|
||||||
- Extend `canonicalize_loop_expr()` to check for escape patterns
|
|
||||||
|
|
||||||
3. (Phase 91 Step 2+) `src/mir/loop_canonicalizer/pattern_recognizer.rs`
|
|
||||||
- Add `try_extract_escape_pattern()` wrapper
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -438,9 +254,8 @@ print(out) // Should print: hello" world
|
|||||||
## Next Steps (Future Sessions)
|
## Next Steps (Future Sessions)
|
||||||
|
|
||||||
### Phase 92: Lowering
|
### Phase 92: Lowering
|
||||||
- Implement Pattern5bEscape lowerer in JoinIR
|
- 進捗は Phase 92 で実施済み(ConditionalStep lowering + body-local 条件式サポート + 最小E2E smoke)。
|
||||||
- Handle ConditionalStep carrier updates with PHI composition
|
- 入口: `docs/development/current/main/phases/phase-92/README.md`
|
||||||
- E2E test with `test_pattern5b_escape_minimal.hako`
|
|
||||||
|
|
||||||
### Phase 93: Pattern P5 (Guard-Bounded)
|
### Phase 93: Pattern P5 (Guard-Bounded)
|
||||||
- Implement Pattern5 for `mini_vm_core.hako:541`
|
- Implement Pattern5 for `mini_vm_core.hako:541`
|
||||||
@ -466,7 +281,7 @@ print(out) // Should print: hello" world
|
|||||||
**Phase 91** establishes the next frontier of JoinIR coverage: **Pattern P5b (Escape Handling)**.
|
**Phase 91** establishes the next frontier of JoinIR coverage: **Pattern P5b (Escape Handling)**.
|
||||||
|
|
||||||
This pattern unlocks:
|
This pattern unlocks:
|
||||||
- ✅ All string escape parsing loops
|
- ✅ escape skip を含む “条件付き増分” 系ループの取り込み足場(recognizer + contract)
|
||||||
- ✅ Foundation for Pattern P5 (guard-bounded)
|
- ✅ Foundation for Pattern P5 (guard-bounded)
|
||||||
- ✅ Preparation for Pattern P6 (nested loops)
|
- ✅ Preparation for Pattern P6 (nested loops)
|
||||||
|
|
||||||
|
|||||||
@ -1,161 +1,10 @@
|
|||||||
# Phase 92 P4: E2E固定+回帰最小化 - 完了報告
|
# Phase 92 P4: E2E固定+回帰最小化 - 完了報告(Historical)
|
||||||
|
|
||||||
**実装日**: 2025-12-16
|
Status: Historical
|
||||||
**戦略**: 3レベルテスト戦略(P4-E2E-PLAN.md参照)
|
Scope: Phase 92 P4 の完了ログ。現行の要約・入口は `README.md` を SSOT とする。
|
||||||
|
Related:
|
||||||
|
- `docs/development/current/main/phases/phase-92/README.md`
|
||||||
|
- `docs/development/current/main/phases/phase-92/P4-E2E-PLAN.md`
|
||||||
|
|
||||||
---
|
Moved summary:
|
||||||
|
- P4 の結果(unit / integration smoke / 残タスク)は `docs/development/current/main/phases/phase-92/README.md` の `P4` 節へ統合した。
|
||||||
## ✅ 完了タスク
|
|
||||||
|
|
||||||
### P4-1: E2E固定戦略(3レベル実装)
|
|
||||||
|
|
||||||
#### Level 1: 既存Pattern2Breakテストで退行確認
|
|
||||||
- **テスト**: `apps/tests/loop_min_while.hako`
|
|
||||||
- **結果**: ✅ PASS(出力: 0, 1, 2)
|
|
||||||
- **確認内容**: Phase 92の変更で既存Pattern2機能が壊れていないことを確認
|
|
||||||
|
|
||||||
#### Level 2: Unit Test追加(Phase 92核心機能検証)
|
|
||||||
- **ファイル**: `src/mir/join_ir/lowering/condition_lowerer.rs`
|
|
||||||
- **追加テスト**:
|
|
||||||
1. `test_body_local_variable_resolution` - body-local変数(`ch`)の条件式での解決
|
|
||||||
2. `test_variable_resolution_priority` - ConditionEnv優先度の検証
|
|
||||||
3. `test_undefined_variable_error` - 未定義変数のエラーメッセージ検証
|
|
||||||
- **結果**: ✅ 全7テストPASS(`cargo test --release condition_lowerer::tests`)
|
|
||||||
|
|
||||||
#### Level 3: P5b完全E2E
|
|
||||||
- **状態**: ⏸️ 延期(body-local promotion実装後)
|
|
||||||
- **理由**: P5bパターン認識は厳密な要件があり、Phase 92スコープ外
|
|
||||||
- 要件: 特定構造(break check + escape check)
|
|
||||||
- `flag`ベースの条件は認識されない
|
|
||||||
- body-local promotion システムの拡張が必要
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### P4-2: Integration Smoke Test追加 ✅
|
|
||||||
|
|
||||||
**ファイル**: `tools/smokes/v2/profiles/integration/apps/phase92_pattern2_baseline.sh`
|
|
||||||
|
|
||||||
**テストケース**:
|
|
||||||
- **Case A**: `loop_min_while.hako` - Pattern2 breakベースライン
|
|
||||||
- 期待出力: `0\n1\n2\n`
|
|
||||||
- 結果: ✅ PASS
|
|
||||||
- **Case B**: `phase92_conditional_step_minimal.hako` - 条件付きインクリメント
|
|
||||||
- 期待出力: `3\n`
|
|
||||||
- 結果: ✅ PASS
|
|
||||||
|
|
||||||
**発見可能性**: ✅ Integration profileで正常に発見
|
|
||||||
```bash
|
|
||||||
tools/smokes/v2/run.sh --profile integration --filter "phase92*" --dry-run
|
|
||||||
# → profiles/integration/apps/phase92_pattern2_baseline.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
**実行結果**:
|
|
||||||
```
|
|
||||||
[INFO] PASS: 2, FAIL: 0
|
|
||||||
[PASS] phase92_pattern2_baseline: All tests passed
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### P4-3: Fail-Fast契約確認 ✅
|
|
||||||
|
|
||||||
**結論**: 追加不要(80/20ルール適用)
|
|
||||||
|
|
||||||
**既存実装確認**:
|
|
||||||
1. **`conditional_step_emitter.rs`**:
|
|
||||||
- Delta equality check実装済み
|
|
||||||
- 条件分岐の両方のパスで同じdelta値を生成することを検証
|
|
||||||
|
|
||||||
2. **`ConditionEnv`**:
|
|
||||||
- 変数解決失敗時のエラーメッセージ実装済み
|
|
||||||
- `Variable '{name}' not found in ConditionEnv or LoopBodyLocalEnv`
|
|
||||||
|
|
||||||
3. **新規unit test**:
|
|
||||||
- `test_undefined_variable_error` - エラーハンドリングを検証
|
|
||||||
|
|
||||||
**判断**: 現状の実装で十分。追加のcontract_checks実装は不要。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## ✅ 受け入れ基準確認
|
|
||||||
|
|
||||||
### Phase 92 E2E smokeがPASS
|
|
||||||
- ✅ **Case A**: Pattern2 breakベースライン(既存テスト退行なし)
|
|
||||||
- ✅ **Case B**: 条件付きインクリメント(Phase 92最小テスト)
|
|
||||||
|
|
||||||
### 既存integration smokesで退行なし
|
|
||||||
- ✅ **Phase 135**: `trim_mir_verify.sh` - PASS確認済み
|
|
||||||
- ✅ **Phase 132/133**: デフォルト動作変更なし(フラグOFF時)
|
|
||||||
|
|
||||||
### デフォルト動作変更なし
|
|
||||||
- ✅ Phase 92の変更は既存コード経路に影響なし
|
|
||||||
- ✅ `lower_condition_to_joinir_no_body_locals`ラッパーで後方互換性確保
|
|
||||||
- ✅ body-local環境は`Option`で必要時のみ渡される
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Phase 92の成果まとめ
|
|
||||||
|
|
||||||
### 実装済み機能
|
|
||||||
1. **Body-local変数サポート**: 条件式で`ch`などのbody-local変数を参照可能
|
|
||||||
2. **変数解決優先度**: ConditionEnv → LoopBodyLocalEnv の明確な優先順位
|
|
||||||
3. **Break condition順序修正**: body-local init後にbreak conditionを評価
|
|
||||||
4. **ConditionalStep emission**: body-local環境を渡してJoinIR Select命令を生成
|
|
||||||
|
|
||||||
### テスト体制
|
|
||||||
- **Unit tests**: 7個(condition_lowerer.rs)- Phase 92核心機能を検証
|
|
||||||
- **Integration smoke**: 1個(phase92_pattern2_baseline.sh)- 2ケース
|
|
||||||
- **既存テスト**: 退行なし確認済み
|
|
||||||
|
|
||||||
### 将来の拡張(Phase 92スコープ外)
|
|
||||||
- Body-local promotionシステム拡張(Pattern2で一般的なbody-local変数を扱う)
|
|
||||||
- P5bパターン認識の汎化(`flag`ベース条件もサポート)
|
|
||||||
- 完全なP5b E2Eテスト
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 技術的詳細
|
|
||||||
|
|
||||||
### 変数解決メカニズム
|
|
||||||
```rust
|
|
||||||
// Phase 92 P2-2: Variable resolution priority
|
|
||||||
// 1. ConditionEnv (loop parameters, captured variables)
|
|
||||||
if let Some(value_id) = env.get(name) {
|
|
||||||
return Ok(value_id);
|
|
||||||
}
|
|
||||||
// 2. LoopBodyLocalEnv (body-local variables like `ch`)
|
|
||||||
if let Some(body_env) = body_local_env {
|
|
||||||
if let Some(value_id) = body_env.get(name) {
|
|
||||||
return Ok(value_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(format!("Variable '{}' not found...", name))
|
|
||||||
```
|
|
||||||
|
|
||||||
### 後方互換性ラッパー
|
|
||||||
```rust
|
|
||||||
pub fn lower_condition_to_joinir_no_body_locals(
|
|
||||||
cond_ast: &ASTNode,
|
|
||||||
alloc_value: &mut dyn FnMut() -> ValueId,
|
|
||||||
env: &ConditionEnv,
|
|
||||||
) -> Result<(ValueId, Vec<JoinInst>), String> {
|
|
||||||
lower_condition_to_joinir(cond_ast, alloc_value, env, None)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
全7ファイルで使用されている(header condition、legacy carrier update等)。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 結論
|
|
||||||
|
|
||||||
**Phase 92 P4完了!**
|
|
||||||
|
|
||||||
Phase 92は「条件式でbody-local変数を使えるようにする基盤」を完成させました。
|
|
||||||
|
|
||||||
- ✅ **P4-1**: 3レベルテスト戦略完了(Level 1-2実装、Level 3延期)
|
|
||||||
- ✅ **P4-2**: Integration smoke test 1本追加(2ケースPASS)
|
|
||||||
- ✅ **P4-3**: Fail-Fast契約確認(追加不要)
|
|
||||||
- ✅ **受け入れ基準**: 全達成
|
|
||||||
|
|
||||||
完全なP5b E2E動作は将来のPhaseで、body-local promotion実装時に達成します。
|
|
||||||
|
|||||||
@ -1,93 +1,9 @@
|
|||||||
# Phase 92 P4: E2E固定+回帰最小化
|
# Phase 92 P4: E2E固定+回帰最小化(Historical)
|
||||||
|
|
||||||
## Phase 92の範囲と成果
|
Status: Historical
|
||||||
|
Scope: Phase 92 P4 の当時メモ。現行の要約・入口は `README.md` を SSOT とする。
|
||||||
|
Related:
|
||||||
|
- `docs/development/current/main/phases/phase-92/README.md`
|
||||||
|
|
||||||
**Phase 92の実装範囲**:
|
Moved summary:
|
||||||
- P0-P2: ConditionalStepのJoinIR生成とbody-local変数サポート
|
- P4 の要点(unit / integration smoke / 残タスク)は `docs/development/current/main/phases/phase-92/README.md` の `P4` 節へ統合した。
|
||||||
- **完了した機能**: `lower_condition_to_joinir`でbody-local変数解決をサポート
|
|
||||||
|
|
||||||
**Phase 92の範囲外**:
|
|
||||||
- P5bパターン認識の拡張(escape_pattern_recognizerは既存のまま)
|
|
||||||
- body-local variable promotionシステムの拡張
|
|
||||||
|
|
||||||
## P4-1: E2E固定戦略
|
|
||||||
|
|
||||||
### 問題
|
|
||||||
P5bパターン認識は厳密な要件があり、テストケースが認識されない:
|
|
||||||
- 要件: 特定の構造(break check + escape check)
|
|
||||||
- 現状: `flag`ベースの条件は認識されない
|
|
||||||
|
|
||||||
### 解決策: 段階的アプローチ
|
|
||||||
|
|
||||||
**Level 1: 最小E2E(既存Pattern2Break)**
|
|
||||||
```bash
|
|
||||||
# 既存のPattern2Breakテストを使用
|
|
||||||
NYASH_DISABLE_PLUGINS=1 ./target/release/hakorune apps/tests/loop_min_while.hako
|
|
||||||
# Expected: 正常動作(退行なし)
|
|
||||||
```
|
|
||||||
|
|
||||||
**Level 2: Unit Test(Phase 92の核心)**
|
|
||||||
```bash
|
|
||||||
# condition_lowerer.rsのunit testでbody-local変数サポートを検証
|
|
||||||
cargo test --release condition_lowerer::tests
|
|
||||||
# Expected: body-local変数の変数解決優先度が正しく動作
|
|
||||||
```
|
|
||||||
|
|
||||||
**Level 3: Integration(将来のP5b完全実装時)**
|
|
||||||
```bash
|
|
||||||
# P5bパターン完全実装後のE2E
|
|
||||||
NYASH_JOINIR_DEV=1 NYASH_DISABLE_PLUGINS=1 ./target/release/hakorune apps/tests/phase92_p5b_full.hako
|
|
||||||
# Note: body-local promotion実装が必要
|
|
||||||
```
|
|
||||||
|
|
||||||
## P4-2: Integration Smoke
|
|
||||||
|
|
||||||
最小限のsmoke testを追加:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# tools/smokes/v2/profiles/integration/rust-vm/phase92_pattern2_baseline.sh
|
|
||||||
# 既存のPattern2Breakテストで退行確認
|
|
||||||
```
|
|
||||||
|
|
||||||
## P4-3: Fail-Fast契約
|
|
||||||
|
|
||||||
現状のFail-Fast実装は十分:
|
|
||||||
- `conditional_step_emitter.rs`: delta equality check
|
|
||||||
- `ConditionEnv`: 変数解決失敗時のエラーメッセージ
|
|
||||||
|
|
||||||
追加不要(80/20ルール)。
|
|
||||||
|
|
||||||
## 受け入れ基準
|
|
||||||
|
|
||||||
✅ **Level 1完了**: 既存Pattern2Breakテストが動作(退行なし)
|
|
||||||
✅ **Level 2完了**: Unit testでbody-local変数サポート検証
|
|
||||||
- `test_body_local_variable_resolution` - body-local変数解決
|
|
||||||
- `test_variable_resolution_priority` - 変数解決優先度(ConditionEnv優先)
|
|
||||||
- `test_undefined_variable_error` - 未定義変数エラーハンドリング
|
|
||||||
- 全7テストPASS確認済み(`cargo test --release condition_lowerer::tests`)
|
|
||||||
✅ **P4-2完了**: Integration smoke test追加
|
|
||||||
- `tools/smokes/v2/profiles/integration/apps/phase92_pattern2_baseline.sh`
|
|
||||||
- Case A: `loop_min_while.hako` (Pattern2 baseline)
|
|
||||||
- Case B: `phase92_conditional_step_minimal.hako` (条件付きインクリメント)
|
|
||||||
- 両テストケースPASS、integration profileで発見可能
|
|
||||||
✅ **P4-3完了**: Fail-Fast契約確認(追加不要と判断)
|
|
||||||
- `conditional_step_emitter.rs`: delta equality check実装済み
|
|
||||||
- `ConditionEnv`: 変数解決失敗時のエラーメッセージ実装済み
|
|
||||||
- 80/20ルール適用: 現状の実装で十分と判断
|
|
||||||
⏸️ **Level 3延期**: P5b完全E2E(body-local promotion実装後)
|
|
||||||
|
|
||||||
## Phase 92の価値
|
|
||||||
|
|
||||||
**実装済み**:
|
|
||||||
1. `lower_condition_to_joinir`でbody-local変数解決(priority: ConditionEnv → LoopBodyLocalEnv)
|
|
||||||
2. `conditional_step_emitter.rs`でbody-local環境を渡す
|
|
||||||
3. Break condition loweringの順序修正(body-local init後に実行)
|
|
||||||
|
|
||||||
**将来の拡張**:
|
|
||||||
- body-local promotionシステム拡張(Pattern2で一般的なbody-local変数を扱う)
|
|
||||||
- P5bパターン認識の汎化
|
|
||||||
|
|
||||||
## 結論
|
|
||||||
|
|
||||||
Phase 92は「条件式でbody-local変数を使えるようにする基盤」を完成させました。
|
|
||||||
E2E完全動作は将来のPhaseで、body-local promotion実装時に達成します。
|
|
||||||
|
|||||||
@ -3,8 +3,10 @@
|
|||||||
## Status
|
## Status
|
||||||
- ✅ P0: Contract + skeleton-to-lowering wiring (foundations)
|
- ✅ P0: Contract + skeleton-to-lowering wiring (foundations)
|
||||||
- ✅ P1: Boxification / module isolation (ConditionalStep emitter)
|
- ✅ P1: Boxification / module isolation (ConditionalStep emitter)
|
||||||
- 🔶 P2: Wire emitter into Pattern2 + enable E2E
|
- ✅ P2: Pattern2 へ配線 + body-local 条件式サポート
|
||||||
- ✅ P3: BodyLocal 1変数(read-only)を Pattern2 条件で許可(Fail-Fast)
|
- ✅ P3: BodyLocal 1変数(read-only)を Pattern2 条件で許可(Fail-Fast)
|
||||||
|
- ✅ P4: E2E固定(最小)+ 回帰最小化(unit + integration smoke)
|
||||||
|
- ⏸️ P5: P5b “完全E2E” は promotion 拡張後
|
||||||
|
|
||||||
## Goal
|
## Goal
|
||||||
- Phase 91 で認識した P5b(escape skip: +1 / +2 の条件付き更新)を、JoinIR lowering まで落とせるようにする。
|
- Phase 91 で認識した P5b(escape skip: +1 / +2 の条件付き更新)を、JoinIR lowering まで落とせるようにする。
|
||||||
@ -14,7 +16,7 @@
|
|||||||
|
|
||||||
- P0-1: ConditionalStep 契約(SSOT)
|
- P0-1: ConditionalStep 契約(SSOT)
|
||||||
- 実装/記録: `src/mir/loop_canonicalizer/skeleton_types.rs`(契約コメント)
|
- 実装/記録: `src/mir/loop_canonicalizer/skeleton_types.rs`(契約コメント)
|
||||||
- 記録: `docs/development/current/main/phases/phase-92/p0-2-skeleton-to-context.md`
|
- 記録(歴史): `docs/development/current/main/phases/phase-92/p0-2-skeleton-to-context.md`
|
||||||
- P0-2: Skeleton → lowering への配線(Option A)
|
- P0-2: Skeleton → lowering への配線(Option A)
|
||||||
- `LoopPatternContext` に skeleton を optional に通した(後に P1 で境界を整理)
|
- `LoopPatternContext` に skeleton を optional に通した(後に P1 で境界を整理)
|
||||||
- P0-3: ConditionalStep を JoinIR(Select 等)で表現する基盤を追加
|
- P0-3: ConditionalStep を JoinIR(Select 等)で表現する基盤を追加
|
||||||
@ -31,19 +33,13 @@
|
|||||||
- E2E fixture
|
- E2E fixture
|
||||||
- `test_pattern5b_escape_minimal.hako` は用意済み(body-local 対応後に実行固定)
|
- `test_pattern5b_escape_minimal.hako` は用意済み(body-local 対応後に実行固定)
|
||||||
|
|
||||||
## P2(次): E2E を通す(最小1本)
|
## P2(完了): Pattern2 へ配線 + 条件式の body-local 対応
|
||||||
|
|
||||||
### P2-1: Pattern2 で emitter を実際に使用する
|
- `ConditionalStep` の lowering を Pattern2 から emitter に委譲(Pattern2 の肥大化を防ぐ)
|
||||||
- Pattern2 lowerer の update emission で `ConditionalStep` を検出したら emitter に委譲する
|
- 条件式の値解決に `LoopBodyLocalEnv` を追加し、`ConditionEnv → LoopBodyLocalEnv` の優先順位で解決
|
||||||
- AST 再検出を増やさない(canonicalizer/recognizer の SSOT を使う)
|
- break guard の lowering 順序を修正し、body-local 初期化の後に条件式を lower(`ch == ...` などを解決)
|
||||||
|
|
||||||
### P2-2: body-local 変数(`ch`)問題を解く
|
## P3(完了): BodyLocal 1変数(read-only)を条件式で許可(Fail-Fast)
|
||||||
- recognizer は cond/delta 抽出に限定し、スコープ/寿命の扱いは Skeleton 側へ寄せる
|
|
||||||
|
|
||||||
### P2-3: E2E fixture を 1 本だけ通す
|
|
||||||
- `test_pattern5b_escape_minimal.hako`(Phase 91 の最小fixture)
|
|
||||||
|
|
||||||
## P3(完了): BodyLocal 1変数対応(Fail-Fast付き)
|
|
||||||
|
|
||||||
- 目的: `ch` のような read-only body-local(毎回再計算)を Pattern2 の break/escape 条件で参照できるようにする
|
- 目的: `ch` のような read-only body-local(毎回再計算)を Pattern2 の break/escape 条件で参照できるようにする
|
||||||
- 新規箱: `src/mir/join_ir/lowering/common/body_local_slot.rs`
|
- 新規箱: `src/mir/join_ir/lowering/common/body_local_slot.rs`
|
||||||
@ -51,7 +47,22 @@
|
|||||||
- 禁止: 複数、代入あり、定義が break guard より後、top-level 以外(分岐内など)
|
- 禁止: 複数、代入あり、定義が break guard より後、top-level 以外(分岐内など)
|
||||||
- 破ると `error_tags::freeze(...)` で理由付き停止
|
- 破ると `error_tags::freeze(...)` で理由付き停止
|
||||||
|
|
||||||
|
## P4(完了): E2E固定(最小)+ 回帰最小化
|
||||||
|
|
||||||
|
- unit: `src/mir/join_ir/lowering/condition_lowerer.rs` に body-local 解決のユニットテストを追加
|
||||||
|
- integration smoke: `tools/smokes/v2/profiles/integration/apps/phase92_pattern2_baseline.sh`
|
||||||
|
- Case A: `apps/tests/loop_min_while.hako`(既存 Pattern2Break の退行チェック)
|
||||||
|
- Case B: `apps/tests/phase92_conditional_step_minimal.hako`(ConditionalStep の最小確認)
|
||||||
|
- 詳細ログ(歴史):
|
||||||
|
- `docs/development/current/main/phases/phase-92/P4-E2E-PLAN.md`
|
||||||
|
- `docs/development/current/main/phases/phase-92/P4-COMPLETION.md`
|
||||||
|
|
||||||
|
## Follow-up(Phase 93)
|
||||||
|
|
||||||
|
- Trim の `is_ch_match` など「ConditionOnly(PHIで運ばない派生値)」を毎イテレーション再計算する Derived Slot を追加(初回値固定の根治)。
|
||||||
|
- `docs/development/current/main/phases/phase-93/README.md`
|
||||||
|
|
||||||
## Acceptance
|
## Acceptance
|
||||||
- `NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1` で parity が green のまま
|
- `NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1` で parity が green のまま
|
||||||
- E2E が 1 本通る(まずは VM でOK)
|
- E2E が 1 本通る(最初は VM でOK)
|
||||||
- 既定挙動不変(フラグOFFで無影響)
|
- 既定挙動不変(フラグOFFで無影響)
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
# Phase 92 P0-2: Skeleton Integration to LoopPatternContext (Option A)
|
# Phase 92 P0-2: Skeleton Integration to LoopPatternContext (Option A)
|
||||||
|
|
||||||
|
Status: Historical
|
||||||
|
Scope: Phase 92 P0-2 の試行配線ログ(Option A)。現行の入口は `docs/development/current/main/phases/phase-92/README.md`。
|
||||||
|
Related:
|
||||||
|
- `docs/development/current/main/phases/phase-92/README.md`
|
||||||
|
|
||||||
## 概要
|
## 概要
|
||||||
|
|
||||||
ConditionalStep情報をPattern2 lowererに渡すため、LoopPatternContextにSkeletonフィールドを追加しました。
|
ConditionalStep情報をPattern2 lowererに渡すため、LoopPatternContextにSkeletonフィールドを追加しました。
|
||||||
|
|||||||
38
docs/development/current/main/phases/phase-93/README.md
Normal file
38
docs/development/current/main/phases/phase-93/README.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Phase 93: ConditionOnly Derived Slot(Trim / body-local)
|
||||||
|
|
||||||
|
Status: Active
|
||||||
|
Scope: Pattern2(Loop with Break)で「ConditionOnly(PHIで運ばない派生値)」を毎イテレーション再計算できるようにする。
|
||||||
|
Related:
|
||||||
|
- 設計地図(入口): `docs/development/current/main/design/joinir-design-map.md`
|
||||||
|
- Phase 92(ConditionalStep / body-local 条件式): `docs/development/current/main/phases/phase-92/README.md`
|
||||||
|
- ExitLine/Boundary 契約(背景): `docs/development/current/main/joinir-boundary-builder-pattern.md`
|
||||||
|
|
||||||
|
## 目的
|
||||||
|
|
||||||
|
Trim 系で使う `is_ch_match` のような「body-local から再計算できる bool」を **ConditionOnly** として扱い、
|
||||||
|
JoinIR で “初回の計算値が固定される” 事故を避ける。
|
||||||
|
|
||||||
|
- ConditionOnly は loop carrier(LoopState)ではない(header PHI で運ばない)
|
||||||
|
- 代わりに **毎イテレーション**で Derived slot として再計算する(SSOT: Recipe)
|
||||||
|
|
||||||
|
## 成果(P0)
|
||||||
|
|
||||||
|
コミット: `04fdac42 feat(mir): Phase 93 P0 - ConditionOnly Derived Slot実装`
|
||||||
|
|
||||||
|
- 新規: `src/mir/join_ir/lowering/common/condition_only_emitter.rs`
|
||||||
|
- `ConditionOnlyRecipe`: 再計算レシピ(運搬禁止のSSOT)
|
||||||
|
- `ConditionOnlyEmitter`: `LoopBodyLocalEnv` を使って毎イテレーション再計算
|
||||||
|
- schedule: `src/mir/join_ir/lowering/step_schedule.rs`
|
||||||
|
- ConditionOnly がある場合に `body-init → derived → break` を強制(評価順のSSOT)
|
||||||
|
- Trim: `src/mir/builder/control_flow/joinir/patterns/trim_loop_lowering.rs`
|
||||||
|
- ConditionOnly 用 break 生成(反転の有無を明示)
|
||||||
|
|
||||||
|
## 受け入れ基準(P0)
|
||||||
|
|
||||||
|
- `apps/tests/loop_min_while.hako` が退行しない(Pattern2 baseline)
|
||||||
|
- `/tmp/test_body_local_simple.hako` が “毎イテレーション再計算” で期待通り動く
|
||||||
|
- ConditionOnly を `ConditionBinding`(join input)で運ばない(初回値固定を禁止)
|
||||||
|
|
||||||
|
## 次
|
||||||
|
|
||||||
|
- P5b の完全E2E(escape skip)に進む場合も、ConditionOnly と schedule の契約は再利用できる
|
||||||
Reference in New Issue
Block a user