Clippy and cleanup

This commit is contained in:
d0cd 2023-02-10 16:50:59 -08:00
parent bf49a0cc48
commit 1dd5887518
7 changed files with 21 additions and 28 deletions

View File

@ -183,9 +183,8 @@ impl<'a> Compiler<'a> {
pub fn static_single_assignment_pass(
&mut self,
symbol_table: &SymbolTable,
assigner: Assigner,
) -> Result<Assigner> {
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<Assigner> {
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))
}

View File

@ -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<String, L
let st = parsed.loop_unrolling_pass(st)?;
let assigner = Assigner::default();
let assigner = parsed.static_single_assignment_pass(&st, assigner)?;
let assigner = parsed.static_single_assignment_pass(&st)?;
let assigner = parsed.flattening_pass(&st, assigner)?;
let _ = parsed.function_inlining_pass(&st, &call_graph, assigner)?;
let _ = parsed.function_inlining_pass(&call_graph, assigner)?;
// Compile Leo program to bytecode.
let bytecode = CodeGenerator::do_pass((&parsed.ast, &st, &struct_graph, &call_graph))?;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
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),

View File

@ -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))

View File

@ -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))

View File

@ -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(),
}
}

View File

@ -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()
})
}