Skip to content

Commit

Permalink
feat: do not return databus returndata, keep it private. (#5023)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Related to  #4974

## Summary\*
Very small PR which avoids returning databus objects, because they need
to be handled as private inputs.
This is incremental work, so it cannot be tested yet. The PR only impact
databus use case.



## Additional Context



## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [ ] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
guipublic authored May 14, 2024
1 parent e5ab24d commit a5b7df1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 17 additions & 4 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,13 +1729,16 @@ impl<'a> Context<'a> {
// will expand the array if there is one.
let return_acir_vars = self.flatten_value_list(return_values, dfg)?;
let mut warnings = Vec::new();
for acir_var in return_acir_vars {
for (acir_var, is_databus) in return_acir_vars {
if self.acir_context.is_constant(&acir_var) {
warnings.push(SsaReport::Warning(InternalWarning::ReturnConstant {
call_stack: call_stack.clone(),
}));
}
self.acir_context.return_var(acir_var)?;
if !is_databus {
// We do not return value for the data bus.
self.acir_context.return_var(acir_var)?;
}
}
Ok(warnings)
}
Expand Down Expand Up @@ -2659,12 +2662,22 @@ impl<'a> Context<'a> {
&mut self,
arguments: &[ValueId],
dfg: &DataFlowGraph,
) -> Result<Vec<AcirVar>, InternalError> {
) -> Result<Vec<(AcirVar, bool)>, InternalError> {
let mut acir_vars = Vec::with_capacity(arguments.len());
for value_id in arguments {
let is_databus = if let Some(return_databus) = self.data_bus.return_data {
dfg[*value_id] == dfg[return_databus]
} else {
false
};
let value = self.convert_value(*value_id, dfg);
acir_vars.append(
&mut self.acir_context.flatten(value)?.iter().map(|(var, _)| *var).collect(),
&mut self
.acir_context
.flatten(value)?
.iter()
.map(|(var, _)| (*var, is_databus))
.collect(),
);
}
Ok(acir_vars)
Expand Down
10 changes: 9 additions & 1 deletion tooling/noirc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,15 @@ impl Abi {
.copied()
})
{
Some(decode_value(&mut return_witness_values.into_iter(), &return_type.abi_type)?)
// We do not return value for the data bus.
if return_type.visibility == AbiVisibility::DataBus {
None
} else {
Some(decode_value(
&mut return_witness_values.into_iter(),
&return_type.abi_type,
)?)
}
} else {
// Unlike for the circuit inputs, we tolerate not being able to find the witness values for the return value.
// This is because the user may be decoding a partial witness map for which is hasn't been calculated yet.
Expand Down

0 comments on commit a5b7df1

Please sign in to comment.