From f1e393a9ab73ef936938430ff840270c9ebb225a Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 30 Oct 2020 12:39:02 -0700 Subject: [PATCH] rename dynamic-check -> type-inference 1 --- compiler/src/compiler.rs | 6 ++-- compiler/src/errors/compiler.rs | 4 +-- compiler/tests/syntax/mod.rs | 4 +-- dynamic-check/src/errors/mod.rs | 6 ++-- .../{dynamic_check.rs => type_inference.rs} | 10 +++---- dynamic-check/src/lib.rs | 4 +-- dynamic-check/src/objects/frame.rs | 2 +- .../{dynamic_check.rs => type_inference.rs} | 30 +++++++++---------- dynamic-check/tests/arrays/mod.rs | 8 ++--- dynamic-check/tests/circuits/mod.rs | 4 +-- dynamic-check/tests/functions/mod.rs | 4 +-- dynamic-check/tests/mod.rs | 20 ++++++------- dynamic-check/tests/tuples/mod.rs | 4 +-- dynamic-check/tests/variables/mod.rs | 10 +++---- 14 files changed, 58 insertions(+), 58 deletions(-) rename dynamic-check/src/errors/{dynamic_check.rs => type_inference.rs} (80%) rename dynamic-check/src/{dynamic_check.rs => type_inference.rs} (85%) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index bbd495c111..68352746af 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -25,7 +25,7 @@ use crate::{ }; use leo_ast::LeoAst; use leo_core_ast::{Input, LeoCoreAst, MainInput, Program}; -use leo_dynamic_check::DynamicCheck; +use leo_dynamic_check::TypeInference; use leo_imports::ImportParser; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; @@ -199,7 +199,7 @@ impl> Compiler { })?; // Run dynamic check on program. - DynamicCheck::new(&self.program, symbol_table).map_err(|mut e| { + TypeInference::new(&self.program, symbol_table).map_err(|mut e| { e.set_path(&self.main_file_path); e @@ -236,7 +236,7 @@ impl> Compiler { let symbol_table = SymbolTable::new(&self.program, &self.imported_programs, &self.program_input)?; // Run dynamic check on program. - DynamicCheck::new(&self.program, symbol_table)?; + TypeInference::new(&self.program, symbol_table)?; tracing::debug!("Program parsing complete\n{:#?}", self.program); diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index c82569dccb..d771721852 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -16,7 +16,7 @@ use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError}; use leo_ast::ParserError; -use leo_dynamic_check::DynamicCheckError; +use leo_dynamic_check::TypeInferenceError; use leo_imports::ImportParserError; use leo_input::InputParserError; use leo_state::LocalDataVerificationError; @@ -28,7 +28,7 @@ use std::path::{Path, PathBuf}; #[derive(Debug, Error)] pub enum CompilerError { #[error("{}", _0)] - DynamicCheckError(#[from] DynamicCheckError), + DynamicCheckError(#[from] TypeInferenceError), #[error("{}", _0)] ImportError(#[from] ImportError), diff --git a/compiler/tests/syntax/mod.rs b/compiler/tests/syntax/mod.rs index f597dd50a9..2d3e1826f5 100644 --- a/compiler/tests/syntax/mod.rs +++ b/compiler/tests/syntax/mod.rs @@ -17,7 +17,7 @@ use crate::{expect_compiler_error, parse_input, parse_program}; use leo_ast::ParserError; use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError}; -use leo_dynamic_check::errors::{DynamicCheckError, FrameError, TypeAssertionError}; +use leo_dynamic_check::errors::{FrameError, TypeAssertionError, TypeInferenceError}; use leo_input::InputParserError; pub mod identifiers; @@ -82,7 +82,7 @@ fn test_compare_mismatched_types() { // Expect a dynamic check error. match error { - CompilerError::DynamicCheckError(DynamicCheckError::FrameError(FrameError::TypeAssertionError( + CompilerError::DynamicCheckError(TypeInferenceError::FrameError(FrameError::TypeAssertionError( TypeAssertionError::Error(_), ))) => {} error => panic!("Expected dynamic check error, found {}", error), diff --git a/dynamic-check/src/errors/mod.rs b/dynamic-check/src/errors/mod.rs index 12128a8127..629a558e2f 100644 --- a/dynamic-check/src/errors/mod.rs +++ b/dynamic-check/src/errors/mod.rs @@ -14,9 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -pub mod dynamic_check; -pub use self::dynamic_check::*; - pub mod frame; pub use self::frame::*; @@ -26,5 +23,8 @@ pub use self::scope::*; pub mod type_assertion; pub use self::type_assertion::*; +pub mod type_inference; +pub use self::type_inference::*; + pub mod variable_table; pub use self::variable_table::*; diff --git a/dynamic-check/src/errors/dynamic_check.rs b/dynamic-check/src/errors/type_inference.rs similarity index 80% rename from dynamic-check/src/errors/dynamic_check.rs rename to dynamic-check/src/errors/type_inference.rs index a165a87a8d..83c7dde93e 100644 --- a/dynamic-check/src/errors/dynamic_check.rs +++ b/dynamic-check/src/errors/type_inference.rs @@ -19,9 +19,9 @@ use leo_core_ast::Error as FormattedError; use std::path::Path; -/// Errors encountered when running dynamic type inference checks. +/// Errors encountered when running type inference checks. #[derive(Debug, Error)] -pub enum DynamicCheckError { +pub enum TypeInferenceError { #[error("{}", _0)] Error(#[from] FormattedError), @@ -29,14 +29,14 @@ pub enum DynamicCheckError { FrameError(#[from] FrameError), } -impl DynamicCheckError { +impl TypeInferenceError { /// /// Set the filepath for the error stacktrace. /// pub fn set_path(&mut self, path: &Path) { match self { - DynamicCheckError::Error(error) => error.set_path(path), - DynamicCheckError::FrameError(error) => error.set_path(path), + TypeInferenceError::Error(error) => error.set_path(path), + TypeInferenceError::FrameError(error) => error.set_path(path), } } } diff --git a/dynamic-check/src/lib.rs b/dynamic-check/src/lib.rs index 3c1f97a363..cbe7bdd069 100644 --- a/dynamic-check/src/lib.rs +++ b/dynamic-check/src/lib.rs @@ -20,8 +20,8 @@ extern crate thiserror; pub mod assertions; pub use self::assertions::*; -pub mod dynamic_check; -pub use self::dynamic_check::*; +pub mod type_inference; +pub use self::type_inference::*; pub mod errors; pub use self::errors::*; diff --git a/dynamic-check/src/objects/frame.rs b/dynamic-check/src/objects/frame.rs index ea2494f39a..1148a619ea 100644 --- a/dynamic-check/src/objects/frame.rs +++ b/dynamic-check/src/objects/frame.rs @@ -288,7 +288,7 @@ impl Frame { // Check if an explicit type is given. if let Some(type_) = variables.type_.clone() { - // Convert the expected type into a dynamic check type. + // Check the expected type. let expected_type = match self.self_type { Some(ref circuit_type) => Type::new_from_circuit( &self.user_defined_types, diff --git a/dynamic-check/src/dynamic_check.rs b/dynamic-check/src/type_inference.rs similarity index 85% rename from dynamic-check/src/dynamic_check.rs rename to dynamic-check/src/type_inference.rs index e5e31596b5..4f9e7fcc48 100644 --- a/dynamic-check/src/dynamic_check.rs +++ b/dynamic-check/src/type_inference.rs @@ -14,37 +14,37 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{DynamicCheckError, Frame, Scope}; +use crate::{Frame, Scope, TypeInferenceError}; use leo_core_ast::{Circuit, CircuitMember, Function, Program}; use leo_symbol_table::SymbolTable; -/// Performs a dynamic type inference check over a program. -pub struct DynamicCheck { +/// Stores information need to run a type inference check over a program. +pub struct TypeInference { table: SymbolTable, frames: Vec, } -impl DynamicCheck { +impl TypeInference { /// - /// Creates a new `DynamicCheck` on a given program and symbol table. + /// Creates and runs a new `TypeInference` check on a given program and symbol table. /// /// Evaluates all `TypeAssertion` predicates. /// - pub fn new(program: &Program, symbol_table: SymbolTable) -> Result<(), DynamicCheckError> { - let mut dynamic_check = Self { + pub fn new(program: &Program, symbol_table: SymbolTable) -> Result<(), TypeInferenceError> { + let mut type_inference = Self { table: symbol_table, frames: Vec::new(), }; - dynamic_check.parse_program(program)?; + type_inference.parse_program(program)?; - dynamic_check.check() + type_inference.check() } /// /// Collects a vector of `TypeAssertion` predicates from a program. /// - fn parse_program(&mut self, program: &Program) -> Result<(), DynamicCheckError> { + fn parse_program(&mut self, program: &Program) -> Result<(), TypeInferenceError> { // Parse circuit types in program context. self.parse_circuits(program.circuits.iter().map(|(_identifier, circuit)| circuit))?; @@ -55,7 +55,7 @@ impl DynamicCheck { /// /// Collects a vector of `Frames`s from a vector of circuit functions. /// - fn parse_circuits<'a>(&mut self, circuits: impl Iterator) -> Result<(), DynamicCheckError> { + fn parse_circuits<'a>(&mut self, circuits: impl Iterator) -> Result<(), TypeInferenceError> { for circuit in circuits { self.parse_circuit(circuit)?; } @@ -68,7 +68,7 @@ impl DynamicCheck { /// /// Each frame collects a vector of `TypeAssertion` predicates from each function. /// - fn parse_circuit(&mut self, circuit: &Circuit) -> Result<(), DynamicCheckError> { + fn parse_circuit(&mut self, circuit: &Circuit) -> Result<(), TypeInferenceError> { let name = &circuit.circuit_name.name; // Get circuit type from circuit symbol table. @@ -97,7 +97,7 @@ impl DynamicCheck { /// /// Collects a vector of `TypeAssertion` predicates from a vector of functions. /// - fn parse_functions<'a>(&mut self, functions: impl Iterator) -> Result<(), DynamicCheckError> { + fn parse_functions<'a>(&mut self, functions: impl Iterator) -> Result<(), TypeInferenceError> { for function in functions { self.parse_function(function)?; } @@ -108,7 +108,7 @@ impl DynamicCheck { /// /// Collects a vector of `TypeAssertion` predicates from a function. /// - fn parse_function(&mut self, function: &Function) -> Result<(), DynamicCheckError> { + fn parse_function(&mut self, function: &Function) -> Result<(), TypeInferenceError> { let frame = Frame::new_function(function.to_owned(), None, None, self.table.clone())?; self.frames.push(frame); @@ -123,7 +123,7 @@ impl DynamicCheck { /// Returns a `LeoResolvedAst` if all `TypeAssertion` predicates are true. /// Returns ERROR if a `TypeAssertion` predicate is false or a solution does not exist. /// - pub fn check(self) -> Result<(), DynamicCheckError> { + pub fn check(self) -> Result<(), TypeInferenceError> { for frame in self.frames { frame.check()?; } diff --git a/dynamic-check/tests/arrays/mod.rs b/dynamic-check/tests/arrays/mod.rs index 72a2845b3f..72ab79478e 100644 --- a/dynamic-check/tests/arrays/mod.rs +++ b/dynamic-check/tests/arrays/mod.rs @@ -14,13 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::TestDynamicCheck; +use crate::TestTypeInference; #[test] fn test_empty_array() { let bytes = include_bytes!("empty_array.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } @@ -29,7 +29,7 @@ fn test_empty_array() { fn test_invalid_array_access() { let bytes = include_bytes!("invalid_array_access.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } @@ -38,7 +38,7 @@ fn test_invalid_array_access() { fn test_invalid_spread() { let bytes = include_bytes!("invalid_spread.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } diff --git a/dynamic-check/tests/circuits/mod.rs b/dynamic-check/tests/circuits/mod.rs index d82726197b..8b8d585bd6 100644 --- a/dynamic-check/tests/circuits/mod.rs +++ b/dynamic-check/tests/circuits/mod.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::TestDynamicCheck; +use crate::TestTypeInference; #[test] fn test_invalid_circuit() { let bytes = include_bytes!("invalid_circuit.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } diff --git a/dynamic-check/tests/functions/mod.rs b/dynamic-check/tests/functions/mod.rs index 5599451646..20e873cbaf 100644 --- a/dynamic-check/tests/functions/mod.rs +++ b/dynamic-check/tests/functions/mod.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::TestDynamicCheck; +use crate::TestTypeInference; #[test] fn test_invalid_function() { let bytes = include_bytes!("invalid_function.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } diff --git a/dynamic-check/tests/mod.rs b/dynamic-check/tests/mod.rs index 576be6d5e2..10dac2f0ad 100644 --- a/dynamic-check/tests/mod.rs +++ b/dynamic-check/tests/mod.rs @@ -21,7 +21,7 @@ pub mod tuples; pub mod variables; use leo_ast::LeoAst; -use leo_dynamic_check::DynamicCheck; +use leo_dynamic_check::TypeInference; use leo_core_ast::{Input, LeoCoreAst, Program}; use leo_imports::ImportParser; @@ -31,13 +31,13 @@ use std::path::PathBuf; const TEST_PROGRAM_PATH: &str = ""; const TEST_PROGRAM_NAME: &str = "test"; -/// A helper struct to test a `DynamicCheck`. -pub struct TestDynamicCheck { +/// A helper struct to test a `TypeInference` check. +pub struct TestTypeInference { program: Program, symbol_table: SymbolTable, } -impl TestDynamicCheck { +impl TestTypeInference { pub fn new(bytes: &[u8]) -> Self { // Get file string from bytes. let file_string = String::from_utf8_lossy(bytes); @@ -61,16 +61,16 @@ impl TestDynamicCheck { // Create symbol table. let symbol_table = SymbolTable::new(&program, &import_parser, &input).unwrap(); - // Store fields for new dynamic check. + // Store fields for new type inference check. Self { program, symbol_table } } - pub fn run(self) { - DynamicCheck::new(&self.program, self.symbol_table).unwrap(); + pub fn check(self) { + TypeInference::new(&self.program, self.symbol_table).unwrap(); } pub fn expect_error(self) { - assert!(DynamicCheck::new(&self.program, self.symbol_table).is_err()); + assert!(TypeInference::new(&self.program, self.symbol_table).is_err()); } } @@ -78,7 +78,7 @@ impl TestDynamicCheck { fn test_new() { let bytes = include_bytes!("empty.leo"); - let dynamic_check = TestDynamicCheck::new(bytes); + let type_inference = TestTypeInference::new(bytes); - dynamic_check.run() + type_inference.check() } diff --git a/dynamic-check/tests/tuples/mod.rs b/dynamic-check/tests/tuples/mod.rs index 31b18ffa45..cc0549cffe 100644 --- a/dynamic-check/tests/tuples/mod.rs +++ b/dynamic-check/tests/tuples/mod.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::TestDynamicCheck; +use crate::TestTypeInference; #[test] fn test_invalid_tuple_access() { let bytes = include_bytes!("invalid_tuple_access.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } diff --git a/dynamic-check/tests/variables/mod.rs b/dynamic-check/tests/variables/mod.rs index 2712890704..9e7b3dd1ea 100644 --- a/dynamic-check/tests/variables/mod.rs +++ b/dynamic-check/tests/variables/mod.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::TestDynamicCheck; +use crate::TestTypeInference; #[test] fn test_duplicate_variable() { let bytes = include_bytes!("duplicate_variable.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } @@ -27,7 +27,7 @@ fn test_duplicate_variable() { #[test] fn test_duplicate_variable_multi() { let bytes = include_bytes!("duplicate_variable_multi.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } @@ -35,7 +35,7 @@ fn test_duplicate_variable_multi() { #[test] fn test_not_enough_values() { let bytes = include_bytes!("not_enough_values.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); } @@ -43,7 +43,7 @@ fn test_not_enough_values() { #[test] fn test_too_many_values() { let bytes = include_bytes!("too_many_values.leo"); - let check = TestDynamicCheck::new(bytes); + let check = TestTypeInference::new(bytes); check.expect_error(); }