From 1205e82578bec0ff5fd84dc1a90afa4f8e4e548d Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Wed, 17 Mar 2021 20:24:29 -0400 Subject: [PATCH] remove unnecessary and ineffective caching --- .../rustc_mir/src/transform/remove_zsts.rs | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_mir/src/transform/remove_zsts.rs b/compiler/rustc_mir/src/transform/remove_zsts.rs index 838ffe9b596..5b1dcba6704 100644 --- a/compiler/rustc_mir/src/transform/remove_zsts.rs +++ b/compiler/rustc_mir/src/transform/remove_zsts.rs @@ -1,7 +1,6 @@ //! Removes assignments to ZST places. use crate::transform::MirPass; -use rustc_data_structures::fx::FxHashMap; use rustc_middle::mir::{Body, StatementKind}; use rustc_middle::ty::TyCtxt; @@ -10,35 +9,23 @@ pub struct RemoveZsts; impl<'tcx> MirPass<'tcx> for RemoveZsts { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let param_env = tcx.param_env(body.source.def_id()); - let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); - - let mut is_zst_cache = FxHashMap::default(); - for block in basic_blocks.iter_mut() { for statement in block.statements.iter_mut() { match statement.kind { StatementKind::Assign(box (place, _)) => { let place_ty = place.ty(local_decls, tcx).ty; - - let is_inhabited_zst = *is_zst_cache.entry(place_ty).or_insert_with(|| { - if let Ok(layout) = tcx.layout_of(param_env.and(place_ty)) { - if layout.is_zst() && !layout.abi.is_uninhabited() { - return true; + if let Ok(layout) = tcx.layout_of(param_env.and(place_ty)) { + if layout.is_zst() && !layout.abi.is_uninhabited() { + if tcx.consider_optimizing(|| { + format!( + "RemoveZsts - Place: {:?} SourceInfo: {:?}", + place, statement.source_info + ) + }) { + statement.make_nop(); } } - false - }); - - if is_inhabited_zst { - if tcx.consider_optimizing(|| { - format!( - "RemoveZsts - Place: {:?} SourceInfo: {:?}", - place, statement.source_info - ) - }) { - statement.make_nop(); - } } } _ => {}