refactor(mir): Remove TypeContext legacy fields (Phase 2-3/7)
完全移行→削除の安全順序(Option C)に従い、TypeContext の deprecated フィールドと sync helpers を完全削除。 ⚠️ 危険ゾーン: TypeFactsBox 等の同名フィールドと混同しないよう、 ファイル単位で手作業移行を実施。 ## Changes - Migrated all MirBuilder access sites to type_ctx.* (manual, 40+ files) - Removed 3 deprecated fields (value_types, value_kinds, value_origin_newbox) - Removed 2 sync helpers (sync_type_ctx_to_legacy, sync_legacy_to_type_ctx) - Verified TypeFactsBox, CalleeGuardBox unchanged (no false positives) ## Tests - cargo test --release --lib: 1029/1033 PASS - TypeFactsBox integration: PASS (borrowed references unchanged) - Deprecation warnings: 456 → 255 (-201, -44%) ## Safety Verification ✅ TypeFactsBox unchanged (still uses &'a BTreeMap borrowed references) ✅ CalleeGuardBox unchanged ✅ CalleeResolverBox unchanged ✅ BoxCompilationContext unchanged Phase 2 Progress: 3/7 contexts complete (43%) - ✅ MetadataContext - ✅ CoreContext - ✅ TypeContext (this commit) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -70,8 +70,8 @@ impl super::MirBuilder {
|
||||
// Phase 196: TypeFacts SSOT - AddOperator call type annotation
|
||||
// Phase 131-11-E: TypeFacts - classify operand types (Phase 136: use TypeFactsBox)
|
||||
let type_facts = super::type_facts::TypeFactsBox::new(
|
||||
&self.value_types,
|
||||
&self.value_origin_newbox,
|
||||
&self.type_ctx.value_types,
|
||||
&self.type_ctx.value_origin_newbox,
|
||||
);
|
||||
let lhs_type = type_facts.classify_operand_type(lhs);
|
||||
let rhs_type = type_facts.classify_operand_type(rhs);
|
||||
@ -80,14 +80,14 @@ impl super::MirBuilder {
|
||||
match (lhs_type, rhs_type) {
|
||||
(String, String) => {
|
||||
// BOTH are strings: result is string
|
||||
self.value_types
|
||||
self.type_ctx.value_types
|
||||
.insert(dst, MirType::Box("StringBox".to_string()));
|
||||
self.value_origin_newbox
|
||||
self.type_ctx.value_origin_newbox
|
||||
.insert(dst, "StringBox".to_string());
|
||||
}
|
||||
(Integer, Integer) | (Integer, Unknown) | (Unknown, Integer) => {
|
||||
// TypeFact: Integer + anything non-String = Integer
|
||||
self.value_types.insert(dst, MirType::Integer);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Integer);
|
||||
}
|
||||
(String, Integer) | (Integer, String) => {
|
||||
// Mixed types: leave as Unknown for use-site coercion
|
||||
@ -132,7 +132,7 @@ impl super::MirBuilder {
|
||||
vec![lhs, rhs],
|
||||
)?;
|
||||
// 型注釈: 算術はおおむね整数(Addは上で注釈済み)
|
||||
self.value_types.insert(dst, MirType::Integer);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Integer);
|
||||
} else {
|
||||
// guard中は従来のBinOp
|
||||
if let (Some(func), Some(cur_bb)) =
|
||||
@ -144,7 +144,7 @@ impl super::MirBuilder {
|
||||
} else {
|
||||
self.emit_instruction(MirInstruction::BinOp { dst, op, lhs, rhs })?;
|
||||
}
|
||||
self.value_types.insert(dst, MirType::Integer);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Integer);
|
||||
}
|
||||
} else {
|
||||
// 既存の算術経路
|
||||
@ -162,8 +162,8 @@ impl super::MirBuilder {
|
||||
if matches!(op, crate::mir::BinaryOp::Add) {
|
||||
// Phase 131-11-E: TypeFacts - classify operand types (Phase 136: use TypeFactsBox)
|
||||
let type_facts = super::type_facts::TypeFactsBox::new(
|
||||
&self.value_types,
|
||||
&self.value_origin_newbox,
|
||||
&self.type_ctx.value_types,
|
||||
&self.type_ctx.value_origin_newbox,
|
||||
);
|
||||
let lhs_type = type_facts.classify_operand_type(lhs);
|
||||
let rhs_type = type_facts.classify_operand_type(rhs);
|
||||
@ -172,15 +172,15 @@ impl super::MirBuilder {
|
||||
match (lhs_type, rhs_type) {
|
||||
(String, String) => {
|
||||
// BOTH are strings: result is definitely a string
|
||||
self.value_types
|
||||
self.type_ctx.value_types
|
||||
.insert(dst, MirType::Box("StringBox".to_string()));
|
||||
self.value_origin_newbox
|
||||
self.type_ctx.value_origin_newbox
|
||||
.insert(dst, "StringBox".to_string());
|
||||
}
|
||||
(Integer, Integer) | (Integer, Unknown) | (Unknown, Integer) => {
|
||||
// TypeFact: Integer + anything non-String = Integer
|
||||
// This handles `counter + 1` where counter might be Unknown
|
||||
self.value_types.insert(dst, MirType::Integer);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Integer);
|
||||
}
|
||||
(String, Integer) | (Integer, String) => {
|
||||
// Mixed types: leave as Unknown for use-site coercion
|
||||
@ -195,7 +195,7 @@ impl super::MirBuilder {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.value_types.insert(dst, MirType::Integer);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Integer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -213,38 +213,38 @@ impl super::MirBuilder {
|
||||
// String concatenation is handled at use-site in LLVM lowering
|
||||
if matches!(op, crate::mir::BinaryOp::Add) {
|
||||
// Check if BOTH operands are known to be strings (TypeFacts)
|
||||
let lhs_is_str = match self.value_types.get(&lhs) {
|
||||
let lhs_is_str = match self.type_ctx.value_types.get(&lhs) {
|
||||
Some(MirType::String) => true,
|
||||
Some(MirType::Box(bt)) if bt == "StringBox" => true,
|
||||
_ => self
|
||||
.value_origin_newbox
|
||||
.type_ctx.value_origin_newbox
|
||||
.get(&lhs)
|
||||
.map(|s| s == "StringBox")
|
||||
.unwrap_or(false),
|
||||
};
|
||||
let rhs_is_str = match self.value_types.get(&rhs) {
|
||||
let rhs_is_str = match self.type_ctx.value_types.get(&rhs) {
|
||||
Some(MirType::String) => true,
|
||||
Some(MirType::Box(bt)) if bt == "StringBox" => true,
|
||||
_ => self
|
||||
.value_origin_newbox
|
||||
.type_ctx.value_origin_newbox
|
||||
.get(&rhs)
|
||||
.map(|s| s == "StringBox")
|
||||
.unwrap_or(false),
|
||||
};
|
||||
if lhs_is_str && rhs_is_str {
|
||||
// BOTH are strings: result is definitely a string
|
||||
self.value_types
|
||||
self.type_ctx.value_types
|
||||
.insert(dst, MirType::Box("StringBox".to_string()));
|
||||
self.value_origin_newbox
|
||||
self.type_ctx.value_origin_newbox
|
||||
.insert(dst, "StringBox".to_string());
|
||||
} else if !lhs_is_str && !rhs_is_str {
|
||||
// NEITHER is a string: numeric addition
|
||||
self.value_types.insert(dst, MirType::Integer);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Integer);
|
||||
}
|
||||
// else: Mixed types (string + int or int + string)
|
||||
// Leave dst type as Unknown - LLVM will handle coercion at use-site
|
||||
} else {
|
||||
self.value_types.insert(dst, MirType::Integer);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Integer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,16 +281,16 @@ impl super::MirBuilder {
|
||||
super::builder_calls::CallTarget::Global(name),
|
||||
vec![op_const, lhs, rhs],
|
||||
)?;
|
||||
self.value_types.insert(dst, MirType::Bool);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Bool);
|
||||
} else {
|
||||
// 既存の比較経路(安全のための型注釈/slot化含む)
|
||||
let (lhs2_raw, rhs2_raw) = if self
|
||||
.value_origin_newbox
|
||||
.type_ctx.value_origin_newbox
|
||||
.get(&lhs)
|
||||
.map(|s| s == "IntegerBox")
|
||||
.unwrap_or(false)
|
||||
&& self
|
||||
.value_origin_newbox
|
||||
.type_ctx.value_origin_newbox
|
||||
.get(&rhs)
|
||||
.map(|s| s == "IntegerBox")
|
||||
.unwrap_or(false)
|
||||
@ -396,7 +396,7 @@ impl super::MirBuilder {
|
||||
func.update_cfg();
|
||||
}
|
||||
let rhs_bool = self.insert_phi_binary(rhs_true_exit, t_id, rhs_false_exit, f_id)?;
|
||||
self.value_types.insert(rhs_bool, MirType::Bool);
|
||||
self.type_ctx.value_types.insert(rhs_bool, MirType::Bool);
|
||||
rhs_bool
|
||||
} else {
|
||||
let t_id = crate::mir::builder::emission::constant::emit_bool(self, true);
|
||||
@ -450,7 +450,7 @@ impl super::MirBuilder {
|
||||
func.update_cfg();
|
||||
}
|
||||
let rhs_bool = self.insert_phi_binary(rhs_true_exit, t_id, rhs_false_exit, f_id)?;
|
||||
self.value_types.insert(rhs_bool, MirType::Bool);
|
||||
self.type_ctx.value_types.insert(rhs_bool, MirType::Bool);
|
||||
rhs_bool
|
||||
};
|
||||
let else_exit_block = self.current_block()?;
|
||||
@ -480,7 +480,7 @@ impl super::MirBuilder {
|
||||
func.update_cfg();
|
||||
}
|
||||
let dst = self.insert_phi(inputs)?;
|
||||
self.value_types.insert(dst, MirType::Bool);
|
||||
self.type_ctx.value_types.insert(dst, MirType::Bool);
|
||||
dst
|
||||
} else if inputs.len() == 1 {
|
||||
inputs[0].1
|
||||
@ -552,7 +552,7 @@ impl super::MirBuilder {
|
||||
super::builder_calls::CallTarget::Global(name.to_string()),
|
||||
vec![operand_val],
|
||||
)?;
|
||||
self.value_types.insert(dst, rett);
|
||||
self.type_ctx.value_types.insert(dst, rett);
|
||||
return Ok(dst);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user