Write boilerplate code for being able to easily test properties.
Loads of plumbing, but we now have at least some nice ways to test property execution and shrinking.
This commit is contained in:
@@ -2,21 +2,16 @@ pub mod air;
|
||||
pub mod builder;
|
||||
pub mod tree;
|
||||
|
||||
use petgraph::{algo, Graph};
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
use itertools::Itertools;
|
||||
use uplc::{
|
||||
ast::{Constant as UplcConstant, Name, NamedDeBruijn, Program, Term, Type as UplcType},
|
||||
builder::{CONSTR_FIELDS_EXPOSER, CONSTR_INDEX_EXPOSER, EXPECT_ON_LIST},
|
||||
builtins::DefaultFunction,
|
||||
machine::cost_model::ExBudget,
|
||||
optimize::aiken_optimize_and_intern,
|
||||
parser::interner::Interner,
|
||||
use self::{
|
||||
air::Air,
|
||||
builder::{
|
||||
air_holds_msg, cast_validator_args, constants_ir, convert_type_to_data, extract_constant,
|
||||
lookup_data_type_by_tipo, modify_cyclic_calls, modify_self_calls, rearrange_list_clauses,
|
||||
AssignmentProperties, ClauseProperties, CodeGenSpecialFuncs, CycleFunctionNames,
|
||||
HoistableFunction, Variant,
|
||||
},
|
||||
tree::{AirMsg, AirTree, TreePath},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ast::{
|
||||
AssignmentKind, BinOp, Bls12_381Point, Curve, DataTypeKey, FunctionAccessKey, Pattern,
|
||||
@@ -42,22 +37,23 @@ use crate::{
|
||||
},
|
||||
IdGenerator,
|
||||
};
|
||||
|
||||
use self::{
|
||||
air::Air,
|
||||
builder::{
|
||||
air_holds_msg, cast_validator_args, constants_ir, convert_type_to_data, extract_constant,
|
||||
lookup_data_type_by_tipo, modify_cyclic_calls, modify_self_calls, rearrange_list_clauses,
|
||||
AssignmentProperties, ClauseProperties, CodeGenSpecialFuncs, CycleFunctionNames,
|
||||
HoistableFunction, Variant,
|
||||
},
|
||||
tree::{AirMsg, AirTree, TreePath},
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
use itertools::Itertools;
|
||||
use petgraph::{algo, Graph};
|
||||
use std::{collections::HashMap, rc::Rc};
|
||||
use uplc::{
|
||||
ast::{Constant as UplcConstant, Name, NamedDeBruijn, Program, Term, Type as UplcType},
|
||||
builder::{CONSTR_FIELDS_EXPOSER, CONSTR_INDEX_EXPOSER, EXPECT_ON_LIST},
|
||||
builtins::DefaultFunction,
|
||||
machine::cost_model::ExBudget,
|
||||
optimize::aiken_optimize_and_intern,
|
||||
parser::interner::Interner,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CodeGenerator<'a> {
|
||||
/// immutable index maps
|
||||
functions: IndexMap<FunctionAccessKey, &'a TypedFunction>,
|
||||
pub functions: IndexMap<FunctionAccessKey, &'a TypedFunction>,
|
||||
data_types: IndexMap<DataTypeKey, &'a TypedDataType>,
|
||||
module_types: IndexMap<&'a String, &'a TypeInfo>,
|
||||
module_src: IndexMap<String, (String, LineNumbers)>,
|
||||
@@ -203,7 +199,7 @@ impl<'a> CodeGenerator<'a> {
|
||||
self.finalize(term)
|
||||
}
|
||||
|
||||
pub fn generate_raw(&mut self, test_body: &TypedExpr, module_name: &String) -> Program<Name> {
|
||||
pub fn generate_raw(&mut self, test_body: &TypedExpr, module_name: &str) -> Program<Name> {
|
||||
let mut air_tree = self.build(test_body, module_name, &[]);
|
||||
|
||||
air_tree = AirTree::no_op(air_tree);
|
||||
@@ -244,7 +240,7 @@ impl<'a> CodeGenerator<'a> {
|
||||
fn build(
|
||||
&mut self,
|
||||
body: &TypedExpr,
|
||||
module_build_name: &String,
|
||||
module_build_name: &str,
|
||||
context: &[TypedExpr],
|
||||
) -> AirTree {
|
||||
if !context.is_empty() {
|
||||
@@ -1766,7 +1762,7 @@ impl<'a> CodeGenerator<'a> {
|
||||
final_clause: TypedClause,
|
||||
subject_tipo: &Rc<Type>,
|
||||
props: &mut ClauseProperties,
|
||||
module_name: &String,
|
||||
module_name: &str,
|
||||
) -> AirTree {
|
||||
assert!(
|
||||
!subject_tipo.is_void(),
|
||||
@@ -3570,7 +3566,13 @@ impl<'a> CodeGenerator<'a> {
|
||||
let code_gen_func = self
|
||||
.code_gen_functions
|
||||
.get(&generic_function_key.function_name)
|
||||
.unwrap_or_else(|| panic!("Missing Code Gen Function Definition"));
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Missing function definition for {}. Known definitions: {:?}",
|
||||
generic_function_key.function_name,
|
||||
self.code_gen_functions.keys(),
|
||||
)
|
||||
});
|
||||
|
||||
if !dependency_functions
|
||||
.iter()
|
||||
@@ -3837,7 +3839,9 @@ impl<'a> CodeGenerator<'a> {
|
||||
}
|
||||
|
||||
DefaultFunction::MkCons | DefaultFunction::MkPairData => {
|
||||
unimplemented!("MkCons and MkPairData should be handled by an anon function or using [] or ( a, b, .., z).\n")
|
||||
unimplemented!(
|
||||
"MkCons and MkPairData should be handled by an anon function or using [] or ( a, b, .., z).\n"
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
let mut term: Term<Name> = (*builtin).into();
|
||||
@@ -4230,7 +4234,9 @@ impl<'a> CodeGenerator<'a> {
|
||||
}
|
||||
|
||||
DefaultFunction::MkCons | DefaultFunction::MkPairData => {
|
||||
unimplemented!("MkCons and MkPairData should be handled by an anon function or using [] or ( a, b, .., z).\n")
|
||||
unimplemented!(
|
||||
"MkCons and MkPairData should be handled by an anon function or using [] or ( a, b, .., z).\n"
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
let mut term: Term<Name> = func.into();
|
||||
|
||||
@@ -1,7 +1,21 @@
|
||||
use std::{collections::HashMap, ops::Deref, rc::Rc};
|
||||
|
||||
use super::{
|
||||
air::{Air, ExpectLevel},
|
||||
tree::{AirMsg, AirTree, TreePath},
|
||||
};
|
||||
use crate::{
|
||||
ast::{
|
||||
AssignmentKind, BinOp, ClauseGuard, Constant, DataType, DataTypeKey, FunctionAccessKey,
|
||||
Pattern, Span, TraceLevel, TypedArg, TypedClause, TypedClauseGuard, TypedDataType,
|
||||
TypedPattern, UnOp,
|
||||
},
|
||||
builtins::{bool, data, function, int, list, string, void},
|
||||
expr::TypedExpr,
|
||||
line_numbers::{LineColumn, LineNumbers},
|
||||
tipo::{PatternConstructor, Type, TypeVar, ValueConstructor, ValueConstructorVariant},
|
||||
};
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
use itertools::{Itertools, Position};
|
||||
use std::{collections::HashMap, ops::Deref, rc::Rc};
|
||||
use uplc::{
|
||||
ast::{Constant as UplcConstant, Name, Term, Type as UplcType},
|
||||
builder::{CONSTR_FIELDS_EXPOSER, CONSTR_INDEX_EXPOSER},
|
||||
@@ -13,27 +27,6 @@ use uplc::{
|
||||
Constr, KeyValuePairs, PlutusData,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ast::{
|
||||
AssignmentKind, DataType, DataTypeKey, FunctionAccessKey, Pattern, Span, TraceLevel,
|
||||
TypedArg, TypedClause, TypedClauseGuard, TypedDataType, TypedPattern,
|
||||
},
|
||||
builtins::{bool, data, function, int, list, string, void},
|
||||
expr::TypedExpr,
|
||||
line_numbers::{LineColumn, LineNumbers},
|
||||
tipo::{PatternConstructor, TypeVar, ValueConstructor, ValueConstructorVariant},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ast::{BinOp, ClauseGuard, Constant, UnOp},
|
||||
tipo::Type,
|
||||
};
|
||||
|
||||
use super::{
|
||||
air::{Air, ExpectLevel},
|
||||
tree::{AirMsg, AirTree, TreePath},
|
||||
};
|
||||
|
||||
pub type Variant = String;
|
||||
|
||||
pub type Params = Vec<String>;
|
||||
@@ -1943,7 +1936,7 @@ pub fn extract_constant(term: &Term<Name>) -> Option<Rc<UplcConstant>> {
|
||||
}
|
||||
|
||||
pub fn get_src_code_by_span(
|
||||
module_name: &String,
|
||||
module_name: &str,
|
||||
span: &Span,
|
||||
module_src: &IndexMap<String, (String, LineNumbers)>,
|
||||
) -> String {
|
||||
@@ -1957,7 +1950,7 @@ pub fn get_src_code_by_span(
|
||||
}
|
||||
|
||||
pub fn get_line_columns_by_span(
|
||||
module_name: &String,
|
||||
module_name: &str,
|
||||
span: &Span,
|
||||
module_src: &IndexMap<String, (String, LineNumbers)>,
|
||||
) -> LineColumn {
|
||||
|
||||
Reference in New Issue
Block a user