mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-28 01:01:53 +03:00
rename dynamic-check -> type-inference 1
This commit is contained in:
parent
7e7d1e58a0
commit
f1e393a9ab
@ -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<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
})?;
|
||||
|
||||
// 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<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
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);
|
||||
|
||||
|
@ -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),
|
||||
|
@ -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),
|
||||
|
@ -14,9 +14,6 @@
|
||||
// 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 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::*;
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
@ -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::*;
|
||||
|
@ -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,
|
||||
|
@ -14,37 +14,37 @@
|
||||
// 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::{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<Frame>,
|
||||
}
|
||||
|
||||
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<Item = &'a Circuit>) -> Result<(), DynamicCheckError> {
|
||||
fn parse_circuits<'a>(&mut self, circuits: impl Iterator<Item = &'a Circuit>) -> 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<Item = &'a Function>) -> Result<(), DynamicCheckError> {
|
||||
fn parse_functions<'a>(&mut self, functions: impl Iterator<Item = &'a Function>) -> 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()?;
|
||||
}
|
@ -14,13 +14,13 @@
|
||||
// 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::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();
|
||||
}
|
||||
|
@ -14,12 +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/>.
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -14,12 +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/>.
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -14,12 +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/>.
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -14,12 +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/>.
|
||||
|
||||
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user