diff --git a/src/mir/builder.rs b/src/mir/builder.rs index 970602cf..36c26387 100644 --- a/src/mir/builder.rs +++ b/src/mir/builder.rs @@ -116,6 +116,12 @@ pub struct MirBuilder { /// 注意: compilation_contextがSomeの場合は使用されません pub(super) value_types: HashMap, + /// Phase 26-A: ValueId型情報マップ(型安全性強化) + /// ValueId -> MirValueKind のマッピング + /// - GUARDバグ予防: ValueId(0)がParameterかLocalか区別可能 + /// - デフォルト: 未登録のValueIdはTemporary扱い + pub(super) value_kinds: HashMap, + /// 関数スコープの SlotRegistry(観測専用) /// - current_function と同じライフサイクルを持つよ。 /// - 既存の variable_map/SSA には影響しない(メタデータのみ)。 @@ -240,6 +246,7 @@ impl MirBuilder { field_origin_class: HashMap::new(), field_origin_by_box: HashMap::new(), value_types: HashMap::new(), + value_kinds: HashMap::new(), // Phase 26-A: ValueId型安全化 current_slot_registry: None, type_registry: type_registry::TypeRegistry::new(), plugin_method_sigs, @@ -842,10 +849,47 @@ impl MirBuilder { false } + // ============================================================================ + // Phase 26-A: ValueId型安全化メソッド + // ============================================================================ + /// 型付きValueIdを発行(新API) + pub fn new_typed_value(&mut self, kind: super::MirValueKind) -> super::TypedValueId { + let id = self.value_gen.next(); + self.value_kinds.insert(id, kind); + super::TypedValueId::new(id, kind) + } + /// 既存ValueIdの型情報を取得 + pub fn get_value_kind(&self, id: ValueId) -> Option { + self.value_kinds.get(&id).copied() + } + /// 既存ValueIdに型情報を後付け(レガシー互換用) + pub fn register_value_kind(&mut self, id: ValueId, kind: super::MirValueKind) { + self.value_kinds.insert(id, kind); + } + /// 型安全なパラメータ判定(ValueIdベース) - GUARD Bug Prevention + pub fn is_value_parameter(&self, id: ValueId) -> bool { + self.get_value_kind(id) + .map(|kind| kind.is_parameter()) + .unwrap_or(false) + } + + /// 型安全なローカル変数判定(ValueIdベース) + pub fn is_value_local(&self, id: ValueId) -> bool { + self.get_value_kind(id) + .map(|kind| kind.is_local()) + .unwrap_or(false) + } + + /// 型安全なLoopCarrier判定(ValueIdベース) + pub fn is_value_loop_carrier(&self, id: ValueId) -> bool { + self.get_value_kind(id) + .map(|kind| kind.is_loop_carrier()) + .unwrap_or(false) + } }