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

fix(aztec_noir): support bools as input types #2674

Merged
merged 1 commit into from
Sep 13, 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
6 changes: 4 additions & 2 deletions compiler/noirc_frontend/src/hir/def_map/aztec_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,15 @@
let expression = match unresolved_type {
// `hasher.add_multiple({ident}.serialize())`
UnresolvedTypeData::Named(..) => add_struct_to_hasher(identifier),
// TODO: if this is an array of structs, we should call serialise on each of them (no methods currently do this yet)

Check warning on line 324 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (serialise)
UnresolvedTypeData::Array(..) => add_array_to_hasher(identifier),
// `hasher.add({ident})`
UnresolvedTypeData::FieldElement => add_field_to_hasher(identifier),
// Add the integer to the hasher, casted to a field
// `hasher.add({ident} as Field)`
UnresolvedTypeData::Integer(..) => add_int_to_hasher(identifier),
UnresolvedTypeData::Integer(..) | UnresolvedTypeData::Bool => {
add_cast_to_hasher(identifier)
}
_ => unreachable!("[Aztec Noir] Provided parameter type is not supported"),
};
injected_expressions.push(expression);
Expand Down Expand Up @@ -391,7 +393,7 @@
let last_statement = &func.def.body.0[len - 1];

// TODO: (length, type) => We can limit the size of the array returned to be limited by kernel size
// Doesnt need done until we have settled on a kernel size

Check warning on line 396 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (Doesnt)
// TODO: support tuples here and in inputs -> convert into an issue

// Check if the return type is an expression, if it is, we can handle it
Expand All @@ -402,7 +404,7 @@
UnresolvedTypeData::Array(..) => Some(make_array_return_type(expression.clone())),
// Cast these types to a field before pushing
UnresolvedTypeData::Bool | UnresolvedTypeData::Integer(..) => {
Some(make_castable_return_type(expression.clone()))

Check warning on line 407 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (castable)
}
UnresolvedTypeData::FieldElement => Some(make_return_push(expression.clone())),
_ => None,
Expand Down Expand Up @@ -443,12 +445,12 @@
/// ```noir
/// `context.return_values.push_array({push_value}.serialize())`
fn make_struct_return_type(expression: Expression) -> Statement {
let serialised_call = method_call(

Check warning on line 448 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (serialised)
expression.clone(), // variable
"serialize", // method name
vec![], // args
);
make_return_push_array(serialised_call)

Check warning on line 453 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (serialised)
}

/// Make array return type
Expand All @@ -471,13 +473,13 @@
create_loop_over(expression.clone(), vec![assignment])
}

/// Castable return type

Check warning on line 476 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (Castable)
///
/// Translates to:
/// ```noir
/// context.return_values.push({ident} as Field)
/// ```
fn make_castable_return_type(expression: Expression) -> Statement {

Check warning on line 482 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (castable)
// Cast these types to a field before pushing
let cast_expression = cast(expression.clone(), UnresolvedTypeData::FieldElement);
make_return_push(cast_expression)
Expand Down Expand Up @@ -545,7 +547,7 @@

fn add_struct_to_hasher(identifier: &Ident) -> Statement {
// If this is a struct, we call serialize and add the array to the hasher
let serialised_call = method_call(

Check warning on line 550 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (serialised)
variable_path(path(identifier.clone())), // variable
"serialize", // method name
vec![], // args
Expand All @@ -554,7 +556,7 @@
Statement::Semi(method_call(
variable("hasher"), // variable
"add_multiple", // method name
vec![serialised_call], // args

Check warning on line 559 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (serialised)
))
}

Expand Down Expand Up @@ -605,7 +607,7 @@

fn add_field_to_hasher(identifier: &Ident) -> Statement {
// `hasher.add({ident})`
let iden = variable_path(path(identifier.clone()));

Check warning on line 610 in compiler/noirc_frontend/src/hir/def_map/aztec_library.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (iden)
Statement::Semi(method_call(
variable("hasher"), // variable
"add", // method name
Expand All @@ -613,7 +615,7 @@
))
}

fn add_int_to_hasher(identifier: &Ident) -> Statement {
fn add_cast_to_hasher(identifier: &Ident) -> Statement {
// `hasher.add({ident} as Field)`
// `{ident} as Field`
let cast_operation = cast(
Expand Down