Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ use dep::aztec::{
},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

// docs:start:address_note_def
// docs:start:address_note_struct
// Stores an address
Expand Down
14 changes: 11 additions & 3 deletions noir-projects/aztec-nr/aztec/src/macros/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,17 @@ pub(crate) comptime fn is_note(typ: Type) -> bool {
})
}

/// Returns the typed expression of a trait method implementation. This is preferred over directly inlining with
/// `$typ::target_method()` in a quote, as direct inlining would result in missing import warnings in the generated
/// code (specifically, warnings that the trait implementation is not in scope).
/// Returns the typed expression of a trait method implementation.
///
/// This helper function is preferred over directly inlining with `$typ::target_method()` in a quote,
/// as direct inlining would result in missing import warnings in the generated code (specifically,
/// warnings that the trait implementation is not in scope).
///
/// # Note
/// A copy of this function exists in `noir-protocol-circuits/crates/types/src/meta/mod.nr`. We maintain separate
/// copies because importing it here from there would cause the `target_trait` to be interpreted in the context
/// of the protocol circuits types crate, making it impossible to compile code for traits from this crate
/// (e.g. NoteInterface).
pub(crate) comptime fn get_trait_impl_method(
typ: Type,
target_trait: Quoted,
Expand Down
3 changes: 0 additions & 3 deletions noir-projects/aztec-nr/uint-note/src/uint_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use dep::aztec::{
},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

// docs:start:UintNote
#[partial_note(quote {value})]
#[derive(Eq, Serialize)]
Expand Down
3 changes: 0 additions & 3 deletions noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ use dep::aztec::{
},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

pub(crate) global VALUE_NOTE_LEN: u32 = 3; // 3 plus a header.

// docs:start:value-note-def
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ use dep::aztec::{
protocol_types::{address::AztecAddress, constants::GENERATOR_INDEX__NOTE_NULLIFIER},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

#[note]
pub struct SubscriptionNote {
owner: AztecAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use dep::aztec::{
},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

// docs:start:state_vars-CardNote
global CARD_NOTE_LEN: u32 = 3; // 3 plus a header.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use dep::aztec::{
},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

// docs:start:nft_note
#[partial_note(quote { token_id})]
#[derive(Eq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use aztec::{
},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

// Stores a public key composed of two fields
// TODO: Do we need to include a nonce, in case we want to read/nullify/recreate with the same pubkey value?
#[note]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use dep::aztec::{
},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

trait OwnedNote {
fn new(amount: U128, owner: AztecAddress) -> Self;
fn get_amount(self) -> U128;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use dep::aztec::{
},
};

// TODO(#12008): Remove the need for the manual import of `Packable` trait here. This is a bug in macros.
use aztec::protocol_types::traits::Packable;

trait OwnedNote {
fn new(amount: U128, owner: AztecAddress) -> Self;
fn get_amount(self) -> U128;
Expand Down
26 changes: 24 additions & 2 deletions noir-projects/noir-protocol-circuits/crates/types/src/meta/mod.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
use super::traits::{Deserialize, Packable, Serialize};

/// Returns the typed expression of a trait method implementation.
///
/// This helper function is preferred over directly inlining with `$typ::target_method()` in a quote,
/// as direct inlining would result in missing import warnings in the generated code (specifically,
/// warnings that the trait implementation is not in scope).
///
/// # Note
/// A copy of this function exists in `aztec-nr/aztec/src/macros/utils.nr`. We maintain separate copies
/// because importing it there from here would cause the `target_trait` to be interpreted in the context
/// of this crate, making it impossible to compile code for traits from that crate (e.g. NoteInterface).
comptime fn get_trait_impl_method(
typ: Type,
target_trait: Quoted,
target_method: Quoted,
) -> TypedExpr {
let trait_constraint = target_trait.as_trait_constraint();
typ.get_trait_impl(trait_constraint).unwrap().methods().filter(|m| m.name() == target_method)[0]
.as_typed_expr()
}

/// Generates code that deserializes a struct, primitive type, array or string from a field array.
///
/// # Parameters
Expand Down Expand Up @@ -91,7 +111,8 @@ pub comptime fn generate_deserialize_from_fields(
let packed_fields = packed_fields_quotes.join(quote {,});

// Now we call unpack on the type
result = quote { Packable::unpack([ $packed_fields ]) };
let unpack_method = get_trait_impl_method(typ, quote { Packable<_> }, quote { unpack });
result = quote { $unpack_method([ $packed_fields ]) };

consumed_counter = packed_len;
} else if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {
Expand Down Expand Up @@ -476,9 +497,10 @@ pub comptime fn derive_packable_and_get_packed_len(s: StructDefinition) -> (Quot

let field_packings = fields.join(quote {,});
let packed_len = fields.len();
let packable_trait: TraitConstraint = quote { Packable<$packed_len> }.as_trait_constraint();
(
quote {
impl Packable<$packed_len> for $typ {
impl $packable_trait for $typ {
fn pack(self) -> [Field; $packed_len] {
$aux_vars_for_packing
[ $field_packings ]
Expand Down