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