From 3ad25c8f07d0e1859fab3573438d36cb72f7070b Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 22 Feb 2022 14:33:43 +0800 Subject: [PATCH] nac3core: sort error messages for determinism --- nac3core/src/codegen/mod.rs | 8 ++++---- nac3core/src/toplevel/composer.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nac3core/src/codegen/mod.rs b/nac3core/src/codegen/mod.rs index d83b22bf4..d4036332c 100644 --- a/nac3core/src/codegen/mod.rs +++ b/nac3core/src/codegen/mod.rs @@ -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(); diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 49275072a..f917e4b94 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -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(()) }