chore: clippy fix
This commit is contained in:
parent
bc0824f4eb
commit
d808197507
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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<Token> {
|
|||
}
|
||||
}
|
||||
|
||||
pub type TypedFunction = Function<Arc<Type>, TypedExpr>;
|
||||
pub type TypedFunction = Function<Rc<Type>, TypedExpr>;
|
||||
pub type UntypedFunction = Function<(), UntypedExpr>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -146,7 +146,7 @@ pub struct Function<T, Expr> {
|
|||
pub can_error: bool,
|
||||
}
|
||||
|
||||
pub type TypedTypeAlias = TypeAlias<Arc<Type>>;
|
||||
pub type TypedTypeAlias = TypeAlias<Rc<Type>>;
|
||||
pub type UntypedTypeAlias = TypeAlias<()>;
|
||||
|
||||
impl TypedFunction {
|
||||
|
@ -206,7 +206,7 @@ pub struct TypeAlias<T> {
|
|||
pub tipo: T,
|
||||
}
|
||||
|
||||
pub type TypedDataType = DataType<Arc<Type>>;
|
||||
pub type TypedDataType = DataType<Rc<Type>>;
|
||||
|
||||
impl TypedDataType {
|
||||
pub fn ordering() -> Self {
|
||||
|
@ -244,7 +244,7 @@ impl TypedDataType {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn option(tipo: Arc<Type>) -> Self {
|
||||
pub fn option(tipo: Rc<Type>) -> Self {
|
||||
DataType {
|
||||
constructors: vec![
|
||||
RecordConstructor {
|
||||
|
@ -308,7 +308,7 @@ pub struct Use<PackageName> {
|
|||
pub unqualified: Vec<UnqualifiedImport>,
|
||||
}
|
||||
|
||||
pub type TypedModuleConstant = ModuleConstant<Arc<Type>>;
|
||||
pub type TypedModuleConstant = ModuleConstant<Rc<Type>>;
|
||||
pub type UntypedModuleConstant = ModuleConstant<()>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -322,7 +322,7 @@ pub struct ModuleConstant<T> {
|
|||
pub tipo: T,
|
||||
}
|
||||
|
||||
pub type TypedValidator = Validator<Arc<Type>, TypedExpr>;
|
||||
pub type TypedValidator = Validator<Rc<Type>, TypedExpr>;
|
||||
pub type UntypedValidator = Validator<(), UntypedExpr>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -335,7 +335,7 @@ pub struct Validator<T, Expr> {
|
|||
pub params: Vec<Arg<T>>,
|
||||
}
|
||||
|
||||
pub type TypedDefinition = Definition<Arc<Type>, TypedExpr, String>;
|
||||
pub type TypedDefinition = Definition<Rc<Type>, 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<Type> {
|
||||
pub fn tipo(&self) -> Rc<Type> {
|
||||
match self {
|
||||
Constant::Int { .. } => builtins::int(),
|
||||
Constant::String { .. } => builtins::string(),
|
||||
|
@ -537,7 +537,7 @@ impl<T: PartialEq> RecordConstructorArg<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub type TypedArg = Arg<Arc<Type>>;
|
||||
pub type TypedArg = Arg<Rc<Type>>;
|
||||
pub type UntypedArg = Arg<()>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -824,7 +824,7 @@ impl BinOp {
|
|||
}
|
||||
|
||||
pub type UntypedPattern = Pattern<(), ()>;
|
||||
pub type TypedPattern = Pattern<PatternConstructor, Arc<Type>>;
|
||||
pub type TypedPattern = Pattern<PatternConstructor, Rc<Type>>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Pattern<Constructor, Type> {
|
||||
|
@ -947,7 +947,7 @@ impl AssignmentKind {
|
|||
pub type MultiPattern<PatternConstructor, Type> = Vec<Pattern<PatternConstructor, Type>>;
|
||||
|
||||
pub type UntypedMultiPattern = MultiPattern<(), ()>;
|
||||
pub type TypedMultiPattern = MultiPattern<PatternConstructor, Arc<Type>>;
|
||||
pub type TypedMultiPattern = MultiPattern<PatternConstructor, Rc<Type>>;
|
||||
|
||||
#[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<PatternConstructor, Arc<Type>>,
|
||||
pub guard: Option<ClauseGuard<Arc<Type>>>,
|
||||
pub pattern: Pattern<PatternConstructor, Rc<Type>>,
|
||||
pub guard: Option<ClauseGuard<Rc<Type>>>,
|
||||
pub then: TypedExpr,
|
||||
}
|
||||
|
||||
|
@ -979,7 +979,7 @@ impl TypedClause {
|
|||
}
|
||||
|
||||
pub type UntypedClauseGuard = ClauseGuard<()>;
|
||||
pub type TypedClauseGuard = ClauseGuard<Arc<Type>>;
|
||||
pub type TypedClauseGuard = ClauseGuard<Rc<Type>>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum ClauseGuard<Type> {
|
||||
|
@ -1079,7 +1079,7 @@ impl<A> ClauseGuard<A> {
|
|||
}
|
||||
|
||||
impl TypedClauseGuard {
|
||||
pub fn tipo(&self) -> Arc<Type> {
|
||||
pub fn tipo(&self) -> Rc<Type> {
|
||||
match self {
|
||||
ClauseGuard::Var { tipo, .. } => tipo.clone(),
|
||||
ClauseGuard::Constant(constant) => constant.tipo(),
|
||||
|
|
|
@ -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<DataTypeKey, TypedDa
|
|||
data_types
|
||||
}
|
||||
|
||||
pub fn int() -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn int() -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
public: true,
|
||||
name: INT.to_string(),
|
||||
module: "".to_string(),
|
||||
|
@ -968,8 +968,8 @@ pub fn int() -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn data() -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn data() -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
public: true,
|
||||
name: DATA.to_string(),
|
||||
module: "".to_string(),
|
||||
|
@ -977,8 +977,8 @@ pub fn data() -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn byte_array() -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn byte_array() -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
args: vec![],
|
||||
public: true,
|
||||
name: BYTE_ARRAY.to_string(),
|
||||
|
@ -986,12 +986,12 @@ pub fn byte_array() -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn tuple(elems: Vec<Arc<Type>>) -> Arc<Type> {
|
||||
Arc::new(Type::Tuple { elems })
|
||||
pub fn tuple(elems: Vec<Rc<Type>>) -> Rc<Type> {
|
||||
Rc::new(Type::Tuple { elems })
|
||||
}
|
||||
|
||||
pub fn bool() -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn bool() -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
args: vec![],
|
||||
public: true,
|
||||
name: BOOL.to_string(),
|
||||
|
@ -999,8 +999,8 @@ pub fn bool() -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn list(t: Arc<Type>) -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn list(t: Rc<Type>) -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
public: true,
|
||||
name: LIST.to_string(),
|
||||
module: "".to_string(),
|
||||
|
@ -1008,8 +1008,8 @@ pub fn list(t: Arc<Type>) -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn string() -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn string() -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
args: vec![],
|
||||
public: true,
|
||||
name: STRING.to_string(),
|
||||
|
@ -1017,8 +1017,8 @@ pub fn string() -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn void() -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn void() -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
args: vec![],
|
||||
public: true,
|
||||
name: VOID.to_string(),
|
||||
|
@ -1026,8 +1026,8 @@ pub fn void() -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn result(a: Arc<Type>, e: Arc<Type>) -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn result(a: Rc<Type>, e: Rc<Type>) -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
public: true,
|
||||
name: RESULT.to_string(),
|
||||
module: "".to_string(),
|
||||
|
@ -1035,8 +1035,8 @@ pub fn result(a: Arc<Type>, e: Arc<Type>) -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn option(a: Arc<Type>) -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn option(a: Rc<Type>) -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
public: true,
|
||||
name: OPTION.to_string(),
|
||||
module: "".to_string(),
|
||||
|
@ -1044,8 +1044,8 @@ pub fn option(a: Arc<Type>) -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn ordering() -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn ordering() -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
public: true,
|
||||
name: ORDERING.to_string(),
|
||||
module: "".to_string(),
|
||||
|
@ -1053,24 +1053,24 @@ pub fn ordering() -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn function(args: Vec<Arc<Type>>, ret: Arc<Type>) -> Arc<Type> {
|
||||
Arc::new(Type::Fn { ret, args })
|
||||
pub fn function(args: Vec<Rc<Type>>, ret: Rc<Type>) -> Rc<Type> {
|
||||
Rc::new(Type::Fn { ret, args })
|
||||
}
|
||||
|
||||
pub fn generic_var(id: u64) -> Arc<Type> {
|
||||
let tipo = Arc::new(RefCell::new(TypeVar::Generic { id }));
|
||||
pub fn generic_var(id: u64) -> Rc<Type> {
|
||||
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<Type> {
|
||||
let tipo = Arc::new(RefCell::new(TypeVar::Unbound { id }));
|
||||
pub fn unbound_var(id: u64) -> Rc<Type> {
|
||||
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<Type>) -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
pub fn wrapped_redeemer(redeemer: Rc<Type>) -> Rc<Type> {
|
||||
Rc::new(Type::App {
|
||||
public: true,
|
||||
module: "".to_string(),
|
||||
name: REDEEMER_WRAPPER.to_string(),
|
||||
|
|
|
@ -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<Type>,
|
||||
tipo: Rc<Type>,
|
||||
value: String,
|
||||
},
|
||||
|
||||
String {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
value: String,
|
||||
},
|
||||
|
||||
ByteArray {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
bytes: Vec<u8>,
|
||||
},
|
||||
|
||||
|
@ -57,30 +57,30 @@ pub enum TypedExpr {
|
|||
|
||||
Fn {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
is_capture: bool,
|
||||
args: Vec<Arg<Arc<Type>>>,
|
||||
args: Vec<Arg<Rc<Type>>>,
|
||||
body: Box<Self>,
|
||||
return_annotation: Option<Annotation>,
|
||||
},
|
||||
|
||||
List {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
elements: Vec<Self>,
|
||||
tail: Option<Box<Self>>,
|
||||
},
|
||||
|
||||
Call {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
fun: Box<Self>,
|
||||
args: Vec<CallArg<Self>>,
|
||||
},
|
||||
|
||||
BinOp {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
name: BinOp,
|
||||
left: Box<Self>,
|
||||
right: Box<Self>,
|
||||
|
@ -88,22 +88,22 @@ pub enum TypedExpr {
|
|||
|
||||
Assignment {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
value: Box<Self>,
|
||||
pattern: Pattern<PatternConstructor, Arc<Type>>,
|
||||
pattern: Pattern<PatternConstructor, Rc<Type>>,
|
||||
kind: AssignmentKind,
|
||||
},
|
||||
|
||||
Trace {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
then: Box<Self>,
|
||||
text: Box<Self>,
|
||||
},
|
||||
|
||||
When {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
subject: Box<Self>,
|
||||
clauses: Vec<TypedClause>,
|
||||
},
|
||||
|
@ -112,12 +112,12 @@ pub enum TypedExpr {
|
|||
location: Span,
|
||||
branches: Vec1<IfBranch<Self>>,
|
||||
final_else: Box<Self>,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
|
||||
RecordAccess {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
label: String,
|
||||
index: u64,
|
||||
record: Box<Self>,
|
||||
|
@ -125,7 +125,7 @@ pub enum TypedExpr {
|
|||
|
||||
ModuleSelect {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
label: String,
|
||||
module_name: String,
|
||||
module_alias: String,
|
||||
|
@ -134,25 +134,25 @@ pub enum TypedExpr {
|
|||
|
||||
Tuple {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
elems: Vec<Self>,
|
||||
},
|
||||
|
||||
TupleIndex {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
index: usize,
|
||||
tuple: Box<Self>,
|
||||
},
|
||||
|
||||
ErrorTerm {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
|
||||
RecordUpdate {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
spread: Box<Self>,
|
||||
args: Vec<TypedRecordUpdateArg>,
|
||||
},
|
||||
|
@ -160,13 +160,13 @@ pub enum TypedExpr {
|
|||
UnOp {
|
||||
location: Span,
|
||||
value: Box<Self>,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
op: UnOp,
|
||||
},
|
||||
}
|
||||
|
||||
impl TypedExpr {
|
||||
pub fn tipo(&self) -> Arc<Type> {
|
||||
pub fn tipo(&self) -> Rc<Type> {
|
||||
match self {
|
||||
Self::Var { constructor, .. } => constructor.tipo.clone(),
|
||||
Self::Trace { then, .. } => then.tipo(),
|
||||
|
|
|
@ -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<Annotation>,
|
||||
return_type: Arc<Type>,
|
||||
return_type: Rc<Type>,
|
||||
) -> 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<Arc<Type>>) -> 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<Annotation>,
|
||||
type_info: &Arc<Type>,
|
||||
type_info: &Rc<Type>,
|
||||
) -> Document<'a> {
|
||||
match annotation {
|
||||
Some(a) => self.annotation(a),
|
||||
|
|
|
@ -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<PatternConstructor, Arc<Type>>,
|
||||
pattern: &TypedPattern,
|
||||
mut value: AirTree,
|
||||
tipo: &Arc<Type>,
|
||||
tipo: &Rc<Type>,
|
||||
props: AssignmentProperties,
|
||||
) -> AirTree {
|
||||
assert!(
|
||||
|
@ -938,7 +938,7 @@ impl<'a> CodeGenerator<'a> {
|
|||
|
||||
let field_map = field_map.clone();
|
||||
|
||||
let mut type_map: IndexMap<usize, Arc<Type>> = IndexMap::new();
|
||||
let mut type_map: IndexMap<usize, Rc<Type>> = 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<usize, Arc<Type>> = IndexMap::new();
|
||||
let mut type_map: IndexMap<usize, Rc<Type>> = IndexMap::new();
|
||||
|
||||
let mut sequence = vec![];
|
||||
|
||||
|
@ -1120,7 +1120,7 @@ impl<'a> CodeGenerator<'a> {
|
|||
|
||||
pub fn expect_type_assign(
|
||||
&mut self,
|
||||
tipo: &Arc<Type>,
|
||||
tipo: &Rc<Type>,
|
||||
value: AirTree,
|
||||
defined_data_types: &mut IndexMap<String, u64>,
|
||||
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<u64, Arc<Type>> = if !data_type.typed_parameters.is_empty() {
|
||||
let mono_types: IndexMap<u64, Rc<Type>> = 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<Type>,
|
||||
subject_tipo: &Rc<Type>,
|
||||
props: &mut ClauseProperties,
|
||||
) -> AirTree {
|
||||
assert!(
|
||||
|
@ -1904,8 +1904,8 @@ impl<'a> CodeGenerator<'a> {
|
|||
|
||||
pub fn clause_pattern(
|
||||
&self,
|
||||
pattern: &Pattern<PatternConstructor, Arc<Type>>,
|
||||
subject_tipo: &Arc<Type>,
|
||||
pattern: &Pattern<PatternConstructor, Rc<Type>>,
|
||||
subject_tipo: &Rc<Type>,
|
||||
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<usize, Arc<Type>> = IndexMap::new();
|
||||
let mut type_map: IndexMap<usize, Rc<Type>> = 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<PatternConstructor, Arc<Type>>,
|
||||
subject_tipo: &Arc<Type>,
|
||||
pattern: &Pattern<PatternConstructor, Rc<Type>>,
|
||||
subject_tipo: &Rc<Type>,
|
||||
props: &mut ClauseProperties,
|
||||
) -> AirTree {
|
||||
if props.final_clause {
|
||||
|
@ -3064,7 +3064,7 @@ impl<'a> CodeGenerator<'a> {
|
|||
&self.data_types,
|
||||
));
|
||||
|
||||
let mono_types: IndexMap<u64, Arc<Type>> = if !function_def_types.is_empty() {
|
||||
let mono_types: IndexMap<u64, Rc<Type>> = if !function_def_types.is_empty() {
|
||||
function_def_types
|
||||
.into_iter()
|
||||
.zip(function_var_types)
|
||||
|
|
|
@ -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<Type>,
|
||||
tipo: Rc<Type>,
|
||||
tail: bool,
|
||||
},
|
||||
Tuple {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
count: usize,
|
||||
},
|
||||
Void,
|
||||
|
@ -40,7 +40,7 @@ pub enum Air {
|
|||
// Functions
|
||||
Call {
|
||||
count: usize,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
DefineFunc {
|
||||
func_name: String,
|
||||
|
@ -56,13 +56,13 @@ pub enum Air {
|
|||
Builtin {
|
||||
count: usize,
|
||||
func: DefaultFunction,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
// Operators
|
||||
BinOp {
|
||||
name: BinOp,
|
||||
tipo: Arc<Type>,
|
||||
argument_tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
argument_tipo: Rc<Type>,
|
||||
},
|
||||
UnOp {
|
||||
op: UnOp,
|
||||
|
@ -72,10 +72,10 @@ pub enum Air {
|
|||
name: String,
|
||||
},
|
||||
CastFromData {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
CastToData {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
AssertConstr {
|
||||
constr_index: usize,
|
||||
|
@ -85,24 +85,24 @@ pub enum Air {
|
|||
},
|
||||
// When
|
||||
When {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
subject_name: String,
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
},
|
||||
Clause {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
subject_name: String,
|
||||
complex_clause: bool,
|
||||
},
|
||||
ListClause {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
tail_name: String,
|
||||
next_tail_name: Option<(String, String)>,
|
||||
complex_clause: bool,
|
||||
},
|
||||
WrapClause,
|
||||
TupleClause {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
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<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
},
|
||||
ListClauseGuard {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
tail_name: String,
|
||||
next_tail_name: Option<String>,
|
||||
inverse: bool,
|
||||
},
|
||||
TupleGuard {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
indices: IndexSet<(usize, String)>,
|
||||
subject_name: String,
|
||||
},
|
||||
Finally,
|
||||
// If
|
||||
If {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
// Record Creation
|
||||
Constr {
|
||||
tag: usize,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
count: usize,
|
||||
},
|
||||
RecordUpdate {
|
||||
highest_index: usize,
|
||||
indices: Vec<(usize, Arc<Type>)>,
|
||||
tipo: Arc<Type>,
|
||||
indices: Vec<(usize, Rc<Type>)>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
// Field Access
|
||||
RecordAccess {
|
||||
record_index: u64,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
FieldsExpose {
|
||||
indices: Vec<(usize, String, Arc<Type>)>,
|
||||
indices: Vec<(usize, String, Rc<Type>)>,
|
||||
check_last_item: bool,
|
||||
},
|
||||
// ListAccess
|
||||
ListAccessor {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
names: Vec<String>,
|
||||
tail: bool,
|
||||
check_last_item: bool,
|
||||
},
|
||||
ListExpose {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
tail_head_names: Vec<(String, String)>,
|
||||
tail: Option<(String, String)>,
|
||||
},
|
||||
// Tuple Access
|
||||
TupleAccessor {
|
||||
names: Vec<String>,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
check_last_item: bool,
|
||||
},
|
||||
TupleIndex {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
tuple_index: usize,
|
||||
},
|
||||
// Misc.
|
||||
ErrorTerm {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
Trace {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
NoOp,
|
||||
FieldsEmpty,
|
||||
|
|
|
@ -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<Type>,
|
||||
pub value_type: Rc<Type>,
|
||||
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<Type>, constr_var: String, subject_name: String) -> Self {
|
||||
pub fn init(t: &Rc<Type>, 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<Type>,
|
||||
t: &Rc<Type>,
|
||||
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<Type>)> {
|
||||
pub fn get_generic_id_and_type(tipo: &Type, param: &Type) -> Vec<(u64, Rc<Type>)> {
|
||||
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<Type>
|
|||
pub fn lookup_data_type_by_tipo(
|
||||
data_types: &IndexMap<DataTypeKey, &TypedDataType>,
|
||||
tipo: &Type,
|
||||
) -> Option<DataType<Arc<Type>>> {
|
||||
) -> Option<DataType<Rc<Type>>> {
|
||||
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<Type>,
|
||||
t: &Rc<Type>,
|
||||
data_types: &IndexMap<DataTypeKey, &TypedDataType>,
|
||||
) -> Arc<Type> {
|
||||
) -> Rc<Type> {
|
||||
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<u64, Arc<Type>>;
|
||||
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<Type>,
|
||||
t: &Rc<Type>,
|
||||
data_types: &IndexMap<DataTypeKey, &TypedDataType>,
|
||||
) -> 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<Type>,
|
||||
mono_types: &IndexMap<u64, Arc<Type>>,
|
||||
) -> Arc<Type> {
|
||||
tipo: &Rc<Type>,
|
||||
mono_types: &IndexMap<u64, Rc<Type>>,
|
||||
) -> Rc<Type> {
|
||||
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<Arc<Type>>) -> 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<Arc<Type>>) -> AirTree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_variant_name(t: &Arc<Type>) -> String {
|
||||
pub fn get_variant_name(t: &Rc<Type>) -> String {
|
||||
if t.is_string() {
|
||||
"_string".to_string()
|
||||
} else if t.is_int() {
|
||||
|
@ -531,7 +531,7 @@ pub fn get_variant_name(t: &Arc<Type>) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn monomorphize(air_tree: &mut AirTree, mono_types: &IndexMap<u64, Arc<Type>>) {
|
||||
pub fn monomorphize(air_tree: &mut AirTree, mono_types: &IndexMap<u64, Rc<Type>>) {
|
||||
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<Name>, field_type: &Arc<Type>) -> Term<Name> {
|
||||
pub fn convert_data_to_type(term: Term<Name>, field_type: &Rc<Type>) -> Term<Name> {
|
||||
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<Rc<UplcConstant>>) -> Vec<UplcCo
|
|||
new_constants
|
||||
}
|
||||
|
||||
pub fn convert_type_to_data(term: Term<Name>, field_type: &Arc<Type>) -> Term<Name> {
|
||||
pub fn convert_type_to_data(term: Term<Name>, field_type: &Rc<Type>) -> Term<Name> {
|
||||
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<Name>,
|
||||
tipos: Vec<Arc<Type>>,
|
||||
tipos: Vec<Rc<Type>>,
|
||||
check_last_item: bool,
|
||||
is_list_accessor: bool,
|
||||
tracing: bool,
|
||||
|
@ -1409,7 +1409,7 @@ pub fn apply_builtin_forces(mut term: Term<Name>, force_count: u32) -> Term<Name
|
|||
pub fn undata_builtin(
|
||||
func: &DefaultFunction,
|
||||
count: usize,
|
||||
tipo: &Arc<Type>,
|
||||
tipo: &Rc<Type>,
|
||||
args: Vec<Term<Name>>,
|
||||
) -> Term<Name> {
|
||||
let mut term: Term<Name> = (*func).into();
|
||||
|
@ -1437,7 +1437,7 @@ pub fn undata_builtin(
|
|||
pub fn to_data_builtin(
|
||||
func: &DefaultFunction,
|
||||
count: usize,
|
||||
tipo: &Arc<Type>,
|
||||
tipo: &Rc<Type>,
|
||||
mut args: Vec<Term<Name>>,
|
||||
) -> Term<Name> {
|
||||
let mut term: Term<Name> = (*func).into();
|
||||
|
@ -1575,7 +1575,7 @@ pub fn wrap_as_multi_validator(spend: Term<Name>, mint: Term<Name>) -> Term<Name
|
|||
/// If the pattern is a list the return the number of elements and if it has a tail
|
||||
/// Otherwise return None
|
||||
pub fn get_list_elements_len_and_tail(
|
||||
pattern: &Pattern<PatternConstructor, Arc<Type>>,
|
||||
pattern: &Pattern<PatternConstructor, Rc<Type>>,
|
||||
) -> Option<(usize, bool)> {
|
||||
if let Pattern::List { elements, tail, .. } = &pattern {
|
||||
Some((elements.len(), tail.is_some()))
|
||||
|
|
|
@ -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<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
pattern: Box<AirTree>,
|
||||
},
|
||||
ListClauseGuard {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
tail_name: String,
|
||||
next_tail_name: Option<String>,
|
||||
inverse: bool,
|
||||
},
|
||||
TupleGuard {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
indices: IndexSet<(usize, String)>,
|
||||
subject_name: String,
|
||||
},
|
||||
// Field Access
|
||||
FieldsExpose {
|
||||
indices: Vec<(usize, String, Arc<Type>)>,
|
||||
indices: Vec<(usize, String, Rc<Type>)>,
|
||||
check_last_item: bool,
|
||||
record: Box<AirTree>,
|
||||
},
|
||||
// List Access
|
||||
ListAccessor {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
names: Vec<String>,
|
||||
tail: bool,
|
||||
check_last_item: bool,
|
||||
list: Box<AirTree>,
|
||||
},
|
||||
ListExpose {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
tail_head_names: Vec<(String, String)>,
|
||||
tail: Option<(String, String)>,
|
||||
},
|
||||
// Tuple Access
|
||||
TupleAccessor {
|
||||
names: Vec<String>,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
check_last_item: bool,
|
||||
tuple: Box<AirTree>,
|
||||
},
|
||||
|
@ -211,12 +211,12 @@ pub enum AirExpression {
|
|||
value: bool,
|
||||
},
|
||||
List {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
tail: bool,
|
||||
items: Vec<AirTree>,
|
||||
},
|
||||
Tuple {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
items: Vec<AirTree>,
|
||||
},
|
||||
Void,
|
||||
|
@ -227,7 +227,7 @@ pub enum AirExpression {
|
|||
},
|
||||
// Functions
|
||||
Call {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
func: Box<AirTree>,
|
||||
args: Vec<AirTree>,
|
||||
},
|
||||
|
@ -238,16 +238,16 @@ pub enum AirExpression {
|
|||
},
|
||||
Builtin {
|
||||
func: DefaultFunction,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
args: Vec<AirTree>,
|
||||
},
|
||||
// Operators
|
||||
BinOp {
|
||||
name: BinOp,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
left: Box<AirTree>,
|
||||
right: Box<AirTree>,
|
||||
argument_tipo: Arc<Type>,
|
||||
argument_tipo: Rc<Type>,
|
||||
},
|
||||
UnOp {
|
||||
op: UnOp,
|
||||
|
@ -255,24 +255,24 @@ pub enum AirExpression {
|
|||
},
|
||||
|
||||
CastFromData {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
value: Box<AirTree>,
|
||||
},
|
||||
CastToData {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
value: Box<AirTree>,
|
||||
},
|
||||
|
||||
// When
|
||||
When {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
subject_name: String,
|
||||
subject: Box<AirTree>,
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
clauses: Box<AirTree>,
|
||||
},
|
||||
Clause {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
subject_name: String,
|
||||
complex_clause: bool,
|
||||
pattern: Box<AirTree>,
|
||||
|
@ -280,7 +280,7 @@ pub enum AirExpression {
|
|||
otherwise: Box<AirTree>,
|
||||
},
|
||||
ListClause {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
tail_name: String,
|
||||
next_tail_name: Option<(String, String)>,
|
||||
complex_clause: bool,
|
||||
|
@ -292,7 +292,7 @@ pub enum AirExpression {
|
|||
otherwise: Box<AirTree>,
|
||||
},
|
||||
TupleClause {
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
indices: IndexSet<(usize, String)>,
|
||||
predefined_indices: IndexSet<(usize, String)>,
|
||||
subject_name: String,
|
||||
|
@ -307,7 +307,7 @@ pub enum AirExpression {
|
|||
},
|
||||
// If
|
||||
If {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
pattern: Box<AirTree>,
|
||||
then: Box<AirTree>,
|
||||
otherwise: Box<AirTree>,
|
||||
|
@ -315,34 +315,34 @@ pub enum AirExpression {
|
|||
// Record Creation
|
||||
Constr {
|
||||
tag: usize,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
args: Vec<AirTree>,
|
||||
},
|
||||
RecordUpdate {
|
||||
highest_index: usize,
|
||||
indices: Vec<(usize, Arc<Type>)>,
|
||||
tipo: Arc<Type>,
|
||||
indices: Vec<(usize, Rc<Type>)>,
|
||||
tipo: Rc<Type>,
|
||||
record: Box<AirTree>,
|
||||
args: Vec<AirTree>,
|
||||
},
|
||||
// Field Access
|
||||
RecordAccess {
|
||||
field_index: u64,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
record: Box<AirTree>,
|
||||
},
|
||||
// Tuple Access
|
||||
TupleIndex {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
tuple_index: usize,
|
||||
tuple: Box<AirTree>,
|
||||
},
|
||||
// Misc.
|
||||
ErrorTerm {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
Trace {
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
msg: Box<AirTree>,
|
||||
then: Box<AirTree>,
|
||||
},
|
||||
|
@ -365,7 +365,7 @@ impl AirTree {
|
|||
pub fn bool(value: bool) -> AirTree {
|
||||
AirTree::Expression(AirExpression::Bool { value })
|
||||
}
|
||||
pub fn list(mut items: Vec<AirTree>, tipo: Arc<Type>, tail: Option<AirTree>) -> AirTree {
|
||||
pub fn list(mut items: Vec<AirTree>, tipo: Rc<Type>, tail: Option<AirTree>) -> AirTree {
|
||||
if let Some(tail) = tail {
|
||||
items.push(tail);
|
||||
|
||||
|
@ -382,7 +382,7 @@ impl AirTree {
|
|||
})
|
||||
}
|
||||
}
|
||||
pub fn tuple(items: Vec<AirTree>, tipo: Arc<Type>) -> AirTree {
|
||||
pub fn tuple(items: Vec<AirTree>, tipo: Rc<Type>) -> 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<Type>) -> AirTree {
|
||||
pub fn local_var(name: impl ToString, tipo: Rc<Type>) -> 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<Type>, args: Vec<AirTree>) -> AirTree {
|
||||
pub fn call(func: AirTree, tipo: Rc<Type>, args: Vec<AirTree>) -> 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<Type>, args: Vec<AirTree>) -> AirTree {
|
||||
pub fn builtin(func: DefaultFunction, tipo: Rc<Type>, args: Vec<AirTree>) -> AirTree {
|
||||
AirTree::Expression(AirExpression::Builtin { func, tipo, args })
|
||||
}
|
||||
pub fn binop(
|
||||
op: BinOp,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
left: AirTree,
|
||||
right: AirTree,
|
||||
argument_tipo: Arc<Type>,
|
||||
argument_tipo: Rc<Type>,
|
||||
) -> 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<Type>) -> AirTree {
|
||||
pub fn cast_from_data(value: AirTree, tipo: Rc<Type>) -> AirTree {
|
||||
AirTree::Expression(AirExpression::CastFromData {
|
||||
tipo,
|
||||
value: value.into(),
|
||||
})
|
||||
}
|
||||
pub fn cast_to_data(value: AirTree, tipo: Arc<Type>) -> AirTree {
|
||||
pub fn cast_to_data(value: AirTree, tipo: Rc<Type>) -> AirTree {
|
||||
AirTree::Expression(AirExpression::CastToData {
|
||||
tipo,
|
||||
value: value.into(),
|
||||
|
@ -511,8 +511,8 @@ impl AirTree {
|
|||
}
|
||||
pub fn when(
|
||||
subject_name: impl ToString,
|
||||
tipo: Arc<Type>,
|
||||
subject_tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
subject: AirTree,
|
||||
clauses: AirTree,
|
||||
) -> AirTree {
|
||||
|
@ -527,7 +527,7 @@ impl AirTree {
|
|||
pub fn clause(
|
||||
subject_name: impl ToString,
|
||||
pattern: AirTree,
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
then: AirTree,
|
||||
otherwise: AirTree,
|
||||
complex_clause: bool,
|
||||
|
@ -543,7 +543,7 @@ impl AirTree {
|
|||
}
|
||||
pub fn list_clause(
|
||||
tail_name: impl ToString,
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
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<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
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<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
) -> AirTree {
|
||||
AirTree::Statement {
|
||||
statement: AirStatement::ClauseGuard {
|
||||
|
@ -599,7 +599,7 @@ impl AirTree {
|
|||
}
|
||||
pub fn list_clause_guard(
|
||||
tail_name: impl ToString,
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
inverse: bool,
|
||||
next_tail_name: Option<String>,
|
||||
) -> AirTree {
|
||||
|
@ -615,7 +615,7 @@ impl AirTree {
|
|||
}
|
||||
pub fn tuple_clause_guard(
|
||||
subject_name: impl ToString,
|
||||
subject_tipo: Arc<Type>,
|
||||
subject_tipo: Rc<Type>,
|
||||
indices: IndexSet<(usize, String)>,
|
||||
) -> AirTree {
|
||||
AirTree::Statement {
|
||||
|
@ -635,7 +635,7 @@ impl AirTree {
|
|||
}
|
||||
pub fn if_branches(
|
||||
mut branches: Vec<(AirTree, AirTree)>,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
otherwise: AirTree,
|
||||
) -> AirTree {
|
||||
assert!(!branches.is_empty());
|
||||
|
@ -659,14 +659,14 @@ impl AirTree {
|
|||
|
||||
final_if
|
||||
}
|
||||
pub fn create_constr(tag: usize, tipo: Arc<Type>, args: Vec<AirTree>) -> AirTree {
|
||||
pub fn create_constr(tag: usize, tipo: Rc<Type>, args: Vec<AirTree>) -> AirTree {
|
||||
AirTree::Expression(AirExpression::Constr { tag, tipo, args })
|
||||
}
|
||||
|
||||
pub fn record_update(
|
||||
indices: Vec<(usize, Arc<Type>)>,
|
||||
indices: Vec<(usize, Rc<Type>)>,
|
||||
highest_index: usize,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
record: AirTree,
|
||||
args: Vec<AirTree>,
|
||||
) -> AirTree {
|
||||
|
@ -678,7 +678,7 @@ impl AirTree {
|
|||
args,
|
||||
})
|
||||
}
|
||||
pub fn record_access(field_index: u64, tipo: Arc<Type>, record: AirTree) -> AirTree {
|
||||
pub fn record_access(field_index: u64, tipo: Rc<Type>, 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<Type>)>,
|
||||
indices: Vec<(usize, String, Rc<Type>)>,
|
||||
check_last_item: bool,
|
||||
record: AirTree,
|
||||
) -> AirTree {
|
||||
|
@ -702,7 +702,7 @@ impl AirTree {
|
|||
}
|
||||
pub fn list_access(
|
||||
names: Vec<String>,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
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<Type>,
|
||||
tipo: Rc<Type>,
|
||||
) -> AirTree {
|
||||
AirTree::Statement {
|
||||
statement: AirStatement::ListExpose {
|
||||
|
@ -734,7 +734,7 @@ impl AirTree {
|
|||
}
|
||||
pub fn tuple_access(
|
||||
names: Vec<String>,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
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<Type>, tuple: AirTree) -> AirTree {
|
||||
pub fn tuple_index(tuple_index: usize, tipo: Rc<Type>, tuple: AirTree) -> AirTree {
|
||||
AirTree::Expression(AirExpression::TupleIndex {
|
||||
tipo,
|
||||
tuple_index,
|
||||
tuple: tuple.into(),
|
||||
})
|
||||
}
|
||||
pub fn error(tipo: Arc<Type>) -> AirTree {
|
||||
pub fn error(tipo: Rc<Type>) -> AirTree {
|
||||
AirTree::Expression(AirExpression::ErrorTerm { tipo })
|
||||
}
|
||||
pub fn trace(msg: AirTree, tipo: Arc<Type>, then: AirTree) -> AirTree {
|
||||
pub fn trace(msg: AirTree, tipo: Rc<Type>, then: AirTree) -> AirTree {
|
||||
AirTree::Expression(AirExpression::Trace {
|
||||
tipo,
|
||||
msg: msg.into(),
|
||||
|
@ -1253,7 +1253,7 @@ impl AirTree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn return_type(&self) -> Arc<Type> {
|
||||
pub fn return_type(&self) -> Rc<Type> {
|
||||
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<Type>> {
|
||||
pub fn mut_held_types(&mut self) -> Vec<&mut Rc<Type>> {
|
||||
match self {
|
||||
AirTree::Statement {
|
||||
statement,
|
||||
|
|
|
@ -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(()),
|
||||
});
|
||||
|
||||
|
|
|
@ -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<Arc<Type>>,
|
||||
args: Vec<Rc<Type>>,
|
||||
},
|
||||
|
||||
/// The type of a function. It takes arguments and returns a value.
|
||||
///
|
||||
Fn {
|
||||
args: Vec<Arc<Type>>,
|
||||
ret: Arc<Type>,
|
||||
args: Vec<Rc<Type>>,
|
||||
ret: Rc<Type>,
|
||||
},
|
||||
|
||||
/// A type variable. See the contained `TypeVar` enum for more information.
|
||||
///
|
||||
Var {
|
||||
tipo: Arc<RefCell<TypeVar>>,
|
||||
tipo: Rc<RefCell<TypeVar>>,
|
||||
},
|
||||
// /// 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<Arc<Type>>,
|
||||
elems: Vec<Rc<Type>>,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -75,14 +75,14 @@ impl Type {
|
|||
matches!(self, Self::Fn { .. })
|
||||
}
|
||||
|
||||
pub fn return_type(&self) -> Option<Arc<Self>> {
|
||||
pub fn return_type(&self) -> Option<Rc<Self>> {
|
||||
match self {
|
||||
Self::Fn { ret, .. } => Some(ret.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn function_types(&self) -> Option<(Vec<Arc<Self>>, Arc<Self>)> {
|
||||
pub fn function_types(&self) -> Option<(Vec<Rc<Self>>, Rc<Self>)> {
|
||||
match self {
|
||||
Self::Fn { args, ret, .. } => Some((args.clone(), ret.clone())),
|
||||
_ => None,
|
||||
|
@ -224,7 +224,7 @@ impl Type {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn arg_types(&self) -> Option<Vec<Arc<Self>>> {
|
||||
pub fn arg_types(&self) -> Option<Vec<Rc<Self>>> {
|
||||
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<Arc<Type>> {
|
||||
pub fn get_inner_types(&self) -> Vec<Rc<Type>> {
|
||||
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<Vec<Arc<Self>>> {
|
||||
) -> Option<Vec<Rc<Self>>> {
|
||||
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<Type> },
|
||||
Link { tipo: Rc<Type> },
|
||||
/// 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<Vec<Arc<Type>>> {
|
||||
pub fn arg_types(&self) -> Option<Vec<Rc<Type>>> {
|
||||
match self {
|
||||
Self::Link { tipo } => tipo.arg_types(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_inner_types(&self) -> Vec<Arc<Type>> {
|
||||
pub fn get_inner_types(&self) -> Vec<Rc<Type>> {
|
||||
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<Type>,
|
||||
pub tipo: Rc<Type>,
|
||||
}
|
||||
|
||||
impl ValueConstructor {
|
||||
pub fn public(tipo: Arc<Type>, variant: ValueConstructorVariant) -> ValueConstructor {
|
||||
pub fn public(tipo: Rc<Type>, variant: ValueConstructorVariant) -> ValueConstructor {
|
||||
ValueConstructor {
|
||||
public: true,
|
||||
variant,
|
||||
|
@ -633,7 +633,7 @@ pub enum ValueConstructorVariant {
|
|||
impl ValueConstructorVariant {
|
||||
fn to_module_value_constructor(
|
||||
&self,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
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<Arc<Type>>,
|
||||
pub tipo: Arc<Type>,
|
||||
pub parameters: Vec<Rc<Type>>,
|
||||
pub tipo: Rc<Type>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AccessorsMap {
|
||||
pub public: bool,
|
||||
pub tipo: Arc<Type>,
|
||||
pub tipo: Rc<Type>,
|
||||
pub accessors: HashMap<String, RecordAccessor>,
|
||||
}
|
||||
|
||||
|
@ -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<Type>,
|
||||
pub tipo: Rc<Type>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -742,7 +742,7 @@ pub enum ModuleValueConstructor {
|
|||
Record {
|
||||
name: String,
|
||||
arity: usize,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
field_map: Option<FieldMap>,
|
||||
location: Span,
|
||||
},
|
||||
|
|
|
@ -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<Type>,
|
||||
tipo: Rc<Type>,
|
||||
arity: usize,
|
||||
fn_location: Span,
|
||||
call_location: Span,
|
||||
) -> Result<(Vec<Arc<Type>>, Arc<Type>), Error> {
|
||||
) -> Result<(Vec<Rc<Type>>, Rc<Type>), 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<Type>,
|
||||
tipo: Rc<Type>,
|
||||
) {
|
||||
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<Type>,
|
||||
ids: &mut HashMap<u64, Arc<Type>>,
|
||||
t: Rc<Type>,
|
||||
ids: &mut HashMap<u64, Rc<Type>>,
|
||||
hydrator: &Hydrator,
|
||||
) -> Arc<Type> {
|
||||
) -> Rc<Type> {
|
||||
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<Vec<Arc<Type>>, Error> {
|
||||
) -> Result<Vec<Rc<Type>>, 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<Type> {
|
||||
pub fn new_generic_var(&mut self) -> Rc<Type> {
|
||||
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<Type> {
|
||||
pub fn new_unbound_var(&mut self) -> Rc<Type> {
|
||||
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<Type>,
|
||||
t2: Arc<Type>,
|
||||
t1: Rc<Type>,
|
||||
t2: Rc<Type>,
|
||||
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<Type>),
|
||||
Unify(Rc<Type>),
|
||||
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<Type>, own_id: u64, location: Span) -> Result<(), Error> {
|
||||
fn unify_unbound_type(tipo: Rc<Type>, 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<Type>, own_id: u64, location: Span) -> Result<()
|
|||
}
|
||||
}
|
||||
|
||||
fn unify_enclosed_type(
|
||||
e1: Arc<Type>,
|
||||
e2: Arc<Type>,
|
||||
result: Result<(), Error>,
|
||||
) -> Result<(), Error> {
|
||||
fn unify_enclosed_type(e1: Rc<Type>, e2: Rc<Type>, 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<A>(args: &[CallArg<A>]) -> Option<(Spa
|
|||
None
|
||||
}
|
||||
|
||||
pub(super) fn collapse_links(t: Arc<Type>) -> Arc<Type> {
|
||||
pub(super) fn collapse_links(t: Rc<Type>) -> Rc<Type> {
|
||||
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<A>(
|
|||
/// 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<Type>, ctx_level: usize) -> Arc<Type> {
|
||||
pub(crate) fn generalise(t: Rc<Type>, ctx_level: usize) -> Rc<Type> {
|
||||
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<Type>, ctx_level: usize) -> Arc<Type> {
|
|||
.map(|t| generalise(t.clone(), ctx_level))
|
||||
.collect();
|
||||
|
||||
Arc::new(Type::App {
|
||||
Rc::new(Type::App {
|
||||
public: *public,
|
||||
module: module.clone(),
|
||||
name: name.clone(),
|
||||
|
|
|
@ -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<Type>,
|
||||
given: Arc<Type>,
|
||||
expected: Rc<Type>,
|
||||
given: Rc<Type>,
|
||||
situation: Option<UnifyErrorSituation>,
|
||||
rigid_type_names: HashMap<u64, String>,
|
||||
},
|
||||
|
@ -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<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
|
||||
#[error("{}\n", if *is_let {
|
||||
|
@ -521,7 +521,7 @@ In this particular instance, the following cases are unmatched:
|
|||
NotFn {
|
||||
#[label]
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
|
||||
#[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<Type>,
|
||||
typ: Rc<Type>,
|
||||
label: String,
|
||||
fields: Vec<String>,
|
||||
situation: Option<UnknownRecordFieldSituation>,
|
||||
|
@ -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<Type>,
|
||||
return_type: Rc<Type>,
|
||||
},
|
||||
|
||||
#[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<Type>,
|
||||
given: &Arc<Type>,
|
||||
expected: &Rc<Type>,
|
||||
given: &Rc<Type>,
|
||||
situation: &Option<UnifyErrorSituation>,
|
||||
rigid_type_names: &HashMap<u64, String>,
|
||||
) -> 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<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
|
||||
#[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<Type>,
|
||||
tipo: Rc<Type>,
|
||||
},
|
||||
|
||||
#[error(
|
||||
|
|
|
@ -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<CallArg<UntypedExpr>>,
|
||||
location: Span,
|
||||
) -> Result<(TypedExpr, Vec<TypedCallArg>, Arc<Type>), Error> {
|
||||
) -> Result<(TypedExpr, Vec<TypedCallArg>, Rc<Type>), 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<CallArg<UntypedExpr>>,
|
||||
location: Span,
|
||||
) -> Result<(TypedExpr, Vec<TypedCallArg>, Arc<Type>), Error> {
|
||||
) -> Result<(TypedExpr, Vec<TypedCallArg>, Rc<Type>), 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<UntypedArg>,
|
||||
expected_args: &[Arc<Type>],
|
||||
expected_args: &[Rc<Type>],
|
||||
body: UntypedExpr,
|
||||
return_annotation: &Option<Annotation>,
|
||||
) -> Result<(Vec<TypedArg>, 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<Arc<Type>>,
|
||||
expected: Option<Rc<Type>>,
|
||||
) -> Result<TypedArg, Error> {
|
||||
let Arg {
|
||||
arg_name,
|
||||
|
@ -984,7 +984,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
|||
fn infer_call_argument(
|
||||
&mut self,
|
||||
value: UntypedExpr,
|
||||
tipo: Arc<Type>,
|
||||
tipo: Rc<Type>,
|
||||
) -> Result<TypedExpr, Error> {
|
||||
let tipo = collapse_links(tipo);
|
||||
|
||||
|
@ -1419,7 +1419,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
|||
fn infer_fn(
|
||||
&mut self,
|
||||
args: Vec<UntypedArg>,
|
||||
expected_args: &[Arc<Type>],
|
||||
expected_args: &[Rc<Type>],
|
||||
body: UntypedExpr,
|
||||
is_capture: bool,
|
||||
return_annotation: Option<Annotation>,
|
||||
|
@ -1445,7 +1445,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
|||
&mut self,
|
||||
args: Vec<TypedArg>,
|
||||
body: UntypedExpr,
|
||||
return_type: Option<Arc<Type>>,
|
||||
return_type: Option<Rc<Type>>,
|
||||
) -> Result<(Vec<TypedArg>, TypedExpr), Error> {
|
||||
assert_no_assignment(&body)?;
|
||||
|
||||
|
@ -1922,7 +1922,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
|||
})
|
||||
}
|
||||
|
||||
fn instantiate(&mut self, t: Arc<Type>, ids: &mut HashMap<u64, Arc<Type>>) -> Arc<Type> {
|
||||
fn instantiate(&mut self, t: Rc<Type>, ids: &mut HashMap<u64, Rc<Type>>) -> Rc<Type> {
|
||||
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<Type> {
|
||||
pub fn new_unbound_var(&mut self) -> Rc<Type> {
|
||||
self.environment.new_unbound_var()
|
||||
}
|
||||
|
||||
pub fn type_from_annotation(&mut self, annotation: &Annotation) -> Result<Arc<Type>, Error> {
|
||||
pub fn type_from_annotation(&mut self, annotation: &Annotation) -> Result<Rc<Type>, Error> {
|
||||
self.hydrator
|
||||
.type_from_annotation(annotation, self.environment)
|
||||
}
|
||||
|
||||
fn unify(
|
||||
&mut self,
|
||||
t1: Arc<Type>,
|
||||
t2: Arc<Type>,
|
||||
t1: Rc<Type>,
|
||||
t2: Rc<Type>,
|
||||
location: Span,
|
||||
allow_cast: bool,
|
||||
) -> Result<(), Error> {
|
||||
|
|
|
@ -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<String, Arc<Type>>,
|
||||
created_type_variables: HashMap<String, Rc<Type>>,
|
||||
/// 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<String, Arc<Type>>,
|
||||
created_type_variables: HashMap<String, Rc<Type>>,
|
||||
rigid_type_names: HashMap<u64, String>,
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ impl Hydrator {
|
|||
&mut self,
|
||||
ast: &Option<Annotation>,
|
||||
environment: &mut Environment,
|
||||
) -> Result<Arc<Type>, Error> {
|
||||
) -> Result<Rc<Type>, 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<Arc<Type>, Error> {
|
||||
) -> Result<Rc<Type>, 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<Arc<Type>, Error> {
|
||||
) -> Result<Rc<Type>, Error> {
|
||||
match annotation {
|
||||
Annotation::Constructor {
|
||||
location,
|
||||
|
|
|
@ -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<Type>,
|
||||
typ: Rc<Type>,
|
||||
location: Span,
|
||||
err_location: Span,
|
||||
) -> Result<(), Error> {
|
||||
|
@ -132,7 +132,7 @@ impl<'a, 'b> PatternTyper<'a, 'b> {
|
|||
pattern: UntypedPattern,
|
||||
subject: &Type,
|
||||
) -> Result<TypedPattern, Error> {
|
||||
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<Type>,
|
||||
ann_type: Option<Arc<Type>>,
|
||||
tipo: Rc<Type>,
|
||||
ann_type: Option<Rc<Type>>,
|
||||
is_assignment: bool,
|
||||
) -> Result<TypedPattern, Error> {
|
||||
match pattern {
|
||||
|
|
|
@ -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<Type>,
|
||||
argument_type: Rc<Type>,
|
||||
argument_location: Span,
|
||||
location: Span,
|
||||
expressions: Vec<TypedExpr>,
|
||||
|
|
|
@ -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<Refcell<Type>>
|
||||
// Is this possible? The lifetime would have to go through the Rc<Refcell<Type>>
|
||||
// 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<Type>]) -> Document<'a> {
|
||||
fn args_to_aiken_doc<'a>(&mut self, args: &[Rc<Type>]) -> 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<Type>) -> String {
|
||||
fn pretty_print(typ: Rc<Type>) -> String {
|
||||
Printer::new().pretty_print(&typ, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::{
|
|||
collections::{BTreeMap, HashMap},
|
||||
fmt::{self, Display},
|
||||
ops::Deref,
|
||||
sync::Arc,
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
// ---------- Definitions
|
||||
|
@ -68,7 +68,7 @@ impl<T> Definitions<T> {
|
|||
pub fn register<F, E>(
|
||||
&mut self,
|
||||
type_info: &Type,
|
||||
type_parameters: &HashMap<u64, Arc<Type>>,
|
||||
type_parameters: &HashMap<u64, Rc<Type>>,
|
||||
build_schema: F,
|
||||
) -> Result<Reference, E>
|
||||
where
|
||||
|
@ -124,7 +124,7 @@ impl Display for Reference {
|
|||
}
|
||||
|
||||
impl Reference {
|
||||
pub fn from_type(type_info: &Type, type_parameters: &HashMap<u64, Arc<Type>>) -> Self {
|
||||
pub fn from_type(type_info: &Type, type_parameters: &HashMap<u64, Rc<Type>>) -> Self {
|
||||
match type_info {
|
||||
Type::App {
|
||||
module, name, args, ..
|
||||
|
@ -168,7 +168,7 @@ impl Reference {
|
|||
}
|
||||
}
|
||||
|
||||
fn from_types(args: &Vec<Arc<Type>>, type_parameters: &HashMap<u64, Arc<Type>>) -> Self {
|
||||
fn from_types(args: &Vec<Rc<Type>>, type_parameters: &HashMap<u64, Rc<Type>>) -> Self {
|
||||
if args.is_empty() {
|
||||
Reference::new("")
|
||||
} else {
|
||||
|
|
|
@ -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<Schema> {
|
|||
pub fn as_wrapped_redeemer(
|
||||
definitions: &mut Definitions<Annotated<Schema>>,
|
||||
schema: Reference,
|
||||
type_info: Arc<Type>,
|
||||
type_info: Rc<Type>,
|
||||
) -> Reference {
|
||||
definitions
|
||||
.register(
|
||||
|
@ -156,7 +157,7 @@ impl Annotated<Schema> {
|
|||
fn do_from_type(
|
||||
type_info: &Type,
|
||||
modules: &HashMap<String, CheckedModule>,
|
||||
type_parameters: &mut HashMap<u64, Arc<Type>>,
|
||||
type_parameters: &mut HashMap<u64, Rc<Type>>,
|
||||
definitions: &mut Definitions<Self>,
|
||||
) -> Result<Reference, Error> {
|
||||
match type_info {
|
||||
|
@ -403,9 +404,9 @@ impl Annotated<Schema> {
|
|||
|
||||
impl Data {
|
||||
fn from_data_type(
|
||||
data_type: &DataType<Arc<Type>>,
|
||||
data_type: &TypedDataType,
|
||||
modules: &HashMap<String, CheckedModule>,
|
||||
type_parameters: &mut HashMap<u64, Arc<Type>>,
|
||||
type_parameters: &mut HashMap<u64, Rc<Type>>,
|
||||
definitions: &mut Definitions<Annotated<Schema>>,
|
||||
) -> Result<Self, Error> {
|
||||
let mut variants = vec![];
|
||||
|
@ -451,9 +452,9 @@ impl Data {
|
|||
}
|
||||
|
||||
fn collect_type_parameters<'a>(
|
||||
type_parameters: &'a mut HashMap<u64, Arc<Type>>,
|
||||
generics: &'a [Arc<Type>],
|
||||
applications: &'a [Arc<Type>],
|
||||
type_parameters: &'a mut HashMap<u64, Rc<Type>>,
|
||||
generics: &'a [Rc<Type>],
|
||||
applications: &'a [Rc<Type>],
|
||||
) {
|
||||
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<DataType<Arc<Type>>> {
|
||||
fn find_data_type(name: &str, definitions: &[TypedDefinition]) -> Option<TypedDataType> {
|
||||
for def in definitions {
|
||||
match def {
|
||||
Definition::DataType(data_type) if name == data_type.name => {
|
||||
|
|
|
@ -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<Arc<Type>>) -> Self {
|
||||
fn from_record_constructor(constructor: &RecordConstructor<Rc<Type>>) -> Self {
|
||||
DocTypeConstructor {
|
||||
definition: format::Formatter::new()
|
||||
.docs_record_constructor(constructor)
|
||||
|
|
|
@ -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<Arc<AikenType>, TypedExpr>),
|
||||
Validator(Validator<Arc<AikenType>, TypedExpr>),
|
||||
Func(TypedFunction),
|
||||
Validator(TypedValidator),
|
||||
}
|
||||
|
||||
fn assert_uplc(source_code: &str, expected: Term<Name>, should_fail: bool) {
|
||||
|
|
Loading…
Reference in New Issue