diff --git a/src/native/cfg/structured_emit/construct_tree.rs b/src/native/cfg/structured_emit/construct_tree.rs index cc000ed6f..13e92ee4b 100644 --- a/src/native/cfg/structured_emit/construct_tree.rs +++ b/src/native/cfg/structured_emit/construct_tree.rs @@ -461,19 +461,10 @@ pub(in crate::native) fn materialize_construct_routes( #[cfg(test)] mod tests { + use super::super::test_support::bb; use super::*; use crate::native::ir::{LlType, LlValue, TypedValue}; use crate::native::tir; - use std::collections::HashMap; - - fn bb(name: &str, lines: &[&str]) -> BodyBlock { - let lines: Vec = lines.iter().map(|line| line.to_string()).collect(); - BodyBlock { - name: name.to_string(), - role: BlockRole::Normal, - typed: tir::lower_block_carrier(name, &lines, &HashMap::new()).map(Into::into), - } - } fn deep_single_owner_nodes() -> Vec { vec![ diff --git a/src/native/cfg/structured_emit/mod.rs b/src/native/cfg/structured_emit/mod.rs index ac86da467..5f2fc0660 100644 --- a/src/native/cfg/structured_emit/mod.rs +++ b/src/native/cfg/structured_emit/mod.rs @@ -71,33 +71,14 @@ pub(in crate::native) use straddle_region::*; #[cfg(test)] mod construct_tree_fixtures; +#[cfg(test)] +mod test_support; #[cfg(test)] mod tests { + use super::test_support::{bb, bb_role}; use super::*; - fn bb(name: &str, lines: &[&str]) -> BodyBlock { - // Populate the typed carrier exactly as production does at split time (the sole substrate). - let lines: Vec = lines.iter().map(|s| s.to_string()).collect(); - let typed = crate::native::tir::lower_block_carrier( - name, - &lines, - &std::collections::HashMap::new(), - ); - BodyBlock { - name: name.to_string(), - role: BlockRole::Normal, - typed: typed.map(Into::into), - } - } - - fn bb_role(name: &str, role: BlockRole, lines: &[&str]) -> BodyBlock { - BodyBlock { - role, - ..bb(name, lines) - } - } - /// A phi incoming VALUE rendered to a comparable token for the carrier-substrate test assertions /// (the cases these tests use: locals, integer constants, `true`/`false`, `undef`). fn val_str(v: &crate::native::ir::LlValue) -> String { diff --git a/src/native/cfg/structured_emit/own_arm.rs b/src/native/cfg/structured_emit/own_arm.rs index 4d378e350..5b54aa72d 100644 --- a/src/native/cfg/structured_emit/own_arm.rs +++ b/src/native/cfg/structured_emit/own_arm.rs @@ -683,20 +683,9 @@ pub(in crate::native) fn renest_cond_phi_shared_own_arm( #[cfg(test)] mod tests { + use super::super::test_support::bb; use super::*; - fn bb(name: &str, lines: &[&str]) -> BodyBlock { - let lines = lines - .iter() - .map(|line| line.to_string()) - .collect::>(); - BodyBlock { - name: name.to_string(), - role: BlockRole::Normal, - typed: tir::lower_block_carrier(name, &lines, &HashMap::new()).map(Into::into), - } - } - #[test] fn r2_own_arm_derivation_is_reject_only() { let admitted = vec![ diff --git a/src/native/cfg/structured_emit/reject.rs b/src/native/cfg/structured_emit/reject.rs index 0af17cf79..b53ac55ee 100644 --- a/src/native/cfg/structured_emit/reject.rs +++ b/src/native/cfg/structured_emit/reject.rs @@ -1330,21 +1330,9 @@ pub(in crate::native) fn reject_reason_inner(blocks: &[BodyBlock]) -> Option BodyBlock { - let lines = lines - .iter() - .map(|line| line.to_string()) - .collect::>(); - BodyBlock { - name: name.to_string(), - role, - typed: crate::native::tir::lower_block_carrier(name, &lines, &HashMap::new()) - .map(Into::into), - } - } - #[test] fn plan_self_check_rejects_merge_claimed_by_two_headers() { let blocks = vec![ diff --git a/src/native/cfg/structured_emit/straddle.rs b/src/native/cfg/structured_emit/straddle.rs index 9be550068..7cc441eb0 100644 --- a/src/native/cfg/structured_emit/straddle.rs +++ b/src/native/cfg/structured_emit/straddle.rs @@ -1741,21 +1741,9 @@ fn typed_instruction_count(blocks: &[BodyBlock]) -> usize { #[cfg(test)] mod tests { + use super::super::test_support::bb; use super::*; - fn bb(name: &str, lines: &[&str]) -> BodyBlock { - let lines = lines - .iter() - .map(|line| line.to_string()) - .collect::>(); - BodyBlock { - name: name.to_string(), - role: BlockRole::Normal, - typed: crate::native::tir::lower_block_carrier(name, &lines, &HashMap::new()) - .map(Into::into), - } - } - #[test] fn straddle_closure_counts_owner_arm_and_merge_tail() { let blocks = vec![ diff --git a/src/native/cfg/structured_emit/straddle_region.rs b/src/native/cfg/structured_emit/straddle_region.rs index 468fd05f5..ea84bf989 100644 --- a/src/native/cfg/structured_emit/straddle_region.rs +++ b/src/native/cfg/structured_emit/straddle_region.rs @@ -1472,20 +1472,9 @@ pub(in crate::native) fn renest_loop_exit_sibling( #[cfg(test)] mod tests { + use super::super::test_support::bb; use super::*; - fn bb(name: &str, lines: &[&str]) -> BodyBlock { - let lines = lines - .iter() - .map(|line| line.to_string()) - .collect::>(); - BodyBlock { - name: name.to_string(), - role: BlockRole::Normal, - typed: tir::lower_block_carrier(name, &lines, &HashMap::new()).map(Into::into), - } - } - #[test] fn r2_straddle_derivation_is_reject_only() { let admitted = vec![ diff --git a/src/native/cfg/structured_emit/test_support.rs b/src/native/cfg/structured_emit/test_support.rs new file mode 100644 index 000000000..20ffd8f07 --- /dev/null +++ b/src/native/cfg/structured_emit/test_support.rs @@ -0,0 +1,30 @@ +//! Shared block fixtures for the structurizer's unit tests. +//! +//! Every `#[cfg(test)] mod` under `structured_emit` builds its CFGs from the same two constructors; +//! they lived as six byte-equivalent private copies before this module. Keeping one copy means a new +//! test module costs a `use super::test_support::*;` line instead of another fixture builder, and a +//! change to how production populates a block carrier is made in one place rather than found in six. + +use super::{BlockRole, BodyBlock}; + +/// A block whose typed carrier is lowered from `lines` exactly as production does at split time +/// (`lower_block_carrier` is the one place block instructions are lexed), with the default +/// [`BlockRole::Normal`] every AIR-sourced block carries. +pub(in crate::native) fn bb(name: &str, lines: &[&str]) -> BodyBlock { + bb_role(name, BlockRole::Normal, lines) +} + +/// [`bb`] with an explicit structural role, for the tests that exercise role-keyed behavior. +pub(in crate::native) fn bb_role(name: &str, role: BlockRole, lines: &[&str]) -> BodyBlock { + let lines: Vec = lines.iter().map(|line| line.to_string()).collect(); + BodyBlock { + name: name.to_string(), + role, + typed: crate::native::tir::lower_block_carrier( + name, + &lines, + &std::collections::HashMap::new(), + ) + .map(Into::into), + } +}