feat(aiken-project): use rayon to run tests in parallel

This commit is contained in:
rvcas
2023-01-09 18:04:39 -05:00
committed by Lucas
parent 6ea9ad9c41
commit 158b3dfe51
5 changed files with 93 additions and 40 deletions

View File

@@ -22,6 +22,7 @@ pallas = "0.16.0"
pallas-traverse = "0.16.0"
petgraph = "0.6.2"
pulldown-cmark = { version = "0.8.0", default-features = false }
rayon = "1.6.1"
regex = "1.6.0"
reqwest = "0.11.13"
serde = { version = "1.0.144", features = ["derive"] }

View File

@@ -10,7 +10,6 @@ pub mod pretty;
pub mod script;
pub mod telemetry;
use crate::module::{CERT, MINT, SPEND, VALIDATOR_NAMES, WITHDRAW};
use aiken_lang::{
ast::{Definition, Function, ModuleKind, TypedDataType, TypedDefinition, TypedFunction},
builder::{DataTypeKey, FunctionAccessKey},
@@ -44,7 +43,10 @@ use uplc::{
use crate::{
config::Config,
error::{Error, Warning},
module::{CheckedModule, CheckedModules, ParsedModule, ParsedModules},
module::{
CheckedModule, CheckedModules, ParsedModule, ParsedModules, CERT, MINT, SPEND,
VALIDATOR_NAMES, WITHDRAW,
},
telemetry::Event,
};
@@ -691,6 +693,8 @@ where
}
fn eval_scripts(&self, scripts: Vec<Script>, match_name: Option<String>) -> Vec<EvalInfo> {
use rayon::prelude::*;
// TODO: in the future we probably just want to be able to
// tell the machine to not explode on budget consumption.
let initial_budget = ExBudget {
@@ -698,43 +702,31 @@ where
cpu: i64::MAX,
};
let mut results = Vec::new();
scripts
.into_par_iter()
.filter(|script| -> bool {
let path = format!("{}{}", script.module, script.name);
for script in scripts {
let path = format!("{}{}", script.module, script.name);
if matches!(&match_name, Some(search_str) if !path.to_string().contains(search_str)) {
continue;
}
match script.program.eval(initial_budget) {
(Ok(result), remaining_budget, logs) => {
let eval_info = EvalInfo {
success: result != Term::Error
&& result != Term::Constant(Constant::Bool(false)),
script,
spent_budget: initial_budget - remaining_budget,
output: Some(result),
logs,
};
results.push(eval_info);
}
(Err(..), remaining_budget, logs) => {
let eval_info = EvalInfo {
success: false,
script,
spent_budget: initial_budget - remaining_budget,
output: None,
logs,
};
results.push(eval_info);
}
}
}
results
!matches!(&match_name, Some(search_str) if !path.contains(search_str))
})
.map(|script| match script.program.eval(initial_budget) {
(Ok(result), remaining_budget, logs) => EvalInfo {
success: result != Term::Error
&& result != Term::Constant(Constant::Bool(false)),
script,
spent_budget: initial_budget - remaining_budget,
output: Some(result),
logs,
},
(Err(..), remaining_budget, logs) => EvalInfo {
success: false,
script,
spent_budget: initial_budget - remaining_budget,
output: None,
logs,
},
})
.collect()
}
fn output_path(&self) -> PathBuf {

View File

@@ -3,7 +3,7 @@ use aiken_lang::ast::BinOp;
use std::path::PathBuf;
use uplc::ast::{NamedDeBruijn, Program};
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Script {
pub input_path: PathBuf,
pub module: String,
@@ -12,6 +12,8 @@ pub struct Script {
pub evaluation_hint: Option<EvalHint>,
}
unsafe impl Send for Script {}
impl Script {
pub fn new(
input_path: PathBuf,
@@ -45,3 +47,5 @@ pub struct EvalInfo {
pub output: Option<Term<NamedDeBruijn>>,
pub logs: Vec<String>,
}
unsafe impl Send for EvalInfo {}