From 5ec005605973e600c2df101850d424e8073c8312 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Fri, 26 Dec 2025 10:51:17 +0900 Subject: [PATCH] =?UTF-8?q?docs(lifecycle):=20Phase=20285=20P0=20-=20Box?= =?UTF-8?q?=20lifecycle/weakref/GC=20SSOT=20=E5=9B=BA=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 言語 SSOT との境界明文化 - lifecycle/weak/fini: lifecycle.md - null/void/truthiness: types.md - Phase 285 は実装状況・差分追跡のみ(言語SSOT書き換えなし) ## 用語・禁止事項固定 - Roots/Strong/Weak/Finalizer/GC 定義 - 禁止: finalizer 再入・例外・allocation・silent fallback ## VM/LLVM 差分分類 - (A) 仕様通り: weak/weak_to_strong/leak report - (B) 未実装: finalizer/GC cycle collection ## P1/P2 導線 - P1: 棚卸し対象ファイル一覧(value.rs, finalization.rs等) - P2: smoke 候補(weak_basic, weak_to_strong_fail, leak_report) quick smoke 154/154 PASS 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- docs/development/current/main/10-Now.md | 9 +- .../current/main/phases/phase-285/README.md | 92 +++++++++++++++++-- 2 files changed, 92 insertions(+), 9 deletions(-) diff --git a/docs/development/current/main/10-Now.md b/docs/development/current/main/10-Now.md index cc1efb23..d3fdd3d9 100644 --- a/docs/development/current/main/10-Now.md +++ b/docs/development/current/main/10-Now.md @@ -1,8 +1,13 @@ # Self Current Task — Now (main) -## Current Focus: Phase 285 P0 (docs-only) +## Current Focus: Phase 285 P1/P2 / Phase 287 計画 -Box lifecycle / weakref / finalization / GC の “実装が仕様” を止めるため、まず docs-only で SSOT と差分運用(VM/LLVM)を固定する。 +Phase 284 P2 + Phase 285 P0 完了。次は Phase 285 P1(棚卸し)または Phase 287(Normalizer Hygiene)。 + +**2025-12-26: Phase 285 P0 完了** ✅ +- 言語 SSOT との境界明文化(lifecycle.md, types.md) +- 用語・禁止事項・VM/LLVM差分分類を固定 +- P1/P2 への導線を箇条書きで追加 **2025-12-26: Phase 284 P2 完了** ✅ - return を含む loop(Pattern5)を VM で smoke 固定 diff --git a/docs/development/current/main/phases/phase-285/README.md b/docs/development/current/main/phases/phase-285/README.md index 87d07b0d..ec32fb4c 100644 --- a/docs/development/current/main/phases/phase-285/README.md +++ b/docs/development/current/main/phases/phase-285/README.md @@ -1,6 +1,13 @@ # Phase 285: Box lifecycle / weakref / finalization / GC conformance -Status: In progress (A1 series implemented; LLVM sub-phases ongoing) +Status: P0 COMPLETE (2025-12-26); A1 series + LLVM sub-phases implemented + +## Next (P0 docs-only → P1/P2) + +- P0 手順書: `docs/development/current/main/phases/phase-285/P0-INSTRUCTIONS.md` +- 言語レベルSSOT: + - lifecycle/weak/fini/GC: `docs/reference/language/lifecycle.md` + - `null`/`void`/truthiness: `docs/reference/language/types.md` ## LLVM Sub-Phases Status @@ -80,7 +87,57 @@ See `docs/development/current/main/phases/phase-285/phase-285a1-boxification.md` - **Roots**: 解放/GC から保護される参照集合(stack/local/global/handle/plugin) - **Finalizer**: 解放に伴う最終化処理(もし存在するなら) -## P0 decisions (docs-only) +## P0 decisions (docs-only) ✅ COMPLETE (2025-12-26) + +### 言語 SSOT との境界 + +| 関心事 | SSOT | Phase 285 での扱い | +|--------|------|-------------------| +| Lifecycle/weak/fini | `docs/reference/language/lifecycle.md` | 実装状況・差分追跡のみ | +| null/void/truthiness | `docs/reference/language/types.md` | 実装状況・差分追跡のみ | +| VM/LLVM 差分 | このファイル | 「未対応/既知バグ/保留」として分類 | + +**原則**: Phase 285 は言語 SSOT を書き換えない。実装の棚卸しと差分追跡を行う。 + +### 用語(固定) + +| 用語 | 定義 | +|------|------| +| **Roots** | 解放/GC から保護される参照集合(stack/local/global/handle/plugin) | +| **Strong reference** | 所有参照(`Arc` 等で Box を保持、解放を遅延) | +| **Weak reference** | 非所有参照(`Weak` / `weak_to_strong()` が失敗しうる) | +| **Weak-to-strong** | weak → strong の昇格(成功/失敗が意味論、失敗時は `null`) | +| **Finalizer (`fini`)** | 解放に伴う論理的終了処理(物理解放とは別) | +| **Collection (GC)** | 到達不能オブジェクトの回収(意味論ではなく補助) | + +### 禁止事項 + +| 禁止事項 | 理由 | +|----------|------| +| Finalizer 内での再入 | デッドロック/無限再帰のリスク | +| Finalizer 内での例外送出 | 終了処理の信頼性を損なう | +| Finalizer 内での allocation | GC サイクル中の新規割当は危険 | +| Silent fallback(黙殺) | 未対応は `Err` または理由付き SKIP で固定 | +| 新しい環境変数トグル | 既存の診断導線の範囲で対応 | + +### VM/LLVM 差分分類 + +| 機能 | VM (Rust) | LLVM harness | 分類 | +|------|-----------|--------------|------| +| `weak ` | ✅ 実装済み | ✅ 実装済み | (A) 仕様通り | +| `weak_to_strong()` | ✅ 実装済み | ✅ 実装済み | (A) 仕様通り | +| Weak field contract | ✅ 実装済み | ✅ 実装済み | (A) 仕様通り | +| Finalizer (`fini`) | ⚠️ 未実装 | ⚠️ 未実装 | (B) 未実装 | +| GC (cycle collection) | ⚠️ RC のみ | ⚠️ RC のみ | (B) 未実装 | +| Exit-time leak report | ✅ 診断あり | ✅ 診断あり | (A) 仕様通り | + +**分類凡例**: +- (A) 仕様通り: VM/LLVM 両方で動作 +- (B) 未実装: 言語仕様にあるが実装されていない +- (C) 既知バグ: 実装はあるが動作が仕様と異なる +- (D) 仕様外: 禁止されている + +### Core decisions - Weak の観測は `weak_to_strong()` で行い、失敗値は `null`(= runtime `Void` の別名)。 - `cleanup`(Stage‑3 block-postfix)が「出口で必ず走る」決定的 cleanup を保証する(`catch` の有無に関係なく、常に実行)。 @@ -112,14 +169,35 @@ If any of the following are missing, treat weak smokes as **unsupported** and sc ### P1(investigation) -- Rust VM の現状実装の棚卸し(どこで roots が形成され、どこで解放/最終化されるか) -- LLVM harness の現状調査(弱参照/GC が無い場合は差分として記録) +**目的**: Rust VM の現状実装の棚卸し(どこで roots が形成され、どこで解放/最終化されるか) + +**棚卸し対象ファイル**: +| ファイル | 観測ポイント | +|----------|-------------| +| `src/value.rs` | `NyashValue::WeakBox` 生成箇所、`weak_to_strong()` 失敗時の観測方法 | +| `src/finalization.rs` | finalizer 存在確認、登録・呼び出しタイミング・順序 | +| `src/box_trait.rs` | Box の所有モデル(Arc/Weak の境界、roots の形成点)| +| `src/scope_tracker.rs` | Box の登録/スコープ管理 | + +**LLVM harness 調査**: +- `src/llvm_py/` で weakref/finalizer の相当機能を確認 +- 無いなら「無い」を明文化し、smoke を SKIP にする ### P2(smoke) -- weakref の最小 fixture/smoke を作り、挙動を固定する - - VM: stdout/exit code で固定 - - LLVM: 未対応なら “スキップ理由” を smoke で明示 +**目的**: weakref の最小 fixture/smoke を作り、挙動を固定する + +**smoke 候補(2-3本)**: +| smoke | 内容 | 期待値 | +|-------|------|--------| +| `phase285_weak_basic_vm.sh` | 既存 weak basic smoke | PASS(既に存在)| +| `phase285_weak_to_strong_fail_vm.sh` | weak_to_strong 失敗観測 | PASS(null 確認)| +| `phase285_leak_report_vm.sh` | exit-time leak report | PASS(既に存在)| + +**LLVM 扱い**: +- VM と同一動作: PASS +- 未対応: 理由付き SKIP(`test_skip "reason"`) +- silent fallback 禁止 ## Non-goals