Skip to content

Commit

Permalink
chore: Revert "feat: Only create new witnesses for distinctiveness wh…
Browse files Browse the repository at this point in the history
…en duplicates exist" (#2209)

Revert "feat: Only create new witnesses for distinctiveness when duplicates exist (#2191)"

This reverts commit 14cbdbc.
  • Loading branch information
kevaundray authored Aug 8, 2023
1 parent a72cc96 commit 5b95ab5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Example that uses the distinct keyword
fn main(x: pub Field) -> distinct pub [Field; 3] {
[x+1, x, x]
fn main(x: pub Field) -> distinct pub [Field;2] {
[x+1, x]
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"public"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"array","length":3,"type":{"kind":"field"}},"return_witnesses":[2,1,3]},"bytecode":"H4sIAAAAAAAA/9VPOQ7AIAzj6IMSkkCy9StFhf8/oQtISB3LUi8+Bss+nHPBvTGzczB8A/qliyAzt5IaEl6QrKoAS82KiqJyJyVqylqsWgFDpoZdjPooCxt3/eVz3LcL5l+/cFx0GP4Bi8kGuhwCAAA=","proving_key":null,"verification_key":null}
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"public"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"array","length":2,"type":{"kind":"field"}},"return_witnesses":[3,4]},"bytecode":"H4sIAAAAAAAA/9WRQQ6AIAwEEfU/LW2lvfkVifj/JxgSTEg8Cgf3srftTnd1zs3uLV99rw7fhFOTRbAx5xgyEh4QLKkAS9oUFUXlDEqUlTVasgiGTBkvMbpqmO/YaySz78g89+sFf9l5GcA8Nf6wl9+WWzcyyYCuDAMAAA==","proving_key":null,"verification_key":null}
Binary file not shown.
32 changes: 13 additions & 19 deletions crates/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ use crate::brillig::{brillig_gen::brillig_fn::FunctionContext as BrilligFunction
use crate::errors::{InternalError, RuntimeError};
pub(crate) use acir_ir::generated_acir::GeneratedAcir;
use acvm::{
acir::{
brillig::Opcode,
circuit::opcodes::BlockId,
native_types::{Expression, Witness},
},
acir::{brillig::Opcode, circuit::opcodes::BlockId, native_types::Expression},
FieldElement,
};
use iter_extended::{try_vecmap, vecmap};
Expand Down Expand Up @@ -123,19 +119,17 @@ impl Ssa {

match abi_distinctness {
AbiDistinctness::Distinct => {
let mut distinct_return_witness: Vec<Witness> =
Vec::with_capacity(generated_acir.return_witnesses.len());

for mut return_witness in generated_acir.return_witnesses.clone() {
// If witness has already been used then create a new one
// to guarantee that the return witnesses are distinct
if distinct_return_witness.contains(&return_witness) {
return_witness = generated_acir
.create_witness_for_expression(&Expression::from(return_witness));
}

distinct_return_witness.push(return_witness);
}
// Create a witness for each return witness we have
// to guarantee that the return witnesses are distinct
let distinct_return_witness: Vec<_> = generated_acir
.return_witnesses
.clone()
.into_iter()
.map(|return_witness| {
generated_acir
.create_witness_for_expression(&Expression::from(return_witness))
})
.collect();

generated_acir.return_witnesses = distinct_return_witness;
Ok(generated_acir)
Expand Down Expand Up @@ -1127,7 +1121,7 @@ impl Context {

#[cfg(test)]
mod tests {
use std::{collections::HashMap, rc::Rc};
use std::{rc::Rc, collections::HashMap};

use acvm::{
acir::{
Expand Down

0 comments on commit 5b95ab5

Please sign in to comment.