This commit is contained in:
Pranav Gaddamadugu 2023-10-11 12:07:59 -04:00 committed by Pranav Gaddamadugu
parent 93aca5c103
commit 3e59672c34
3 changed files with 12 additions and 7 deletions

View File

@ -24,6 +24,7 @@ use leo_ast::{
ExpressionReconstructor,
Identifier,
IterationStatement,
NodeID,
ProgramReconstructor,
Statement,
StatementReconstructor,
@ -48,9 +49,9 @@ impl<'a> AssignmentRenamer<'a> {
}
/// Load the internal rename table with a set of entries.
pub fn load(&mut self, entries: impl Iterator<Item = (Symbol, Symbol)>) {
for (key, value) in entries {
self.rename_table.update(key, value);
pub fn load(&mut self, entries: impl Iterator<Item = (Symbol, Symbol, NodeID)>) {
for (key, value, id) in entries {
self.rename_table.update(key, value, id);
}
}
@ -69,7 +70,7 @@ impl ExpressionReconstructor for AssignmentRenamer<'_> {
// If consuming the left-hand side of an assignment, a new unique name is introduced.
true => {
let new_name = self.assigner.unique_symbol(input.name, "$");
self.rename_table.update(input.name, new_name);
self.rename_table.update(input.name, new_name, input.id);
new_name
}
// Otherwise, we look up the previous name in the `RenameTable`.

View File

@ -63,8 +63,12 @@ impl ExpressionReconstructor for FunctionInliner<'_> {
.collect::<IndexMap<_, _>>();
// Initializer `self.assignment_renamer` with the function parameters.
self.assignment_renamer
.load(callee.input.iter().map(|input| (input.identifier().name, input.identifier().name)));
self.assignment_renamer.load(
callee
.input
.iter()
.map(|input| (input.identifier().name, input.identifier().name, input.identifier().id)),
);
// Duplicate the body of the callee and create a unique assignment statement for each assignment in the body.
// This is necessary to ensure the inlined variables do not conflict with variables in the caller.

View File

@ -27,7 +27,7 @@ use std::cell::RefCell;
pub struct TypeChecker<'a> {
/// The symbol table for the program.
pub(crate) symbol_table: RefCell<SymbolTable>,
/// A mapping from nod IDs to their respective type.
/// A mapping from node IDs to their types.
pub(crate) type_table: TypeTable,
/// A dependency graph of the structs in program.
pub(crate) struct_graph: StructGraph,