From a919f55d932bd0e522e4438ec69061efe0b7b6bc Mon Sep 17 00:00:00 2001 From: vezenovm Date: Fri, 29 Sep 2023 18:37:37 +0000 Subject: [PATCH 01/12] working tuple types in the ABI --- .../execution_success/tuple_inputs/Nargo.toml | 7 ++++++ .../tuple_inputs/Prover.toml | 2 ++ .../tuple_inputs/src/main.nr | 22 +++++++++++++++++ tooling/noirc_abi/src/input_parser/json.rs | 13 ++++++++++ tooling/noirc_abi/src/input_parser/mod.rs | 8 +++++++ tooling/noirc_abi/src/input_parser/toml.rs | 20 ++++++++++++++++ tooling/noirc_abi/src/lib.rs | 24 ++++++++++++++++++- 7 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tooling/nargo_cli/tests/execution_success/tuple_inputs/Nargo.toml create mode 100644 tooling/nargo_cli/tests/execution_success/tuple_inputs/Prover.toml create mode 100644 tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr diff --git a/tooling/nargo_cli/tests/execution_success/tuple_inputs/Nargo.toml b/tooling/nargo_cli/tests/execution_success/tuple_inputs/Nargo.toml new file mode 100644 index 0000000000..7cc7bc8539 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/tuple_inputs/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "tuple_inputs" +type = "bin" +authors = [""] +compiler_version = "0.14.1" + +[dependencies] \ No newline at end of file diff --git a/tooling/nargo_cli/tests/execution_success/tuple_inputs/Prover.toml b/tooling/nargo_cli/tests/execution_success/tuple_inputs/Prover.toml new file mode 100644 index 0000000000..73310e0aea --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/tuple_inputs/Prover.toml @@ -0,0 +1,2 @@ +pair = [1, 0] +x = [[0, 1, 2], [3, 4, 5]] diff --git a/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr b/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr new file mode 100644 index 0000000000..cfd33f7b65 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr @@ -0,0 +1,22 @@ +fn main(pair : (Field, Field), x: [(u8, u8, u8); 2]) -> pub (Field, Field) { + assert(pair.0 == 1); + assert(pair.1 == 0); + + let mut start_val = 0; + for i in 0..2 { + assert(x[i].0 == start_val); + assert(x[i].1 == start_val + 1); + assert(x[i].2 == start_val + 2); + start_val += 3; + } + + let (u, v) = if pair.0 as u32 < 1 { + (pair.0, pair.0 + 1) + } else { + (pair.0 + 1, pair.0) + }; + assert(u == pair.0 + 1); + assert(v == pair.0); + + (u, v) +} \ No newline at end of file diff --git a/tooling/noirc_abi/src/input_parser/json.rs b/tooling/noirc_abi/src/input_parser/json.rs index c6f1e30472..9cad636989 100644 --- a/tooling/noirc_abi/src/input_parser/json.rs +++ b/tooling/noirc_abi/src/input_parser/json.rs @@ -104,6 +104,11 @@ impl JsonTypes { JsonTypes::Table(map_with_json_types) } + (InputValue::Vec(vector), AbiType::Tuple { fields }) => { + let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| JsonTypes::try_from_input_value(value, typ))?; + JsonTypes::Array(fields) + } + _ => return Err(InputParserError::AbiTypeMismatch(abi_type.clone())), }; Ok(json_value) @@ -169,6 +174,14 @@ impl InputValue { InputValue::Struct(native_table) } + (JsonTypes::Array(array), AbiType::Tuple { fields }) => { + let tuple_fields = try_vecmap( + array.into_iter().zip(fields.iter()), + |(value, typ)| InputValue::try_from_json(value, typ, arg_name) + )?; + InputValue::Vec(tuple_fields) + } + (_, _) => return Err(InputParserError::AbiTypeMismatch(param_type.clone())), }; diff --git a/tooling/noirc_abi/src/input_parser/mod.rs b/tooling/noirc_abi/src/input_parser/mod.rs index fc6cd4b3b3..e88c2c211d 100644 --- a/tooling/noirc_abi/src/input_parser/mod.rs +++ b/tooling/noirc_abi/src/input_parser/mod.rs @@ -64,6 +64,14 @@ impl InputValue { }) } + (InputValue::Vec(vec_elements), AbiType::Tuple { fields }) => { + if vec_elements.len() != fields.len() { + return false; + } + + vec_elements.iter().zip(fields.iter()).all(|(input_value, abi_param)| input_value.matches_abi(abi_param)) + } + // All other InputValue-AbiType combinations are fundamentally incompatible. _ => false, } diff --git a/tooling/noirc_abi/src/input_parser/toml.rs b/tooling/noirc_abi/src/input_parser/toml.rs index dc47cbcda3..682bb00747 100644 --- a/tooling/noirc_abi/src/input_parser/toml.rs +++ b/tooling/noirc_abi/src/input_parser/toml.rs @@ -102,6 +102,14 @@ impl TomlTypes { TomlTypes::Table(map_with_toml_types) } + (InputValue::Vec(vector), AbiType::Tuple { fields }) => { + if vector.len() != fields.len() { + return Err(InputParserError::AbiTypeMismatch(abi_type.clone())) + } + let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| TomlTypes::try_from_input_value(value, typ))?; + TomlTypes::Array(fields) + } + _ => return Err(InputParserError::AbiTypeMismatch(abi_type.clone())), }; Ok(toml_value) @@ -156,6 +164,18 @@ impl InputValue { InputValue::Struct(native_table) } + (TomlTypes::Array(array), AbiType::Tuple { fields }) => { + if array.len() != fields.len() { + return Err(InputParserError::AbiTypeMismatch(param_type.clone())) + } + + let tuple_fields = try_vecmap( + array.into_iter().zip(fields.iter()), + |(value, typ)| InputValue::try_from_toml(value, typ, arg_name) + )?; + InputValue::Vec(tuple_fields) + } + (_, _) => return Err(InputParserError::AbiTypeMismatch(param_type.clone())), }; diff --git a/tooling/noirc_abi/src/lib.rs b/tooling/noirc_abi/src/lib.rs index eb654e25f8..ea548d8a05 100644 --- a/tooling/noirc_abi/src/lib.rs +++ b/tooling/noirc_abi/src/lib.rs @@ -62,6 +62,9 @@ pub enum AbiType { )] fields: Vec<(String, AbiType)>, }, + Tuple { + fields: Vec, + }, String { length: u64, }, @@ -164,7 +167,10 @@ impl AbiType { context.fully_qualified_struct_path(context.root_crate_id(), struct_type.id); Self::Struct { fields, path } } - Type::Tuple(_) => todo!("AbiType::from_type not yet implemented for tuple types"), + Type::Tuple(fields) => { + let fields = vecmap(fields, |typ| Self::from_type(context, typ)); + Self::Tuple { fields } + } Type::TypeVariable(_, _) => unreachable!(), Type::NamedGeneric(..) => unreachable!(), Type::Forall(..) => unreachable!(), @@ -182,6 +188,9 @@ impl AbiType { AbiType::Struct { fields, .. } => { fields.iter().fold(0, |acc, (_, field_type)| acc + field_type.field_count()) } + AbiType::Tuple { fields } => { + fields.iter().fold(0, |acc, field_typ| acc + field_typ.field_count()) + } AbiType::String { length } => *length as u32, } } @@ -370,6 +379,11 @@ impl Abi { encoded_value.extend(Self::encode_value(object[field].clone(), typ)?); } } + (InputValue::Vec(vec_elements), AbiType::Tuple { fields }) => { + for (i, typ) in fields.iter().enumerate() { + encoded_value.extend(Self::encode_value(vec_elements[i].clone(), typ)?); + } + } _ => unreachable!("value should have already been checked to match abi type"), } Ok(encoded_value) @@ -462,6 +476,14 @@ fn decode_value( InputValue::Struct(struct_map) } + AbiType::Tuple { fields } => { + let mut tuple_elements = Vec::with_capacity(fields.len()); + for field_typ in fields { + tuple_elements.push(decode_value(field_iterator, field_typ)?); + } + + InputValue::Vec(tuple_elements) + } }; Ok(value) From d072f12a47a2c67abb77232f8da5a969e4851ac5 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Fri, 29 Sep 2023 18:42:01 +0000 Subject: [PATCH 02/12] cargo fmt --- tooling/noirc_abi/src/input_parser/json.rs | 12 +++++++----- tooling/noirc_abi/src/input_parser/mod.rs | 5 ++++- tooling/noirc_abi/src/input_parser/toml.rs | 16 +++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/tooling/noirc_abi/src/input_parser/json.rs b/tooling/noirc_abi/src/input_parser/json.rs index 9cad636989..ad668627da 100644 --- a/tooling/noirc_abi/src/input_parser/json.rs +++ b/tooling/noirc_abi/src/input_parser/json.rs @@ -105,7 +105,9 @@ impl JsonTypes { } (InputValue::Vec(vector), AbiType::Tuple { fields }) => { - let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| JsonTypes::try_from_input_value(value, typ))?; + let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| { + JsonTypes::try_from_input_value(value, typ) + })?; JsonTypes::Array(fields) } @@ -175,10 +177,10 @@ impl InputValue { } (JsonTypes::Array(array), AbiType::Tuple { fields }) => { - let tuple_fields = try_vecmap( - array.into_iter().zip(fields.iter()), - |(value, typ)| InputValue::try_from_json(value, typ, arg_name) - )?; + let tuple_fields = + try_vecmap(array.into_iter().zip(fields.iter()), |(value, typ)| { + InputValue::try_from_json(value, typ, arg_name) + })?; InputValue::Vec(tuple_fields) } diff --git a/tooling/noirc_abi/src/input_parser/mod.rs b/tooling/noirc_abi/src/input_parser/mod.rs index e88c2c211d..3c3548a494 100644 --- a/tooling/noirc_abi/src/input_parser/mod.rs +++ b/tooling/noirc_abi/src/input_parser/mod.rs @@ -69,7 +69,10 @@ impl InputValue { return false; } - vec_elements.iter().zip(fields.iter()).all(|(input_value, abi_param)| input_value.matches_abi(abi_param)) + vec_elements + .iter() + .zip(fields.iter()) + .all(|(input_value, abi_param)| input_value.matches_abi(abi_param)) } // All other InputValue-AbiType combinations are fundamentally incompatible. diff --git a/tooling/noirc_abi/src/input_parser/toml.rs b/tooling/noirc_abi/src/input_parser/toml.rs index 682bb00747..593446ed96 100644 --- a/tooling/noirc_abi/src/input_parser/toml.rs +++ b/tooling/noirc_abi/src/input_parser/toml.rs @@ -104,9 +104,11 @@ impl TomlTypes { (InputValue::Vec(vector), AbiType::Tuple { fields }) => { if vector.len() != fields.len() { - return Err(InputParserError::AbiTypeMismatch(abi_type.clone())) + return Err(InputParserError::AbiTypeMismatch(abi_type.clone())); } - let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| TomlTypes::try_from_input_value(value, typ))?; + let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| { + TomlTypes::try_from_input_value(value, typ) + })?; TomlTypes::Array(fields) } @@ -166,13 +168,13 @@ impl InputValue { (TomlTypes::Array(array), AbiType::Tuple { fields }) => { if array.len() != fields.len() { - return Err(InputParserError::AbiTypeMismatch(param_type.clone())) + return Err(InputParserError::AbiTypeMismatch(param_type.clone())); } - let tuple_fields = try_vecmap( - array.into_iter().zip(fields.iter()), - |(value, typ)| InputValue::try_from_toml(value, typ, arg_name) - )?; + let tuple_fields = + try_vecmap(array.into_iter().zip(fields.iter()), |(value, typ)| { + InputValue::try_from_toml(value, typ, arg_name) + })?; InputValue::Vec(tuple_fields) } From 8eefa46fa13bd472785a6eb73569e7b88f9fed35 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Fri, 29 Sep 2023 18:46:41 +0000 Subject: [PATCH 03/12] remove size check --- tooling/noirc_abi/src/input_parser/toml.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tooling/noirc_abi/src/input_parser/toml.rs b/tooling/noirc_abi/src/input_parser/toml.rs index 593446ed96..5083258974 100644 --- a/tooling/noirc_abi/src/input_parser/toml.rs +++ b/tooling/noirc_abi/src/input_parser/toml.rs @@ -103,9 +103,6 @@ impl TomlTypes { } (InputValue::Vec(vector), AbiType::Tuple { fields }) => { - if vector.len() != fields.len() { - return Err(InputParserError::AbiTypeMismatch(abi_type.clone())); - } let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| { TomlTypes::try_from_input_value(value, typ) })?; @@ -167,10 +164,6 @@ impl InputValue { } (TomlTypes::Array(array), AbiType::Tuple { fields }) => { - if array.len() != fields.len() { - return Err(InputParserError::AbiTypeMismatch(param_type.clone())); - } - let tuple_fields = try_vecmap(array.into_iter().zip(fields.iter()), |(value, typ)| { InputValue::try_from_toml(value, typ, arg_name) From 3f1d9e100bae2d28bdd1d2eaabe1b607b41bcdba Mon Sep 17 00:00:00 2001 From: vezenovm Date: Fri, 29 Sep 2023 19:27:26 +0000 Subject: [PATCH 04/12] show tuple of struct inputs in test --- .../execution_success/tuple_inputs/Prover.toml | 10 ++++++++++ .../execution_success/tuple_inputs/src/main.nr | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tooling/nargo_cli/tests/execution_success/tuple_inputs/Prover.toml b/tooling/nargo_cli/tests/execution_success/tuple_inputs/Prover.toml index 73310e0aea..43d62a7a15 100644 --- a/tooling/nargo_cli/tests/execution_success/tuple_inputs/Prover.toml +++ b/tooling/nargo_cli/tests/execution_success/tuple_inputs/Prover.toml @@ -1,2 +1,12 @@ pair = [1, 0] x = [[0, 1, 2], [3, 4, 5]] + +[[struct_pair]] +a = "1" +b = ["2", "3", "20"] + +[struct_pair.bar] +inner = ["100", "101", "102"] + +[[struct_pair]] +inner = ["103", "104", "105"] diff --git a/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr b/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr index cfd33f7b65..759acf20f3 100644 --- a/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr @@ -1,4 +1,14 @@ -fn main(pair : (Field, Field), x: [(u8, u8, u8); 2]) -> pub (Field, Field) { +struct Bar { + inner: [Field; 3], +} + +struct Foo { + a: Field, + b: [Field; 3], + bar: Bar, +} + +fn main(pair : (Field, Field), x: [(u8, u8, u8); 2], struct_pair: (Foo, Bar)) -> pub (Field, Field) { assert(pair.0 == 1); assert(pair.1 == 0); @@ -10,6 +20,11 @@ fn main(pair : (Field, Field), x: [(u8, u8, u8); 2]) -> pub (Field, Field) { start_val += 3; } + assert(struct_pair.0.a == 1); + assert(struct_pair.0.b == [2, 3, 20]); + assert(struct_pair.0.bar.inner == [100, 101, 102]); + assert(struct_pair.1.inner == [103, 104, 105]); + let (u, v) = if pair.0 as u32 < 1 { (pair.0, pair.0 + 1) } else { From cc512e151aa06beefa3152ab82a408cda43520a2 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 29 Sep 2023 21:08:56 +0100 Subject: [PATCH 05/12] Update tooling/noirc_abi/src/lib.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/noirc_abi/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tooling/noirc_abi/src/lib.rs b/tooling/noirc_abi/src/lib.rs index ea548d8a05..d5c2314b3a 100644 --- a/tooling/noirc_abi/src/lib.rs +++ b/tooling/noirc_abi/src/lib.rs @@ -380,8 +380,8 @@ impl Abi { } } (InputValue::Vec(vec_elements), AbiType::Tuple { fields }) => { - for (i, typ) in fields.iter().enumerate() { - encoded_value.extend(Self::encode_value(vec_elements[i].clone(), typ)?); + for (value, typ) in vec_elements.into_iter().zip(fields) { + encoded_value.extend(Self::encode_value(value, typ)?); } } _ => unreachable!("value should have already been checked to match abi type"), From 0ce6de1f6a82e285263cabcda994a337634c41c5 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 29 Sep 2023 21:09:26 +0100 Subject: [PATCH 06/12] Update tooling/noirc_abi/src/input_parser/toml.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/noirc_abi/src/input_parser/toml.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/noirc_abi/src/input_parser/toml.rs b/tooling/noirc_abi/src/input_parser/toml.rs index 5083258974..16cf36535f 100644 --- a/tooling/noirc_abi/src/input_parser/toml.rs +++ b/tooling/noirc_abi/src/input_parser/toml.rs @@ -165,7 +165,7 @@ impl InputValue { (TomlTypes::Array(array), AbiType::Tuple { fields }) => { let tuple_fields = - try_vecmap(array.into_iter().zip(fields.iter()), |(value, typ)| { + try_vecmap(array.into_iter().zip(fields), |(value, typ)| { InputValue::try_from_toml(value, typ, arg_name) })?; InputValue::Vec(tuple_fields) From adae638de11b01235cddc0f297c3c051f87719ee Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 29 Sep 2023 21:09:33 +0100 Subject: [PATCH 07/12] Update tooling/noirc_abi/src/input_parser/toml.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/noirc_abi/src/input_parser/toml.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/noirc_abi/src/input_parser/toml.rs b/tooling/noirc_abi/src/input_parser/toml.rs index 16cf36535f..7452d008e5 100644 --- a/tooling/noirc_abi/src/input_parser/toml.rs +++ b/tooling/noirc_abi/src/input_parser/toml.rs @@ -103,7 +103,7 @@ impl TomlTypes { } (InputValue::Vec(vector), AbiType::Tuple { fields }) => { - let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| { + let fields = try_vecmap(vector.iter().zip(fields), |(value, typ)| { TomlTypes::try_from_input_value(value, typ) })?; TomlTypes::Array(fields) From 09d0296cfb7eb509a092b922934cedc184932bc6 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 29 Sep 2023 21:09:41 +0100 Subject: [PATCH 08/12] Update tooling/noirc_abi/src/input_parser/mod.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/noirc_abi/src/input_parser/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/noirc_abi/src/input_parser/mod.rs b/tooling/noirc_abi/src/input_parser/mod.rs index 3c3548a494..e26cfecc38 100644 --- a/tooling/noirc_abi/src/input_parser/mod.rs +++ b/tooling/noirc_abi/src/input_parser/mod.rs @@ -71,7 +71,7 @@ impl InputValue { vec_elements .iter() - .zip(fields.iter()) + .zip(fields) .all(|(input_value, abi_param)| input_value.matches_abi(abi_param)) } From 7208af1ff94379248b95f9db85d8f23c700288a8 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 29 Sep 2023 21:09:50 +0100 Subject: [PATCH 09/12] Update tooling/noirc_abi/src/input_parser/json.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/noirc_abi/src/input_parser/json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/noirc_abi/src/input_parser/json.rs b/tooling/noirc_abi/src/input_parser/json.rs index ad668627da..a80ebda2a8 100644 --- a/tooling/noirc_abi/src/input_parser/json.rs +++ b/tooling/noirc_abi/src/input_parser/json.rs @@ -105,7 +105,7 @@ impl JsonTypes { } (InputValue::Vec(vector), AbiType::Tuple { fields }) => { - let fields = try_vecmap(vector.iter().zip(fields.iter()), |(value, typ)| { + let fields = try_vecmap(vector.iter().zip(fields), |(value, typ)| { JsonTypes::try_from_input_value(value, typ) })?; JsonTypes::Array(fields) From e5881a87b507cdc7c5a469b913cce61593b0bafd Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 29 Sep 2023 21:09:54 +0100 Subject: [PATCH 10/12] Update tooling/noirc_abi/src/input_parser/json.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/noirc_abi/src/input_parser/json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/noirc_abi/src/input_parser/json.rs b/tooling/noirc_abi/src/input_parser/json.rs index a80ebda2a8..df7b0cb399 100644 --- a/tooling/noirc_abi/src/input_parser/json.rs +++ b/tooling/noirc_abi/src/input_parser/json.rs @@ -178,7 +178,7 @@ impl InputValue { (JsonTypes::Array(array), AbiType::Tuple { fields }) => { let tuple_fields = - try_vecmap(array.into_iter().zip(fields.iter()), |(value, typ)| { + try_vecmap(array.into_iter().zip(fields), |(value, typ)| { InputValue::try_from_json(value, typ, arg_name) })?; InputValue::Vec(tuple_fields) From 57aaaba0e79284226af6bf9109ed0f5ed7840874 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Fri, 29 Sep 2023 20:13:42 +0000 Subject: [PATCH 11/12] reflect tuple abi changes in noirc_abi_wasm --- tooling/noirc_abi/src/input_parser/json.rs | 7 +++---- tooling/noirc_abi/src/input_parser/toml.rs | 7 +++---- tooling/noirc_abi_wasm/src/temp.rs | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tooling/noirc_abi/src/input_parser/json.rs b/tooling/noirc_abi/src/input_parser/json.rs index df7b0cb399..518685b7cf 100644 --- a/tooling/noirc_abi/src/input_parser/json.rs +++ b/tooling/noirc_abi/src/input_parser/json.rs @@ -177,10 +177,9 @@ impl InputValue { } (JsonTypes::Array(array), AbiType::Tuple { fields }) => { - let tuple_fields = - try_vecmap(array.into_iter().zip(fields), |(value, typ)| { - InputValue::try_from_json(value, typ, arg_name) - })?; + let tuple_fields = try_vecmap(array.into_iter().zip(fields), |(value, typ)| { + InputValue::try_from_json(value, typ, arg_name) + })?; InputValue::Vec(tuple_fields) } diff --git a/tooling/noirc_abi/src/input_parser/toml.rs b/tooling/noirc_abi/src/input_parser/toml.rs index 7452d008e5..645b59b00c 100644 --- a/tooling/noirc_abi/src/input_parser/toml.rs +++ b/tooling/noirc_abi/src/input_parser/toml.rs @@ -164,10 +164,9 @@ impl InputValue { } (TomlTypes::Array(array), AbiType::Tuple { fields }) => { - let tuple_fields = - try_vecmap(array.into_iter().zip(fields), |(value, typ)| { - InputValue::try_from_toml(value, typ, arg_name) - })?; + let tuple_fields = try_vecmap(array.into_iter().zip(fields), |(value, typ)| { + InputValue::try_from_toml(value, typ, arg_name) + })?; InputValue::Vec(tuple_fields) } diff --git a/tooling/noirc_abi_wasm/src/temp.rs b/tooling/noirc_abi_wasm/src/temp.rs index e6c4e38495..f833ecb756 100644 --- a/tooling/noirc_abi_wasm/src/temp.rs +++ b/tooling/noirc_abi_wasm/src/temp.rs @@ -55,6 +55,13 @@ impl JsonTypes { JsonTypes::Table(map_with_json_types) } + (InputValue::Vec(vector), AbiType::Tuple { fields }) => { + let fields = try_vecmap(vector.iter().zip(fields), |(value, typ)| { + JsonTypes::try_from_input_value(value, typ) + })?; + JsonTypes::Array(fields) + } + _ => return Err(InputParserError::AbiTypeMismatch(abi_type.clone())), }; Ok(json_value) @@ -104,6 +111,13 @@ pub(super) fn input_value_from_json_type( InputValue::Struct(native_table) } + (JsonTypes::Array(array), AbiType::Tuple { fields }) => { + let tuple_fields = try_vecmap(array.into_iter().zip(fields), |(value, typ)| { + input_value_from_json_type(value, typ, arg_name) + })?; + InputValue::Vec(tuple_fields) + } + (_, _) => return Err(InputParserError::AbiTypeMismatch(param_type.clone())), }; From c0171481c28b07bda525809d7af40c84ad107e96 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 29 Sep 2023 22:55:52 +0100 Subject: [PATCH 12/12] chore: heterogeneous tuple return value --- .../tests/execution_success/tuple_inputs/src/main.nr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr b/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr index 759acf20f3..37160d5a0e 100644 --- a/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/tuple_inputs/src/main.nr @@ -8,7 +8,7 @@ struct Foo { bar: Bar, } -fn main(pair : (Field, Field), x: [(u8, u8, u8); 2], struct_pair: (Foo, Bar)) -> pub (Field, Field) { +fn main(pair : (Field, Field), x: [(u8, u8, u8); 2], struct_pair: (Foo, Bar)) -> pub (Field, u8) { assert(pair.0 == 1); assert(pair.1 == 0); @@ -33,5 +33,5 @@ fn main(pair : (Field, Field), x: [(u8, u8, u8); 2], struct_pair: (Foo, Bar)) -> assert(u == pair.0 + 1); assert(v == pair.0); - (u, v) -} \ No newline at end of file + (u, v as u8) +}