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:
@ -49,6 +49,7 @@ mod types; // types::annotation / inference(型注釈/推論の箱: 推論
|
||||
mod router; // RouterPolicyBox(Unified vs BoxCall)
|
||||
mod emit_guard; // EmitGuardBox(emit直前の最終関所)
|
||||
mod name_const; // NameConstBox(関数名Const生成)
|
||||
pub(crate) mod type_registry; // TypeRegistryBox(型情報管理の一元化)
|
||||
|
||||
// Unified member property kinds for computed/once/birth_once
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
@ -112,6 +113,10 @@ pub struct MirBuilder {
|
||||
/// 注意: compilation_contextがSomeの場合は使用されません
|
||||
pub(super) value_types: HashMap<ValueId, super::MirType>,
|
||||
|
||||
/// 🎯 箱理論: 型情報管理の一元化(TypeRegistryBox)
|
||||
/// NYASH_USE_TYPE_REGISTRY=1 で有効化(段階的移行用)
|
||||
pub(super) type_registry: type_registry::TypeRegistry,
|
||||
|
||||
/// Plugin method return type signatures loaded from nyash_box.toml
|
||||
plugin_method_sigs: HashMap<(String, String), super::MirType>,
|
||||
/// Current static box name when lowering a static box body (e.g., "Main")
|
||||
@ -215,6 +220,7 @@ impl MirBuilder {
|
||||
field_origin_class: HashMap::new(),
|
||||
field_origin_by_box: HashMap::new(),
|
||||
value_types: HashMap::new(),
|
||||
type_registry: type_registry::TypeRegistry::new(),
|
||||
plugin_method_sigs,
|
||||
current_static_box: None,
|
||||
static_method_index: std::collections::HashMap::new(),
|
||||
@ -513,7 +519,7 @@ impl MirBuilder {
|
||||
// Must happen BEFORE function mutable borrow to avoid borrowck conflicts.
|
||||
if let MirInstruction::Call { callee: Some(callee), dst, args, effects, .. } = &instruction {
|
||||
use crate::mir::definitions::call_unified::Callee;
|
||||
if let Callee::Method { box_name, method, receiver: Some(r), certainty } = callee.clone() {
|
||||
if let Callee::Method { box_name, method, receiver: Some(r), certainty, box_kind } = callee.clone() {
|
||||
// LocalSSA: ensure receiver has a Copy in current_block
|
||||
let r_local = crate::mir::builder::ssa::local::recv(self, r);
|
||||
|
||||
@ -522,7 +528,8 @@ impl MirBuilder {
|
||||
box_name: box_name.clone(),
|
||||
method: method.clone(),
|
||||
receiver: Some(r_local),
|
||||
certainty
|
||||
certainty,
|
||||
box_kind,
|
||||
};
|
||||
instruction = MirInstruction::Call {
|
||||
dst: *dst,
|
||||
|
||||
Reference in New Issue
Block a user