Skip to content

Commit 1205e82

Browse files
remove unnecessary and ineffective caching
1 parent b6d5b72 commit 1205e82

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

compiler/rustc_mir/src/transform/remove_zsts.rs

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Removes assignments to ZST places.
22
33
use crate::transform::MirPass;
4-
use rustc_data_structures::fx::FxHashMap;
54
use rustc_middle::mir::{Body, StatementKind};
65
use rustc_middle::ty::TyCtxt;
76

@@ -10,35 +9,23 @@ pub struct RemoveZsts;
109
impl<'tcx> MirPass<'tcx> for RemoveZsts {
1110
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
1211
let param_env = tcx.param_env(body.source.def_id());
13-
1412
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
15-
16-
let mut is_zst_cache = FxHashMap::default();
17-
1813
for block in basic_blocks.iter_mut() {
1914
for statement in block.statements.iter_mut() {
2015
match statement.kind {
2116
StatementKind::Assign(box (place, _)) => {
2217
let place_ty = place.ty(local_decls, tcx).ty;
23-
24-
let is_inhabited_zst = *is_zst_cache.entry(place_ty).or_insert_with(|| {
25-
if let Ok(layout) = tcx.layout_of(param_env.and(place_ty)) {
26-
if layout.is_zst() && !layout.abi.is_uninhabited() {
27-
return true;
18+
if let Ok(layout) = tcx.layout_of(param_env.and(place_ty)) {
19+
if layout.is_zst() && !layout.abi.is_uninhabited() {
20+
if tcx.consider_optimizing(|| {
21+
format!(
22+
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
23+
place, statement.source_info
24+
)
25+
}) {
26+
statement.make_nop();
2827
}
2928
}
30-
false
31-
});
32-
33-
if is_inhabited_zst {
34-
if tcx.consider_optimizing(|| {
35-
format!(
36-
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
37-
place, statement.source_info
38-
)
39-
}) {
40-
statement.make_nop();
41-
}
4229
}
4330
}
4431
_ => {}

0 commit comments

Comments
 (0)