feat(builder): CalleeBoxKind構造ガードで静的/ランタイムBox混線を根絶

🎯 箱理論の実践: 「境界を作る」原則による構造レベル分離

## 問題
- StageBArgsBox.resolve_src内のargs.get(i)が
  Stage1UsingResolverBox.getに化ける(静的Box名混入)
- 未定義ValueIdエラー発生(receiver定義なし)

## 解決策(構造ガード)
 CalleeBoxKind enum追加
  - StaticCompiler: Stage-B/Stage-1コンパイラBox
  - RuntimeData: MapBox/ArrayBox等ランタイムBox
  - UserDefined: ユーザー定義Box

 classify_box_kind(): Box名から種別判定
  - 静的Box群を明示的に列挙(1箇所に集約)
  - ランタイムBox群を明示的に列挙
  - 将来の拡張も容易

 apply_static_runtime_guard(): 混線検出・正規化
  - me-call判定(receiver型==box_name → 静的降下に委ねる)
  - 真の混線検出(receiver型≠box_name → 正規化)
  - トレースログで可視化

## 効果
- 修正前: Invalid value ValueId(150/187)
- 修正後: Unknown method 'is_space' (別issue、StringBox実装不足)
- → 静的Box名混入問題を根絶!

## 箱理論原則
-  境界を作る: Static/Runtime/UserDefinedを構造的に分離
-  Fail-Fast: フォールバックより明示的エラー
-  箱にする: CalleeBoxKindでBox種類を1箇所に集約

## ファイル
- src/mir/definitions/call_unified.rs: CalleeBoxKind enum
- src/mir/builder/calls/call_unified.rs: classify_box_kind()
- src/mir/builder/calls/emit.rs: apply_static_runtime_guard()
- docs/development/roadmap/phases/phase-25.1d/README.md: 箱化メモ更新

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-17 23:13:57 +09:00
parent 3e3e6318bb
commit 73844dbe04
16 changed files with 577 additions and 35 deletions

View File

@ -16,6 +16,20 @@ pub enum TypeCertainty {
Union,
}
/// Classification of Box types to prevent static/runtime mixing
/// Prevents Stage-B/Stage-1 compiler boxes from being confused with runtime data boxes
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CalleeBoxKind {
/// Static compiler boxes (StageBArgsBox, Stage1UsingResolverBox, BundleResolver, ParserBox, etc.)
/// These are only for compile-time static method lowering
StaticCompiler,
/// Runtime data boxes (MapBox, ArrayBox, StringBox, IntegerBox, etc.)
/// These handle actual runtime values and method dispatch
RuntimeData,
/// User-defined boxes (neither compiler nor built-in runtime)
UserDefined,
}
/// Call target specification for type-safe function resolution
/// Replaces runtime string-based resolution with compile-time typed targets
#[derive(Debug, Clone, PartialEq)]
@ -31,6 +45,7 @@ pub enum Callee {
method: String, // "upper", "print", etc.
receiver: Option<ValueId>, // Some(obj) for instance, None for static/constructor
certainty: TypeCertainty, // Phase 3: known vs union
box_kind: CalleeBoxKind, // Structural guard: prevent static/runtime mixing
},
/// Constructor call (NewBox equivalent)
@ -192,6 +207,7 @@ impl MirCall {
method,
receiver: Some(receiver),
certainty: TypeCertainty::Known,
box_kind: CalleeBoxKind::RuntimeData, // Default to runtime for helper
},
args,
)
@ -307,6 +323,7 @@ pub mod migration {
method,
receiver: Some(box_val),
certainty: TypeCertainty::Union,
box_kind: CalleeBoxKind::RuntimeData, // BoxCall is always runtime
},
args,
);