Minor refactors and cleaning

This commit is contained in:
d0cd 2023-02-10 09:07:14 -08:00
parent 53cbaa5f96
commit ccae285408
6 changed files with 26 additions and 8 deletions

View File

@ -180,8 +180,12 @@ impl<'a> Compiler<'a> {
}
/// Runs the static single assignment pass.
pub fn static_single_assignment_pass(&mut self, symbol_table: &SymbolTable) -> Result<Assigner> {
let (ast, assigner) = StaticSingleAssigner::do_pass((std::mem::take(&mut self.ast), symbol_table))?;
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))?;
self.ast = ast;
if self.output_options.ssa_ast {
@ -210,8 +214,11 @@ 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)?;
let assigner = self.static_single_assignment_pass(&st, assigner)?;
self.flattening_pass(&st, assigner)?;

View File

@ -211,4 +211,11 @@ mod test {
let expected = Vec::from([1u32, 2, 4, 1]);
assert_eq!(cycle, expected);
}
#[test]
fn test_unconnected_graph() {
let mut graph = DiGraph::<u32>::new(IndexSet::from([1, 2, 3, 4, 5]));
check_post_order(&graph, &[1, 2, 3, 4, 5]);
}
}

View File

@ -23,5 +23,8 @@ pub use graph::*;
pub mod rename_table;
pub use rename_table::*;
pub mod replacer;
pub use replacer::*;
pub mod symbol_table;
pub use symbol_table::*;

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);
type Input = (Ast, &'a SymbolTable, Assigner);
type Output = Result<(Ast, Assigner)>;
fn do_pass((ast, symbol_table): Self::Input) -> Self::Output {
let mut consumer = StaticSingleAssigner::new(symbol_table);
fn do_pass((ast, symbol_table, assigner): Self::Input) -> Self::Output {
let mut consumer = StaticSingleAssigner::new(symbol_table, assigner);
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) -> Self {
pub(crate) fn new(symbol_table: &'a SymbolTable, assigner: Assigner) -> Self {
Self {
symbol_table,
rename_table: RenameTable::new(None),
is_lhs: false,
assigner: Assigner::default(),
assigner,
}
}

View File

@ -100,6 +100,7 @@ impl<'a> TypeChecker<'a> {
let function_names = symbol_table.functions.keys().cloned().collect();
// Note that the `struct_graph` and `call_graph` are initialized with their full node sets.
Self {
symbol_table: RefCell::new(symbol_table),
struct_graph: StructGraph::new(struct_names),