-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
StorageDead
and StorageLive
statements using MIR locals of…
… type `()`
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! The `RemoveUnitStorage` pass removes `StorageLive` and `StorageDead` statements | ||
//! which operates on locals of type `()`. | ||
|
||
use crate::transform::{MirPass, MirSource}; | ||
use rustc::mir::*; | ||
use rustc::ty::TyCtxt; | ||
use smallvec::SmallVec; | ||
|
||
pub struct RemoveUnitStorage; | ||
|
||
impl<'tcx> MirPass<'tcx> for RemoveUnitStorage { | ||
fn run_pass(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) { | ||
let unit_locals: SmallVec<[_; 32]> = | ||
body.local_decls.iter().map(|local| local.ty == tcx.types.unit).collect(); | ||
|
||
for block in body.basic_blocks_mut() { | ||
for stmt in &mut block.statements { | ||
match &stmt.kind { | ||
StatementKind::StorageLive(l) | StatementKind::StorageDead(l) => { | ||
if unit_locals[l.as_usize()] { | ||
stmt.make_nop(); | ||
} | ||
} | ||
_ => (), | ||
} | ||
} | ||
} | ||
} | ||
} |