leo_passes/common_subexpression_elimination/
ast.rs1use super::CommonSubexpressionEliminatingVisitor;
18
19use leo_ast::*;
20
21impl AstReconstructor for CommonSubexpressionEliminatingVisitor<'_> {
22 type AdditionalInput = ();
23 type AdditionalOutput = ();
24
25 fn reconstruct_expression(&mut self, input: Expression, _additional: &()) -> (Expression, Self::AdditionalOutput) {
26 (self.try_expr(input, None).expect("CSE Error").0, Default::default())
29 }
30
31 fn reconstruct_block(&mut self, mut block: Block) -> (Block, Self::AdditionalOutput) {
32 self.in_scope(|slf| {
33 block.statements = block.statements.into_iter().map(|s| slf.reconstruct_statement(s).0).collect();
34 (block, Default::default())
35 })
36 }
37
38 fn reconstruct_definition(&mut self, mut input: DefinitionStatement) -> (Statement, Self::AdditionalOutput) {
39 match input.place {
40 DefinitionPlace::Single(place) => {
41 let (value, definition_not_needed) = self.try_expr(input.value, Some(place.name)).expect("CSE Error");
42
43 if definition_not_needed {
44 (Statement::dummy(), Default::default())
47 } else {
48 input.value = value;
49 (input.into(), Default::default())
50 }
51 }
52 DefinitionPlace::Multiple(_) => {
53 let (value, _) = self.try_expr(input.value, None).expect("CSE Error");
54 input.value = value;
55 (input.into(), Default::default())
56 }
57 }
58 }
59
60 fn reconstruct_iteration(&mut self, _: IterationStatement) -> (Statement, Self::AdditionalOutput) {
61 panic!("`IterationStatement`s should not be in the AST at this phase of compilation.");
62 }
63}