refactor(lifecycle): Phase 285 P2.1 hygiene - lifecycle.rs 箱化完了
責務分離により KeepAlive 処理を handlers/lifecycle.rs に隔離: - handlers/lifecycle.rs 新規作成(47行) - handle_keepalive() で drop_after 判定 - release_strong_refs() で Arc 同一性探索を集約 - HashSet による O(1) 検索最適化 - handlers/mod.rs を dispatch 専用化(49行削除→1行呼び出し) - README.md に P2.1 完了状態を記載(SKIP→PASS) - phase-29y 将来設計相談パケット追加(NyRT ABI/RC insertion pass) Test: 154/154 PASS ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# Phase 285: Box lifecycle / weakref / finalization / GC conformance
|
||||
|
||||
Status: P0 COMPLETE (2025-12-26); A1 series + LLVM sub-phases implemented
|
||||
Status: P0/P1/P2/P2.1 ✅ COMPLETE (2025-12-26)
|
||||
|
||||
## Next (P0 docs-only → P1/P2)
|
||||
|
||||
@ -9,6 +9,32 @@ Status: P0 COMPLETE (2025-12-26); A1 series + LLVM sub-phases implemented
|
||||
- lifecycle/weak/fini/GC: `docs/reference/language/lifecycle.md`
|
||||
- `null`/`void`/truthiness: `docs/reference/language/types.md`
|
||||
|
||||
## P2.1(Hidden root investigation & fix)✅ COMPLETE (2025-12-26)
|
||||
|
||||
P2 の weak-fail fixture(明示 drop `x = null`)が “失敗→null” にならず、`weak_to_strong()` が成功してしまう(hidden root)問題を根治した。
|
||||
|
||||
### Root cause(要旨)
|
||||
|
||||
- VM の `regs` が古い `ValueId` を保持し続け、`Arc` が drop されない
|
||||
- SSA last-use をそのまま寿命にすると、言語の block-scoped locals と衝突して `weak_basic` が壊れる
|
||||
|
||||
### Fix(要旨)
|
||||
|
||||
MIR 命令 `KeepAlive` を “スコープ維持 / 上書きdrop” の両方に使い分ける。
|
||||
|
||||
- `drop_after=false`(scope-end keepalive): スコープ終端まで値を生存維持(language scope semantics)
|
||||
- `drop_after=true`(overwrite drop): 変数上書き前の旧値を解放(weak-fail を成立させる)
|
||||
- SSA `Copy` により同一 `Arc` を複数 `ValueId` が参照するため、VM は **alias も含めて** `regs` から除去する
|
||||
|
||||
実装の責務分離(hygiene):
|
||||
- VM 側の KeepAlive 処理は `src/backend/mir_interpreter/handlers/lifecycle.rs` に隔離(dispatch から分離)
|
||||
|
||||
### Verification
|
||||
|
||||
- `apps/tests/phase285_weak_basic.hako`: exit 2 ✅
|
||||
- `apps/tests/phase285_p2_weak_upgrade_fail_min.hako`: exit 1 ✅
|
||||
- quick gate: `./tools/smokes/v2/run.sh --profile quick` → 154/154 PASS ✅
|
||||
|
||||
## LLVM Sub-Phases Status
|
||||
|
||||
| Phase | Status | Summary |
|
||||
@ -233,18 +259,13 @@ If any of the following are missing, treat weak smokes as **unsupported** and sc
|
||||
1. `tools/smokes/v2/profiles/integration/apps/phase285_p2_weak_upgrade_success_vm.sh`
|
||||
- Fixture A 実行、期待: **exit 2** → **PASS**
|
||||
2. `tools/smokes/v2/profiles/integration/apps/phase285_p2_weak_upgrade_fail_vm.sh`
|
||||
- Fixture B 実行、**SKIP**(既知の hidden root 問題)
|
||||
- Fixture B 実行、期待: **exit 1** → **PASS**
|
||||
|
||||
**LLVM smoke scripts(2本)**:
|
||||
3. `tools/smokes/v2/profiles/integration/apps/phase285_p2_weak_upgrade_success_llvm.sh`
|
||||
- Fixture A 実行(LLVM harness)、期待: **exit 2** → **PASS** または理由付き SKIP
|
||||
4. `tools/smokes/v2/profiles/integration/apps/phase285_p2_weak_upgrade_fail_llvm.sh`
|
||||
- Fixture B 実行(LLVM harness)、**SKIP**(既知の hidden root 問題、VM と同じ)
|
||||
|
||||
**既知の問題(Fixture B)**:
|
||||
- **Hidden root issue**: `x = null` で明示 drop しても weak_to_strong が成功(exit 0)
|
||||
- 原因: 隠れた root が strong ref を保持している可能性
|
||||
- 対応: Phase 285 P2.1 (investigation) で root 保持箇所を棚卸し
|
||||
- Fixture B 実行(LLVM harness)、期待: **exit 1** → **PASS** または理由付き SKIP
|
||||
|
||||
**LLVM 対応**:
|
||||
- WeakNew/WeakLoad は **両バックエンド実装済み**(P1 確認済み)→ PASS が理想
|
||||
@ -256,30 +277,16 @@ If any of the following are missing, treat weak smokes as **unsupported** and sc
|
||||
- ✅ Fixture B 新規作成(明示 drop 方式)
|
||||
- ✅ VM smoke success PASS
|
||||
- ✅ LLVM smoke success PASS(または理由付き SKIP)
|
||||
- ✅ VM/LLVM smoke fail SKIP(hidden root 問題で理由付き)
|
||||
- ✅ VM smoke fail PASS(exit 1)
|
||||
- ✅ LLVM smoke fail PASS(または理由付き SKIP)
|
||||
- ✅ quick 154/154 PASS 維持
|
||||
- ✅ Finalizer は「VM のみ・LLVM 未対応」と差分表に明記済み(上記 VM/LLVM 差分分類テーブル参照)
|
||||
|
||||
**P2 で扱わない項目**:
|
||||
- **Block scope drop conformance** → 別タスク(未整合の可能性あり)
|
||||
- **Hidden root investigation** → Phase 285 P2.1 で root 保持箇所を棚卸し
|
||||
- Finalizer (`fini()`) の統一テスト → 両バックエンド未実装のため Phase 286+ で検討
|
||||
- GC cycle collection → Reference Count のみで既知の制約
|
||||
|
||||
### P2.1(investigation)- 提案
|
||||
|
||||
**目的**: Hidden root 問題の原因特定(`x = null` で明示 drop しても weak_to_strong が成功する理由)
|
||||
|
||||
**調査対象**:
|
||||
- VM の strong ref 保持箇所(VMValue/registry/handles/scope_tracker/等)
|
||||
- Arc drop タイミング(明示 `x = null` 代入時に Arc が drop されるか)
|
||||
- 隠れた root 候補(MIR interpreter state/local variables/等)
|
||||
|
||||
**期待成果**:
|
||||
- Hidden root の特定(どこが strong ref を保持しているか)
|
||||
- 分類: (B) 未実装 / (C) 既知バグ / (D) 仕様外
|
||||
- 修正方針の提示(Phase 286+ で修正)
|
||||
|
||||
## Non-goals
|
||||
|
||||
- GC アルゴリズム刷新(RC→tracing 等の設計変更)
|
||||
|
||||
Reference in New Issue
Block a user