mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 02:31:44 +03:00
clippy lints 1
This commit is contained in:
parent
2bb17b496b
commit
33fae17b35
@ -81,9 +81,7 @@ impl ArrayDimensions {
|
||||
///
|
||||
pub fn remove_first(&mut self) -> Option<PositiveNumber> {
|
||||
// If there are no dimensions in the array, then return None.
|
||||
if self.0.first().is_none() {
|
||||
return None;
|
||||
}
|
||||
self.0.first()?;
|
||||
|
||||
// Remove the first dimension.
|
||||
let removed = self.0.remove(0);
|
||||
|
@ -91,7 +91,7 @@ impl Type {
|
||||
let right_new_type = inner_array_type(*right_type.to_owned(), right_dim_owned);
|
||||
|
||||
// Call eq_flat() on the new left and right types.
|
||||
return left_new_type.eq_flat(&right_new_type);
|
||||
left_new_type.eq_flat(&right_new_type)
|
||||
}
|
||||
(Type::Tuple(left), Type::Tuple(right)) => left
|
||||
.iter()
|
||||
|
@ -70,7 +70,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
output_directory,
|
||||
program: Program::new(package_name),
|
||||
program_input: Input::new(),
|
||||
imported_programs: ImportParser::new(),
|
||||
imported_programs: ImportParser::default(),
|
||||
_engine: PhantomData,
|
||||
_group: PhantomData,
|
||||
}
|
||||
@ -214,7 +214,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
})?;
|
||||
|
||||
// Run type inference check on program.
|
||||
TypeInference::new(&self.program, symbol_table).map_err(|mut e| {
|
||||
TypeInference::run(&self.program, symbol_table).map_err(|mut e| {
|
||||
e.set_path(&self.main_file_path);
|
||||
|
||||
e
|
||||
@ -256,7 +256,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 type inference check on program.
|
||||
TypeInference::new(&self.program, symbol_table)?;
|
||||
TypeInference::run(&self.program, symbol_table)?;
|
||||
|
||||
tracing::debug!("Program parsing complete\n{:#?}", self.program);
|
||||
|
||||
|
@ -48,9 +48,7 @@ pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: Constrai
|
||||
|
||||
resolved_program.store_definitions(program, imported_programs)?;
|
||||
|
||||
let main = resolved_program
|
||||
.get(&main_function_name)
|
||||
.ok_or_else(|| CompilerError::NoMain)?;
|
||||
let main = resolved_program.get(&main_function_name).ok_or(CompilerError::NoMain)?;
|
||||
|
||||
match main.clone() {
|
||||
ConstrainedValue::Function(_circuit_identifier, function) => {
|
||||
|
@ -107,7 +107,10 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
Ok(ConstrainedValue::Array(result))
|
||||
}
|
||||
|
||||
/// Enforce array expressions
|
||||
///
|
||||
/// Returns an array value from an array initializer expression.
|
||||
///
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_array_initializer<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
@ -142,8 +145,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
}
|
||||
|
||||
Ok(value)
|
||||
} else {
|
||||
if expected_dimensions.first().eq(&actual_dimensions.first()) {
|
||||
} else if expected_dimensions.first().eq(&actual_dimensions.first()) {
|
||||
// Case 2 - enforce expression with updated array type.
|
||||
let dimension = match expected_dimensions.remove_first() {
|
||||
Some(number) => {
|
||||
@ -170,7 +172,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
expected_expression_type,
|
||||
element_expression,
|
||||
actual_dimensions.clone(),
|
||||
span.clone(),
|
||||
span,
|
||||
)?
|
||||
}
|
||||
None => {
|
||||
@ -195,13 +197,12 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
Err(ExpressionError::invalid_first_dimension(
|
||||
expected_dimensions
|
||||
.first()
|
||||
.ok_or(ExpressionError::undefined_first_dimension(span.clone()))?,
|
||||
.ok_or_else(|| ExpressionError::undefined_first_dimension(span.clone()))?,
|
||||
actual_dimensions
|
||||
.first()
|
||||
.ok_or(ExpressionError::undefined_first_dimension(span.clone()))?,
|
||||
.ok_or_else(|| ExpressionError::undefined_first_dimension(span))?,
|
||||
))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No explicit type given - evaluate array element expression.
|
||||
let mut value =
|
||||
|
@ -70,7 +70,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
|
||||
*old_value = selected_value;
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
} else {
|
||||
match assignee.accesses[0].clone() {
|
||||
AssigneeAccess::Array(range_or_expression) => self.assign_array(
|
||||
|
@ -28,11 +28,13 @@ pub type StatementResult<T> = Result<T, StatementError>;
|
||||
pub type IndicatorAndConstrainedValue<T, U> = (Option<Boolean>, ConstrainedValue<T, U>);
|
||||
|
||||
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
///
|
||||
/// Enforce a program statement.
|
||||
/// Returns a Vector of (indicator, value) tuples.
|
||||
/// Each evaluated statement may execute of one or more statements that may return early.
|
||||
/// To indicate which of these return values to take we conditionally select the value according
|
||||
/// to the `indicator` bit that evaluates to true.
|
||||
///
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_statement<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -58,7 +58,7 @@ impl ImportParserError {
|
||||
/// Failed to convert a file path into an os string.
|
||||
///
|
||||
pub fn convert_os_string(span: Span) -> Self {
|
||||
let message = format!("Failed to convert file string name, maybe an illegal character?");
|
||||
let message = "Failed to convert file string name, maybe an illegal character?".to_string();
|
||||
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
@ -26,23 +26,13 @@ use std::{
|
||||
///
|
||||
/// A program can import one or more packages. A package can be found locally in the source
|
||||
/// directory, foreign in the imports directory, or part of the core package list.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ImportParser {
|
||||
imports: HashMap<String, Program>,
|
||||
core_packages: HashSet<Package>,
|
||||
}
|
||||
|
||||
impl ImportParser {
|
||||
///
|
||||
/// Creates a new empty `ImportParser`.
|
||||
///
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
imports: HashMap::new(),
|
||||
core_packages: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Inserts a (file name -> program) pair into the `ImportParser`.
|
||||
///
|
||||
@ -96,10 +86,10 @@ impl ImportParser {
|
||||
/// 3. Insert the typed syntax tree into the `ImportParser`
|
||||
///
|
||||
pub fn parse(program: &Program) -> Result<Self, ImportParserError> {
|
||||
let mut imports = Self::new();
|
||||
let mut imports = Self::default();
|
||||
|
||||
// Find all imports relative to current directory.
|
||||
let path = current_dir().map_err(|error| ImportParserError::current_directory_error(error))?;
|
||||
let path = current_dir().map_err(ImportParserError::current_directory_error)?;
|
||||
|
||||
// Parse each import statement.
|
||||
for import in &program.imports {
|
||||
|
@ -46,7 +46,7 @@ impl TypeError {
|
||||
/// The `Self` keyword was used outside of a circuit.
|
||||
///
|
||||
pub fn self_not_available(span: Span) -> Self {
|
||||
let message = format!("Type `Self` is only available in circuit definitions and circuit functions.");
|
||||
let message = "Type `Self` is only available in circuit definitions and circuit functions.".to_string();
|
||||
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ impl SymbolTable {
|
||||
self.check_function_names(&program.functions)
|
||||
} else {
|
||||
// Check for a symbol alias.
|
||||
let identifier = symbol.alias.to_owned().unwrap_or(symbol.symbol.to_owned());
|
||||
let identifier = symbol.alias.to_owned().unwrap_or_else(|| symbol.symbol.to_owned());
|
||||
|
||||
// Check if the imported symbol is a circuit
|
||||
match program.circuits.get(&symbol.symbol) {
|
||||
|
@ -92,7 +92,7 @@ impl FunctionType {
|
||||
// Type check function output.
|
||||
let output = FunctionOutputType::new_from_circuit(
|
||||
table,
|
||||
circuit_name.clone(),
|
||||
circuit_name,
|
||||
unresolved_function.output,
|
||||
unresolved_function.span,
|
||||
)?;
|
||||
|
@ -76,7 +76,7 @@ impl Type {
|
||||
// Lookup the circuit type in the symbol table
|
||||
let circuit_type = table
|
||||
.get_circuit_type(&identifier.name)
|
||||
.ok_or(TypeError::undefined_circuit(identifier))?;
|
||||
.ok_or_else(|| TypeError::undefined_circuit(identifier))?;
|
||||
|
||||
Type::Circuit(circuit_type.identifier.clone())
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ impl TestSymbolTable {
|
||||
let program = self.typed.into_repr();
|
||||
|
||||
// Create empty import parser.
|
||||
let import_parser = ImportParser::new();
|
||||
let import_parser = ImportParser::default();
|
||||
|
||||
// Create empty input.
|
||||
let input = Input::new();
|
||||
@ -82,7 +82,7 @@ impl TestSymbolTable {
|
||||
let static_check = &mut SymbolTable::default();
|
||||
|
||||
// Create empty import parser.
|
||||
let import_parser = ImportParser::new();
|
||||
let import_parser = ImportParser::default();
|
||||
|
||||
// Run pass one and expect an error.
|
||||
let error = static_check.check_names(&program, &import_parser).unwrap_err();
|
||||
@ -106,7 +106,7 @@ impl TestSymbolTable {
|
||||
let static_check = &mut SymbolTable::default();
|
||||
|
||||
// Create empty import parser.
|
||||
let import_parser = ImportParser::new();
|
||||
let import_parser = ImportParser::default();
|
||||
|
||||
// Run the pass one and expect no errors.
|
||||
static_check.check_names(&program, &import_parser).unwrap();
|
||||
|
@ -85,8 +85,14 @@ impl TypeVariablePairs {
|
||||
///
|
||||
pub fn push_pairs(&mut self, left: Type, right: Type, span: &Span) -> Result<(), TypeAssertionError> {
|
||||
match (left, right) {
|
||||
(Type::TypeVariable(variable), type_) => Ok(self.push(variable, type_)),
|
||||
(type_, Type::TypeVariable(variable)) => Ok(self.push(variable, type_)),
|
||||
(Type::TypeVariable(variable), type_) => {
|
||||
self.push(variable, type_);
|
||||
Ok(())
|
||||
}
|
||||
(type_, Type::TypeVariable(variable)) => {
|
||||
self.push(variable, type_);
|
||||
Ok(())
|
||||
}
|
||||
(Type::Array(left_type), Type::Array(right_type)) => self.push_pairs_array(*left_type, *right_type, span),
|
||||
(Type::Tuple(left_types), Type::Tuple(right_types)) => {
|
||||
self.push_pairs_tuple(left_types.into_iter(), right_types.into_iter(), span)
|
||||
|
@ -302,7 +302,7 @@ impl Frame {
|
||||
};
|
||||
|
||||
// Assert that the expected type is equal to the actual type.
|
||||
self.assert_equal(expected_type.clone(), actual_type.clone(), span)
|
||||
self.assert_equal(expected_type, actual_type.clone(), span)
|
||||
}
|
||||
|
||||
// Check for multiple defined variables.
|
||||
@ -1128,7 +1128,7 @@ impl Frame {
|
||||
}
|
||||
|
||||
// Return the function output type.
|
||||
Ok(function_type.output.type_.clone())
|
||||
Ok(function_type.output.type_)
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -34,7 +34,7 @@ impl TypeInference {
|
||||
///
|
||||
/// Evaluates all `TypeAssertion` predicates.
|
||||
///
|
||||
pub fn new(program: &Program, symbol_table: SymbolTable) -> Result<(), TypeInferenceError> {
|
||||
pub fn run(program: &Program, symbol_table: SymbolTable) -> Result<(), TypeInferenceError> {
|
||||
let mut type_inference = Self {
|
||||
table: symbol_table,
|
||||
frames: Vec::new(),
|
||||
|
@ -53,7 +53,7 @@ impl TestTypeInference {
|
||||
let program = typed.into_repr();
|
||||
|
||||
// Create empty import parser.
|
||||
let import_parser = ImportParser::new();
|
||||
let import_parser = ImportParser::default();
|
||||
|
||||
// Create empty input.
|
||||
let input = Input::new();
|
||||
@ -66,11 +66,11 @@ impl TestTypeInference {
|
||||
}
|
||||
|
||||
pub fn check(self) {
|
||||
TypeInference::new(&self.program, self.symbol_table).unwrap();
|
||||
TypeInference::run(&self.program, self.symbol_table).unwrap();
|
||||
}
|
||||
|
||||
pub fn expect_error(self) {
|
||||
assert!(TypeInference::new(&self.program, self.symbol_table).is_err());
|
||||
assert!(TypeInference::run(&self.program, self.symbol_table).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user