1
1
//! Removes assignments to ZST places.
2
2
3
3
use crate :: transform:: MirPass ;
4
- use rustc_data_structures:: fx:: FxHashMap ;
5
4
use rustc_middle:: mir:: { Body , StatementKind } ;
6
5
use rustc_middle:: ty:: TyCtxt ;
7
6
@@ -10,35 +9,23 @@ pub struct RemoveZsts;
10
9
impl < ' tcx > MirPass < ' tcx > for RemoveZsts {
11
10
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
12
11
let param_env = tcx. param_env ( body. source . def_id ( ) ) ;
13
-
14
12
let ( basic_blocks, local_decls) = body. basic_blocks_and_local_decls_mut ( ) ;
15
-
16
- let mut is_zst_cache = FxHashMap :: default ( ) ;
17
-
18
13
for block in basic_blocks. iter_mut ( ) {
19
14
for statement in block. statements . iter_mut ( ) {
20
15
match statement. kind {
21
16
StatementKind :: Assign ( box ( place, _) ) => {
22
17
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 ( ) ;
28
27
}
29
28
}
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
- }
42
29
}
43
30
}
44
31
_ => { }
0 commit comments