📚 Phase 11 documentation: Everything is Box × MIR15 revolution

Key updates:
- Document MIR 26→15 instruction reduction plan (transitioning status)
- Add Core-15 target instruction set in INSTRUCTION_SET.md
- Save AI conference analyses validating Box Theory and 15-instruction design
- Create MIR annotation system proposal for optimization hints
- Update SKIP_PHASE_10_DECISION.md with LLVM direct migration rationale

Technical insights:
- RefNew/RefGet/RefSet can be eliminated through Box unification
- GC/sync/async all achievable with 15 core instructions
- BoxCall lowering can automatically insert GC barriers
- 2-3x performance improvement expected with LLVM
- Build time reduction 50%, binary size reduction 40%

Status: Design complete, implementation pending
This commit is contained in:
Moe Charm
2025-08-31 03:03:04 +09:00
parent 1812cda7d5
commit b003bdf25b
50 changed files with 2621 additions and 136 deletions

View File

@ -0,0 +1,133 @@
# Phase 11.5 現状確認2025-08-31
## 🎯 LLVMに行く前に固めるべき足場
### 📊 現在の実装状況
#### ✅ 完了済み基盤
1. **GC Write Barrier**
- `src/backend/gc_helpers.rs` に実装済み
- `gc_write_barrier_site()` 関数が各所で呼び出される
- RefSet, ArraySet, BoxCall(mutating) で動作確認済み
2. **デバッグ・計測機能**
- `NYASH_GC_TRACE=1` でバリア呼び出しトレース
- `NYASH_GC_BARRIER_STRICT=1` で厳密検証
- カウンティングGCでの統計情報
3. **VM統合**
- すべての書き込み操作でバリア呼び出し
- 一貫したGCインターフェース
#### ✅ 追加VM足場; LLVM前倒し
1. **Escape AnalysisVM専用トグル**
- `src/mir/passes/escape.rs` を追加(保守的: NewBox起点の関数内ローカルを追跡
- `NYASH_VM_ESCAPE_ANALYSIS=1` でON。非エスケープなBoxに対する `Barrier(Read/Write)` をNop化
- まずVMで効果検証→LLVM(inkwell)へ最適化ヒント伝播予定
#### ❌ 未実装(優先度高)
1. **Escape Analysisの精度強化**JIT/AOT/LLVM 連携)
- 関数間/コレクション経由の伝播、簡易エイリアス、サイト統計JSON出力
- JIT最適化統合バリア発行抑制; 保守的フォールバック)
2. **Atomic最適化** - Phase 11.5b
- Read-onlyメソッド識別なし
- Arc<Mutex> → RwLock移行なし
3. **Coroutine** - Phase 11.5c
- async/await構文なし
- State machine変換なし
## 🚀 推奨実装順序LLVM前
### 1. Escape Analysis基礎実装1週間
```rust
// src/mir/escape_analysis.rs を新規作成
pub struct EscapeAnalysis {
allocations: HashMap<ValueId, AllocInfo>,
escapes: HashSet<ValueId>,
}
```
**理由**:
- VMレベルで検証可能実装済の最小版で効果検証を開始
- JIT/AOT/LLVM共通で使えるテーション伝播の足場
- 性能改善が即座に見える
### 2. Read-only最適化3日
```rust
// BoxCoreトレイトに追加
trait BoxCore {
fn is_readonly_method(&self, method: &str) -> bool;
}
```
**理由**:
- 実装が簡単
- 既存コードへの影響最小
- マルチスレッド性能向上
### 3. LLVM移行準備1週間
- MIRアテーションシステム実装
- 最適化情報の伝播経路確立
- inkwell依存追加
## 📈 期待される効果
### Escape Analysis実装後
- ローカル変数操作: 90%バリア除去
- ループ内操作: 80%高速化
- 全体GCオーバーヘッド: 50%削減
### Read-only最適化後
- 読み取り操作: 10倍高速化
- マルチスレッドスケーラビリティ向上
## 🎯 成功基準
1. **VMベンチマーク改善**
```bash
# Before
./target/release/nyash --benchmark --iterations 1000
# GC overhead: 30%
# After escape analysis
NYASH_JIT_ESCAPE_ANALYSIS=1 ./target/release/nyash --benchmark
# GC overhead: 15% (目標)
```
2. **テストスイート通過**
- 既存テストすべてグリーン
- 新規escape analysisテスト追加
3. **デバッグ情報充実**
- バリア除去統計JSON出力
- 最適化トレース機能
## 📋 アクションアイテム
### 今すぐ始められること
1. [ ] `src/mir/escape_analysis.rs` スケルトン作成
2. [ ] 基本的なallocation追跡実装
3. [ ] VMでのバリア除去統合テスト
### 次のステップ
1. [ ] Read-onlyメソッドのアテーション
2. [ ] RwLock移行の段階的実施
3. [ ] ベンチマーク自動化
## 💡 注意事項
**LLVM移行前に必ず**:
- Escape analysisの基本動作確認
- バリア除去の効果測定
- 最適化情報の保存形式確定
これらの足場があれば、LLVM移行時に:
- 最適化ヒントをそのまま活用
- JIT/AOTで同じ解析結果を共有
- 段階的な性能向上を実現
---
**結論**: Phase 11.5aのEscape Analysisを最優先で実装し、VMレベルで効果を確認してからLLVM移行に進むべき。