Skip to content

Commit 2b56f91

Browse files
committed
Merge #381: Add sorting to is_consistent function for deterministic error ordering
4a21dcd refactor: add sorting to `is_consistent` function for deterministic error ordering (LesterEvSe) Pull request description: Error output ordering was nondeterministic because `Arguments` and `Witness` used `HashMap` internally, causing diagnostics to be emitted in arbitrary iteration order across runs. This PR add sorting to `is_consistent` for deterministic error ordering. ACKs for top commit: KyrylR: ACK 4a21dcd; Tree-SHA512: f5262a9429a3eae5088d31f43db8206df44792e80dad3d2842e32097a1d52d57eea71fd0f198f9c54c4627608507806fac46ab9a0e16c0e24f00b12a7c584b0a
2 parents d1b52b0 + 4a21dcd commit 2b56f91

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/witness.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ impl WitnessValues {
112112
/// finalized Simplicity program. However, before the finalization, we cannot know which
113113
/// witnesses will be pruned and which won't be pruned.
114114
pub fn is_consistent(&self, witness_types: &WitnessTypes, diagnostics: &mut DiagnosticManager) {
115-
for (name, declared_ty) in witness_types.iter() {
115+
let mut entries: Vec<_> = witness_types.iter().collect();
116+
entries.sort_unstable_by_key(|(k, _)| *k);
117+
118+
for (name, declared_ty) in entries {
116119
let Some(value) = self.get(name) else {
117120
diagnostics.push(Diagnostic::global(Error::WitnessMissing {
118121
name: name.shallow_clone(),
@@ -237,7 +240,10 @@ impl Arguments {
237240
///
238241
/// Arguments without a corresponding parameter are ignored.
239242
pub fn is_consistent(&self, parameters: &Parameters, diagnostics: &mut DiagnosticManager) {
240-
for (name, parameter_ty) in parameters.iter() {
243+
let mut entries: Vec<_> = parameters.iter().collect();
244+
entries.sort_unstable_by_key(|(k, _)| *k);
245+
246+
for (name, parameter_ty) in entries {
241247
let Some(argument) = self.get(name) else {
242248
diagnostics.push(Diagnostic::global(Error::ArgumentMissing {
243249
name: name.shallow_clone(),

0 commit comments

Comments
 (0)