Skip to content

Commit bf19ff6

Browse files
committed
eliminate promoted temp
1 parent 70a6ae2 commit bf19ff6

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

compiler/rustc_mir_transform/src/promote_consts_local_arrays.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -1060,9 +1060,6 @@ fn promote_candidates<'tcx>(
10601060
}
10611061

10621062
let mut promotions = IndexVec::new();
1063-
// FIXME: buggy things, there shouldn't be more than 42 promoted items by PromoteTemps.
1064-
// cannot check body.source.promoted,maybe stealed
1065-
// let already = 0;
10661063

10671064
let mut extra_statements = vec![];
10681065
// Visit candidates in reverse, in case they're nested.
@@ -1121,5 +1118,30 @@ fn promote_candidates<'tcx>(
11211118
body[loc.block].statements.insert(loc.statement_index, statement);
11221119
}
11231120

1121+
// Eliminate assignments to, and drops of promoted temps.
1122+
let is_promoted_out = |index: Local| temps[index] == TempState::PromotedOut;
1123+
for block in body.basic_blocks_mut() {
1124+
block.statements.retain(|statement| match &statement.kind {
1125+
StatementKind::Assign(box (
1126+
place,
1127+
Rvalue::Use(Operand::Constant(box ConstOperand {
1128+
const_: Const::Val(_, ty), ..
1129+
})),
1130+
)) => {
1131+
if ty.is_unit()
1132+
&& let Some(index) = place.as_local()
1133+
{
1134+
!is_promoted_out(index)
1135+
} else {
1136+
true
1137+
}
1138+
}
1139+
StatementKind::StorageLive(index) | StatementKind::StorageDead(index) => {
1140+
!is_promoted_out(*index)
1141+
}
1142+
_ => true,
1143+
});
1144+
}
1145+
11241146
promotions
11251147
}

0 commit comments

Comments
 (0)