charon_lib/transform/
remove_nops.rs

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

use derive_visitor::{visitor_enter_fn_mut, DriveMut};

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
            .drive_mut(&mut visitor_enter_fn_mut(|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())
                }
            }));
    }
}