diff --git a/examples/fixture/asm/kimchi/generic_nested_func.asm b/examples/fixture/asm/kimchi/generic_nested_func.asm new file mode 100644 index 000000000..ea83d5c55 --- /dev/null +++ b/examples/fixture/asm/kimchi/generic_nested_func.asm @@ -0,0 +1,13 @@ +@ noname.0.7.0 + +DoubleGeneric<1> +DoubleGeneric<1> +DoubleGeneric<1> +DoubleGeneric<1> +DoubleGeneric<1,-1> +DoubleGeneric<1,-1> +DoubleGeneric<1,-1> +(0,0) -> (4,0) +(1,0) -> (5,0) +(2,0) -> (6,0) +(3,0) -> (4,1) -> (5,1) -> (6,1) diff --git a/examples/fixture/asm/kimchi/generic_nested_method.asm b/examples/fixture/asm/kimchi/generic_nested_method.asm new file mode 100644 index 000000000..ea83d5c55 --- /dev/null +++ b/examples/fixture/asm/kimchi/generic_nested_method.asm @@ -0,0 +1,13 @@ +@ noname.0.7.0 + +DoubleGeneric<1> +DoubleGeneric<1> +DoubleGeneric<1> +DoubleGeneric<1> +DoubleGeneric<1,-1> +DoubleGeneric<1,-1> +DoubleGeneric<1,-1> +(0,0) -> (4,0) +(1,0) -> (5,0) +(2,0) -> (6,0) +(3,0) -> (4,1) -> (5,1) -> (6,1) diff --git a/examples/fixture/asm/r1cs/generic_nested_func.asm b/examples/fixture/asm/r1cs/generic_nested_func.asm new file mode 100644 index 000000000..4d0e4621a --- /dev/null +++ b/examples/fixture/asm/r1cs/generic_nested_func.asm @@ -0,0 +1,5 @@ +@ noname.0.7.0 + +v_4 == (v_1) * (1) +v_4 == (v_2) * (1) +v_4 == (v_3) * (1) diff --git a/examples/fixture/asm/r1cs/generic_nested_method.asm b/examples/fixture/asm/r1cs/generic_nested_method.asm new file mode 100644 index 000000000..4d0e4621a --- /dev/null +++ b/examples/fixture/asm/r1cs/generic_nested_method.asm @@ -0,0 +1,5 @@ +@ noname.0.7.0 + +v_4 == (v_1) * (1) +v_4 == (v_2) * (1) +v_4 == (v_3) * (1) diff --git a/examples/generic_nested_func.no b/examples/generic_nested_func.no new file mode 100644 index 000000000..e12a84430 --- /dev/null +++ b/examples/generic_nested_func.no @@ -0,0 +1,17 @@ +fn nested_func(const LEN: Field) -> [Field; LEN] { + return [0; LEN]; +} + +fn mod_arr(val: Field) -> [Field; 3] { + // this generic function should be instantiated + let mut result = nested_func(3); + for idx in 0..3 { + result[idx] = val; + } + return result; +} + +fn main(pub val: Field) -> [Field; 3] { + let result = mod_arr(val); + return result; +} \ No newline at end of file diff --git a/examples/generic_nested_method.no b/examples/generic_nested_method.no new file mode 100644 index 000000000..b5d087b63 --- /dev/null +++ b/examples/generic_nested_method.no @@ -0,0 +1,21 @@ +struct Thing { + xx: Field, +} + +fn Thing.nested_func(const LEN: Field) -> [Field; LEN] { + return [0; LEN]; +} + +fn Thing.mod_arr(self) -> [Field; 3] { + // this generic function should be instantiated + let mut result = self.nested_func(3); + for idx in 0..3 { + result[idx] = self.xx; + } + return result; +} + +fn main(pub val: Field) -> [Field; 3] { + let thing = Thing {xx: val}; + return thing.mod_arr(); +} \ No newline at end of file diff --git a/src/tests/examples.rs b/src/tests/examples.rs index 34065e460..3aade9de0 100644 --- a/src/tests/examples.rs +++ b/src/tests/examples.rs @@ -664,3 +664,39 @@ fn test_generic_iterator(#[case] backend: BackendKind) -> miette::Result<()> { Ok(()) } + +#[rstest] +#[case::kimchi_vesta(BackendKind::KimchiVesta(KimchiVesta::new(false)))] +#[case::r1cs(BackendKind::R1csBls12_381(R1CS::new()))] +fn test_generic_nested_func(#[case] backend: BackendKind) -> miette::Result<()> { + let public_inputs = r#"{"val":"1"}"#; + let private_inputs = r#"{}"#; + + test_file( + "generic_nested_func", + public_inputs, + private_inputs, + vec!["1", "1", "1"], + backend, + )?; + + Ok(()) +} + +#[rstest] +#[case::kimchi_vesta(BackendKind::KimchiVesta(KimchiVesta::new(false)))] +#[case::r1cs(BackendKind::R1csBls12_381(R1CS::new()))] +fn test_generic_nested_method(#[case] backend: BackendKind) -> miette::Result<()> { + let public_inputs = r#"{"val":"1"}"#; + let private_inputs = r#"{}"#; + + test_file( + "generic_nested_method", + public_inputs, + private_inputs, + vec!["1", "1", "1"], + backend, + )?; + + Ok(()) +}