refactor(mir): Remove VariableContext legacy fields (Phase 2-6/7)
完全移行→削除の安全順序(Option C)に従い、VariableContext の deprecated フィールドと sync helpers を完全削除。 ## Changes - Migrated all 66+ access sites to variable_ctx.variable_map - Removed 1 deprecated field (variable_map) from MirBuilder - Removed 2 sync helpers (sync_variable_ctx_to_legacy, sync_legacy_to_variable_ctx) - Fixed BoxCompilationContext.variable_map references (kept as-is, different scope) - Fixed ExitBindingBuilder.variable_map references (kept as-is, local field) - Updated observer.rs to use variable_map() accessor method ## JoinIR Integration Verified - CarrierInfo::from_variable_map() works correctly - ExitLine contract maintained (Phase 132-135) - NYASH_TRACE_VARMAP debug support preserved - Pattern 1-5 lowering all functional ## Tests - cargo test --release --lib: 1033 passed, 0 failed - phase135_trim_mir_verify.sh: PASS (MIR SSA/ValueId OK) - cargo build --release: SUCCESS - Deprecation warnings: reduced (86 remaining, from other contexts) ## Statistics - 27 files changed - 146 insertions(+), 174 deletions(-) - Net: -28 lines Phase 2 Progress: 6/7 contexts complete (86%) - ✅ MetadataContext - ✅ CoreContext - ✅ TypeContext - ✅ ScopeContext - ✅ BindingContext - ✅ VariableContext (this commit) - ⏳ CompilationContext (Phase 2-7 next) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -54,7 +54,7 @@ impl MirBuilder {
|
||||
let ctx = build_pattern_context(self, condition, body, PatternVariant::Pattern1)?;
|
||||
|
||||
// Phase 195: Use unified trace
|
||||
trace::trace().varmap("pattern1_start", &self.variable_map);
|
||||
trace::trace().varmap("pattern1_start", &self.variable_ctx.variable_map);
|
||||
|
||||
// Phase 202-A: Create JoinValueSpace for unified ValueId allocation
|
||||
// Pattern 1 uses Param region for boundary input slots (loop var) and Local region for temps.
|
||||
|
||||
@ -108,7 +108,7 @@ fn prepare_pattern2_inputs(
|
||||
ConditionEnvBuilder::build_for_break_condition_v2(
|
||||
condition,
|
||||
&loop_var_name,
|
||||
&builder.variable_map,
|
||||
&builder.variable_ctx.variable_map,
|
||||
loop_var_id,
|
||||
&mut join_value_space,
|
||||
)?;
|
||||
@ -140,7 +140,7 @@ fn prepare_pattern2_inputs(
|
||||
|
||||
// Add captured vars
|
||||
for var in &captured_env.vars {
|
||||
if let Some(&host_id) = builder.variable_map.get(&var.name) {
|
||||
if let Some(&host_id) = builder.variable_ctx.variable_map.get(&var.name) {
|
||||
let join_id = join_value_space.alloc_param();
|
||||
env.insert(var.name.clone(), join_id);
|
||||
condition_bindings.push(ConditionBinding {
|
||||
@ -676,7 +676,7 @@ pub(crate) fn can_lower(builder: &MirBuilder, ctx: &super::router::LoopPatternCo
|
||||
CommonPatternInitializer::check_carrier_updates_allowed(
|
||||
ctx.body,
|
||||
&loop_var_name,
|
||||
&builder.variable_map,
|
||||
&builder.variable_ctx.variable_map,
|
||||
)
|
||||
}
|
||||
|
||||
@ -745,7 +745,7 @@ impl MirBuilder {
|
||||
use super::pattern_pipeline::{build_pattern_context, PatternVariant};
|
||||
let ctx = build_pattern_context(self, condition, _body, PatternVariant::Pattern2)?;
|
||||
|
||||
trace::trace().varmap("pattern2_start", &self.variable_map);
|
||||
trace::trace().varmap("pattern2_start", &self.variable_ctx.variable_map);
|
||||
|
||||
let mut inputs =
|
||||
prepare_pattern2_inputs(self, condition, _body, fn_body, &ctx, verbose)?;
|
||||
@ -977,11 +977,11 @@ mod tests {
|
||||
use crate::mir::ValueId;
|
||||
|
||||
let mut builder = MirBuilder::new();
|
||||
builder.variable_map.insert("i".to_string(), ValueId(1));
|
||||
builder.variable_map.insert("len".to_string(), ValueId(2));
|
||||
builder.variable_map.insert("s".to_string(), ValueId(3));
|
||||
builder.variable_map.insert("digits".to_string(), ValueId(4));
|
||||
builder.variable_map.insert("result".to_string(), ValueId(5));
|
||||
builder.variable_ctx.variable_map.insert("i".to_string(), ValueId(1));
|
||||
builder.variable_ctx.variable_map.insert("len".to_string(), ValueId(2));
|
||||
builder.variable_ctx.variable_map.insert("s".to_string(), ValueId(3));
|
||||
builder.variable_ctx.variable_map.insert("digits".to_string(), ValueId(4));
|
||||
builder.variable_ctx.variable_map.insert("result".to_string(), ValueId(5));
|
||||
|
||||
let condition = bin(BinaryOperator::Less, var("i"), var("len"));
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@ impl MirBuilder {
|
||||
ConditionEnvBuilder::build_for_break_condition_v2(
|
||||
condition,
|
||||
&loop_var_name,
|
||||
&self.variable_map,
|
||||
&self.variable_ctx.variable_map,
|
||||
loop_var_id,
|
||||
&mut join_value_space,
|
||||
)?;
|
||||
@ -183,7 +183,7 @@ impl MirBuilder {
|
||||
// Collect parent-defined variables from function scope
|
||||
// For now, use all variables in variable_map except loop_var
|
||||
let parent_defined: Vec<String> = self
|
||||
.variable_map
|
||||
.variable_ctx.variable_map
|
||||
.keys()
|
||||
.filter(|name| *name != &loop_var_name)
|
||||
.cloned()
|
||||
|
||||
@ -81,7 +81,7 @@ pub(crate) fn can_lower(builder: &MirBuilder, ctx: &super::router::LoopPatternCo
|
||||
CommonPatternInitializer::check_carrier_updates_allowed(
|
||||
ctx.body,
|
||||
&loop_var_name,
|
||||
&builder.variable_map,
|
||||
&builder.variable_ctx.variable_map,
|
||||
)
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ fn lower_pattern4_joinir(
|
||||
use crate::mir::join_ir::lowering::loop_with_continue_minimal::lower_loop_with_continue_minimal;
|
||||
use crate::mir::join_ir::lowering::JoinInlineBoundaryBuilder;
|
||||
|
||||
trace::trace().varmap("pattern4_start", &builder.variable_map);
|
||||
trace::trace().varmap("pattern4_start", &builder.variable_ctx.variable_map);
|
||||
|
||||
let mut join_value_space = JoinValueSpace::new();
|
||||
|
||||
|
||||
@ -316,9 +316,9 @@ pub(crate) fn lower(
|
||||
);
|
||||
}
|
||||
|
||||
// Step 2: Get counter ValueId from variable_map
|
||||
let counter_id = builder.variable_map.get(&counter_name).copied().ok_or_else(|| {
|
||||
format!("Counter variable '{}' not found in variable_map", counter_name)
|
||||
// Step 2: Get counter ValueId from variable_ctx.variable_map
|
||||
let counter_id = builder.variable_ctx.variable_map.get(&counter_name).copied().ok_or_else(|| {
|
||||
format!("Counter variable '{}' not found in variable_ctx.variable_map", counter_name)
|
||||
})?;
|
||||
|
||||
if debug {
|
||||
|
||||
@ -263,7 +263,7 @@ pub(crate) fn build_pattern_context(
|
||||
let (loop_var_name, loop_var_id, carrier_info) = CommonPatternInitializer::initialize_pattern(
|
||||
builder,
|
||||
condition,
|
||||
&builder.variable_map,
|
||||
&builder.variable_ctx.variable_map,
|
||||
None, // No exclusions for now (Pattern 2/4 will filter carriers later)
|
||||
)?;
|
||||
|
||||
|
||||
@ -280,7 +280,7 @@ impl TrimLoopLowerer {
|
||||
Self::generate_carrier_initialization(builder, body, trim_helper)?;
|
||||
|
||||
eprintln!(
|
||||
"[TrimLoopLowerer] Registered carrier '{}' in variable_map",
|
||||
"[TrimLoopLowerer] Registered carrier '{}' in variable_ctx.variable_map",
|
||||
trim_helper.carrier_name
|
||||
);
|
||||
|
||||
@ -328,7 +328,7 @@ impl TrimLoopLowerer {
|
||||
/// Generates:
|
||||
/// 1. ch0 = s.substring(start, start+1)
|
||||
/// 2. is_ch_match0 = (ch0 == " " || ch0 == "\t" || ...)
|
||||
/// 3. Registers carrier in variable_map
|
||||
/// 3. Registers carrier in variable_ctx.variable_map
|
||||
fn generate_carrier_initialization(
|
||||
builder: &mut MirBuilder,
|
||||
body: &[ASTNode],
|
||||
@ -353,7 +353,7 @@ impl TrimLoopLowerer {
|
||||
|
||||
// Get ValueIds for string and start
|
||||
let s_id =
|
||||
builder.variable_map.get(&s_name).copied().ok_or_else(|| {
|
||||
builder.variable_ctx.variable_map.get(&s_name).copied().ok_or_else(|| {
|
||||
format!("[TrimLoopLowerer] String variable '{}' not found", s_name)
|
||||
})?;
|
||||
|
||||
@ -401,9 +401,9 @@ impl TrimLoopLowerer {
|
||||
is_ch_match0
|
||||
);
|
||||
|
||||
// Register carrier in variable_map
|
||||
// Register carrier in variable_ctx.variable_map
|
||||
builder
|
||||
.variable_map
|
||||
.variable_ctx.variable_map
|
||||
.insert(trim_helper.carrier_name.clone(), is_ch_match0);
|
||||
|
||||
Ok(())
|
||||
@ -438,7 +438,7 @@ impl TrimLoopLowerer {
|
||||
let mut bindings = Vec::new();
|
||||
|
||||
// Add carrier to ConditionEnv
|
||||
let get_value = |name: &str| builder.variable_map.get(name).copied();
|
||||
let get_value = |name: &str| builder.variable_ctx.variable_map.get(name).copied();
|
||||
let mut env_temp = std::collections::HashMap::new(); // Temporary env for closure
|
||||
|
||||
let binding = TrimPatternLowerer::add_to_condition_env(
|
||||
|
||||
Reference in New Issue
Block a user