Files
hakorune/docs/development/roadmap/phases/phase-15/planning/preparation.md
Selfhosting Dev 4f4c6397a9 🏗️ Refactor: Major LLVM codegen modularization + Phase 15 docs cleanup + Phase 21 DDD concept
## LLVM Codegen Refactoring (by ChatGPT5)
- Split massive boxcall.rs into focused submodules:
  - strings.rs: String method optimizations (concat, length)
  - arrays.rs: Array operations (get, set, push, length)
  - maps.rs: Map operations (get, set, has, size)
  - fields.rs: getField/setField handling
  - invoke.rs: Tagged invoke implementation
  - marshal.rs: Helper functions for marshaling
- Improved code organization and maintainability
- No functional changes, pure refactoring

## Phase 15 Documentation Cleanup
- Restructured phase-15 folder:
  - implementation/: Technical implementation docs
  - planning/: Planning and sequence docs
  - archive/: Redundant/old content
- Removed duplicate content (80k→20k line reduction mentioned 5 times)
- Converted all .txt files to .md for consistency
- Fixed broken links in README.md
- Removed redundant INDEX.md

## Phase 21: Database-Driven Development (New)
- Revolutionary concept: Source code in SQLite instead of files
- Instant refactoring with SQL transactions
- Structured management of boxes, methods, dependencies
- Technical design with security considerations
- Vision: World's first DB-driven programming language

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 00:35:11 +09:00

3.6 KiB
Raw Blame History

Phase 15 セルフホスティング準備まとめ

作成日: 2025-09-03 作成者: Claude (Gemini・Codex協議結果統合)

専門家の技術評価まとめ

Gemini先生の分析

  • 実現可能性: MIR 13命令で十分実現可能、BoxCallの設計が鍵
  • 推奨バックエンド: Cranelift + lld開発速度・安全性・成熟度
  • コード削減: 75%削減は現実的Arc→GC、動的ディスパッチ
  • 段階的アプローチ: まず動くものを作り、後から最適化

Codex先生の具体設計

  • BoxCall実装: 隠れクラスShape+ vtable + セレクタインターン
  • JIT最適化: IC/PIC、Shapeガード、devirtualization
  • ブートストラップ: c0→c1→c1'の具体手順、決定論的ビルド
  • 並列化: GCでロック削減、フェーズ境界でバリア同期

今すぐ着手可能な準備作業

1. BoxCall設計の詳細化最優先

// BoxCall命令のメタデータ設計
BoxCall {
    dst: ValueId,
    receiver: ValueId,
    selector: Sel(u32),  // インターン化されたメソッド名
    args: Vec<ValueId>,
    flags: {
        op_kind: OpKind,     // Get/Set/Invoke/Convert
        target_type: Option<TypeId>,
        site_id: u32,        // IC/PIC管理用
    }
}

2. 最小言語サブセット定義

必須機能:

  • 基本型Integer, String, Bool, Array, Map
  • Box定義box, birth, field, method
  • 制御構造if, loop, return
  • 関数定義static/instance method
  • エラー処理Result型

初期は省略:

  • ジェネリクス
  • trait/interface
  • マクロ
  • 非同期async/await

3. セレクタインターン実装

// src/runtime/selector_intern.rs
pub struct SelectorInterner {
    string_to_id: HashMap<String, Sel>,
    id_to_string: Vec<String>,
}

4. TypeDesc/VTable構造定義

// crates/nyrt/src/types.rs
pub struct TypeDesc {
    id: TypeId,
    vtable: *const VTable,
    shape_epoch: u32,
}

pub struct VTable {
    get: fn(recv: *mut BoxHdr, sel: Sel) -> Value,
    set: fn(recv: *mut BoxHdr, sel: Sel, val: Value),
    invoke: fn(recv: *mut BoxHdr, sel: Sel, args: &[Value]) -> Value,
    // ... 他のメソッド
}

5. MIR最適化パス準備

  • BoxCallのdevirtualization検出
  • Shapeガード生成
  • IC/PICサイト管理

実装ロードマップ

Phase 1: 基盤整備1-2ヶ月

  1. BoxCall命令の完全定義
  2. セレクタインターンシステム
  3. TypeDesc/VTable基盤
  4. 最小サブセット言語仕様

Phase 2: プロトタイプ2-3ヶ月

  1. 素朴なBoxCall実装文字列ディスパッチ
  2. Cranelift統合
  3. 最小コンパイラc0.5)実装

Phase 3: 最適化2-3ヶ月

  1. Shape/vtableハイブリッド
  2. IC/PIC実装
  3. devirtualization

Phase 4: セルフホスティング2-3ヶ月

  1. c1実装Nyashで20,000行
  2. ブートストラップ検証
  3. 性能チューニング

技術的リスクと対策

リスク

  1. BoxCallの性能オーバーヘッド
  2. ブートストラップの決定論性
  3. デバッグの困難さ

対策

  1. 早期にIC/PIC実装で緩和
  2. SOURCE_DATE_EPOCH等で環境統一
  3. MIRダンプ比較ツール整備

成功の指標

  • c1がc1'を正しくコンパイル(バイナリ一致)
  • 80,000行→20,000行達成
  • VM比2倍以上の性能Cranelift JIT

次のアクション

  1. BoxCall詳細設計ドキュメント作成
  2. セレクタインターン実装開始
  3. 最小サブセット言語仕様確定
  4. MIRへのBoxCallメタデータ追加