Skip to content

Commit

Permalink
Auto merge of #117801 - tmiasko:remove-zsts-fuel, r=cjgillot
Browse files Browse the repository at this point in the history
Remove incorrect transformation from RemoveZsts

Partial removal of storage statements for a local is incorrect, so a decision to optimize cannot be make independently for each statement.

Avoid the issue by performing the transformation completely or not at all.
  • Loading branch information
bors committed Nov 14, 2023
2 parents d5375d0 + d7d2e76 commit 5777f2c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions compiler/rustc_mir_transform/src/remove_zsts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts {
if tcx.type_of(body.source.def_id()).instantiate_identity().is_coroutine() {
return;
}

if !tcx.consider_optimizing(|| format!("RemoveZsts - {:?}", body.source.def_id())) {
return;
}

let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
let local_decls = &body.local_decls;
let mut replacer = Replacer { tcx, param_env, local_decls };
Expand Down Expand Up @@ -125,12 +130,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
if let Some(place_for_ty) = place_for_ty
&& let ty = place_for_ty.ty(self.local_decls, self.tcx).ty
&& self.known_to_be_zst(ty)
&& self.tcx.consider_optimizing(|| {
format!(
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
place_for_ty, statement.source_info
)
})
{
statement.make_nop();
} else {
Expand Down

0 comments on commit 5777f2c

Please sign in to comment.