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

chore(ssa refactor): Switch to immutable arrays #1578

Merged
merged 26 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b7ff73b
Represent SSA arrays with im::Vector
jfecher Jun 2, 2023
31dd36f
Get tests passing
jfecher Jun 2, 2023
5d4be5c
Implement assign with immutable arrays
jfecher Jun 6, 2023
584f972
Add constant folding pass
jfecher Jun 6, 2023
399b708
Update comments
jfecher Jun 6, 2023
fccb3e8
Merge branch 'jf/constant-folding' into jf/ssa-im-vector
jfecher Jun 6, 2023
3e80698
Clippy
jfecher Jun 6, 2023
e6be421
Update comment
jfecher Jun 6, 2023
fc296ab
Update type of array
jfecher Jun 6, 2023
9107005
Update crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs
jfecher Jun 7, 2023
3aaa978
Undo formatting changes in instruction.rs
jfecher Jun 7, 2023
bfc4fe2
Merge branch 'master' into jf/ssa-im-vector
jfecher Jun 7, 2023
65f5b0c
Massive acir_gen update
jfecher Jun 7, 2023
d48bf2b
Merge branch 'master' into jf/ssa-im-vector
jfecher Jun 7, 2023
1116881
Refactor acir array operations into a shared function
jfecher Jun 7, 2023
d94444c
Appease clippy
jfecher Jun 7, 2023
e6c3cd0
Update to_radix and to_bits in acir_gen to return arrays
jfecher Jun 7, 2023
faa991c
Disable assert
jfecher Jun 8, 2023
9c28a16
Merge branch 'master' into jf/ssa-im-vector
jfecher Jun 8, 2023
5e7c1dd
Fix convert_type for arrays
jfecher Jun 8, 2023
81f1e05
Include AcirType in AcirValue::Var variant
jfecher Jun 8, 2023
0d26c7a
Merge branch 'master' into jf/ssa-im-vector
jfecher Jun 8, 2023
1478a35
Fix black box functions
jfecher Jun 8, 2023
70137b8
Appease clippy
jfecher Jun 8, 2023
4715851
Fix simple_radix
jfecher Jun 8, 2023
9b0748e
Add doc comments
jfecher Jun 8, 2023
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
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) struct ProveCommand {
verifier_name: String,

/// Verify proof after proving
#[arg(short, long)]
#[arg(long)]
verify: bool,

#[clap(flatten)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,8 @@ impl AcirContext {
let constants = match name {
BlackBoxFunc::Pedersen => {
// The last argument of pedersen is the domain separator, which must be a constant
let domain_var = inputs
.pop()
.expect("ICE: Pedersen call requires domain separator")
.into_var();
let domain_var =
inputs.pop().expect("ICE: Pedersen call requires domain separator").into_var();

let domain_constant = self.vars[domain_var]
.as_constant()
Expand All @@ -579,9 +577,7 @@ impl AcirContext {
//
// We do not apply range information on the output of the black box function.
// See issue #1439
Ok(vecmap(&outputs, |witness_index| {
self.add_data(AcirVarData::Witness(*witness_index))
}))
Ok(vecmap(&outputs, |witness_index| self.add_data(AcirVarData::Witness(*witness_index))))
}

/// Black box function calls expect their inputs to be in a specific data structure (FunctionInput).
Expand Down Expand Up @@ -635,11 +631,10 @@ impl AcirContext {

let limbs = self.acir_ir.radix_le_decompose(input_expr, radix, limb_count)?;

let mut limb_vars =
vecmap(limbs, |witness| {
let witness = self.add_data(AcirVarData::Witness(witness));
AcirValue::Var(witness, result_element_type)
});
let mut limb_vars = vecmap(limbs, |witness| {
let witness = self.add_data(AcirVarData::Witness(witness));
AcirValue::Var(witness, result_element_type)
});

if endian == Endian::Big {
limb_vars.reverse();
Expand Down
49 changes: 45 additions & 4 deletions crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,18 @@ impl Context {
arguments: &[ValueId],
dfg: &DataFlowGraph,
allow_log_ops: bool,
result_ids: &[ValueId]
result_ids: &[ValueId],
) -> Vec<AcirValue> {
match intrinsic {
Intrinsic::BlackBox(black_box) => {
let inputs = vecmap(arguments, |arg| self.convert_value(*arg, dfg));

let vars = self.acir_context
let vars = self
.acir_context
.black_box_function(black_box, inputs)
.expect("add Result types to all methods so errors bubble up");

self.convert_vars_to_values(vars, dfg, result_ids)
Self::convert_vars_to_values(vars, dfg, result_ids)
}
Intrinsic::ToRadix(endian) => {
let field = self.convert_value(arguments[0], dfg).into_var();
Expand Down Expand Up @@ -550,8 +551,48 @@ impl Context {
}
}

fn convert_vars_to_values(&self, vars: Vec<AcirVar>, dfg: &DataFlowGraph, result_ids: &[ValueId]) -> Vec<AcirValue> {
/// Convert a Vec<AcirVar> into a Vec<AcirValue> using the given result ids.
/// If the type of a result id is an array, several acirvars are collected into
/// a single AcirValue::Array of the same length.
fn convert_vars_to_values(
vars: Vec<AcirVar>,
dfg: &DataFlowGraph,
result_ids: &[ValueId],
) -> Vec<AcirValue> {
let mut values = vec![];
let mut vars = vars.into_iter();

for result in result_ids {
Self::convert_var_type_to_values(
dfg,
&dfg.type_of_value(*result),
&mut values,
&mut vars,
);
}

values
}

fn convert_var_type_to_values(
dfg: &DataFlowGraph,
result_type: &Type,
values: &mut Vec<AcirValue>,
vars: &mut impl Iterator<Item = AcirVar>,
) {
match result_type {
Type::Array(elements, size) => {
for _ in 0..*size {
for element_type in elements.iter() {
Self::convert_var_type_to_values(dfg, element_type, values, vars);
}
}
}
typ => {
let var = vars.next().unwrap();
values.push(AcirValue::Var(var, typ.into()));
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_evaluator/src/ssa_refactor/ir/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ impl Type {
Type::unsigned(1)
}

/// Creates the char type, represented as just a field to avoid extra range constraints.
/// Creates the char type, represented as u8.
pub(crate) fn char() -> Type {
Type::field()
Type::unsigned(8)
}

/// Creates the native field type.
Expand Down