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: fix more issues with generics #8302

Merged
merged 2 commits into from
Aug 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use dep::types::{
address::AztecAddress, traits::{Empty, is_empty}, transaction::tx_request::TxRequest
};

fn validate_array_prepended<T, N>(dest: [T; N], source: [T; N], num_source_items: u32) where T: Eq {
fn validate_array_prepended<T, let N: u32>(
dest: [T; N],
source: [T; N],
num_source_items: u32
) where T: Eq {
let mut proceed = true;
for i in 0..source.len() {
proceed &= i != num_source_items;
Expand All @@ -19,7 +23,7 @@ fn validate_array_prepended<T, N>(dest: [T; N], source: [T; N], num_source_items
}
}

fn validate_array_appended<T, N, M>(
fn validate_array_appended<T, let N: u32, let M: u32>(
dest: [T; N],
source: [T; M],
num_source_items: u32,
Expand All @@ -43,7 +47,7 @@ fn validate_array_appended<T, N, M>(
}

// Similar to validate_array_appended, except that the contract address of the dest items will also be checked.
fn validate_array_appended_scoped<ST, T, N, M>(
fn validate_array_appended_scoped<ST, T, let N: u32, let M: u32>(
dest: [ST; N],
source: [T; M],
num_source_items: u32,
Expand Down Expand Up @@ -73,7 +77,7 @@ fn validate_array_appended_scoped<ST, T, N, M>(
}

// Similar to validate_array_appended, except that the souce items will be appended to dest in reversed order.
fn validate_array_appended_reversed<T, N, M>(
fn validate_array_appended_reversed<T, let N: u32, let M: u32>(
dest: [T; N],
source: [T; M],
num_source_items: u32,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::tests::private_call_data_validator_builder::PrivateCallDataValidatorBuilder;

fn unshift_empty_item<T, N>(vec: &mut BoundedVec<T, N>) {
fn unshift_empty_item<T, let N: u32>(vec: &mut BoundedVec<T, N>) {
let len = vec.len();
let empty_item = vec.storage[len];
let first_item = vec.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl LeafDataReadHint {
}
}

fn validate_pending_read_requests<READ_REQUEST_LEN, PENDING_VALUE_LEN, NUM_PENDING_READS>(
fn validate_pending_read_requests<let READ_REQUEST_LEN: u32, let PENDING_VALUE_LEN: u32, let NUM_PENDING_READS: u32>(
read_requests: [PublicDataRead; READ_REQUEST_LEN],
data_writes: [PublicDataUpdateRequest; PENDING_VALUE_LEN],
hints: [PendingReadHint; NUM_PENDING_READS]
Expand All @@ -40,7 +40,7 @@ fn validate_pending_read_requests<READ_REQUEST_LEN, PENDING_VALUE_LEN, NUM_PENDI
}
}

fn validate_leaf_data_read_requests<READ_REQUEST_LEN, NUM_LEAF_DATA_HINTS, H, NUM_LEAF_DATA_READS>(
fn validate_leaf_data_read_requests<let READ_REQUEST_LEN: u32, let NUM_LEAF_DATA_HINTS: u32, H, let NUM_LEAF_DATA_READS: u32>(
read_requests: [PublicDataRead; READ_REQUEST_LEN],
leaf_data_hints: [H; NUM_LEAF_DATA_HINTS],
hints: [LeafDataReadHint; NUM_LEAF_DATA_READS]
Expand All @@ -60,7 +60,7 @@ fn validate_leaf_data_read_requests<READ_REQUEST_LEN, NUM_LEAF_DATA_HINTS, H, NU
}
}

fn ensure_all_read_requests_are_verified<READ_REQUEST_LEN, NUM_PENDING_READS, NUM_LEAF_DATA_READS>(
fn ensure_all_read_requests_are_verified<let READ_REQUEST_LEN: u32, let NUM_PENDING_READS: u32, let NUM_LEAF_DATA_READS: u32>(
read_requests: [PublicDataRead; READ_REQUEST_LEN],
read_request_statuses: [ReadRequestStatus; READ_REQUEST_LEN],
pending_read_hints: [PendingReadHint; NUM_PENDING_READS],
Expand All @@ -85,7 +85,14 @@ fn ensure_all_read_requests_are_verified<READ_REQUEST_LEN, NUM_PENDING_READS, NU
}
}

pub fn reset_mutable_data_read_requests<READ_REQUEST_LEN, PENDING_VALUE_LEN, H, NUM_LEAF_DATA_HINTS, NUM_PENDING_READS, NUM_LEAF_DATA_READS>(
pub fn reset_mutable_data_read_requests<
let READ_REQUEST_LEN: u32,
let PENDING_VALUE_LEN: u32,
H,
let NUM_LEAF_DATA_HINTS: u32,
let NUM_PENDING_READS: u32,
let NUM_LEAF_DATA_READS: u32
>(
read_requests: [PublicDataRead; READ_REQUEST_LEN],
read_request_statuses: [ReadRequestStatus; READ_REQUEST_LEN],
data_writes: [PublicDataUpdateRequest; PENDING_VALUE_LEN],
Expand Down Expand Up @@ -150,7 +157,7 @@ mod tests {
TestLeafDataHint { leaf_slot: 5, value: 50 },
];

fn create_pending_read_requests<N>(data_write_indices: [u32; N]) -> ([PublicDataRead; N], [PendingReadHint; N]) {
fn create_pending_read_requests<let N: u32>(data_write_indices: [u32; N]) -> ([PublicDataRead; N], [PendingReadHint; N]) {
let read_requests = data_write_indices.map(
|data_write_index: u32| PublicDataRead { leaf_slot: data_writes[data_write_index].leaf_slot, value: data_writes[data_write_index].new_value }
);
Expand All @@ -161,7 +168,7 @@ mod tests {
(read_requests, hints.storage)
}

fn create_leaf_data_read_requests<N>(data_hint_indices: [u32; N]) -> ([PublicDataRead; N], [LeafDataReadHint; N]) {
fn create_leaf_data_read_requests<let N: u32>(data_hint_indices: [u32; N]) -> ([PublicDataRead; N], [LeafDataReadHint; N]) {
let read_requests = data_hint_indices.map(
|data_hint_index: u32| PublicDataRead { leaf_slot: leaf_data_hints[data_hint_index].leaf_slot, value: leaf_data_hints[data_hint_index].value }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use dep::types::{
traits::{Empty, is_empty}
};

trait NonMembershipHint<TREE_HEIGHT, LEAF_PREIMAGE> where LEAF_PREIMAGE: IndexedTreeLeafPreimage {
trait NonMembershipHint<let TREE_HEIGHT: u32, LEAF_PREIMAGE> where LEAF_PREIMAGE: IndexedTreeLeafPreimage {
fn low_leaf_preimage(self) -> LEAF_PREIMAGE;
fn membership_witness(self) -> MembershipWitness<TREE_HEIGHT>;
}

fn check_no_matching_pending_value<T, N>(
fn check_no_matching_pending_value<T, let N: u32>(
read_request: ScopedReadRequest,
sorted_pending_values: BoundedVec<T, N>,
next_value_index: u32
Expand All @@ -30,7 +30,7 @@ fn check_no_matching_pending_value<T, N>(
}
}

fn check_is_read_before_pending_value<T, N>(
fn check_is_read_before_pending_value<T, let N: u32>(
read_request: ScopedReadRequest,
sorted_pending_values: BoundedVec<T, N>,
next_value_index: u32
Expand All @@ -51,14 +51,14 @@ fn check_is_read_before_pending_value<T, N>(
// Unlike regular read requests, which can be reset at any time between two function executions.
// Non existent read requests can only be verified at the end, after all pending values are present.
// The values in read_requests and in sorted_pending_values should've been siloed before calling this.
pub fn reset_non_existent_read_requests<T, N, M, NON_MEMBERSHIP_HINT, TREE_HEIGHT, LEAF_PREIMAGE>(
pub fn reset_non_existent_read_requests<T, let N: u32, let M: u32, NON_MEMBERSHIP_HINT, let TREE_HEIGHT: u32, LEAF_PREIMAGE>(
siloed_read_requests: [ScopedReadRequest; N],
non_membership_hints: [NON_MEMBERSHIP_HINT; N],
tree_root: Field,
sorted_pending_values: BoundedVec<T, M>,
next_pending_value_indices: [u32; N]
) where
T: OrderedValue<Field>,
) where
T: OrderedValue<Field>,
NON_MEMBERSHIP_HINT: NonMembershipHint<TREE_HEIGHT, LEAF_PREIMAGE>,
LEAF_PREIMAGE: IndexedTreeLeafPreimage {
for i in 0..siloed_read_requests.len() {
Expand Down Expand Up @@ -176,7 +176,7 @@ mod tests {
)
}

fn get_non_membership_hints<N>(leaf_indices: [Field; N]) -> ([TestNonMembershipHint; N], Field) {
fn get_non_membership_hints<let N: u32>(leaf_indices: [Field; N]) -> ([TestNonMembershipHint; N], Field) {
let tree = build_tree();
let hints = leaf_indices.map(
|leaf_index| TestNonMembershipHint {
Expand Down
Loading