Uh, formatting again..

This commit is contained in:
Riley-Kilgore 2024-12-17 06:10:45 -08:00 committed by Riley
parent d73ee3dfe7
commit df05ae7e5d
5 changed files with 27 additions and 31 deletions

View File

@ -260,7 +260,7 @@ impl Type {
.into(), .into(),
} }
.into(), .into(),
} },
} }
.into(), .into(),
), ),

View File

@ -506,7 +506,7 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
tipo: Type::sampler(sampler_generic), tipo: Type::sampler(sampler_generic),
module: "".to_string(), module: "".to_string(),
public: true, public: true,
} },
); );
prelude prelude

View File

@ -49,7 +49,7 @@ use vec1::{vec1, Vec1};
pub enum Test { pub enum Test {
UnitTest(UnitTest), UnitTest(UnitTest),
PropertyTest(PropertyTest), PropertyTest(PropertyTest),
Benchmark(Benchmark) Benchmark(Benchmark),
} }
unsafe impl Send for Test {} unsafe impl Send for Test {}
@ -383,9 +383,7 @@ impl PropertyTest {
value, value,
choices: next_prng.choices(), choices: next_prng.choices(),
cache: Cache::new(move |choices| { cache: Cache::new(move |choices| {
match Prng::from_choices(choices) match Prng::from_choices(choices).sample(&self.fuzzer.program) {
.sample(&self.fuzzer.program)
{
Err(..) => Status::Invalid, Err(..) => Status::Invalid,
Ok(None) => Status::Invalid, Ok(None) => Status::Invalid,
Ok(Some((_, value))) => { Ok(Some((_, value))) => {
@ -468,7 +466,10 @@ impl Benchmark {
let mut prng = Prng::from_seed(seed); let mut prng = Prng::from_seed(seed);
while n > iteration { while n > iteration {
let fuzzer = self.sampler.program.apply_data(Data::integer(num_bigint::BigInt::from(iteration as i64))); let fuzzer = self
.sampler
.program
.apply_data(Data::integer(num_bigint::BigInt::from(iteration as i64)));
match prng.sample(&fuzzer) { match prng.sample(&fuzzer) {
Ok(Some((new_prng, value))) => { Ok(Some((new_prng, value))) => {
prng = new_prng; prng = new_prng;
@ -529,14 +530,8 @@ impl Benchmark {
/// ///
#[derive(Debug)] #[derive(Debug)]
pub enum Prng { pub enum Prng {
Seeded { Seeded { choices: Vec<u8>, uplc: PlutusData },
choices: Vec<u8>, Replayed { choices: Vec<u8>, uplc: PlutusData },
uplc: PlutusData,
},
Replayed {
choices: Vec<u8>,
uplc: PlutusData,
},
} }
impl Prng { impl Prng {
@ -607,9 +602,7 @@ impl Prng {
fuzzer: &Program<Name>, fuzzer: &Program<Name>,
// iteration: usize, // iteration: usize,
) -> Result<Option<(Prng, PlutusData)>, FuzzerError> { ) -> Result<Option<(Prng, PlutusData)>, FuzzerError> {
let program = Program::<NamedDeBruijn>::try_from( let program = Program::<NamedDeBruijn>::try_from(fuzzer.apply_data(self.uplc())).unwrap();
fuzzer
.apply_data(self.uplc())).unwrap();
let mut result = program.eval(ExBudget::max()); let mut result = program.eval(ExBudget::max());
result result
.result() .result()
@ -630,9 +623,7 @@ impl Prng {
/// made during shrinking aren't breaking underlying invariants (if only, because we run out of /// made during shrinking aren't breaking underlying invariants (if only, because we run out of
/// values to replay). In such case, the replayed sequence is simply invalid and the fuzzer /// values to replay). In such case, the replayed sequence is simply invalid and the fuzzer
/// aborted altogether with 'None'. /// aborted altogether with 'None'.
pub fn from_result( pub fn from_result(result: Term<NamedDeBruijn>) -> Option<(Self, PlutusData)> {
result: Term<NamedDeBruijn>,
) -> Option<(Self, PlutusData)> {
/// Interpret the given 'PlutusData' as one of two Prng constructors. /// Interpret the given 'PlutusData' as one of two Prng constructors.
fn as_prng(cst: &PlutusData) -> Prng { fn as_prng(cst: &PlutusData) -> Prng {
if let PlutusData::Constr(Constr { tag, fields, .. }) = cst { if let PlutusData::Constr(Constr { tag, fields, .. }) = cst {

View File

@ -365,7 +365,7 @@ fn infer_definition(
&arg.via.location(), &arg.via.location(),
) { ) {
Ok(result) => Ok(result), Ok(result) => Ok(result),
Err(err) => Err(err) Err(err) => Err(err),
}?; }?;
// Ensure that the annotation, if any, matches the type inferred from the // Ensure that the annotation, if any, matches the type inferred from the
@ -501,7 +501,7 @@ fn infer_definition(
&arg.via.location(), &arg.via.location(),
) { ) {
Ok(result) => Ok(result), Ok(result) => Ok(result),
Err(err) => Err(err) Err(err) => Err(err),
}?; }?;
// Ensure that the annotation, if any, matches the type inferred from the // Ensure that the annotation, if any, matches the type inferred from the
@ -930,11 +930,13 @@ fn infer_sampler(
ret, ret,
args, args,
alias: _, alias: _,
} => if args.len() == 1 && args[0].is_int() { } => {
if args.len() == 1 && args[0].is_int() {
infer_fuzzer(environment, expected_inner_type, ret, &Span::empty()) infer_fuzzer(environment, expected_inner_type, ret, &Span::empty())
} else { } else {
Err(could_not_unify()) Err(could_not_unify())
}, }
}
Type::Var { tipo, alias } => match &*tipo.deref().borrow() { Type::Var { tipo, alias } => match &*tipo.deref().borrow() {
TypeVar::Link { tipo } => infer_sampler( TypeVar::Link { tipo } => infer_sampler(

View File

@ -474,7 +474,8 @@ where
output, output,
} => { } => {
// todo - collect benchmarks // todo - collect benchmarks
let tests = self.collect_benchmarks(false, match_tests, exact_match, options.tracing)?; let tests =
self.collect_benchmarks(false, match_tests, exact_match, options.tracing)?;
if !tests.is_empty() { if !tests.is_empty() {
self.event_listener.handle_event(Event::RunningBenchmarks); self.event_listener.handle_event(Event::RunningBenchmarks);
@ -1215,7 +1216,7 @@ where
Test::PropertyTest(property_test) => { Test::PropertyTest(property_test) => {
property_test.run(seed, property_max_success, plutus_version) property_test.run(seed, property_max_success, plutus_version)
} }
Test::Benchmark(_) => unreachable!("Benchmarks cannot be run in PBT.") Test::Benchmark(_) => unreachable!("Benchmarks cannot be run in PBT."),
}) })
.collect::<Vec<TestResult<(Constant, Rc<Type>), PlutusData>>>() .collect::<Vec<TestResult<(Constant, Rc<Type>), PlutusData>>>()
.into_iter() .into_iter()
@ -1237,7 +1238,9 @@ where
tests tests
.into_par_iter() .into_par_iter()
.flat_map(|test| match test { .flat_map(|test| match test {
Test::UnitTest(_) | Test::PropertyTest(_) => unreachable!("Tests cannot be ran during benchmarking."), Test::UnitTest(_) | Test::PropertyTest(_) => {
unreachable!("Tests cannot be ran during benchmarking.")
}
Test::Benchmark(benchmark) => benchmark Test::Benchmark(benchmark) => benchmark
.benchmark(seed, property_max_success, plutus_version) .benchmark(seed, property_max_success, plutus_version)
.into_iter() .into_iter()