Files
hakorune/docs/development/current/main/phases/phase-285/P0-INSTRUCTIONS.md
tomoaki cc8b27a1aa feat(weak): Phase 285A1 - Weak Field Contract (Strict Type Enforcement)
Remove automatic WeakNew conversion and enforce strict compile-time type
checking for weak field assignments. Only 3 assignment types allowed:
1. Result of weak(x) call (WeakRef type)
2. Existing WeakRef variable (e.g., me.parent = other.parent)
3. Void/null (clear operation)

**Implementation**:
- Added MirType::WeakRef to type system (src/mir/types.rs)
- Track WeakRef type in emit_weak_new() even in pure mode
- Weak field reads return WeakRef without auto-upgrade
- Removed automatic WeakNew conversion from field writes
- Implemented check_weak_field_assignment() with actionable errors
- Fixed null literal type tracking (Phase 285A1.1: Unknown → Void)

**Testing**:
- 5 test fixtures (3 OK, 2 NG cases) - all passing
- Smoke test: phase285_weak_field_vm.sh
- Error messages guide users to use weak() or null

**Documentation**:
- Updated lifecycle.md SSOT with weak field contract

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-24 03:17:30 +09:00

2.7 KiB
Raw Blame History

Phase 285 P0docs-only: Box lifecycle / weakref / finalization / GC SSOT

目的: “実装が仕様” になっている Box の寿命・弱参照・最終化を、docs と smoke の SSOT に固定する。

1. このP0でやることコード変更なし

  1. 仕様SSOTを 1 ファイルにまとめる

    • 言語レベルの SSOT は docs/reference/language/lifecycle.mdlifecyle/weak/fini/GCdocs/reference/language/types.mdtruthiness と null/void)に集約する。
    • Phase 285 は「実装の棚卸し・差分追跡・受け入れ条件」を書く言語SSOTを書き換えない
  2. 用語と境界を固定する

    • strong/weak/roots/finalizer/collection の定義
    • weakref の APIweak_to_strong/生存判定)
    • finalizer の禁止事項(再入・例外・順序)
  3. LLVM harness の扱いを明文化する

    • 未対応なら “未対応” を差分として書く(差分を隠さない)。
    • 差分は「仕様差」ではなく「未実装/バグ/保留」として分類する言語SSOTは揺らさない

2. README に必ず書く事項(チェックリスト)

  • “roots” は何かstack/local/global/handle/plugin 等)
  • strong/weak の意味weak_to_strong の成否条件)
  • strong/weak の意味weak_to_strong の成否条件)
  • finalizer はあるか/いつ発火するか/何が禁止か
  • GC/解放のトリガ(自動/手動/閾値/テスト用)
  • VM と LLVM harness の差分(未対応の場合の方針)
    • 分類: (A) 仕様通り / (B) 未実装 / (C) 既知バグ / (D) 仕様外(禁止)

3. 次P1/P2への導線箇条書きでOK

  • P1investigation: 棚卸し対象のファイル一覧と観測ポイント
  • P2smoke: fixture の仕様stdout/exitと LLVM 側の扱いPASS/SKIP

4. P1 調査チェックリスト(提案)

Rust VMSSOT

  • src/value.rs
    • NyashValue::WeakBox の生成箇所weak をどう作るか)
    • weak_to_strong() 失敗時の観測方法(文字列化/判定API
    • unit test: test_weak_reference_drop の仕様(何を固定しているか)
  • src/finalization.rs
    • finalizer の存在(あれば: 登録、呼び出しタイミング、順序)
    • 禁止事項(再入/例外/I/O/allocをどこでガードするか
  • src/box_trait.rs / src/scope_tracker.rs
    • Box の所有モデルArc/Weakの境界、roots の形成点)

LLVM harness差分を SSOT 化)

  • src/llvm_py/
    • weakref/finalizer の相当機能があるか(まず “無いなら無い” を明文化)
    • 未対応の場合は smoke を SKIP にし、理由をログで固定する方針