📊 Phase 25.1l: Region観測レイヤー骨格 + スコープ契約設計理解

**Region Box統一理論の実装開始**

新規追加:
- src/mir/region/mod.rs: Region/RefSlotKind型定義
- src/mir/region/observer.rs: Region観測レイヤー
- docs/development/roadmap/phases/phase-25.1l/: 設計ドキュメント

主要概念:
- Region Box = Function/Loop/If の統一箱
- RefSlotKind = GC管理用スロット種別(Strong/Weak/Borrowed/NonRef)
- 観測専用(NYASH_REGION_TRACE=1で動作、挙動変更なし)

設計理解の深化:
- ValueId(40)問題 = LoopForm v2スコープ契約違反の症状
- 根本解決 = Region観測で無名一時値のスコープまたぎを検出
- 箱理論3原則: 境界明確化/差し替え可能/段階的移行

関連議論:
- ChatGPT提案: Region統一理論でGC/寿命管理の基盤構築
- SlotRegistry: 変数の単一真実源(SSOT)
- 階層構造: FunctionRegion → LoopRegion → IfRegion

次のステップ:
- Phase 1: Region観測(現在)- 非破壊的追加
- Phase 2: メタデータ出力(MIR JSON拡張)
- Phase 3: GC統合(retain/release挿入)

テスト追加:
- lang/src/compiler/tests/stageb_mini_driver.hako
- tools/test_loopssa_breakfinder_slot.sh

Build:  全警告は既存のもの
Tests: 既存テスト全て緑維持
This commit is contained in:
nyash-codex
2025-11-19 02:44:40 +09:00
parent 80f8a7bc8c
commit 39f5256c18
22 changed files with 941 additions and 68 deletions

View File

@ -329,6 +329,10 @@ impl super::MirBuilder {
}
// Propagate lightweight metadata so downstream resolution/type inference remains stable
crate::mir::builder::metadata::propagate::propagate(self, v, dst);
// Remember pin slot name for both the original and the pinned value.
// LocalSSA uses this to redirect old pinned values to the latest slot value.
self.pin_slot_names.insert(v, slot_name.clone());
self.pin_slot_names.insert(dst, slot_name.clone());
self.variable_map.insert(slot_name, dst);
Ok(dst)
}