refactor(joinir): Phase 229 - Remove redundant ConditionAlias
Replace static alias mapping with dynamic condition variable resolution using: - promoted_loopbodylocals as source of truth - Naming conventions: is_<var> or is_<var>_match - Pattern-aware inference during lowering Benefits: - Simpler data structure (6 fields → 5) - Single source of truth - Self-documenting with explicit naming conventions - Fewer maintenance points Net: -25 lines (60 additions, 85 deletions) Tests: 877/884 PASS (no regressions) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -348,43 +348,42 @@ impl MirBuilder {
|
||||
carrier.name, carrier_join_id);
|
||||
}
|
||||
|
||||
// Phase 224-D: Save carriers with join_ids BEFORE filtering
|
||||
let carriers_with_join_ids = carrier_info.carriers.clone();
|
||||
// Phase 229: Dynamic condition variable resolution for promoted variables
|
||||
// Instead of using condition_aliases, we dynamically resolve promoted variables
|
||||
// using promoted_loopbodylocals + naming convention
|
||||
for promoted_var in &carrier_info.promoted_loopbodylocals {
|
||||
// Try both naming conventions:
|
||||
// 1. DigitPos pattern: "var" → "is_var"
|
||||
// 2. Trim pattern: "var" → "is_var_match"
|
||||
|
||||
// Phase 224-D: Add condition aliases to ConditionEnv
|
||||
// This allows promoted variables to be referenced by their original names in conditions
|
||||
for alias in &carrier_info.condition_aliases {
|
||||
// Check if the carrier_name matches the loop_var_name (promoted as main carrier)
|
||||
if alias.carrier_name == carrier_info.loop_var_name {
|
||||
// Use loop variable's join_id from env
|
||||
if let Some(join_id) = env.get(&carrier_info.loop_var_name) {
|
||||
env.insert(alias.old_name.clone(), join_id);
|
||||
eprintln!(
|
||||
"[pattern2/phase224d] Added condition alias '{}' → loop_var '{}' (join_id={:?})",
|
||||
alias.old_name, carrier_info.loop_var_name, join_id
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Find the carrier's join_id in the carriers list (BEFORE filtering, with join_ids)
|
||||
if let Some(carrier) = carriers_with_join_ids.iter().find(|c| c.name == alias.carrier_name) {
|
||||
if let Some(join_id) = carrier.join_id {
|
||||
// Add alias mapping: old_name → carrier's join_id
|
||||
env.insert(alias.old_name.clone(), join_id);
|
||||
let candidate_names = vec![
|
||||
format!("is_{}", promoted_var), // DigitPos pattern
|
||||
format!("is_{}_match", promoted_var), // Trim pattern
|
||||
];
|
||||
|
||||
for carrier_name in candidate_names {
|
||||
// Check if it's the loop variable
|
||||
if carrier_name == carrier_info.loop_var_name {
|
||||
if let Some(join_id) = env.get(&carrier_info.loop_var_name) {
|
||||
env.insert(promoted_var.clone(), join_id);
|
||||
eprintln!(
|
||||
"[pattern2/phase224d] Added condition alias '{}' → carrier '{}' (join_id={:?})",
|
||||
alias.old_name, alias.carrier_name, join_id
|
||||
);
|
||||
} else {
|
||||
eprintln!(
|
||||
"[pattern2/phase224d] WARNING: Carrier '{}' has no join_id yet!",
|
||||
alias.carrier_name
|
||||
"[pattern2/phase229] Dynamically resolved promoted '{}' → loop_var '{}' (join_id={:?})",
|
||||
promoted_var, carrier_info.loop_var_name, join_id
|
||||
);
|
||||
break; // Found resolution
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise check carriers
|
||||
if let Some(carrier) = carrier_info.carriers.iter().find(|c| c.name == carrier_name) {
|
||||
if let Some(join_id) = carrier.join_id {
|
||||
env.insert(promoted_var.clone(), join_id);
|
||||
eprintln!(
|
||||
"[pattern2/phase229] Dynamically resolved promoted '{}' → carrier '{}' (join_id={:?})",
|
||||
promoted_var, carrier_name, join_id
|
||||
);
|
||||
break; // Found resolution
|
||||
}
|
||||
} else {
|
||||
eprintln!(
|
||||
"[pattern2/phase224d] WARNING: Carrier '{}' not found in carriers list!",
|
||||
alias.carrier_name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,6 @@ impl Pattern4CarrierAnalyzer {
|
||||
carriers: updated_carriers,
|
||||
trim_helper: all_carriers.trim_helper.clone(),
|
||||
promoted_loopbodylocals: all_carriers.promoted_loopbodylocals.clone(), // Phase 224
|
||||
condition_aliases: all_carriers.condition_aliases.clone(), // Phase 224-D
|
||||
})
|
||||
}
|
||||
|
||||
@ -296,7 +295,6 @@ mod tests {
|
||||
],
|
||||
trim_helper: None,
|
||||
promoted_loopbodylocals: Vec::new(), // Phase 224
|
||||
condition_aliases: Vec::new(), // Phase 224-D
|
||||
};
|
||||
|
||||
// Analyze carriers
|
||||
|
||||
@ -409,7 +409,6 @@ mod tests {
|
||||
],
|
||||
trim_helper: None,
|
||||
promoted_loopbodylocals: Vec::new(), // Phase 224
|
||||
condition_aliases: Vec::new(), // Phase 224-D
|
||||
},
|
||||
loop_scope: LoopScopeShapeBuilder::empty_body_locals(
|
||||
BasicBlockId(0),
|
||||
@ -449,7 +448,6 @@ mod tests {
|
||||
whitespace_chars: vec![" ".to_string(), "\t".to_string()],
|
||||
}),
|
||||
promoted_loopbodylocals: Vec::new(), // Phase 224
|
||||
condition_aliases: Vec::new(), // Phase 224-D
|
||||
},
|
||||
loop_scope: LoopScopeShapeBuilder::empty_body_locals(
|
||||
BasicBlockId(0),
|
||||
|
||||
Reference in New Issue
Block a user