mirror of
https://github.com/powdr-labs/powdr.git
synced 2026-05-13 03:00:26 -04:00
@@ -30,6 +30,11 @@ enum Commands {
|
||||
#[arg(short, long)]
|
||||
#[arg(default_value_t = false)]
|
||||
force: bool,
|
||||
|
||||
/// Verbose output (provides a full execution trace).
|
||||
#[arg(short, long)]
|
||||
#[arg(default_value_t = false)]
|
||||
verbose: bool,
|
||||
},
|
||||
|
||||
/// Parses and prints the PIL file on stdout.
|
||||
@@ -56,6 +61,7 @@ fn main() {
|
||||
inputs,
|
||||
output_directory,
|
||||
force,
|
||||
verbose,
|
||||
} => {
|
||||
let inputs = inputs
|
||||
.split(',')
|
||||
@@ -63,7 +69,13 @@ fn main() {
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect::<Vec<AbstractNumberType>>();
|
||||
powdr::compiler::compile_asm(&file, inputs, Path::new(&output_directory), force);
|
||||
powdr::compiler::compile_asm(
|
||||
&file,
|
||||
inputs,
|
||||
Path::new(&output_directory),
|
||||
force,
|
||||
verbose,
|
||||
);
|
||||
}
|
||||
Commands::Reformat { file } => {
|
||||
let contents = fs::read_to_string(&file).unwrap();
|
||||
|
||||
@@ -22,6 +22,7 @@ pub fn generate<'a>(
|
||||
degree: &DegreeType,
|
||||
constants: &[(&String, Vec<AbstractNumberType>)],
|
||||
query_callback: Option<impl FnMut(&str) -> Option<AbstractNumberType>>,
|
||||
verbose: bool,
|
||||
) -> Vec<(&'a String, Vec<AbstractNumberType>)> {
|
||||
let polys: Vec<WitnessColumn> = analyzed
|
||||
.committed_polys_in_source_order()
|
||||
@@ -37,6 +38,7 @@ pub fn generate<'a>(
|
||||
let mut values: Vec<(&String, Vec<AbstractNumberType>)> =
|
||||
polys.iter().map(|p| (p.name, Vec::new())).collect();
|
||||
let mut evaluator = Evaluator::new(analyzed, constants, &polys, query_callback);
|
||||
evaluator.set_verbose(verbose);
|
||||
for row in 0..*degree as DegreeType {
|
||||
let row_values = evaluator.compute_next_row(row);
|
||||
for (col, v) in row_values.into_iter().enumerate() {
|
||||
@@ -93,6 +95,7 @@ where
|
||||
next_row: DegreeType,
|
||||
failure_reasons: Vec<String>,
|
||||
progress: bool,
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
@@ -129,9 +132,14 @@ where
|
||||
next_row: 0,
|
||||
failure_reasons: vec![],
|
||||
progress: true,
|
||||
verbose: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_verbose(&mut self, verbose: bool) {
|
||||
self.verbose = verbose;
|
||||
}
|
||||
|
||||
pub fn compute_next_row(&mut self, next_row: DegreeType) -> Vec<AbstractNumberType> {
|
||||
self.next_row = next_row;
|
||||
|
||||
@@ -144,15 +152,6 @@ where
|
||||
self.progress = false;
|
||||
self.failure_reasons.clear();
|
||||
|
||||
if self.query_callback.is_some() {
|
||||
// TODO avoid clone
|
||||
for column in self.committed.clone().values() {
|
||||
if !self.has_known_next_value(column.id) && column.query.is_some() {
|
||||
let result = self.process_witness_query(column);
|
||||
self.handle_eval_result(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
for identity in &self.analyzed.identities {
|
||||
let result = match identity.kind {
|
||||
IdentityKind::Polynomial => {
|
||||
@@ -173,25 +172,25 @@ where
|
||||
}
|
||||
self.handle_eval_result(result);
|
||||
}
|
||||
if self.query_callback.is_some() {
|
||||
// TODO avoid clone
|
||||
for column in self.committed.clone().values() {
|
||||
if !self.has_known_next_value(column.id) && column.query.is_some() {
|
||||
let result = self.process_witness_query(column);
|
||||
self.handle_eval_result(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !self.progress {
|
||||
break;
|
||||
}
|
||||
if self.next.iter().all(|v| v.is_some()) {
|
||||
// let values = self
|
||||
// .next
|
||||
// .iter()
|
||||
// .enumerate()
|
||||
// .map(|(i, v)| format!("{} = {}", self.committed_names[i], v.unwrap()))
|
||||
// .collect::<Vec<_>>()
|
||||
// .join(", ");
|
||||
// println!("Row {next_row}: {values}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
//println!("\n\n================================\n");
|
||||
if identity_failed && self.next.iter().any(|v| v.is_none()) {
|
||||
eprintln!(
|
||||
"Error: Row {next_row}: Unable to derive values for committed polynomials: {}",
|
||||
"\nError: Row {next_row}: Unable to derive values for committed polynomials: {}\n",
|
||||
self.next
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -203,24 +202,19 @@ where
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
);
|
||||
eprintln!("Reasons: {}", self.failure_reasons.join("\n\n"));
|
||||
eprintln!("Reasons:\n{}\n", self.failure_reasons.join("\n\n"));
|
||||
eprintln!(
|
||||
"Current values:\n{}",
|
||||
self.next
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, v)| format!(
|
||||
"{} = {}",
|
||||
self.committed_names[i],
|
||||
v.as_ref()
|
||||
.map(format_number)
|
||||
.unwrap_or("<unknown>".to_string())
|
||||
))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
indent(&self.format_next_values().join("\n"), " ")
|
||||
);
|
||||
panic!();
|
||||
} else {
|
||||
if self.verbose {
|
||||
println!(
|
||||
"===== Row {next_row}:\n{}",
|
||||
indent(&self.format_next_values().join("\n"), " ")
|
||||
);
|
||||
}
|
||||
std::mem::swap(&mut self.next, &mut self.current);
|
||||
self.next = vec![None; self.current.len()];
|
||||
// TODO check a bit better that "None" values do not
|
||||
@@ -232,6 +226,22 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn format_next_values(&self) -> Vec<String> {
|
||||
self.next
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, v)| {
|
||||
format!(
|
||||
"{} = {}",
|
||||
self.committed_names[i],
|
||||
v.as_ref()
|
||||
.map(format_number)
|
||||
.unwrap_or("<unknown>".to_string())
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn process_witness_query(
|
||||
&mut self,
|
||||
column: &&WitnessColumn,
|
||||
|
||||
@@ -27,6 +27,7 @@ pub fn compile_pil(
|
||||
pil_file.file_name().unwrap().to_str().unwrap(),
|
||||
output_dir,
|
||||
query_callback,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ pub fn compile_pil_ast(
|
||||
file_name: &str,
|
||||
output_dir: &Path,
|
||||
query_callback: Option<impl FnMut(&str) -> Option<AbstractNumberType>>,
|
||||
verbose: bool,
|
||||
) -> bool {
|
||||
// TODO exporting this to string as a hack because the parser
|
||||
// is tied into the analyzer due to imports.
|
||||
@@ -43,6 +45,7 @@ pub fn compile_pil_ast(
|
||||
file_name,
|
||||
output_dir,
|
||||
query_callback,
|
||||
verbose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -53,6 +56,7 @@ pub fn compile_asm(
|
||||
inputs: Vec<AbstractNumberType>,
|
||||
output_dir: &Path,
|
||||
force_overwrite: bool,
|
||||
verbose: bool,
|
||||
) {
|
||||
let contents = fs::read_to_string(file_name).unwrap();
|
||||
let pil = asm_compiler::compile(Some(file_name), &contents).unwrap_or_else(|err| {
|
||||
@@ -93,6 +97,7 @@ pub fn compile_asm(
|
||||
pil_file_name.to_str().unwrap(),
|
||||
output_dir,
|
||||
Some(query_callback),
|
||||
verbose,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,6 +106,7 @@ fn compile(
|
||||
file_name: &str,
|
||||
output_dir: &Path,
|
||||
query_callback: Option<impl FnMut(&str) -> Option<AbstractNumberType>>,
|
||||
verbose: bool,
|
||||
) -> bool {
|
||||
let mut success = true;
|
||||
let (constants, degree) = constant_evaluator::generate(analyzed);
|
||||
@@ -111,7 +117,8 @@ fn compile(
|
||||
&constants,
|
||||
);
|
||||
println!("Wrote constants.bin.");
|
||||
let commits = commit_evaluator::generate(analyzed, °ree, &constants, query_callback);
|
||||
let commits =
|
||||
commit_evaluator::generate(analyzed, °ree, &constants, query_callback, verbose);
|
||||
write_polys_file(
|
||||
&mut BufWriter::new(&mut fs::File::create(output_dir.join("commits.bin")).unwrap()),
|
||||
degree,
|
||||
|
||||
@@ -42,6 +42,7 @@ fn verify_asm(file_name: &str, inputs: Vec<AbstractNumberType>) {
|
||||
}
|
||||
None
|
||||
}),
|
||||
false
|
||||
));
|
||||
verify(pil_file_name, &temp_dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user