From cd4269c705be029c5442b15c92d5b2667636b771 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 7 Mar 2024 13:24:35 -0600 Subject: [PATCH 1/4] Force src impl for == on slices --- compiler/noirc_frontend/src/hir/type_check/expr.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/noirc_frontend/src/hir/type_check/expr.rs b/compiler/noirc_frontend/src/hir/type_check/expr.rs index 7b854e58fca..a1150b8c26f 100644 --- a/compiler/noirc_frontend/src/hir/type_check/expr.rs +++ b/compiler/noirc_frontend/src/hir/type_check/expr.rs @@ -863,7 +863,13 @@ impl<'interner> TypeChecker<'interner> { span: op.location.span, }); - self.comparator_operand_type_rules(x_type, y_type, op, span) + self.comparator_operand_type_rules(x_type, y_type, op, span)?; + + // If the size is not constant, we must fall back to a user-provided impl for + // equality on slices. + let size = x_size.follow_bindings(); + let use_src_code_impl = size.evaluate_to_u64().is_none(); + Ok((Bool, use_src_code_impl)) } (String(x_size), String(y_size)) => { From 1050557fcee95245a3cfba8bb4368dc52af64589 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 7 Mar 2024 13:27:21 -0600 Subject: [PATCH 2/4] Add test --- compiler/noirc_frontend/src/tests.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 0c8c677d9af..41581cad462 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -1206,4 +1206,16 @@ fn lambda$f1(mut env$l1: (Field)) -> Field { "#; assert_eq!(get_program_errors(src).len(), 1); } + + // This is a regression for #4507 + #[test] + fn slice_eq_works() { + let src = r#" + fn main() { + let slice: [Field] = [1, 2, 3]; + assert(slice == slice); + } + "#; + assert_eq!(get_program_errors(src).len(), 1); + } } From a11151f44445e194ca1235193244a48db75ef92a Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 7 Mar 2024 13:43:11 -0600 Subject: [PATCH 3/4] Carry over result from nested call --- compiler/noirc_frontend/src/hir/type_check/expr.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/noirc_frontend/src/hir/type_check/expr.rs b/compiler/noirc_frontend/src/hir/type_check/expr.rs index a1150b8c26f..c5287d35caf 100644 --- a/compiler/noirc_frontend/src/hir/type_check/expr.rs +++ b/compiler/noirc_frontend/src/hir/type_check/expr.rs @@ -863,13 +863,13 @@ impl<'interner> TypeChecker<'interner> { span: op.location.span, }); - self.comparator_operand_type_rules(x_type, y_type, op, span)?; + let (_, use_impl) = self.comparator_operand_type_rules(x_type, y_type, op, span)?; // If the size is not constant, we must fall back to a user-provided impl for // equality on slices. let size = x_size.follow_bindings(); - let use_src_code_impl = size.evaluate_to_u64().is_none(); - Ok((Bool, use_src_code_impl)) + let use_impl = use_impl || size.evaluate_to_u64().is_none(); + Ok((Bool, use_impl)) } (String(x_size), String(y_size)) => { From 60fa45f2ccbcb243cfaf651e798ea0c0e0b62b4a Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 7 Mar 2024 13:54:45 -0600 Subject: [PATCH 4/4] Move test to test_programs since it requires the stdlib --- compiler/noirc_frontend/src/tests.rs | 12 ------------ test_programs/execution_success/slices/src/main.nr | 7 +++++++ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 41581cad462..0c8c677d9af 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -1206,16 +1206,4 @@ fn lambda$f1(mut env$l1: (Field)) -> Field { "#; assert_eq!(get_program_errors(src).len(), 1); } - - // This is a regression for #4507 - #[test] - fn slice_eq_works() { - let src = r#" - fn main() { - let slice: [Field] = [1, 2, 3]; - assert(slice == slice); - } - "#; - assert_eq!(get_program_errors(src).len(), 1); - } } diff --git a/test_programs/execution_success/slices/src/main.nr b/test_programs/execution_success/slices/src/main.nr index eca42a660c4..6823bf05d96 100644 --- a/test_programs/execution_success/slices/src/main.nr +++ b/test_programs/execution_success/slices/src/main.nr @@ -50,6 +50,8 @@ fn main(x: Field, y: pub Field) { // The parameters to this function must come from witness values (inputs to main) regression_merge_slices(x, y); regression_2370(); + + regression_4506(); } // Ensure that slices of struct/tuple values work. fn regression_2083() { @@ -297,3 +299,8 @@ fn regression_2370() { let mut slice = []; slice = [1, 2, 3]; } + +fn regression_4506() { + let slice: [Field] = [1, 2, 3]; + assert(slice == slice); +}