phase29aa(p7): deterministic ReleaseStrong values ordering

This commit is contained in:
2025-12-28 05:59:22 +09:00
parent ec1a84c465
commit d3cf73f2ae
4 changed files with 66 additions and 13 deletions

View File

@ -429,13 +429,8 @@ fn plan_rc_insertion_for_block(
}
if matches!(terminator, Some(MirInstruction::Return { .. })) && !ptr_to_value.is_empty() {
let release_values: Vec<ValueId> = {
let mut set = HashSet::new();
for v in ptr_to_value.values() {
set.insert(*v);
}
set.into_iter().collect()
};
// P7: HashSet 削除、sort+dedup は apply 側のヘルパーで処理される
let release_values: Vec<ValueId> = ptr_to_value.values().copied().collect();
if !release_values.is_empty() {
plan.drops.push(DropSite {
at: DropPoint::BeforeTerminator,
@ -448,6 +443,14 @@ fn plan_rc_insertion_for_block(
(plan, ptr_to_value)
}
/// P7: ReleaseStrong の values を決定的順序ValueId 昇順)にする
#[cfg(feature = "rc-insertion-minimal")]
fn sorted_release_values(mut values: Vec<ValueId>) -> Vec<ValueId> {
values.sort_unstable();
values.dedup();
values
}
#[cfg(feature = "rc-insertion-minimal")]
fn apply_rc_plan(
insts: Vec<MirInstruction>,
@ -490,7 +493,7 @@ fn apply_rc_plan(
for drop_site in drops_before_instr[idx].drain(..) {
let _ = drop_site.reason;
new_insts.push(MirInstruction::ReleaseStrong {
values: drop_site.values,
values: sorted_release_values(drop_site.values),
});
new_spans.push(span.clone());
stats.release_inserted += 1;
@ -510,7 +513,7 @@ fn apply_rc_plan(
for drop_site in drops_before_terminator {
let _ = drop_site.reason;
new_insts.push(MirInstruction::ReleaseStrong {
values: drop_site.values,
values: sorted_release_values(drop_site.values),
});
new_spans.push(span.clone());
stats.release_inserted += 1;