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: reuse witnesses more when interacting with memory #3658

Merged
merged 2 commits into from
Dec 1, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,8 @@ impl AcirContext {
/// Converts the `AcirVar` to a `Witness` if it hasn't been already, and appends it to the
/// `GeneratedAcir`'s return witnesses.
pub(crate) fn return_var(&mut self, acir_var: AcirVar) -> Result<(), InternalError> {
let witness = self.var_to_witness(acir_var)?;
let return_var = self.get_or_create_witness_var(acir_var)?;
let witness = self.var_to_witness(return_var)?;
self.acir_ir.push_return_witness(witness);
Ok(())
}
Expand Down Expand Up @@ -1425,7 +1426,8 @@ impl AcirContext {
index: &AcirVar,
) -> Result<AcirVar, InternalError> {
// Fetch the witness corresponding to the index
let index_witness = self.var_to_witness(*index)?;
let index_var = self.get_or_create_witness_var(*index)?;
let index_witness = self.var_to_witness(index_var)?;
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved

// Create a Variable to hold the result of the read and extract the corresponding Witness
let value_read_var = self.add_variable();
Expand All @@ -1446,11 +1448,12 @@ impl AcirContext {
value: &AcirVar,
) -> Result<(), InternalError> {
// Fetch the witness corresponding to the index
//
let index_witness = self.var_to_witness(*index)?;
let index_var = self.get_or_create_witness_var(*index)?;
let index_witness = self.var_to_witness(index_var)?;

// Fetch the witness corresponding to the value to be written
let value_write_witness = self.var_to_witness(*value)?;
let value_write_var = self.get_or_create_witness_var(*value)?;
let value_write_witness = self.var_to_witness(value_write_var)?;

// Add the memory write operation to the list of opcodes
let op = MemOp::write_to_mem_index(index_witness.into(), value_write_witness.into());
Expand Down Expand Up @@ -1492,6 +1495,7 @@ impl AcirContext {
) -> Result<(), InternalError> {
match input {
AcirValue::Var(var, _) => {
let var = self.get_or_create_witness_var(var)?;
witnesses.push(self.var_to_witness(var)?);
}
AcirValue::Array(values) => {
Expand Down
Loading