feat(mir): Phase 26-A-2 MirBuilder統合完了 - 型情報マップ実装
## ✅ 実装内容 - **フィールド追加**: `value_kinds: HashMap<ValueId, MirValueKind>` - ValueId→MirValueKindのマッピング - デフォルト未登録はTemporary扱い - **新規メソッド**(6個): - `new_typed_value()`: 型付きValueId発行 - `get_value_kind()`: 既存ValueIdの型取得 - `register_value_kind()`: 型情報後付け - `is_value_parameter()`: ValueIdベースのParameter判定 - `is_value_local()`: ValueIdベースのLocal判定 - `is_value_loop_carrier()`: ValueIdベースのLoopCarrier判定 ## ✅ テスト結果 - **241テストPASS**: 既存機能に回帰なし - 1失敗: mir_funcscanner_skip_ws (PHI nodeバグ、Phase 26-A-4で修正予定) ## 🎯 GUARD Bug Prevention `is_value_parameter()`でValueId(0)の型安全判定が可能に ## 📋 次のステップ - Phase 26-A-3: パラメータ登録修正(型情報自動付与) - Phase 26-A-4: loop_builder.rs修正(名前ベース→ValueIdベース) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -116,6 +116,12 @@ pub struct MirBuilder {
|
|||||||
/// 注意: compilation_contextがSomeの場合は使用されません
|
/// 注意: compilation_contextがSomeの場合は使用されません
|
||||||
pub(super) value_types: HashMap<ValueId, super::MirType>,
|
pub(super) value_types: HashMap<ValueId, super::MirType>,
|
||||||
|
|
||||||
|
/// Phase 26-A: ValueId型情報マップ(型安全性強化)
|
||||||
|
/// ValueId -> MirValueKind のマッピング
|
||||||
|
/// - GUARDバグ予防: ValueId(0)がParameterかLocalか区別可能
|
||||||
|
/// - デフォルト: 未登録のValueIdはTemporary扱い
|
||||||
|
pub(super) value_kinds: HashMap<ValueId, super::MirValueKind>,
|
||||||
|
|
||||||
/// 関数スコープの SlotRegistry(観測専用)
|
/// 関数スコープの SlotRegistry(観測専用)
|
||||||
/// - current_function と同じライフサイクルを持つよ。
|
/// - current_function と同じライフサイクルを持つよ。
|
||||||
/// - 既存の variable_map/SSA には影響しない(メタデータのみ)。
|
/// - 既存の variable_map/SSA には影響しない(メタデータのみ)。
|
||||||
@ -240,6 +246,7 @@ impl MirBuilder {
|
|||||||
field_origin_class: HashMap::new(),
|
field_origin_class: HashMap::new(),
|
||||||
field_origin_by_box: HashMap::new(),
|
field_origin_by_box: HashMap::new(),
|
||||||
value_types: HashMap::new(),
|
value_types: HashMap::new(),
|
||||||
|
value_kinds: HashMap::new(), // Phase 26-A: ValueId型安全化
|
||||||
current_slot_registry: None,
|
current_slot_registry: None,
|
||||||
type_registry: type_registry::TypeRegistry::new(),
|
type_registry: type_registry::TypeRegistry::new(),
|
||||||
plugin_method_sigs,
|
plugin_method_sigs,
|
||||||
@ -842,10 +849,47 @@ impl MirBuilder {
|
|||||||
false
|
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<super::MirValueKind> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user