Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove predicate from sort intrinsic function #4228

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,6 @@ impl AcirContext {
&mut self,
inputs: Vec<AcirVar>,
bit_size: u32,
predicate: AcirVar,
) -> Result<Vec<AcirVar>, RuntimeError> {
let len = inputs.len();
// Convert the inputs into expressions
Expand All @@ -1666,25 +1665,16 @@ impl AcirContext {
self.acir_ir.permutation(&inputs_expr, &output_expr)?;

// Enforce the outputs to be sorted
let true_var = self.add_constant(true);
for i in 0..(outputs_var.len() - 1) {
self.less_than_constrain(outputs_var[i], outputs_var[i + 1], bit_size, predicate)?;
let less_than_next_element =
self.more_than_eq_var(outputs_var[i + 1], outputs_var[i], bit_size)?;
self.assert_eq_var(less_than_next_element, true_var, None)?;
}

Ok(outputs_var)
}

/// Constrain lhs to be less than rhs
fn less_than_constrain(
&mut self,
lhs: AcirVar,
rhs: AcirVar,
bit_size: u32,
predicate: AcirVar,
) -> Result<(), RuntimeError> {
let lhs_less_than_rhs = self.more_than_eq_var(rhs, lhs, bit_size)?;
self.maybe_eq_predicate(lhs_less_than_rhs, predicate)
}

/// Returns a Variable that is constrained to be the result of reading
/// from the memory `block_id` at the given `index`.
pub(crate) fn read_from_memory(
Expand Down
5 changes: 1 addition & 4 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,10 +1623,7 @@ impl Context {
}
}
// Generate the sorted output variables
let out_vars = self
.acir_context
.sort(input_vars, bit_size, self.current_side_effects_enabled_var)
.expect("Could not sort");
let out_vars = self.acir_context.sort(input_vars, bit_size)?;

Ok(self.convert_vars_to_values(out_vars, dfg, result_ids))
}
Expand Down
Loading