diff --git a/compiler/compiler/src/compiler.rs b/compiler/compiler/src/compiler.rs index 0bfd63b28e..344037eb34 100644 --- a/compiler/compiler/src/compiler.rs +++ b/compiler/compiler/src/compiler.rs @@ -183,9 +183,8 @@ impl<'a> Compiler<'a> { pub fn static_single_assignment_pass( &mut self, symbol_table: &SymbolTable, - assigner: Assigner, ) -> Result { - let (ast, assigner) = StaticSingleAssigner::do_pass((std::mem::take(&mut self.ast), symbol_table, assigner))?; + let (ast, assigner) = StaticSingleAssigner::do_pass((std::mem::take(&mut self.ast), symbol_table))?; self.ast = ast; if self.output_options.ssa_ast { @@ -210,12 +209,11 @@ impl<'a> Compiler<'a> { /// Runs the function inlining pass. pub fn function_inlining_pass( &mut self, - symbol_table: &SymbolTable, call_graph: &CallGraph, assigner: Assigner, ) -> Result { let (ast, assigner) = - FunctionInliner::do_pass((std::mem::take(&mut self.ast), symbol_table, call_graph, assigner))?; + FunctionInliner::do_pass((std::mem::take(&mut self.ast), call_graph, assigner))?; self.ast = ast; if self.output_options.inlined_ast { @@ -233,15 +231,12 @@ impl<'a> Compiler<'a> { // TODO: Make this pass optional. let st = self.loop_unrolling_pass(st)?; - // Initialize the assigner. This is responsible for creating unique variable names in the following passes. - let assigner = Assigner::default(); - // TODO: Make this pass optional. - let assigner = self.static_single_assignment_pass(&st, assigner)?; + let assigner = self.static_single_assignment_pass(&st)?; let assigner = self.flattening_pass(&st, assigner)?; - let _ = self.function_inlining_pass(&st, &call_graph, assigner)?; + let _ = self.function_inlining_pass(&call_graph, assigner)?; Ok((st, struct_graph, call_graph)) } diff --git a/compiler/compiler/tests/utilities/mod.rs b/compiler/compiler/tests/utilities/mod.rs index b4c0bd2c3d..754aafce7a 100644 --- a/compiler/compiler/tests/utilities/mod.rs +++ b/compiler/compiler/tests/utilities/mod.rs @@ -19,7 +19,7 @@ use leo_errors::{ emitter::{Buffer, Emitter, Handler}, LeoError, LeoWarning, }; -use leo_passes::{Assigner, CodeGenerator, Pass}; +use leo_passes::{CodeGenerator, Pass}; use leo_span::source_map::FileName; use leo_test_framework::Test; @@ -190,13 +190,11 @@ pub fn compile_and_process<'a>(parsed: &'a mut Compiler<'a>) -> Result. -use crate::{Assigner, AssignmentRenamer, CallGraph, SymbolTable}; +use crate::{Assigner, AssignmentRenamer, CallGraph}; use leo_ast::Function; use leo_span::Symbol; @@ -32,7 +32,7 @@ pub struct FunctionInliner<'a> { impl<'a> FunctionInliner<'a> { /// Initializes a new `FunctionInliner`. - pub fn new(_symbol_table: &'a SymbolTable, call_graph: &'a CallGraph, assigner: Assigner) -> Self { + pub fn new(call_graph: &'a CallGraph, assigner: Assigner) -> Self { Self { call_graph, assignment_renamer: AssignmentRenamer::new(assigner), diff --git a/compiler/passes/src/function_inlining/mod.rs b/compiler/passes/src/function_inlining/mod.rs index d7ce5fd412..d0ad6c1ac9 100644 --- a/compiler/passes/src/function_inlining/mod.rs +++ b/compiler/passes/src/function_inlining/mod.rs @@ -65,17 +65,17 @@ mod inline_program; pub mod function_inliner; pub use function_inliner::*; -use crate::{Assigner, CallGraph, Pass, SymbolTable}; +use crate::{Assigner, CallGraph, Pass}; use leo_ast::{Ast, ProgramReconstructor}; use leo_errors::Result; impl<'a> Pass for FunctionInliner<'a> { - type Input = (Ast, &'a SymbolTable, &'a CallGraph, Assigner); + type Input = (Ast, &'a CallGraph, Assigner); type Output = Result<(Ast, Assigner)>; - fn do_pass((ast, st, call_graph, assigner): Self::Input) -> Self::Output { - let mut reconstructor = FunctionInliner::new(st, call_graph, assigner); + fn do_pass((ast, call_graph, assigner): Self::Input) -> Self::Output { + let mut reconstructor = FunctionInliner::new(call_graph, assigner); let program = reconstructor.reconstruct_program(ast.into_repr()); Ok((Ast::new(program), reconstructor.assignment_renamer.assigner)) diff --git a/compiler/passes/src/static_single_assignment/mod.rs b/compiler/passes/src/static_single_assignment/mod.rs index 89d88debf6..32c718bc1a 100644 --- a/compiler/passes/src/static_single_assignment/mod.rs +++ b/compiler/passes/src/static_single_assignment/mod.rs @@ -65,11 +65,11 @@ use leo_ast::{Ast, ProgramConsumer}; use leo_errors::Result; impl<'a> Pass for StaticSingleAssigner<'a> { - type Input = (Ast, &'a SymbolTable, Assigner); + type Input = (Ast, &'a SymbolTable); type Output = Result<(Ast, Assigner)>; - fn do_pass((ast, symbol_table, assigner): Self::Input) -> Self::Output { - let mut consumer = StaticSingleAssigner::new(symbol_table, assigner); + fn do_pass((ast, symbol_table): Self::Input) -> Self::Output { + let mut consumer = StaticSingleAssigner::new(symbol_table); let program = consumer.consume_program(ast.into_repr()); Ok((Ast::new(program), consumer.assigner)) diff --git a/compiler/passes/src/static_single_assignment/static_single_assigner.rs b/compiler/passes/src/static_single_assignment/static_single_assigner.rs index 3ceca43988..7464aca202 100644 --- a/compiler/passes/src/static_single_assignment/static_single_assigner.rs +++ b/compiler/passes/src/static_single_assignment/static_single_assigner.rs @@ -29,12 +29,12 @@ pub struct StaticSingleAssigner<'a> { impl<'a> StaticSingleAssigner<'a> { /// Initializes a new `StaticSingleAssigner` with an empty `RenameTable`. - pub(crate) fn new(symbol_table: &'a SymbolTable, assigner: Assigner) -> Self { + pub(crate) fn new(symbol_table: &'a SymbolTable) -> Self { Self { symbol_table, rename_table: RenameTable::new(None), is_lhs: false, - assigner, + assigner: Assigner::default(), } } diff --git a/tests/test-framework/benches/leo_compiler.rs b/tests/test-framework/benches/leo_compiler.rs index 75ba8f9e3f..05353a5294 100644 --- a/tests/test-framework/benches/leo_compiler.rs +++ b/tests/test-framework/benches/leo_compiler.rs @@ -234,11 +234,11 @@ impl Sample { let assigner = compiler .static_single_assignment_pass(&symbol_table) .expect("failed to run ssa pass"); - let (symbol_table, assigner) = compiler + let assigner = compiler .flattening_pass(&symbol_table, assigner) .expect("failed to run flattener pass"); let start = Instant::now(); - let out = compiler.function_inlining_pass(&symbol_table, &call_graph, assigner); + let out = compiler.function_inlining_pass(&call_graph, assigner); let time = start.elapsed(); out.expect("failed to run inliner pass"); time @@ -265,7 +265,7 @@ impl Sample { let assigner = compiler .flattening_pass(&symbol_table, assigner) .expect("failed to run flattening pass"); - compiler.function_inlining_pass(&symbol_table, &call_graph, assigner); + compiler.function_inlining_pass(&call_graph, assigner).expect("failed to run function inlining pass"); start.elapsed() }) }