From d808197507e8de738483d333a72b27f7e837c331 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 13 Sep 2023 18:17:59 -0400 Subject: [PATCH] chore: clippy fix --- Cargo.lock | 13 +- crates/aiken-lang/src/ast.rs | 32 ++--- crates/aiken-lang/src/builtins.rs | 66 +++++----- crates/aiken-lang/src/expr.rs | 44 +++---- crates/aiken-lang/src/format.rs | 8 +- crates/aiken-lang/src/gen_uplc.rs | 30 ++--- crates/aiken-lang/src/gen_uplc/air.rs | 58 ++++----- crates/aiken-lang/src/gen_uplc/builder.rs | 48 +++---- crates/aiken-lang/src/gen_uplc/tree.rs | 120 +++++++++--------- .../src/parser/literal/bytearray.rs | 6 +- crates/aiken-lang/src/tipo.rs | 46 +++---- crates/aiken-lang/src/tipo/environment.rs | 50 ++++---- crates/aiken-lang/src/tipo/error.rs | 22 ++-- crates/aiken-lang/src/tipo/expr.rs | 32 ++--- crates/aiken-lang/src/tipo/hydrator.rs | 12 +- crates/aiken-lang/src/tipo/pattern.rs | 10 +- crates/aiken-lang/src/tipo/pipe.rs | 4 +- crates/aiken-lang/src/tipo/pretty.rs | 40 +++--- crates/aiken-project/Cargo.toml | 2 +- .../src/blueprint/definitions.rs | 8 +- crates/aiken-project/src/blueprint/schema.rs | 21 +-- crates/aiken-project/src/docs.rs | 4 +- crates/aiken-project/src/tests/gen_uplc.rs | 12 +- 23 files changed, 336 insertions(+), 352 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b357c973..ede41dd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2042,16 +2042,15 @@ dependencies = [ [[package]] name = "proptest" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70" +checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65" dependencies = [ "bit-set", "bitflags", "byteorder", "lazy_static", "num-traits", - "quick-error 2.0.1", "rand", "rand_chacha", "rand_xorshift", @@ -2087,12 +2086,6 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -[[package]] -name = "quick-error" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" - [[package]] name = "quote" version = "1.0.26" @@ -2289,7 +2282,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = [ "fnv", - "quick-error 1.2.3", + "quick-error", "tempfile", "wait-timeout", ] diff --git a/crates/aiken-lang/src/ast.rs b/crates/aiken-lang/src/ast.rs index 90600664..ea61375b 100644 --- a/crates/aiken-lang/src/ast.rs +++ b/crates/aiken-lang/src/ast.rs @@ -9,7 +9,7 @@ use owo_colors::{OwoColorize, Stream::Stdout}; use std::{ fmt::{self, Display}, ops::Range, - sync::Arc, + rc::Rc, }; use vec1::Vec1; @@ -129,7 +129,7 @@ fn str_to_keyword(word: &str) -> Option { } } -pub type TypedFunction = Function, TypedExpr>; +pub type TypedFunction = Function, TypedExpr>; pub type UntypedFunction = Function<(), UntypedExpr>; #[derive(Debug, Clone, PartialEq)] @@ -146,7 +146,7 @@ pub struct Function { pub can_error: bool, } -pub type TypedTypeAlias = TypeAlias>; +pub type TypedTypeAlias = TypeAlias>; pub type UntypedTypeAlias = TypeAlias<()>; impl TypedFunction { @@ -206,7 +206,7 @@ pub struct TypeAlias { pub tipo: T, } -pub type TypedDataType = DataType>; +pub type TypedDataType = DataType>; impl TypedDataType { pub fn ordering() -> Self { @@ -244,7 +244,7 @@ impl TypedDataType { } } - pub fn option(tipo: Arc) -> Self { + pub fn option(tipo: Rc) -> Self { DataType { constructors: vec![ RecordConstructor { @@ -308,7 +308,7 @@ pub struct Use { pub unqualified: Vec, } -pub type TypedModuleConstant = ModuleConstant>; +pub type TypedModuleConstant = ModuleConstant>; pub type UntypedModuleConstant = ModuleConstant<()>; #[derive(Debug, Clone, PartialEq)] @@ -322,7 +322,7 @@ pub struct ModuleConstant { pub tipo: T, } -pub type TypedValidator = Validator, TypedExpr>; +pub type TypedValidator = Validator, TypedExpr>; pub type UntypedValidator = Validator<(), UntypedExpr>; #[derive(Debug, Clone, PartialEq)] @@ -335,7 +335,7 @@ pub struct Validator { pub params: Vec>, } -pub type TypedDefinition = Definition, TypedExpr, String>; +pub type TypedDefinition = Definition, TypedExpr, String>; pub type UntypedDefinition = Definition<(), UntypedExpr, ()>; #[derive(Debug, Clone, PartialEq)] @@ -464,7 +464,7 @@ pub enum Constant { } impl Constant { - pub fn tipo(&self) -> Arc { + pub fn tipo(&self) -> Rc { match self { Constant::Int { .. } => builtins::int(), Constant::String { .. } => builtins::string(), @@ -537,7 +537,7 @@ impl RecordConstructorArg { } } -pub type TypedArg = Arg>; +pub type TypedArg = Arg>; pub type UntypedArg = Arg<()>; #[derive(Debug, Clone, PartialEq)] @@ -824,7 +824,7 @@ impl BinOp { } pub type UntypedPattern = Pattern<(), ()>; -pub type TypedPattern = Pattern>; +pub type TypedPattern = Pattern>; #[derive(Debug, Clone, PartialEq)] pub enum Pattern { @@ -947,7 +947,7 @@ impl AssignmentKind { pub type MultiPattern = Vec>; pub type UntypedMultiPattern = MultiPattern<(), ()>; -pub type TypedMultiPattern = MultiPattern>; +pub type TypedMultiPattern = MultiPattern>; #[derive(Debug, Clone, PartialEq)] pub struct UntypedClause { @@ -960,8 +960,8 @@ pub struct UntypedClause { #[derive(Debug, Clone, PartialEq)] pub struct TypedClause { pub location: Span, - pub pattern: Pattern>, - pub guard: Option>>, + pub pattern: Pattern>, + pub guard: Option>>, pub then: TypedExpr, } @@ -979,7 +979,7 @@ impl TypedClause { } pub type UntypedClauseGuard = ClauseGuard<()>; -pub type TypedClauseGuard = ClauseGuard>; +pub type TypedClauseGuard = ClauseGuard>; #[derive(Debug, Clone, PartialEq)] pub enum ClauseGuard { @@ -1079,7 +1079,7 @@ impl ClauseGuard { } impl TypedClauseGuard { - pub fn tipo(&self) -> Arc { + pub fn tipo(&self) -> Rc { match self { ClauseGuard::Var { tipo, .. } => tipo.clone(), ClauseGuard::Constant(constant) => constant.tipo(), diff --git a/crates/aiken-lang/src/builtins.rs b/crates/aiken-lang/src/builtins.rs index 24903d9a..030e85a0 100644 --- a/crates/aiken-lang/src/builtins.rs +++ b/crates/aiken-lang/src/builtins.rs @@ -9,7 +9,7 @@ use crate::{ IdGenerator, }; use indexmap::IndexMap; -use std::{cell::RefCell, collections::HashMap, sync::Arc}; +use std::{cell::RefCell, collections::HashMap, rc::Rc}; use strum::IntoEnumIterator; use uplc::builtins::DefaultFunction; @@ -959,8 +959,8 @@ pub fn prelude_data_types(id_gen: &IdGenerator) -> IndexMap Arc { - Arc::new(Type::App { +pub fn int() -> Rc { + Rc::new(Type::App { public: true, name: INT.to_string(), module: "".to_string(), @@ -968,8 +968,8 @@ pub fn int() -> Arc { }) } -pub fn data() -> Arc { - Arc::new(Type::App { +pub fn data() -> Rc { + Rc::new(Type::App { public: true, name: DATA.to_string(), module: "".to_string(), @@ -977,8 +977,8 @@ pub fn data() -> Arc { }) } -pub fn byte_array() -> Arc { - Arc::new(Type::App { +pub fn byte_array() -> Rc { + Rc::new(Type::App { args: vec![], public: true, name: BYTE_ARRAY.to_string(), @@ -986,12 +986,12 @@ pub fn byte_array() -> Arc { }) } -pub fn tuple(elems: Vec>) -> Arc { - Arc::new(Type::Tuple { elems }) +pub fn tuple(elems: Vec>) -> Rc { + Rc::new(Type::Tuple { elems }) } -pub fn bool() -> Arc { - Arc::new(Type::App { +pub fn bool() -> Rc { + Rc::new(Type::App { args: vec![], public: true, name: BOOL.to_string(), @@ -999,8 +999,8 @@ pub fn bool() -> Arc { }) } -pub fn list(t: Arc) -> Arc { - Arc::new(Type::App { +pub fn list(t: Rc) -> Rc { + Rc::new(Type::App { public: true, name: LIST.to_string(), module: "".to_string(), @@ -1008,8 +1008,8 @@ pub fn list(t: Arc) -> Arc { }) } -pub fn string() -> Arc { - Arc::new(Type::App { +pub fn string() -> Rc { + Rc::new(Type::App { args: vec![], public: true, name: STRING.to_string(), @@ -1017,8 +1017,8 @@ pub fn string() -> Arc { }) } -pub fn void() -> Arc { - Arc::new(Type::App { +pub fn void() -> Rc { + Rc::new(Type::App { args: vec![], public: true, name: VOID.to_string(), @@ -1026,8 +1026,8 @@ pub fn void() -> Arc { }) } -pub fn result(a: Arc, e: Arc) -> Arc { - Arc::new(Type::App { +pub fn result(a: Rc, e: Rc) -> Rc { + Rc::new(Type::App { public: true, name: RESULT.to_string(), module: "".to_string(), @@ -1035,8 +1035,8 @@ pub fn result(a: Arc, e: Arc) -> Arc { }) } -pub fn option(a: Arc) -> Arc { - Arc::new(Type::App { +pub fn option(a: Rc) -> Rc { + Rc::new(Type::App { public: true, name: OPTION.to_string(), module: "".to_string(), @@ -1044,8 +1044,8 @@ pub fn option(a: Arc) -> Arc { }) } -pub fn ordering() -> Arc { - Arc::new(Type::App { +pub fn ordering() -> Rc { + Rc::new(Type::App { public: true, name: ORDERING.to_string(), module: "".to_string(), @@ -1053,24 +1053,24 @@ pub fn ordering() -> Arc { }) } -pub fn function(args: Vec>, ret: Arc) -> Arc { - Arc::new(Type::Fn { ret, args }) +pub fn function(args: Vec>, ret: Rc) -> Rc { + Rc::new(Type::Fn { ret, args }) } -pub fn generic_var(id: u64) -> Arc { - let tipo = Arc::new(RefCell::new(TypeVar::Generic { id })); +pub fn generic_var(id: u64) -> Rc { + let tipo = Rc::new(RefCell::new(TypeVar::Generic { id })); - Arc::new(Type::Var { tipo }) + Rc::new(Type::Var { tipo }) } -pub fn unbound_var(id: u64) -> Arc { - let tipo = Arc::new(RefCell::new(TypeVar::Unbound { id })); +pub fn unbound_var(id: u64) -> Rc { + let tipo = Rc::new(RefCell::new(TypeVar::Unbound { id })); - Arc::new(Type::Var { tipo }) + Rc::new(Type::Var { tipo }) } -pub fn wrapped_redeemer(redeemer: Arc) -> Arc { - Arc::new(Type::App { +pub fn wrapped_redeemer(redeemer: Rc) -> Rc { + Rc::new(Type::App { public: true, module: "".to_string(), name: REDEEMER_WRAPPER.to_string(), diff --git a/crates/aiken-lang/src/expr.rs b/crates/aiken-lang/src/expr.rs index 6a5da8c8..cf9cf5c6 100644 --- a/crates/aiken-lang/src/expr.rs +++ b/crates/aiken-lang/src/expr.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::rc::Rc; use vec1::Vec1; @@ -18,19 +18,19 @@ use crate::{ pub enum TypedExpr { UInt { location: Span, - tipo: Arc, + tipo: Rc, value: String, }, String { location: Span, - tipo: Arc, + tipo: Rc, value: String, }, ByteArray { location: Span, - tipo: Arc, + tipo: Rc, bytes: Vec, }, @@ -57,30 +57,30 @@ pub enum TypedExpr { Fn { location: Span, - tipo: Arc, + tipo: Rc, is_capture: bool, - args: Vec>>, + args: Vec>>, body: Box, return_annotation: Option, }, List { location: Span, - tipo: Arc, + tipo: Rc, elements: Vec, tail: Option>, }, Call { location: Span, - tipo: Arc, + tipo: Rc, fun: Box, args: Vec>, }, BinOp { location: Span, - tipo: Arc, + tipo: Rc, name: BinOp, left: Box, right: Box, @@ -88,22 +88,22 @@ pub enum TypedExpr { Assignment { location: Span, - tipo: Arc, + tipo: Rc, value: Box, - pattern: Pattern>, + pattern: Pattern>, kind: AssignmentKind, }, Trace { location: Span, - tipo: Arc, + tipo: Rc, then: Box, text: Box, }, When { location: Span, - tipo: Arc, + tipo: Rc, subject: Box, clauses: Vec, }, @@ -112,12 +112,12 @@ pub enum TypedExpr { location: Span, branches: Vec1>, final_else: Box, - tipo: Arc, + tipo: Rc, }, RecordAccess { location: Span, - tipo: Arc, + tipo: Rc, label: String, index: u64, record: Box, @@ -125,7 +125,7 @@ pub enum TypedExpr { ModuleSelect { location: Span, - tipo: Arc, + tipo: Rc, label: String, module_name: String, module_alias: String, @@ -134,25 +134,25 @@ pub enum TypedExpr { Tuple { location: Span, - tipo: Arc, + tipo: Rc, elems: Vec, }, TupleIndex { location: Span, - tipo: Arc, + tipo: Rc, index: usize, tuple: Box, }, ErrorTerm { location: Span, - tipo: Arc, + tipo: Rc, }, RecordUpdate { location: Span, - tipo: Arc, + tipo: Rc, spread: Box, args: Vec, }, @@ -160,13 +160,13 @@ pub enum TypedExpr { UnOp { location: Span, value: Box, - tipo: Arc, + tipo: Rc, op: UnOp, }, } impl TypedExpr { - pub fn tipo(&self) -> Arc { + pub fn tipo(&self) -> Rc { match self { Self::Var { constructor, .. } => constructor.tipo.clone(), Self::Trace { then, .. } => then.tipo(), diff --git a/crates/aiken-lang/src/format.rs b/crates/aiken-lang/src/format.rs index 09ae5b2d..808d6726 100644 --- a/crates/aiken-lang/src/format.rs +++ b/crates/aiken-lang/src/format.rs @@ -21,7 +21,7 @@ use crate::{ use itertools::Itertools; use num_bigint::BigInt; use ordinal::Ordinal; -use std::sync::Arc; +use std::rc::Rc; use vec1::Vec1; const INDENT: isize = 2; @@ -1460,7 +1460,7 @@ impl<'comments> Formatter<'comments> { name: &'a str, args: &'a [TypedArg], return_annotation: &'a Option, - return_type: Arc, + return_type: Rc, ) -> Document<'a> { let head = name.to_doc().append(self.docs_fn_args(args)).append(" -> "); @@ -1489,7 +1489,7 @@ impl<'comments> Formatter<'comments> { wrap_args(args.iter().map(|e| (self.docs_fn_arg(e), false))) } - fn docs_fn_arg<'a>(&mut self, arg: &'a Arg>) -> Document<'a> { + fn docs_fn_arg<'a>(&mut self, arg: &'a TypedArg) -> Document<'a> { self.docs_fn_arg_name(&arg.arg_name) .append(self.type_or_annotation(&arg.annotation, &arg.tipo)) .group() @@ -1506,7 +1506,7 @@ impl<'comments> Formatter<'comments> { fn type_or_annotation<'a>( &mut self, annotation: &'a Option, - type_info: &Arc, + type_info: &Rc, ) -> Document<'a> { match annotation { Some(a) => self.annotation(a), diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 2c01a264..97b9a302 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -2,7 +2,7 @@ pub mod air; pub mod builder; pub mod tree; -use std::sync::Arc; +use std::rc::Rc; use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; @@ -18,7 +18,7 @@ use uplc::{ use crate::{ ast::{ AssignmentKind, BinOp, Pattern, Span, TypedArg, TypedClause, TypedDataType, TypedFunction, - TypedValidator, UnOp, + TypedPattern, TypedValidator, UnOp, }, builtins::{bool, data, int, void}, expr::TypedExpr, @@ -658,9 +658,9 @@ impl<'a> CodeGenerator<'a> { pub fn assignment( &mut self, - pattern: &Pattern>, + pattern: &TypedPattern, mut value: AirTree, - tipo: &Arc, + tipo: &Rc, props: AssignmentProperties, ) -> AirTree { assert!( @@ -938,7 +938,7 @@ impl<'a> CodeGenerator<'a> { let field_map = field_map.clone(); - let mut type_map: IndexMap> = IndexMap::new(); + let mut type_map: IndexMap> = IndexMap::new(); for (index, arg) in constr_tipo .arg_types() @@ -1038,7 +1038,7 @@ impl<'a> CodeGenerator<'a> { Pattern::Tuple { elems, location, .. } => { - let mut type_map: IndexMap> = IndexMap::new(); + let mut type_map: IndexMap> = IndexMap::new(); let mut sequence = vec![]; @@ -1120,7 +1120,7 @@ impl<'a> CodeGenerator<'a> { pub fn expect_type_assign( &mut self, - tipo: &Arc, + tipo: &Rc, value: AirTree, defined_data_types: &mut IndexMap, location: Span, @@ -1388,7 +1388,7 @@ impl<'a> CodeGenerator<'a> { assert!(data_type.typed_parameters.len() == tipo.arg_types().unwrap().len()); - let mono_types: IndexMap> = if !data_type.typed_parameters.is_empty() { + let mono_types: IndexMap> = if !data_type.typed_parameters.is_empty() { data_type .typed_parameters .iter() @@ -1558,7 +1558,7 @@ impl<'a> CodeGenerator<'a> { &mut self, clauses: &[TypedClause], final_clause: TypedClause, - subject_tipo: &Arc, + subject_tipo: &Rc, props: &mut ClauseProperties, ) -> AirTree { assert!( @@ -1904,8 +1904,8 @@ impl<'a> CodeGenerator<'a> { pub fn clause_pattern( &self, - pattern: &Pattern>, - subject_tipo: &Arc, + pattern: &Pattern>, + subject_tipo: &Rc, props: &mut ClauseProperties, // We return condition and then assignments sequence ) -> (AirTree, AirTree) { @@ -2102,7 +2102,7 @@ impl<'a> CodeGenerator<'a> { PatternConstructor::Record { field_map, .. } => field_map.clone(), }; - let mut type_map: IndexMap> = IndexMap::new(); + let mut type_map: IndexMap> = IndexMap::new(); for (index, arg) in function_tipo.arg_types().unwrap().iter().enumerate() { let field_type = arg.clone(); @@ -2330,8 +2330,8 @@ impl<'a> CodeGenerator<'a> { fn nested_clause_condition( &self, - pattern: &Pattern>, - subject_tipo: &Arc, + pattern: &Pattern>, + subject_tipo: &Rc, props: &mut ClauseProperties, ) -> AirTree { if props.final_clause { @@ -3064,7 +3064,7 @@ impl<'a> CodeGenerator<'a> { &self.data_types, )); - let mono_types: IndexMap> = if !function_def_types.is_empty() { + let mono_types: IndexMap> = if !function_def_types.is_empty() { function_def_types .into_iter() .zip(function_var_types) diff --git a/crates/aiken-lang/src/gen_uplc/air.rs b/crates/aiken-lang/src/gen_uplc/air.rs index 62d1485a..277dbf4a 100644 --- a/crates/aiken-lang/src/gen_uplc/air.rs +++ b/crates/aiken-lang/src/gen_uplc/air.rs @@ -1,5 +1,5 @@ use indexmap::IndexSet; -use std::sync::Arc; +use std::rc::Rc; use uplc::builtins::DefaultFunction; use crate::{ @@ -24,11 +24,11 @@ pub enum Air { }, List { count: usize, - tipo: Arc, + tipo: Rc, tail: bool, }, Tuple { - tipo: Arc, + tipo: Rc, count: usize, }, Void, @@ -40,7 +40,7 @@ pub enum Air { // Functions Call { count: usize, - tipo: Arc, + tipo: Rc, }, DefineFunc { func_name: String, @@ -56,13 +56,13 @@ pub enum Air { Builtin { count: usize, func: DefaultFunction, - tipo: Arc, + tipo: Rc, }, // Operators BinOp { name: BinOp, - tipo: Arc, - argument_tipo: Arc, + tipo: Rc, + argument_tipo: Rc, }, UnOp { op: UnOp, @@ -72,10 +72,10 @@ pub enum Air { name: String, }, CastFromData { - tipo: Arc, + tipo: Rc, }, CastToData { - tipo: Arc, + tipo: Rc, }, AssertConstr { constr_index: usize, @@ -85,24 +85,24 @@ pub enum Air { }, // When When { - tipo: Arc, + tipo: Rc, subject_name: String, - subject_tipo: Arc, + subject_tipo: Rc, }, Clause { - subject_tipo: Arc, + subject_tipo: Rc, subject_name: String, complex_clause: bool, }, ListClause { - subject_tipo: Arc, + subject_tipo: Rc, tail_name: String, next_tail_name: Option<(String, String)>, complex_clause: bool, }, WrapClause, TupleClause { - subject_tipo: Arc, + subject_tipo: Rc, indices: IndexSet<(usize, String)>, predefined_indices: IndexSet<(usize, String)>, subject_name: String, @@ -110,72 +110,72 @@ pub enum Air { }, ClauseGuard { subject_name: String, - subject_tipo: Arc, + subject_tipo: Rc, }, ListClauseGuard { - subject_tipo: Arc, + subject_tipo: Rc, tail_name: String, next_tail_name: Option, inverse: bool, }, TupleGuard { - subject_tipo: Arc, + subject_tipo: Rc, indices: IndexSet<(usize, String)>, subject_name: String, }, Finally, // If If { - tipo: Arc, + tipo: Rc, }, // Record Creation Constr { tag: usize, - tipo: Arc, + tipo: Rc, count: usize, }, RecordUpdate { highest_index: usize, - indices: Vec<(usize, Arc)>, - tipo: Arc, + indices: Vec<(usize, Rc)>, + tipo: Rc, }, // Field Access RecordAccess { record_index: u64, - tipo: Arc, + tipo: Rc, }, FieldsExpose { - indices: Vec<(usize, String, Arc)>, + indices: Vec<(usize, String, Rc)>, check_last_item: bool, }, // ListAccess ListAccessor { - tipo: Arc, + tipo: Rc, names: Vec, tail: bool, check_last_item: bool, }, ListExpose { - tipo: Arc, + tipo: Rc, tail_head_names: Vec<(String, String)>, tail: Option<(String, String)>, }, // Tuple Access TupleAccessor { names: Vec, - tipo: Arc, + tipo: Rc, check_last_item: bool, }, TupleIndex { - tipo: Arc, + tipo: Rc, tuple_index: usize, }, // Misc. ErrorTerm { - tipo: Arc, + tipo: Rc, }, Trace { - tipo: Arc, + tipo: Rc, }, NoOp, FieldsEmpty, diff --git a/crates/aiken-lang/src/gen_uplc/builder.rs b/crates/aiken-lang/src/gen_uplc/builder.rs index 7dad571d..557e8630 100644 --- a/crates/aiken-lang/src/gen_uplc/builder.rs +++ b/crates/aiken-lang/src/gen_uplc/builder.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, rc::Rc, sync::Arc}; +use std::{collections::HashMap, rc::Rc}; use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; @@ -15,7 +15,8 @@ use uplc::{ use crate::{ ast::{ - AssignmentKind, DataType, Pattern, Span, TypedArg, TypedClause, TypedDataType, TypedPattern, + AssignmentKind, DataType, Pattern, Span, TypedArg, TypedClause, TypedClauseGuard, + TypedDataType, TypedPattern, }, builtins::{bool, void}, expr::TypedExpr, @@ -80,7 +81,7 @@ pub struct FunctionAccessKey { #[derive(Clone, Debug)] pub struct AssignmentProperties { - pub value_type: Arc, + pub value_type: Rc, pub kind: AssignmentKind, pub remove_unused: bool, pub full_check: bool, @@ -110,7 +111,7 @@ pub enum SpecificClause { } impl ClauseProperties { - pub fn init(t: &Arc, constr_var: String, subject_name: String) -> Self { + pub fn init(t: &Rc, constr_var: String, subject_name: String) -> Self { if t.is_list() { ClauseProperties { clause_var_name: constr_var, @@ -148,7 +149,7 @@ impl ClauseProperties { } pub fn init_inner( - t: &Arc, + t: &Rc, constr_var: String, subject_name: String, final_clause: bool, @@ -190,7 +191,7 @@ impl ClauseProperties { } } -pub fn get_generic_id_and_type(tipo: &Type, param: &Type) -> Vec<(u64, Arc)> { +pub fn get_generic_id_and_type(tipo: &Type, param: &Type) -> Vec<(u64, Rc)> { let mut generics_ids = vec![]; if let Some(id) = tipo.get_generic() { @@ -211,7 +212,7 @@ pub fn get_generic_id_and_type(tipo: &Type, param: &Type) -> Vec<(u64, Arc pub fn lookup_data_type_by_tipo( data_types: &IndexMap, tipo: &Type, -) -> Option>> { +) -> Option>> { match tipo { Type::Fn { ret, .. } => match ret.as_ref() { Type::App { module, name, .. } => { @@ -261,20 +262,19 @@ pub fn get_arg_type_name(tipo: &Type) -> String { } pub fn convert_opaque_type( - t: &Arc, + t: &Rc, data_types: &IndexMap, -) -> Arc { +) -> Rc { if check_replaceable_opaque_type(t, data_types) && matches!(t.as_ref(), Type::App { .. }) { let data_type = lookup_data_type_by_tipo(data_types, t).unwrap(); let new_type_fields = data_type.typed_parameters; - let mono_types: IndexMap>; let mut mono_type_vec = vec![]; for (tipo, param) in new_type_fields.iter().zip(t.arg_types().unwrap()) { mono_type_vec.append(&mut get_generic_id_and_type(tipo, ¶m)); } - mono_types = mono_type_vec.into_iter().collect(); + let mono_types = mono_type_vec.into_iter().collect(); let generic_type = &data_type.constructors[0].arguments[0].tipo; @@ -337,7 +337,7 @@ pub fn convert_opaque_type( } pub fn check_replaceable_opaque_type( - t: &Arc, + t: &Rc, data_types: &IndexMap, ) -> bool { let data_type = lookup_data_type_by_tipo(data_types, t); @@ -352,9 +352,9 @@ pub fn check_replaceable_opaque_type( } pub fn find_and_replace_generics( - tipo: &Arc, - mono_types: &IndexMap>, -) -> Arc { + tipo: &Rc, + mono_types: &IndexMap>, +) -> Rc { if let Some(id) = tipo.get_generic() { // If a generic does not have a type we know of // like a None in option then just use same type @@ -427,7 +427,7 @@ pub fn constants_ir(literal: &Constant) -> AirTree { } } -pub fn handle_clause_guard(clause_guard: &ClauseGuard>) -> AirTree { +pub fn handle_clause_guard(clause_guard: &TypedClauseGuard) -> AirTree { match clause_guard { ClauseGuard::Not { value, .. } => { let val = handle_clause_guard(value); @@ -487,7 +487,7 @@ pub fn handle_clause_guard(clause_guard: &ClauseGuard>) -> AirTree { } } -pub fn get_variant_name(t: &Arc) -> String { +pub fn get_variant_name(t: &Rc) -> String { if t.is_string() { "_string".to_string() } else if t.is_int() { @@ -531,7 +531,7 @@ pub fn get_variant_name(t: &Arc) -> String { } } -pub fn monomorphize(air_tree: &mut AirTree, mono_types: &IndexMap>) { +pub fn monomorphize(air_tree: &mut AirTree, mono_types: &IndexMap>) { let mut held_types = air_tree.mut_held_types(); while let Some(tipo) = held_types.pop() { @@ -1029,7 +1029,7 @@ pub fn find_list_clause_or_default_first(clauses: &[TypedClause]) -> &TypedClaus .unwrap_or(&clauses[0]) } -pub fn convert_data_to_type(term: Term, field_type: &Arc) -> Term { +pub fn convert_data_to_type(term: Term, field_type: &Rc) -> Term { if field_type.is_int() { Term::un_i_data().apply(term) } else if field_type.is_bytearray() { @@ -1142,7 +1142,7 @@ pub fn convert_constants_to_data(constants: Vec>) -> Vec, field_type: &Arc) -> Term { +pub fn convert_type_to_data(term: Term, field_type: &Rc) -> Term { if field_type.is_bytearray() { Term::b_data().apply(term) } else if field_type.is_int() { @@ -1206,7 +1206,7 @@ pub fn list_access_to_uplc( tail: bool, current_index: usize, term: Term, - tipos: Vec>, + tipos: Vec>, check_last_item: bool, is_list_accessor: bool, tracing: bool, @@ -1409,7 +1409,7 @@ pub fn apply_builtin_forces(mut term: Term, force_count: u32) -> Term, + tipo: &Rc, args: Vec>, ) -> Term { let mut term: Term = (*func).into(); @@ -1437,7 +1437,7 @@ pub fn undata_builtin( pub fn to_data_builtin( func: &DefaultFunction, count: usize, - tipo: &Arc, + tipo: &Rc, mut args: Vec>, ) -> Term { let mut term: Term = (*func).into(); @@ -1575,7 +1575,7 @@ pub fn wrap_as_multi_validator(spend: Term, mint: Term) -> Term>, + pattern: &Pattern>, ) -> Option<(usize, bool)> { if let Pattern::List { elements, tail, .. } = &pattern { Some((elements.len(), tail.is_some())) diff --git a/crates/aiken-lang/src/gen_uplc/tree.rs b/crates/aiken-lang/src/gen_uplc/tree.rs index e37b6754..98145795 100644 --- a/crates/aiken-lang/src/gen_uplc/tree.rs +++ b/crates/aiken-lang/src/gen_uplc/tree.rs @@ -1,6 +1,6 @@ use indexmap::IndexSet; use itertools::Itertools; -use std::{borrow::BorrowMut, slice::Iter, sync::Arc}; +use std::{borrow::BorrowMut, rc::Rc, slice::Iter}; use uplc::{builder::EXPECT_ON_LIST, builtins::DefaultFunction}; use crate::{ @@ -145,43 +145,43 @@ pub enum AirStatement { // Clause Guards ClauseGuard { subject_name: String, - subject_tipo: Arc, + subject_tipo: Rc, pattern: Box, }, ListClauseGuard { - subject_tipo: Arc, + subject_tipo: Rc, tail_name: String, next_tail_name: Option, inverse: bool, }, TupleGuard { - subject_tipo: Arc, + subject_tipo: Rc, indices: IndexSet<(usize, String)>, subject_name: String, }, // Field Access FieldsExpose { - indices: Vec<(usize, String, Arc)>, + indices: Vec<(usize, String, Rc)>, check_last_item: bool, record: Box, }, // List Access ListAccessor { - tipo: Arc, + tipo: Rc, names: Vec, tail: bool, check_last_item: bool, list: Box, }, ListExpose { - tipo: Arc, + tipo: Rc, tail_head_names: Vec<(String, String)>, tail: Option<(String, String)>, }, // Tuple Access TupleAccessor { names: Vec, - tipo: Arc, + tipo: Rc, check_last_item: bool, tuple: Box, }, @@ -211,12 +211,12 @@ pub enum AirExpression { value: bool, }, List { - tipo: Arc, + tipo: Rc, tail: bool, items: Vec, }, Tuple { - tipo: Arc, + tipo: Rc, items: Vec, }, Void, @@ -227,7 +227,7 @@ pub enum AirExpression { }, // Functions Call { - tipo: Arc, + tipo: Rc, func: Box, args: Vec, }, @@ -238,16 +238,16 @@ pub enum AirExpression { }, Builtin { func: DefaultFunction, - tipo: Arc, + tipo: Rc, args: Vec, }, // Operators BinOp { name: BinOp, - tipo: Arc, + tipo: Rc, left: Box, right: Box, - argument_tipo: Arc, + argument_tipo: Rc, }, UnOp { op: UnOp, @@ -255,24 +255,24 @@ pub enum AirExpression { }, CastFromData { - tipo: Arc, + tipo: Rc, value: Box, }, CastToData { - tipo: Arc, + tipo: Rc, value: Box, }, // When When { - tipo: Arc, + tipo: Rc, subject_name: String, subject: Box, - subject_tipo: Arc, + subject_tipo: Rc, clauses: Box, }, Clause { - subject_tipo: Arc, + subject_tipo: Rc, subject_name: String, complex_clause: bool, pattern: Box, @@ -280,7 +280,7 @@ pub enum AirExpression { otherwise: Box, }, ListClause { - subject_tipo: Arc, + subject_tipo: Rc, tail_name: String, next_tail_name: Option<(String, String)>, complex_clause: bool, @@ -292,7 +292,7 @@ pub enum AirExpression { otherwise: Box, }, TupleClause { - subject_tipo: Arc, + subject_tipo: Rc, indices: IndexSet<(usize, String)>, predefined_indices: IndexSet<(usize, String)>, subject_name: String, @@ -307,7 +307,7 @@ pub enum AirExpression { }, // If If { - tipo: Arc, + tipo: Rc, pattern: Box, then: Box, otherwise: Box, @@ -315,34 +315,34 @@ pub enum AirExpression { // Record Creation Constr { tag: usize, - tipo: Arc, + tipo: Rc, args: Vec, }, RecordUpdate { highest_index: usize, - indices: Vec<(usize, Arc)>, - tipo: Arc, + indices: Vec<(usize, Rc)>, + tipo: Rc, record: Box, args: Vec, }, // Field Access RecordAccess { field_index: u64, - tipo: Arc, + tipo: Rc, record: Box, }, // Tuple Access TupleIndex { - tipo: Arc, + tipo: Rc, tuple_index: usize, tuple: Box, }, // Misc. ErrorTerm { - tipo: Arc, + tipo: Rc, }, Trace { - tipo: Arc, + tipo: Rc, msg: Box, then: Box, }, @@ -365,7 +365,7 @@ impl AirTree { pub fn bool(value: bool) -> AirTree { AirTree::Expression(AirExpression::Bool { value }) } - pub fn list(mut items: Vec, tipo: Arc, tail: Option) -> AirTree { + pub fn list(mut items: Vec, tipo: Rc, tail: Option) -> AirTree { if let Some(tail) = tail { items.push(tail); @@ -382,7 +382,7 @@ impl AirTree { }) } } - pub fn tuple(items: Vec, tipo: Arc) -> AirTree { + pub fn tuple(items: Vec, tipo: Rc) -> AirTree { AirTree::Expression(AirExpression::Tuple { tipo, items }) } pub fn void() -> AirTree { @@ -399,7 +399,7 @@ impl AirTree { variant_name: variant_name.to_string(), }) } - pub fn local_var(name: impl ToString, tipo: Arc) -> AirTree { + pub fn local_var(name: impl ToString, tipo: Rc) -> AirTree { AirTree::Expression(AirExpression::Var { constructor: ValueConstructor::public( tipo, @@ -411,7 +411,7 @@ impl AirTree { variant_name: "".to_string(), }) } - pub fn call(func: AirTree, tipo: Arc, args: Vec) -> AirTree { + pub fn call(func: AirTree, tipo: Rc, args: Vec) -> AirTree { AirTree::Expression(AirExpression::Call { tipo, func: func.into(), @@ -446,15 +446,15 @@ impl AirTree { func_body: func_body.into(), }) } - pub fn builtin(func: DefaultFunction, tipo: Arc, args: Vec) -> AirTree { + pub fn builtin(func: DefaultFunction, tipo: Rc, args: Vec) -> AirTree { AirTree::Expression(AirExpression::Builtin { func, tipo, args }) } pub fn binop( op: BinOp, - tipo: Arc, + tipo: Rc, left: AirTree, right: AirTree, - argument_tipo: Arc, + argument_tipo: Rc, ) -> AirTree { AirTree::Expression(AirExpression::BinOp { name: op, @@ -479,13 +479,13 @@ impl AirTree { hoisted_over: None, } } - pub fn cast_from_data(value: AirTree, tipo: Arc) -> AirTree { + pub fn cast_from_data(value: AirTree, tipo: Rc) -> AirTree { AirTree::Expression(AirExpression::CastFromData { tipo, value: value.into(), }) } - pub fn cast_to_data(value: AirTree, tipo: Arc) -> AirTree { + pub fn cast_to_data(value: AirTree, tipo: Rc) -> AirTree { AirTree::Expression(AirExpression::CastToData { tipo, value: value.into(), @@ -511,8 +511,8 @@ impl AirTree { } pub fn when( subject_name: impl ToString, - tipo: Arc, - subject_tipo: Arc, + tipo: Rc, + subject_tipo: Rc, subject: AirTree, clauses: AirTree, ) -> AirTree { @@ -527,7 +527,7 @@ impl AirTree { pub fn clause( subject_name: impl ToString, pattern: AirTree, - subject_tipo: Arc, + subject_tipo: Rc, then: AirTree, otherwise: AirTree, complex_clause: bool, @@ -543,7 +543,7 @@ impl AirTree { } pub fn list_clause( tail_name: impl ToString, - subject_tipo: Arc, + subject_tipo: Rc, then: AirTree, otherwise: AirTree, next_tail_name: Option<(String, String)>, @@ -560,7 +560,7 @@ impl AirTree { } pub fn tuple_clause( subject_name: impl ToString, - subject_tipo: Arc, + subject_tipo: Rc, indices: IndexSet<(usize, String)>, predefined_indices: IndexSet<(usize, String)>, then: AirTree, @@ -586,7 +586,7 @@ impl AirTree { pub fn clause_guard( subject_name: impl ToString, pattern: AirTree, - subject_tipo: Arc, + subject_tipo: Rc, ) -> AirTree { AirTree::Statement { statement: AirStatement::ClauseGuard { @@ -599,7 +599,7 @@ impl AirTree { } pub fn list_clause_guard( tail_name: impl ToString, - subject_tipo: Arc, + subject_tipo: Rc, inverse: bool, next_tail_name: Option, ) -> AirTree { @@ -615,7 +615,7 @@ impl AirTree { } pub fn tuple_clause_guard( subject_name: impl ToString, - subject_tipo: Arc, + subject_tipo: Rc, indices: IndexSet<(usize, String)>, ) -> AirTree { AirTree::Statement { @@ -635,7 +635,7 @@ impl AirTree { } pub fn if_branches( mut branches: Vec<(AirTree, AirTree)>, - tipo: Arc, + tipo: Rc, otherwise: AirTree, ) -> AirTree { assert!(!branches.is_empty()); @@ -659,14 +659,14 @@ impl AirTree { final_if } - pub fn create_constr(tag: usize, tipo: Arc, args: Vec) -> AirTree { + pub fn create_constr(tag: usize, tipo: Rc, args: Vec) -> AirTree { AirTree::Expression(AirExpression::Constr { tag, tipo, args }) } pub fn record_update( - indices: Vec<(usize, Arc)>, + indices: Vec<(usize, Rc)>, highest_index: usize, - tipo: Arc, + tipo: Rc, record: AirTree, args: Vec, ) -> AirTree { @@ -678,7 +678,7 @@ impl AirTree { args, }) } - pub fn record_access(field_index: u64, tipo: Arc, record: AirTree) -> AirTree { + pub fn record_access(field_index: u64, tipo: Rc, record: AirTree) -> AirTree { AirTree::Expression(AirExpression::RecordAccess { field_index, tipo, @@ -687,7 +687,7 @@ impl AirTree { } pub fn fields_expose( - indices: Vec<(usize, String, Arc)>, + indices: Vec<(usize, String, Rc)>, check_last_item: bool, record: AirTree, ) -> AirTree { @@ -702,7 +702,7 @@ impl AirTree { } pub fn list_access( names: Vec, - tipo: Arc, + tipo: Rc, tail: bool, check_last_item: bool, list: AirTree, @@ -721,7 +721,7 @@ impl AirTree { pub fn list_expose( tail_head_names: Vec<(String, String)>, tail: Option<(String, String)>, - tipo: Arc, + tipo: Rc, ) -> AirTree { AirTree::Statement { statement: AirStatement::ListExpose { @@ -734,7 +734,7 @@ impl AirTree { } pub fn tuple_access( names: Vec, - tipo: Arc, + tipo: Rc, check_last_item: bool, tuple: AirTree, ) -> AirTree { @@ -748,17 +748,17 @@ impl AirTree { hoisted_over: None, } } - pub fn tuple_index(tuple_index: usize, tipo: Arc, tuple: AirTree) -> AirTree { + pub fn tuple_index(tuple_index: usize, tipo: Rc, tuple: AirTree) -> AirTree { AirTree::Expression(AirExpression::TupleIndex { tipo, tuple_index, tuple: tuple.into(), }) } - pub fn error(tipo: Arc) -> AirTree { + pub fn error(tipo: Rc) -> AirTree { AirTree::Expression(AirExpression::ErrorTerm { tipo }) } - pub fn trace(msg: AirTree, tipo: Arc, then: AirTree) -> AirTree { + pub fn trace(msg: AirTree, tipo: Rc, then: AirTree) -> AirTree { AirTree::Expression(AirExpression::Trace { tipo, msg: msg.into(), @@ -1253,7 +1253,7 @@ impl AirTree { } } - pub fn return_type(&self) -> Arc { + pub fn return_type(&self) -> Rc { match self { AirTree::Statement { hoisted_over: Some(hoisted_over), @@ -1296,7 +1296,7 @@ impl AirTree { } } - pub fn mut_held_types(&mut self) -> Vec<&mut Arc> { + pub fn mut_held_types(&mut self) -> Vec<&mut Rc> { match self { AirTree::Statement { statement, diff --git a/crates/aiken-lang/src/parser/literal/bytearray.rs b/crates/aiken-lang/src/parser/literal/bytearray.rs index 5516b981..e48c49e8 100644 --- a/crates/aiken-lang/src/parser/literal/bytearray.rs +++ b/crates/aiken-lang/src/parser/literal/bytearray.rs @@ -39,9 +39,9 @@ pub fn array_of_bytes( .delimited_by(just(Token::LeftSquare), just(Token::RightSquare)), ) .validate(|bytes, span, emit| { - let base = bytes.iter().fold(Ok(None), |acc, (_, base)| match acc { - Ok(None) => Ok(Some(base)), - Ok(Some(previous_base)) if previous_base == base => Ok(Some(base)), + let base = bytes.iter().try_fold(None, |acc, (_, base)| match acc { + None => Ok(Some(base)), + Some(previous_base) if previous_base == base => Ok(Some(base)), _ => Err(()), }); diff --git a/crates/aiken-lang/src/tipo.rs b/crates/aiken-lang/src/tipo.rs index 1334e79e..5eaf7fa6 100644 --- a/crates/aiken-lang/src/tipo.rs +++ b/crates/aiken-lang/src/tipo.rs @@ -3,7 +3,7 @@ use crate::{ ast::{Constant, DefinitionLocation, ModuleKind, Span}, tipo::fields::FieldMap, }; -use std::{cell::RefCell, collections::HashMap, ops::Deref, sync::Arc}; +use std::{cell::RefCell, collections::HashMap, ops::Deref, rc::Rc}; use uplc::{ast::Type as UplcType, builtins::DefaultFunction}; mod environment; @@ -31,27 +31,27 @@ pub enum Type { public: bool, module: String, name: String, - args: Vec>, + args: Vec>, }, /// The type of a function. It takes arguments and returns a value. /// Fn { - args: Vec>, - ret: Arc, + args: Vec>, + ret: Rc, }, /// A type variable. See the contained `TypeVar` enum for more information. /// Var { - tipo: Arc>, + tipo: Rc>, }, // /// A tuple is an ordered collection of 0 or more values, each of which // /// can have a different type, so the `tuple` type is the sum of all the // /// contained types. // /// Tuple { - elems: Vec>, + elems: Vec>, }, } @@ -75,14 +75,14 @@ impl Type { matches!(self, Self::Fn { .. }) } - pub fn return_type(&self) -> Option> { + pub fn return_type(&self) -> Option> { match self { Self::Fn { ret, .. } => Some(ret.clone()), _ => None, } } - pub fn function_types(&self) -> Option<(Vec>, Arc)> { + pub fn function_types(&self) -> Option<(Vec>, Rc)> { match self { Self::Fn { args, ret, .. } => Some((args.clone(), ret.clone())), _ => None, @@ -224,7 +224,7 @@ impl Type { } } - pub fn arg_types(&self) -> Option>> { + pub fn arg_types(&self) -> Option>> { match self { Self::Fn { args, .. } => Some(args.clone()), Self::App { args, .. } => Some(args.clone()), @@ -240,7 +240,7 @@ impl Type { } } - pub fn get_inner_types(&self) -> Vec> { + pub fn get_inner_types(&self) -> Vec> { if self.is_list() { match self { Self::App { args, .. } => args.clone(), @@ -310,7 +310,7 @@ impl Type { name: &str, arity: usize, environment: &mut Environment<'_>, - ) -> Option>> { + ) -> Option>> { match self { Self::App { module: m, @@ -341,7 +341,7 @@ impl Type { // We are an unbound type variable! So convert us to a type link // to the desired type. *tipo.borrow_mut() = TypeVar::Link { - tipo: Arc::new(Self::App { + tipo: Rc::new(Self::App { name: name.to_string(), module: module.to_owned(), args: args.clone(), @@ -407,7 +407,7 @@ pub enum TypeVar { /// Link is type variable where it was an unbound variable but we worked out /// that it is some other type and now we point to that one. /// - Link { tipo: Arc }, + Link { tipo: Rc }, /// A Generic variable stands in for any possible type and cannot be /// specialised to any one type /// @@ -521,14 +521,14 @@ impl TypeVar { } } - pub fn arg_types(&self) -> Option>> { + pub fn arg_types(&self) -> Option>> { match self { Self::Link { tipo } => tipo.arg_types(), _ => None, } } - pub fn get_inner_types(&self) -> Vec> { + pub fn get_inner_types(&self) -> Vec> { match self { Self::Link { tipo } => tipo.get_inner_types(), var => { @@ -552,11 +552,11 @@ impl TypeVar { pub struct ValueConstructor { pub public: bool, pub variant: ValueConstructorVariant, - pub tipo: Arc, + pub tipo: Rc, } impl ValueConstructor { - pub fn public(tipo: Arc, variant: ValueConstructorVariant) -> ValueConstructor { + pub fn public(tipo: Rc, variant: ValueConstructorVariant) -> ValueConstructor { ValueConstructor { public: true, variant, @@ -633,7 +633,7 @@ pub enum ValueConstructorVariant { impl ValueConstructorVariant { fn to_module_value_constructor( &self, - tipo: Arc, + tipo: Rc, module_name: &str, function_name: &str, ) -> ModuleValueConstructor { @@ -710,14 +710,14 @@ pub struct TypeConstructor { pub public: bool, pub location: Span, pub module: String, - pub parameters: Vec>, - pub tipo: Arc, + pub parameters: Vec>, + pub tipo: Rc, } #[derive(Debug, Clone)] pub struct AccessorsMap { pub public: bool, - pub tipo: Arc, + pub tipo: Rc, pub accessors: HashMap, } @@ -726,7 +726,7 @@ pub struct RecordAccessor { // TODO: smaller int. Doesn't need to be this big pub index: u64, pub label: String, - pub tipo: Arc, + pub tipo: Rc, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -742,7 +742,7 @@ pub enum ModuleValueConstructor { Record { name: String, arity: usize, - tipo: Arc, + tipo: Rc, field_map: Option, location: Span, }, diff --git a/crates/aiken-lang/src/tipo/environment.rs b/crates/aiken-lang/src/tipo/environment.rs index 0c8d76ca..b95a5a0b 100644 --- a/crates/aiken-lang/src/tipo/environment.rs +++ b/crates/aiken-lang/src/tipo/environment.rs @@ -1,7 +1,7 @@ use std::{ collections::{HashMap, HashSet}, ops::Deref, - sync::Arc, + rc::Rc, }; use crate::{ @@ -104,11 +104,11 @@ impl<'a> Environment<'a> { pub fn match_fun_type( &mut self, - tipo: Arc, + tipo: Rc, arity: usize, fn_location: Span, call_location: Span, - ) -> Result<(Vec>, Arc), Error> { + ) -> Result<(Vec>, Rc), Error> { if let Type::Var { tipo } = tipo.deref() { let new_value = match tipo.borrow().deref() { TypeVar::Link { tipo, .. } => { @@ -492,7 +492,7 @@ impl<'a> Environment<'a> { &mut self, name: String, variant: ValueConstructorVariant, - tipo: Arc, + tipo: Rc, ) { self.scope.insert( name, @@ -507,10 +507,10 @@ impl<'a> Environment<'a> { /// Instantiate converts generic variables into unbound ones. pub fn instantiate( &mut self, - t: Arc, - ids: &mut HashMap>, + t: Rc, + ids: &mut HashMap>, hydrator: &Hydrator, - ) -> Arc { + ) -> Rc { match t.deref() { Type::App { public, @@ -522,7 +522,7 @@ impl<'a> Environment<'a> { .iter() .map(|t| self.instantiate(t.clone(), ids, hydrator)) .collect(); - Arc::new(Type::App { + Rc::new(Type::App { public: *public, name: name.clone(), module: module.clone(), @@ -534,7 +534,7 @@ impl<'a> Environment<'a> { match tipo.borrow().deref() { TypeVar::Link { tipo } => return self.instantiate(tipo.clone(), ids, hydrator), - TypeVar::Unbound { .. } => return Arc::new(Type::Var { tipo: tipo.clone() }), + TypeVar::Unbound { .. } => return Rc::new(Type::Var { tipo: tipo.clone() }), TypeVar::Generic { id } => match ids.get(id) { Some(t) => return t.clone(), @@ -550,7 +550,7 @@ impl<'a> Environment<'a> { } }, } - Arc::new(Type::Var { tipo: tipo.clone() }) + Rc::new(Type::Var { tipo: tipo.clone() }) } Type::Fn { args, ret, .. } => function( @@ -582,7 +582,7 @@ impl<'a> Environment<'a> { args: &[String], location: &Span, hydrator: &mut Hydrator, - ) -> Result>, Error> { + ) -> Result>, Error> { let mut type_vars = Vec::new(); for arg in args { @@ -630,13 +630,13 @@ impl<'a> Environment<'a> { } /// Create a new generic type that can stand in for any type. - pub fn new_generic_var(&mut self) -> Arc { + pub fn new_generic_var(&mut self) -> Rc { generic_var(self.next_uid()) } /// Create a new unbound type that is a specific type, we just don't /// know which one yet. - pub fn new_unbound_var(&mut self) -> Arc { + pub fn new_unbound_var(&mut self) -> Rc { unbound_var(self.next_uid()) } @@ -931,7 +931,7 @@ impl<'a> Environment<'a> { let parameters = self.make_type_vars(parameters, location, &mut hydrator)?; - let tipo = Arc::new(Type::App { + let tipo = Rc::new(Type::App { public: *public, module: module.to_owned(), name: name.clone(), @@ -1276,8 +1276,8 @@ impl<'a> Environment<'a> { #[allow(clippy::only_used_in_recursion)] pub fn unify( &mut self, - t1: Arc, - t2: Arc, + t1: Rc, + t2: Rc, location: Span, allow_cast: bool, ) -> Result<(), Error> { @@ -1305,7 +1305,7 @@ impl<'a> Environment<'a> { if let Type::Var { tipo } = t1.deref() { enum Action { - Unify(Arc), + Unify(Rc), CouldNotUnify, Link, } @@ -1585,7 +1585,7 @@ pub enum EntityKind { /// prevents the algorithm from inferring recursive types, which /// could cause naively-implemented type checking to diverge. /// While traversing the type tree. -fn unify_unbound_type(tipo: Arc, own_id: u64, location: Span) -> Result<(), Error> { +fn unify_unbound_type(tipo: Rc, own_id: u64, location: Span) -> Result<(), Error> { if let Type::Var { tipo } = tipo.deref() { let new_value = match tipo.borrow().deref() { TypeVar::Link { tipo, .. } => { @@ -1638,11 +1638,7 @@ fn unify_unbound_type(tipo: Arc, own_id: u64, location: Span) -> Result<() } } -fn unify_enclosed_type( - e1: Arc, - e2: Arc, - result: Result<(), Error>, -) -> Result<(), Error> { +fn unify_enclosed_type(e1: Rc, e2: Rc, result: Result<(), Error>) -> Result<(), Error> { // If types cannot unify, show the type error with the enclosing types, e1 and e2. match result { Err(Error::CouldNotUnify { @@ -1716,7 +1712,7 @@ pub(super) fn assert_no_labeled_arguments(args: &[CallArg]) -> Option<(Spa None } -pub(super) fn collapse_links(t: Arc) -> Arc { +pub(super) fn collapse_links(t: Rc) -> Rc { if let Type::Var { tipo } = t.deref() { if let TypeVar::Link { tipo } = tipo.borrow().deref() { return tipo.clone(); @@ -1757,12 +1753,12 @@ fn get_compatible_record_fields( /// Takes a level and a type and turns all type variables within the type that have /// level higher than the input level into generalized (polymorphic) type variables. #[allow(clippy::only_used_in_recursion)] -pub(crate) fn generalise(t: Arc, ctx_level: usize) -> Arc { +pub(crate) fn generalise(t: Rc, ctx_level: usize) -> Rc { match t.deref() { Type::Var { tipo } => match tipo.borrow().deref() { TypeVar::Unbound { id } => generic_var(*id), TypeVar::Link { tipo } => generalise(tipo.clone(), ctx_level), - TypeVar::Generic { .. } => Arc::new(Type::Var { tipo: tipo.clone() }), + TypeVar::Generic { .. } => Rc::new(Type::Var { tipo: tipo.clone() }), }, Type::App { @@ -1776,7 +1772,7 @@ pub(crate) fn generalise(t: Arc, ctx_level: usize) -> Arc { .map(|t| generalise(t.clone(), ctx_level)) .collect(); - Arc::new(Type::App { + Rc::new(Type::App { public: *public, module: module.clone(), name: name.clone(), diff --git a/crates/aiken-lang/src/tipo/error.rs b/crates/aiken-lang/src/tipo/error.rs index b909e2d7..a99a07ef 100644 --- a/crates/aiken-lang/src/tipo/error.rs +++ b/crates/aiken-lang/src/tipo/error.rs @@ -13,7 +13,7 @@ use owo_colors::{ OwoColorize, Stream::{Stderr, Stdout}, }; -use std::{collections::HashMap, fmt::Display, sync::Arc}; +use std::{collections::HashMap, fmt::Display, rc::Rc}; #[derive(Debug, thiserror::Error, Diagnostic, Clone)] #[error("Something is possibly wrong here...")] @@ -89,8 +89,8 @@ pub enum Error { expected.to_pretty_with_names(rigid_type_names.clone(), 0), )] location: Span, - expected: Arc, - given: Arc, + expected: Rc, + given: Rc, situation: Option, rigid_type_names: HashMap, }, @@ -474,7 +474,7 @@ If you really meant to return that last expression, try to replace it with the f NotATuple { #[label] location: Span, - tipo: Arc, + tipo: Rc, }, #[error("{}\n", if *is_let { @@ -521,7 +521,7 @@ In this particular instance, the following cases are unmatched: NotFn { #[label] location: Span, - tipo: Arc, + tipo: Rc, }, #[error("I discovered a positional argument after a label argument.\n")] @@ -769,7 +769,7 @@ Perhaps, try the following: UnknownRecordField { #[label] location: Span, - typ: Arc, + typ: Rc, label: String, fields: Vec, situation: Option, @@ -880,7 +880,7 @@ The best thing to do from here is to remove it."#))] ValidatorMustReturnBool { #[label("invalid return type")] location: Span, - return_type: Arc, + return_type: Rc, }, #[error("Validators require at least 2 arguments and at most 3 arguments.\n")] @@ -1072,8 +1072,8 @@ fn suggest_constructor_pattern( } fn suggest_unify( - expected: &Arc, - given: &Arc, + expected: &Rc, + given: &Rc, situation: &Option, rigid_type_names: &HashMap, ) -> String { @@ -1356,7 +1356,7 @@ pub enum Warning { Todo { #[label("An expression of type {} is expected here.", tipo.to_pretty(0))] location: Span, - tipo: Arc, + tipo: Rc, }, #[error("I found a type hole in an annotation.\n")] @@ -1364,7 +1364,7 @@ pub enum Warning { UnexpectedTypeHole { #[label("{}", tipo.to_pretty(0))] location: Span, - tipo: Arc, + tipo: Rc, }, #[error( diff --git a/crates/aiken-lang/src/tipo/expr.rs b/crates/aiken-lang/src/tipo/expr.rs index 0d1c6507..6030acb7 100644 --- a/crates/aiken-lang/src/tipo/expr.rs +++ b/crates/aiken-lang/src/tipo/expr.rs @@ -1,4 +1,4 @@ -use std::{cmp::Ordering, collections::HashMap, sync::Arc}; +use std::{cmp::Ordering, collections::HashMap, rc::Rc}; use vec1::Vec1; use crate::{ @@ -73,7 +73,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { fun: UntypedExpr, args: Vec>, location: Span, - ) -> Result<(TypedExpr, Vec, Arc), Error> { + ) -> Result<(TypedExpr, Vec, Rc), Error> { let fun = self.infer(fun)?; let (fun, args, typ) = self.do_infer_call_with_known_fun(fun, args, location)?; @@ -86,7 +86,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { fun: TypedExpr, mut args: Vec>, location: Span, - ) -> Result<(TypedExpr, Vec, Arc), Error> { + ) -> Result<(TypedExpr, Vec, Rc), Error> { // Check to see if the function accepts labelled arguments match self.get_field_map(&fun, location)? { // The fun has a field map so labelled arguments may be present and need to be reordered. @@ -127,7 +127,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { pub fn do_infer_fn( &mut self, args: Vec, - expected_args: &[Arc], + expected_args: &[Rc], body: UntypedExpr, return_annotation: &Option, ) -> Result<(Vec, TypedExpr), Error> { @@ -712,19 +712,19 @@ impl<'a, 'b> ExprTyper<'a, 'b> { let constructor = match &constructor.variant { variant @ ValueConstructorVariant::ModuleFn { name, module, .. } => { - variant.to_module_value_constructor(Arc::clone(&tipo), module, name) + variant.to_module_value_constructor(Rc::clone(&tipo), module, name) } variant @ (ValueConstructorVariant::LocalVariable { .. } | ValueConstructorVariant::ModuleConstant { .. } | ValueConstructorVariant::Record { .. }) => { - variant.to_module_value_constructor(Arc::clone(&tipo), &module_name, &label) + variant.to_module_value_constructor(Rc::clone(&tipo), &module_name, &label) } }; Ok(TypedExpr::ModuleSelect { label, - tipo: Arc::clone(&tipo), + tipo: Rc::clone(&tipo), location: select_location, module_name, module_alias: module_alias.to_string(), @@ -825,7 +825,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { fn infer_param( &mut self, arg: UntypedArg, - expected: Option>, + expected: Option>, ) -> Result { let Arg { arg_name, @@ -984,7 +984,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { fn infer_call_argument( &mut self, value: UntypedExpr, - tipo: Arc, + tipo: Rc, ) -> Result { let tipo = collapse_links(tipo); @@ -1419,7 +1419,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { fn infer_fn( &mut self, args: Vec, - expected_args: &[Arc], + expected_args: &[Rc], body: UntypedExpr, is_capture: bool, return_annotation: Option, @@ -1445,7 +1445,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { &mut self, args: Vec, body: UntypedExpr, - return_type: Option>, + return_type: Option>, ) -> Result<(Vec, TypedExpr), Error> { assert_no_assignment(&body)?; @@ -1922,7 +1922,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { }) } - fn instantiate(&mut self, t: Arc, ids: &mut HashMap>) -> Arc { + fn instantiate(&mut self, t: Rc, ids: &mut HashMap>) -> Rc { self.environment.instantiate(t, ids, &self.hydrator) } @@ -1935,19 +1935,19 @@ impl<'a, 'b> ExprTyper<'a, 'b> { } } - pub fn new_unbound_var(&mut self) -> Arc { + pub fn new_unbound_var(&mut self) -> Rc { self.environment.new_unbound_var() } - pub fn type_from_annotation(&mut self, annotation: &Annotation) -> Result, Error> { + pub fn type_from_annotation(&mut self, annotation: &Annotation) -> Result, Error> { self.hydrator .type_from_annotation(annotation, self.environment) } fn unify( &mut self, - t1: Arc, - t2: Arc, + t1: Rc, + t2: Rc, location: Span, allow_cast: bool, ) -> Result<(), Error> { diff --git a/crates/aiken-lang/src/tipo/hydrator.rs b/crates/aiken-lang/src/tipo/hydrator.rs index a06482c8..6701e58e 100644 --- a/crates/aiken-lang/src/tipo/hydrator.rs +++ b/crates/aiken-lang/src/tipo/hydrator.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, sync::Arc}; +use std::{collections::HashMap, rc::Rc}; use crate::{ ast::Annotation, @@ -26,7 +26,7 @@ use super::{ /// #[derive(Debug)] pub struct Hydrator { - created_type_variables: HashMap>, + created_type_variables: HashMap>, /// A rigid type is a generic type that was specified as being generic in /// an annotation. As such it should never be instantiated into an unbound /// variable. This type_id => name map is used for reporting the original @@ -37,7 +37,7 @@ pub struct Hydrator { #[derive(Debug)] pub struct ScopeResetData { - created_type_variables: HashMap>, + created_type_variables: HashMap>, rigid_type_names: HashMap, } @@ -90,7 +90,7 @@ impl Hydrator { &mut self, ast: &Option, environment: &mut Environment, - ) -> Result, Error> { + ) -> Result, Error> { match ast { Some(ast) => self.type_from_annotation(ast, environment), None => Ok(environment.new_unbound_var()), @@ -101,7 +101,7 @@ impl Hydrator { &mut self, annotation: &Annotation, environment: &mut Environment, - ) -> Result, Error> { + ) -> Result, Error> { let mut unbounds = vec![]; let tipo = self.do_type_from_annotation(annotation, environment, &mut unbounds)?; @@ -122,7 +122,7 @@ impl Hydrator { annotation: &'a Annotation, environment: &mut Environment, unbounds: &mut Vec<&'a Span>, - ) -> Result, Error> { + ) -> Result, Error> { match annotation { Annotation::Constructor { location, diff --git a/crates/aiken-lang/src/tipo/pattern.rs b/crates/aiken-lang/src/tipo/pattern.rs index e4241fad..afe90ec6 100644 --- a/crates/aiken-lang/src/tipo/pattern.rs +++ b/crates/aiken-lang/src/tipo/pattern.rs @@ -3,7 +3,7 @@ use std::{ collections::{HashMap, HashSet}, ops::Deref, - sync::Arc, + rc::Rc, }; use itertools::Itertools; @@ -44,7 +44,7 @@ impl<'a, 'b> PatternTyper<'a, 'b> { fn insert_variable( &mut self, name: &str, - typ: Arc, + typ: Rc, location: Span, err_location: Span, ) -> Result<(), Error> { @@ -132,7 +132,7 @@ impl<'a, 'b> PatternTyper<'a, 'b> { pattern: UntypedPattern, subject: &Type, ) -> Result { - self.unify(pattern, Arc::new(subject.clone()), None, false) + self.unify(pattern, Rc::new(subject.clone()), None, false) } /// When we have an assignment or a case expression we unify the pattern with the @@ -141,8 +141,8 @@ impl<'a, 'b> PatternTyper<'a, 'b> { pub fn unify( &mut self, pattern: UntypedPattern, - tipo: Arc, - ann_type: Option>, + tipo: Rc, + ann_type: Option>, is_assignment: bool, ) -> Result { match pattern { diff --git a/crates/aiken-lang/src/tipo/pipe.rs b/crates/aiken-lang/src/tipo/pipe.rs index d0b0e481..2a564982 100644 --- a/crates/aiken-lang/src/tipo/pipe.rs +++ b/crates/aiken-lang/src/tipo/pipe.rs @@ -1,4 +1,4 @@ -use std::{ops::Deref, sync::Arc}; +use std::{ops::Deref, rc::Rc}; use vec1::Vec1; @@ -17,7 +17,7 @@ use super::{ #[derive(Debug)] pub(crate) struct PipeTyper<'a, 'b, 'c> { size: usize, - argument_type: Arc, + argument_type: Rc, argument_location: Span, location: Span, expressions: Vec, diff --git a/crates/aiken-lang/src/tipo/pretty.rs b/crates/aiken-lang/src/tipo/pretty.rs index c851d219..892d3042 100644 --- a/crates/aiken-lang/src/tipo/pretty.rs +++ b/crates/aiken-lang/src/tipo/pretty.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, sync::Arc}; +use std::{collections::HashMap, rc::Rc}; use itertools::Itertools; @@ -45,7 +45,7 @@ impl Printer { } // TODO: have this function return a Document that borrows from the Type. - // Is this possible? The lifetime would have to go through the Arc> + // Is this possible? The lifetime would have to go through the Rc> // for TypeVar::Link'd types. pub fn print<'a>(&mut self, typ: &Type) -> Document<'a> { match typ { @@ -141,7 +141,7 @@ impl Printer { chars.into_iter().rev().collect() } - fn args_to_aiken_doc<'a>(&mut self, args: &[Arc]) -> Document<'a> { + fn args_to_aiken_doc<'a>(&mut self, args: &[Rc]) -> Document<'a> { if args.is_empty() { return nil(); } @@ -284,13 +284,13 @@ mod tests { name: "Pair".to_string(), public: true, args: vec![ - Arc::new(Type::App { + Rc::new(Type::App { module: "whatever".to_string(), name: "Int".to_string(), public: true, args: vec![], }), - Arc::new(Type::App { + Rc::new(Type::App { module: "whatever".to_string(), name: "Bool".to_string(), public: true, @@ -303,20 +303,20 @@ mod tests { assert_string!( Type::Fn { args: vec![ - Arc::new(Type::App { + Rc::new(Type::App { args: vec![], module: "whatever".to_string(), name: "Int".to_string(), public: true, }), - Arc::new(Type::App { + Rc::new(Type::App { args: vec![], module: "whatever".to_string(), name: "Bool".to_string(), public: true, }), ], - ret: Arc::new(Type::App { + ret: Rc::new(Type::App { args: vec![], module: "whatever".to_string(), name: "Bool".to_string(), @@ -327,8 +327,8 @@ mod tests { ); assert_string!( Type::Var { - tipo: Arc::new(RefCell::new(TypeVar::Link { - tipo: Arc::new(Type::App { + tipo: Rc::new(RefCell::new(TypeVar::Link { + tipo: Rc::new(Type::App { args: vec![], module: "whatever".to_string(), name: "Int".to_string(), @@ -340,28 +340,28 @@ mod tests { ); assert_string!( Type::Var { - tipo: Arc::new(RefCell::new(TypeVar::Unbound { id: 2231 })), + tipo: Rc::new(RefCell::new(TypeVar::Unbound { id: 2231 })), }, "a", ); assert_string!( function( - vec![Arc::new(Type::Var { - tipo: Arc::new(RefCell::new(TypeVar::Unbound { id: 78 })), + vec![Rc::new(Type::Var { + tipo: Rc::new(RefCell::new(TypeVar::Unbound { id: 78 })), })], - Arc::new(Type::Var { - tipo: Arc::new(RefCell::new(TypeVar::Unbound { id: 2 })), + Rc::new(Type::Var { + tipo: Rc::new(RefCell::new(TypeVar::Unbound { id: 2 })), }), ), "fn(a) -> b", ); assert_string!( function( - vec![Arc::new(Type::Var { - tipo: Arc::new(RefCell::new(TypeVar::Generic { id: 78 })), + vec![Rc::new(Type::Var { + tipo: Rc::new(RefCell::new(TypeVar::Generic { id: 78 })), })], - Arc::new(Type::Var { - tipo: Arc::new(RefCell::new(TypeVar::Generic { id: 2 })), + Rc::new(Type::Var { + tipo: Rc::new(RefCell::new(TypeVar::Generic { id: 2 })), }), ), "fn(a) -> b", @@ -378,7 +378,7 @@ mod tests { ); } - fn pretty_print(typ: Arc) -> String { + fn pretty_print(typ: Rc) -> String { Printer::new().pretty_print(&typ, 0) } } diff --git a/crates/aiken-project/Cargo.toml b/crates/aiken-project/Cargo.toml index 016a50e1..d91e560d 100644 --- a/crates/aiken-project/Cargo.toml +++ b/crates/aiken-project/Cargo.toml @@ -46,5 +46,5 @@ aiken-lang = { path = "../aiken-lang", version = "1.0.16-alpha" } uplc = { path = '../uplc', version = "1.0.16-alpha" } [dev-dependencies] -proptest = "1.1.0" +proptest = "1.2.0" pretty_assertions = "1.3.0" diff --git a/crates/aiken-project/src/blueprint/definitions.rs b/crates/aiken-project/src/blueprint/definitions.rs index bdd1e01e..492e3cb3 100644 --- a/crates/aiken-project/src/blueprint/definitions.rs +++ b/crates/aiken-project/src/blueprint/definitions.rs @@ -8,7 +8,7 @@ use std::{ collections::{BTreeMap, HashMap}, fmt::{self, Display}, ops::Deref, - sync::Arc, + rc::Rc, }; // ---------- Definitions @@ -68,7 +68,7 @@ impl Definitions { pub fn register( &mut self, type_info: &Type, - type_parameters: &HashMap>, + type_parameters: &HashMap>, build_schema: F, ) -> Result where @@ -124,7 +124,7 @@ impl Display for Reference { } impl Reference { - pub fn from_type(type_info: &Type, type_parameters: &HashMap>) -> Self { + pub fn from_type(type_info: &Type, type_parameters: &HashMap>) -> Self { match type_info { Type::App { module, name, args, .. @@ -168,7 +168,7 @@ impl Reference { } } - fn from_types(args: &Vec>, type_parameters: &HashMap>) -> Self { + fn from_types(args: &Vec>, type_parameters: &HashMap>) -> Self { if args.is_empty() { Reference::new("") } else { diff --git a/crates/aiken-project/src/blueprint/schema.rs b/crates/aiken-project/src/blueprint/schema.rs index 16a42e26..125decbb 100644 --- a/crates/aiken-project/src/blueprint/schema.rs +++ b/crates/aiken-project/src/blueprint/schema.rs @@ -1,7 +1,7 @@ use crate::blueprint::definitions::{Definitions, Reference}; use crate::CheckedModule; use aiken_lang::{ - ast::{DataType, Definition, TypedDefinition}, + ast::{Definition, TypedDataType, TypedDefinition}, builtins::wrapped_redeemer, tipo::{pretty, Type, TypeVar}, }; @@ -12,7 +12,8 @@ use serde::{ ser::{Serialize, SerializeStruct, Serializer}, }; use serde_json as json; -use std::{collections::HashMap, fmt, ops::Deref, sync::Arc}; +use std::rc::Rc; +use std::{collections::HashMap, fmt, ops::Deref}; // NOTE: Can be anything BUT 0 pub const REDEEMER_DISCRIMINANT: usize = 1; @@ -124,7 +125,7 @@ impl Annotated { pub fn as_wrapped_redeemer( definitions: &mut Definitions>, schema: Reference, - type_info: Arc, + type_info: Rc, ) -> Reference { definitions .register( @@ -156,7 +157,7 @@ impl Annotated { fn do_from_type( type_info: &Type, modules: &HashMap, - type_parameters: &mut HashMap>, + type_parameters: &mut HashMap>, definitions: &mut Definitions, ) -> Result { match type_info { @@ -403,9 +404,9 @@ impl Annotated { impl Data { fn from_data_type( - data_type: &DataType>, + data_type: &TypedDataType, modules: &HashMap, - type_parameters: &mut HashMap>, + type_parameters: &mut HashMap>, definitions: &mut Definitions>, ) -> Result { let mut variants = vec![]; @@ -451,9 +452,9 @@ impl Data { } fn collect_type_parameters<'a>( - type_parameters: &'a mut HashMap>, - generics: &'a [Arc], - applications: &'a [Arc], + type_parameters: &'a mut HashMap>, + generics: &'a [Rc], + applications: &'a [Rc], ) { for (index, generic) in generics.iter().enumerate() { match &**generic { @@ -474,7 +475,7 @@ fn collect_type_parameters<'a>( } } -fn find_data_type(name: &str, definitions: &[TypedDefinition]) -> Option>> { +fn find_data_type(name: &str, definitions: &[TypedDefinition]) -> Option { for def in definitions { match def { Definition::DataType(data_type) if name == data_type.name => { diff --git a/crates/aiken-project/src/docs.rs b/crates/aiken-project/src/docs.rs index dc8b3f72..dbbbbbc6 100644 --- a/crates/aiken-project/src/docs.rs +++ b/crates/aiken-project/src/docs.rs @@ -14,7 +14,7 @@ use serde::Serialize; use serde_json as json; use std::{ path::{Path, PathBuf}, - sync::Arc, + rc::Rc, time::{Duration, SystemTime}, }; @@ -524,7 +524,7 @@ struct DocTypeConstructor { } impl DocTypeConstructor { - fn from_record_constructor(constructor: &RecordConstructor>) -> Self { + fn from_record_constructor(constructor: &RecordConstructor>) -> Self { DocTypeConstructor { definition: format::Formatter::new() .docs_record_constructor(constructor) diff --git a/crates/aiken-project/src/tests/gen_uplc.rs b/crates/aiken-project/src/tests/gen_uplc.rs index a66b946a..fb3bc96e 100644 --- a/crates/aiken-project/src/tests/gen_uplc.rs +++ b/crates/aiken-project/src/tests/gen_uplc.rs @@ -1,12 +1,6 @@ -use std::sync::Arc; - use pretty_assertions::assert_eq; -use aiken_lang::{ - ast::{Definition, Function, Validator}, - expr::TypedExpr, - tipo::Type as AikenType, -}; +use aiken_lang::ast::{Definition, Function, TypedFunction, TypedValidator}; use uplc::{ ast::{Constant, Data, DeBruijn, Name, Program, Term, Type}, builder::{CONSTR_FIELDS_EXPOSER, CONSTR_GET_FIELD, CONSTR_INDEX_EXPOSER}, @@ -19,8 +13,8 @@ use crate::module::CheckedModules; use super::TestProject; enum TestType { - Func(Function, TypedExpr>), - Validator(Validator, TypedExpr>), + Func(TypedFunction), + Validator(TypedValidator), } fn assert_uplc(source_code: &str, expected: Term, should_fail: bool) {