Skip to content

Commit e0197fd

Browse files
author
AztecBot
committed
fix: Non-determinism from under constrained checks (noir-lang/noir#6945)
chore: use logs for benchmarking (noir-lang/noir#6911) chore: bump `noir-gates-diff` (noir-lang/noir#6944) chore: bump `noir-gates-diff` (noir-lang/noir#6943) fix: Show output of `test_program_is_idempotent` on failure (noir-lang/noir#6942) chore: delete a bunch of dead code from `noirc_evaluator` (noir-lang/noir#6939) feat: require trait function calls (`Foo::bar()`) to have the trait in scope (imported) (noir-lang/noir#6882) chore: Bump arkworks to version `0.5.0` (noir-lang/noir#6871)
2 parents da593f2 + 7fbb5c7 commit e0197fd

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

.noir-sync-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
06ba20c1b7a72fe42801616512f61e0b454e0652
1+
203242c0c05e9333caaa8df55a4ed9a02e000882

noir/noir-repo/compiler/noirc_evaluator/src/ssa/checks/check_for_underconstrained_values.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ssa::ir::value::{Value, ValueId};
1010
use crate::ssa::ssa_gen::Ssa;
1111
use im::HashMap;
1212
use rayon::prelude::*;
13-
use std::collections::{BTreeMap, HashSet};
13+
use std::collections::{BTreeMap, BTreeSet, HashSet};
1414
use tracing::trace;
1515

1616
impl Ssa {
@@ -73,15 +73,15 @@ fn check_for_underconstrained_values_within_function(
7373

7474
context.compute_sets_of_connected_value_ids(function, all_functions);
7575

76-
let all_brillig_generated_values: HashSet<ValueId> =
76+
let all_brillig_generated_values: BTreeSet<ValueId> =
7777
context.brillig_return_to_argument.keys().copied().collect();
7878

7979
let connected_sets_indices =
8080
context.find_sets_connected_to_function_inputs_or_outputs(function);
8181

8282
// Go through each disconnected set, find brillig calls that caused it and form warnings
8383
for set_index in
84-
HashSet::from_iter(0..(context.value_sets.len())).difference(&connected_sets_indices)
84+
BTreeSet::from_iter(0..(context.value_sets.len())).difference(&connected_sets_indices)
8585
{
8686
let current_set = &context.value_sets[*set_index];
8787
warnings.append(&mut context.find_disconnecting_brillig_calls_with_results_in_set(
@@ -104,7 +104,7 @@ struct DependencyContext {
104104
array_elements: HashMap<ValueId, ValueId>,
105105
// Map of brillig call ids to sets of the value ids descending
106106
// from their arguments and results
107-
tainted: HashMap<InstructionId, BrilligTaintedIds>,
107+
tainted: BTreeMap<InstructionId, BrilligTaintedIds>,
108108
}
109109

110110
/// Structure keeping track of value ids descending from Brillig calls'
@@ -434,7 +434,7 @@ impl DependencyContext {
434434
struct Context {
435435
visited_blocks: HashSet<BasicBlockId>,
436436
block_queue: Vec<BasicBlockId>,
437-
value_sets: Vec<HashSet<ValueId>>,
437+
value_sets: Vec<BTreeSet<ValueId>>,
438438
brillig_return_to_argument: HashMap<ValueId, Vec<ValueId>>,
439439
brillig_return_to_instruction_id: HashMap<ValueId, InstructionId>,
440440
}
@@ -467,15 +467,15 @@ impl Context {
467467
fn find_sets_connected_to_function_inputs_or_outputs(
468468
&mut self,
469469
function: &Function,
470-
) -> HashSet<usize> {
470+
) -> BTreeSet<usize> {
471471
let variable_parameters_and_return_values = function
472472
.parameters()
473473
.iter()
474474
.chain(function.returns())
475475
.filter(|id| function.dfg.get_numeric_constant(**id).is_none())
476476
.map(|value_id| function.dfg.resolve(*value_id));
477477

478-
let mut connected_sets_indices: HashSet<usize> = HashSet::new();
478+
let mut connected_sets_indices: BTreeSet<usize> = BTreeSet::default();
479479

480480
// Go through each parameter and each set and check if the set contains the parameter
481481
// If it's the case, then that set doesn't present an issue
@@ -492,8 +492,8 @@ impl Context {
492492
/// Find which Brillig calls separate this set from others and return bug warnings about them
493493
fn find_disconnecting_brillig_calls_with_results_in_set(
494494
&self,
495-
current_set: &HashSet<ValueId>,
496-
all_brillig_generated_values: &HashSet<ValueId>,
495+
current_set: &BTreeSet<ValueId>,
496+
all_brillig_generated_values: &BTreeSet<ValueId>,
497497
function: &Function,
498498
) -> Vec<SsaReport> {
499499
let mut warnings = Vec::new();
@@ -503,7 +503,7 @@ impl Context {
503503
// Go through all Brillig outputs in the set
504504
for brillig_output_in_set in intersection {
505505
// Get the inputs that correspond to the output
506-
let inputs: HashSet<ValueId> =
506+
let inputs: BTreeSet<ValueId> =
507507
self.brillig_return_to_argument[&brillig_output_in_set].iter().copied().collect();
508508

509509
// Check if any of them are not in the set
@@ -532,7 +532,7 @@ impl Context {
532532
let instructions = function.dfg[block].instructions();
533533

534534
for instruction in instructions.iter() {
535-
let mut instruction_arguments_and_results = HashSet::new();
535+
let mut instruction_arguments_and_results = BTreeSet::new();
536536

537537
// Insert non-constant instruction arguments
538538
function.dfg[*instruction].for_each_value(|value_id| {
@@ -638,15 +638,15 @@ impl Context {
638638
/// Merge all small sets into larger ones based on whether the sets intersect or not
639639
///
640640
/// If two small sets have a common ValueId, we merge them into one
641-
fn merge_sets(current: &[HashSet<ValueId>]) -> Vec<HashSet<ValueId>> {
641+
fn merge_sets(current: &[BTreeSet<ValueId>]) -> Vec<BTreeSet<ValueId>> {
642642
let mut new_set_id: usize = 0;
643-
let mut updated_sets: HashMap<usize, HashSet<ValueId>> = HashMap::new();
644-
let mut value_dictionary: HashMap<ValueId, usize> = HashMap::new();
645-
let mut parsed_value_set: HashSet<ValueId> = HashSet::new();
643+
let mut updated_sets: BTreeMap<usize, BTreeSet<ValueId>> = BTreeMap::default();
644+
let mut value_dictionary: HashMap<ValueId, usize> = HashMap::default();
645+
let mut parsed_value_set: BTreeSet<ValueId> = BTreeSet::default();
646646

647647
for set in current.iter() {
648648
// Check if the set has any of the ValueIds we've encountered at previous iterations
649-
let intersection: HashSet<ValueId> =
649+
let intersection: BTreeSet<ValueId> =
650650
set.intersection(&parsed_value_set).copied().collect();
651651
parsed_value_set.extend(set.iter());
652652

@@ -663,7 +663,7 @@ impl Context {
663663
}
664664

665665
// If there is an intersection, we have to join the sets
666-
let mut joining_sets_ids: HashSet<usize> =
666+
let mut joining_sets_ids: BTreeSet<usize> =
667667
intersection.iter().map(|x| value_dictionary[x]).collect();
668668
let mut largest_set_size = usize::MIN;
669669
let mut largest_set_index = usize::MAX;
@@ -677,7 +677,7 @@ impl Context {
677677
joining_sets_ids.remove(&largest_set_index);
678678

679679
let mut largest_set =
680-
updated_sets.extract(&largest_set_index).expect("Set should be in the hashmap").0;
680+
updated_sets.remove(&largest_set_index).expect("Set should be in the hashmap");
681681

682682
// For each of other sets that need to be joined
683683
for set_id in joining_sets_ids.iter() {
@@ -702,7 +702,7 @@ impl Context {
702702

703703
/// Parallel version of merge_sets
704704
/// The sets are merged by chunks, and then the chunks are merged together
705-
fn merge_sets_par(sets: &[HashSet<ValueId>]) -> Vec<HashSet<ValueId>> {
705+
fn merge_sets_par(sets: &[BTreeSet<ValueId>]) -> Vec<BTreeSet<ValueId>> {
706706
let mut sets = sets.to_owned();
707707
let mut len = sets.len();
708708
let mut prev_len = len + 1;

noir/noir-repo/tooling/nargo_cli/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ fn test_{test_name}(force_brillig: ForceBrillig, inliner_aggressiveness: Inliner
208208
nargo.arg("--program-dir").arg(test_program_dir);
209209
nargo.arg("{test_command}").arg("--force");
210210
nargo.arg("--inliner-aggressiveness").arg(inliner_aggressiveness.0.to_string());
211+
nargo.arg("--check-non-determinism");
211212
212213
if force_brillig.0 {{
213214
nargo.arg("--force-brillig");
@@ -217,7 +218,6 @@ fn test_{test_name}(force_brillig: ForceBrillig, inliner_aggressiveness: Inliner
217218
nargo.arg("50");
218219
219220
// Check whether the test case is non-deterministic
220-
nargo.arg("--check-non-determinism");
221221
}}
222222
223223
{test_content}

0 commit comments

Comments
 (0)