refactor(mir): phase260 p0.2 hide legacy edge-args reads behind BasicBlock API
- Add block.return_env() getter for Return env metadata - Update instruction_rewriter.rs to use block.return_env() - Update exit_collection.rs to use block.return_env() - Prepare for Phase 260 P2 (jump_args deletion) This consolidates all legacy edge-args reads through BasicBlock API, enabling clean deletion of jump_args field in P2.
This commit is contained in:
@ -23,9 +23,6 @@
|
||||
- `src/mir/basic_block.rs:254` — reason: legacy setter API; expected: writer 側は edge-args を併記する経路に統一
|
||||
- `src/mir/basic_block.rs:281` — reason: legacy edge-args 生成 API; expected: read-side の移行完了後に削除(P2)
|
||||
- `src/mir/basic_block.rs:337` — reason: legacy edge-args fallback; expected: verify で legacy-only を検出し、P2で撤去
|
||||
- `src/mir/builder/control_flow/joinir/merge/rewriter/exit_collection.rs:64` — reason: legacy edge-args を read; expected: edge-args SSOT 経路に寄せて置換(P1〜P2)
|
||||
- `src/mir/builder/control_flow/joinir/merge/instruction_rewriter.rs:415` — reason: legacy edge-args read; expected: 同上
|
||||
- `src/mir/builder/control_flow/joinir/merge/instruction_rewriter.rs:930` — reason: legacy edge-args read; expected: 同上
|
||||
|
||||
## Current First FAIL (SSOT)
|
||||
|
||||
|
||||
@ -360,6 +360,20 @@ impl BasicBlock {
|
||||
})
|
||||
}
|
||||
|
||||
/// Get edge-args from the current terminator (migration helper)
|
||||
///
|
||||
/// Jump uses its edge-args operand when present, otherwise falls back to
|
||||
/// stored metadata. Return relies on stored metadata.
|
||||
pub fn edge_args_from_terminator(&self) -> Option<EdgeArgs> {
|
||||
match self.terminator {
|
||||
Some(MirInstruction::Jump { ref edge_args, .. }) => {
|
||||
edge_args.clone().or_else(|| self.legacy_edge_args())
|
||||
}
|
||||
Some(MirInstruction::Return { .. }) => self.legacy_edge_args(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a predecessor
|
||||
pub fn add_predecessor(&mut self, pred: BasicBlockId) {
|
||||
self.predecessors.insert(pred);
|
||||
|
||||
@ -31,7 +31,7 @@ use super::rewriter::type_propagation::propagate_value_type_for_inst;
|
||||
use super::rewriter::terminator::{apply_remapped_terminator, remap_branch, remap_jump};
|
||||
// Phase 260 P0.1 Step 6: exit_collection module available
|
||||
// TODO: Migrate inline Return→Jump conversion to use exit_collection functions:
|
||||
// - collect_exit_values_from_legacy_edge_args()
|
||||
// - collect_exit_values_from_edge_args()
|
||||
// - add_carrier_values_to_inputs()
|
||||
// - handle_fallback_exit_collection()
|
||||
// - collect_k_exit_values()
|
||||
@ -411,8 +411,20 @@ pub(super) fn merge_and_rewrite(
|
||||
// This is a k_exit tail call - policy says normalize to exit jump
|
||||
k_exit_lowering_decision = Some(decision);
|
||||
if let Some(b) = boundary {
|
||||
k_exit_edge_args =
|
||||
old_block.legacy_edge_args_with_layout(b.jump_args_layout);
|
||||
if let Some(edge_args) = old_block.edge_args_from_terminator() {
|
||||
if edge_args.layout != b.jump_args_layout {
|
||||
let msg = format!(
|
||||
"[joinir/merge] k_exit edge-args layout mismatch: block={:?} edge={:?} boundary={:?}",
|
||||
old_block.id, edge_args.layout, b.jump_args_layout
|
||||
);
|
||||
if strict_exit {
|
||||
return Err(msg);
|
||||
} else if debug {
|
||||
log!(true, "[DEBUG-177] {}", msg);
|
||||
}
|
||||
}
|
||||
k_exit_edge_args = Some(edge_args);
|
||||
}
|
||||
}
|
||||
found_tail_call = true;
|
||||
if debug {
|
||||
@ -925,10 +937,19 @@ pub(super) fn merge_and_rewrite(
|
||||
let mut exit_edge_args: Option<crate::mir::EdgeArgs> = None;
|
||||
if value.is_some() {
|
||||
if let Some(b) = boundary {
|
||||
// Phase 246-EX: Check if this block has legacy jump_args metadata
|
||||
if let Some(edge_args) =
|
||||
old_block.legacy_edge_args_with_layout(b.jump_args_layout)
|
||||
{
|
||||
// Phase 246-EX: Use terminator edge-args via BasicBlock API
|
||||
if let Some(edge_args) = old_block.edge_args_from_terminator() {
|
||||
if edge_args.layout != b.jump_args_layout {
|
||||
let msg = format!(
|
||||
"[joinir/merge] exit edge-args layout mismatch: block={:?} edge={:?} boundary={:?}",
|
||||
old_block.id, edge_args.layout, b.jump_args_layout
|
||||
);
|
||||
if strict_exit {
|
||||
return Err(msg);
|
||||
} else if debug {
|
||||
log!(true, "[DEBUG-177] {}", msg);
|
||||
}
|
||||
}
|
||||
log!(
|
||||
verbose,
|
||||
"[DEBUG-177] Phase 246-EX: Block {:?} has legacy jump_args metadata: {:?}",
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
//!
|
||||
//! ## Responsibilities
|
||||
//!
|
||||
//! 1. Collect exit values from legacy_edge_args (Phase 246-EX)
|
||||
//! 1. Collect exit values from terminator edge-args (Phase 246-EX)
|
||||
//! 2. Populate exit_phi_inputs and carrier_inputs
|
||||
//! 3. Handle fallback path when no jump_args present
|
||||
//!
|
||||
@ -36,14 +36,14 @@ pub(in crate::mir::builder::control_flow::joinir::merge) struct ExitCollectionRe
|
||||
pub carrier_values: Vec<(String, (BasicBlockId, ValueId))>,
|
||||
}
|
||||
|
||||
/// Collect exit values from legacy_edge_args_with_layout
|
||||
/// Collect exit values from terminator edge-args
|
||||
///
|
||||
/// Phase 246-EX: Uses legacy jump_args metadata to recover all original Jump args.
|
||||
/// Remaps values from JoinIR value space to HOST value space.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `old_block` - Source block with legacy_edge_args metadata
|
||||
/// * `old_block` - Source block with terminator edge-args (legacy hidden inside API)
|
||||
/// * `boundary` - JoinInlineBoundary with exit_bindings and layout info
|
||||
/// * `remapper` - JoinIR→HOST value remapper
|
||||
/// * `new_block_id` - Target block ID in HOST MIR
|
||||
@ -53,15 +53,26 @@ pub(in crate::mir::builder::control_flow::joinir::merge) struct ExitCollectionRe
|
||||
///
|
||||
/// * `Ok(ExitCollectionResult)` - Collection result with edge_args if found
|
||||
/// * `Err(String)` - Error if strict mode fails
|
||||
pub(in crate::mir::builder::control_flow::joinir::merge) fn collect_exit_values_from_legacy_edge_args(
|
||||
pub(in crate::mir::builder::control_flow::joinir::merge) fn collect_exit_values_from_edge_args(
|
||||
old_block: &crate::mir::BasicBlock,
|
||||
boundary: &JoinInlineBoundary,
|
||||
remapper: &crate::mir::builder::joinir_id_remapper::JoinIrIdRemapper,
|
||||
new_block_id: BasicBlockId,
|
||||
strict_exit: bool,
|
||||
) -> Result<ExitCollectionResult, String> {
|
||||
// Phase 246-EX: Check if this block has legacy jump_args metadata
|
||||
if let Some(edge_args) = old_block.legacy_edge_args_with_layout(boundary.jump_args_layout) {
|
||||
// Phase 246-EX: Read edge-args via BasicBlock API (legacy-only is hidden inside)
|
||||
if let Some(edge_args) = old_block.edge_args_from_terminator() {
|
||||
if edge_args.layout != boundary.jump_args_layout {
|
||||
let msg = format!(
|
||||
"[joinir/exit-line] edge-args layout mismatch: block={:?} edge={:?} boundary={:?}",
|
||||
old_block.id, edge_args.layout, boundary.jump_args_layout
|
||||
);
|
||||
if strict_exit {
|
||||
return Err(msg);
|
||||
} else {
|
||||
eprintln!("[DEBUG-177] {}", msg);
|
||||
}
|
||||
}
|
||||
// The jump_args are in JoinIR value space, remap them to HOST
|
||||
let remapped_args: Vec<ValueId> = edge_args
|
||||
.values
|
||||
@ -178,7 +189,7 @@ pub(in crate::mir::builder::control_flow::joinir::merge) fn handle_fallback_exit
|
||||
/// Collect exit values for k_exit tail call lowering
|
||||
///
|
||||
/// Phase 131: Handles NormalizeToExitJump decision from TailCallLoweringPolicyBox.
|
||||
/// Similar to collect_exit_values_from_legacy_edge_args but uses k_exit_edge_args.
|
||||
/// Similar to collect_exit_values_from_edge_args but uses k_exit_edge_args.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user