charon_lib/transform/simplify_output/
remove_nops.rs

1//! Remove the useless no-ops.
2use crate::ast::*;
3use crate::transform::TransformCtx;
4
5use crate::transform::ctx::TransformPass;
6
7pub struct Transform;
8impl TransformPass for Transform {
9    fn transform_ctx(&self, ctx: &mut TransformCtx) {
10        ctx.for_each_fun_decl(|_ctx, fun| {
11            match &mut fun.body {
12                Body::Unstructured(body) => {
13                    for blk in &mut body.body {
14                        if blk.statements.iter().any(|st| st.kind.is_nop()) {
15                            blk.statements.retain(|st| !st.kind.is_nop())
16                        }
17                    }
18                }
19                Body::Structured(body) => {
20                    body.body.visit_blocks_bwd(|blk: &mut llbc_ast::Block| {
21                        // Remove all the `Nop`s from this sequence.
22                        if blk.statements.iter().any(|st| st.kind.is_nop()) {
23                            blk.statements.retain(|st| !st.kind.is_nop())
24                        }
25                    });
26                }
27                _ => {}
28            }
29        });
30    }
31}