mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-13 08:47:17 +03:00
fixes
This commit is contained in:
parent
0d1ed9671e
commit
52bb785ff4
@ -138,7 +138,7 @@ impl ParserContext<'_> {
|
||||
self.expect(&Token::LeftCurly)?;
|
||||
|
||||
// Parse the body of the program scope.
|
||||
let mut consts: Vec<(Symbol, DefinitionStatement)> = Vec::new();
|
||||
let mut consts: Vec<(Symbol, ConstDeclaration)> = Vec::new();
|
||||
let mut functions: Vec<(Symbol, Function)> = Vec::new();
|
||||
let mut structs: Vec<(Symbol, Struct)> = Vec::new();
|
||||
let mut mappings: Vec<(Symbol, Mapping)> = Vec::new();
|
||||
@ -146,7 +146,7 @@ impl ParserContext<'_> {
|
||||
while self.has_next() {
|
||||
match &self.token.token {
|
||||
Token::Const => {
|
||||
let definition = self.parse_const_definition_statement()?;
|
||||
let definition = self.parse_const_declaration_statement()?;
|
||||
consts.push((Symbol::intern(&definition.place.to_string()), definition));
|
||||
}
|
||||
Token::Struct | Token::Record => {
|
||||
|
@ -15,6 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{Assigner, AssignmentRenamer, CallGraph};
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use leo_ast::{Function, NodeBuilder};
|
||||
use leo_span::Symbol;
|
||||
@ -27,7 +28,7 @@ pub struct FunctionInliner<'a> {
|
||||
/// A wrapper around an Assigner used to create unique variable assignments.
|
||||
pub(crate) assignment_renamer: AssignmentRenamer<'a>,
|
||||
/// A map of reconstructed functions in the current program scope.
|
||||
pub(crate) reconstructed_functions: Vec<(Symbol, Function)>,
|
||||
pub(crate) reconstructed_functions: IndexMap<Symbol, Function>,
|
||||
}
|
||||
|
||||
impl<'a> FunctionInliner<'a> {
|
||||
|
@ -48,7 +48,7 @@ impl ExpressionReconstructor for FunctionInliner<'_> {
|
||||
|
||||
// Lookup the reconstructed callee function.
|
||||
// Since this pass processes functions in post-order, the callee function is guaranteed to exist in `self.reconstructed_functions`
|
||||
let (_, callee) = self.reconstructed_functions.iter().find(|(symbol, _)| *symbol == function_name).unwrap();
|
||||
let callee = self.reconstructed_functions.get(&function_name).unwrap();
|
||||
|
||||
// Inline the callee function, if required, otherwise, return the call expression.
|
||||
match callee.variant {
|
||||
|
@ -29,12 +29,13 @@ impl ProgramReconstructor for FunctionInliner<'_> {
|
||||
for function_name in order.into_iter() {
|
||||
// None: If `function_name` is not in `input.functions`, then it must be an external function.
|
||||
// TODO: Check that this is indeed an external function. Requires a redesign of the symbol table.
|
||||
|
||||
if let Some(pos) = input.functions.iter().position(|(symbol, _)| *symbol == function_name) {
|
||||
let (_, function) = input.functions.remove(pos);
|
||||
// Reconstruct the function.
|
||||
let reconstructed_function = self.reconstruct_function(function);
|
||||
// Add the reconstructed function to the mapping.
|
||||
self.reconstructed_functions.push((function_name, reconstructed_function));
|
||||
self.reconstructed_functions.insert(function_name, reconstructed_function);
|
||||
}
|
||||
}
|
||||
// Check that `input.functions` is empty.
|
||||
@ -42,7 +43,9 @@ impl ProgramReconstructor for FunctionInliner<'_> {
|
||||
assert!(input.functions.is_empty(), "All functions in the program scope should have been processed.");
|
||||
|
||||
// Note that this intentionally clears `self.reconstructed_functions` for the next program scope.
|
||||
let functions = core::mem::take(&mut self.reconstructed_functions);
|
||||
let functions = core::mem::take(
|
||||
&mut self.reconstructed_functions.iter().map(|(symbol, function)| (*symbol, function.clone())).collect(),
|
||||
);
|
||||
|
||||
ProgramScope {
|
||||
program_id: input.program_id,
|
||||
|
@ -14,7 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use leo_ast::*;
|
||||
|
||||
use crate::Unroller;
|
||||
@ -30,7 +29,7 @@ impl ProgramReconstructor for Unroller<'_> {
|
||||
structs: input.structs,
|
||||
mappings: input.mappings,
|
||||
functions: input.functions.into_iter().map(|(i, f)| (i, self.reconstruct_function(f))).collect(),
|
||||
consts: IndexMap::new(),
|
||||
consts: Vec::new(),
|
||||
span: input.span,
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
|
||||
|
||||
fn visit_program_scope(&mut self, input: &'a ProgramScope) {
|
||||
// Typecheck each const definition, and append to symbol table.
|
||||
input.consts.iter().for_each(|(_, c)| self.vist_const(c));
|
||||
input.consts.iter().for_each(|(_, c)| self.visit_const(c));
|
||||
|
||||
// Typecheck each struct definition.
|
||||
input.structs.iter().for_each(|(_, function)| self.visit_struct(function));
|
||||
|
@ -684,4 +684,5 @@ create_messages!(
|
||||
msg: format!("A constant declaration statement can only bind a single value"),
|
||||
help: None,
|
||||
}
|
||||
|
||||
);
|
||||
|
@ -5,11 +5,11 @@ outputs:
|
||||
- - initial_symbol_table: af2effe11f5047f1accaca1df1d8456dbb355969e1e843ba37eda44257570551
|
||||
type_checked_symbol_table: 61642b3cd24a2f6303c7abf5dac2821ed2f739f5d009f448b7eef2693fbfb0eb
|
||||
unrolled_symbol_table: 751fa39b0cb4c55b0bd8ac36ef03aefc90829cb4f06ed664b5915b16dbaaaa70
|
||||
initial_ast: 8147cde7c4f4b40f45e67afc32bb4f1c28e994968b52b4d2c7f40fa9b9ef3d0c
|
||||
unrolled_ast: d0850814c6ead0d76661bf37b45212d2edbb6b47d38a006d43e5cba4fcc779f1
|
||||
ssa_ast: b02e95a4c70b6d2fe4b9ba66d742d6001acf85fee058f0f065525265b5ee9c2b
|
||||
flattened_ast: 7d8d33926bf19f4e5e00d9611b77284ce467483bb35192e7f4f9c7ae295c559b
|
||||
inlined_ast: 7d8d33926bf19f4e5e00d9611b77284ce467483bb35192e7f4f9c7ae295c559b
|
||||
dce_ast: 419b58124f548bd498b1cb0dda20f13505372d86cc2d405e9e97cca9327a3bd9
|
||||
initial_ast: a3400f0498e9b246f5436801606d8ecd0220991482ea3d410f80bd7e45cb9ef7
|
||||
unrolled_ast: 0c06e50b891d11cbee05e3429695d656dfe665057d3bdae65e187a3bf9c099ba
|
||||
ssa_ast: 3fbb92a571545e99fa835f9b99cf0899d501b5a6c7473417fa5e6f1f0701ad85
|
||||
flattened_ast: 22336606d0111b633fd6b6cd7c431fea39ed98bc06bc3685347ddf83f116af6a
|
||||
inlined_ast: 22336606d0111b633fd6b6cd7c431fea39ed98bc06bc3685347ddf83f116af6a
|
||||
dce_ast: 31e2ff94d3cd3165201afcd4c2812f3da6acf39d0aa5af1539e3b52e26100c3f
|
||||
bytecode: acfb8fc365ba153cf8598a04dad8ff4ac65b9df6c6356cb077fcf9dafbead7e9
|
||||
warnings: ""
|
||||
|
@ -5,11 +5,11 @@ outputs:
|
||||
- - initial_symbol_table: 77b127880b95652f948bc184d24fb51eb368cc2ccb022093cd27c2fbc03bb70e
|
||||
type_checked_symbol_table: be1bdc9825b662e2070dabbd8e16d24d51ed989e91e385f9ebf27e11dc12b902
|
||||
unrolled_symbol_table: 435f5b6da45d68cf00a82aca5b9bd6e326c5d7d2252811db0e96afd1de00a727
|
||||
initial_ast: f7f9f8362006d7a5e3659df72b883a2f21bc5ee43381ccbd023b32de23c5f833
|
||||
unrolled_ast: 6ec80c2610eb0231078e39c207e6fef0346325d175c821c4e16d8aa96becedec
|
||||
ssa_ast: bb89e164033dca2cb1b61d21c2e012bf72ce6d832c94de647a94f3a0ddf579e6
|
||||
flattened_ast: 40c0e11be11bed1d1214f8b9a1dba9a34a86070eb9ffbc92827185ceaa458f08
|
||||
inlined_ast: 40c0e11be11bed1d1214f8b9a1dba9a34a86070eb9ffbc92827185ceaa458f08
|
||||
dce_ast: 40c0e11be11bed1d1214f8b9a1dba9a34a86070eb9ffbc92827185ceaa458f08
|
||||
initial_ast: 7a198a2494fdf3d024929e3b226e2224e467113902322165f9ebbe7a9d6efe28
|
||||
unrolled_ast: 43a9265edc4c3d7f085b1ff324ac84623a23e1902261b710be40bf79c3165559
|
||||
ssa_ast: 2f44a9100711404013984bca5e5f9dcea0b41f10b6f4c7e6457e9d87fe6af9dd
|
||||
flattened_ast: 36e01ba88e97e69090afa47f0f44bab28c2182b38b246800a22f12dee3599564
|
||||
inlined_ast: 36e01ba88e97e69090afa47f0f44bab28c2182b38b246800a22f12dee3599564
|
||||
dce_ast: 36e01ba88e97e69090afa47f0f44bab28c2182b38b246800a22f12dee3599564
|
||||
bytecode: 88de5519495f51852482cfc5ab129cde77b8d2b53fd2eebfd66472c6fe0cdafe
|
||||
warnings: ""
|
||||
|
@ -5,11 +5,11 @@ outputs:
|
||||
- - initial_symbol_table: d1eed24f01e5256fec3b444fd3a38b7e25756c5fb20010872884a34d54ef888c
|
||||
type_checked_symbol_table: 89c060252a9e229b91f2ac52e5e3823e04400f3e060ead04999aa4911f42c731
|
||||
unrolled_symbol_table: c00e0818651bd9e2c068becdf3819b8d46238e0cfad46c87791efa9c97c6f9de
|
||||
initial_ast: 310ef81cd18a675700a7c5d315978a5aeddfcb5220d7cb3ebb2c22cdefc72c27
|
||||
unrolled_ast: 7e5cc7fedc616597a85fa4a5b46cc5432b93cf2d1f76f615f72d0a287f17232a
|
||||
ssa_ast: a789faf5dde9e018665a22e2aa96674ca424dfdc6abc954c099113d7136e7e02
|
||||
flattened_ast: 6d1021575d55836a866f7b99e87fed633869521e08d97f3d25fdfc2e7e60648d
|
||||
inlined_ast: 6d1021575d55836a866f7b99e87fed633869521e08d97f3d25fdfc2e7e60648d
|
||||
dce_ast: 6d1021575d55836a866f7b99e87fed633869521e08d97f3d25fdfc2e7e60648d
|
||||
initial_ast: 064721479ca1f1002f795fe2286b19cd30130b486004c04cc0b65b6537332276
|
||||
unrolled_ast: f6686b6690f957d6bab9fabde31a7e152bc77e529626fee1ba29b2035d7d35aa
|
||||
ssa_ast: 1f9cb362c185a895e4a0021580db7962aa803a19a22b5f3936262321d200c783
|
||||
flattened_ast: ceb2ad5deaa807b651ac3ac79ce9c14ca706856198ae6a42ce79792a1474a70d
|
||||
inlined_ast: ceb2ad5deaa807b651ac3ac79ce9c14ca706856198ae6a42ce79792a1474a70d
|
||||
dce_ast: ceb2ad5deaa807b651ac3ac79ce9c14ca706856198ae6a42ce79792a1474a70d
|
||||
bytecode: a6350aaded46f7047061f7e68a8ae41eb8aa0d29f02560257ecdc582a6c684f9
|
||||
warnings: ""
|
||||
|
@ -5,11 +5,11 @@ outputs:
|
||||
- - initial_symbol_table: c6a4e40ae8f466c3ff6bf5d356d6ba89684438f88015e8ea23ff43eadb662b49
|
||||
type_checked_symbol_table: 0b88104308fe0b9e390a59a4359d6245170347557911b21ba04cd1d9124da14d
|
||||
unrolled_symbol_table: af56532f8dd6c6ca6f5fc8af3667202298898a54fe2f871a7874684a712f141d
|
||||
initial_ast: 542dc099a401102c60c971fc4c4a97dc5a885e9b949b647ffd12fa418b82ede0
|
||||
unrolled_ast: 6cee219515c51e5b250b0e1905eaeeb27b2d6de0690055bc9e2a8fbb50f5330a
|
||||
ssa_ast: cd15cc9451d67fd9489a4de0ad5debd70f410ca9b8608bacd408948ee1d79e18
|
||||
flattened_ast: a9cb531c3f1a8f3ae4d192d5c630fb0e92800ce2b974017835c90658969cda46
|
||||
inlined_ast: a9cb531c3f1a8f3ae4d192d5c630fb0e92800ce2b974017835c90658969cda46
|
||||
dce_ast: a9cb531c3f1a8f3ae4d192d5c630fb0e92800ce2b974017835c90658969cda46
|
||||
initial_ast: 073156180f17eb97f74a550fad09db2a97f0c6f2fb731384186d9f2df561cecf
|
||||
unrolled_ast: c320a18349a9dc1f73a1d694733aabe364176e7a6744d7db3674d1fdaf30f10b
|
||||
ssa_ast: 42315652d19b89a59857507e03ec426f17c633ef6dfd6523d284dd6f279181ac
|
||||
flattened_ast: 8c8a488425a63ab7e66e2a68e82a8e5a8e4bf50a49652e2aad318e6ecc7adcc2
|
||||
inlined_ast: 8c8a488425a63ab7e66e2a68e82a8e5a8e4bf50a49652e2aad318e6ecc7adcc2
|
||||
dce_ast: 8c8a488425a63ab7e66e2a68e82a8e5a8e4bf50a49652e2aad318e6ecc7adcc2
|
||||
bytecode: d9595550f8a3d55b350b4f46059fb01bf63308aa4b4416594c2eb20231f6483a
|
||||
warnings: ""
|
||||
|
@ -5,12 +5,12 @@ outputs:
|
||||
- - initial_symbol_table: 4194c6207c716b52d30529becd081afc9b7313e8e1ce400cc65c33fac50fab31
|
||||
type_checked_symbol_table: 51dec1877b8da96c81929eabd624019ae50c181362703756b68d94d002cb2f56
|
||||
unrolled_symbol_table: 0b6340ef766a4154f31b5fa00d9bebe8478a8e3c81f091b8433e870ad7213b25
|
||||
initial_ast: bc84c92328b456b2a88fadd3998ae180078447418a1adacbc9495f3d9177a38a
|
||||
unrolled_ast: e9972535de2da936d1db8f65497b529ceedc0a691ea34a9e407447c84311332f
|
||||
ssa_ast: 5a9e0d139821e42ea9cdb3a75c9b9ccdd10e4368490f2c5a1edca0e3d41913d5
|
||||
flattened_ast: 99f8c4ca373d413eba9db8b8949bdf493e6a201298578c22608de3bc8f4abcbf
|
||||
inlined_ast: 99f8c4ca373d413eba9db8b8949bdf493e6a201298578c22608de3bc8f4abcbf
|
||||
dce_ast: 99f8c4ca373d413eba9db8b8949bdf493e6a201298578c22608de3bc8f4abcbf
|
||||
initial_ast: 40475813e3504e84b34352130d1a54e9480d73afa3995801d03c24d315d710cc
|
||||
unrolled_ast: 6757faa19ffcaa549c376165dd4154c278bb8f28527d1491ec9bca8467c6c557
|
||||
ssa_ast: dba16f838232238e78f9d6fcfe6477195a270950f25670227d7ba63ac7c7354e
|
||||
flattened_ast: e7e1acecec4717cebee63e90d9e7de8217031ed3e715be7c6b0f0155438814ff
|
||||
inlined_ast: e7e1acecec4717cebee63e90d9e7de8217031ed3e715be7c6b0f0155438814ff
|
||||
dce_ast: e7e1acecec4717cebee63e90d9e7de8217031ed3e715be7c6b0f0155438814ff
|
||||
bytecode: 6f468335c2ba73721aece1b1018fff421437eee9d52956368d33822d46e8c012
|
||||
warnings: ""
|
||||
results:
|
||||
|
Loading…
Reference in New Issue
Block a user