phase29aa(p7): deterministic ReleaseStrong values ordering
This commit is contained in:
@ -527,5 +527,52 @@ fn main() {
|
||||
"branch_no_cleanup",
|
||||
);
|
||||
|
||||
// Case 3.11: ReleaseStrong values are sorted (deterministic ordering)
|
||||
// P7: 複数 ptr に異なる順序で store し、ReturnCleanup の values が昇順になることを検証
|
||||
let ptr1 = ValueId::new(3111);
|
||||
let ptr2 = ValueId::new(3112);
|
||||
let v_high = ValueId::new(100); // 大きい index
|
||||
let v_low = ValueId::new(50); // 小さい index
|
||||
|
||||
let mut block = BasicBlock::new(BasicBlockId::new(0));
|
||||
block.instructions = vec![
|
||||
MirInstruction::Store { value: v_high, ptr: ptr1 }, // 先に v100 を store
|
||||
MirInstruction::Store { value: v_low, ptr: ptr2 }, // 後に v50 を store
|
||||
];
|
||||
block.instruction_spans = vec![Span::unknown(), Span::unknown()];
|
||||
block.terminator = Some(MirInstruction::Return { value: None });
|
||||
block.terminator_span = Some(Span::unknown());
|
||||
let entry = block.id;
|
||||
let module = build_module_with_block(block, "selfcheck_sorted_values", "selfcheck_mod3p11");
|
||||
|
||||
// 関数全体の ReleaseStrong が昇順であることを検証
|
||||
assert_release_inserted(module.clone(), "selfcheck_sorted_values", entry, 1, "sorted_values_count");
|
||||
assert_all_release_values_sorted(module, "selfcheck_sorted_values", "sorted_values_order");
|
||||
|
||||
println!("[PASS] rc_insertion_selfcheck");
|
||||
}
|
||||
|
||||
fn assert_all_release_values_sorted(
|
||||
mut module: MirModule,
|
||||
func_name: &str,
|
||||
label: &str,
|
||||
) {
|
||||
let _stats = insert_rc_instructions(&mut module);
|
||||
let func = module.get_function(func_name).expect("function exists");
|
||||
|
||||
for (bid, bb) in &func.blocks {
|
||||
for inst in &bb.instructions {
|
||||
if let MirInstruction::ReleaseStrong { values } = inst {
|
||||
for window in values.windows(2) {
|
||||
if window[0] > window[1] {
|
||||
eprintln!(
|
||||
"[FAIL] {}: block {:?} values not sorted: {:?} > {:?}",
|
||||
label, bid, window[0], window[1]
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user