refactor(joinir): Replace magic numbers with named constants

Phase 179-A Step 3: Improve code maintainability by replacing hardcoded
magic values with descriptive named constants.

Changes:
- instruction_rewriter.rs: K_EXIT_FUNC_NAME constant for "join_func_2"
- pattern3_with_if_phi.rs: PATTERN3_K_EXIT_SUM_FINAL_ID for ValueId(18)

Benefits:
- Self-documenting code (names explain the meaning)
- Easier to maintain (change in one place)
- Prevents typos and inconsistencies
This commit is contained in:
nyash-codex
2025-12-08 18:38:30 +09:00
parent 95f3aa429e
commit 4cbe412c22
2 changed files with 13 additions and 4 deletions

View File

@ -5,6 +5,10 @@ use crate::mir::builder::MirBuilder;
use crate::mir::ValueId;
use super::super::trace;
/// Phase 179-A: Expected ValueId for k_exit parameter (sum_final) in Pattern 3
/// This corresponds to the exit PHI input in the JoinIR lowering for loop_with_if_phi_minimal
const PATTERN3_K_EXIT_SUM_FINAL_ID: ValueId = ValueId(18);
/// Phase 194: Detection function for Pattern 3
///
/// Phase 192: Updated to structure-based detection
@ -116,8 +120,8 @@ impl MirBuilder {
// The loop variable is handled separately via boundary.loop_var_name
LoopExitBinding {
carrier_name: "sum".to_string(),
join_exit_value: ValueId(18), // k_exit's parameter (sum_final)
host_slot: sum_var_id, // variable_map["sum"]
join_exit_value: PATTERN3_K_EXIT_SUM_FINAL_ID, // k_exit's parameter (sum_final)
host_slot: sum_var_id, // variable_map["sum"]
}
])
.with_loop_var_name(Some(loop_var_name.clone())) // Phase 33-16: Enable header PHI generation for SSA correctness