diff --git a/compiler/ast/src/stub/function_stub.rs b/compiler/ast/src/stub/function_stub.rs index 910b84a0ae..4268fcd892 100644 --- a/compiler/ast/src/stub/function_stub.rs +++ b/compiler/ast/src/stub/function_stub.rs @@ -189,7 +189,7 @@ impl> From<&ClosureCore Type::Unit, 1 => output_vec[0].clone(), - _ => Type::Tuple(Tuple(output_vec)), + _ => Type::Tuple(TupleType::new(output_vec)), }; Self { annotations: Vec::new(), @@ -272,13 +272,13 @@ impl, Command: CommandTrait> .iter() .map(|output| match output { Output::Internal(output) => output.type_.clone(), - Output::External(output) => Type::Identifier(output.record.clone()), + Output::External(output) => Type::Identifier(output.record), }) .collect_vec(); let output_type = match output_vec.len() { 0 => Type::Unit, 1 => output_vec[0].clone(), - _ => Type::Tuple(Tuple(output_vec)), + _ => Type::Tuple(TupleType::new(output_vec)), }; Self { diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index 90ad4170a5..f68524974c 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ArrayType, common, Identifier, IntegerType, MappingType, TupleType}; +use crate::{common, ArrayType, Identifier, IntegerType, MappingType, TupleType}; use itertools::Itertools; use serde::{Deserialize, Serialize}; diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index a6c5adec3e..8958322196 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -128,7 +128,7 @@ impl ParserContext<'_> { self.expect(&Token::Dot)?; // Otherwise throw parser error - self.expect(&Token::Aleo).or_else(|_| Err(ParserError::invalid_network(self.token.span)))?; + self.expect(&Token::Aleo).map_err(|_| ParserError::invalid_network(self.token.span))?; // Construct the program id. let program_id = @@ -221,7 +221,7 @@ impl ParserContext<'_> { // Parse `program` keyword. let start = self.expect(&Token::Program)?; let (program_scope, imports) = self.parse_program_body(start)?; - if imports.len() != 0 { + if !imports.is_empty() { self.emit_err(ParserError::cannot_import_inside_program_body(self.token.span)); } Ok(program_scope) diff --git a/compiler/parser/src/parser/type_.rs b/compiler/parser/src/parser/type_.rs index 560baa9531..66cf348751 100644 --- a/compiler/parser/src/parser/type_.rs +++ b/compiler/parser/src/parser/type_.rs @@ -81,7 +81,7 @@ impl ParserContext<'_> { if let Some(ident) = self.eat_identifier() { // Check if using external type let file_type = self.look_ahead(1, |t| &t.token); - if &self.token.token == &Token::Dot && (file_type == &Token::Leo || file_type == &Token::Aleo) { + if self.token.token == Token::Dot && (file_type == &Token::Leo || file_type == &Token::Aleo) { return Err(ParserError::external_type_cannot_be_used_inside_function( ident, file_type, diff --git a/compiler/passes/src/code_generation/visit_expressions.rs b/compiler/passes/src/code_generation/visit_expressions.rs index 60811f91f6..72f7ce15cd 100644 --- a/compiler/passes/src/code_generation/visit_expressions.rs +++ b/compiler/passes/src/code_generation/visit_expressions.rs @@ -539,9 +539,9 @@ impl<'a> CodeGenerator<'a> { { Some(program) => program, None => { - let stub_program = self.program.stubs.get(&program_name); - if stub_program.is_some() { - stub_scope = ProgramScope::from(stub_program.unwrap().clone()); + let _stub_program = self.program.stubs.get(&program_name); + if let Some(stub) = self.program.stubs.get(&program_name) { + stub_scope = ProgramScope::from(stub.clone()); &stub_scope } else { unreachable!("Type checking guarantees that imported and stub programs are well defined.") diff --git a/compiler/passes/src/destructuring/destructure_statement.rs b/compiler/passes/src/destructuring/destructure_statement.rs index 8d7189ce74..c5cd99cd92 100644 --- a/compiler/passes/src/destructuring/destructure_statement.rs +++ b/compiler/passes/src/destructuring/destructure_statement.rs @@ -173,7 +173,7 @@ impl StatementReconstructor for Destructurer<'_> { let statements = lhs_tuple .elements .into_iter() - .zip_eq(rhs_tuple.elements.into_iter()) + .zip_eq(rhs_tuple.elements) .map(|(lhs, rhs)| { // Get the type of the rhs. let type_ = match self.type_table.get(&lhs.id()) { diff --git a/compiler/passes/src/type_checking/check_program.rs b/compiler/passes/src/type_checking/check_program.rs index d388efc20c..7a25efcd1d 100644 --- a/compiler/passes/src/type_checking/check_program.rs +++ b/compiler/passes/src/type_checking/check_program.rs @@ -57,7 +57,7 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> { fn visit_stub(&mut self, input: &'a Stub) { // Cannot have mappings in stubs. - if input.mappings.len() != 0 { + if !input.mappings.is_empty() { self.emit_err(TypeCheckerError::stubs_can_only_have_records_and_transitions( "mapping", input.mappings.get(0).unwrap().1.span, @@ -65,7 +65,7 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> { } // Cannot have constant declarations in stubs. - if input.consts.len() != 0 { + if !input.consts.is_empty() { self.emit_err(TypeCheckerError::stubs_can_only_have_records_and_transitions( "constant declaration", input.consts.get(0).unwrap().1.span, @@ -111,66 +111,6 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> { self.exit_scope(function_index); } - fn visit_struct_stub(&mut self, input: &'a Struct) { - self.visit_struct(input); - } - - fn visit_stub(&mut self, input: &'a Stub) { - // Cannot have mappings in stubs. - if input.mappings.len() != 0 { - self.emit_err(TypeCheckerError::stubs_can_only_have_records_and_transitions( - "mapping", - input.mappings.get(0).unwrap().1.span, - )); - } - - // Cannot have constant declarations in stubs. - if input.consts.len() != 0 { - self.emit_err(TypeCheckerError::stubs_can_only_have_records_and_transitions( - "constant declaration", - input.consts.get(0).unwrap().1.span, - )); - } - - // Typecheck the program's structs. - input.structs.iter().for_each(|(_, function)| self.visit_struct_stub(function)); - - // Typecheck the program's functions. - input.functions.iter().for_each(|(_, function)| self.visit_function_stub(function)); - } - - fn visit_function_stub(&mut self, input: &'a FunctionStub) { - // Cannot have finalize scopes - if input.finalize.is_some() { - self.emit_err(TypeCheckerError::stub_functions_must_have_no_finalize( - input.finalize.as_ref().unwrap().span, - )); - } - - // Must be transition functions - if input.variant == Variant::Inline { - self.emit_err(TypeCheckerError::stub_functions_must_not_be_inlines(input.span)); - } - - // Must be empty - if !input.block.statements.is_empty() { - self.emit_err(TypeCheckerError::stub_functions_must_be_empty(input.block.span)); - } - - // Lookup function metadata in the symbol table. - // Note that this unwrap is safe since function metadata is stored in a prior pass. - let function_index = self.symbol_table.borrow().lookup_fn_symbol(input.identifier.name).unwrap().id; - - // Enter the function's scope. - self.enter_scope(function_index); - - // Query helper function to type check function parameters and outputs. - self.check_function_signature(&Function::from(input.clone())); - - // Exit the function's scope. - self.exit_scope(function_index); - } - fn visit_struct_stub(&mut self, input: &'a Struct) { // Allow records only. if !input.is_record { diff --git a/errors/src/errors/parser/parser_errors.rs b/errors/src/errors/parser/parser_errors.rs index 0287c5872b..10a176f289 100644 --- a/errors/src/errors/parser/parser_errors.rs +++ b/errors/src/errors/parser/parser_errors.rs @@ -292,30 +292,6 @@ create_messages!( help: None, } - /// Enforce that empty functions cannot have finalize functions attached to them - @formatted - empty_function_cannot_have_finalize { - args: (), - msg: format!("Empty functions cannot have finalize functions attached to them."), - help: None, - } - - /// Enforce that cannot use an external type to do anything except input/output of function - @formatted - external_type_cannot_be_used_inside_function { - args: (program: impl Display, file_type: impl Display), - msg: format!("External types cannot be used inside function (only as input/output types) -- found exported type from '{program}.{file_type}'."), - help: None, - } - - /// Enforce that cannot use import in program scope - @formatted - cannot_import_inside_program_body { - args: (), - msg: format!("Cannot use import inside program body."), - help: None, - } - @formatted array_must_have_at_least_one_element { args: (kind: impl Display), diff --git a/errors/src/errors/type_checker/type_checker_error.rs b/errors/src/errors/type_checker/type_checker_error.rs index 1741c42525..c6e5bc189b 100644 --- a/errors/src/errors/type_checker/type_checker_error.rs +++ b/errors/src/errors/type_checker/type_checker_error.rs @@ -699,12 +699,7 @@ create_messages!( help: None, } - @formatted - stub_functions_must_be_empty { - args: (), - msg: format!("Functions stubs must be empty"), - help: None, - } + @formatted stub_functions_must_have_no_finalize { @@ -713,20 +708,6 @@ create_messages!( help: None, } - @formatted - stubs_can_only_have_records_and_transitions { - args: (found: impl Display), - msg: format!("Stubs can only have records, transitions, functions and imports -- found {found}"), - help: None, - } - - @formatted - stub_functions_must_not_be_inlines { - args: (), - msg: format!("Function stubs must be transitions or function variants not inlines"), - help: None, - } - @formatted stub_functions_must_be_empty { args: (), @@ -734,13 +715,6 @@ create_messages!( help: None, } - @formatted - stub_functions_must_have_no_finalize { - args: (), - msg: format!("Function stubs must not have finalize blocks"), - help: None, - } - @formatted array_empty { args: (), diff --git a/utils/disassembler/Cargo.toml b/utils/disassembler/Cargo.toml index 5b7089db05..346445ba1e 100644 --- a/utils/disassembler/Cargo.toml +++ b/utils/disassembler/Cargo.toml @@ -10,7 +10,7 @@ workspace = true [dependencies.leo-ast] path = "../../compiler/ast" -version = "=1.9.4" +version = "=1.10.0" [dependencies.leo-span] path = "../../compiler/span" diff --git a/utils/disassembler/src/main.rs b/utils/disassembler/src/main.rs index dda3e20cc6..d3b68820e2 100644 --- a/utils/disassembler/src/main.rs +++ b/utils/disassembler/src/main.rs @@ -15,16 +15,11 @@ // along with the Leo library. If not, see . use snarkvm::{ - console::network::Testnet3, prelude::{Itertools, Network}, - synthesizer::program::{CommandTrait, InstructionTrait, Program, ProgramCore}, + synthesizer::program::{CommandTrait, InstructionTrait, ProgramCore}, }; -use std::str::FromStr; use leo_ast::{FunctionStub, Identifier, ProgramId, Struct, Stub}; -use leo_span::symbol::create_session_if_not_set_then; - -type CurrentNetwork = Testnet3; fn main() {} @@ -61,6 +56,11 @@ pub fn disassemble, Command: Comman #[cfg(test)] mod tests { use super::*; + use leo_span::symbol::create_session_if_not_set_then; + use snarkvm::{prelude::Testnet3, synthesizer::program::Program}; + use std::str::FromStr; + + type CurrentNetwork = Testnet3; #[test] fn credits_test() { @@ -68,7 +68,7 @@ mod tests { let aleo_prog_1 = std::fs::read_to_string("/Users/evanschott/work/leo/utils/disassembler/src/tests/credits.aleo") .unwrap(); - let program = Program::::from_str(&*aleo_prog_1); + let program = Program::::from_str(&aleo_prog_1); match program { Ok(p) => { let disassembled = disassemble(p);