From 22a1c1dfb403c47a6cd0c40995785f1e429d4f54 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sun, 29 Jan 2023 13:30:58 +0100 Subject: [PATCH] Use IndexMap throughout In an ideal world, I should have handlded that directly at the conflicting commit in the rebase, but this would have bubbled up through all commits... which I wasn't really quite keen on going through. So here's an extra ugly commit that comes and 'fix the rebase'. --- crates/aiken-lang/src/builtins.rs | 18 ++++++++---------- crates/aiken-lang/src/uplc.rs | 4 ++-- .../aiken-project/src/blueprint/validator.rs | 5 +++-- crates/aiken-project/src/lib.rs | 4 ++-- crates/aiken-project/src/module.rs | 15 ++++++++++----- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/crates/aiken-lang/src/builtins.rs b/crates/aiken-lang/src/builtins.rs index 3d426d8b..dfd4c093 100644 --- a/crates/aiken-lang/src/builtins.rs +++ b/crates/aiken-lang/src/builtins.rs @@ -1,9 +1,3 @@ -use std::{cell::RefCell, collections::HashMap, sync::Arc}; - -use strum::IntoEnumIterator; - -use uplc::builtins::DefaultFunction; - use crate::{ ast::{Arg, ArgName, CallArg, Function, ModuleKind, Span, TypedDataType, TypedFunction, UnOp}, builder::{DataTypeKey, FunctionAccessKey}, @@ -14,6 +8,10 @@ use crate::{ }, IdGenerator, }; +use indexmap::IndexMap; +use std::{cell::RefCell, collections::HashMap, sync::Arc}; +use strum::IntoEnumIterator; +use uplc::builtins::DefaultFunction; pub const BYTE_ARRAY: &str = "ByteArray"; pub const BOOL: &str = "Bool"; @@ -533,8 +531,8 @@ pub fn from_default_function( }) } -pub fn prelude_functions(id_gen: &IdGenerator) -> HashMap { - let mut functions = HashMap::new(); +pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap { + let mut functions = IndexMap::new(); // /// Negate the argument. Useful for map/fold and pipelines. // pub fn not(self: Bool) -> Bool { @@ -800,8 +798,8 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> HashMap HashMap { - let mut data_types = HashMap::new(); +pub fn prelude_data_types(id_gen: &IdGenerator) -> IndexMap { + let mut data_types = IndexMap::new(); // Option let option_data_type = TypedDataType::option(generic_var(id_gen.next())); diff --git a/crates/aiken-lang/src/uplc.rs b/crates/aiken-lang/src/uplc.rs index 806dee1e..d4738d8b 100644 --- a/crates/aiken-lang/src/uplc.rs +++ b/crates/aiken-lang/src/uplc.rs @@ -44,7 +44,7 @@ pub struct CodeGenerator<'a> { defined_functions: IndexMap, functions: IndexMap, data_types: IndexMap, - module_types: &'a IndexMap, + module_types: IndexMap<&'a String, &'a TypeInfo>, id_gen: IdGenerator, needs_field_access: bool, used_data_assert_on_list: bool, @@ -55,7 +55,7 @@ impl<'a> CodeGenerator<'a> { pub fn new( functions: IndexMap, data_types: IndexMap, - module_types: &'a IndexMap, + module_types: IndexMap<&'a String, &'a TypeInfo>, ) -> Self { CodeGenerator { defined_functions: IndexMap::new(), diff --git a/crates/aiken-project/src/blueprint/validator.rs b/crates/aiken-project/src/blueprint/validator.rs index 814d4202..73e825e3 100644 --- a/crates/aiken-project/src/blueprint/validator.rs +++ b/crates/aiken-project/src/blueprint/validator.rs @@ -166,6 +166,7 @@ mod test { IdGenerator, }; use assert_json_diff::assert_json_eq; + use indexmap::IndexMap; use serde_json::{self, json}; use std::{collections::HashMap, path::PathBuf}; @@ -176,8 +177,8 @@ mod test { package: PackageName, id_gen: IdGenerator, module_types: HashMap, - functions: HashMap, - data_types: HashMap, + functions: IndexMap, + data_types: IndexMap, } impl TestProject { diff --git a/crates/aiken-project/src/lib.rs b/crates/aiken-project/src/lib.rs index 6bd6cbc5..e3172ca8 100644 --- a/crates/aiken-project/src/lib.rs +++ b/crates/aiken-project/src/lib.rs @@ -65,8 +65,8 @@ where sources: Vec, pub warnings: Vec, event_listener: T, - functions: HashMap, - data_types: HashMap, + functions: IndexMap, + data_types: IndexMap, } impl Project diff --git a/crates/aiken-project/src/module.rs b/crates/aiken-project/src/module.rs index c083bc30..f4417276 100644 --- a/crates/aiken-project/src/module.rs +++ b/crates/aiken-project/src/module.rs @@ -9,6 +9,7 @@ use aiken_lang::{ uplc::CodeGenerator, VALIDATOR_NAMES, }; +use indexmap::IndexMap; use petgraph::{algo, graph::NodeIndex, Direction, Graph}; use std::{ collections::{HashMap, HashSet}, @@ -272,16 +273,16 @@ impl CheckedModules { pub fn new_generator<'a>( &'a self, - builtin_functions: &'a HashMap, - builtin_data_types: &'a HashMap, + builtin_functions: &'a IndexMap, + builtin_data_types: &'a IndexMap, module_types: &'a HashMap, ) -> CodeGenerator<'a> { - let mut functions = HashMap::new(); + let mut functions = IndexMap::new(); for (k, v) in builtin_functions { functions.insert(k.clone(), v); } - let mut data_types = HashMap::new(); + let mut data_types = IndexMap::new(); for (k, v) in builtin_data_types { data_types.insert(k.clone(), v); } @@ -316,7 +317,11 @@ impl CheckedModules { } } } - CodeGenerator::new(functions, data_types, module_types) + + let mut module_types_index = IndexMap::new(); + module_types_index.extend(module_types); + + CodeGenerator::new(functions, data_types, module_types_index) } }