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
11 changes: 9 additions & 2 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2511,7 +2511,7 @@ pub fn perform_impl_bindings(
}

pub fn resolve_trait_method(
interner: &NodeInterner,
interner: &mut NodeInterner,
method: TraitMethodId,
expr_id: ExprId,
) -> Result<node_interner::FuncId, InterpreterError> {
Expand All @@ -2531,7 +2531,14 @@ pub fn resolve_trait_method(
&trait_generics.ordered,
&trait_generics.named,
) {
Ok((TraitImplKind::Normal(impl_id), _instantiation_bindings)) => impl_id,
Ok((TraitImplKind::Normal(impl_id), instantiation_bindings)) => {
// Insert any additional instantiation bindings into this expression's instantiation bindings.
// This is similar to what's done in `verify_trait_constraint` in the frontend.
let mut bindings = interner.get_instantiation_bindings(expr_id).clone();
bindings.extend(instantiation_bindings);
interner.store_instantiation_bindings(expr_id, bindings);
impl_id
}
Ok((TraitImplKind::Assumed { .. }, _instantiation_bindings)) => {
return Err(InterpreterError::NoImpl { location });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "serialize"
name = "serialize_1"
type = "bin"
authors = [""]
compiler_version = ">=0.32.0"
Expand Down
64 changes: 64 additions & 0 deletions test_programs/compile_success_empty/serialize_1/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
trait Serialize {
let Size: u32;

// Note that Rust disallows referencing constants here!
fn serialize(self) -> [Field; Self::Size];
}

impl<A, B> Serialize for (A, B)
where
A: Serialize,
B: Serialize,
{
let Size = <A as Serialize>::Size + <B as Serialize>::Size;

fn serialize(self: Self) -> [Field; Self::Size] {
let mut array: [Field; Self::Size] = std::mem::zeroed();
let a = self.0.serialize();
let b = self.1.serialize();

for i in 0..a.len() {
array[i] = a[i];
}
for i in 0..b.len() {
array[i + a.len()] = b[i];
}
array
}
}

impl<T, let N: u32> Serialize for [T; N]
where
T: Serialize,
{
let Size = <T as Serialize>::Size * N;

fn serialize(self: Self) -> [Field; Self::Size] {
let mut array: [Field; Self::Size] = std::mem::zeroed();
let mut array_i = 0;

for elem in self {
let elem_fields = elem.serialize();

for i in 0..elem_fields.len() {
array[array_i] = elem_fields[i];
array_i += 1;
}
}

array
}
}

impl Serialize for Field {
let Size: u32 = 1;

fn serialize(self) -> [Field; Self::Size] {
[self]
}
}

fn main() {
let x = (((1, [2, 3, 4]), [5, 6, 7, 8]), 9);
assert_eq(x.serialize().len(), 9);
}
7 changes: 7 additions & 0 deletions test_programs/compile_success_empty/serialize_2/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "serialize_2"
type = "bin"
authors = [""]
compiler_version = ">=0.32.0"

[dependencies]
27 changes: 27 additions & 0 deletions test_programs/compile_success_empty/serialize_2/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
trait Serialize {
let Size: u32;

fn serialize(self);
}

impl Serialize for Field {
let Size: u32 = 1;

fn serialize(self) {}
}

impl<A> Serialize for (A,)
where
A: Serialize,
{
let Size = <A as Serialize>::Size;

fn serialize(self: Self) {
self.0.serialize();
}
}

fn main() {
let x = ((1,),);
x.serialize();
}
7 changes: 7 additions & 0 deletions test_programs/compile_success_empty/serialize_3/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "serialize_3"
type = "bin"
authors = [""]
compiler_version = ">=0.32.0"

[dependencies]
42 changes: 42 additions & 0 deletions test_programs/compile_success_empty/serialize_3/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
trait Serialize {
let Size: u32;

fn serialize(self) -> [Field; Self::Size];
}

impl<A, B> Serialize for (A, B)
where
A: Serialize,
B: Serialize,
{
let Size = <A as Serialize>::Size + <B as Serialize>::Size;

fn serialize(self: Self) -> [Field; Self::Size] {
let _ = self.0.serialize();
[0; Self::Size]
}
}

impl<T, let N: u32> Serialize for [T; N]
where
T: Serialize,
{
let Size = <T as Serialize>::Size * N;

fn serialize(self: Self) -> [Field; Self::Size] {
[0; Self::Size]
}
}

impl Serialize for Field {
let Size: u32 = 1;

fn serialize(self) -> [Field; Self::Size] {
[self]
}
}

fn main() {
let x = (((1, [2, 3, 4]), [5, 6, 7, 8]), 9);
assert_eq(x.serialize().len(), 9);
}
7 changes: 7 additions & 0 deletions test_programs/compile_success_empty/serialize_4/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "serialize_4"
type = "bin"
authors = [""]
compiler_version = ">=0.32.0"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ impl Serialize for Field {
}

fn main() {
let x = ((1, [2, 3, 4]), [5, 6, 7, 8]);
assert_eq(x.serialize().len(), 8);
let x = (1, [2, 3, 4]);
assert_eq(x.serialize().len(), 4);
}
10 changes: 8 additions & 2 deletions tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
// There's no "src/main.nr" here so it's trickier to make this work
"overlapping_dep_and_mod",
// bug
"poseidonsponge_x5_254",

Check warning on line 131 in tooling/nargo_cli/build.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (poseidonsponge)
// bug
"regression_5045",
// bug
Expand All @@ -145,7 +145,7 @@
/// These tests are ignored because of existing bugs in `nargo expand`.
/// As the bugs are fixed these tests should be removed from this list.
/// (some are ignored on purpose for the same reason as `IGNORED_NARGO_EXPAND_EXECUTION_TESTS`)
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 17] = [
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 20] = [
// bug
"associated_type_bounds",
// bug
Expand All @@ -163,7 +163,13 @@
// bug
"regression_7038_4",
// bug
"serialize",
"serialize_1",
// bug
"serialize_2",
// bug
"serialize_3",
// bug
"serialize_4",
// bug
"trait_allowed_item_name_matches",
// bug
Expand Down Expand Up @@ -681,7 +687,7 @@
writeln!(test_file, "}}").unwrap();
}

/// Here we check, for every program in `test_programs/exeuction_success`, that:

Check warning on line 690 in tooling/nargo_cli/build.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (exeuction)
/// 1. `nargo expand` works on it
/// 2. That the output of the original program is the same as the output of the expanded program
/// (that is, we run `nargo execute` on the original program and the expanded program and compare the output)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading