Skip to content

Commit 2d2a32e

Browse files
author
rkarabut
committed
Deal with the leftover unnecessary actions
1 parent 0effedd commit 2d2a32e

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

compiler/noirc_evaluator/src/ssa/checks/check_for_underconstrained_values.rs

+39-26
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ impl DependencyContext {
363363
}
364364

365365
// Start tracking calls when their argument value ids first appear,
366-
// or when their instruction id comes up
366+
// or when their instruction id comes up (in case there were
367+
// no non-constant arguments)
367368
for argument in &arguments {
368369
if let Some(calls) = self.call_arguments.get(argument) {
369370
for call in calls {
@@ -530,34 +531,41 @@ impl DependencyContext {
530531

531532
/// Update sets of value ids that can be traced back to the Brillig calls being tracked
532533
fn update_children(&mut self, parents: &[ValueId], children: &[ValueId]) {
533-
let mut parents: HashSet<_> = HashSet::from_iter(parents.iter().copied());
534+
// Don't update sets for the calls not yet being tracked
535+
let mut tracked =
536+
self.tainted.iter_mut().filter(|(_, tainted_ids)| tainted_ids.tracking).peekable();
537+
if tracked.peek().is_some() {
538+
let mut parents: HashSet<_> = HashSet::from_iter(parents.iter().copied());
534539

535-
// Also include the current EnableSideEffectsIf condition in parents
536-
// (as it would affect every following statement)
537-
self.side_effects_condition.map(|v| parents.insert(v));
540+
// Also include the current EnableSideEffectsIf condition in parents
541+
// (as it would affect every following statement)
542+
self.side_effects_condition.map(|v| parents.insert(v));
538543

539-
for (_, tainted_ids) in self.tainted.iter_mut() {
540-
// Don't update sets for the calls not yet being tracked
541-
if tainted_ids.tracking {
544+
tracked.for_each(|(_, tainted_ids)| {
542545
tainted_ids.update_children(&parents, children);
543-
}
546+
});
544547
}
545548
}
546549

547550
/// Check if any of the recorded Brillig calls have been properly constrained
548551
/// by given values after recording partial constraints, if so stop tracking them
549552
fn clear_constrained(&mut self, constrained_values: &[ValueId], function: &Function) {
550-
// Remove numeric constants
551-
let constrained_values: HashSet<_> = constrained_values
552-
.iter()
553-
.filter(|v| function.dfg.get_numeric_constant(**v).is_none())
554-
.copied()
555-
.collect();
556-
557-
self.tainted.iter_mut().for_each(|(_, tainted_ids)| {
558-
tainted_ids.store_partial_constraints(&constrained_values);
559-
});
560-
self.tainted.retain(|_, tainted_ids| !tainted_ids.check_constrained());
553+
// Skip untracked calls
554+
let mut tracked =
555+
self.tainted.iter_mut().filter(|(_, tainted_ids)| tainted_ids.tracking).peekable();
556+
if tracked.peek().is_some() {
557+
// Remove numeric constants
558+
let constrained_values: HashSet<_> = constrained_values
559+
.iter()
560+
.filter(|v| function.dfg.get_numeric_constant(**v).is_none())
561+
.copied()
562+
.collect();
563+
564+
tracked.for_each(|(_, tainted_ids)| {
565+
tainted_ids.store_partial_constraints(&constrained_values);
566+
});
567+
self.tainted.retain(|_, tainted_ids| !tainted_ids.check_constrained());
568+
}
561569
}
562570

563571
/// Process ArrayGet instruction for tracked Brillig calls
@@ -570,12 +578,17 @@ impl DependencyContext {
570578
) {
571579
use acvm::acir::AcirField;
572580

573-
// Only allow numeric constant indices
574-
if let Some(value) = function.dfg.get_numeric_constant(index) {
575-
if let Some(index) = value.try_to_u32() {
576-
self.tainted.iter_mut().for_each(|(_, tainted_ids)| {
577-
tainted_ids.process_array_get(array, index as usize, element_results);
578-
});
581+
// Skip untracked calls
582+
let mut tracked =
583+
self.tainted.iter_mut().filter(|(_, tainted_ids)| tainted_ids.tracking).peekable();
584+
if tracked.peek().is_some() {
585+
// Only allow numeric constant indices
586+
if let Some(value) = function.dfg.get_numeric_constant(index) {
587+
if let Some(index) = value.try_to_u32() {
588+
tracked.for_each(|(_, tainted_ids)| {
589+
tainted_ids.process_array_get(array, index as usize, element_results);
590+
});
591+
}
579592
}
580593
}
581594
}

0 commit comments

Comments
 (0)