Create common module; move pass data structures (#2173)

Co-authored-by: collin <16715212+collinc97@users.noreply.github.com>
This commit is contained in:
d0cd 2022-11-23 12:05:05 -08:00 committed by GitHub
parent ae18c6198c
commit 8986be33e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 50 additions and 34 deletions

View File

@ -159,7 +159,7 @@ impl<'a> Compiler<'a> {
/// Runs the symbol table pass.
pub fn symbol_table_pass(&self) -> Result<SymbolTable> {
CreateSymbolTable::do_pass((&self.ast, self.handler))
SymbolTableCreator::do_pass((&self.ast, self.handler))
}
/// Runs the type checker pass.

View File

@ -0,0 +1,24 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 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/>.
pub mod assigner;
pub use assigner::*;
pub mod rename_table;
pub use rename_table::*;
pub mod symbol_table;
pub use symbol_table::*;

View File

@ -20,7 +20,7 @@ use indexmap::IndexMap;
/// `RenameTable` tracks the names assigned by static single assignment in a single scope.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub(crate) struct RenameTable {
pub struct RenameTable {
/// The `RenameTable` of the parent scope.
pub(crate) parent: Option<Box<RenameTable>>,
/// The mapping from names in the original AST to new names in the renamed AST.

View File

@ -14,6 +14,12 @@
// 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/>.
pub mod function_symbol;
pub use function_symbol::*;
pub mod variable_symbol;
pub use variable_symbol::*;
use std::cell::RefCell;
use leo_ast::{Function, Struct};
@ -22,8 +28,6 @@ use leo_span::{Span, Symbol};
use indexmap::IndexMap;
use crate::{FunctionSymbol, VariableSymbol};
#[derive(Clone, Debug, Default)]
pub struct SymbolTable {
/// The parent scope if it exists.

View File

@ -20,6 +20,9 @@
pub mod code_generation;
pub use code_generation::*;
pub mod common;
pub use common::*;
pub mod flattening;
pub use flattening::*;
@ -32,8 +35,8 @@ pub use self::pass::*;
pub mod static_single_assignment;
pub use static_single_assignment::*;
pub mod symbol_table;
pub use symbol_table::*;
pub mod symbol_table_creator;
pub use symbol_table_creator::*;
pub mod type_checking;
pub use type_checking::*;

View File

@ -50,22 +50,16 @@
//! ```
//! Note that the redundant assignments have no effect on the bytecode generated by the compiler.
pub mod assigner;
pub use assigner::*;
mod rename_expression;
mod rename_program;
mod rename_statement;
mod rename_table;
pub(crate) use rename_table::*;
pub mod static_single_assigner;
pub use static_single_assigner::*;
use crate::{Pass, SymbolTable};
use crate::{Assigner, Pass, SymbolTable};
use leo_ast::{Ast, ProgramConsumer};
use leo_errors::Result;

View File

@ -22,14 +22,14 @@ use crate::{SymbolTable, VariableSymbol, VariableType};
/// A compiler pass during which the `SymbolTable` is created.
/// Note that this pass only creates the initial entries for functions, structs, and records.
/// The table is populated further during the type checking pass.
pub struct CreateSymbolTable<'a> {
pub struct SymbolTableCreator<'a> {
/// The `SymbolTable` constructed by this compiler pass.
pub(crate) symbol_table: SymbolTable,
/// The error handler.
handler: &'a Handler,
}
impl<'a> CreateSymbolTable<'a> {
impl<'a> SymbolTableCreator<'a> {
pub fn new(handler: &'a Handler) -> Self {
Self {
symbol_table: Default::default(),
@ -38,14 +38,14 @@ impl<'a> CreateSymbolTable<'a> {
}
}
impl<'a> ExpressionVisitor<'a> for CreateSymbolTable<'a> {
impl<'a> ExpressionVisitor<'a> for SymbolTableCreator<'a> {
type AdditionalInput = ();
type Output = ();
}
impl<'a> StatementVisitor<'a> for CreateSymbolTable<'a> {}
impl<'a> StatementVisitor<'a> for SymbolTableCreator<'a> {}
impl<'a> ProgramVisitor<'a> for CreateSymbolTable<'a> {
impl<'a> ProgramVisitor<'a> for SymbolTableCreator<'a> {
fn visit_import(&mut self, input: &'a Program) {
self.visit_program(input)
}

View File

@ -14,30 +14,21 @@
// 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/>.
pub mod create;
pub use create::*;
pub mod creator;
pub use creator::*;
pub mod function_symbol;
pub use function_symbol::*;
pub mod table;
pub use table::*;
pub mod variable_symbol;
pub use variable_symbol::*;
use crate::Pass;
use crate::{Pass, SymbolTable};
use leo_ast::{Ast, ProgramVisitor};
use leo_errors::{emitter::Handler, Result};
impl<'a> Pass for CreateSymbolTable<'a> {
impl<'a> Pass for SymbolTableCreator<'a> {
type Input = (&'a Ast, &'a Handler);
type Output = Result<SymbolTable>;
/// Runs the compiler pass.
fn do_pass((ast, handler): Self::Input) -> Self::Output {
let mut visitor = CreateSymbolTable::new(handler);
let mut visitor = SymbolTableCreator::new(handler);
visitor.visit_program(ast.as_repr());
handler.last_err().map_err(|e| *e)?;

View File

@ -442,7 +442,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
// Note that the parser guarantees that `input.function` is always an identifier.
Expression::Identifier(ident) => {
// Note: The function symbol lookup is performed outside of the `if let Some(func) ...` block to avoid a RefCell lifetime bug in Rust.
// Do not move it into the `if let Some(func) ...` block or it will keep `self.symbol_table` alive for the entire block and will be very memory inefficient!
// Do not move it into the `if let Some(func) ...` block or it will keep `self.symbol_table_creator` alive for the entire block and will be very memory inefficient!
let func = self.symbol_table.borrow().lookup_fn_symbol(ident.name).cloned();
if let Some(func) = func {

View File

@ -13,7 +13,7 @@ You will know that the download has failed if you see the following error messag
ATTENTION - "genesis.prover.1c9bbe9" does not exist, downloading this file remotely and storing it locally. Please ensure "genesis.prover.1c9bbe9" is stored in "/Users/xxx/.aleo/resources/genesis.prover.1c9bbe9".
snarkvm_parameters::testnet3 - Downloading parameters...
snarkvm_parameters::testnet3 - thread `main` panicked at 'Failed to load proving key: Crate("curl::error", "Error { description: \"Transferred a partial file\", code: 18, extra: Some(\"transfer closed with 92197356 bytes remaining to read\") }")', /Users/xxx/.cargo/git/checkouts/snarkvm-f1160780ffe17de8/ea14990/parameters/src/testnet3/mod.rs:95:9
snarkvm_parameters::testnet3 - thread `main` panicked at 'Failed to load proving key: Crate("curl::error", "Error { description: \"Transferred a partial file\", code: 18, extra: Some(\"transfer closed with 92197356 bytes remaining to read\") }")', /Users/xxx/.cargo/git/checkouts/snarkvm-f1160780ffe17de8/ea14990/parameters/src/testnet3/symbol_table_creator:95:9
stack backtrace:
0: backtrace::capture::Backtrace::new
1: leo::set_panic_hook::{{closure}}