From 3b26e610500e944fc8ddee49faffbac2de188995 Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Fri, 27 Aug 2021 11:42:20 -0700 Subject: [PATCH 01/28] refactor global consts should no longer allow shadowing --- asg/src/program/mod.rs | 68 ++++++++++++++------ ast-passes/src/import_resolution/importer.rs | 2 +- ast/src/program.rs | 2 +- ast/src/reducer/reconstructing_reducer.rs | 2 +- errors/src/asg/asg_errors.rs | 8 +++ parser/src/parser/file.rs | 7 +- 6 files changed, 61 insertions(+), 28 deletions(-) diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index c0e94dc561..4cf7b51a88 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -242,6 +242,23 @@ impl<'a> Program<'a> { scope.aliases.borrow_mut().insert(name.name.to_string(), asg_alias); } + for (names, global_const) in program.global_consts.iter() { + let gc = <&Statement<'a>>::from_ast(scope, global_const, None)?; + if let Statement::Definition(def) = gc { + let name = names + .iter() + .enumerate() + .map(|(i, name)| { + assert_eq!(name.name, def.variables.get(i).unwrap().borrow().name.name); + name.name.to_string() + }) + .collect::>() + .join(","); + + scope.global_consts.borrow_mut().insert(name, def); + } + } + for (name, circuit) in program.circuits.iter() { assert_eq!(name.name, circuit.circuit_name.name); let asg_circuit = Circuit::init(scope, circuit)?; @@ -264,19 +281,26 @@ impl<'a> Program<'a> { scope.functions.borrow_mut().insert(name.name.to_string(), function); } - for (name, global_const) in program.global_consts.iter() { - global_const - .variable_names - .iter() - .for_each(|variable_name| assert!(name.contains(&variable_name.identifier.name.to_string()))); - let gc = <&Statement<'a>>::from_ast(scope, global_const, None)?; - if let Statement::Definition(gc) = gc { - scope.global_consts.borrow_mut().insert(name.clone(), gc); - } - } - // Load concrete definitions. let mut aliases = IndexMap::new(); + let mut global_consts = IndexMap::new(); + let mut functions = IndexMap::new(); + let mut circuits = IndexMap::new(); + + /* let check_global_shadowing = |name: String, span: &Span| -> Result<()> { + if aliases.contains_key(&name) { + return Err(AsgError::duplicate_alias_definition(name, span).into()); + } else if global_consts.contains_key(&name) { + return Err(AsgError::duplicate_global_const_definition(name, span).into()); + } else if functions.contains_key(&name) { + return Err(AsgError::duplicate_function_definition(name, span).into()); + } else if circuits.contains_key(&name) { + return Err(AsgError::duplicate_circuit_definition(name, span).into()); + } else { + Ok(()) + } + }; */ + for (name, alias) in program.aliases.iter() { assert_eq!(name.name, alias.name.name); let asg_alias = *scope.aliases.borrow().get(name.name.as_ref()).unwrap(); @@ -290,18 +314,21 @@ impl<'a> Program<'a> { aliases.insert(name, asg_alias); } - let mut global_consts = IndexMap::new(); - for (name, global_const) in program.global_consts.iter() { - global_const - .variable_names - .iter() - .for_each(|variable_name| assert!(name.contains(&variable_name.identifier.name.to_string()))); - let asg_global_const = *scope.global_consts.borrow().get(name).unwrap(); + for (names, global_const) in program.global_consts.iter() { + for (identifier, variable) in names.iter().zip(global_const.variable_names.iter()) { + assert_eq!(identifier.name, variable.identifier.name); - global_consts.insert(name.clone(), asg_global_const); + let name = identifier.name.to_string(); + let asg_global_const = *scope.global_consts.borrow().get(&name).unwrap(); + + if global_consts.contains_key(&name) { + return Err(AsgError::duplicate_global_const_definition(name, &global_const.span).into()); + } + + global_consts.insert(name.clone(), asg_global_const); + } } - let mut functions = IndexMap::new(); for (name, function) in program.functions.iter() { assert_eq!(name.name, function.identifier.name); let asg_function = *scope.functions.borrow().get(name.name.as_ref()).unwrap(); @@ -317,7 +344,6 @@ impl<'a> Program<'a> { functions.insert(name, asg_function); } - let mut circuits = IndexMap::new(); for (name, circuit) in program.circuits.iter() { assert_eq!(name.name, circuit.circuit_name.name); let asg_circuit = *scope.circuits.borrow().get(name.name.as_ref()).unwrap(); diff --git a/ast-passes/src/import_resolution/importer.rs b/ast-passes/src/import_resolution/importer.rs index 003dd945f0..118a8a5c43 100644 --- a/ast-passes/src/import_resolution/importer.rs +++ b/ast-passes/src/import_resolution/importer.rs @@ -128,7 +128,7 @@ where aliases: IndexMap, circuits: IndexMap, functions: IndexMap, - global_consts: IndexMap, + global_consts: IndexMap, DefinitionStatement>, ) -> Result { if !empty_imports.is_empty() { return Err(AstError::injected_programs(empty_imports.len()).into()); diff --git a/ast/src/program.rs b/ast/src/program.rs index e666663e96..3c42d14058 100644 --- a/ast/src/program.rs +++ b/ast/src/program.rs @@ -33,7 +33,7 @@ pub struct Program { pub imports: IndexMap, Program>, pub aliases: IndexMap, pub circuits: IndexMap, - pub global_consts: IndexMap, + pub global_consts: IndexMap, DefinitionStatement>, pub functions: IndexMap, } diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index ce3df848a6..671c60ffce 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -387,7 +387,7 @@ pub trait ReconstructingReducer { aliases: IndexMap, circuits: IndexMap, functions: IndexMap, - global_consts: IndexMap, + global_consts: IndexMap, DefinitionStatement>, ) -> Result { Ok(Program { name: program.name.clone(), diff --git a/errors/src/asg/asg_errors.rs b/errors/src/asg/asg_errors.rs index e7217461d3..da31092e39 100644 --- a/errors/src/asg/asg_errors.rs +++ b/errors/src/asg/asg_errors.rs @@ -420,6 +420,14 @@ create_errors!( help: None, } + /// For when a user defines an circuit with the same name twice. + @formatted + duplicate_circuit_definition { + args: (name: impl Display), + msg: format!("a circuit named \"{}\" already exists in this scope", name), + help: None, + } + /// For when a user defines a function input with the same name twice. @formatted duplicate_function_input_definition { diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index c28ad28021..993c2200ed 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -507,14 +507,13 @@ impl ParserContext { /// Returns an [`(String, DefinitionStatement)`] AST node if the next tokens represent a global /// const definition statement and assignment. /// - pub fn parse_global_const_declaration(&mut self) -> Result<(String, DefinitionStatement)> { + pub fn parse_global_const_declaration(&mut self) -> Result<(Vec, DefinitionStatement)> { let statement = self.parse_definition_statement()?; let variable_names = statement .variable_names .iter() - .map(|variable_name| variable_name.identifier.name.to_string()) - .collect::>() - .join(","); + .map(|variable_name| variable_name.identifier.clone()) + .collect::>(); Ok((variable_names, statement)) } From eee2db223de06cb77e079d5c125ebc0cb7cbe407 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Tue, 31 Aug 2021 09:11:26 -0700 Subject: [PATCH 02/28] [RFC] Streamline RFC author information. --- docs/rfc/001-initial-strings.md | 10 +--- docs/rfc/002-bounded-recursion.md | 9 +--- docs/rfc/003-imports-stabilization.md | 53 ++++++++----------- docs/rfc/004-integer-type-casts.md | 9 +--- docs/rfc/005-countdown-loops.md | 23 +++----- docs/rfc/006-arrays-without-size.md | 9 +--- docs/rfc/007-type-aliases.md | 9 +--- docs/rfc/008-built-in-declarations.md | 9 +--- docs/rfc/009-bit-byte-conversions.md | 9 +--- docs/rfc/010-native-functions.md | 9 +--- .../011-scalar-type-accesses-and-methods.md | 11 +--- 11 files changed, 41 insertions(+), 119 deletions(-) diff --git a/docs/rfc/001-initial-strings.md b/docs/rfc/001-initial-strings.md index 3ffadae193..7066d704ab 100644 --- a/docs/rfc/001-initial-strings.md +++ b/docs/rfc/001-initial-strings.md @@ -2,15 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Pratyush Mishra -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status diff --git a/docs/rfc/002-bounded-recursion.md b/docs/rfc/002-bounded-recursion.md index 3e56153b65..01aadcb208 100644 --- a/docs/rfc/002-bounded-recursion.md +++ b/docs/rfc/002-bounded-recursion.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status diff --git a/docs/rfc/003-imports-stabilization.md b/docs/rfc/003-imports-stabilization.md index 27a393c32f..6f1cd1fe81 100644 --- a/docs/rfc/003-imports-stabilization.md +++ b/docs/rfc/003-imports-stabilization.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status @@ -18,7 +11,7 @@ FINAL # Summary This proposal aims to improve the import management system in Leo programs to -make program environment more reproducible, predictable and compatible. To achieve +make program environment more reproducible, predictable and compatible. To achieve that we suggest few changes to Leo CLI and Manifest: - add a "dependencies" section to Leo Manifest and add a command to pull those dependencies; @@ -29,19 +22,19 @@ that we suggest few changes to Leo CLI and Manifest: # Motivation -The current design of imports does not provide any guarantees on what's stored -in program imports and published with the program to Aleo Package Manager. +The current design of imports does not provide any guarantees on what's stored +in program imports and published with the program to Aleo Package Manager. When a dependency is "added," it is stored inside imports folder, and it is possible to manually edit and/or add packages in this folder. Also, imports are stored under the package name which makes it impossible to import -two different packages with the same name. +two different packages with the same name. Another important detail in the scope of this proposal is that in future Leo -programs will have the ability to be run with different proving systems -and curves, possibly creating incompatibility between programs written +programs will have the ability to be run with different proving systems +and curves, possibly creating incompatibility between programs written for different proving systems or curves. To make a foundation for these features, -imports need to be managed with include/exclude lists for allowed (compatible) +imports need to be managed with include/exclude lists for allowed (compatible) proving systems and curves. # Design @@ -67,7 +60,7 @@ curve = "Bls12_377" proving_system = "Groth16" ``` -These fields are meant to be used to determine whether imported program is +These fields are meant to be used to determine whether imported program is compatible to the original when support for different curves and proving systems is added. @@ -88,7 +81,7 @@ version = "1.0" ### Parameters description -`name` field sets the name of the dependency in Leo code. That way we allow +`name` field sets the name of the dependency in Leo code. That way we allow developer to resolve collisions in import names manually. So, for example, if a developer is adding `howard/silly-sudoku` package to his program, he might define its in-code name as `sudoku` and import it with that name: @@ -97,13 +90,13 @@ might define its in-code name as `sudoku` and import it with that name: import sudoku; ``` -`package`, `author` and `version` are package name, package author and -version respectively. They are already used as arguments in `leo add` +`package`, `author` and `version` are package name, package author and +version respectively. They are already used as arguments in `leo add` command, so these fields are already understood by the Leo developers. -## Leo CLI +## Leo CLI -To support updated Manifest new command should be added to Leo CLI. +To support updated Manifest new command should be added to Leo CLI. ```bash # pull imports @@ -113,11 +106,11 @@ leo fetch ## Imports Restructurization One of the goals of proposed changes is to allow importing packages with the -same name but different authors. This has to be solved not only on the -language level but also on the level of storing program imports. +same name but different authors. This has to be solved not only on the +language level but also on the level of storing program imports. We suggest using set of all 3 possible program identifiers for import -folder name: `author-package@version`. Later it can be extended to +folder name: `author-package@version`. Later it can be extended to include hash for version, but having the inital set already solves name collisions. @@ -140,7 +133,7 @@ leo-program This change would also affect the way imports are being processed on the ASG level, and we'd need to add an imports map as an argument to the Leo compiler. -The Leo Manifest's dependencies sections needs to be parsed and passed as +The Leo Manifest's dependencies sections needs to be parsed and passed as a hashmap to the compiler: ``` @@ -184,7 +177,7 @@ The format described here allows the Leo binary to form an imports map which can passed to the compiler. It is important to note that Leo.lock file is created only when a package has dependencies. -For programs with no dependencies, a lock file is not required and not created. +For programs with no dependencies, a lock file is not required and not created. ## Recursive Dependencies @@ -208,12 +201,12 @@ It also introduces the danger of having recursive dependencies, this problem is # Effect on Ecosystem Proposed improvement provides safety inside Leo programs and should not affect -ecosystem except for the tools which use Leo directly (such as Aleo Studio). +ecosystem except for the tools which use Leo directly (such as Aleo Studio). -It is possible that some of the proposed features will open new features on Aleo PM. +It is possible that some of the proposed features will open new features on Aleo PM. # Alternatives Another approach to the stated cases is to keep everything as we have now but change -the way programs are imported and stored and make names unique. Also, current -implementation provides some guarantees on import stablitity and consistency. +the way programs are imported and stored and make names unique. Also, current +implementation provides some guarantees on import stablitity and consistency. diff --git a/docs/rfc/004-integer-type-casts.md b/docs/rfc/004-integer-type-casts.md index 81a99abe11..38f4a3552e 100644 --- a/docs/rfc/004-integer-type-casts.md +++ b/docs/rfc/004-integer-type-casts.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status diff --git a/docs/rfc/005-countdown-loops.md b/docs/rfc/005-countdown-loops.md index 2cbb3a4a6a..ab76016ec5 100644 --- a/docs/rfc/005-countdown-loops.md +++ b/docs/rfc/005-countdown-loops.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status @@ -67,7 +60,7 @@ function bubble_sort(a: [u32; 10]) -> [u32; 10] { Having a countdown loop in the examples above could improve readability and usability of the language by making it more natural to the developer. -However, if we imagined this example using a countdown loop, we would see that +However, if we imagined this example using a countdown loop, we would see that it wouldn't be possible to count to 0; because the first bound of the range is inclusive and the second is exclusive, and loops ranges must use only unsigned integers. @@ -75,19 +68,19 @@ inclusive and the second is exclusive, and loops ranges must use only unsigned i // loop goes 0,1,2,3,4,5,6,7,8 for i in 0..9 { /* ... */ } -// loop goes 9,8,7,6,5,4,3,2,1 +// loop goes 9,8,7,6,5,4,3,2,1 for i in 9..0 { /* ... */ } ``` Hence direct implementation of the coundown loop ranges would create asymmetry (1) -and would not allow loops to count down to 0 (2). To implement coundown loops and +and would not allow loops to count down to 0 (2). To implement coundown loops and solve these two problems we suggest adding an inclusive range bounds. # Design ## Coundown loops -Countdown ranges do not need any changes to the existing syntax. However their +Countdown ranges do not need any changes to the existing syntax. However their functionality needs to be implemented in the compiler. ```ts @@ -96,9 +89,9 @@ for i in 5..0 {} ## Inclusive ranges -To solve loop asymmetry and to improve loop ranges in general we suggest adding -inclusive range operator to Leo. Inclusive range would extend the second bound -of the loop making it inclusive (instead of default - exclusive) +To solve loop asymmetry and to improve loop ranges in general we suggest adding +inclusive range operator to Leo. Inclusive range would extend the second bound +of the loop making it inclusive (instead of default - exclusive) therefore allowing countdown loops to reach 0 value. ```ts diff --git a/docs/rfc/006-arrays-without-size.md b/docs/rfc/006-arrays-without-size.md index 0fc67ac6c6..ec84e9d094 100644 --- a/docs/rfc/006-arrays-without-size.md +++ b/docs/rfc/006-arrays-without-size.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status diff --git a/docs/rfc/007-type-aliases.md b/docs/rfc/007-type-aliases.md index 5cb84bb882..ec424d4643 100644 --- a/docs/rfc/007-type-aliases.md +++ b/docs/rfc/007-type-aliases.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status diff --git a/docs/rfc/008-built-in-declarations.md b/docs/rfc/008-built-in-declarations.md index 4f710ec3a0..28d1af7360 100644 --- a/docs/rfc/008-built-in-declarations.md +++ b/docs/rfc/008-built-in-declarations.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status diff --git a/docs/rfc/009-bit-byte-conversions.md b/docs/rfc/009-bit-byte-conversions.md index ff3b4eb51d..b582ae0997 100644 --- a/docs/rfc/009-bit-byte-conversions.md +++ b/docs/rfc/009-bit-byte-conversions.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status diff --git a/docs/rfc/010-native-functions.md b/docs/rfc/010-native-functions.md index 17b28d6440..3d85f58cc7 100644 --- a/docs/rfc/010-native-functions.md +++ b/docs/rfc/010-native-functions.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status diff --git a/docs/rfc/011-scalar-type-accesses-and-methods.md b/docs/rfc/011-scalar-type-accesses-and-methods.md index 02b1fb731d..2867ee13b3 100644 --- a/docs/rfc/011-scalar-type-accesses-and-methods.md +++ b/docs/rfc/011-scalar-type-accesses-and-methods.md @@ -2,14 +2,7 @@ ## Authors -- Max Bruce -- Collin Chin -- Alessandro Coglio -- Eric McCarthy -- Jon Pavlik -- Damir Shamanaev -- Damon Sicore -- Howard Wu +The Aleo Team. ## Status @@ -52,7 +45,7 @@ postfix-expression = primary-expression / identifier function-arguments / postfix-expression "." identifier function-arguments / named-type "::" identifier function-arguments ; this used to be a circuit-type - / named-type "::" identifier ; this is new to allow static members on + / named-type "::" identifier ; this is new to allow static members on / postfix-expression "[" expression "]" / postfix-expression "[" [expression] ".." [expression] "]" ``` From 2c66f5589b899bf964b6a27ddc36053edab9237d Mon Sep 17 00:00:00 2001 From: damirka Date: Tue, 31 Aug 2021 20:23:11 +0300 Subject: [PATCH 03/28] workflow dispatch --- .github/workflows/acl2.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/acl2.yml b/.github/workflows/acl2.yml index bc9aabf1b5..91d44aa0b7 100644 --- a/.github/workflows/acl2.yml +++ b/.github/workflows/acl2.yml @@ -1,14 +1,5 @@ name: Leo-ACL2 -on: - pull_request: - push: - branches: - - master - - staging - - trying - paths-ignore: - - 'docs/**' - - 'documentation/**' +on: workflow_dispatch env: RUST_BACKTRACE: 1 From 3a60404038a7e71dcfae88ed16eb8d19c7f71634 Mon Sep 17 00:00:00 2001 From: damirka Date: Tue, 31 Aug 2021 20:23:40 +0300 Subject: [PATCH 04/28] remove output --- .github/workflows/acl2.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/acl2.yml b/.github/workflows/acl2.yml index 91d44aa0b7..9f742b3feb 100644 --- a/.github/workflows/acl2.yml +++ b/.github/workflows/acl2.yml @@ -62,8 +62,8 @@ jobs: echo "Attaching logs:" for dir in ${canonicalization_errors[@]}; do - cat tmp/tgc/$dir/canonicalization_result.out - cat tmp/tgc/$dir/canonicalization-theorem.lisp + # cat tmp/tgc/$dir/canonicalization_result.out + # cat tmp/tgc/$dir/canonicalization-theorem.lisp done; exit 1 fi @@ -80,7 +80,7 @@ jobs: echo "Attaching logs:" for dir in ${type_inference_errors[@]}; do - cat tmp/tgc/$dir/type_inference_result.out + # cat tmp/tgc/$dir/type_inference_result.out done; exit 1 From ab01d45bfcaa18af9948753de71d8ee6532e9152 Mon Sep 17 00:00:00 2001 From: damirka Date: Tue, 31 Aug 2021 20:29:50 +0300 Subject: [PATCH 05/28] enable ti --- .github/workflows/acl2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/acl2.yml b/.github/workflows/acl2.yml index 9f742b3feb..5f9c63e335 100644 --- a/.github/workflows/acl2.yml +++ b/.github/workflows/acl2.yml @@ -46,7 +46,7 @@ jobs: cd tmp/tgc/$dir; # enter the directory ./../../../acl2/tgc canonicalization initial_ast.json canonicalization_ast.json canonicalization-theorem.lisp > canonicalization_result.out || canonicalization_errors+=("$dir"); # Disabling Type inference for now - # ./../../../acl2/tgc type-inference canonicalization_ast.json type_inferenced_ast.json type-inference-theorem.lisp > type_inference_result.out || type_inference_errors+=("$dir"); + ./../../../acl2/tgc type-inference canonicalization_ast.json type_inferenced_ast.json type-inference-theorem.lisp > type_inference_result.out || type_inference_errors+=("$dir"); cd ../../.. done; From 0bc843f8f671443f5a6f9d5b573932f0867503b9 Mon Sep 17 00:00:00 2001 From: Damir S Date: Tue, 31 Aug 2021 20:41:04 +0300 Subject: [PATCH 06/28] Update acl2.yml --- .github/workflows/acl2.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/acl2.yml b/.github/workflows/acl2.yml index 5f9c63e335..68a0b47624 100644 --- a/.github/workflows/acl2.yml +++ b/.github/workflows/acl2.yml @@ -59,12 +59,12 @@ jobs: echo $dir; done; - echo "Attaching logs:" - for dir in ${canonicalization_errors[@]}; - do - # cat tmp/tgc/$dir/canonicalization_result.out - # cat tmp/tgc/$dir/canonicalization-theorem.lisp - done; + #echo "Attaching logs:" + #for dir in ${canonicalization_errors[@]}; + #do + # cat tmp/tgc/$dir/canonicalization_result.out + # cat tmp/tgc/$dir/canonicalization-theorem.lisp + #done; exit 1 fi @@ -77,11 +77,11 @@ jobs: echo $dir; done; - echo "Attaching logs:" - for dir in ${type_inference_errors[@]}; - do - # cat tmp/tgc/$dir/type_inference_result.out - done; + #echo "Attaching logs:" + #for dir in ${type_inference_errors[@]}; + #do + # cat tmp/tgc/$dir/type_inference_result.out + #done; exit 1 fi From 1c18f4c56d729a3882291dc107d7b977e61dd237 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Thu, 2 Sep 2021 21:54:42 -0700 Subject: [PATCH 07/28] [ABNF] Improve nomenclature. Replace 'circuit-or-alias-type' with 'identifier-or-self-type'. This makes the nomenclature for types more clear and extensible: - A type may be an identifier, which may be the name of a circuit type or the name of a type alias. - In the future, an identifier used as a type could refer to other kinds of types that we may add, such as enumerations. - While both 'alias type' and 'type alias' could be acceptable terms, it seems best to standardize on 'type alias': the latter describes an alias of a type (which is the right concept), while the former suggests a type of the "alias" kind (cf. 'circuit type', 'field type', 'integer type', etc.). Type aliases are not another kind of types like the other: they are aliases of (any of) those kinds of types. So by not having 'circuit-or-alias-type' we avoid suggesting a notion of 'alias type'. This does not change the language described by the grammar, it merely changes some nomenclature in the grammar. Thus, no change to the parser is needed. Aligning the nomenclature in the abstract syntax and parser to the ABNF would be good, but entirely optional at this point. --- grammar/abnf-grammar.txt | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/grammar/abnf-grammar.txt b/grammar/abnf-grammar.txt index 3786d3906a..dbec25b6ba 100644 --- a/grammar/abnf-grammar.txt +++ b/grammar/abnf-grammar.txt @@ -659,13 +659,16 @@ character-type = %s"char" scalar-type = boolean-type / arithmetic-type / address-type / character-type -; Circuit types are denoted by identifiers and the keyword `Self`. -; The latter is only allowed inside a circuit definition, -; to denote the circuit being defined. +; Circuit types are denoted by identifiers and the keyword `Self`; +; the latter is only allowed inside a circuit definition, +; to denote the circuit type being defined. +; Identifiers may also be type aliases; +; syntactically (i.e. without a semantic analysis), +; they cannot be distinguished from circuit types. self-type = %s"Self" -circuit-or-alias-type = identifier / self-type +identifier-or-self-type = identifier / self-type ; A tuple type consists of zero, two, or more component types. @@ -683,7 +686,7 @@ array-dimensions = natural ; Scalar and the remaining types form all the types. -type = scalar-type / tuple-type / array-type / circuit-or-alias-type +type = scalar-type / tuple-type / array-type / identifier-or-self-type ; The lexical grammar given earlier defines product group literals. ; The other kind of group literal is a pair of integer coordinates, @@ -769,7 +772,7 @@ array-expression = array-construction ; while the right one denotes an expression (a variable), ; so they are syntactically identical but semantically different. -circuit-construction = circuit-or-alias-type "{" +circuit-construction = identifier-or-self-type "{" circuit-inline-element *( "," circuit-inline-element ) [ "," ] "}" @@ -805,7 +808,7 @@ postfix-expression = primary-expression / postfix-expression "." identifier / identifier function-arguments / postfix-expression "." identifier function-arguments - / circuit-or-alias-type "::" identifier function-arguments + / identifier-or-self-type "::" identifier function-arguments / postfix-expression "[" expression "]" / postfix-expression "[" [expression] ".." [expression] "]" @@ -935,7 +938,8 @@ conditional-statement = branch ; that goes from a starting value (inclusive) to an ending value (exclusive). ; The body is a block. -loop-statement = %s"for" identifier %s"in" expression ".." [ "=" ] expression block +loop-statement = %s"for" identifier %s"in" expression ".." [ "=" ] expression + block ; An assignment statement is straightforward. ; Based on the operator, the assignment may be simple (i.e. `=`) @@ -1047,9 +1051,7 @@ package-path = "*" / package-name "." package-path / "(" package-path *( "," package-path ) [","] ")" -; A type declaration consists of the `type` keyword -; followed by an identifier and a type that the alias -; would refer to. +; A type alias declaration defines an identifier to stand for a type. type-alias-declaration = %s"type" identifier "=" type ";" From 2426fada7dd997188a96a2cc9a18f0de18a6c1ea Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Thu, 2 Sep 2021 22:05:44 -0700 Subject: [PATCH 08/28] [ABNF] Re-generate markdown. --- grammar/README.md | 96 ++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/grammar/README.md b/grammar/README.md index 7ed850b034..5603ab524c 100644 --- a/grammar/README.md +++ b/grammar/README.md @@ -476,7 +476,7 @@ Line terminators form whitespace, along with spaces and horizontal tabs. whitespace = space / horizontal-tab / newline ``` -Go to: _[horizontal-tab](#user-content-horizontal-tab), [newline](#user-content-newline), [space](#user-content-space)_; +Go to: _[newline](#user-content-newline), [space](#user-content-space), [horizontal-tab](#user-content-horizontal-tab)_; There are two kinds of comments in Leo, as in other languages. @@ -511,7 +511,7 @@ rest-of-block-comment = "*" rest-of-block-comment-after-star / not-star rest-of-block-comment ``` -Go to: _[not-star](#user-content-not-star), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [rest-of-block-comment](#user-content-rest-of-block-comment)_; +Go to: _[rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star](#user-content-not-star), [rest-of-block-comment](#user-content-rest-of-block-comment)_; @@ -521,7 +521,7 @@ rest-of-block-comment-after-star = "/" / not-star-or-slash rest-of-block-comment ``` -Go to: _[rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment)_; +Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star-or-slash](#user-content-not-star-or-slash)_; @@ -774,7 +774,7 @@ character-literal-element = not-single-quote-or-backslash / unicode-character-escape ``` -Go to: _[unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape)_; +Go to: _[ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape)_; @@ -829,7 +829,7 @@ simple-character-escape = single-quote-escape / null-character-escape ``` -Go to: _[line-feed-escape](#user-content-line-feed-escape), [single-quote-escape](#user-content-single-quote-escape), [double-quote-escape](#user-content-double-quote-escape), [carriage-return-escape](#user-content-carriage-return-escape), [null-character-escape](#user-content-null-character-escape), [horizontal-tab-escape](#user-content-horizontal-tab-escape), [backslash-escape](#user-content-backslash-escape)_; +Go to: _[horizontal-tab-escape](#user-content-horizontal-tab-escape), [null-character-escape](#user-content-null-character-escape), [carriage-return-escape](#user-content-carriage-return-escape), [backslash-escape](#user-content-backslash-escape), [single-quote-escape](#user-content-single-quote-escape), [double-quote-escape](#user-content-double-quote-escape), [line-feed-escape](#user-content-line-feed-escape)_; @@ -837,7 +837,7 @@ Go to: _[line-feed-escape](#user-content-line-feed-escape), [single-quote-escape ascii-character-escape = %s"\x" octal-digit hexadecimal-digit ``` -Go to: _[octal-digit](#user-content-octal-digit), [hexadecimal-digit](#user-content-hexadecimal-digit)_; +Go to: _[hexadecimal-digit](#user-content-hexadecimal-digit), [octal-digit](#user-content-octal-digit)_; @@ -865,7 +865,7 @@ string-literal-element = not-double-quote-or-backslash / unicode-character-escape ``` -Go to: _[unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape), [not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape)_; +Go to: _[ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape), [not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash)_; The ones above are all the atomic literals @@ -885,7 +885,7 @@ atomic-literal = untyped-literal / string-literal ``` -Go to: _[field-literal](#user-content-field-literal), [boolean-literal](#user-content-boolean-literal), [address-literal](#user-content-address-literal), [signed-literal](#user-content-signed-literal), [character-literal](#user-content-character-literal), [string-literal](#user-content-string-literal), [unsigned-literal](#user-content-unsigned-literal), [product-group-literal](#user-content-product-group-literal), [untyped-literal](#user-content-untyped-literal)_; +Go to: _[boolean-literal](#user-content-boolean-literal), [character-literal](#user-content-character-literal), [string-literal](#user-content-string-literal), [address-literal](#user-content-address-literal), [unsigned-literal](#user-content-unsigned-literal), [signed-literal](#user-content-signed-literal), [untyped-literal](#user-content-untyped-literal), [field-literal](#user-content-field-literal), [product-group-literal](#user-content-product-group-literal)_; After defining the (mostly) alphanumeric tokens above, @@ -929,7 +929,7 @@ token = keyword / symbol ``` -Go to: _[identifier](#user-content-identifier), [atomic-literal](#user-content-atomic-literal), [package-name](#user-content-package-name), [annotation-name](#user-content-annotation-name), [symbol](#user-content-symbol), [keyword](#user-content-keyword)_; +Go to: _[package-name](#user-content-package-name), [annotation-name](#user-content-annotation-name), [keyword](#user-content-keyword), [identifier](#user-content-identifier), [symbol](#user-content-symbol), [atomic-literal](#user-content-atomic-literal)_; Tokens, comments, and whitespace are lexemes, i.e. lexical units. @@ -975,7 +975,7 @@ signed-type = %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128" integer-type = unsigned-type / signed-type ``` -Go to: _[unsigned-type](#user-content-unsigned-type), [signed-type](#user-content-signed-type)_; +Go to: _[signed-type](#user-content-signed-type), [unsigned-type](#user-content-unsigned-type)_; The integer types, along with the field and group types, @@ -1022,21 +1022,24 @@ character-type = %s"char" scalar-type = boolean-type / arithmetic-type / address-type / character-type ``` -Go to: _[character-type](#user-content-character-type), [boolean-type](#user-content-boolean-type), [address-type](#user-content-address-type), [arithmetic-type](#user-content-arithmetic-type)_; +Go to: _[arithmetic-type](#user-content-arithmetic-type), [boolean-type](#user-content-boolean-type), [character-type](#user-content-character-type), [address-type](#user-content-address-type)_; -Circuit types are denoted by identifiers and the keyword `Self`. -The latter is only allowed inside a circuit definition, -to denote the circuit being defined. +Circuit types are denoted by identifiers and the keyword `Self`; +the latter is only allowed inside a circuit definition, +to denote the circuit type being defined. +Identifiers may also be type aliases; +syntactically (i.e. without a semantic analysis), +they cannot be distinguished from circuit types. ```abnf self-type = %s"Self" ``` - + ```abnf -circuit-or-alias-type = identifier / self-type +identifier-or-self-type = identifier / self-type ``` Go to: _[self-type](#user-content-self-type), [identifier](#user-content-identifier)_; @@ -1062,7 +1065,7 @@ or a tuple of one or more dimensions. array-type = "[" type ";" array-dimensions "]" ``` -Go to: _[type](#user-content-type), [array-dimensions](#user-content-array-dimensions)_; +Go to: _[array-dimensions](#user-content-array-dimensions), [type](#user-content-type)_; @@ -1078,10 +1081,10 @@ Scalar and the remaining types form all the types. ```abnf -type = scalar-type / tuple-type / array-type / circuit-or-alias-type +type = scalar-type / tuple-type / array-type / identifier-or-self-type ``` -Go to: _[circuit-or-alias-type](#user-content-circuit-or-alias-type), [tuple-type](#user-content-tuple-type), [array-type](#user-content-array-type), [scalar-type](#user-content-scalar-type)_; +Go to: _[array-type](#user-content-array-type), [tuple-type](#user-content-tuple-type), [scalar-type](#user-content-scalar-type), [identifier-or-self-type](#user-content-identifier-or-self-type)_; The lexical grammar given earlier defines product group literals. @@ -1117,7 +1120,7 @@ A literal is either an atomic one or an affine group literal. literal = atomic-literal / affine-group-literal ``` -Go to: _[atomic-literal](#user-content-atomic-literal), [affine-group-literal](#user-content-affine-group-literal)_; +Go to: _[affine-group-literal](#user-content-affine-group-literal), [atomic-literal](#user-content-atomic-literal)_; The following rule is not directly referenced in the rules for expressions @@ -1159,7 +1162,7 @@ primary-expression = identifier / circuit-expression ``` -Go to: _[identifier](#user-content-identifier), [literal](#user-content-literal), [expression](#user-content-expression), [tuple-expression](#user-content-tuple-expression), [array-expression](#user-content-array-expression), [circuit-expression](#user-content-circuit-expression)_; +Go to: _[literal](#user-content-literal), [circuit-expression](#user-content-circuit-expression), [identifier](#user-content-identifier), [expression](#user-content-expression), [tuple-expression](#user-content-tuple-expression), [array-expression](#user-content-array-expression)_; Tuple expressions construct tuples. @@ -1220,7 +1223,7 @@ Go to: _[expression](#user-content-expression), [array-dimensions](#user-content array-construction = array-inline-construction / array-repeat-construction ``` -Go to: _[array-repeat-construction](#user-content-array-repeat-construction), [array-inline-construction](#user-content-array-inline-construction)_; +Go to: _[array-inline-construction](#user-content-array-inline-construction), [array-repeat-construction](#user-content-array-repeat-construction)_; @@ -1242,13 +1245,13 @@ so they are syntactically identical but semantically different. ```abnf -circuit-construction = circuit-or-alias-type "{" +circuit-construction = identifier-or-self-type "{" circuit-inline-element *( "," circuit-inline-element ) [ "," ] "}" ``` -Go to: _[circuit-inline-element](#user-content-circuit-inline-element), [circuit-or-alias-type](#user-content-circuit-or-alias-type)_; +Go to: _[identifier-or-self-type](#user-content-identifier-or-self-type), [circuit-inline-element](#user-content-circuit-inline-element)_; @@ -1256,7 +1259,7 @@ Go to: _[circuit-inline-element](#user-content-circuit-inline-element), [circuit circuit-inline-element = identifier ":" expression / identifier ``` -Go to: _[identifier](#user-content-identifier), [expression](#user-content-expression)_; +Go to: _[expression](#user-content-expression), [identifier](#user-content-identifier)_; @@ -1302,12 +1305,12 @@ postfix-expression = primary-expression / postfix-expression "." identifier / identifier function-arguments / postfix-expression "." identifier function-arguments - / circuit-or-alias-type "::" identifier function-arguments + / identifier-or-self-type "::" identifier function-arguments / postfix-expression "[" expression "]" / postfix-expression "[" [expression] ".." [expression] "]" ``` -Go to: _[identifier](#user-content-identifier), [postfix-expression](#user-content-postfix-expression), [function-arguments](#user-content-function-arguments), [circuit-or-alias-type](#user-content-circuit-or-alias-type), [primary-expression](#user-content-primary-expression), [natural](#user-content-natural), [expression](#user-content-expression)_; +Go to: _[identifier](#user-content-identifier), [postfix-expression](#user-content-postfix-expression), [natural](#user-content-natural), [function-arguments](#user-content-function-arguments), [primary-expression](#user-content-primary-expression), [expression](#user-content-expression), [identifier-or-self-type](#user-content-identifier-or-self-type)_; Unary operators have the highest operator precedence. @@ -1335,7 +1338,7 @@ exponential-expression = unary-expression / unary-expression "**" exponential-expression ``` -Go to: _[unary-expression](#user-content-unary-expression), [exponential-expression](#user-content-exponential-expression)_; +Go to: _[exponential-expression](#user-content-exponential-expression), [unary-expression](#user-content-unary-expression)_; Next in precedence come multiplication and division, both left-associative. @@ -1359,7 +1362,7 @@ additive-expression = multiplicative-expression / additive-expression "-" multiplicative-expression ``` -Go to: _[multiplicative-expression](#user-content-multiplicative-expression), [additive-expression](#user-content-additive-expression)_; +Go to: _[additive-expression](#user-content-additive-expression), [multiplicative-expression](#user-content-multiplicative-expression)_; Next in the precedence order are ordering relations. @@ -1398,7 +1401,7 @@ conjunctive-expression = equality-expression / conjunctive-expression "&&" equality-expression ``` -Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [equality-expression](#user-content-equality-expression)_; +Go to: _[equality-expression](#user-content-equality-expression), [conjunctive-expression](#user-content-conjunctive-expression)_; Next come disjunctive expressions, left-associative. @@ -1409,7 +1412,7 @@ disjunctive-expression = conjunctive-expression / disjunctive-expression "||" conjunctive-expression ``` -Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [conjunctive-expression](#user-content-conjunctive-expression)_; +Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [disjunctive-expression](#user-content-disjunctive-expression)_; Finally we have conditional expressions. @@ -1455,7 +1458,7 @@ statement = expression-statement / block ``` -Go to: _[assignment-statement](#user-content-assignment-statement), [expression-statement](#user-content-expression-statement), [loop-statement](#user-content-loop-statement), [return-statement](#user-content-return-statement), [console-statement](#user-content-console-statement), [variable-declaration](#user-content-variable-declaration), [conditional-statement](#user-content-conditional-statement), [block](#user-content-block), [constant-declaration](#user-content-constant-declaration)_; +Go to: _[return-statement](#user-content-return-statement), [constant-declaration](#user-content-constant-declaration), [assignment-statement](#user-content-assignment-statement), [console-statement](#user-content-console-statement), [block](#user-content-block), [conditional-statement](#user-content-conditional-statement), [variable-declaration](#user-content-variable-declaration), [expression-statement](#user-content-expression-statement), [loop-statement](#user-content-loop-statement)_; @@ -1498,7 +1501,7 @@ variable-declaration = %s"let" identifier-or-identifiers [ ":" type ] "=" expression ";" ``` -Go to: _[expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type)_; +Go to: _[identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type), [expression](#user-content-expression)_; @@ -1530,7 +1533,7 @@ Note that blocks are required in all branches, not merely statements. branch = %s"if" expression block ``` -Go to: _[expression](#user-content-expression), [block](#user-content-block)_; +Go to: _[block](#user-content-block), [expression](#user-content-expression)_; @@ -1540,7 +1543,7 @@ conditional-statement = branch / branch %s"else" conditional-statement ``` -Go to: _[branch](#user-content-branch), [block](#user-content-block), [conditional-statement](#user-content-conditional-statement)_; +Go to: _[conditional-statement](#user-content-conditional-statement), [branch](#user-content-branch), [block](#user-content-block)_; A loop statement implicitly defines a loop variable @@ -1549,10 +1552,11 @@ The body is a block. ```abnf -loop-statement = %s"for" identifier %s"in" expression ".." [ "=" ] expression block +loop-statement = %s"for" identifier %s"in" expression ".." [ "=" ] expression + block ``` -Go to: _[block](#user-content-block), [identifier](#user-content-identifier), [expression](#user-content-expression)_; +Go to: _[identifier](#user-content-identifier), [block](#user-content-block), [expression](#user-content-expression)_; An assignment statement is straightforward. @@ -1569,7 +1573,7 @@ assignment-operator = "=" / "+=" / "-=" / "*=" / "/=" / "**=" assignment-statement = expression assignment-operator expression ";" ``` -Go to: _[expression](#user-content-expression), [assignment-operator](#user-content-assignment-operator)_; +Go to: _[assignment-operator](#user-content-assignment-operator), [expression](#user-content-expression)_; Console statements start with the `console` keyword, @@ -1625,7 +1629,7 @@ Go to: _[string-literal](#user-content-string-literal)_; print-call = print-function print-arguments ``` -Go to: _[print-function](#user-content-print-function), [print-arguments](#user-content-print-arguments)_; +Go to: _[print-arguments](#user-content-print-arguments), [print-function](#user-content-print-function)_; An annotation consists of an annotation name (which starts with `@`) @@ -1638,7 +1642,7 @@ annotation = annotation-name [ "(" identifier *( "," identifier ) ")" ] ``` -Go to: _[identifier](#user-content-identifier), [annotation-name](#user-content-annotation-name)_; +Go to: _[annotation-name](#user-content-annotation-name), [identifier](#user-content-identifier)_; A function declaration defines a function. @@ -1655,7 +1659,7 @@ function-declaration = *annotation %s"function" identifier block ``` -Go to: _[block](#user-content-block), [type](#user-content-type), [identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters)_; +Go to: _[type](#user-content-type), [block](#user-content-block), [identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters)_; @@ -1665,7 +1669,7 @@ function-parameters = self-parameter / function-inputs ``` -Go to: _[self-parameter](#user-content-self-parameter), [function-inputs](#user-content-function-inputs)_; +Go to: _[function-inputs](#user-content-function-inputs), [self-parameter](#user-content-self-parameter)_; @@ -1767,12 +1771,10 @@ package-path = "*" / "(" package-path *( "," package-path ) [","] ")" ``` -Go to: _[package-name](#user-content-package-name), [identifier](#user-content-identifier), [package-path](#user-content-package-path)_; +Go to: _[package-path](#user-content-package-path), [package-name](#user-content-package-name), [identifier](#user-content-identifier)_; -A type declaration consists of the `type` keyword -followed by an identifier and a type that the alias -would refer to. +A type alias declaration defines an identifier to stand for a type. ```abnf @@ -1795,7 +1797,7 @@ declaration = import-declaration / type-alias-declaration ``` -Go to: _[import-declaration](#user-content-import-declaration), [circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration), [type-alias-declaration](#user-content-type-alias-declaration), [function-declaration](#user-content-function-declaration)_; +Go to: _[constant-declaration](#user-content-constant-declaration), [type-alias-declaration](#user-content-type-alias-declaration), [circuit-declaration](#user-content-circuit-declaration), [import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration)_; From cfb8720af7fb686eee581b609835761619438c20 Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Mon, 6 Sep 2021 03:53:02 -0700 Subject: [PATCH 09/28] fix scope shadowing, and importing global consts --- asg/src/expression/variable_ref.rs | 5 + asg/src/program/function.rs | 18 ++- asg/src/program/mod.rs | 128 ++++++++++-------- asg/src/scope.rs | 16 +++ asg/src/statement/definition.rs | 16 ++- ast/src/common/global_consts_json.rs | 57 ++++++++ ast/src/common/mod.rs | 2 + ast/src/program.rs | 1 + errors/src/asg/asg_errors.rs | 24 +++- .../alias_circuit_namespace_conflict_fail.leo | 17 +++ ...alias_function_namespace_conflict_fail.leo | 14 ++ ...bal_const_namespace_conflict_fail copy.leo | 14 ++ .../circuit_alias_namespace_conflict_fail.leo | 16 +++ ...rcuit_function_namespace_conflict_fail.leo | 16 +++ ...bal_const_namespace_conflict_fail copy.leo | 16 +++ ...function_alias_namespace_conflict_fail.leo | 14 ++ ...nction_circuit_namespace_conflict_fail.leo | 16 +++ ...bal_const_namespace_conflict_fail copy.leo | 14 ++ .../shadow_global_const_input_fail copy.leo | 13 ++ .../function/shadow_global_const_var_fail.leo | 13 ++ .../function/shadow_parameter_fail.leo | 13 ++ ...al_const_alias_namespace_conflict_fail.leo | 14 ++ ...t_circuit_namespace_conflict_fail copy.leo | 16 +++ ...const_function_namespace_conflict_fail.leo | 14 ++ .../global_consts/global_const_types.leo | 4 +- tests/compiler/global_consts/inputs/dummy.in | 6 + tests/compiler/import_local/import_all.leo | 3 +- .../import_local/local_imports/circuits.leo | 2 + tests/compiler/tuples/basic.leo | 4 +- tests/compiler/tuples/dependent.leo | 4 +- tests/compiler/tuples/destructured.leo | 4 +- ...as_circuit_namespace_conflict_fail.leo.out | 5 + ...s_function_namespace_conflict_fail.leo.out | 5 + ...const_namespace_conflict_fail copy.leo.out | 5 + ...cuit_alias_namespace_conflict_fail.leo.out | 5 + ...t_function_namespace_conflict_fail.leo.out | 5 + ...const_namespace_conflict_fail copy.leo.out | 5 + .../function/duplicate_parameter_fail.leo.out | 2 +- ...tion_alias_namespace_conflict_fail.leo.out | 5 + ...on_circuit_namespace_conflict_fail.leo.out | 5 + ...const_namespace_conflict_fail copy.leo.out | 5 + ...hadow_global_const_input_fail copy.leo.out | 5 + .../shadow_global_const_var_fail.leo.out | 5 + .../function/shadow_parameter_fail.leo.out | 5 + ...onst_alias_namespace_conflict_fail.leo.out | 5 + ...rcuit_namespace_conflict_fail copy.leo.out | 5 + ...t_function_namespace_conflict_fail.leo.out | 5 + .../global_consts/global_const_types.leo.out | 8 +- .../compiler/import_local/import_all.leo.out | 8 +- .../compiler/import_local/import_many.leo.out | 6 +- .../statements/duplicate_variable.leo.out | 2 +- .../compiler/compiler/tuples/basic.leo.out | 8 +- .../compiler/tuples/dependent.leo.out | 8 +- .../compiler/tuples/destructured.leo.out | 8 +- 54 files changed, 540 insertions(+), 99 deletions(-) create mode 100644 ast/src/common/global_consts_json.rs create mode 100644 tests/compiler/aliases/alias_circuit_namespace_conflict_fail.leo create mode 100644 tests/compiler/aliases/alias_function_namespace_conflict_fail.leo create mode 100644 tests/compiler/aliases/alias_global_const_namespace_conflict_fail copy.leo create mode 100644 tests/compiler/circuits/circuit_alias_namespace_conflict_fail.leo create mode 100644 tests/compiler/circuits/circuit_function_namespace_conflict_fail.leo create mode 100644 tests/compiler/circuits/circuit_global_const_namespace_conflict_fail copy.leo create mode 100644 tests/compiler/function/function_alias_namespace_conflict_fail.leo create mode 100644 tests/compiler/function/function_circuit_namespace_conflict_fail.leo create mode 100644 tests/compiler/function/function_global_const_namespace_conflict_fail copy.leo create mode 100644 tests/compiler/function/shadow_global_const_input_fail copy.leo create mode 100644 tests/compiler/function/shadow_global_const_var_fail.leo create mode 100644 tests/compiler/function/shadow_parameter_fail.leo create mode 100644 tests/compiler/global_consts/global_const_alias_namespace_conflict_fail.leo create mode 100644 tests/compiler/global_consts/global_const_circuit_namespace_conflict_fail copy.leo create mode 100644 tests/compiler/global_consts/global_const_function_namespace_conflict_fail.leo create mode 100644 tests/compiler/global_consts/inputs/dummy.in create mode 100644 tests/expectations/compiler/compiler/aliases/alias_circuit_namespace_conflict_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/aliases/alias_function_namespace_conflict_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/aliases/alias_global_const_namespace_conflict_fail copy.leo.out create mode 100644 tests/expectations/compiler/compiler/circuits/circuit_alias_namespace_conflict_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/circuits/circuit_function_namespace_conflict_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/circuits/circuit_global_const_namespace_conflict_fail copy.leo.out create mode 100644 tests/expectations/compiler/compiler/function/function_alias_namespace_conflict_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/function/function_circuit_namespace_conflict_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/function/function_global_const_namespace_conflict_fail copy.leo.out create mode 100644 tests/expectations/compiler/compiler/function/shadow_global_const_input_fail copy.leo.out create mode 100644 tests/expectations/compiler/compiler/function/shadow_global_const_var_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/function/shadow_parameter_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/global_consts/global_const_alias_namespace_conflict_fail.leo.out create mode 100644 tests/expectations/compiler/compiler/global_consts/global_const_circuit_namespace_conflict_fail copy.leo.out create mode 100644 tests/expectations/compiler/compiler/global_consts/global_const_function_namespace_conflict_fail.leo.out diff --git a/asg/src/expression/variable_ref.rs b/asg/src/expression/variable_ref.rs index f16598ac44..bb514fb38d 100644 --- a/asg/src/expression/variable_ref.rs +++ b/asg/src/expression/variable_ref.rs @@ -132,6 +132,11 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> { } else { return Err(AsgError::illegal_input_variable_reference(&value.span).into()); } + } else if let Some(gc) = scope.resolve_global_const(&value.name) { + gc.variables + .iter() + .find(|&&v| v.borrow().name.name == value.name) + .unwrap() } else { match scope.resolve_variable(&value.name) { Some(v) => v, diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index 39ff826f91..26efe0e8de 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -89,6 +89,14 @@ impl<'a> Function<'a> { ) .into()); } + /* else if let Some(_) = scope.resolve_global_const(input_variable.identifier.name.as_ref()) { + // TODO ERROR FOR INPUT BEING NAMED AFTER GLOBAL CONST. + return Err(AsgError::duplicate_function_input_definition( + input_variable.identifier.name.as_ref(), + &input_variable.identifier.span, + ) + .into()); + } */ let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable { id: scope.context.get_id(), @@ -141,9 +149,13 @@ impl<'a> Function<'a> { .insert("self".to_string(), self_variable); } for (name, argument) in self.arguments.iter() { - /* if self.scope.resolve_alias(name).is_some() { - return Err(AsgError::cannot_shadow_name("function input", name, "alias", &argument.get().borrow().name.span).into()); - } */ + if self.scope.resolve_global_const(name).is_some() { + return Err(AsgError::function_input_cannot_shadow_global_const( + name, + &argument.get().borrow().name.span, + ) + .into()); + } self.scope.variables.borrow_mut().insert(name.clone(), argument.get()); } diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index 4cf7b51a88..86a81cdbf9 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -130,6 +130,27 @@ fn resolve_import_package_access( } } +fn check_top_level_namespaces<'a>( + name: &str, + span: &Span, + aliases: &IndexMap>, + functions: &IndexMap>, + circuits: &IndexMap>, + global_consts: &IndexMap>, +) -> Result<()> { + if aliases.contains_key(name) { + Err(AsgError::duplicate_alias_definition(name, span).into()) + } else if global_consts.contains_key(name) { + Err(AsgError::duplicate_global_const_definition(name, span).into()) + } else if functions.contains_key(name) { + Err(AsgError::duplicate_function_definition(name, span).into()) + } else if circuits.contains_key(name) { + Err(AsgError::duplicate_circuit_definition(name, span).into()) + } else { + Ok(()) + } +} + impl<'a> Program<'a> { /// Returns a new Leo program ASG from the given Leo program AST and its imports. /// @@ -242,23 +263,6 @@ impl<'a> Program<'a> { scope.aliases.borrow_mut().insert(name.name.to_string(), asg_alias); } - for (names, global_const) in program.global_consts.iter() { - let gc = <&Statement<'a>>::from_ast(scope, global_const, None)?; - if let Statement::Definition(def) = gc { - let name = names - .iter() - .enumerate() - .map(|(i, name)| { - assert_eq!(name.name, def.variables.get(i).unwrap().borrow().name.name); - name.name.to_string() - }) - .collect::>() - .join(","); - - scope.global_consts.borrow_mut().insert(name, def); - } - } - for (name, circuit) in program.circuits.iter() { assert_eq!(name.name, circuit.circuit_name.name); let asg_circuit = Circuit::init(scope, circuit)?; @@ -281,25 +285,28 @@ impl<'a> Program<'a> { scope.functions.borrow_mut().insert(name.name.to_string(), function); } + for (names, global_const) in program.global_consts.iter() { + let gc = <&Statement<'a>>::from_ast(scope, global_const, None)?; + if let Statement::Definition(def) = gc { + let name = names + .iter() + .enumerate() + .map(|(i, name)| { + assert_eq!(name.name, def.variables.get(i).unwrap().borrow().name.name); + name.name.to_string() + }) + .collect::>() + .join(","); + + scope.global_consts.borrow_mut().insert(name, def); + } + } + // Load concrete definitions. let mut aliases = IndexMap::new(); - let mut global_consts = IndexMap::new(); let mut functions = IndexMap::new(); let mut circuits = IndexMap::new(); - - /* let check_global_shadowing = |name: String, span: &Span| -> Result<()> { - if aliases.contains_key(&name) { - return Err(AsgError::duplicate_alias_definition(name, span).into()); - } else if global_consts.contains_key(&name) { - return Err(AsgError::duplicate_global_const_definition(name, span).into()); - } else if functions.contains_key(&name) { - return Err(AsgError::duplicate_function_definition(name, span).into()); - } else if circuits.contains_key(&name) { - return Err(AsgError::duplicate_circuit_definition(name, span).into()); - } else { - Ok(()) - } - }; */ + let mut global_consts = IndexMap::new(); for (name, alias) in program.aliases.iter() { assert_eq!(name.name, alias.name.name); @@ -307,28 +314,11 @@ impl<'a> Program<'a> { let name = name.name.to_string(); - if aliases.contains_key(&name) { - return Err(AsgError::duplicate_alias_definition(name, &alias.span).into()); - } + check_top_level_namespaces(&name, &alias.span, &aliases, &functions, &circuits, &global_consts)?; aliases.insert(name, asg_alias); } - for (names, global_const) in program.global_consts.iter() { - for (identifier, variable) in names.iter().zip(global_const.variable_names.iter()) { - assert_eq!(identifier.name, variable.identifier.name); - - let name = identifier.name.to_string(); - let asg_global_const = *scope.global_consts.borrow().get(&name).unwrap(); - - if global_consts.contains_key(&name) { - return Err(AsgError::duplicate_global_const_definition(name, &global_const.span).into()); - } - - global_consts.insert(name.clone(), asg_global_const); - } - } - for (name, function) in program.functions.iter() { assert_eq!(name.name, function.identifier.name); let asg_function = *scope.functions.borrow().get(name.name.as_ref()).unwrap(); @@ -337,9 +327,7 @@ impl<'a> Program<'a> { let name = name.name.to_string(); - if functions.contains_key(&name) { - return Err(AsgError::duplicate_function_definition(name, &function.span).into()); - } + check_top_level_namespaces(&name, &function.span, &aliases, &functions, &circuits, &global_consts)?; functions.insert(name, asg_function); } @@ -350,7 +338,39 @@ impl<'a> Program<'a> { asg_circuit.fill_from_ast(circuit)?; - circuits.insert(name.name.to_string(), asg_circuit); + let name = name.name.to_string(); + + check_top_level_namespaces( + &name, + &circuit.circuit_name.span, + &aliases, + &functions, + &circuits, + &global_consts, + )?; + + circuits.insert(name, asg_circuit); + } + + for (names, global_const) in program.global_consts.iter() { + let name = names + .iter() + .map(|name| name.name.to_string()) + .collect::>() + .join(","); + + let asg_global_const = *scope.global_consts.borrow().get(&name).unwrap(); + + check_top_level_namespaces( + &name, + &global_const.span, + &aliases, + &functions, + &circuits, + &global_consts, + )?; + + global_consts.insert(name.clone(), asg_global_const); } Ok(Program { diff --git a/asg/src/scope.rs b/asg/src/scope.rs index 6a35ad2672..84fa31dcee 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -151,6 +151,22 @@ impl<'a> Scope<'a> { } } + /// + /// Returns a reference to the global const definition statement corresponding to the name. + /// + /// If the current scope did not have this name present, then the parent scope is checked. + /// If there is no parent scope, then `None` is returned. + /// + pub fn resolve_global_const(&self, name: &str) -> Option<&'a DefinitionStatement<'a>> { + if let Some(resolved) = self.global_consts.borrow().get(name) { + Some(*resolved) + } else if let Some(resolved) = self.parent_scope.get() { + resolved.resolve_global_const(name) + } else { + None + } + } + /// /// Returns a new scope given a parent scope. /// diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index 6f658e048a..a896a9cb3a 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -110,10 +110,18 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { } for (variable, type_) in statement.variable_names.iter().zip(output_types.into_iter()) { - /* let name = variable.identifier.name.as_ref(); - if scope.resolve_alias(name).is_some() { - return Err(AsgError::cannot_shadow_name("function input", name, "alias", &variable.identifier.span).into()); - } */ + let name = variable.identifier.name.as_ref(); + if scope.resolve_global_const(name).is_some() { + return Err( + AsgError::function_variable_cannot_shadow_global_const(name, &variable.identifier.span).into(), + ); + } else if scope.resolve_variable(name).is_some() { + return Err(AsgError::function_variable_cannot_shadow_other_function_variable( + name, + &variable.identifier.span, + ) + .into()); + } variables.push(&*scope.context.alloc_variable(RefCell::new(InnerVariable { id: scope.context.get_id(), diff --git a/ast/src/common/global_consts_json.rs b/ast/src/common/global_consts_json.rs new file mode 100644 index 0000000000..68d0eb62a3 --- /dev/null +++ b/ast/src/common/global_consts_json.rs @@ -0,0 +1,57 @@ +// Copyright (C) 2019-2021 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 . + +use crate::{DefinitionStatement, Identifier}; + +use indexmap::IndexMap; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[allow(clippy::ptr_arg)] +pub fn serialize( + global_consts: &IndexMap, DefinitionStatement>, + serializer: S, +) -> Result { + let joined: IndexMap = global_consts + .into_iter() + .map(|(idents, program)| { + ( + idents.iter().map(|i| i.name.to_string()).collect::>().join(","), + program.clone(), + ) + }) + .collect(); + + joined.serialize(serializer) +} + +pub fn deserialize<'de, D: Deserializer<'de>>( + deserializer: D, +) -> Result, DefinitionStatement>, D::Error> { + Ok(IndexMap::::deserialize(deserializer)? + .into_iter() + .map(|(name, program)| { + ( + name.split(',') + .map(|ident_name| Identifier { + name: ident_name.into(), + span: Default::default(), + }) + .collect::>(), + program, + ) + }) + .collect()) +} diff --git a/ast/src/common/mod.rs b/ast/src/common/mod.rs index db9e9a8934..dc05c0de0f 100644 --- a/ast/src/common/mod.rs +++ b/ast/src/common/mod.rs @@ -20,6 +20,8 @@ pub use array_dimensions::*; pub mod const_self_keyword; pub use const_self_keyword::*; +pub mod global_consts_json; + pub mod identifier; pub use identifier::*; diff --git a/ast/src/program.rs b/ast/src/program.rs index 3c42d14058..aee5660bd9 100644 --- a/ast/src/program.rs +++ b/ast/src/program.rs @@ -33,6 +33,7 @@ pub struct Program { pub imports: IndexMap, Program>, pub aliases: IndexMap, pub circuits: IndexMap, + #[serde(with = "crate::common::global_consts_json")] pub global_consts: IndexMap, DefinitionStatement>, pub functions: IndexMap, } diff --git a/errors/src/asg/asg_errors.rs b/errors/src/asg/asg_errors.rs index da31092e39..6524b6ab95 100644 --- a/errors/src/asg/asg_errors.rs +++ b/errors/src/asg/asg_errors.rs @@ -444,11 +444,27 @@ create_errors!( help: None, } - /// For when a named identifier is being shadowed. + /// For when a function input shadows a global const. @formatted - cannot_shadow_name { - args: (type_: impl Display, name: impl Display, location: impl Display), - msg: format!("a {} cannot be named `{}` as a {} with that name already exists in this scope", type_, name, location), + function_input_cannot_shadow_global_const { + args: (name: impl Display), + msg: format!("a function input cannot be named `{}` as a global const with that name already exists in this scope", name), + help: None, + } + + /// For when a variable definition shadows a global const. + @formatted + function_variable_cannot_shadow_global_const { + args: (name: impl Display), + msg: format!("a variable cannot be named `{}` as a global const with that name already exists in this scope", name), + help: None, + } + + /// For when a variable definition shadows a function input. + @formatted + function_variable_cannot_shadow_other_function_variable { + args: (name: impl Display), + msg: format!("a variable cannot be named `{}` as a function input or variable with that name already exists in this scope", name), help: None, } ); diff --git a/tests/compiler/aliases/alias_circuit_namespace_conflict_fail.leo b/tests/compiler/aliases/alias_circuit_namespace_conflict_fail.leo new file mode 100644 index 0000000000..f2396a5878 --- /dev/null +++ b/tests/compiler/aliases/alias_circuit_namespace_conflict_fail.leo @@ -0,0 +1,17 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + + +type Int = u32; + +circuit Int { + x: u8; +} + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/aliases/alias_function_namespace_conflict_fail.leo b/tests/compiler/aliases/alias_function_namespace_conflict_fail.leo new file mode 100644 index 0000000000..272d53e519 --- /dev/null +++ b/tests/compiler/aliases/alias_function_namespace_conflict_fail.leo @@ -0,0 +1,14 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +type int = u32; + +function int() {} + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/aliases/alias_global_const_namespace_conflict_fail copy.leo b/tests/compiler/aliases/alias_global_const_namespace_conflict_fail copy.leo new file mode 100644 index 0000000000..6a12761425 --- /dev/null +++ b/tests/compiler/aliases/alias_global_const_namespace_conflict_fail copy.leo @@ -0,0 +1,14 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +type int = u32; + +const int = 8u8; + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/circuits/circuit_alias_namespace_conflict_fail.leo b/tests/compiler/circuits/circuit_alias_namespace_conflict_fail.leo new file mode 100644 index 0000000000..6a16938b37 --- /dev/null +++ b/tests/compiler/circuits/circuit_alias_namespace_conflict_fail.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +circuit Int { + x: u8; +} + +type Int = u32; + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/circuits/circuit_function_namespace_conflict_fail.leo b/tests/compiler/circuits/circuit_function_namespace_conflict_fail.leo new file mode 100644 index 0000000000..5ced98b02d --- /dev/null +++ b/tests/compiler/circuits/circuit_function_namespace_conflict_fail.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +circuit Foo { + x: u8; +} + +function Foo() {} + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/circuits/circuit_global_const_namespace_conflict_fail copy.leo b/tests/compiler/circuits/circuit_global_const_namespace_conflict_fail copy.leo new file mode 100644 index 0000000000..53e363a137 --- /dev/null +++ b/tests/compiler/circuits/circuit_global_const_namespace_conflict_fail copy.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +circuit Foo { + x: u8; +} + +const Foo = 8u8; + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/function/function_alias_namespace_conflict_fail.leo b/tests/compiler/function/function_alias_namespace_conflict_fail.leo new file mode 100644 index 0000000000..b8cad08251 --- /dev/null +++ b/tests/compiler/function/function_alias_namespace_conflict_fail.leo @@ -0,0 +1,14 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +function int() {} + +type int = u32; + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/function/function_circuit_namespace_conflict_fail.leo b/tests/compiler/function/function_circuit_namespace_conflict_fail.leo new file mode 100644 index 0000000000..3ddbb6c8c2 --- /dev/null +++ b/tests/compiler/function/function_circuit_namespace_conflict_fail.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +function Foo() {} + +circuit Foo { + x: u8; +} + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/function/function_global_const_namespace_conflict_fail copy.leo b/tests/compiler/function/function_global_const_namespace_conflict_fail copy.leo new file mode 100644 index 0000000000..1f3fd2880f --- /dev/null +++ b/tests/compiler/function/function_global_const_namespace_conflict_fail copy.leo @@ -0,0 +1,14 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +function foo() {} + +const foo = 8u8; + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/function/shadow_global_const_input_fail copy.leo b/tests/compiler/function/shadow_global_const_input_fail copy.leo new file mode 100644 index 0000000000..c07c729b2a --- /dev/null +++ b/tests/compiler/function/shadow_global_const_input_fail copy.leo @@ -0,0 +1,13 @@ +/* +namespace: Compile +expectation: Fail +input_file: input/dummy.in +*/ + +const hi = 1u32; + +function tester(hi: u8) {} + +function main (y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/function/shadow_global_const_var_fail.leo b/tests/compiler/function/shadow_global_const_var_fail.leo new file mode 100644 index 0000000000..e2d340f2e8 --- /dev/null +++ b/tests/compiler/function/shadow_global_const_var_fail.leo @@ -0,0 +1,13 @@ +/* +namespace: Compile +expectation: Fail +input_file: input/dummy.in +*/ + +function tester(hi: u8) { + const hi = 1u8; +} + +function main (y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/function/shadow_parameter_fail.leo b/tests/compiler/function/shadow_parameter_fail.leo new file mode 100644 index 0000000000..3d44753da1 --- /dev/null +++ b/tests/compiler/function/shadow_parameter_fail.leo @@ -0,0 +1,13 @@ +/* +namespace: Compile +expectation: Fail +input_file: input/dummy.in +*/ + +function tester(hi: u8) { + const hi = 2u8; +} + +function main (y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/global_consts/global_const_alias_namespace_conflict_fail.leo b/tests/compiler/global_consts/global_const_alias_namespace_conflict_fail.leo new file mode 100644 index 0000000000..e76d422fe6 --- /dev/null +++ b/tests/compiler/global_consts/global_const_alias_namespace_conflict_fail.leo @@ -0,0 +1,14 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +const int = 8u8; + +type int = u32; + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/global_consts/global_const_circuit_namespace_conflict_fail copy.leo b/tests/compiler/global_consts/global_const_circuit_namespace_conflict_fail copy.leo new file mode 100644 index 0000000000..855aacc400 --- /dev/null +++ b/tests/compiler/global_consts/global_const_circuit_namespace_conflict_fail copy.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +const Foo = 8u8; + +circuit Foo { + x: u8; +} + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/global_consts/global_const_function_namespace_conflict_fail.leo b/tests/compiler/global_consts/global_const_function_namespace_conflict_fail.leo new file mode 100644 index 0000000000..81e3fa489f --- /dev/null +++ b/tests/compiler/global_consts/global_const_function_namespace_conflict_fail.leo @@ -0,0 +1,14 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/dummy.in +*/ + +const two = 2u8; + +function two() {} + +function main(y: bool) -> bool { + return y; +} \ No newline at end of file diff --git a/tests/compiler/global_consts/global_const_types.leo b/tests/compiler/global_consts/global_const_types.leo index 8550672aeb..db73b8cc04 100644 --- a/tests/compiler/global_consts/global_const_types.leo +++ b/tests/compiler/global_consts/global_const_types.leo @@ -19,7 +19,7 @@ const complex_group = (_, 1)group; const field_test: field = 2; const use_another_const = basic + 1; const foo = Foo { width: 10, height: 20 }; -const uno = uno(); +const one = uno(); const character = 'a'; const hello = "Hello, World!"; @@ -49,7 +49,7 @@ function main(a: u32) -> bool { && use_another_const == 9u32 // use another const test && foo.width == 10u32 // circuit test && foo.height == 20u32 - && uno == 1u32 // function test + && one == 1u32 // function test && character == 'a' // char test && hello == "Hello, World!"; } diff --git a/tests/compiler/global_consts/inputs/dummy.in b/tests/compiler/global_consts/inputs/dummy.in new file mode 100644 index 0000000000..d63f21e6b5 --- /dev/null +++ b/tests/compiler/global_consts/inputs/dummy.in @@ -0,0 +1,6 @@ +[main] +y: bool = true; +x: bool = false; + +[registers] +r0: bool = true; diff --git a/tests/compiler/import_local/import_all.leo b/tests/compiler/import_local/import_all.leo index 6d81a15dab..c03261c640 100644 --- a/tests/compiler/import_local/import_all.leo +++ b/tests/compiler/import_local/import_all.leo @@ -11,6 +11,7 @@ function main(y: bool) -> bool { const a = Point { x: 1u32, y: 0u32 }; const hello_alias: char5 = "hello"; const hello = "hello"; + const eight = 8u8; - return( (foo() == 1u32) && hello_alias == hello) == y; + return( (foo() == 1u32) && hello_alias == hello && EIGHT == eight) == y; } diff --git a/tests/compiler/import_local/local_imports/circuits.leo b/tests/compiler/import_local/local_imports/circuits.leo index fd589fd865..32451e9ce7 100644 --- a/tests/compiler/import_local/local_imports/circuits.leo +++ b/tests/compiler/import_local/local_imports/circuits.leo @@ -8,3 +8,5 @@ function foo() -> u32 { } type char5 = [char; 5]; + +const EIGHT = 8u8; \ No newline at end of file diff --git a/tests/compiler/tuples/basic.leo b/tests/compiler/tuples/basic.leo index 3a9b0e414c..51dbfaa7c2 100644 --- a/tests/compiler/tuples/basic.leo +++ b/tests/compiler/tuples/basic.leo @@ -5,7 +5,7 @@ input_file: inputs/true_true.in */ function main(a: (bool, bool)) -> (bool, bool) { - const a = (true, false); + const b = (true, false); - return (a.0, a.1); + return (b.0, b.1); } \ No newline at end of file diff --git a/tests/compiler/tuples/dependent.leo b/tests/compiler/tuples/dependent.leo index 3e46824bf5..7ba2b59dd1 100644 --- a/tests/compiler/tuples/dependent.leo +++ b/tests/compiler/tuples/dependent.leo @@ -5,7 +5,7 @@ input_file: inputs/true_true.in */ function main(a: (bool, bool)) -> (bool, bool) { - let a = (a.0 ? false : true, a.1 ? false : true); + let b = (a.0 ? false : true, a.1 ? false : true); - return (a.0, a.1); + return (b.0, b.1); } diff --git a/tests/compiler/tuples/destructured.leo b/tests/compiler/tuples/destructured.leo index d9f1c0def8..8810a989d5 100644 --- a/tests/compiler/tuples/destructured.leo +++ b/tests/compiler/tuples/destructured.leo @@ -5,7 +5,7 @@ input_file: inputs/true_true.in */ function main(a: (bool, bool)) -> (bool, bool) { - let (a, b) = (a.0 ? false : true, a.1 ? false : true); + let (b, c) = (a.0 ? false : true, a.1 ? false : true); - return (b, a); + return (c, b); } diff --git a/tests/expectations/compiler/compiler/aliases/alias_circuit_namespace_conflict_fail.leo.out b/tests/expectations/compiler/compiler/aliases/alias_circuit_namespace_conflict_fail.leo.out new file mode 100644 index 0000000000..deffee764c --- /dev/null +++ b/tests/expectations/compiler/compiler/aliases/alias_circuit_namespace_conflict_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373044]: a alias named \"Int\" already exists in this scope\n --> compiler-test:6:9\n |\n 6 | circuit Int {\n | ^^^" diff --git a/tests/expectations/compiler/compiler/aliases/alias_function_namespace_conflict_fail.leo.out b/tests/expectations/compiler/compiler/aliases/alias_function_namespace_conflict_fail.leo.out new file mode 100644 index 0000000000..71b0ec6d18 --- /dev/null +++ b/tests/expectations/compiler/compiler/aliases/alias_function_namespace_conflict_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373044]: a alias named \"int\" already exists in this scope\n --> compiler-test:5:1\n |\n 5 | function int() {}\n | ^^^^^^^^^^^^^^^^^" diff --git a/tests/expectations/compiler/compiler/aliases/alias_global_const_namespace_conflict_fail copy.leo.out b/tests/expectations/compiler/compiler/aliases/alias_global_const_namespace_conflict_fail copy.leo.out new file mode 100644 index 0000000000..162a0f02ed --- /dev/null +++ b/tests/expectations/compiler/compiler/aliases/alias_global_const_namespace_conflict_fail copy.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373044]: a alias named \"int\" already exists in this scope\n --> compiler-test:5:1\n |\n 5 | const int = 8u8;\n | ^^^^^^^^^^^^^^^" diff --git a/tests/expectations/compiler/compiler/circuits/circuit_alias_namespace_conflict_fail.leo.out b/tests/expectations/compiler/compiler/circuits/circuit_alias_namespace_conflict_fail.leo.out new file mode 100644 index 0000000000..017fecf202 --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/circuit_alias_namespace_conflict_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373044]: a alias named \"Int\" already exists in this scope\n --> compiler-test:3:9\n |\n 3 | circuit Int {\n | ^^^" diff --git a/tests/expectations/compiler/compiler/circuits/circuit_function_namespace_conflict_fail.leo.out b/tests/expectations/compiler/compiler/circuits/circuit_function_namespace_conflict_fail.leo.out new file mode 100644 index 0000000000..bbeac5be1c --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/circuit_function_namespace_conflict_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373015]: a function named \"Foo\" already exists in this scope\n --> compiler-test:3:9\n |\n 3 | circuit Foo {\n | ^^^" diff --git a/tests/expectations/compiler/compiler/circuits/circuit_global_const_namespace_conflict_fail copy.leo.out b/tests/expectations/compiler/compiler/circuits/circuit_global_const_namespace_conflict_fail copy.leo.out new file mode 100644 index 0000000000..f00773408c --- /dev/null +++ b/tests/expectations/compiler/compiler/circuits/circuit_global_const_namespace_conflict_fail copy.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373045]: a circuit named \"Foo\" already exists in this scope\n --> compiler-test:7:1\n |\n 7 | const Foo = 8u8;\n | ^^^^^^^^^^^^^^^" diff --git a/tests/expectations/compiler/compiler/function/duplicate_parameter_fail.leo.out b/tests/expectations/compiler/compiler/function/duplicate_parameter_fail.leo.out index 7edb1e7d52..66b341780f 100644 --- a/tests/expectations/compiler/compiler/function/duplicate_parameter_fail.leo.out +++ b/tests/expectations/compiler/compiler/function/duplicate_parameter_fail.leo.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [EASG0373045]: a function input named \"a\" already exists in this scope\n --> compiler-test:3:23\n |\n 3 | function main(a: u32, a: u32) {\n | ^" + - "Error [EASG0373046]: a function input named \"a\" already exists in this scope\n --> compiler-test:3:23\n |\n 3 | function main(a: u32, a: u32) {\n | ^" diff --git a/tests/expectations/compiler/compiler/function/function_alias_namespace_conflict_fail.leo.out b/tests/expectations/compiler/compiler/function/function_alias_namespace_conflict_fail.leo.out new file mode 100644 index 0000000000..3362cb13e7 --- /dev/null +++ b/tests/expectations/compiler/compiler/function/function_alias_namespace_conflict_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373044]: a alias named \"int\" already exists in this scope\n --> compiler-test:3:1\n |\n 3 | function int() {}\n | ^^^^^^^^^^^^^^^^^" diff --git a/tests/expectations/compiler/compiler/function/function_circuit_namespace_conflict_fail.leo.out b/tests/expectations/compiler/compiler/function/function_circuit_namespace_conflict_fail.leo.out new file mode 100644 index 0000000000..d1aaa77036 --- /dev/null +++ b/tests/expectations/compiler/compiler/function/function_circuit_namespace_conflict_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373015]: a function named \"Foo\" already exists in this scope\n --> compiler-test:5:9\n |\n 5 | circuit Foo {\n | ^^^" diff --git a/tests/expectations/compiler/compiler/function/function_global_const_namespace_conflict_fail copy.leo.out b/tests/expectations/compiler/compiler/function/function_global_const_namespace_conflict_fail copy.leo.out new file mode 100644 index 0000000000..4f5d7221b3 --- /dev/null +++ b/tests/expectations/compiler/compiler/function/function_global_const_namespace_conflict_fail copy.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373015]: a function named \"foo\" already exists in this scope\n --> compiler-test:5:1\n |\n 5 | const foo = 8u8;\n | ^^^^^^^^^^^^^^^" diff --git a/tests/expectations/compiler/compiler/function/shadow_global_const_input_fail copy.leo.out b/tests/expectations/compiler/compiler/function/shadow_global_const_input_fail copy.leo.out new file mode 100644 index 0000000000..1a9a12a532 --- /dev/null +++ b/tests/expectations/compiler/compiler/function/shadow_global_const_input_fail copy.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373048]: a function input cannot be named `hi` as a global const with that name already exists in this scope\n --> compiler-test:5:17\n |\n 5 | function tester(hi: u8) {}\n | ^^" diff --git a/tests/expectations/compiler/compiler/function/shadow_global_const_var_fail.leo.out b/tests/expectations/compiler/compiler/function/shadow_global_const_var_fail.leo.out new file mode 100644 index 0000000000..dfb5575007 --- /dev/null +++ b/tests/expectations/compiler/compiler/function/shadow_global_const_var_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373050]: a variable cannot be named `hi` as a function input or variable with that name already exists in this scope\n --> compiler-test:4:11\n |\n 4 | const hi = 1u8;\n | ^^" diff --git a/tests/expectations/compiler/compiler/function/shadow_parameter_fail.leo.out b/tests/expectations/compiler/compiler/function/shadow_parameter_fail.leo.out new file mode 100644 index 0000000000..1640957ef3 --- /dev/null +++ b/tests/expectations/compiler/compiler/function/shadow_parameter_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373050]: a variable cannot be named `hi` as a function input or variable with that name already exists in this scope\n --> compiler-test:4:11\n |\n 4 | const hi = 2u8;\n | ^^" diff --git a/tests/expectations/compiler/compiler/global_consts/global_const_alias_namespace_conflict_fail.leo.out b/tests/expectations/compiler/compiler/global_consts/global_const_alias_namespace_conflict_fail.leo.out new file mode 100644 index 0000000000..431afecbd2 --- /dev/null +++ b/tests/expectations/compiler/compiler/global_consts/global_const_alias_namespace_conflict_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373044]: a alias named \"int\" already exists in this scope\n --> compiler-test:3:1\n |\n 3 | const int = 8u8;\n | ^^^^^^^^^^^^^^^" diff --git a/tests/expectations/compiler/compiler/global_consts/global_const_circuit_namespace_conflict_fail copy.leo.out b/tests/expectations/compiler/compiler/global_consts/global_const_circuit_namespace_conflict_fail copy.leo.out new file mode 100644 index 0000000000..cc06fa82d5 --- /dev/null +++ b/tests/expectations/compiler/compiler/global_consts/global_const_circuit_namespace_conflict_fail copy.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373045]: a circuit named \"Foo\" already exists in this scope\n --> compiler-test:3:1\n |\n 3 | const Foo = 8u8;\n | ^^^^^^^^^^^^^^^" diff --git a/tests/expectations/compiler/compiler/global_consts/global_const_function_namespace_conflict_fail.leo.out b/tests/expectations/compiler/compiler/global_consts/global_const_function_namespace_conflict_fail.leo.out new file mode 100644 index 0000000000..0fbb9c150a --- /dev/null +++ b/tests/expectations/compiler/compiler/global_consts/global_const_function_namespace_conflict_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EASG0373015]: a function named \"two\" already exists in this scope\n --> compiler-test:3:1\n |\n 3 | const two = 2u8;\n | ^^^^^^^^^^^^^^^" diff --git a/tests/expectations/compiler/compiler/global_consts/global_const_types.leo.out b/tests/expectations/compiler/compiler/global_consts/global_const_types.leo.out index 1f8e049ff5..67962787bd 100644 --- a/tests/expectations/compiler/compiler/global_consts/global_const_types.leo.out +++ b/tests/expectations/compiler/compiler/global_consts/global_const_types.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "false" - initial_ast: b4e5073c07791c4726b69f3e60ec66ccebefb7a3811f4a3576fc4042f8c80114 - imports_resolved_ast: b4e5073c07791c4726b69f3e60ec66ccebefb7a3811f4a3576fc4042f8c80114 - canonicalized_ast: 03a4e0ffc6deea9c6500a9d91eb683a780e8f5961801bea1aab26c14e4543325 - type_inferenced_ast: 66d0a55ff2ab6931d5806dcbb2ff23f9dbc41a883f19a45af8a41d3be84e136d + initial_ast: d53a0267c4afe271c6488aeda9910433e3a947d96530ea1286eba511e6e8f17e + imports_resolved_ast: d53a0267c4afe271c6488aeda9910433e3a947d96530ea1286eba511e6e8f17e + canonicalized_ast: 86bc6722c866a18e2b4d022e67c82dfa0f20f1b4d86d2869f6267010ef45c0c6 + type_inferenced_ast: 57202f3b3a4808ce13cce466b6e7a6b153c1950e6af6fcbe68bf04a4d95476f1 diff --git a/tests/expectations/compiler/compiler/import_local/import_all.leo.out b/tests/expectations/compiler/compiler/import_local/import_all.leo.out index 9e299f3691..4361f3ee2e 100644 --- a/tests/expectations/compiler/compiler/import_local/import_all.leo.out +++ b/tests/expectations/compiler/compiler/import_local/import_all.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: 6e689aa459b9ea2fa0c18c9dc0f2512db9d430f5c7101cb3104a275711d60210 - imports_resolved_ast: c4260b58a631ee77b0492ba1354182b2c95d260dcf01a62e2a0797eb5f268478 - canonicalized_ast: 7e2eaf52ce5c79242b44357609ab667df411190bf7a11228d240c314f0ce0502 - type_inferenced_ast: be897b5b17a946c2595afcc8a802df5fa4e013ba3acb4159a0123d7cf1941544 + initial_ast: d2d8f4a8a59423b81f6f31d335762b57cf771ade0241acc6d61614d1fabfc618 + imports_resolved_ast: 95c9a6a9d333cdaff558735babd0d9a200d29fe752cb3a80288a69abecdc872d + canonicalized_ast: a2ef4029e1d95374b6b7f6b9e601acb6e4ee7481f7387fd0724149c548e46399 + type_inferenced_ast: b7d5149d5beae517ba02c0af1a23183ec28e3f763252be89baed9ba96a3e2786 diff --git a/tests/expectations/compiler/compiler/import_local/import_many.leo.out b/tests/expectations/compiler/compiler/import_local/import_many.leo.out index 551b30394a..e7cebd9f5c 100644 --- a/tests/expectations/compiler/compiler/import_local/import_many.leo.out +++ b/tests/expectations/compiler/compiler/import_local/import_many.leo.out @@ -17,6 +17,6 @@ outputs: type: bool value: "true" initial_ast: ae6826642faa492e34507695dbd11e5b44c319aecb0b1e78b29ce03ae446d907 - imports_resolved_ast: e08b138c63ede9de6e090e6b7fbcfbbc27a1ae49b032a6cffcafaa8f76410839 - canonicalized_ast: e08b138c63ede9de6e090e6b7fbcfbbc27a1ae49b032a6cffcafaa8f76410839 - type_inferenced_ast: b311680f4429cc16661f774b0547936be148a3dd9f478013adefe575629b88fa + imports_resolved_ast: 718ca8903a55a3b9208aea6c80d8969a5413a0499266c887b68dfea620f689e9 + canonicalized_ast: 718ca8903a55a3b9208aea6c80d8969a5413a0499266c887b68dfea620f689e9 + type_inferenced_ast: 9470aa103176806fd2d40b69224ec249e086fd5c70d56ebe22922e6cf39156e5 diff --git a/tests/expectations/compiler/compiler/statements/duplicate_variable.leo.out b/tests/expectations/compiler/compiler/statements/duplicate_variable.leo.out index e975210ed2..e0930ed9aa 100644 --- a/tests/expectations/compiler/compiler/statements/duplicate_variable.leo.out +++ b/tests/expectations/compiler/compiler/statements/duplicate_variable.leo.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [EASG0373016]: a variable named \"x\" already exists in this scope\n --> compiler-test:5:3\n |\n 5 | let x = true;\n | ^^^^^^^^^^^^" + - "Error [EASG0373050]: a variable cannot be named `x` as a function input or variable with that name already exists in this scope\n --> compiler-test:5:7\n |\n 5 | let x = true;\n | ^" diff --git a/tests/expectations/compiler/compiler/tuples/basic.leo.out b/tests/expectations/compiler/compiler/tuples/basic.leo.out index 3841846e9d..1a231ec76b 100644 --- a/tests/expectations/compiler/compiler/tuples/basic.leo.out +++ b/tests/expectations/compiler/compiler/tuples/basic.leo.out @@ -19,7 +19,7 @@ outputs: c: type: bool value: "false" - initial_ast: 51cc6c9ff08fa4320783cf8b6683f784a6325a0e371c7d93049c30eb9d04cf72 - imports_resolved_ast: 51cc6c9ff08fa4320783cf8b6683f784a6325a0e371c7d93049c30eb9d04cf72 - canonicalized_ast: 51cc6c9ff08fa4320783cf8b6683f784a6325a0e371c7d93049c30eb9d04cf72 - type_inferenced_ast: a1e55a4a926b0d9c8d0f611136c7f9ba8ed5c6156a85d1d04adc9faaadf1a611 + initial_ast: 10550feaa2c5235500abf424e222f1f8383225ae3b6906c1cd76835e83286817 + imports_resolved_ast: 10550feaa2c5235500abf424e222f1f8383225ae3b6906c1cd76835e83286817 + canonicalized_ast: 10550feaa2c5235500abf424e222f1f8383225ae3b6906c1cd76835e83286817 + type_inferenced_ast: db07b90097bb2605e23365d07d039b7845e9c7e7313a7ecaa01116dae93912ad diff --git a/tests/expectations/compiler/compiler/tuples/dependent.leo.out b/tests/expectations/compiler/compiler/tuples/dependent.leo.out index 8b49eeab86..4a3cf972dd 100644 --- a/tests/expectations/compiler/compiler/tuples/dependent.leo.out +++ b/tests/expectations/compiler/compiler/tuples/dependent.leo.out @@ -19,7 +19,7 @@ outputs: c: type: bool value: "false" - initial_ast: 6692e9d94d784dd3cd11dbf48ac13b0b54f61d83ba0d85bf038e9bf84590851f - imports_resolved_ast: 6692e9d94d784dd3cd11dbf48ac13b0b54f61d83ba0d85bf038e9bf84590851f - canonicalized_ast: 6692e9d94d784dd3cd11dbf48ac13b0b54f61d83ba0d85bf038e9bf84590851f - type_inferenced_ast: 0d8c2b2b77762cfb957d5d6247366317b8fbe4ac7cb985df1b4d3511accf13b8 + initial_ast: be3a0206397e9b0f95c696b4d7174ee81262e805fc787b3516b1b1a277892a4d + imports_resolved_ast: be3a0206397e9b0f95c696b4d7174ee81262e805fc787b3516b1b1a277892a4d + canonicalized_ast: be3a0206397e9b0f95c696b4d7174ee81262e805fc787b3516b1b1a277892a4d + type_inferenced_ast: 672df08a8f52ff75d5cdba1f4ebc070baba70a981351819d2205b3e8de76bfc7 diff --git a/tests/expectations/compiler/compiler/tuples/destructured.leo.out b/tests/expectations/compiler/compiler/tuples/destructured.leo.out index 774c7fdf01..4c8ca35ede 100644 --- a/tests/expectations/compiler/compiler/tuples/destructured.leo.out +++ b/tests/expectations/compiler/compiler/tuples/destructured.leo.out @@ -19,7 +19,7 @@ outputs: c: type: bool value: "true" - initial_ast: 531df9191a6ee867da7a9c5aa5120a9ab93eec5d4d29bdc78aa965fce0f52c8d - imports_resolved_ast: 531df9191a6ee867da7a9c5aa5120a9ab93eec5d4d29bdc78aa965fce0f52c8d - canonicalized_ast: 531df9191a6ee867da7a9c5aa5120a9ab93eec5d4d29bdc78aa965fce0f52c8d - type_inferenced_ast: b841d6651b93193e0bbd24df8b667bd16066ee77481dd3b8b0187c37968ca1c1 + initial_ast: ea7f6cc8c9fe0deda02c3fde1f33dd71c33b6938c832af0f220fb681f56f9354 + imports_resolved_ast: ea7f6cc8c9fe0deda02c3fde1f33dd71c33b6938c832af0f220fb681f56f9354 + canonicalized_ast: ea7f6cc8c9fe0deda02c3fde1f33dd71c33b6938c832af0f220fb681f56f9354 + type_inferenced_ast: 72d9dedc48ac69de544b2f35b1f0e675f4053f562fc708b30eebcfdc6ac59dc9 From 857ab9a2b6a09b43d0a6cf1fb3a9cfbc1657cf0f Mon Sep 17 00:00:00 2001 From: damirka Date: Mon, 6 Sep 2021 14:10:06 +0300 Subject: [PATCH 10/28] change CircuitOrAlias to Identifier --- asg/src/scope.rs | 2 +- asg/src/type_.rs | 2 +- .../src/canonicalization/canonicalizer.rs | 2 +- ast/src/reducer/reconstructing_director.rs | 2 +- ast/src/types/type_.rs | 8 +++---- compiler/src/phases/reducing_director.rs | 2 +- parser/src/parser/type_.rs | 2 +- .../compiler/compiler/aliases/arith.leo.out | 6 +++--- .../compiler/compiler/aliases/basic.leo.out | 8 +++---- .../compiler/compiler/aliases/circuit.leo.out | 8 +++---- .../compiler/aliases/fn_return.leo.out | 6 +++--- .../compiler/aliases/shadowing_arg.leo.out | 8 +++---- .../aliases/shadowing_arg_fail.leo.out | 5 ----- .../aliases/shadowing_var_allowed.leo.out | 6 +++--- .../aliases/shadowing_var_fail.leo.out | 5 ----- .../compiler/array/complex_access.leo.out | 2 +- .../compiler/compiler/array/registers.leo.out | 2 +- .../compiler/compiler/char/circuit.leo.out | 2 +- .../big_self_in_circuit_replacement.leo.out | 8 +++---- .../circuits/const_self_variable.leo.out | 2 +- ...ne_circuit_inside_circuit_function.leo.out | 2 +- .../circuits/duplicate_name_context.leo.out | 2 +- .../compiler/compiler/circuits/inline.leo.out | 2 +- .../circuits/inline_member_pass.leo.out | 4 ++-- .../compiler/circuits/member_function.leo.out | 2 +- .../circuits/member_function_nested.leo.out | 2 +- .../compiler/circuits/member_variable.leo.out | 2 +- .../member_variable_and_function.leo.out | 2 +- .../circuits/mut_self_variable.leo.out | 2 +- .../circuits/mut_self_variable_branch.leo.out | 2 +- .../mut_self_variable_conditional.leo.out | 2 +- .../compiler/circuits/mut_variable.leo.out | 2 +- .../mutable_call_immutable_context.leo.out | 8 +++---- .../compiler/circuits/pedersen_mock.leo.out | 4 ++-- .../circuits/return_self_type_array.leo.out | 4 ++-- .../circuits/return_self_type_tuple.leo.out | 4 ++-- .../compiler/circuits/self_member.leo.out | 2 +- .../compiler/compiler/console/debug.leo.out | 21 ------------------- .../function/multiple_returns_main.leo.out | 2 +- .../global_consts/global_const_types.leo.out | 2 +- .../compiler/import_local/import_all.leo.out | 8 +++---- .../compiler/import_local/import_many.leo.out | 2 +- .../const_different_types_fail_signed.leo.out | 5 ----- ...onst_different_types_fail_unsigned.leo.out | 5 ----- .../different_types_fail.leo.out | 5 ----- .../different_types_fail_unsigned.leo.out | 5 ----- .../basic.leo.out | 2 +- .../token_withdraw.leo.out | 2 +- .../program_state/access_all.leo.out | 2 +- .../program_state/access_state.leo.out | 2 +- .../mutability/circuit_function_mut.leo.out | 2 +- .../mutability/circuit_variable_mut.leo.out | 2 +- .../statements/compound_assignment.leo.out | 2 +- .../compiler/statements/reverse_loop.leo.out | 21 ------------------- .../compiler/compiler/string/circuit.leo.out | 2 +- .../parser/parser/expression/cast.leo.out | 2 +- .../parser/functions/param_circuit.leo.out | 2 +- 57 files changed, 80 insertions(+), 152 deletions(-) delete mode 100644 tests/expectations/compiler/compiler/aliases/shadowing_arg_fail.leo.out delete mode 100644 tests/expectations/compiler/compiler/aliases/shadowing_var_fail.leo.out delete mode 100644 tests/expectations/compiler/compiler/console/debug.leo.out delete mode 100644 tests/expectations/compiler/compiler/input_files/program_input/const_different_types_fail_signed.leo.out delete mode 100644 tests/expectations/compiler/compiler/input_files/program_input/const_different_types_fail_unsigned.leo.out delete mode 100644 tests/expectations/compiler/compiler/input_files/program_input/different_types_fail.leo.out delete mode 100644 tests/expectations/compiler/compiler/input_files/program_input/different_types_fail_unsigned.leo.out delete mode 100644 tests/expectations/compiler/compiler/statements/reverse_loop.leo.out diff --git a/asg/src/scope.rs b/asg/src/scope.rs index 26687a495d..dfa151b85a 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -199,7 +199,7 @@ impl<'a> Scope<'a> { .collect::>>()?, ), SelfType => return Err(AsgError::unexpected_big_self(span).into()), - CircuitOrAlias(name) => { + Identifier(name) => { if let Some(circuit) = self.resolve_circuit(&name.name) { Type::Circuit(circuit) } else if let Some(alias) = self.resolve_alias(&name.name) { diff --git a/asg/src/type_.rs b/asg/src/type_.rs index 74543b2555..8731b2716b 100644 --- a/asg/src/type_.rs +++ b/asg/src/type_.rs @@ -212,7 +212,7 @@ impl<'a> Into for &Type<'a> { }]), ), Tuple(subtypes) => leo_ast::Type::Tuple(subtypes.iter().map(Into::into).collect()), - Circuit(circuit) => leo_ast::Type::CircuitOrAlias(circuit.name.borrow().clone()), + Circuit(circuit) => leo_ast::Type::Identifier(circuit.name.borrow().clone()), } } } diff --git a/ast-passes/src/canonicalization/canonicalizer.rs b/ast-passes/src/canonicalization/canonicalizer.rs index 353e284584..47634a7146 100644 --- a/ast-passes/src/canonicalization/canonicalizer.rs +++ b/ast-passes/src/canonicalization/canonicalizer.rs @@ -116,7 +116,7 @@ impl Canonicalizer { fn canonicalize_self_type(&self, type_option: Option<&Type>) -> Option { match type_option { Some(type_) => match type_ { - Type::SelfType => Some(Type::CircuitOrAlias(self.circuit_name.as_ref().unwrap().clone())), + Type::SelfType => Some(Type::Identifier(self.circuit_name.as_ref().unwrap().clone())), Type::Array(type_, dimensions) => Some(Type::Array( Box::new(self.canonicalize_self_type(Some(type_)).unwrap()), dimensions.clone(), diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 22246090d9..513fc7bb19 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -41,7 +41,7 @@ impl ReconstructingDirector { Type::Tuple(reduced_types) } - Type::CircuitOrAlias(identifier) => Type::CircuitOrAlias(self.reduce_identifier(identifier)?), + Type::Identifier(identifier) => Type::Identifier(self.reduce_identifier(identifier)?), _ => type_.clone(), }; diff --git a/ast/src/types/type_.rs b/ast/src/types/type_.rs index b26e09c644..d292c27a28 100644 --- a/ast/src/types/type_.rs +++ b/ast/src/types/type_.rs @@ -36,7 +36,7 @@ pub enum Type { // Data type wrappers Array(Box, ArrayDimensions), Tuple(Vec), - CircuitOrAlias(Identifier), + Identifier(Identifier), // ex Circuit or Alias SelfType, } @@ -52,7 +52,7 @@ impl Type { /// Returns `true` if the self `Type` is a `Circuit`. /// pub fn is_circuit(&self) -> bool { - matches!(self, Type::CircuitOrAlias(_)) + matches!(self, Type::Identifier(_)) } /// @@ -68,7 +68,7 @@ impl Type { (Type::Field, Type::Field) => true, (Type::Group, Type::Group) => true, (Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right), - (Type::CircuitOrAlias(left), Type::CircuitOrAlias(right)) => left.eq(right), + (Type::Identifier(left), Type::Identifier(right)) => left.eq(right), (Type::SelfType, Type::SelfType) => true, (Type::Array(left_type, left_dim), Type::Array(right_type, right_dim)) => { // Convert array dimensions to owned. @@ -151,7 +151,7 @@ impl fmt::Display for Type { Type::Field => write!(f, "field"), Type::Group => write!(f, "group"), Type::IntegerType(ref integer_type) => write!(f, "{}", integer_type), - Type::CircuitOrAlias(ref variable) => write!(f, "circuit {}", variable), + Type::Identifier(ref variable) => write!(f, "circuit {}", variable), Type::SelfType => write!(f, "SelfType"), Type::Array(ref array, ref dimensions) => write!(f, "[{}; {}]", *array, dimensions), Type::Tuple(ref tuple) => { diff --git a/compiler/src/phases/reducing_director.rs b/compiler/src/phases/reducing_director.rs index 56e7ba565b..3fd70dc97b 100644 --- a/compiler/src/phases/reducing_director.rs +++ b/compiler/src/phases/reducing_director.rs @@ -266,7 +266,7 @@ impl CombineAstAsgDirector { asg: &AsgCircuitAccessExpression, ) -> Result { let type_ = if self.options.type_inference_enabled() { - Some(leo_ast::Type::CircuitOrAlias(asg.circuit.get().name.borrow().clone())) + Some(leo_ast::Type::Identifier(asg.circuit.get().name.borrow().clone())) } else { None }; diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index 60d5b01d05..78663e8d98 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -89,7 +89,7 @@ impl ParserContext { (Type::SelfType, token.span) } else if let Some(ident) = self.eat_identifier() { let span = ident.span.clone(); - (Type::CircuitOrAlias(ident), span) + (Type::Identifier(ident), span) } else if let Some(token) = self.eat(Token::LeftParen) { let mut types = Vec::new(); let end_span; diff --git a/tests/expectations/compiler/compiler/aliases/arith.leo.out b/tests/expectations/compiler/compiler/aliases/arith.leo.out index afd5ac5a6e..f0d844fe99 100644 --- a/tests/expectations/compiler/compiler/aliases/arith.leo.out +++ b/tests/expectations/compiler/compiler/aliases/arith.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: a4a3b4b30742544a6dae3d76794504173c1cc64f217bd3feda033ce51512a670 - imports_resolved_ast: a4a3b4b30742544a6dae3d76794504173c1cc64f217bd3feda033ce51512a670 - canonicalized_ast: a4a3b4b30742544a6dae3d76794504173c1cc64f217bd3feda033ce51512a670 + initial_ast: 6349e2684562bad873bcf643e01eeb02039295bd41e2df77f1fefc7bb3f2d3bb + imports_resolved_ast: 6349e2684562bad873bcf643e01eeb02039295bd41e2df77f1fefc7bb3f2d3bb + canonicalized_ast: 6349e2684562bad873bcf643e01eeb02039295bd41e2df77f1fefc7bb3f2d3bb type_inferenced_ast: 508686ddeb2f8fad60d9ad58639b5a761e6c5f5b61e105803eb8a98d8065a2ad diff --git a/tests/expectations/compiler/compiler/aliases/basic.leo.out b/tests/expectations/compiler/compiler/aliases/basic.leo.out index 246cf547ed..237825d43d 100644 --- a/tests/expectations/compiler/compiler/aliases/basic.leo.out +++ b/tests/expectations/compiler/compiler/aliases/basic.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: d83b33119db295fa2ed7795c8e17d4073cabba5e90e9438cd53f3a9a77585f19 - imports_resolved_ast: d83b33119db295fa2ed7795c8e17d4073cabba5e90e9438cd53f3a9a77585f19 - canonicalized_ast: d83b33119db295fa2ed7795c8e17d4073cabba5e90e9438cd53f3a9a77585f19 - type_inferenced_ast: 77be8ec74bc15f2a45e8bf29e7973bc0c721008fe5508dcc6d02b91aae3d84ee + initial_ast: 9f78c996da10363fb594947ca29fef29e35a7032761ce87f69f3ae454650d47e + imports_resolved_ast: 9f78c996da10363fb594947ca29fef29e35a7032761ce87f69f3ae454650d47e + canonicalized_ast: 9f78c996da10363fb594947ca29fef29e35a7032761ce87f69f3ae454650d47e + type_inferenced_ast: 103314a18ce6036da1ab4cc32c025b694cf799492460ab9553dfbd5232544a89 diff --git a/tests/expectations/compiler/compiler/aliases/circuit.leo.out b/tests/expectations/compiler/compiler/aliases/circuit.leo.out index 579ebcce07..530d901e79 100644 --- a/tests/expectations/compiler/compiler/aliases/circuit.leo.out +++ b/tests/expectations/compiler/compiler/aliases/circuit.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: d9b0b6772317f0e2d1042dba26c19b4eb71a7e902c643cbeb0a4f62630f0f1bc - imports_resolved_ast: d9b0b6772317f0e2d1042dba26c19b4eb71a7e902c643cbeb0a4f62630f0f1bc - canonicalized_ast: d9b0b6772317f0e2d1042dba26c19b4eb71a7e902c643cbeb0a4f62630f0f1bc - type_inferenced_ast: e384fbed9e161b04c6c9e85f45788e5047385f289ef89d20fdacee00a8fb3e5c + initial_ast: ee817c17e6bef3b458e14d3a81c087ed6a75c4554bc70b62466e8d8e43ff1b5e + imports_resolved_ast: ee817c17e6bef3b458e14d3a81c087ed6a75c4554bc70b62466e8d8e43ff1b5e + canonicalized_ast: ee817c17e6bef3b458e14d3a81c087ed6a75c4554bc70b62466e8d8e43ff1b5e + type_inferenced_ast: b15c7e773ebb56e339f750401241e38aab4ab8950c20a70acc293afc1b91d917 diff --git a/tests/expectations/compiler/compiler/aliases/fn_return.leo.out b/tests/expectations/compiler/compiler/aliases/fn_return.leo.out index 80aeb65553..3d3f415760 100644 --- a/tests/expectations/compiler/compiler/aliases/fn_return.leo.out +++ b/tests/expectations/compiler/compiler/aliases/fn_return.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: 7feac3e33e75789d3b532a7cc857f324cd7abed380d578791803b3162edcfdec - imports_resolved_ast: 7feac3e33e75789d3b532a7cc857f324cd7abed380d578791803b3162edcfdec - canonicalized_ast: 7feac3e33e75789d3b532a7cc857f324cd7abed380d578791803b3162edcfdec + initial_ast: 8d5ed3110bc3a61ddee37408133fcc1f77209b65bb83d230729203009e093f40 + imports_resolved_ast: 8d5ed3110bc3a61ddee37408133fcc1f77209b65bb83d230729203009e093f40 + canonicalized_ast: 8d5ed3110bc3a61ddee37408133fcc1f77209b65bb83d230729203009e093f40 type_inferenced_ast: bc54ad21e90ab297b40ff570dfc379cbca61fdc9e20bd6899f4b964f726954b0 diff --git a/tests/expectations/compiler/compiler/aliases/shadowing_arg.leo.out b/tests/expectations/compiler/compiler/aliases/shadowing_arg.leo.out index e9b87ef19d..5c4e3edf6f 100644 --- a/tests/expectations/compiler/compiler/aliases/shadowing_arg.leo.out +++ b/tests/expectations/compiler/compiler/aliases/shadowing_arg.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: 671704ed30a8c68ebffe2a58ff4799f626badf975d2d0dded3b06f5264e5c0db - imports_resolved_ast: 671704ed30a8c68ebffe2a58ff4799f626badf975d2d0dded3b06f5264e5c0db - canonicalized_ast: 671704ed30a8c68ebffe2a58ff4799f626badf975d2d0dded3b06f5264e5c0db - type_inferenced_ast: eb525f7c227207a1037b96838d2f0cf597968c14117b3fae30564f3cd5a3a27b + initial_ast: f7b2eb89c51644dc8596988bcc66fbfe471489887c6f46b78ca417746c7ef442 + imports_resolved_ast: f7b2eb89c51644dc8596988bcc66fbfe471489887c6f46b78ca417746c7ef442 + canonicalized_ast: f7b2eb89c51644dc8596988bcc66fbfe471489887c6f46b78ca417746c7ef442 + type_inferenced_ast: f24ef5063928ee7998b53e5e66064c56c01bd99d55b736309d3a1d11ff2fec05 diff --git a/tests/expectations/compiler/compiler/aliases/shadowing_arg_fail.leo.out b/tests/expectations/compiler/compiler/aliases/shadowing_arg_fail.leo.out deleted file mode 100644 index 70318ab6fb..0000000000 --- a/tests/expectations/compiler/compiler/aliases/shadowing_arg_fail.leo.out +++ /dev/null @@ -1,5 +0,0 @@ ---- -namespace: Compile -expectation: Fail -outputs: - - "Error [EASG0373047]: a function input cannot be named `x` as a alias with that name already exists in this scope\n --> compiler-test:5:15\n |\n 5 | function main(x: u32, y: bool) -> bool {\n | ^" diff --git a/tests/expectations/compiler/compiler/aliases/shadowing_var_allowed.leo.out b/tests/expectations/compiler/compiler/aliases/shadowing_var_allowed.leo.out index c1d479dd9b..6027b63169 100644 --- a/tests/expectations/compiler/compiler/aliases/shadowing_var_allowed.leo.out +++ b/tests/expectations/compiler/compiler/aliases/shadowing_var_allowed.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: cd2e85ff29ee11d30e73dbba0a612223a8a26dff125069ad7ac05697fd4c9829 - imports_resolved_ast: cd2e85ff29ee11d30e73dbba0a612223a8a26dff125069ad7ac05697fd4c9829 - canonicalized_ast: cd2e85ff29ee11d30e73dbba0a612223a8a26dff125069ad7ac05697fd4c9829 + initial_ast: 66ead06ceac4fea6a24fe071a955986722a53975fa98d2ad2909a83fa8ba8525 + imports_resolved_ast: 66ead06ceac4fea6a24fe071a955986722a53975fa98d2ad2909a83fa8ba8525 + canonicalized_ast: 66ead06ceac4fea6a24fe071a955986722a53975fa98d2ad2909a83fa8ba8525 type_inferenced_ast: 1e73226b2cbbd5c7a36ffe70b778e0e544976d2e09a1f0ba3f2b486d1b604d58 diff --git a/tests/expectations/compiler/compiler/aliases/shadowing_var_fail.leo.out b/tests/expectations/compiler/compiler/aliases/shadowing_var_fail.leo.out deleted file mode 100644 index 9cbec43215..0000000000 --- a/tests/expectations/compiler/compiler/aliases/shadowing_var_fail.leo.out +++ /dev/null @@ -1,5 +0,0 @@ ---- -namespace: Compile -expectation: Fail -outputs: - - "Error [EASG0373047]: a function input cannot be named `int` as a alias with that name already exists in this scope\n --> compiler-test:6:9\n |\n 6 | let int: int = 1u32;\n | ^^^" diff --git a/tests/expectations/compiler/compiler/array/complex_access.leo.out b/tests/expectations/compiler/compiler/array/complex_access.leo.out index 841bf13445..358b65def2 100644 --- a/tests/expectations/compiler/compiler/array/complex_access.leo.out +++ b/tests/expectations/compiler/compiler/array/complex_access.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 843884ddf198fe566cea0f8e84a2902f720d6211c9d8bad98299eea4da846870 imports_resolved_ast: 843884ddf198fe566cea0f8e84a2902f720d6211c9d8bad98299eea4da846870 canonicalized_ast: c30721e60523bc31af9a9bf342d9b89bf92a26e3886394cc0c1a574560715bdf - type_inferenced_ast: c37f209961a9acff1d942af1e4a9a332123676f2bc581ca94604314f9d738a1e + type_inferenced_ast: baed608da257be0625cd54a796c2f89e9aec8b1ff60f23c7657a0c4fc260e1d1 diff --git a/tests/expectations/compiler/compiler/array/registers.leo.out b/tests/expectations/compiler/compiler/array/registers.leo.out index 96a5800d2b..9a707ce101 100644 --- a/tests/expectations/compiler/compiler/array/registers.leo.out +++ b/tests/expectations/compiler/compiler/array/registers.leo.out @@ -25,4 +25,4 @@ outputs: initial_ast: 4e74124bc410534941ef9b79ffb64656d14e145b5a79fbd14419c1aef2f0ef69 imports_resolved_ast: 4e74124bc410534941ef9b79ffb64656d14e145b5a79fbd14419c1aef2f0ef69 canonicalized_ast: 4e74124bc410534941ef9b79ffb64656d14e145b5a79fbd14419c1aef2f0ef69 - type_inferenced_ast: f5cb6326028b3cf9187889be6ac5ed5bd095a570d45ae63c7285a09366fc6803 + type_inferenced_ast: de80815f88fb65efa62ce7f5fa23c6fc4f1bbdf601954e94c1212c4eabbee1cb diff --git a/tests/expectations/compiler/compiler/char/circuit.leo.out b/tests/expectations/compiler/compiler/char/circuit.leo.out index 0a4821256d..50beb63398 100644 --- a/tests/expectations/compiler/compiler/char/circuit.leo.out +++ b/tests/expectations/compiler/compiler/char/circuit.leo.out @@ -103,4 +103,4 @@ outputs: initial_ast: 0c2aeb5b47fc21f5aded4e3aebcdf55eb98c10c6b51a2a6dcb98490a96da0c97 imports_resolved_ast: 0c2aeb5b47fc21f5aded4e3aebcdf55eb98c10c6b51a2a6dcb98490a96da0c97 canonicalized_ast: 0c2aeb5b47fc21f5aded4e3aebcdf55eb98c10c6b51a2a6dcb98490a96da0c97 - type_inferenced_ast: 84977d828c2988392d85d4156d34d168a3265aca3c3516b3ddb974d3d9eee2dc + type_inferenced_ast: e9c5fc64aad2390305671ffbe316eee04d5fca7a6f09dcc8c8a69c38db8b3a62 diff --git a/tests/expectations/compiler/compiler/circuits/big_self_in_circuit_replacement.leo.out b/tests/expectations/compiler/compiler/circuits/big_self_in_circuit_replacement.leo.out index 0fc5a81aef..b904e031f7 100644 --- a/tests/expectations/compiler/compiler/circuits/big_self_in_circuit_replacement.leo.out +++ b/tests/expectations/compiler/compiler/circuits/big_self_in_circuit_replacement.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: 58f66e3a45b1752bb5dbb454adbbe6136394a7a87bc7b812d154aec1d5eac816 - imports_resolved_ast: 58f66e3a45b1752bb5dbb454adbbe6136394a7a87bc7b812d154aec1d5eac816 - canonicalized_ast: f7359bbb8cecd0923c0aa7dd7fd6b01cb2c64e45f1e777709fb14d4e6ba0ee5a - type_inferenced_ast: f3a0378b8b60f66ca164be498224592907216262a54a92d878e52f0a85f53389 + initial_ast: 3802c9e1638389140218e5eacb10d9ee53398ed6c083cfa4c24b7f4218512e45 + imports_resolved_ast: 3802c9e1638389140218e5eacb10d9ee53398ed6c083cfa4c24b7f4218512e45 + canonicalized_ast: 6c18b527bfd6571cfb1af7113259977040ec35ad2593bbe275011d0b204afe81 + type_inferenced_ast: 3f4dc74bea13fe2e97a042f3b4dd7042df725a172a151db628745ee3c7d7cd1a diff --git a/tests/expectations/compiler/compiler/circuits/const_self_variable.leo.out b/tests/expectations/compiler/compiler/circuits/const_self_variable.leo.out index 43b8d36554..114074fdf6 100644 --- a/tests/expectations/compiler/compiler/circuits/const_self_variable.leo.out +++ b/tests/expectations/compiler/compiler/circuits/const_self_variable.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 50c0f7261d879373f4e01ec3d140a2067ca4e78622c8340e8312d717f6effb05 imports_resolved_ast: 50c0f7261d879373f4e01ec3d140a2067ca4e78622c8340e8312d717f6effb05 canonicalized_ast: 50c0f7261d879373f4e01ec3d140a2067ca4e78622c8340e8312d717f6effb05 - type_inferenced_ast: 161edd5d1900f2902bd8cc972308ce7fb0afe7c6cf64ab7cfe952c3f1b3189c0 + type_inferenced_ast: 68174a753a3191ea961db29f62b6557f410ee33c2cad28c43a5098bb6cb230f2 diff --git a/tests/expectations/compiler/compiler/circuits/define_circuit_inside_circuit_function.leo.out b/tests/expectations/compiler/compiler/circuits/define_circuit_inside_circuit_function.leo.out index 4a4ff1f5fd..f20fb08065 100644 --- a/tests/expectations/compiler/compiler/circuits/define_circuit_inside_circuit_function.leo.out +++ b/tests/expectations/compiler/compiler/circuits/define_circuit_inside_circuit_function.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: bfd7751e8ea64c6d41af36d968f194a18a5411ac71932a67766f40448ce755f5 imports_resolved_ast: bfd7751e8ea64c6d41af36d968f194a18a5411ac71932a67766f40448ce755f5 canonicalized_ast: bfd7751e8ea64c6d41af36d968f194a18a5411ac71932a67766f40448ce755f5 - type_inferenced_ast: 910b51f962861da6011f214a5379bc9296034e3fecda347b17c7db97df833a25 + type_inferenced_ast: c6ca022e97bef335bf6df235875d507240eb48ea28f6504cc17c3d09820430f9 diff --git a/tests/expectations/compiler/compiler/circuits/duplicate_name_context.leo.out b/tests/expectations/compiler/compiler/circuits/duplicate_name_context.leo.out index 3e8bc37c51..d9e1076d49 100644 --- a/tests/expectations/compiler/compiler/circuits/duplicate_name_context.leo.out +++ b/tests/expectations/compiler/compiler/circuits/duplicate_name_context.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: d8a66347f480161a2215c92d2cf6ded2d0b49fd76b7eb0036d4fa33de371925a imports_resolved_ast: d8a66347f480161a2215c92d2cf6ded2d0b49fd76b7eb0036d4fa33de371925a canonicalized_ast: d8a66347f480161a2215c92d2cf6ded2d0b49fd76b7eb0036d4fa33de371925a - type_inferenced_ast: d5bb87130d78bb39fa948ce868999184f90c78ada176cf08c49051517de3351c + type_inferenced_ast: cb82c955829007961356ca2760b6ca84e2ea321cd640e87d4a51fd3ba65eb7a7 diff --git a/tests/expectations/compiler/compiler/circuits/inline.leo.out b/tests/expectations/compiler/compiler/circuits/inline.leo.out index dff5b84d3e..cfd62ab7e7 100644 --- a/tests/expectations/compiler/compiler/circuits/inline.leo.out +++ b/tests/expectations/compiler/compiler/circuits/inline.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: c40a1d60f872fdb03ab7379a3abf43439a100b8f1546b76ffeac60c8739e0d68 imports_resolved_ast: c40a1d60f872fdb03ab7379a3abf43439a100b8f1546b76ffeac60c8739e0d68 canonicalized_ast: c40a1d60f872fdb03ab7379a3abf43439a100b8f1546b76ffeac60c8739e0d68 - type_inferenced_ast: 3d56ffd95d1b84970e24f10a48f52053717876f062db72d8be93f413f7b2c9a3 + type_inferenced_ast: 2221472ded58b4a6c77545040ca32138d68eb6f2c3e47b830317872f045f91f8 diff --git a/tests/expectations/compiler/compiler/circuits/inline_member_pass.leo.out b/tests/expectations/compiler/compiler/circuits/inline_member_pass.leo.out index 486a6ec9b8..f3df395a9e 100644 --- a/tests/expectations/compiler/compiler/circuits/inline_member_pass.leo.out +++ b/tests/expectations/compiler/compiler/circuits/inline_member_pass.leo.out @@ -18,5 +18,5 @@ outputs: value: "true" initial_ast: cf642f2f983cd8bcd6cbca2d2920f5234d79375601c1da3c06f97b6185a5629d imports_resolved_ast: cf642f2f983cd8bcd6cbca2d2920f5234d79375601c1da3c06f97b6185a5629d - canonicalized_ast: f99560385252ad2965e39b19402e7c56db402458206187eeb54adc26effd9bb5 - type_inferenced_ast: c7c5cd5ed24fd3967f19a5ad895aeb7778b3dfadc7965c3f5bc1d44c61448083 + canonicalized_ast: de45d7a621a1309ca9ae0dd11f4a99e8ff1e0b92c9f990d2f72a6c43067a7611 + type_inferenced_ast: 690a93dcec9c31c26b52ca234ce8e07067649c038e47fd8b7eeef9e36dddf05b diff --git a/tests/expectations/compiler/compiler/circuits/member_function.leo.out b/tests/expectations/compiler/compiler/circuits/member_function.leo.out index 48b1947e43..a0ec36306d 100644 --- a/tests/expectations/compiler/compiler/circuits/member_function.leo.out +++ b/tests/expectations/compiler/compiler/circuits/member_function.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 5273a592b167cfe040b2bca7337521084d7a6640651bca584545e9eeb2e4fa88 imports_resolved_ast: 5273a592b167cfe040b2bca7337521084d7a6640651bca584545e9eeb2e4fa88 canonicalized_ast: 5273a592b167cfe040b2bca7337521084d7a6640651bca584545e9eeb2e4fa88 - type_inferenced_ast: 6d1bef6ecbba4533266f9478b06e52acc56f04850e99a658abffe39e7e463cdf + type_inferenced_ast: ee2152aedd637adcfdd84540bfd8814c65cc8552c0bae80a0176b91d70b1266e diff --git a/tests/expectations/compiler/compiler/circuits/member_function_nested.leo.out b/tests/expectations/compiler/compiler/circuits/member_function_nested.leo.out index 5428da7f87..a71956d836 100644 --- a/tests/expectations/compiler/compiler/circuits/member_function_nested.leo.out +++ b/tests/expectations/compiler/compiler/circuits/member_function_nested.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 241f1a42877b012b2e2062cefbd83523a5c719557cb422cf1fbd7efb0f7b1796 imports_resolved_ast: 241f1a42877b012b2e2062cefbd83523a5c719557cb422cf1fbd7efb0f7b1796 canonicalized_ast: 241f1a42877b012b2e2062cefbd83523a5c719557cb422cf1fbd7efb0f7b1796 - type_inferenced_ast: 2982ee6fda2fcbd00f64d2c0c75ccacf58ab05961f85e9a64cc0ddec12bb5209 + type_inferenced_ast: e063513fb0d009c0cadd36cab9feb4327528bbba45087d7a65e0e97fcd54bb7a diff --git a/tests/expectations/compiler/compiler/circuits/member_variable.leo.out b/tests/expectations/compiler/compiler/circuits/member_variable.leo.out index 01852c344d..ffa5a78e70 100644 --- a/tests/expectations/compiler/compiler/circuits/member_variable.leo.out +++ b/tests/expectations/compiler/compiler/circuits/member_variable.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: cf41b78f9435c6555014db8aeebe662556f4f8547ee0f3a204d6f522fcf72644 imports_resolved_ast: cf41b78f9435c6555014db8aeebe662556f4f8547ee0f3a204d6f522fcf72644 canonicalized_ast: cf41b78f9435c6555014db8aeebe662556f4f8547ee0f3a204d6f522fcf72644 - type_inferenced_ast: d947fa6d8fa1b34cc9822ade386062dbd6ebc2cb5987479d4263bcfa554586cd + type_inferenced_ast: 2fbe148dcadf6f460f64824e311f1f061265dc81e2eaff555987dbf55094b3a4 diff --git a/tests/expectations/compiler/compiler/circuits/member_variable_and_function.leo.out b/tests/expectations/compiler/compiler/circuits/member_variable_and_function.leo.out index dafeae69a8..ef27e8f875 100644 --- a/tests/expectations/compiler/compiler/circuits/member_variable_and_function.leo.out +++ b/tests/expectations/compiler/compiler/circuits/member_variable_and_function.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 622baae85ab7776fc38cff17465e8e0dbcdb98f4ba74e734ca494b696cea8ccd imports_resolved_ast: 622baae85ab7776fc38cff17465e8e0dbcdb98f4ba74e734ca494b696cea8ccd canonicalized_ast: 622baae85ab7776fc38cff17465e8e0dbcdb98f4ba74e734ca494b696cea8ccd - type_inferenced_ast: c604cecb0efbae6b8ea3d69909c5decbb06d6a2e95ff67661f5936ef8fd951a5 + type_inferenced_ast: f97b773504a230c42546d6a565b970fbf51ec293c15ee58d4f9dfa40b7a4a988 diff --git a/tests/expectations/compiler/compiler/circuits/mut_self_variable.leo.out b/tests/expectations/compiler/compiler/circuits/mut_self_variable.leo.out index 15d4737f53..f889ea11c9 100644 --- a/tests/expectations/compiler/compiler/circuits/mut_self_variable.leo.out +++ b/tests/expectations/compiler/compiler/circuits/mut_self_variable.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: ba91ea172a2f753bf4a338f29fff05c358d4dc0cb1c2ef461d492ee4fe2a1114 imports_resolved_ast: ba91ea172a2f753bf4a338f29fff05c358d4dc0cb1c2ef461d492ee4fe2a1114 canonicalized_ast: 8d1beaecc785aa79a5a6bec47cf10426b9d3d87ccc15c359f12c7d3ee2a95561 - type_inferenced_ast: 520a83004a666274e62958b6e2025d11ed5e24d888b6bc0ded6d01ee9a3bc634 + type_inferenced_ast: d69ef792ee9b73a3d486535216ade98bd500aff7061e5b3cb48e5f1ffd519286 diff --git a/tests/expectations/compiler/compiler/circuits/mut_self_variable_branch.leo.out b/tests/expectations/compiler/compiler/circuits/mut_self_variable_branch.leo.out index 075d930428..20613db255 100644 --- a/tests/expectations/compiler/compiler/circuits/mut_self_variable_branch.leo.out +++ b/tests/expectations/compiler/compiler/circuits/mut_self_variable_branch.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: fe7ca41c29d33107a4316b9c6788898217129937cbf1de0f2ea7566a360245f0 imports_resolved_ast: fe7ca41c29d33107a4316b9c6788898217129937cbf1de0f2ea7566a360245f0 canonicalized_ast: d2b30a9485e7166a0efde9d179432e481a4d40540e1b3eeec043b84d993e66df - type_inferenced_ast: 2c666d0e878095617bc562aa74de4fe069401b4a80ba8dba28a47a789f517ab5 + type_inferenced_ast: 7f279d6a24e597f0d1e6dbc5d26db3bc0ac6dc8520b7b485f296824c2e872a0e diff --git a/tests/expectations/compiler/compiler/circuits/mut_self_variable_conditional.leo.out b/tests/expectations/compiler/compiler/circuits/mut_self_variable_conditional.leo.out index 1f3edc74a6..8532ec1155 100644 --- a/tests/expectations/compiler/compiler/circuits/mut_self_variable_conditional.leo.out +++ b/tests/expectations/compiler/compiler/circuits/mut_self_variable_conditional.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 659e5fcdd16752c6e3504f821a5afd6f0756bd6b8641f127ba049c2a4c83a088 imports_resolved_ast: 659e5fcdd16752c6e3504f821a5afd6f0756bd6b8641f127ba049c2a4c83a088 canonicalized_ast: 8cf6113b757cfeee53554c67dd3f380f0f417032b8835259bf30076b19349f61 - type_inferenced_ast: d4106eb006385de5bf2a56a1ebaa25a65b048f77dda6fb9585c86a9260073585 + type_inferenced_ast: 63445b0618aa26ad71f316dea01a0558be3462295c4ef7ddcc042a6098e80725 diff --git a/tests/expectations/compiler/compiler/circuits/mut_variable.leo.out b/tests/expectations/compiler/compiler/circuits/mut_variable.leo.out index 2d1473ebfd..6cf717c440 100644 --- a/tests/expectations/compiler/compiler/circuits/mut_variable.leo.out +++ b/tests/expectations/compiler/compiler/circuits/mut_variable.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 8c4a98dec3d2e9e826e3419c91a251e821861a146325b025c52ff15b5edefe1c imports_resolved_ast: 8c4a98dec3d2e9e826e3419c91a251e821861a146325b025c52ff15b5edefe1c canonicalized_ast: 8c4a98dec3d2e9e826e3419c91a251e821861a146325b025c52ff15b5edefe1c - type_inferenced_ast: 2497671092bacab8cb5d75177298a700100bfa8412a48a7115d178e5d9816a6b + type_inferenced_ast: a88491df0bd761c2c92882182087308683df773c06b6337d47e47658024ba6ea diff --git a/tests/expectations/compiler/compiler/circuits/mutable_call_immutable_context.leo.out b/tests/expectations/compiler/compiler/circuits/mutable_call_immutable_context.leo.out index 3e206e0757..8ca3ebf9a2 100644 --- a/tests/expectations/compiler/compiler/circuits/mutable_call_immutable_context.leo.out +++ b/tests/expectations/compiler/compiler/circuits/mutable_call_immutable_context.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: 1f7de14429213b2b3b564d664c33e9cea134e1a157b861a1cf0ea1abc90b32f6 - imports_resolved_ast: 1f7de14429213b2b3b564d664c33e9cea134e1a157b861a1cf0ea1abc90b32f6 - canonicalized_ast: 94752f37ca7553267f341d2f96e657eb2fe6b5e403a4d3fb7d66d1662b81eb00 - type_inferenced_ast: e675411217f3465fdc23bab3c2f50c2264452d198ab3dd2e8059e546e54312a4 + initial_ast: 842ec0aa120289fc341e19deefa59c7f78af032b1221b749323e0e4b6ce9023d + imports_resolved_ast: 842ec0aa120289fc341e19deefa59c7f78af032b1221b749323e0e4b6ce9023d + canonicalized_ast: c554b4086bcc2a245ee45c1a7ee7879c23dfab6872c8f0254bd258f1d78854b5 + type_inferenced_ast: 8aca5d3beb3f7988b97d7ee3ed5f5376e508e35b687bc70cc402824e3740afc9 diff --git a/tests/expectations/compiler/compiler/circuits/pedersen_mock.leo.out b/tests/expectations/compiler/compiler/circuits/pedersen_mock.leo.out index ba7f2afaa3..fbc3e24305 100644 --- a/tests/expectations/compiler/compiler/circuits/pedersen_mock.leo.out +++ b/tests/expectations/compiler/compiler/circuits/pedersen_mock.leo.out @@ -18,5 +18,5 @@ outputs: value: "true" initial_ast: c341e62f8a3940ddc9527bcd01c814f8d496a1f02ca903b080b6228d155af02b imports_resolved_ast: c341e62f8a3940ddc9527bcd01c814f8d496a1f02ca903b080b6228d155af02b - canonicalized_ast: 60cd9f24460e06522814151af817c9d394c779477091aab2c77c77dfe228b611 - type_inferenced_ast: 876f075ed034c8914b9f74f46f07bd6c2ed3e7d7f1ffb15e756da10e9ec9abf8 + canonicalized_ast: 3f982b126b30b7d4e6f69d186eae87e539ac99c186e3ffc95e101996c447aac6 + type_inferenced_ast: ca39452d2a0bfc4763004f6422de9c969c90bef10f6ec1ce47d71ce6fbf14d60 diff --git a/tests/expectations/compiler/compiler/circuits/return_self_type_array.leo.out b/tests/expectations/compiler/compiler/circuits/return_self_type_array.leo.out index e10652f432..02174bccab 100644 --- a/tests/expectations/compiler/compiler/circuits/return_self_type_array.leo.out +++ b/tests/expectations/compiler/compiler/circuits/return_self_type_array.leo.out @@ -18,5 +18,5 @@ outputs: value: "true" initial_ast: 5da09287f1d3a5e4ab57f8da2c8094df25c3b35614791e2f6e84a77b609f29b0 imports_resolved_ast: 5da09287f1d3a5e4ab57f8da2c8094df25c3b35614791e2f6e84a77b609f29b0 - canonicalized_ast: de5114bff3425e0c67e9e70e3a0d02bdf2d6c3ed9108dac43a00b79d4db9b3d2 - type_inferenced_ast: 9a6f5ee1784a1af0a04736e1b3bc886107bbddc5d45bbabd59812d083acacdea + canonicalized_ast: ef7bf4fbec528e16a88b50e4c5b96f9e16a136fb06b9d7ba145641e22382e166 + type_inferenced_ast: cfec0af03e9a908d876dd84a977fbccb7ddbda93e4f26b2bb7c1e7349ef41c3f diff --git a/tests/expectations/compiler/compiler/circuits/return_self_type_tuple.leo.out b/tests/expectations/compiler/compiler/circuits/return_self_type_tuple.leo.out index ac229cd771..9b181dcebc 100644 --- a/tests/expectations/compiler/compiler/circuits/return_self_type_tuple.leo.out +++ b/tests/expectations/compiler/compiler/circuits/return_self_type_tuple.leo.out @@ -18,5 +18,5 @@ outputs: value: "true" initial_ast: 1dce719e850f6ca6a091fea163d5d6bb069bcdafeeed0a10fb332ba8837e6e5c imports_resolved_ast: 1dce719e850f6ca6a091fea163d5d6bb069bcdafeeed0a10fb332ba8837e6e5c - canonicalized_ast: 3bd96f7e9530f426db4a2e12d5a93a5ebcafedbcb7b4549d08ad387fa15918d9 - type_inferenced_ast: 6bbb246f57aa199b9ef31b61b6e858004617455efe22393892bf0c22f552d69a + canonicalized_ast: c2e6a47b169e35f9d0eeb382b9ad3fbfb474dcfcce36f518a615bedd50f168dc + type_inferenced_ast: ada2285ca841403ea8f299de603e6f83f001aa7c59f0ccdb798cf3ed874cbe1f diff --git a/tests/expectations/compiler/compiler/circuits/self_member.leo.out b/tests/expectations/compiler/compiler/circuits/self_member.leo.out index 40907b9500..67698dec41 100644 --- a/tests/expectations/compiler/compiler/circuits/self_member.leo.out +++ b/tests/expectations/compiler/compiler/circuits/self_member.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: c2f6d0da67de691b14cffbdbe20eba613f2ea274c45aba4347045da2446b6af6 imports_resolved_ast: c2f6d0da67de691b14cffbdbe20eba613f2ea274c45aba4347045da2446b6af6 canonicalized_ast: c2f6d0da67de691b14cffbdbe20eba613f2ea274c45aba4347045da2446b6af6 - type_inferenced_ast: 3bf3d109f59519ecbfd601c36a8cb89cfb36e1ace395e361860023b8f93fc220 + type_inferenced_ast: 66f38055929362798774a530c32dd375c979368f2ed3c7b0345dd8ecfefe3ea7 diff --git a/tests/expectations/compiler/compiler/console/debug.leo.out b/tests/expectations/compiler/compiler/console/debug.leo.out deleted file mode 100644 index 9eecd263fd..0000000000 --- a/tests/expectations/compiler/compiler/console/debug.leo.out +++ /dev/null @@ -1,21 +0,0 @@ ---- -namespace: Compile -expectation: Pass -outputs: - - circuit: - num_public_variables: 0 - num_private_variables: 1 - num_constraints: 1 - at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f - bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c - ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05 - output: - - input_file: input/dummy.in - output: - registers: - r0: - type: bool - value: "true" - initial_ast: 80d3dbfdeb9d6fb6e9ba17ba028bd2bf71014b4353f34db9d69a66ee1d0914cf - canonicalized_ast: 80d3dbfdeb9d6fb6e9ba17ba028bd2bf71014b4353f34db9d69a66ee1d0914cf - type_inferenced_ast: bbad9d7593fb1aa2bcc25f2f2625ace659e18f293af35082ad39b1e3cd71e8b5 diff --git a/tests/expectations/compiler/compiler/function/multiple_returns_main.leo.out b/tests/expectations/compiler/compiler/function/multiple_returns_main.leo.out index 48df2bb219..0b7972b852 100644 --- a/tests/expectations/compiler/compiler/function/multiple_returns_main.leo.out +++ b/tests/expectations/compiler/compiler/function/multiple_returns_main.leo.out @@ -22,4 +22,4 @@ outputs: initial_ast: f8b2853c4b5db8f5e8402455ceae54d8ae421c4b950d15fc88fe9f9c9a9701b8 imports_resolved_ast: f8b2853c4b5db8f5e8402455ceae54d8ae421c4b950d15fc88fe9f9c9a9701b8 canonicalized_ast: f8b2853c4b5db8f5e8402455ceae54d8ae421c4b950d15fc88fe9f9c9a9701b8 - type_inferenced_ast: 8a3cbc4e3f51c432179167c22247efecc49afe8990c5b2e5a1eb757d0f5adad9 + type_inferenced_ast: 52232bc9ef6145283b66f274ab534f35ad5cbf76ed6396c34cf0d6bf59b0797c diff --git a/tests/expectations/compiler/compiler/global_consts/global_const_types.leo.out b/tests/expectations/compiler/compiler/global_consts/global_const_types.leo.out index 1f8e049ff5..54bb4216df 100644 --- a/tests/expectations/compiler/compiler/global_consts/global_const_types.leo.out +++ b/tests/expectations/compiler/compiler/global_consts/global_const_types.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: b4e5073c07791c4726b69f3e60ec66ccebefb7a3811f4a3576fc4042f8c80114 imports_resolved_ast: b4e5073c07791c4726b69f3e60ec66ccebefb7a3811f4a3576fc4042f8c80114 canonicalized_ast: 03a4e0ffc6deea9c6500a9d91eb683a780e8f5961801bea1aab26c14e4543325 - type_inferenced_ast: 66d0a55ff2ab6931d5806dcbb2ff23f9dbc41a883f19a45af8a41d3be84e136d + type_inferenced_ast: abbbde55152e4dfe84e7c1f1a6cb82cbcf8b54d46efbcaa7b8c0854f6dee9e25 diff --git a/tests/expectations/compiler/compiler/import_local/import_all.leo.out b/tests/expectations/compiler/compiler/import_local/import_all.leo.out index 9e299f3691..733b04e3ab 100644 --- a/tests/expectations/compiler/compiler/import_local/import_all.leo.out +++ b/tests/expectations/compiler/compiler/import_local/import_all.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: 6e689aa459b9ea2fa0c18c9dc0f2512db9d430f5c7101cb3104a275711d60210 - imports_resolved_ast: c4260b58a631ee77b0492ba1354182b2c95d260dcf01a62e2a0797eb5f268478 - canonicalized_ast: 7e2eaf52ce5c79242b44357609ab667df411190bf7a11228d240c314f0ce0502 - type_inferenced_ast: be897b5b17a946c2595afcc8a802df5fa4e013ba3acb4159a0123d7cf1941544 + initial_ast: 7db61dab5c9e6647ad0649ba4fac74c7d5c7d6990f301db9f8da7c2deb2d0078 + imports_resolved_ast: a1eeec54a46d6e9afba716fbc27cf5650875e01bb4f035d74f504934654761a6 + canonicalized_ast: 12b30de036076b06f0409f38b0b84df3100cd8293eb8bf5def0f397d133f8ce1 + type_inferenced_ast: 9db739a86d6e420f1d2a60078efc7a048a2985b264fb25ab218d962be573c20c diff --git a/tests/expectations/compiler/compiler/import_local/import_many.leo.out b/tests/expectations/compiler/compiler/import_local/import_many.leo.out index 551b30394a..9be4ec1e6a 100644 --- a/tests/expectations/compiler/compiler/import_local/import_many.leo.out +++ b/tests/expectations/compiler/compiler/import_local/import_many.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: ae6826642faa492e34507695dbd11e5b44c319aecb0b1e78b29ce03ae446d907 imports_resolved_ast: e08b138c63ede9de6e090e6b7fbcfbbc27a1ae49b032a6cffcafaa8f76410839 canonicalized_ast: e08b138c63ede9de6e090e6b7fbcfbbc27a1ae49b032a6cffcafaa8f76410839 - type_inferenced_ast: b311680f4429cc16661f774b0547936be148a3dd9f478013adefe575629b88fa + type_inferenced_ast: 71e74fbf0bd10a5f2069ebc887ae3e624bd1d4f8654878b54fb932cdbb067752 diff --git a/tests/expectations/compiler/compiler/input_files/program_input/const_different_types_fail_signed.leo.out b/tests/expectations/compiler/compiler/input_files/program_input/const_different_types_fail_signed.leo.out deleted file mode 100644 index 995afe29e0..0000000000 --- a/tests/expectations/compiler/compiler/input_files/program_input/const_different_types_fail_signed.leo.out +++ /dev/null @@ -1,5 +0,0 @@ ---- -namespace: Compile -expectation: Fail -outputs: - - aborting due to syntax error diff --git a/tests/expectations/compiler/compiler/input_files/program_input/const_different_types_fail_unsigned.leo.out b/tests/expectations/compiler/compiler/input_files/program_input/const_different_types_fail_unsigned.leo.out deleted file mode 100644 index 995afe29e0..0000000000 --- a/tests/expectations/compiler/compiler/input_files/program_input/const_different_types_fail_unsigned.leo.out +++ /dev/null @@ -1,5 +0,0 @@ ---- -namespace: Compile -expectation: Fail -outputs: - - aborting due to syntax error diff --git a/tests/expectations/compiler/compiler/input_files/program_input/different_types_fail.leo.out b/tests/expectations/compiler/compiler/input_files/program_input/different_types_fail.leo.out deleted file mode 100644 index 43d9de36b7..0000000000 --- a/tests/expectations/compiler/compiler/input_files/program_input/different_types_fail.leo.out +++ /dev/null @@ -1,5 +0,0 @@ ---- -namespace: Compile -expectation: Fail -outputs: - - " --> compiler-test:3:15\n |\n 3 | function main(a: u32) {\n | ^\n |\n = expected data type `u32`, found `u8`" diff --git a/tests/expectations/compiler/compiler/input_files/program_input/different_types_fail_unsigned.leo.out b/tests/expectations/compiler/compiler/input_files/program_input/different_types_fail_unsigned.leo.out deleted file mode 100644 index 995afe29e0..0000000000 --- a/tests/expectations/compiler/compiler/input_files/program_input/different_types_fail_unsigned.leo.out +++ /dev/null @@ -1,5 +0,0 @@ ---- -namespace: Compile -expectation: Fail -outputs: - - aborting due to syntax error diff --git a/tests/expectations/compiler/compiler/input_files/program_input_and_program_state/basic.leo.out b/tests/expectations/compiler/compiler/input_files/program_input_and_program_state/basic.leo.out index 49969669f4..0b5c9be010 100644 --- a/tests/expectations/compiler/compiler/input_files/program_input_and_program_state/basic.leo.out +++ b/tests/expectations/compiler/compiler/input_files/program_input_and_program_state/basic.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: dc7f40a1cfc4daa659784bf538f1273145b430875116ef1aad7fd778dcb5f736 imports_resolved_ast: dc7f40a1cfc4daa659784bf538f1273145b430875116ef1aad7fd778dcb5f736 canonicalized_ast: dc7f40a1cfc4daa659784bf538f1273145b430875116ef1aad7fd778dcb5f736 - type_inferenced_ast: f86a95c627e69d54fd6f1f651eda77cfc1ac1fab33b1ef8bbe5bf511a8c4beb7 + type_inferenced_ast: f1d1997e4d2a975664689164c1113ab8ac1e0933910410324aeb204a72da3b12 diff --git a/tests/expectations/compiler/compiler/input_files/program_input_and_program_state/token_withdraw.leo.out b/tests/expectations/compiler/compiler/input_files/program_input_and_program_state/token_withdraw.leo.out index b284218dd5..212946e888 100644 --- a/tests/expectations/compiler/compiler/input_files/program_input_and_program_state/token_withdraw.leo.out +++ b/tests/expectations/compiler/compiler/input_files/program_input_and_program_state/token_withdraw.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 6b051c3f9ce82efb30d3ba89764cc9c2607a126cb0cede72ad55ecda6c9d996d imports_resolved_ast: 6b051c3f9ce82efb30d3ba89764cc9c2607a126cb0cede72ad55ecda6c9d996d canonicalized_ast: 6b051c3f9ce82efb30d3ba89764cc9c2607a126cb0cede72ad55ecda6c9d996d - type_inferenced_ast: 3c04200d560739b0d551204b65e56abc11f26843b99aa0361362f61f0d6a3328 + type_inferenced_ast: 945f580a5c7a138000c0163b32e004c52e048ddf2166d0c9cfd67cd9485dc886 diff --git a/tests/expectations/compiler/compiler/input_files/program_state/access_all.leo.out b/tests/expectations/compiler/compiler/input_files/program_state/access_all.leo.out index 36e4948b29..e5bfdaa04e 100644 --- a/tests/expectations/compiler/compiler/input_files/program_state/access_all.leo.out +++ b/tests/expectations/compiler/compiler/input_files/program_state/access_all.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 6fce132965ff40126f6175d2abe5b8598004e90cdb29c4707f7c63dbe1093474 imports_resolved_ast: 6fce132965ff40126f6175d2abe5b8598004e90cdb29c4707f7c63dbe1093474 canonicalized_ast: 6fce132965ff40126f6175d2abe5b8598004e90cdb29c4707f7c63dbe1093474 - type_inferenced_ast: 75cff35e24806b8a66431668c319a96e95f5106a8fe513eb53abb264beab4390 + type_inferenced_ast: e79e7662148ee3db46c9d52b751fb80a13213b22065e4a5008a7443ae85419e0 diff --git a/tests/expectations/compiler/compiler/input_files/program_state/access_state.leo.out b/tests/expectations/compiler/compiler/input_files/program_state/access_state.leo.out index 9ee8ceab48..c564c2cb73 100644 --- a/tests/expectations/compiler/compiler/input_files/program_state/access_state.leo.out +++ b/tests/expectations/compiler/compiler/input_files/program_state/access_state.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: a155141331da2d7bdaa11ae738d6ca2e1d62d875c872b8b8213184d989cc8baa imports_resolved_ast: a155141331da2d7bdaa11ae738d6ca2e1d62d875c872b8b8213184d989cc8baa canonicalized_ast: a155141331da2d7bdaa11ae738d6ca2e1d62d875c872b8b8213184d989cc8baa - type_inferenced_ast: b4969327ce0ee30ab1526ce3b2479a7bf6efa38cb9616477f854cd28b1faf61a + type_inferenced_ast: 096e1372719be459b86ad5dea6e2e62f3afc350a204c382d4bebb835fa2dc615 diff --git a/tests/expectations/compiler/compiler/mutability/circuit_function_mut.leo.out b/tests/expectations/compiler/compiler/mutability/circuit_function_mut.leo.out index 42baf76272..3ad11e8018 100644 --- a/tests/expectations/compiler/compiler/mutability/circuit_function_mut.leo.out +++ b/tests/expectations/compiler/compiler/mutability/circuit_function_mut.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 71448f3f5387cd67a8d8c0b974fa93cf81cdfb72ae0d8f9499c9c5e478a0d15b imports_resolved_ast: 71448f3f5387cd67a8d8c0b974fa93cf81cdfb72ae0d8f9499c9c5e478a0d15b canonicalized_ast: 16d4030e454d8c83d2073afaaa7e8fa1eb40d36026909144db29d311ab005f46 - type_inferenced_ast: a446d016451281bab9b21f8a86250b4a3fd8a9b6f917e855e5dae816362c8925 + type_inferenced_ast: 2d0489a411d4336c01958f074b96957f3f8ae682b0046ffadf9cbddf66f7f168 diff --git a/tests/expectations/compiler/compiler/mutability/circuit_variable_mut.leo.out b/tests/expectations/compiler/compiler/mutability/circuit_variable_mut.leo.out index 643f7e5a5d..488666e39f 100644 --- a/tests/expectations/compiler/compiler/mutability/circuit_variable_mut.leo.out +++ b/tests/expectations/compiler/compiler/mutability/circuit_variable_mut.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 83da7a1bf2887678937835ac77b33a0e21dd3b04d5739146f16a559b8dc3c6ab imports_resolved_ast: 83da7a1bf2887678937835ac77b33a0e21dd3b04d5739146f16a559b8dc3c6ab canonicalized_ast: 83da7a1bf2887678937835ac77b33a0e21dd3b04d5739146f16a559b8dc3c6ab - type_inferenced_ast: bd7710479d2a5bb2da060358fc13379dc1d7e334ead42519315bce0cd0db30c0 + type_inferenced_ast: b0d9f15a133962134f094c0aa682d7f2f77085b9cad845b8af05cf48e9b7b9ca diff --git a/tests/expectations/compiler/compiler/statements/compound_assignment.leo.out b/tests/expectations/compiler/compiler/statements/compound_assignment.leo.out index 200e0e0e5c..6484927e26 100644 --- a/tests/expectations/compiler/compiler/statements/compound_assignment.leo.out +++ b/tests/expectations/compiler/compiler/statements/compound_assignment.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 108be85422345d78a93d2e36e633c3a15a1465e7c868f65e2925a47e0b5f691a imports_resolved_ast: 108be85422345d78a93d2e36e633c3a15a1465e7c868f65e2925a47e0b5f691a canonicalized_ast: d986fa603a5031dbd5034507d05df038fe99f60f603f7ca4b2d2c8ac2b409e7a - type_inferenced_ast: c95a6049c552c5b018f423fc1999b433cf94429c6edc32e2b55d326b78e36812 + type_inferenced_ast: 2f852c7591f1790075fe73a53f9b2ceb3bca69a8cc7ef1d27d70e5f53e8b144f diff --git a/tests/expectations/compiler/compiler/statements/reverse_loop.leo.out b/tests/expectations/compiler/compiler/statements/reverse_loop.leo.out deleted file mode 100644 index bb4416faf3..0000000000 --- a/tests/expectations/compiler/compiler/statements/reverse_loop.leo.out +++ /dev/null @@ -1,21 +0,0 @@ ---- -namespace: Compile -expectation: Pass -outputs: - - circuit: - num_public_variables: 0 - num_private_variables: 1 - num_constraints: 1 - at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f - bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c - ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05 - output: - - input_file: inputs/dummy.in - output: - registers: - r0: - type: bool - value: "true" - initial_ast: 75fbb3ed1613fbf39ce803ff903befe209b26a953ba8db1d68e35066655d96e6 - canonicalized_ast: a96cae2c9e347245e07c63b5c94cf43497063c3f548c615627da4b1775e9a17b - type_inferenced_ast: dc663974ed1cce7b15c35eda29c9b1af5426eafddbd108b5a03cd7071ad4a6bc diff --git a/tests/expectations/compiler/compiler/string/circuit.leo.out b/tests/expectations/compiler/compiler/string/circuit.leo.out index 20aad44ee7..db348e5a04 100644 --- a/tests/expectations/compiler/compiler/string/circuit.leo.out +++ b/tests/expectations/compiler/compiler/string/circuit.leo.out @@ -19,4 +19,4 @@ outputs: initial_ast: 3aa0745060289c1a1af4e66265f8a92a89caff1731dc70d8c6a59798152f1a38 imports_resolved_ast: 3aa0745060289c1a1af4e66265f8a92a89caff1731dc70d8c6a59798152f1a38 canonicalized_ast: a1acfd3169b8f72975cd7cc9ef2059cd8fb1ed5ea0a7f51911d3365b52375e36 - type_inferenced_ast: 55d57669ceeb95e039cb000e3673f7590c2bd69bb67786057977d158ab77dbdb + type_inferenced_ast: f84470f86eadd14d2a9a56e4f1c2ff349610064704c30b169f15f0bd82b61959 diff --git a/tests/expectations/parser/parser/expression/cast.leo.out b/tests/expectations/parser/parser/expression/cast.leo.out index 4ef12a6088..d10228b0b2 100644 --- a/tests/expectations/parser/parser/expression/cast.leo.out +++ b/tests/expectations/parser/parser/expression/cast.leo.out @@ -18,7 +18,7 @@ outputs: inner: Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"y as id\\\"}\"}" target_type: - CircuitOrAlias: "{\"name\":\"id\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"y as id\\\"}\"}" + Identifier: "{\"name\":\"id\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"y as id\\\"}\"}" span: line_start: 1 line_stop: 1 diff --git a/tests/expectations/parser/parser/functions/param_circuit.leo.out b/tests/expectations/parser/parser/functions/param_circuit.leo.out index e315902126..41aa2496ab 100644 --- a/tests/expectations/parser/parser/functions/param_circuit.leo.out +++ b/tests/expectations/parser/parser/functions/param_circuit.leo.out @@ -19,7 +19,7 @@ outputs: const_: false mutable: true type_: - CircuitOrAlias: "{\"name\":\"MyCircuit\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":15,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: MyCircuit) {\\\"}\"}" + Identifier: "{\"name\":\"MyCircuit\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":15,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: MyCircuit) {\\\"}\"}" span: line_start: 3 line_stop: 3 From dcdb2346373062f70b9de889116d3e40b8b858be Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Mon, 6 Sep 2021 06:12:58 -0700 Subject: [PATCH 11/28] fix imported circuit return from function in import --- ast-passes/src/import_resolution/importer.rs | 114 ++++++------------ compiler/src/compiler.rs | 2 +- imports/src/parser/parse_package.rs | 5 +- test-framework/src/bin/tgc.rs | 2 +- tests/compiler/import_local/import_all.leo | 1 + .../import_local/local_imports/circuits.leo | 8 +- .../import_local/local_imports/nested/c-d.leo | 4 + .../compiler/import_local/import_all.leo.out | 8 +- .../compiler/import_local/import_many.leo.out | 6 +- .../import_weird_names_nested.leo.out | 6 +- 10 files changed, 62 insertions(+), 94 deletions(-) diff --git a/ast-passes/src/import_resolution/importer.rs b/ast-passes/src/import_resolution/importer.rs index 118a8a5c43..428f4411dc 100644 --- a/ast-passes/src/import_resolution/importer.rs +++ b/ast-passes/src/import_resolution/importer.rs @@ -21,25 +21,42 @@ use leo_errors::{AstError, Result, Span}; use indexmap::IndexMap; -pub struct Importer -where - T: ImportResolver, -{ - import_resolver: T, -} +pub struct Importer {} -impl Importer -where - T: ImportResolver, -{ - pub fn new(import_resolver: T) -> Self { - Self { import_resolver } - } +impl Importer { + pub fn do_pass(program: Program, importer: &mut T) -> Result + where + T: ImportResolver, + { + let mut imported_symbols: Vec<(Vec, ImportSymbol, Span)> = vec![]; + for import_statement in program.import_statements.iter() { + resolve_import_package(&mut imported_symbols, vec![], &import_statement.package_or_packages); + } - pub fn do_pass(ast: Program, importer: T) -> Result { - Ok(Ast::new( - ReconstructingDirector::new(Importer::new(importer)).reduce_program(&ast)?, - )) + let mut deduplicated_imports: IndexMap, Span> = IndexMap::new(); + for (package, _symbol, span) in imported_symbols.iter() { + deduplicated_imports.insert(package.clone(), span.clone()); + } + + let mut wrapped_resolver = CoreImportResolver::new(importer); + + let mut resolved_packages: IndexMap, Program> = IndexMap::new(); + for (package, span) in deduplicated_imports { + let pretty_package = package.join("."); + + let resolved_package = + match wrapped_resolver.resolve_package(&package.iter().map(|x| &**x).collect::>()[..], &span)? { + Some(x) => x, + None => return Err(AstError::unresolved_import(pretty_package, &span).into()), + }; + + resolved_packages.insert(package.clone(), resolved_package); + } + + let mut ast = program; + ast.imports = resolved_packages; + + Ok(Ast::new(ast)) } } @@ -108,66 +125,3 @@ fn resolve_import_package_access( } } } - -impl ReconstructingReducer for Importer -where - T: ImportResolver, -{ - fn in_circuit(&self) -> bool { - false - } - - fn swap_in_circuit(&mut self) {} - - fn reduce_program( - &mut self, - program: &Program, - expected_input: Vec, - import_statements: Vec, - empty_imports: IndexMap, Program>, - aliases: IndexMap, - circuits: IndexMap, - functions: IndexMap, - global_consts: IndexMap, DefinitionStatement>, - ) -> Result { - if !empty_imports.is_empty() { - return Err(AstError::injected_programs(empty_imports.len()).into()); - } - - let mut imported_symbols: Vec<(Vec, ImportSymbol, Span)> = vec![]; - for import_statement in import_statements.iter() { - resolve_import_package(&mut imported_symbols, vec![], &import_statement.package_or_packages); - } - - let mut deduplicated_imports: IndexMap, Span> = IndexMap::new(); - for (package, _symbol, span) in imported_symbols.iter() { - deduplicated_imports.insert(package.clone(), span.clone()); - } - - let mut wrapped_resolver = CoreImportResolver::new(&mut self.import_resolver); - - let mut resolved_packages: IndexMap, Program> = IndexMap::new(); - for (package, span) in deduplicated_imports { - let pretty_package = package.join("."); - - let resolved_package = - match wrapped_resolver.resolve_package(&package.iter().map(|x| &**x).collect::>()[..], &span)? { - Some(x) => x, - None => return Err(AstError::unresolved_import(pretty_package, &span).into()), - }; - - resolved_packages.insert(package.clone(), resolved_package); - } - - Ok(Program { - name: program.name.clone(), - expected_input, - import_statements, - imports: resolved_packages, - aliases, - circuits, - functions, - global_consts, - }) - } -} diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 3e22a03342..7d83268e48 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -251,7 +251,7 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { // Preform import resolution. ast = leo_ast_passes::Importer::do_pass( ast.into_repr(), - ImportParser::new(self.main_file_path.clone(), self.imports_map.clone()), + &mut ImportParser::new(self.main_file_path.clone(), self.imports_map.clone()), )?; if self.ast_snapshot_options.imports_resolved { diff --git a/imports/src/parser/parse_package.rs b/imports/src/parser/parse_package.rs index 0bb41db4e4..c041fe57d9 100644 --- a/imports/src/parser/parse_package.rs +++ b/imports/src/parser/parse_package.rs @@ -35,7 +35,10 @@ impl ImportParser { return self.parse_package(package.path(), remaining_segments, span); } - Self::parse_import_file(package, span) + let program = Self::parse_import_file(package, span)?; + let ast = leo_ast_passes::Importer::do_pass(program, self)?.into_repr(); + + Ok(ast) } /// diff --git a/test-framework/src/bin/tgc.rs b/test-framework/src/bin/tgc.rs index d92e4a0eaf..c55661b122 100644 --- a/test-framework/src/bin/tgc.rs +++ b/test-framework/src/bin/tgc.rs @@ -143,7 +143,7 @@ fn generate_asts(path: PathBuf, text: &str) -> Result<(String, String, String, S let mut ast = leo_parser::parse_ast(path.clone().into_os_string().into_string().unwrap(), text)?; let initial = ast.to_json_string()?; - ast = leo_ast_passes::Importer::do_pass(ast.into_repr(), ImportParser::new(path, Default::default()))?; + ast = leo_ast_passes::Importer::do_pass(ast.into_repr(), &mut ImportParser::new(path, Default::default()))?; let imports_resolved = ast.to_json_string()?; ast = leo_ast_passes::Canonicalizer::do_pass(ast.into_repr())?; diff --git a/tests/compiler/import_local/import_all.leo b/tests/compiler/import_local/import_all.leo index c03261c640..9839a6d139 100644 --- a/tests/compiler/import_local/import_all.leo +++ b/tests/compiler/import_local/import_all.leo @@ -12,6 +12,7 @@ function main(y: bool) -> bool { const hello_alias: char5 = "hello"; const hello = "hello"; const eight = 8u8; + const fab = fab_gen(); return( (foo() == 1u32) && hello_alias == hello && EIGHT == eight) == y; } diff --git a/tests/compiler/import_local/local_imports/circuits.leo b/tests/compiler/import_local/local_imports/circuits.leo index 32451e9ce7..0a6857c965 100644 --- a/tests/compiler/import_local/local_imports/circuits.leo +++ b/tests/compiler/import_local/local_imports/circuits.leo @@ -9,4 +9,10 @@ function foo() -> u32 { type char5 = [char; 5]; -const EIGHT = 8u8; \ No newline at end of file +const EIGHT = 8u8; + +import nested.c-d.Fab; + +function fab_gen() -> Fab { + return Fab { x: 3 }; +} \ No newline at end of file diff --git a/tests/compiler/import_local/local_imports/nested/c-d.leo b/tests/compiler/import_local/local_imports/nested/c-d.leo index 99a62646ee..e06de190df 100644 --- a/tests/compiler/import_local/local_imports/nested/c-d.leo +++ b/tests/compiler/import_local/local_imports/nested/c-d.leo @@ -1,3 +1,7 @@ +circuit Fab { + x: u8; +} + function cd() -> bool { return true; } diff --git a/tests/expectations/compiler/compiler/import_local/import_all.leo.out b/tests/expectations/compiler/compiler/import_local/import_all.leo.out index 4361f3ee2e..4b02dd6445 100644 --- a/tests/expectations/compiler/compiler/import_local/import_all.leo.out +++ b/tests/expectations/compiler/compiler/import_local/import_all.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: d2d8f4a8a59423b81f6f31d335762b57cf771ade0241acc6d61614d1fabfc618 - imports_resolved_ast: 95c9a6a9d333cdaff558735babd0d9a200d29fe752cb3a80288a69abecdc872d - canonicalized_ast: a2ef4029e1d95374b6b7f6b9e601acb6e4ee7481f7387fd0724149c548e46399 - type_inferenced_ast: b7d5149d5beae517ba02c0af1a23183ec28e3f763252be89baed9ba96a3e2786 + initial_ast: af29b4526e16fa59b0c58106f77bc4453a845480a04c82a321157d667c6d07c9 + imports_resolved_ast: ecd27f76f14e754b00f5c1b4d3f14092e76775865933668c7072885b77067e86 + canonicalized_ast: dedb5d6243d79db6a186b4cc8bfbf652c8dcf982c4fc8a32b4bf51e8cf689253 + type_inferenced_ast: 316391d0eec112e0fea34a14f2388c320f99d5da63211aea90cd7ca92eb81cf9 diff --git a/tests/expectations/compiler/compiler/import_local/import_many.leo.out b/tests/expectations/compiler/compiler/import_local/import_many.leo.out index e7cebd9f5c..83ca58a566 100644 --- a/tests/expectations/compiler/compiler/import_local/import_many.leo.out +++ b/tests/expectations/compiler/compiler/import_local/import_many.leo.out @@ -17,6 +17,6 @@ outputs: type: bool value: "true" initial_ast: ae6826642faa492e34507695dbd11e5b44c319aecb0b1e78b29ce03ae446d907 - imports_resolved_ast: 718ca8903a55a3b9208aea6c80d8969a5413a0499266c887b68dfea620f689e9 - canonicalized_ast: 718ca8903a55a3b9208aea6c80d8969a5413a0499266c887b68dfea620f689e9 - type_inferenced_ast: 9470aa103176806fd2d40b69224ec249e086fd5c70d56ebe22922e6cf39156e5 + imports_resolved_ast: 38cdae0ceb9feea0550ae88df86e9d0676c592fdc7a0a37f56da8c2d62dd3199 + canonicalized_ast: 38cdae0ceb9feea0550ae88df86e9d0676c592fdc7a0a37f56da8c2d62dd3199 + type_inferenced_ast: 93e0e825fc6daeabfd3891441979f4575d87a019996de7ce43241d1b535c5604 diff --git a/tests/expectations/compiler/compiler/import_local/import_weird_names_nested.leo.out b/tests/expectations/compiler/compiler/import_local/import_weird_names_nested.leo.out index acb4a60b7e..3a3b98103a 100644 --- a/tests/expectations/compiler/compiler/import_local/import_weird_names_nested.leo.out +++ b/tests/expectations/compiler/compiler/import_local/import_weird_names_nested.leo.out @@ -17,6 +17,6 @@ outputs: type: bool value: "true" initial_ast: bb86f336b58de89c79741628133e6aa997f3f49a6f066b8c054261e91e3f18a8 - imports_resolved_ast: 1fe862bf85cf0c88ce3c52066118d544f367984dbe97665b2719281de15c449c - canonicalized_ast: 1fe862bf85cf0c88ce3c52066118d544f367984dbe97665b2719281de15c449c - type_inferenced_ast: d8f6f5bde53232553d1ff891e7f78823645d9a8984139d06409cb2ccde562e76 + imports_resolved_ast: 7f53319b8eeb7fd2e7e76e7cbe6f130b3af9918060519cc111a45f9739cd8085 + canonicalized_ast: 7f53319b8eeb7fd2e7e76e7cbe6f130b3af9918060519cc111a45f9739cd8085 + type_inferenced_ast: 1fcfebcdbf04cba7f2878b8efe881f598407a0f15c5419bb7da7a8ea9ec37438 From 9c29f217750ba22c2e20239709d571ed903e6f67 Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Mon, 6 Sep 2021 08:14:24 -0700 Subject: [PATCH 12/28] document new function, remove old comments --- asg/src/program/function.rs | 8 -------- asg/src/program/mod.rs | 2 ++ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index 26efe0e8de..67bd656a57 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -89,14 +89,6 @@ impl<'a> Function<'a> { ) .into()); } - /* else if let Some(_) = scope.resolve_global_const(input_variable.identifier.name.as_ref()) { - // TODO ERROR FOR INPUT BEING NAMED AFTER GLOBAL CONST. - return Err(AsgError::duplicate_function_input_definition( - input_variable.identifier.name.as_ref(), - &input_variable.identifier.span, - ) - .into()); - } */ let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable { id: scope.context.get_id(), diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index 86a81cdbf9..51261a54b3 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -130,6 +130,8 @@ fn resolve_import_package_access( } } +/// Checks whether a given string is found in any other global namespaces. +/// If it is found it returns an error. fn check_top_level_namespaces<'a>( name: &str, span: &Span, From b45a722d6b092083af9a1d3c88e8ca8cc0b63eed Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Mon, 6 Sep 2021 13:02:20 -0700 Subject: [PATCH 13/28] [ABNF] Move two rules within file. No content change, just layout change. Prepares for next change to the file. --- grammar/abnf-grammar.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/grammar/abnf-grammar.txt b/grammar/abnf-grammar.txt index dbec25b6ba..0ce05fc0bb 100644 --- a/grammar/abnf-grammar.txt +++ b/grammar/abnf-grammar.txt @@ -659,17 +659,6 @@ character-type = %s"char" scalar-type = boolean-type / arithmetic-type / address-type / character-type -; Circuit types are denoted by identifiers and the keyword `Self`; -; the latter is only allowed inside a circuit definition, -; to denote the circuit type being defined. -; Identifiers may also be type aliases; -; syntactically (i.e. without a semantic analysis), -; they cannot be distinguished from circuit types. - -self-type = %s"Self" - -identifier-or-self-type = identifier / self-type - ; A tuple type consists of zero, two, or more component types. tuple-type = "(" [ type 1*( "," type ) ] ")" @@ -684,6 +673,17 @@ array-type = "[" type ";" array-dimensions "]" array-dimensions = natural / "(" natural *( "," natural ) ")" +; Circuit types are denoted by identifiers and the keyword `Self`; +; the latter is only allowed inside a circuit definition, +; to denote the circuit type being defined. +; Identifiers may also be type aliases; +; syntactically (i.e. without a semantic analysis), +; they cannot be distinguished from circuit types. + +self-type = %s"Self" + +identifier-or-self-type = identifier / self-type + ; Scalar and the remaining types form all the types. type = scalar-type / tuple-type / array-type / identifier-or-self-type From dab6f494b187c86afdfd23b2829158fdde70e633 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Mon, 6 Sep 2021 13:08:31 -0700 Subject: [PATCH 14/28] [ABNF] Improve formulation of rule for types. As discussed on GitHub, list identifiers separately from Self. Also adapt and improve some of the documentation comments. --- grammar/abnf-grammar.txt | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/grammar/abnf-grammar.txt b/grammar/abnf-grammar.txt index 0ce05fc0bb..e13b9b1aac 100644 --- a/grammar/abnf-grammar.txt +++ b/grammar/abnf-grammar.txt @@ -673,21 +673,28 @@ array-type = "[" type ";" array-dimensions "]" array-dimensions = natural / "(" natural *( "," natural ) ")" -; Circuit types are denoted by identifiers and the keyword `Self`; -; the latter is only allowed inside a circuit definition, -; to denote the circuit type being defined. +; The keyword `Self` denotes the enclosing circuit type. +; It is only allowed inside a circuit type declaration. + +self-type = %s"Self" + +; Circuit types are denoted by identifiers and by `Self`. ; Identifiers may also be type aliases; ; syntactically (i.e. without a semantic analysis), ; they cannot be distinguished from circuit types. -self-type = %s"Self" +; Scalar types, tuple types, array types, +; identifiers (which may be circuit types or type aliases), +; and the `Self` type +; form all the types. + +type = scalar-type / tuple-type / array-type / identifier / self-type + +; It is convenient to introduce a rule for types that are +; either identifiers or `Self`, as this is used in other rules. identifier-or-self-type = identifier / self-type -; Scalar and the remaining types form all the types. - -type = scalar-type / tuple-type / array-type / identifier-or-self-type - ; The lexical grammar given earlier defines product group literals. ; The other kind of group literal is a pair of integer coordinates, ; which are reduced modulo the prime to identify a point, From 593aac5636895bb509eebb6588ba2e074290992b Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Mon, 6 Sep 2021 13:10:55 -0700 Subject: [PATCH 15/28] [ABNF] Incorporate change for unspecified array sizes. That change was made on master concurrently with this PR. This commit integrates the concurrent changes. --- grammar/abnf-grammar.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/grammar/abnf-grammar.txt b/grammar/abnf-grammar.txt index e13b9b1aac..d0fb9dc44c 100644 --- a/grammar/abnf-grammar.txt +++ b/grammar/abnf-grammar.txt @@ -667,11 +667,14 @@ tuple-type = "(" [ type 1*( "," type ) ] ")" ; and an indication of dimensions. ; There is either a single dimension, ; or a tuple of one or more dimensions. +; Each dimension is either a natural or is unspecified. array-type = "[" type ";" array-dimensions "]" -array-dimensions = natural - / "(" natural *( "," natural ) ")" +array-dimension = natural / "_" + +array-dimensions = array-dimension + / "(" array-dimension *( "," array-dimension ) ")" ; The keyword `Self` denotes the enclosing circuit type. ; It is only allowed inside a circuit type declaration. From e9d61ab519df511d253c83ae44d951302c7f528e Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Mon, 6 Sep 2021 13:13:26 -0700 Subject: [PATCH 16/28] [ABNF] Regenerate markdown. --- grammar/README.md | 138 ++++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 61 deletions(-) diff --git a/grammar/README.md b/grammar/README.md index 5603ab524c..e3c7d5cb16 100644 --- a/grammar/README.md +++ b/grammar/README.md @@ -476,7 +476,7 @@ Line terminators form whitespace, along with spaces and horizontal tabs. whitespace = space / horizontal-tab / newline ``` -Go to: _[newline](#user-content-newline), [space](#user-content-space), [horizontal-tab](#user-content-horizontal-tab)_; +Go to: _[newline](#user-content-newline), [horizontal-tab](#user-content-horizontal-tab), [space](#user-content-space)_; There are two kinds of comments in Leo, as in other languages. @@ -494,7 +494,7 @@ the ones used in the Java language reference. comment = block-comment / end-of-line-comment ``` -Go to: _[end-of-line-comment](#user-content-end-of-line-comment), [block-comment](#user-content-block-comment)_; +Go to: _[block-comment](#user-content-block-comment), [end-of-line-comment](#user-content-end-of-line-comment)_; @@ -511,7 +511,7 @@ rest-of-block-comment = "*" rest-of-block-comment-after-star / not-star rest-of-block-comment ``` -Go to: _[rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star](#user-content-not-star), [rest-of-block-comment](#user-content-rest-of-block-comment)_; +Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star](#user-content-not-star)_; @@ -521,7 +521,7 @@ rest-of-block-comment-after-star = "/" / not-star-or-slash rest-of-block-comment ``` -Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star-or-slash](#user-content-not-star-or-slash)_; +Go to: _[not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star)_; @@ -774,7 +774,7 @@ character-literal-element = not-single-quote-or-backslash / unicode-character-escape ``` -Go to: _[ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape)_; +Go to: _[not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape), [ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape)_; @@ -829,7 +829,7 @@ simple-character-escape = single-quote-escape / null-character-escape ``` -Go to: _[horizontal-tab-escape](#user-content-horizontal-tab-escape), [null-character-escape](#user-content-null-character-escape), [carriage-return-escape](#user-content-carriage-return-escape), [backslash-escape](#user-content-backslash-escape), [single-quote-escape](#user-content-single-quote-escape), [double-quote-escape](#user-content-double-quote-escape), [line-feed-escape](#user-content-line-feed-escape)_; +Go to: _[carriage-return-escape](#user-content-carriage-return-escape), [backslash-escape](#user-content-backslash-escape), [single-quote-escape](#user-content-single-quote-escape), [line-feed-escape](#user-content-line-feed-escape), [horizontal-tab-escape](#user-content-horizontal-tab-escape), [null-character-escape](#user-content-null-character-escape), [double-quote-escape](#user-content-double-quote-escape)_; @@ -865,7 +865,7 @@ string-literal-element = not-double-quote-or-backslash / unicode-character-escape ``` -Go to: _[ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape), [not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash)_; +Go to: _[simple-character-escape](#user-content-simple-character-escape), [ascii-character-escape](#user-content-ascii-character-escape), [not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [unicode-character-escape](#user-content-unicode-character-escape)_; The ones above are all the atomic literals @@ -885,7 +885,7 @@ atomic-literal = untyped-literal / string-literal ``` -Go to: _[boolean-literal](#user-content-boolean-literal), [character-literal](#user-content-character-literal), [string-literal](#user-content-string-literal), [address-literal](#user-content-address-literal), [unsigned-literal](#user-content-unsigned-literal), [signed-literal](#user-content-signed-literal), [untyped-literal](#user-content-untyped-literal), [field-literal](#user-content-field-literal), [product-group-literal](#user-content-product-group-literal)_; +Go to: _[unsigned-literal](#user-content-unsigned-literal), [untyped-literal](#user-content-untyped-literal), [string-literal](#user-content-string-literal), [product-group-literal](#user-content-product-group-literal), [signed-literal](#user-content-signed-literal), [address-literal](#user-content-address-literal), [boolean-literal](#user-content-boolean-literal), [character-literal](#user-content-character-literal), [field-literal](#user-content-field-literal)_; After defining the (mostly) alphanumeric tokens above, @@ -929,7 +929,7 @@ token = keyword / symbol ``` -Go to: _[package-name](#user-content-package-name), [annotation-name](#user-content-annotation-name), [keyword](#user-content-keyword), [identifier](#user-content-identifier), [symbol](#user-content-symbol), [atomic-literal](#user-content-atomic-literal)_; +Go to: _[atomic-literal](#user-content-atomic-literal), [identifier](#user-content-identifier), [annotation-name](#user-content-annotation-name), [keyword](#user-content-keyword), [package-name](#user-content-package-name), [symbol](#user-content-symbol)_; Tokens, comments, and whitespace are lexemes, i.e. lexical units. @@ -939,7 +939,7 @@ Tokens, comments, and whitespace are lexemes, i.e. lexical units. lexeme = token / comment / whitespace ``` -Go to: _[token](#user-content-token), [comment](#user-content-comment), [whitespace](#user-content-whitespace)_; +Go to: _[token](#user-content-token), [whitespace](#user-content-whitespace), [comment](#user-content-comment)_; @@ -996,7 +996,7 @@ group-type = %s"group" arithmetic-type = integer-type / field-type / group-type ``` -Go to: _[integer-type](#user-content-integer-type), [group-type](#user-content-group-type), [field-type](#user-content-field-type)_; +Go to: _[field-type](#user-content-field-type), [group-type](#user-content-group-type), [integer-type](#user-content-integer-type)_; The arithmetic types, along with the boolean, address, and character types, @@ -1022,27 +1022,7 @@ character-type = %s"char" scalar-type = boolean-type / arithmetic-type / address-type / character-type ``` -Go to: _[arithmetic-type](#user-content-arithmetic-type), [boolean-type](#user-content-boolean-type), [character-type](#user-content-character-type), [address-type](#user-content-address-type)_; - - -Circuit types are denoted by identifiers and the keyword `Self`; -the latter is only allowed inside a circuit definition, -to denote the circuit type being defined. -Identifiers may also be type aliases; -syntactically (i.e. without a semantic analysis), -they cannot be distinguished from circuit types. - - -```abnf -self-type = %s"Self" -``` - - -```abnf -identifier-or-self-type = identifier / self-type -``` - -Go to: _[self-type](#user-content-self-type), [identifier](#user-content-identifier)_; +Go to: _[character-type](#user-content-character-type), [arithmetic-type](#user-content-arithmetic-type), [boolean-type](#user-content-boolean-type), [address-type](#user-content-address-type)_; A tuple type consists of zero, two, or more component types. @@ -1059,6 +1039,7 @@ An array type consists of an element type and an indication of dimensions. There is either a single dimension, or a tuple of one or more dimensions. +Each dimension is either a natural or is unspecified. ```abnf @@ -1068,23 +1049,58 @@ array-type = "[" type ";" array-dimensions "]" Go to: _[array-dimensions](#user-content-array-dimensions), [type](#user-content-type)_; - + ```abnf -array-dimensions = natural - / "(" natural *( "," natural ) ")" +array-dimension = natural / "_" ``` Go to: _[natural](#user-content-natural)_; -Scalar and the remaining types form all the types. + +```abnf +array-dimensions = array-dimension + / "(" array-dimension *( "," array-dimension ) ")" +``` + +Go to: _[array-dimension](#user-content-array-dimension)_; + + +The keyword `Self` denotes the enclosing circuit type. +It is only allowed inside a circuit type declaration. + + +```abnf +self-type = %s"Self" +``` + +Circuit types are denoted by identifiers and by `Self`. +Identifiers may also be type aliases; +syntactically (i.e. without a semantic analysis), +they cannot be distinguished from circuit types. + +Scalar types, tuple types, array types, +identifiers (which may be circuit types or type aliases), +and the `Self` type +form all the types. ```abnf -type = scalar-type / tuple-type / array-type / identifier-or-self-type +type = scalar-type / tuple-type / array-type / identifier / self-type ``` -Go to: _[array-type](#user-content-array-type), [tuple-type](#user-content-tuple-type), [scalar-type](#user-content-scalar-type), [identifier-or-self-type](#user-content-identifier-or-self-type)_; +Go to: _[identifier](#user-content-identifier), [scalar-type](#user-content-scalar-type), [self-type](#user-content-self-type), [array-type](#user-content-array-type), [tuple-type](#user-content-tuple-type)_; + + +It is convenient to introduce a rule for types that are +either identifiers or `Self`, as this is used in other rules. + + +```abnf +identifier-or-self-type = identifier / self-type +``` + +Go to: _[self-type](#user-content-self-type), [identifier](#user-content-identifier)_; The lexical grammar given earlier defines product group literals. @@ -1133,7 +1149,7 @@ a group literal is either a product group literal or an affine group literal. group-literal = product-group-literal / affine-group-literal ``` -Go to: _[affine-group-literal](#user-content-affine-group-literal), [product-group-literal](#user-content-product-group-literal)_; +Go to: _[product-group-literal](#user-content-product-group-literal), [affine-group-literal](#user-content-affine-group-literal)_; As often done in grammatical language syntax specifications, @@ -1162,7 +1178,7 @@ primary-expression = identifier / circuit-expression ``` -Go to: _[literal](#user-content-literal), [circuit-expression](#user-content-circuit-expression), [identifier](#user-content-identifier), [expression](#user-content-expression), [tuple-expression](#user-content-tuple-expression), [array-expression](#user-content-array-expression)_; +Go to: _[literal](#user-content-literal), [identifier](#user-content-identifier), [circuit-expression](#user-content-circuit-expression), [tuple-expression](#user-content-tuple-expression), [array-expression](#user-content-array-expression), [expression](#user-content-expression)_; Tuple expressions construct tuples. @@ -1215,7 +1231,7 @@ Go to: _[expression](#user-content-expression)_; array-repeat-construction = "[" expression ";" array-dimensions "]" ``` -Go to: _[expression](#user-content-expression), [array-dimensions](#user-content-array-dimensions)_; +Go to: _[array-dimensions](#user-content-array-dimensions), [expression](#user-content-expression)_; @@ -1223,7 +1239,7 @@ Go to: _[expression](#user-content-expression), [array-dimensions](#user-content array-construction = array-inline-construction / array-repeat-construction ``` -Go to: _[array-inline-construction](#user-content-array-inline-construction), [array-repeat-construction](#user-content-array-repeat-construction)_; +Go to: _[array-repeat-construction](#user-content-array-repeat-construction), [array-inline-construction](#user-content-array-inline-construction)_; @@ -1251,7 +1267,7 @@ circuit-construction = identifier-or-self-type "{" "}" ``` -Go to: _[identifier-or-self-type](#user-content-identifier-or-self-type), [circuit-inline-element](#user-content-circuit-inline-element)_; +Go to: _[circuit-inline-element](#user-content-circuit-inline-element), [identifier-or-self-type](#user-content-identifier-or-self-type)_; @@ -1259,7 +1275,7 @@ Go to: _[identifier-or-self-type](#user-content-identifier-or-self-type), [circu circuit-inline-element = identifier ":" expression / identifier ``` -Go to: _[expression](#user-content-expression), [identifier](#user-content-identifier)_; +Go to: _[identifier](#user-content-identifier), [expression](#user-content-expression)_; @@ -1310,7 +1326,7 @@ postfix-expression = primary-expression / postfix-expression "[" [expression] ".." [expression] "]" ``` -Go to: _[identifier](#user-content-identifier), [postfix-expression](#user-content-postfix-expression), [natural](#user-content-natural), [function-arguments](#user-content-function-arguments), [primary-expression](#user-content-primary-expression), [expression](#user-content-expression), [identifier-or-self-type](#user-content-identifier-or-self-type)_; +Go to: _[identifier-or-self-type](#user-content-identifier-or-self-type), [primary-expression](#user-content-primary-expression), [expression](#user-content-expression), [identifier](#user-content-identifier), [natural](#user-content-natural), [function-arguments](#user-content-function-arguments), [postfix-expression](#user-content-postfix-expression)_; Unary operators have the highest operator precedence. @@ -1324,7 +1340,7 @@ unary-expression = postfix-expression / "-" unary-expression ``` -Go to: _[unary-expression](#user-content-unary-expression), [postfix-expression](#user-content-postfix-expression)_; +Go to: _[postfix-expression](#user-content-postfix-expression), [unary-expression](#user-content-unary-expression)_; Next in the operator precedence is exponentiation, @@ -1338,7 +1354,7 @@ exponential-expression = unary-expression / unary-expression "**" exponential-expression ``` -Go to: _[exponential-expression](#user-content-exponential-expression), [unary-expression](#user-content-unary-expression)_; +Go to: _[unary-expression](#user-content-unary-expression), [exponential-expression](#user-content-exponential-expression)_; Next in precedence come multiplication and division, both left-associative. @@ -1425,7 +1441,7 @@ conditional-expression = disjunctive-expression ":" conditional-expression ``` -Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [expression](#user-content-expression), [conditional-expression](#user-content-conditional-expression)_; +Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [conditional-expression](#user-content-conditional-expression), [expression](#user-content-expression)_; Those above are all the expressions. @@ -1458,7 +1474,7 @@ statement = expression-statement / block ``` -Go to: _[return-statement](#user-content-return-statement), [constant-declaration](#user-content-constant-declaration), [assignment-statement](#user-content-assignment-statement), [console-statement](#user-content-console-statement), [block](#user-content-block), [conditional-statement](#user-content-conditional-statement), [variable-declaration](#user-content-variable-declaration), [expression-statement](#user-content-expression-statement), [loop-statement](#user-content-loop-statement)_; +Go to: _[assignment-statement](#user-content-assignment-statement), [expression-statement](#user-content-expression-statement), [conditional-statement](#user-content-conditional-statement), [constant-declaration](#user-content-constant-declaration), [block](#user-content-block), [console-statement](#user-content-console-statement), [return-statement](#user-content-return-statement), [variable-declaration](#user-content-variable-declaration), [loop-statement](#user-content-loop-statement)_; @@ -1501,7 +1517,7 @@ variable-declaration = %s"let" identifier-or-identifiers [ ":" type ] "=" expression ";" ``` -Go to: _[identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type), [expression](#user-content-expression)_; +Go to: _[expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type)_; @@ -1510,7 +1526,7 @@ constant-declaration = %s"const" identifier-or-identifiers [ ":" type ] "=" expression ";" ``` -Go to: _[identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type), [expression](#user-content-expression)_; +Go to: _[expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type)_; @@ -1543,7 +1559,7 @@ conditional-statement = branch / branch %s"else" conditional-statement ``` -Go to: _[conditional-statement](#user-content-conditional-statement), [branch](#user-content-branch), [block](#user-content-block)_; +Go to: _[branch](#user-content-branch), [block](#user-content-block), [conditional-statement](#user-content-conditional-statement)_; A loop statement implicitly defines a loop variable @@ -1556,7 +1572,7 @@ loop-statement = %s"for" identifier %s"in" expression ".." [ "=" ] expression block ``` -Go to: _[identifier](#user-content-identifier), [block](#user-content-block), [expression](#user-content-expression)_; +Go to: _[identifier](#user-content-identifier), [expression](#user-content-expression), [block](#user-content-block)_; An assignment statement is straightforward. @@ -1600,7 +1616,7 @@ console-call = assert-call / print-call ``` -Go to: _[print-call](#user-content-print-call), [assert-call](#user-content-assert-call)_; +Go to: _[assert-call](#user-content-assert-call), [print-call](#user-content-print-call)_; @@ -1642,7 +1658,7 @@ annotation = annotation-name [ "(" identifier *( "," identifier ) ")" ] ``` -Go to: _[annotation-name](#user-content-annotation-name), [identifier](#user-content-identifier)_; +Go to: _[identifier](#user-content-identifier), [annotation-name](#user-content-annotation-name)_; A function declaration defines a function. @@ -1659,7 +1675,7 @@ function-declaration = *annotation %s"function" identifier block ``` -Go to: _[type](#user-content-type), [block](#user-content-block), [identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters)_; +Go to: _[identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters), [type](#user-content-type), [block](#user-content-block)_; @@ -1669,7 +1685,7 @@ function-parameters = self-parameter / function-inputs ``` -Go to: _[function-inputs](#user-content-function-inputs), [self-parameter](#user-content-self-parameter)_; +Go to: _[self-parameter](#user-content-self-parameter), [function-inputs](#user-content-function-inputs)_; @@ -1760,7 +1776,7 @@ by using an explicit package name before the package path. import-declaration = %s"import" package-name "." package-path ";" ``` -Go to: _[package-path](#user-content-package-path), [package-name](#user-content-package-name)_; +Go to: _[package-name](#user-content-package-name), [package-path](#user-content-package-path)_; @@ -1771,7 +1787,7 @@ package-path = "*" / "(" package-path *( "," package-path ) [","] ")" ``` -Go to: _[package-path](#user-content-package-path), [package-name](#user-content-package-name), [identifier](#user-content-identifier)_; +Go to: _[package-path](#user-content-package-path), [identifier](#user-content-identifier), [package-name](#user-content-package-name)_; A type alias declaration defines an identifier to stand for a type. @@ -1781,7 +1797,7 @@ A type alias declaration defines an identifier to stand for a type. type-alias-declaration = %s"type" identifier "=" type ";" ``` -Go to: _[type](#user-content-type), [identifier](#user-content-identifier)_; +Go to: _[identifier](#user-content-identifier), [type](#user-content-type)_; Finally, we define a file as a sequence of zero or more declarations. @@ -1797,7 +1813,7 @@ declaration = import-declaration / type-alias-declaration ``` -Go to: _[constant-declaration](#user-content-constant-declaration), [type-alias-declaration](#user-content-type-alias-declaration), [circuit-declaration](#user-content-circuit-declaration), [import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration)_; +Go to: _[import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration), [circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration), [type-alias-declaration](#user-content-type-alias-declaration)_; From fe77354db7a392919ce3e8409183c6642e9382f7 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Mon, 6 Sep 2021 13:17:19 -0700 Subject: [PATCH 17/28] [ABNF] Re-generate markdown file. --- grammar/README.md | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/grammar/README.md b/grammar/README.md index e3c7d5cb16..e0a413f4a8 100644 --- a/grammar/README.md +++ b/grammar/README.md @@ -476,7 +476,7 @@ Line terminators form whitespace, along with spaces and horizontal tabs. whitespace = space / horizontal-tab / newline ``` -Go to: _[newline](#user-content-newline), [horizontal-tab](#user-content-horizontal-tab), [space](#user-content-space)_; +Go to: _[newline](#user-content-newline), [space](#user-content-space), [horizontal-tab](#user-content-horizontal-tab)_; There are two kinds of comments in Leo, as in other languages. @@ -521,7 +521,7 @@ rest-of-block-comment-after-star = "/" / not-star-or-slash rest-of-block-comment ``` -Go to: _[not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star)_; +Go to: _[rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment)_; @@ -590,7 +590,7 @@ lowercase-letter = %x61-7A ; a-z letter = uppercase-letter / lowercase-letter ``` -Go to: _[uppercase-letter](#user-content-uppercase-letter), [lowercase-letter](#user-content-lowercase-letter)_; +Go to: _[lowercase-letter](#user-content-lowercase-letter), [uppercase-letter](#user-content-uppercase-letter)_; The following rules defines (ASCII) decimal, octal, and hexadecimal digits. @@ -774,7 +774,7 @@ character-literal-element = not-single-quote-or-backslash / unicode-character-escape ``` -Go to: _[not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape), [ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape)_; +Go to: _[ascii-character-escape](#user-content-ascii-character-escape), [simple-character-escape](#user-content-simple-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash)_; @@ -829,7 +829,7 @@ simple-character-escape = single-quote-escape / null-character-escape ``` -Go to: _[carriage-return-escape](#user-content-carriage-return-escape), [backslash-escape](#user-content-backslash-escape), [single-quote-escape](#user-content-single-quote-escape), [line-feed-escape](#user-content-line-feed-escape), [horizontal-tab-escape](#user-content-horizontal-tab-escape), [null-character-escape](#user-content-null-character-escape), [double-quote-escape](#user-content-double-quote-escape)_; +Go to: _[line-feed-escape](#user-content-line-feed-escape), [carriage-return-escape](#user-content-carriage-return-escape), [double-quote-escape](#user-content-double-quote-escape), [backslash-escape](#user-content-backslash-escape), [null-character-escape](#user-content-null-character-escape), [single-quote-escape](#user-content-single-quote-escape), [horizontal-tab-escape](#user-content-horizontal-tab-escape)_; @@ -837,7 +837,7 @@ Go to: _[carriage-return-escape](#user-content-carriage-return-escape), [backsla ascii-character-escape = %s"\x" octal-digit hexadecimal-digit ``` -Go to: _[hexadecimal-digit](#user-content-hexadecimal-digit), [octal-digit](#user-content-octal-digit)_; +Go to: _[octal-digit](#user-content-octal-digit), [hexadecimal-digit](#user-content-hexadecimal-digit)_; @@ -865,7 +865,7 @@ string-literal-element = not-double-quote-or-backslash / unicode-character-escape ``` -Go to: _[simple-character-escape](#user-content-simple-character-escape), [ascii-character-escape](#user-content-ascii-character-escape), [not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [unicode-character-escape](#user-content-unicode-character-escape)_; +Go to: _[simple-character-escape](#user-content-simple-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape)_; The ones above are all the atomic literals @@ -885,7 +885,7 @@ atomic-literal = untyped-literal / string-literal ``` -Go to: _[unsigned-literal](#user-content-unsigned-literal), [untyped-literal](#user-content-untyped-literal), [string-literal](#user-content-string-literal), [product-group-literal](#user-content-product-group-literal), [signed-literal](#user-content-signed-literal), [address-literal](#user-content-address-literal), [boolean-literal](#user-content-boolean-literal), [character-literal](#user-content-character-literal), [field-literal](#user-content-field-literal)_; +Go to: _[character-literal](#user-content-character-literal), [unsigned-literal](#user-content-unsigned-literal), [signed-literal](#user-content-signed-literal), [address-literal](#user-content-address-literal), [field-literal](#user-content-field-literal), [untyped-literal](#user-content-untyped-literal), [product-group-literal](#user-content-product-group-literal), [string-literal](#user-content-string-literal), [boolean-literal](#user-content-boolean-literal)_; After defining the (mostly) alphanumeric tokens above, @@ -929,7 +929,7 @@ token = keyword / symbol ``` -Go to: _[atomic-literal](#user-content-atomic-literal), [identifier](#user-content-identifier), [annotation-name](#user-content-annotation-name), [keyword](#user-content-keyword), [package-name](#user-content-package-name), [symbol](#user-content-symbol)_; +Go to: _[identifier](#user-content-identifier), [annotation-name](#user-content-annotation-name), [package-name](#user-content-package-name), [keyword](#user-content-keyword), [symbol](#user-content-symbol), [atomic-literal](#user-content-atomic-literal)_; Tokens, comments, and whitespace are lexemes, i.e. lexical units. @@ -975,7 +975,7 @@ signed-type = %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128" integer-type = unsigned-type / signed-type ``` -Go to: _[signed-type](#user-content-signed-type), [unsigned-type](#user-content-unsigned-type)_; +Go to: _[unsigned-type](#user-content-unsigned-type), [signed-type](#user-content-signed-type)_; The integer types, along with the field and group types, @@ -1022,7 +1022,7 @@ character-type = %s"char" scalar-type = boolean-type / arithmetic-type / address-type / character-type ``` -Go to: _[character-type](#user-content-character-type), [arithmetic-type](#user-content-arithmetic-type), [boolean-type](#user-content-boolean-type), [address-type](#user-content-address-type)_; +Go to: _[boolean-type](#user-content-boolean-type), [arithmetic-type](#user-content-arithmetic-type), [character-type](#user-content-character-type), [address-type](#user-content-address-type)_; A tuple type consists of zero, two, or more component types. @@ -1089,7 +1089,7 @@ form all the types. type = scalar-type / tuple-type / array-type / identifier / self-type ``` -Go to: _[identifier](#user-content-identifier), [scalar-type](#user-content-scalar-type), [self-type](#user-content-self-type), [array-type](#user-content-array-type), [tuple-type](#user-content-tuple-type)_; +Go to: _[array-type](#user-content-array-type), [scalar-type](#user-content-scalar-type), [tuple-type](#user-content-tuple-type), [identifier](#user-content-identifier), [self-type](#user-content-self-type)_; It is convenient to introduce a rule for types that are @@ -1178,7 +1178,7 @@ primary-expression = identifier / circuit-expression ``` -Go to: _[literal](#user-content-literal), [identifier](#user-content-identifier), [circuit-expression](#user-content-circuit-expression), [tuple-expression](#user-content-tuple-expression), [array-expression](#user-content-array-expression), [expression](#user-content-expression)_; +Go to: _[tuple-expression](#user-content-tuple-expression), [array-expression](#user-content-array-expression), [identifier](#user-content-identifier), [literal](#user-content-literal), [expression](#user-content-expression), [circuit-expression](#user-content-circuit-expression)_; Tuple expressions construct tuples. @@ -1231,7 +1231,7 @@ Go to: _[expression](#user-content-expression)_; array-repeat-construction = "[" expression ";" array-dimensions "]" ``` -Go to: _[array-dimensions](#user-content-array-dimensions), [expression](#user-content-expression)_; +Go to: _[expression](#user-content-expression), [array-dimensions](#user-content-array-dimensions)_; @@ -1239,7 +1239,7 @@ Go to: _[array-dimensions](#user-content-array-dimensions), [expression](#user-c array-construction = array-inline-construction / array-repeat-construction ``` -Go to: _[array-repeat-construction](#user-content-array-repeat-construction), [array-inline-construction](#user-content-array-inline-construction)_; +Go to: _[array-inline-construction](#user-content-array-inline-construction), [array-repeat-construction](#user-content-array-repeat-construction)_; @@ -1267,7 +1267,7 @@ circuit-construction = identifier-or-self-type "{" "}" ``` -Go to: _[circuit-inline-element](#user-content-circuit-inline-element), [identifier-or-self-type](#user-content-identifier-or-self-type)_; +Go to: _[identifier-or-self-type](#user-content-identifier-or-self-type), [circuit-inline-element](#user-content-circuit-inline-element)_; @@ -1326,7 +1326,7 @@ postfix-expression = primary-expression / postfix-expression "[" [expression] ".." [expression] "]" ``` -Go to: _[identifier-or-self-type](#user-content-identifier-or-self-type), [primary-expression](#user-content-primary-expression), [expression](#user-content-expression), [identifier](#user-content-identifier), [natural](#user-content-natural), [function-arguments](#user-content-function-arguments), [postfix-expression](#user-content-postfix-expression)_; +Go to: _[function-arguments](#user-content-function-arguments), [primary-expression](#user-content-primary-expression), [expression](#user-content-expression), [postfix-expression](#user-content-postfix-expression), [identifier](#user-content-identifier), [natural](#user-content-natural), [identifier-or-self-type](#user-content-identifier-or-self-type)_; Unary operators have the highest operator precedence. @@ -1340,7 +1340,7 @@ unary-expression = postfix-expression / "-" unary-expression ``` -Go to: _[postfix-expression](#user-content-postfix-expression), [unary-expression](#user-content-unary-expression)_; +Go to: _[unary-expression](#user-content-unary-expression), [postfix-expression](#user-content-postfix-expression)_; Next in the operator precedence is exponentiation, @@ -1354,7 +1354,7 @@ exponential-expression = unary-expression / unary-expression "**" exponential-expression ``` -Go to: _[unary-expression](#user-content-unary-expression), [exponential-expression](#user-content-exponential-expression)_; +Go to: _[exponential-expression](#user-content-exponential-expression), [unary-expression](#user-content-unary-expression)_; Next in precedence come multiplication and division, both left-associative. @@ -1366,7 +1366,7 @@ multiplicative-expression = exponential-expression / multiplicative-expression "/" exponential-expression ``` -Go to: _[exponential-expression](#user-content-exponential-expression), [multiplicative-expression](#user-content-multiplicative-expression)_; +Go to: _[multiplicative-expression](#user-content-multiplicative-expression), [exponential-expression](#user-content-exponential-expression)_; Then there are addition and subtraction, both left-assocative. @@ -1441,7 +1441,7 @@ conditional-expression = disjunctive-expression ":" conditional-expression ``` -Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [conditional-expression](#user-content-conditional-expression), [expression](#user-content-expression)_; +Go to: _[expression](#user-content-expression), [disjunctive-expression](#user-content-disjunctive-expression), [conditional-expression](#user-content-conditional-expression)_; Those above are all the expressions. @@ -1474,7 +1474,7 @@ statement = expression-statement / block ``` -Go to: _[assignment-statement](#user-content-assignment-statement), [expression-statement](#user-content-expression-statement), [conditional-statement](#user-content-conditional-statement), [constant-declaration](#user-content-constant-declaration), [block](#user-content-block), [console-statement](#user-content-console-statement), [return-statement](#user-content-return-statement), [variable-declaration](#user-content-variable-declaration), [loop-statement](#user-content-loop-statement)_; +Go to: _[loop-statement](#user-content-loop-statement), [expression-statement](#user-content-expression-statement), [console-statement](#user-content-console-statement), [block](#user-content-block), [return-statement](#user-content-return-statement), [variable-declaration](#user-content-variable-declaration), [constant-declaration](#user-content-constant-declaration), [assignment-statement](#user-content-assignment-statement), [conditional-statement](#user-content-conditional-statement)_; @@ -1517,7 +1517,7 @@ variable-declaration = %s"let" identifier-or-identifiers [ ":" type ] "=" expression ";" ``` -Go to: _[expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type)_; +Go to: _[identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type), [expression](#user-content-expression)_; @@ -1526,7 +1526,7 @@ constant-declaration = %s"const" identifier-or-identifiers [ ":" type ] "=" expression ";" ``` -Go to: _[expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type)_; +Go to: _[expression](#user-content-expression), [type](#user-content-type), [identifier-or-identifiers](#user-content-identifier-or-identifiers)_; @@ -1549,7 +1549,7 @@ Note that blocks are required in all branches, not merely statements. branch = %s"if" expression block ``` -Go to: _[block](#user-content-block), [expression](#user-content-expression)_; +Go to: _[expression](#user-content-expression), [block](#user-content-block)_; @@ -1559,7 +1559,7 @@ conditional-statement = branch / branch %s"else" conditional-statement ``` -Go to: _[branch](#user-content-branch), [block](#user-content-block), [conditional-statement](#user-content-conditional-statement)_; +Go to: _[block](#user-content-block), [conditional-statement](#user-content-conditional-statement), [branch](#user-content-branch)_; A loop statement implicitly defines a loop variable @@ -1572,7 +1572,7 @@ loop-statement = %s"for" identifier %s"in" expression ".." [ "=" ] expression block ``` -Go to: _[identifier](#user-content-identifier), [expression](#user-content-expression), [block](#user-content-block)_; +Go to: _[expression](#user-content-expression), [identifier](#user-content-identifier), [block](#user-content-block)_; An assignment statement is straightforward. @@ -1589,7 +1589,7 @@ assignment-operator = "=" / "+=" / "-=" / "*=" / "/=" / "**=" assignment-statement = expression assignment-operator expression ";" ``` -Go to: _[assignment-operator](#user-content-assignment-operator), [expression](#user-content-expression)_; +Go to: _[expression](#user-content-expression), [assignment-operator](#user-content-assignment-operator)_; Console statements start with the `console` keyword, @@ -1616,7 +1616,7 @@ console-call = assert-call / print-call ``` -Go to: _[assert-call](#user-content-assert-call), [print-call](#user-content-print-call)_; +Go to: _[print-call](#user-content-print-call), [assert-call](#user-content-assert-call)_; @@ -1658,7 +1658,7 @@ annotation = annotation-name [ "(" identifier *( "," identifier ) ")" ] ``` -Go to: _[identifier](#user-content-identifier), [annotation-name](#user-content-annotation-name)_; +Go to: _[annotation-name](#user-content-annotation-name), [identifier](#user-content-identifier)_; A function declaration defines a function. @@ -1675,7 +1675,7 @@ function-declaration = *annotation %s"function" identifier block ``` -Go to: _[identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters), [type](#user-content-type), [block](#user-content-block)_; +Go to: _[identifier](#user-content-identifier), [type](#user-content-type), [block](#user-content-block), [function-parameters](#user-content-function-parameters)_; @@ -1685,7 +1685,7 @@ function-parameters = self-parameter / function-inputs ``` -Go to: _[self-parameter](#user-content-self-parameter), [function-inputs](#user-content-function-inputs)_; +Go to: _[function-inputs](#user-content-function-inputs), [self-parameter](#user-content-self-parameter)_; @@ -1813,7 +1813,7 @@ declaration = import-declaration / type-alias-declaration ``` -Go to: _[import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration), [circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration), [type-alias-declaration](#user-content-type-alias-declaration)_; +Go to: _[circuit-declaration](#user-content-circuit-declaration), [import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration), [constant-declaration](#user-content-constant-declaration), [type-alias-declaration](#user-content-type-alias-declaration)_; From b39eab953d745b9929c5ce1f73c2552433d783e9 Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Tue, 7 Sep 2021 01:50:41 -0700 Subject: [PATCH 18/28] regen test after merge --- .../compiler/array_without_size/type_alias.leo.out | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/expectations/compiler/compiler/array_without_size/type_alias.leo.out b/tests/expectations/compiler/compiler/array_without_size/type_alias.leo.out index 5e0c6d6871..23713b3ffe 100644 --- a/tests/expectations/compiler/compiler/array_without_size/type_alias.leo.out +++ b/tests/expectations/compiler/compiler/array_without_size/type_alias.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: 1695abb58931812bfe65ffdb967c9e8e36abbab771bfd8a20e289e3e1b102b5a - imports_resolved_ast: 1695abb58931812bfe65ffdb967c9e8e36abbab771bfd8a20e289e3e1b102b5a - canonicalized_ast: 637eaabe62c318b0c9f9d6d26936c11aa8804022866ce356e14dc02e29a34251 - type_inferenced_ast: 1540899195a176d1b1d0e1d886a671f07f063dd10fea15f853e67ffcfc0ae9ce + initial_ast: 0e8ea2eb2de2ad93883ced129ab7c42674fd476d94ede483f5ea042f8386b730 + imports_resolved_ast: 0e8ea2eb2de2ad93883ced129ab7c42674fd476d94ede483f5ea042f8386b730 + canonicalized_ast: 529ba1d5564ef0c1752343e3e6e8b181f13bec0620c4ecbe23080ef4a080cb2b + type_inferenced_ast: b4d3305f7179dfc2a7a330e538a41e3cdf51f12e4a6545cd57ff9a2e5a9d1db0 From 2e51e81be1959e719d44f2b4ad8fa6200a7915b9 Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Tue, 7 Sep 2021 02:05:15 -0700 Subject: [PATCH 19/28] mere conflicts, try to fix duplicate definition fail test --- tests/compiler/function/duplicate_definition_fail.leo | 6 ++++-- .../compiler/function/duplicate_definition_fail.leo.out | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/compiler/function/duplicate_definition_fail.leo b/tests/compiler/function/duplicate_definition_fail.leo index 43ec30e787..9b003b6015 100644 --- a/tests/compiler/function/duplicate_definition_fail.leo +++ b/tests/compiler/function/duplicate_definition_fail.leo @@ -5,10 +5,12 @@ input_file: input/dummy.in */ -function main() { +function main(y: bool) -> bool { console.log("{}", 1u8); + return y; } -function main() { +function main(y: bool) -> bool { console.log("{}", 2u8); + return y; } diff --git a/tests/expectations/compiler/compiler/function/duplicate_definition_fail.leo.out b/tests/expectations/compiler/compiler/function/duplicate_definition_fail.leo.out index 3d740f571f..c7ba950269 100644 --- a/tests/expectations/compiler/compiler/function/duplicate_definition_fail.leo.out +++ b/tests/expectations/compiler/compiler/function/duplicate_definition_fail.leo.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [EASG0373015]: a function named \"main\" already exists in this scope\n --> compiler-test:8:1\n |\n 8 | function main() {\n 9 | ...\n 10 | }\n | ^" + - "Error [EASG0373015]: a function named \"main\" already exists in this scope\n --> compiler-test:9:1\n |\n 9 | function main(y: bool) -> bool {\n 10 | ...\n 11 | ...\n 12 | }\n | ^" From d1dd42a70a6c3fc9fa235448070a1cd71c58f005 Mon Sep 17 00:00:00 2001 From: Damir S Date: Tue, 7 Sep 2021 13:11:44 +0300 Subject: [PATCH 20/28] [Bug] Fix ordering in unexpected_type error (#1329) fixes ordering in ASG::unexpected_type error --- asg/src/expression/array_init.rs | 2 +- asg/src/expression/array_inline.rs | 2 +- asg/src/expression/array_range_access.rs | 2 +- asg/src/expression/binary.rs | 12 +++++++----- asg/src/expression/circuit_access.rs | 2 +- asg/src/expression/tuple_access.rs | 2 +- asg/src/expression/unary.rs | 6 +++--- errors/src/asg/asg_errors.rs | 7 +++++++ 8 files changed, 22 insertions(+), 13 deletions(-) diff --git a/asg/src/expression/array_init.rs b/asg/src/expression/array_init.rs index 23ea049271..d493d07290 100644 --- a/asg/src/expression/array_init.rs +++ b/asg/src/expression/array_init.rs @@ -74,7 +74,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> { Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims), None => (None, None), Some(type_) => { - return Err(AsgError::unexpected_type(type_, "array", &value.span).into()); + return Err(AsgError::unexpected_type("array", type_, &value.span).into()); } }; let dimensions = value diff --git a/asg/src/expression/array_inline.rs b/asg/src/expression/array_inline.rs index 9d79c50f95..de9772e419 100644 --- a/asg/src/expression/array_inline.rs +++ b/asg/src/expression/array_inline.rs @@ -110,7 +110,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<' Some(PartialType::Type(Type::ArrayWithoutSize(item))) => (Some(item.partial()), None), None => (None, None), Some(type_) => { - return Err(AsgError::unexpected_type(type_, "array", &value.span).into()); + return Err(AsgError::unexpected_type("array", type_, &value.span).into()); } }; diff --git a/asg/src/expression/array_range_access.rs b/asg/src/expression/array_range_access.rs index 0d32f3933f..af54b1a2b0 100644 --- a/asg/src/expression/array_range_access.rs +++ b/asg/src/expression/array_range_access.rs @@ -108,7 +108,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx Some(PartialType::Array(element, len)) => (Some(PartialType::Array(element, None)), len), None => (None, None), Some(x) => { - return Err(AsgError::unexpected_type(x, "array", &value.span).into()); + return Err(AsgError::unexpected_type("array", x, &value.span).into()); } }; let array = <&Expression<'a>>::from_ast(scope, &*value.array, expected_array)?; diff --git a/asg/src/expression/binary.rs b/asg/src/expression/binary.rs index 3029e2b98c..c5b2d4ab2b 100644 --- a/asg/src/expression/binary.rs +++ b/asg/src/expression/binary.rs @@ -123,7 +123,7 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { BinaryOperationClass::Boolean => match expected_type { Some(PartialType::Type(Type::Boolean)) | None => None, Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span).into()); + return Err(AsgError::unexpected_type(Type::Boolean, x, &value.span).into()); } }, BinaryOperationClass::Numeric => match expected_type { @@ -131,7 +131,7 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { Some(x @ PartialType::Type(Type::Field)) => Some(x), Some(x @ PartialType::Type(Type::Group)) => Some(x), Some(x) => { - return Err(AsgError::unexpected_type(x, "integer, field, or group", &value.span).into()); + return Err(AsgError::unexpected_type("integer, field, or group", x, &value.span).into()); } None => None, }, @@ -192,14 +192,16 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { BinaryOperation::And | BinaryOperation::Or => match left_type { Some(Type::Boolean) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span).into()); + return Err(AsgError::unexpected_type(Type::Boolean, x, &value.span).into()); } }, BinaryOperation::Eq | BinaryOperation::Ne => (), // all types allowed - _ => match left_type { + op => match left_type { Some(Type::Integer(_)) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, "integer", &value.span).into()); + return Err( + AsgError::operator_allowed_only_for_type(op.as_ref(), "integer", x, &value.span).into(), + ); } }, }, diff --git a/asg/src/expression/circuit_access.rs b/asg/src/expression/circuit_access.rs index b01dca1ff3..9003a4cca0 100644 --- a/asg/src/expression/circuit_access.rs +++ b/asg/src/expression/circuit_access.rs @@ -172,7 +172,7 @@ impl<'a> FromAst<'a, leo_ast::CircuitStaticFunctionAccessExpression> for Circuit }; if let Some(expected_type) = expected_type { - return Err(AsgError::unexpected_type(expected_type, "none", &value.span).into()); + return Err(AsgError::unexpected_type("none", expected_type, &value.span).into()); } if let Some(CircuitMember::Function(_)) = circuit.members.borrow().get(value.name.name.as_ref()) { diff --git a/asg/src/expression/tuple_access.rs b/asg/src/expression/tuple_access.rs index 327ed51548..44f524aec0 100644 --- a/asg/src/expression/tuple_access.rs +++ b/asg/src/expression/tuple_access.rs @@ -90,7 +90,7 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<' if let Some(Type::Tuple(_items)) = tuple_type { } else { return Err(AsgError::unexpected_type( - "a tuple", + "tuple", tuple_type .map(|x| x.to_string()) .unwrap_or_else(|| "unknown".to_string()), diff --git a/asg/src/expression/unary.rs b/asg/src/expression/unary.rs index a9da91eec6..d3aad2dea0 100644 --- a/asg/src/expression/unary.rs +++ b/asg/src/expression/unary.rs @@ -95,7 +95,7 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { UnaryOperation::Not => match expected_type.map(|x| x.full()).flatten() { Some(Type::Boolean) | None => Some(Type::Boolean), Some(type_) => { - return Err(AsgError::unexpected_type(type_, Type::Boolean, &value.span).into()); + return Err(AsgError::unexpected_type(Type::Boolean, type_, &value.span).into()); } }, UnaryOperation::Negate => match expected_type.map(|x| x.full()).flatten() { @@ -104,14 +104,14 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { Some(Type::Field) => Some(Type::Field), None => None, Some(type_) => { - return Err(AsgError::unexpected_type(type_, "integer, group, field", &value.span).into()); + return Err(AsgError::unexpected_type("integer, group, field", type_, &value.span).into()); } }, UnaryOperation::BitNot => match expected_type.map(|x| x.full()).flatten() { Some(type_ @ Type::Integer(_)) => Some(type_), None => None, Some(type_) => { - return Err(AsgError::unexpected_type(type_, "integer", &value.span).into()); + return Err(AsgError::unexpected_type("integer", type_, &value.span).into()); } }, }; diff --git a/errors/src/asg/asg_errors.rs b/errors/src/asg/asg_errors.rs index 6524b6ab95..b507af18e4 100644 --- a/errors/src/asg/asg_errors.rs +++ b/errors/src/asg/asg_errors.rs @@ -467,4 +467,11 @@ create_errors!( msg: format!("a variable cannot be named `{}` as a function input or variable with that name already exists in this scope", name), help: None, } + + @formatted + operator_allowed_only_for_type { + args: (operator: impl Display, type_: impl Display, received: impl Display), + msg: format!("operator '{}' is only allowed for type '{}', received: '{}'", operator, type_, received), + help: None, + } ); From 9ac0510cb92a3273f6f0c83e21e6e29177cbb639 Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Tue, 7 Sep 2021 03:58:28 -0700 Subject: [PATCH 21/28] update rfc #8 --- docs/rfc/008-built-in-declarations.md | 68 +++++++++++---------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/docs/rfc/008-built-in-declarations.md b/docs/rfc/008-built-in-declarations.md index 4f710ec3a0..96e764e319 100644 --- a/docs/rfc/008-built-in-declarations.md +++ b/docs/rfc/008-built-in-declarations.md @@ -15,24 +15,19 @@ DRAFT -# Summary +## Summary -This RFC proposes a framework for making certain (top-level) declarations (e.g. type aliases) -available in every Leo program without the need to explicitly write those declarations. -These may be hardwired into the language, or provided by standard libraries/packages; -in the latter case, the libraries may be either implicitly imported or required to be explicitly imported. +This RFC proposes a framework for making certain (top-level) declarations (e.g. type aliases) available in every Leo program without the need to write those declarations explicitly. These may be hardwired into the language or provided by standard libraries/packages; in the latter case, the libraries may be implicitly imported or required to be explicitly imported. -# Motivation +## Motivation It is common for programming languages to provide predefined types, functions, etc. -that can be readily used in programs. -The initial motivation for this in Leo was to have a type alias `string` for character arrays of unspecified sizes -(array types of unspecified sizes and type aliases are discussed in separate RFCs), -but the feature is clearly more general. +that can be readily used in programs. The initial motivation for this in Leo was to have a type alias `string` for character arrays of unspecified sizes (array types of unspecified sizes and type aliases are discussed in separate RFCs), but the feature is clearly more general. -# Design +## Design Leo supports four kinds of top-level declarations: + - Import declarations. - Function declarations. - Circuit type declarations. @@ -41,42 +36,33 @@ Leo supports four kinds of top-level declarations: Leaving import declarations aside for the moment since they are "meta" in some sense (as they bring in names of entities declared elsewhere), -it may make sense for any of the four kinds of declarations above to have built-in instances, -i.e. we could have some built-in functions, circuit types, global constants, and type aliases. -This is why this RFC talks of built-in declarations, more broadly than just built-in type aliases that inspired it. +it may make sense for any of the four kinds of declarations above to have built-in instances, i.e., we could have some built-in functions, circuit types, global constants, and type aliases. These features are why this RFC talks of built-in declarations, more broadly than just built-in type aliases that inspired it. -The built-in status of the envisioned declarations could be achieved in slightly different ways: -1. Their names could be simply available in any program, - without any explicit declaration found anywhere for them. -2. They could be declared in some core library files explicitly, - and be available in any program without needing to be explicitly import them, - like `java.lang.String` in Java or `std::Option` in Rust. -3. They could be declared in some core library files explicitly, - and be available only in programs that explicitly import them. +The built-in status of the envisioned declarations will be done through explicitly declared core library files. Then these core library files must be explicitly imported. This way helps avoid unnecessary code bloat in the compilation, and any user asked for AST snapshots. -From a user's perspective, there is not a lot of difference between cases 1 and 2 above: -in both cases, the names are available; the only difference is that in case 2 the user can see the declaration somewhere. - -Also note that case 2 could be seen as having an implicit (i.e. built-in) import of the library/libraries in question. -Again, imports are "meta" in this context, and what counts are really the other kinds of declarations. - -In cases 2 and 3, a related but somewhat independent issue is whether those declarations have Leo definitions or not. -The Leo library already includes functions like the one for BLAKE2s that are not defined in Leo, -but rather "natively" in Rust/R1CS. - -# Drawbacks +## Drawbacks This does not seem to bring any drawbacks. -# Effect on Ecosystem +## Effect on Ecosystem -This may interact with libraries and packages in some way, +This change may interact with libraries and packages in some way, if we go with case 2 or 3 above. -But it should be not much different from regular libraries/packages. +But it should not be much different from standard libraries/packages. -# Alternatives +## Alternatives -The 'Design' section above currently discusses a few alternatives, -rather than prescribing a defined approach. -When consensus is reached on one of the alternatives discussed there, -the others will be moved to this section. +Some alternative approaches are: + +1. Their names could be simply available in any program, + without any explicit declaration found anywhere for them. +2. They could be declared in some core library files explicitly + and be available in any program without explicitly importing them, + like `java.lang.String` in Java or `std::Option` in Rust. + +From a user's perspective, there is not a lot of difference between cases 1 and 2 above: +in both cases, the names are available; the only difference is that in case 2, the user can see the declaration somewhere. + +Also, note that case 2 could be seen as having an implicit (i.e., built-in) import of the library/libraries in question. Again, imports are "meta" in this context, and what counts are the other kinds of declarations. + +In cases 2 and the decided upon design choice, a related but somewhat independent issue is whether those declarations have Leo definitions or not. The Leo library already includes functions like BLAKE2s that are not defined in Leo but rather "natively" in Rust/R1CS though some of this may be subject to change for native definitions(see the separate RFC on those). From 192270c49c5b35a26138b1beae5a45f9b54de0fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Sep 2021 14:24:04 +0300 Subject: [PATCH 22/28] Bump assert_cmd from 2.0.0 to 2.0.1 (#1331) Bumps [assert_cmd](https://github.com/assert-rs/assert_cmd) from 2.0.0 to 2.0.1. - [Release notes](https://github.com/assert-rs/assert_cmd/releases) - [Changelog](https://github.com/assert-rs/assert_cmd/blob/master/CHANGELOG.md) - [Commits](https://github.com/assert-rs/assert_cmd/compare/v2.0.0...v2.0.1) --- updated-dependencies: - dependency-name: assert_cmd dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12088aed81..b484086af6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,9 +88,9 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "assert_cmd" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54f002ce7d0c5e809ebb02be78fd503aeed4a511fd0fcaff6e6914cbdabbfa33" +checksum = "b800c4403e8105d959595e1f88119e78bc12bc874c4336973658b648a746ba93" dependencies = [ "bstr", "doc-comment", diff --git a/Cargo.toml b/Cargo.toml index 4ce8b175d6..78687f1ac9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -169,7 +169,7 @@ version = "0.12.1" version = "0.11.2" [dev-dependencies.assert_cmd] -version = "2.0.0" +version = "2.0.1" [dev-dependencies.test_dir] version = "0.1.0" From 80eeacb3c5f46c46e91c1663f5076b419e726959 Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Tue, 7 Sep 2021 09:24:00 -0700 Subject: [PATCH 23/28] fix some refrences --- docs/rfc/008-built-in-declarations.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/rfc/008-built-in-declarations.md b/docs/rfc/008-built-in-declarations.md index 96e764e319..c91b03e12b 100644 --- a/docs/rfc/008-built-in-declarations.md +++ b/docs/rfc/008-built-in-declarations.md @@ -26,7 +26,7 @@ that can be readily used in programs. The initial motivation for this in Leo was ## Design -Leo supports four kinds of top-level declarations: +Leo supports five kinds of top-level declarations: - Import declarations. - Function declarations. @@ -46,8 +46,7 @@ This does not seem to bring any drawbacks. ## Effect on Ecosystem -This change may interact with libraries and packages in some way, -if we go with case 2 or 3 above. +This change may interact with libraries and packages in some way. But it should not be much different from standard libraries/packages. ## Alternatives From a9c81d6596228f102c0055b9059ce637b828f52d Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Wed, 8 Sep 2021 04:18:11 -0700 Subject: [PATCH 24/28] fix canoncialization of function inputs --- .../src/canonicalization/canonicalizer.rs | 18 +++++++++--------- .../big_self_in_circuit_replacement.leo | 2 +- .../big_self_in_circuit_replacement.leo.out | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ast-passes/src/canonicalization/canonicalizer.rs b/ast-passes/src/canonicalization/canonicalizer.rs index cd8e7a294e..94bdc5d5d0 100644 --- a/ast-passes/src/canonicalization/canonicalizer.rs +++ b/ast-passes/src/canonicalization/canonicalizer.rs @@ -470,15 +470,15 @@ impl Canonicalizer { fn canonicalize_function_input(&mut self, input: &FunctionInput) -> FunctionInput { if let FunctionInput::Variable(variable) = input { - if variable.type_.is_self() { - return FunctionInput::Variable(FunctionInputVariable { - identifier: variable.identifier.clone(), - const_: variable.const_, - mutable: variable.mutable, - type_: Type::CircuitOrAlias(self.circuit_name.as_ref().unwrap().clone()), - span: variable.span.clone(), - }); - } + let type_ = self.canonicalize_self_type(Some(&variable.type_)).unwrap(); + + return FunctionInput::Variable(FunctionInputVariable { + identifier: variable.identifier.clone(), + const_: variable.const_, + mutable: variable.mutable, + type_, + span: variable.span.clone(), + }); } input.clone() diff --git a/tests/compiler/circuits/big_self_in_circuit_replacement.leo b/tests/compiler/circuits/big_self_in_circuit_replacement.leo index 7f0e58b378..74ebb27854 100644 --- a/tests/compiler/circuits/big_self_in_circuit_replacement.leo +++ b/tests/compiler/circuits/big_self_in_circuit_replacement.leo @@ -20,7 +20,7 @@ circuit Foo { y[Self {x: 0}.x] += 2; } - function func() { + function func(a: [Self; 3], y: (Self)) { const x: Self = Foo {x: Self {x: 1}.x}; } diff --git a/tests/expectations/compiler/compiler/circuits/big_self_in_circuit_replacement.leo.out b/tests/expectations/compiler/compiler/circuits/big_self_in_circuit_replacement.leo.out index c504804bcc..53138f0bf9 100644 --- a/tests/expectations/compiler/compiler/circuits/big_self_in_circuit_replacement.leo.out +++ b/tests/expectations/compiler/compiler/circuits/big_self_in_circuit_replacement.leo.out @@ -16,7 +16,7 @@ outputs: r0: type: bool value: "true" - initial_ast: 8ccdbe000ca6a2ae3b7cf8601d5b6a922106181fe3f1b8aede16c5661a816b93 - imports_resolved_ast: 8ccdbe000ca6a2ae3b7cf8601d5b6a922106181fe3f1b8aede16c5661a816b93 - canonicalized_ast: 551e7de9ff8d1391a435861819576c9ac1a0ff93818c7a907830be890e27311f - type_inferenced_ast: b83403b86ddd7a10d070a4537a95ac03075e292d3004cdb667564b630dcae805 + initial_ast: dc05209ad2e30af4f03aa0f8c043849071e71bb2cc63aeb898d9eb7e4770d05c + imports_resolved_ast: dc05209ad2e30af4f03aa0f8c043849071e71bb2cc63aeb898d9eb7e4770d05c + canonicalized_ast: 7522e99656edfe20bd643a5e95af536f50445613c60d8c525e678149e3ab257b + type_inferenced_ast: 34257803056274397099d0a7bf3fcd2a20815d7d988e17c1c4404d43300283b4 From c40106c15da680cf5ec6ba93dd6a4ec13affe094 Mon Sep 17 00:00:00 2001 From: damirka Date: Wed, 8 Sep 2021 19:26:27 +0300 Subject: [PATCH 25/28] adds more examples from playground, updates manifests --- examples/hello-world/Leo.toml | 4 ++ examples/linear-regression/.gitignore | 1 + examples/linear-regression/Leo.toml | 12 ++++ examples/linear-regression/README.md | 20 ++++++ .../inputs/linear-regression.in | 7 ++ .../inputs/linear-regression.state | 26 ++++++++ examples/linear-regression/src/main.leo | 65 +++++++++++++++++++ examples/palindrome/.gitignore | 1 + examples/palindrome/Leo.toml | 15 +++++ examples/palindrome/README.md | 20 ++++++ examples/palindrome/inputs/palindrome.in | 5 ++ examples/palindrome/inputs/palindrome.state | 26 ++++++++ examples/palindrome/src/main.leo | 59 +++++++++++++++++ examples/pedersen-hash/Leo.toml | 4 ++ examples/silly-sudoku/Leo.toml | 4 ++ 15 files changed, 269 insertions(+) create mode 100644 examples/linear-regression/.gitignore create mode 100644 examples/linear-regression/Leo.toml create mode 100644 examples/linear-regression/README.md create mode 100644 examples/linear-regression/inputs/linear-regression.in create mode 100644 examples/linear-regression/inputs/linear-regression.state create mode 100644 examples/linear-regression/src/main.leo create mode 100644 examples/palindrome/.gitignore create mode 100644 examples/palindrome/Leo.toml create mode 100644 examples/palindrome/README.md create mode 100644 examples/palindrome/inputs/palindrome.in create mode 100644 examples/palindrome/inputs/palindrome.state create mode 100644 examples/palindrome/src/main.leo diff --git a/examples/hello-world/Leo.toml b/examples/hello-world/Leo.toml index 7255a801f9..b481087ab6 100644 --- a/examples/hello-world/Leo.toml +++ b/examples/hello-world/Leo.toml @@ -6,3 +6,7 @@ license = "LICENSE-MIT" [remote] author = "aleo" + +[target] +curve = "bls12_377" +proving_system = "groth16" diff --git a/examples/linear-regression/.gitignore b/examples/linear-regression/.gitignore new file mode 100644 index 0000000000..17aa483ab4 --- /dev/null +++ b/examples/linear-regression/.gitignore @@ -0,0 +1 @@ +outputs/ diff --git a/examples/linear-regression/Leo.toml b/examples/linear-regression/Leo.toml new file mode 100644 index 0000000000..052350b291 --- /dev/null +++ b/examples/linear-regression/Leo.toml @@ -0,0 +1,12 @@ +[project] +name = "linear-regression" +version = "0.1.0" +description = "The linear-regression package" +license = "MIT" + +[remote] +author = "aleo" + +[target] +curve = "bls12_377" +proving_system = "groth16" diff --git a/examples/linear-regression/README.md b/examples/linear-regression/README.md new file mode 100644 index 0000000000..58b8463cbc --- /dev/null +++ b/examples/linear-regression/README.md @@ -0,0 +1,20 @@ +# linear-regression + +## Build Guide + +To compile this Leo program, run: +```bash +leo build +``` + +To test this Leo program, run: +```bash +leo test +``` + +## Development + +To output the number of constraints, run: +```bash +leo build -d +``` diff --git a/examples/linear-regression/inputs/linear-regression.in b/examples/linear-regression/inputs/linear-regression.in new file mode 100644 index 0000000000..2969aa3b83 --- /dev/null +++ b/examples/linear-regression/inputs/linear-regression.in @@ -0,0 +1,7 @@ +// The program input for light-cuddly-cyan-polo/src/main.leo +[main] +x: i32 = 1i32; +y: i32 = 2i32; + +[registers] +r0: [i32; 2] = [1i32, 2i32]; diff --git a/examples/linear-regression/inputs/linear-regression.state b/examples/linear-regression/inputs/linear-regression.state new file mode 100644 index 0000000000..3a4a276e17 --- /dev/null +++ b/examples/linear-regression/inputs/linear-regression.state @@ -0,0 +1,26 @@ +// The program state for linear-regression/src/main.leo +[[public]] + +[state] +leaf_index: u32 = 0; +root: [u8; 32] = [0; 32]; + +[[private]] + +[record] +serial_number: [u8; 64] = [0; 64]; +commitment: [u8; 32] = [0; 32]; +owner: address = aleo1daxej63vwrmn2zhl4dymygagh89k5d2vaw6rjauueme7le6k2q8sjn0ng9; +is_dummy: bool = false; +value: u64 = 0; +payload: [u8; 32] = [0; 32]; +birth_program_id: [u8; 48] = [0; 48]; +death_program_id: [u8; 48] = [0; 48]; +serial_number_nonce: [u8; 32] = [0; 32]; +commitment_randomness: [u8; 32] = [0; 32]; + +[state_leaf] +path: [u8; 128] = [0; 128]; +memo: [u8; 32] = [0; 32]; +network_id: u8 = 0; +leaf_randomness: [u8; 32] = [0; 32]; diff --git a/examples/linear-regression/src/main.leo b/examples/linear-regression/src/main.leo new file mode 100644 index 0000000000..51dc4dd908 --- /dev/null +++ b/examples/linear-regression/src/main.leo @@ -0,0 +1,65 @@ +circuit Point { + x: i32, + y: i32, + + function new(x: i32, y: i32) -> Self { + return Self { x, y }; + } +} + +circuit LinearRegression { + points: [Point; 5], + + // Instantiates a linear regression circuit. + function new(points: [Point; 5]) -> Self { + return Self { points }; + } + + // Return the slope of the linear regression. + function slope(self) -> i32 { + + let num_points = 5i32; + // Calculate the sums. + let x_sum = 0i32; + let y_sum = 0i32; + let xy_sum = 0i32; + let x2_sum = 0i32; + for i in 0..5 { + x_sum += self.points[i].x; + y_sum += self.points[i].y; + xy_sum += self.points[i].x * self.points[i].y; + x2_sum += self.points[i].x * self.points[i].x; + } + let numerator = (num_points * xy_sum) - (x_sum * y_sum); + let denominator = (num_points * x2_sum) - (x_sum * x_sum); + let slope = numerator / denominator; + return slope; + } + // Return the offset of the linear regression. + function offset(self, slope: i32) -> i32 { + let num_points = 5i32; + // Calculate the sum. + let x_sum = 0i32; + let y_sum = 0i32; + for i in 0..5 { + x_sum += self.points[i].x; + y_sum += self.points[i].y; + } + return (y_sum - slope * x_sum) / num_points; + } +} + + +function main (x: i32, y: i32) -> [i32; 2] { + let points: [Point; 5] = [ + Point{x: x + 1, y: y + 1}, + Point{x: x + 2, y: y + 2}, + Point{x: x + 3, y: y + 3}, + Point{x: x + 4, y: y + 4}, + Point{x: x + 5, y: y + 5} + ]; + let reg = LinearRegression::new(points); + let slope = reg.slope(); + let offset = reg.offset(slope); + return [slope, offset]; +} diff --git a/examples/palindrome/.gitignore b/examples/palindrome/.gitignore new file mode 100644 index 0000000000..17aa483ab4 --- /dev/null +++ b/examples/palindrome/.gitignore @@ -0,0 +1 @@ +outputs/ diff --git a/examples/palindrome/Leo.toml b/examples/palindrome/Leo.toml new file mode 100644 index 0000000000..ffcfe51757 --- /dev/null +++ b/examples/palindrome/Leo.toml @@ -0,0 +1,15 @@ +[project] +name = "palindrome" +version = "0.1.0" +description = "The palindrome package" +license = "MIT" + +[remote] +author = "aleo" + +[target] +curve = "bls12_377" +proving_system = "groth16" + +[dependencies] +# none diff --git a/examples/palindrome/README.md b/examples/palindrome/README.md new file mode 100644 index 0000000000..4703046c4e --- /dev/null +++ b/examples/palindrome/README.md @@ -0,0 +1,20 @@ +# palindrome + +## Build Guide + +To compile this Leo program, run: +```bash +leo build +``` + +To test this Leo program, run: +```bash +leo test +``` + +## Development + +To output the number of constraints, run: +```bash +leo build -d +``` diff --git a/examples/palindrome/inputs/palindrome.in b/examples/palindrome/inputs/palindrome.in new file mode 100644 index 0000000000..0e175a1c35 --- /dev/null +++ b/examples/palindrome/inputs/palindrome.in @@ -0,0 +1,5 @@ +[main] +str: [char; 20] = "borrow or rob "; // char array can be defined as a string + +[registers] +r0: bool = false; diff --git a/examples/palindrome/inputs/palindrome.state b/examples/palindrome/inputs/palindrome.state new file mode 100644 index 0000000000..ffb7590fa9 --- /dev/null +++ b/examples/palindrome/inputs/palindrome.state @@ -0,0 +1,26 @@ +// The program state for palindrome/src/main.leo +[[public]] + +[state] +leaf_index: u32 = 0; +root: [u8; 32] = [0; 32]; + +[[private]] + +[record] +serial_number: [u8; 64] = [0; 64]; +commitment: [u8; 32] = [0; 32]; +owner: address = aleo1daxej63vwrmn2zhl4dymygagh89k5d2vaw6rjauueme7le6k2q8sjn0ng9; +is_dummy: bool = false; +value: u64 = 0; +payload: [u8; 32] = [0; 32]; +birth_program_id: [u8; 48] = [0; 48]; +death_program_id: [u8; 48] = [0; 48]; +serial_number_nonce: [u8; 32] = [0; 32]; +commitment_randomness: [u8; 32] = [0; 32]; + +[state_leaf] +path: [u8; 128] = [0; 128]; +memo: [u8; 32] = [0; 32]; +network_id: u8 = 0; +leaf_randomness: [u8; 32] = [0; 32]; diff --git a/examples/palindrome/src/main.leo b/examples/palindrome/src/main.leo new file mode 100644 index 0000000000..f2b1872733 --- /dev/null +++ b/examples/palindrome/src/main.leo @@ -0,0 +1,59 @@ +// This Program takes in any 20-byte low register string and tells +// whether a string is a palindrome ignoring any spaces. + +function main(str: [char; 20]) -> bool { + return is_palindrome(str); +} + +function is_palindrome(str: [char; 20]) -> bool { + const str_len = 20u32; // saving const for convenience + + // By default we assume that input is a palindrome. + let result = true; + let processed = 0u8; + + for start in 0..(str_len / 2) { + let start_sym = str[start]; + if start_sym != ' ' { + let skipped = 0u8; + let end_empty = 0u8; + let end_sym = ' '; + + for end in (str_len - 1)..start { + if str[end] != ' ' && skipped == processed && end_sym == ' ' { + end_sym = str[end]; + } else { + end_empty = end_empty + 1; + if str[end] != ' ' { + skipped = skipped + 1; + } + } + } + + // If there are symbols left to the right from the start. + if end_sym != ' ' { + console.log("Comparing: {} ? {}", start_sym, end_sym); + + if result { + result = (start_sym == end_sym); + } + + processed = processed + 1; + } + } + } + + console.log("Result is: {}", result); + + return result; +} + +@test +function test_is_palindrome() { + console.assert(is_palindrome("a b a ")); + console.assert(is_palindrome("😀😀😀😀😀 😀😀😀😀😀")); + console.assert(is_palindrome("borrow or rob ")); + console.assert(is_palindrome("bbbb aaaa aaaa bbbb")); + console.assert(is_palindrome("aaaaaaaaaaaaaaaaaaaa")); + console.assert(is_palindrome("taco cat ")); +} diff --git a/examples/pedersen-hash/Leo.toml b/examples/pedersen-hash/Leo.toml index 5076066fa2..a217cf0127 100644 --- a/examples/pedersen-hash/Leo.toml +++ b/examples/pedersen-hash/Leo.toml @@ -6,3 +6,7 @@ license = "LICENSE-MIT" [remote] author = "aleo" + +[target] +curve = "bls12_377" +proving_system = "groth16" diff --git a/examples/silly-sudoku/Leo.toml b/examples/silly-sudoku/Leo.toml index aecf26ff25..386a97dec0 100644 --- a/examples/silly-sudoku/Leo.toml +++ b/examples/silly-sudoku/Leo.toml @@ -6,3 +6,7 @@ license = "MIT" [remote] author = "howard" + +[target] +curve = "bls12_377" +proving_system = "groth16" From c169e48a56f4d3b3151a6c087bfb6b2a05866170 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Sep 2021 15:16:40 +0300 Subject: [PATCH 26/28] Bump sha2 from 0.9.6 to 0.9.8 (#1338) Bumps [sha2](https://github.com/RustCrypto/hashes) from 0.9.6 to 0.9.8. - [Release notes](https://github.com/RustCrypto/hashes/releases) - [Commits](https://github.com/RustCrypto/hashes/compare/sha2-v0.9.6...sha2-v0.9.8) --- updated-dependencies: - dependency-name: sha2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b484086af6..ec0da68f83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2451,9 +2451,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.6" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9204c41a1597a8c5af23c82d1c921cb01ec0a4c59e07a9c7306062829a3903f3" +checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", From 041adf2b3be5b6b4ed31090c102d910efa55793c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Sep 2021 14:05:58 +0300 Subject: [PATCH 27/28] Bump serde_yaml from 0.8.20 to 0.8.21 (#1341) Bumps [serde_yaml](https://github.com/dtolnay/serde-yaml) from 0.8.20 to 0.8.21. - [Release notes](https://github.com/dtolnay/serde-yaml/releases) - [Commits](https://github.com/dtolnay/serde-yaml/compare/0.8.20...0.8.21) --- updated-dependencies: - dependency-name: serde_yaml dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec0da68f83..fd6531d0c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2427,9 +2427,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad104641f3c958dab30eb3010e834c2622d1f3f4c530fef1dee20ad9485f3c09" +checksum = "d8c608a35705a5d3cdc9fbe403147647ff34b921f8e833e49306df898f9b20af" dependencies = [ "dtoa", "indexmap", From 49a1ffbdff714d890940908e0aac327ec065ae74 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Sep 2021 14:06:32 +0300 Subject: [PATCH 28/28] Bump anyhow from 1.0.43 to 1.0.44 (#1340) Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.43 to 1.0.44. - [Release notes](https://github.com/dtolnay/anyhow/releases) - [Commits](https://github.com/dtolnay/anyhow/compare/1.0.43...1.0.44) --- updated-dependencies: - dependency-name: anyhow dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd6531d0c0..121a8d0ae3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.43" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf" +checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" [[package]] name = "arrayvec"