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:
@ -5,6 +5,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Phase 4 Extraction: Separated from merge_joinir_mir_blocks (lines 260-546)
|
//! Phase 4 Extraction: Separated from merge_joinir_mir_blocks (lines 260-546)
|
||||||
//! Phase 33-17: Further modularization - extracted TailCallClassifier and MergeResult
|
//! Phase 33-17: Further modularization - extracted TailCallClassifier and MergeResult
|
||||||
|
//! Phase 179-A Step 3: Named constants for magic values
|
||||||
|
|
||||||
use crate::mir::{BasicBlock, BasicBlockId, MirInstruction, MirModule, ValueId};
|
use crate::mir::{BasicBlock, BasicBlockId, MirInstruction, MirModule, ValueId};
|
||||||
use crate::mir::builder::joinir_id_remapper::JoinIrIdRemapper;
|
use crate::mir::builder::joinir_id_remapper::JoinIrIdRemapper;
|
||||||
@ -14,6 +15,10 @@ use super::tail_call_classifier::{TailCallKind, classify_tail_call};
|
|||||||
use super::merge_result::MergeResult;
|
use super::merge_result::MergeResult;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
/// Phase 179-A: Exit continuation function name (MIR convention)
|
||||||
|
/// This is the standard name for k_exit continuations in JoinIR → MIR lowering
|
||||||
|
const K_EXIT_FUNC_NAME: &str = "join_func_2";
|
||||||
|
|
||||||
/// Phase 4: Merge ALL functions and rewrite instructions
|
/// Phase 4: Merge ALL functions and rewrite instructions
|
||||||
///
|
///
|
||||||
/// Returns:
|
/// Returns:
|
||||||
@ -88,8 +93,8 @@ pub(super) fn merge_and_rewrite(
|
|||||||
// Phase 33-15: Identify continuation functions (join_func_2 = k_exit, etc.)
|
// Phase 33-15: Identify continuation functions (join_func_2 = k_exit, etc.)
|
||||||
// Continuation functions receive values from Jump args, not as independent sources
|
// Continuation functions receive values from Jump args, not as independent sources
|
||||||
// We should NOT collect their Return values for exit_phi_inputs
|
// We should NOT collect their Return values for exit_phi_inputs
|
||||||
// Note: MIR uses "join_func_N" naming, where N=2 is typically k_exit
|
// Phase 179-A: Use named constant for k_exit function name
|
||||||
let is_continuation_func = func_name == "join_func_2" || func_name.ends_with("k_exit");
|
let is_continuation_func = func_name == K_EXIT_FUNC_NAME || func_name.ends_with("k_exit");
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
|||||||
@ -5,6 +5,10 @@ use crate::mir::builder::MirBuilder;
|
|||||||
use crate::mir::ValueId;
|
use crate::mir::ValueId;
|
||||||
use super::super::trace;
|
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 194: Detection function for Pattern 3
|
||||||
///
|
///
|
||||||
/// Phase 192: Updated to structure-based detection
|
/// Phase 192: Updated to structure-based detection
|
||||||
@ -116,7 +120,7 @@ impl MirBuilder {
|
|||||||
// The loop variable is handled separately via boundary.loop_var_name
|
// The loop variable is handled separately via boundary.loop_var_name
|
||||||
LoopExitBinding {
|
LoopExitBinding {
|
||||||
carrier_name: "sum".to_string(),
|
carrier_name: "sum".to_string(),
|
||||||
join_exit_value: ValueId(18), // k_exit's parameter (sum_final)
|
join_exit_value: PATTERN3_K_EXIT_SUM_FINAL_ID, // k_exit's parameter (sum_final)
|
||||||
host_slot: sum_var_id, // variable_map["sum"]
|
host_slot: sum_var_id, // variable_map["sum"]
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user