Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Riley-Kilgore committed Dec 4, 2024
1 parent 36a1299 commit e2c1ee7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 34 deletions.
6 changes: 4 additions & 2 deletions crates/aiken-lang/src/ast/well_known.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,11 @@ impl Type {
},
],
}],
}.into(),
}
.into(),
},
}.into(),
}
.into(),
),
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken-lang/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
// fn(PRNG, Int) -> Option<(PRNG, a)>
let scaled_fuzzer_value = Type::generic_var(id_gen.next());
prelude.types.insert(
well_known::SCALED_FUZZER.to_string(),
well_known::SCALED_FUZZER.to_string(),
TypeConstructor {
location: Span::empty(),
parameters: vec![scaled_fuzzer_value.clone()],
Expand Down
46 changes: 24 additions & 22 deletions crates/aiken-lang/src/test_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ impl PropertyTest {
value,
choices: next_prng.choices(),
cache: Cache::new(move |choices| {
match Prng::from_choices(choices, iteration).sample(&self.fuzzer.program, iteration) {
match Prng::from_choices(choices, iteration)
.sample(&self.fuzzer.program, iteration)
{
Err(..) => Status::Invalid,
Ok(None) => Status::Invalid,
Ok(Some((_, value))) => {
Expand Down Expand Up @@ -504,13 +506,13 @@ impl PropertyTest {
///
#[derive(Debug)]
pub enum Prng {
Seeded {
choices: Vec<u8>,
Seeded {
choices: Vec<u8>,
uplc: PlutusData,
iteration: usize,
},
Replayed {
choices: Vec<u8>,
Replayed {
choices: Vec<u8>,
uplc: PlutusData,
iteration: usize,
},
Expand Down Expand Up @@ -556,10 +558,7 @@ impl Prng {
choices: vec![],
uplc: Data::constr(
Prng::SEEDED,
vec![
Data::bytestring(digest.to_vec()),
Data::bytestring(vec![]),
],
vec![Data::bytestring(digest.to_vec()), Data::bytestring(vec![])],
),
iteration: 0,
}
Expand Down Expand Up @@ -591,30 +590,30 @@ impl Prng {
let program_clone = program.clone();

let result = program.eval(ExBudget::max());

match result.result() {
Ok(term) if matches!(term, Term::Constant(_)) => {
// If we got a valid constant result, process it
Ok(Prng::from_result(term, iteration))
}
_ => {
// Use the cloned program for the second attempt
let program_with_iteration = Program::<NamedDeBruijn>::try_from(
program_clone.apply_data(Data::integer(num_bigint::BigInt::from(iteration as i64)))
).unwrap();

let program_with_iteration = program_clone
.apply_data(Data::integer(num_bigint::BigInt::from(iteration as i64)));
// Program::<NamedDeBruijn>::try_from(
// program_clone.apply_data(Data::integer(num_bigint::BigInt::from(iteration as i64)))
// ).unwrap();

let mut result = program_with_iteration.eval(ExBudget::max());
match result.result() {
Ok(term) if matches!(term, Term::Constant(_)) => {
Ok(Prng::from_result(term, iteration))
}
Err(uplc_error) => {
Err(FuzzerError {
traces: result.logs(),
uplc_error,
})
}
_ => unreachable!("Fuzzer returned a malformed result? {result:#?}")
Err(uplc_error) => Err(FuzzerError {
traces: result.logs(),
uplc_error,
}),
_ => unreachable!("Fuzzer returned a malformed result? {result:#?}"),
}
}
}
Expand All @@ -630,7 +629,10 @@ impl Prng {
/// 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
/// aborted altogether with 'None'.
pub fn from_result(result: Term<NamedDeBruijn>, iteration: usize) -> Option<(Self, PlutusData)> {
pub fn from_result(
result: Term<NamedDeBruijn>,
iteration: usize,
) -> Option<(Self, PlutusData)> {
/// Interpret the given 'PlutusData' as one of two Prng constructors.
fn as_prng(cst: &PlutusData, iteration: usize) -> Prng {
if let PlutusData::Constr(Constr { tag, fields, .. }) = cst {
Expand Down
12 changes: 8 additions & 4 deletions crates/aiken-lang/src/tipo/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,12 @@ fn infer_scaled_fuzzer(
// Check if this is a ScaledFuzzer (fn(PRNG, Int) -> Option<(PRNG, a)>)
if args.len() == 2 {
match ret.borrow() {
Type::App { module, name, args: ret_args, .. }
if module.is_empty() && name == "Option" && ret_args.len() == 1 => {
Type::App {
module,
name,
args: ret_args,
..
} if module.is_empty() && name == "Option" && ret_args.len() == 1 => {
if let Type::Tuple { elems, .. } = ret_args[0].borrow() {
if elems.len() == 2 {
let wrapped = &elems[1];
Expand All @@ -879,7 +883,7 @@ fn infer_scaled_fuzzer(
}
}
}
_ => ()
_ => (),
}
}

Expand Down Expand Up @@ -947,4 +951,4 @@ fn put_params_in_scope<'a>(
ArgName::Named { .. } | ArgName::Discarded { .. } => (),
};
}
}
}
5 changes: 2 additions & 3 deletions crates/aiken-project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,8 @@ where
error,
path: options.blueprint_path,
}
})?;

Ok(())
.into()
})
}
CodeGenMode::Test {
match_tests,
Expand Down
3 changes: 1 addition & 2 deletions crates/aiken-project/src/telemetry/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ impl EventListener for Terminal {
" Complete"
.if_supports_color(Stderr, |s| s.bold())
.if_supports_color(Stderr, |s| s.green()),
"benchmark results written to CSV"
.if_supports_color(Stderr, |s| s.bold())
"benchmark results written to CSV".if_supports_color(Stderr, |s| s.bold())
);
}
}
Expand Down

0 comments on commit e2c1ee7

Please sign in to comment.