Better error messages #195

Merged
sb10q merged 1 commits from error-messages into master 2024-08-17 17:37:19 +08:00
2 changed files with 12 additions and 12 deletions

View File

@ -20,7 +20,7 @@ use inkwell::{
use itertools::Itertools;
use nac3parser::ast::{Stmt, StrRef};
use parking_lot::{Condvar, Mutex};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
@ -206,7 +206,7 @@ impl WorkerRegistry {
let passes = PassManager::create(&module);
pass_builder.populate_function_pass_manager(&passes);
let mut errors = Vec::new();
let mut errors = HashSet::new();
while let Some(task) = self.receiver.recv().unwrap() {
let tmp_module = context.create_module("tmp");
match gen_func(&context, generator, self, builder, tmp_module, task) {
@ -217,14 +217,14 @@ impl WorkerRegistry {
}
Err((old_builder, e)) => {
builder = old_builder;
errors.push(e);
errors.insert(e);
}
}
*self.task_count.lock() -= 1;
self.wait_condvar.notify_all();
}
if !errors.is_empty() {
panic!("Codegen error: {}", errors.iter().join("\n----------\n"));
panic!("Codegen error: {}", errors.into_iter().sorted().join("\n----------\n"));
}
let result = module.verify();

View File

@ -464,7 +464,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors.iter().join("\n----------\n"));
return Err(errors.into_iter().sorted().join("\n----------\n"));
}
Ok(())
}
@ -560,7 +560,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors.iter().join("\n----------\n"));
return Err(errors.into_iter().sorted().join("\n----------\n"));
}
// second, get all ancestors
@ -591,7 +591,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors.iter().join("\n----------\n"));
return Err(errors.into_iter().sorted().join("\n----------\n"));
}
// insert the ancestors to the def list
@ -674,7 +674,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors.iter().join("\n----------\n"));
return Err(errors.into_iter().sorted().join("\n----------\n"));
}
// handle the inheritanced methods and fields
@ -727,7 +727,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors.iter().join("\n----------\n"));
return Err(errors.into_iter().sorted().join("\n----------\n"));
}
Ok(())
@ -953,7 +953,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors.iter().join("\n----------\n"));
return Err(errors.into_iter().sorted().join("\n----------\n"));
}
Ok(())
}
@ -1555,7 +1555,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors.iter().join("\n---------\n"));
return Err(errors.into_iter().sorted().join("\n---------\n"));
}
for (i, signature, id) in constructors.into_iter() {
@ -1851,7 +1851,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors.iter().join("\n----------\n"));
return Err(errors.into_iter().sorted().join("\n----------\n"));
}
Ok(())
}