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: fix compilation using aztec feature flag #2663

Merged
merged 1 commit into from
Sep 12, 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
33 changes: 18 additions & 15 deletions compiler/noirc_frontend/src/hir/def_map/aztec_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
use noirc_errors::{CustomDiagnostic, Span};

use crate::graph::CrateId;
use crate::token::SecondaryAttribute;
use crate::{
hir::Context, token::Attribute, BlockExpression, CallExpression, CastExpression, Distinctness,
Expression, ExpressionKind, ForExpression, FunctionReturnType, Ident, ImportStatement,
IndexExpression, LetStatement, Literal, MemberAccessExpression, MethodCallExpression,
NoirFunction, ParsedModule, Path, PathKind, Pattern, Statement, UnresolvedType,
UnresolvedTypeData, Visibility,
hir::Context, BlockExpression, CallExpression, CastExpression, Distinctness, Expression,
ExpressionKind, ForExpression, FunctionReturnType, Ident, ImportStatement, IndexExpression,
LetStatement, Literal, MemberAccessExpression, MethodCallExpression, NoirFunction,
ParsedModule, Path, PathKind, Pattern, Statement, UnresolvedType, UnresolvedTypeData,
Visibility,
};
use noirc_errors::FileDiagnostic;

Expand Down Expand Up @@ -188,17 +189,19 @@
fn transform_module(functions: &mut [NoirFunction]) -> bool {
let mut has_annotated_functions = false;
for func in functions.iter_mut() {
if let Some(Attribute::Custom(custom_attribute)) = func.def.attribute.as_ref() {
match custom_attribute.as_str() {
"aztec(private)" => {
transform_function("Private", func);
has_annotated_functions = true;
for secondary_attribute in func.def.attributes.secondary.clone() {
if let SecondaryAttribute::Custom(custom_attribute) = secondary_attribute {
match custom_attribute.as_str() {
"aztec(private)" => {
transform_function("Private", func);
has_annotated_functions = true;
}
"aztec(public)" => {
transform_function("Public", func);
has_annotated_functions = true;
}
_ => continue,
}
"aztec(public)" => {
transform_function("Public", func);
has_annotated_functions = true;
}
_ => continue,
}
}
}
Expand Down Expand Up @@ -318,7 +321,7 @@
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),
Expand Down Expand Up @@ -388,7 +391,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 394 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 @@ -399,7 +402,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 405 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 @@ -440,12 +443,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 446 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 451 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 @@ -468,13 +471,13 @@
create_loop_over(expression.clone(), vec![assignment])
}

/// Castable return type

Check warning on line 474 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 480 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 @@ -542,7 +545,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 548 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 @@ -551,7 +554,7 @@
Statement::Semi(method_call(
variable("hasher"), // variable
"add_multiple", // method name
vec![serialised_call], // args

Check warning on line 557 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 @@ -602,7 +605,7 @@

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

Check warning on line 608 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 Down