charon_lib/transform/
remove_nops.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Remove the useless no-ops.

use crate::llbc_ast::*;
use crate::transform::TransformCtx;

use super::ctx::LlbcPass;

pub struct Transform;
impl LlbcPass for Transform {
    fn transform_body(&self, _ctx: &mut TransformCtx, b: &mut ExprBody) {
        b.body.visit_blocks_bwd(|blk: &mut Block| {
            // Remove all the `Nop`s from this sequence.
            if blk.statements.iter().any(|st| st.content.is_nop()) {
                blk.statements.retain(|st| !st.content.is_nop())
            }
        });
    }
}