From a6939db10cd57d778c554fd73f6ecc1815595dd7 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 11 Apr 2025 19:37:06 +0000 Subject: [PATCH 1/7] no not use the inner else condition when simplifying ifelse, want to add regression for the switched then/else value --- .../src/ssa/ir/dfg/simplify.rs | 4 +- .../src/ssa/opt/flatten_cfg.rs | 1 + .../noirc_evaluator/src/ssa/ssa_gen/mod.rs | 1 + .../return_array_witness_if_cond/Nargo.toml | 6 ++ .../return_array_witness_if_cond/Prover.toml | 4 ++ .../return_array_witness_if_cond/src/main.nr | 18 +++++ .../return_array_witness_if_cond/stdout.txt | 1 + ...lig_true_inliner_-9223372036854775808.snap | 68 +++++++++++++++++++ ...__tests__force_brillig_true_inliner_0.snap | 68 +++++++++++++++++++ ...llig_true_inliner_9223372036854775807.snap | 68 +++++++++++++++++++ 10 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 test_programs/execution_success/return_array_witness_if_cond/Nargo.toml create mode 100644 test_programs/execution_success/return_array_witness_if_cond/Prover.toml create mode 100644 test_programs/execution_success/return_array_witness_if_cond/src/main.nr create mode 100644 test_programs/execution_success/return_array_witness_if_cond/stdout.txt create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_0.snap create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap diff --git a/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs b/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs index b56698dcc6d..afba41a51dc 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs @@ -229,7 +229,7 @@ pub(crate) fn simplify( if let Instruction::IfElse { then_condition: inner_then_condition, then_value: inner_then_value, - else_condition: inner_else_condition, + else_condition, .. } = dfg[*instruction] { @@ -237,7 +237,7 @@ pub(crate) fn simplify( let instruction = Instruction::IfElse { then_condition, then_value: inner_then_value, - else_condition: inner_else_condition, + else_condition, else_value, }; return SimplifiedToInstruction(instruction); diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs index da4f5a0014a..03cc257e306 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs @@ -648,6 +648,7 @@ impl<'f> Context<'f> { self.inserter.function.dfg.make_constant(FieldElement::one(), NumericType::bool()) } }; + let enable_side_effects = Instruction::EnableSideEffectsIf { condition }; let call_stack = self.inserter.function.dfg.get_value_call_stack_id(condition); self.insert_instruction_with_typevars(enable_side_effects, None, call_stack); diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs index aec25a4b958..f50ef353e04 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -687,6 +687,7 @@ impl FunctionContext<'_> { /// ``` fn codegen_if(&mut self, if_expr: &ast::If) -> Result { let condition = self.codegen_non_tuple_expression(&if_expr.condition)?; + if let Some(result) = self.try_codegen_constant_if(condition, if_expr) { return result; } diff --git a/test_programs/execution_success/return_array_witness_if_cond/Nargo.toml b/test_programs/execution_success/return_array_witness_if_cond/Nargo.toml new file mode 100644 index 00000000000..16eba7d04ec --- /dev/null +++ b/test_programs/execution_success/return_array_witness_if_cond/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "return_array_witness_if_cond" +type = "bin" +authors = [""] + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/return_array_witness_if_cond/Prover.toml b/test_programs/execution_success/return_array_witness_if_cond/Prover.toml new file mode 100644 index 00000000000..2252155bbac --- /dev/null +++ b/test_programs/execution_success/return_array_witness_if_cond/Prover.toml @@ -0,0 +1,4 @@ +a = 0 +b = [[1, 0], [1, 0], [1, 1]] + +return = [1, 0] \ No newline at end of file diff --git a/test_programs/execution_success/return_array_witness_if_cond/src/main.nr b/test_programs/execution_success/return_array_witness_if_cond/src/main.nr new file mode 100644 index 00000000000..f544a418c2b --- /dev/null +++ b/test_programs/execution_success/return_array_witness_if_cond/src/main.nr @@ -0,0 +1,18 @@ +// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961) +fn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] { + // let z = !!a; + // println(z); + let x = b[0]; + if (!!a) { + if (!!a) { + b[0] + // x + } else { + b[0] + // x + } + } else { + b[0] + // x + } +} \ No newline at end of file diff --git a/test_programs/execution_success/return_array_witness_if_cond/stdout.txt b/test_programs/execution_success/return_array_witness_if_cond/stdout.txt new file mode 100644 index 00000000000..95253ddbdb5 --- /dev/null +++ b/test_programs/execution_success/return_array_witness_if_cond/stdout.txt @@ -0,0 +1 @@ +[return_array_witness_if_cond] Circuit output: Vec([Field(1), Field(0)]) \ No newline at end of file diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..14669d2d268 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap @@ -0,0 +1,68 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": { + "12049594436772143978": { + "error_kind": "string", + "string": "array ref-count underflow detected" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1ZTW+bQBBd8IKNE8tW+0cw4OKjD83nJVJvbU/YrqWeeuiph6ocWqk/O15lBz+GJYlkJhGRV7J2Yd/Ox5uZBdaeemij/c+zY217XzUbYVa2j49r8w5lxca2UNher0N7pWz0e2DjoAc26h7YGPTAxlB1W+NkI+1PQ/Wwf1UXioFMsplgGrJwg3AKAAL+2z5ieM/KXHVEUMT0dil/GWfbSNVbx/anEcgUkJ+TfC0jP6ac+VjW5Sumd8BwfA1iLgBz0YK5BMxlC+YKMFctmGvAXLdgbgBz04K5Bcwtw0zs2DtAKt8pPhL1sc/fhXD804mqxxz9Jt2BjO7MY/owHjhH+sdKtNbmHtNH9nB+fMbPUMaemOSPhOSTv5HDX8znIfP3TMaehHJxDPbwXDyX0Z0+NxdJ/5jZKpWL56oZG+SH4jQhTHmwJ2Jzumz6QXMBzFF8Td7dgX84h/bg/kC5OlPNXCG7hesmEa6b+aluqnaqG5jred1kwnWTnOqmaqe6gTnpuqE483d00vkFxl+Zft+hH2PG3wUl3k333wFr4e+AxBVPHmtd1nXjHMZTA593jB+h76S18Hd48l615xDlw7BUVRswPpEj4myEeDYXwZwu63rG9lqDHpRFdgQM/9leT20fwhpaP3PoD5n+mt2Oe8gRlzVw3CO8OZ/6ZMdn9mdy6A+tUaI1UO2BeE7mej6R/qlq7kchm8N1wcv4EXM/NPiBOn3gH/Gcg4Dd+2Z7E5t/sKZtv8R7NJ45uPOZPsqfn7Y3+r/b8ZRhXPwKnVlW/BKXWrnzxAOfOfc0Rn/p3g/bu/jFZ89jzyMXv4TjZz6IMxz/tuO3zPEv2782x/xsEdeY/Y/eqXRZn1/Z+/ERLV8e/lSg50+g6mddiukPGP6vvcb3UuqP+RNplxfzXVrsikWx3Wab4h2Tb5oPPHWtv8jT5SbJNvl6kRbphyf13wOf+U+CTR4AAA==", + "debug_symbols": "ldTNqoQgAAXgd3Hdwp9M7VUul8HKBkEsrC5concfjWCGmdmcjXjED0Hl7GRw3Xa/+ThOC2l/dhKm3q5+ijntR0W65EPw99vrMqFlMPzcv8w2lrisNq2kZYZVxMWhzGT2ow+OtJIevxUxAhY1LCQsGlgoWGhYGFQwSnHCcMJx8vVNRK0uIiT7IA1OFE40TgxMGMUJwwnHydd34aa+CDf6gzQ4UTjRODEw4RQnDCccI0dOfzZ52wV3dfC4xf6lktf/2b2185ym3g1bcqWnnxVd+laZSpvz5+bAuKqY4OeFlShEjjKfmc99AA==", + "file_map": { + "50": { + "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n // let z = !!a;\n // println(z);\n let x = b[0];\n if (!!a) {\n if (!!a) {\n b[0]\n // x\n } else {\n b[0]\n // x\n }\n } else {\n b[0]\n // x\n }\n}", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_0.snap new file mode 100644 index 00000000000..14669d2d268 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_0.snap @@ -0,0 +1,68 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": { + "12049594436772143978": { + "error_kind": "string", + "string": "array ref-count underflow detected" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1ZTW+bQBBd8IKNE8tW+0cw4OKjD83nJVJvbU/YrqWeeuiph6ocWqk/O15lBz+GJYlkJhGRV7J2Yd/Ox5uZBdaeemij/c+zY217XzUbYVa2j49r8w5lxca2UNher0N7pWz0e2DjoAc26h7YGPTAxlB1W+NkI+1PQ/Wwf1UXioFMsplgGrJwg3AKAAL+2z5ieM/KXHVEUMT0dil/GWfbSNVbx/anEcgUkJ+TfC0jP6ac+VjW5Sumd8BwfA1iLgBz0YK5BMxlC+YKMFctmGvAXLdgbgBz04K5Bcwtw0zs2DtAKt8pPhL1sc/fhXD804mqxxz9Jt2BjO7MY/owHjhH+sdKtNbmHtNH9nB+fMbPUMaemOSPhOSTv5HDX8znIfP3TMaehHJxDPbwXDyX0Z0+NxdJ/5jZKpWL56oZG+SH4jQhTHmwJ2Jzumz6QXMBzFF8Td7dgX84h/bg/kC5OlPNXCG7hesmEa6b+aluqnaqG5jred1kwnWTnOqmaqe6gTnpuqE483d00vkFxl+Zft+hH2PG3wUl3k333wFr4e+AxBVPHmtd1nXjHMZTA593jB+h76S18Hd48l615xDlw7BUVRswPpEj4myEeDYXwZwu63rG9lqDHpRFdgQM/9leT20fwhpaP3PoD5n+mt2Oe8gRlzVw3CO8OZ/6ZMdn9mdy6A+tUaI1UO2BeE7mej6R/qlq7kchm8N1wcv4EXM/NPiBOn3gH/Gcg4Dd+2Z7E5t/sKZtv8R7NJ45uPOZPsqfn7Y3+r/b8ZRhXPwKnVlW/BKXWrnzxAOfOfc0Rn/p3g/bu/jFZ89jzyMXv4TjZz6IMxz/tuO3zPEv2782x/xsEdeY/Y/eqXRZn1/Z+/ERLV8e/lSg50+g6mddiukPGP6vvcb3UuqP+RNplxfzXVrsikWx3Wab4h2Tb5oPPHWtv8jT5SbJNvl6kRbphyf13wOf+U+CTR4AAA==", + "debug_symbols": "ldTNqoQgAAXgd3Hdwp9M7VUul8HKBkEsrC5concfjWCGmdmcjXjED0Hl7GRw3Xa/+ThOC2l/dhKm3q5+ijntR0W65EPw99vrMqFlMPzcv8w2lrisNq2kZYZVxMWhzGT2ow+OtJIevxUxAhY1LCQsGlgoWGhYGFQwSnHCcMJx8vVNRK0uIiT7IA1OFE40TgxMGMUJwwnHydd34aa+CDf6gzQ4UTjRODEw4RQnDCccI0dOfzZ52wV3dfC4xf6lktf/2b2185ym3g1bcqWnnxVd+laZSpvz5+bAuKqY4OeFlShEjjKfmc99AA==", + "file_map": { + "50": { + "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n // let z = !!a;\n // println(z);\n let x = b[0];\n if (!!a) {\n if (!!a) {\n b[0]\n // x\n } else {\n b[0]\n // x\n }\n } else {\n b[0]\n // x\n }\n}", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..14669d2d268 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap @@ -0,0 +1,68 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": { + "12049594436772143978": { + "error_kind": "string", + "string": "array ref-count underflow detected" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1ZTW+bQBBd8IKNE8tW+0cw4OKjD83nJVJvbU/YrqWeeuiph6ocWqk/O15lBz+GJYlkJhGRV7J2Yd/Ox5uZBdaeemij/c+zY217XzUbYVa2j49r8w5lxca2UNher0N7pWz0e2DjoAc26h7YGPTAxlB1W+NkI+1PQ/Wwf1UXioFMsplgGrJwg3AKAAL+2z5ieM/KXHVEUMT0dil/GWfbSNVbx/anEcgUkJ+TfC0jP6ac+VjW5Sumd8BwfA1iLgBz0YK5BMxlC+YKMFctmGvAXLdgbgBz04K5Bcwtw0zs2DtAKt8pPhL1sc/fhXD804mqxxz9Jt2BjO7MY/owHjhH+sdKtNbmHtNH9nB+fMbPUMaemOSPhOSTv5HDX8znIfP3TMaehHJxDPbwXDyX0Z0+NxdJ/5jZKpWL56oZG+SH4jQhTHmwJ2Jzumz6QXMBzFF8Td7dgX84h/bg/kC5OlPNXCG7hesmEa6b+aluqnaqG5jred1kwnWTnOqmaqe6gTnpuqE483d00vkFxl+Zft+hH2PG3wUl3k333wFr4e+AxBVPHmtd1nXjHMZTA593jB+h76S18Hd48l615xDlw7BUVRswPpEj4myEeDYXwZwu63rG9lqDHpRFdgQM/9leT20fwhpaP3PoD5n+mt2Oe8gRlzVw3CO8OZ/6ZMdn9mdy6A+tUaI1UO2BeE7mej6R/qlq7kchm8N1wcv4EXM/NPiBOn3gH/Gcg4Dd+2Z7E5t/sKZtv8R7NJ45uPOZPsqfn7Y3+r/b8ZRhXPwKnVlW/BKXWrnzxAOfOfc0Rn/p3g/bu/jFZ89jzyMXv4TjZz6IMxz/tuO3zPEv2782x/xsEdeY/Y/eqXRZn1/Z+/ERLV8e/lSg50+g6mddiukPGP6vvcb3UuqP+RNplxfzXVrsikWx3Wab4h2Tb5oPPHWtv8jT5SbJNvl6kRbphyf13wOf+U+CTR4AAA==", + "debug_symbols": "ldTNqoQgAAXgd3Hdwp9M7VUul8HKBkEsrC5concfjWCGmdmcjXjED0Hl7GRw3Xa/+ThOC2l/dhKm3q5+ijntR0W65EPw99vrMqFlMPzcv8w2lrisNq2kZYZVxMWhzGT2ow+OtJIevxUxAhY1LCQsGlgoWGhYGFQwSnHCcMJx8vVNRK0uIiT7IA1OFE40TgxMGMUJwwnHydd34aa+CDf6gzQ4UTjRODEw4RQnDCccI0dOfzZ52wV3dfC4xf6lktf/2b2185ym3g1bcqWnnxVd+laZSpvz5+bAuKqY4OeFlShEjjKfmc99AA==", + "file_map": { + "50": { + "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n // let z = !!a;\n // println(z);\n let x = b[0];\n if (!!a) {\n if (!!a) {\n b[0]\n // x\n } else {\n b[0]\n // x\n }\n } else {\n b[0]\n // x\n }\n}", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} From 6eb3f405ed9306b80dbcb0f549af68d03d19ce51 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 11 Apr 2025 19:52:57 +0000 Subject: [PATCH 2/7] actually don't use inner else cond --- compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs | 1 - .../return_array_witness_if_cond/src/main.nr | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs b/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs index afba41a51dc..c04d84548d8 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs @@ -229,7 +229,6 @@ pub(crate) fn simplify( if let Instruction::IfElse { then_condition: inner_then_condition, then_value: inner_then_value, - else_condition, .. } = dfg[*instruction] { diff --git a/test_programs/execution_success/return_array_witness_if_cond/src/main.nr b/test_programs/execution_success/return_array_witness_if_cond/src/main.nr index f544a418c2b..2e034d2efd6 100644 --- a/test_programs/execution_success/return_array_witness_if_cond/src/main.nr +++ b/test_programs/execution_success/return_array_witness_if_cond/src/main.nr @@ -1,18 +1,12 @@ // Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961) fn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] { - // let z = !!a; - // println(z); - let x = b[0]; if (!!a) { if (!!a) { b[0] - // x } else { b[0] - // x } } else { b[0] - // x } -} \ No newline at end of file +} From faa53809e18302c71861abba68404f8480f02408 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 11 Apr 2025 20:13:33 +0000 Subject: [PATCH 3/7] also do not replace else_cond for else value --- .../src/ssa/ir/dfg/simplify.rs | 3 +- .../Nargo.toml | 2 +- .../Prover.toml | 0 .../src/main.nr | 0 .../nested_if_then_block_same_cond/stdout.txt | 1 + .../return_array_witness_if_cond/stdout.txt | 1 - ...ig_false_inliner_-9223372036854775808.snap | 52 ++++++++++++++ ..._tests__force_brillig_false_inliner_0.snap | 52 ++++++++++++++ ...lig_false_inliner_9223372036854775807.snap | 52 ++++++++++++++ ...lig_true_inliner_-9223372036854775808.snap | 68 +++++++++++++++++++ ...__tests__force_brillig_true_inliner_0.snap | 68 +++++++++++++++++++ ...llig_true_inliner_9223372036854775807.snap | 68 +++++++++++++++++++ 12 files changed, 363 insertions(+), 4 deletions(-) rename test_programs/execution_success/{return_array_witness_if_cond => nested_if_then_block_same_cond}/Nargo.toml (56%) rename test_programs/execution_success/{return_array_witness_if_cond => nested_if_then_block_same_cond}/Prover.toml (100%) rename test_programs/execution_success/{return_array_witness_if_cond => nested_if_then_block_same_cond}/src/main.nr (100%) create mode 100644 test_programs/execution_success/nested_if_then_block_same_cond/stdout.txt delete mode 100644 test_programs/execution_success/return_array_witness_if_cond/stdout.txt create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_0.snap create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_9223372036854775807.snap create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_0.snap create mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap diff --git a/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs b/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs index c04d84548d8..921152c8bb0 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs @@ -249,7 +249,6 @@ pub(crate) fn simplify( if let Value::Instruction { instruction, .. } = &dfg[else_value] { if let Instruction::IfElse { then_condition: inner_then_condition, - else_condition: inner_else_condition, else_value: inner_else_value, .. } = dfg[*instruction] @@ -258,7 +257,7 @@ pub(crate) fn simplify( let instruction = Instruction::IfElse { then_condition, then_value, - else_condition: inner_else_condition, + else_condition, else_value: inner_else_value, }; return SimplifiedToInstruction(instruction); diff --git a/test_programs/execution_success/return_array_witness_if_cond/Nargo.toml b/test_programs/execution_success/nested_if_then_block_same_cond/Nargo.toml similarity index 56% rename from test_programs/execution_success/return_array_witness_if_cond/Nargo.toml rename to test_programs/execution_success/nested_if_then_block_same_cond/Nargo.toml index 16eba7d04ec..3053b05a042 100644 --- a/test_programs/execution_success/return_array_witness_if_cond/Nargo.toml +++ b/test_programs/execution_success/nested_if_then_block_same_cond/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "return_array_witness_if_cond" +name = "nested_if_then_block_same_cond" type = "bin" authors = [""] diff --git a/test_programs/execution_success/return_array_witness_if_cond/Prover.toml b/test_programs/execution_success/nested_if_then_block_same_cond/Prover.toml similarity index 100% rename from test_programs/execution_success/return_array_witness_if_cond/Prover.toml rename to test_programs/execution_success/nested_if_then_block_same_cond/Prover.toml diff --git a/test_programs/execution_success/return_array_witness_if_cond/src/main.nr b/test_programs/execution_success/nested_if_then_block_same_cond/src/main.nr similarity index 100% rename from test_programs/execution_success/return_array_witness_if_cond/src/main.nr rename to test_programs/execution_success/nested_if_then_block_same_cond/src/main.nr diff --git a/test_programs/execution_success/nested_if_then_block_same_cond/stdout.txt b/test_programs/execution_success/nested_if_then_block_same_cond/stdout.txt new file mode 100644 index 00000000000..9d6b1827fc1 --- /dev/null +++ b/test_programs/execution_success/nested_if_then_block_same_cond/stdout.txt @@ -0,0 +1 @@ +[nested_if_then_block_same_cond] Circuit output: Vec([Field(1), Field(0)]) \ No newline at end of file diff --git a/test_programs/execution_success/return_array_witness_if_cond/stdout.txt b/test_programs/execution_success/return_array_witness_if_cond/stdout.txt deleted file mode 100644 index 95253ddbdb5..00000000000 --- a/test_programs/execution_success/return_array_witness_if_cond/stdout.txt +++ /dev/null @@ -1 +0,0 @@ -[return_array_witness_if_cond] Circuit output: Vec([Field(1), Field(0)]) \ No newline at end of file diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..d8c5772cf2c --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap @@ -0,0 +1,52 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": {} + }, + "bytecode": "H4sIAAAAAAAA/7WSYQrDIAyFq66ru01itMZ/u8pk9v5HWEsjyOa/2Qch+omRJ09Np+xeD1mrvYz0um+Z6jDdYabDbh02d9i9eb9KS39KJ1i9L9EVJHyBS5kD+JBXRsbA4e2YqLDnmHKKkNBTwS0k2uCUambBf8Jl3Cy40rMe6NkO9FyzcWhp/NdsGTmfJRvf/3PcsdOvPiwHCgvgAgAA", + "debug_symbols": "XYxLCoAwDAXvkrUn8Coi0k9aAqEpsRWk9O5+cCFdzhveNPBoa9woBdlhXhqwOFNI0k2tT2CVmCluw3wYJWMZPww1uZ8tZ8bhn1Uc+qr4lF7X134B", + "file_map": {}, + "names": [ + "main" + ], + "brillig_names": [] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_0.snap new file mode 100644 index 00000000000..d8c5772cf2c --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_0.snap @@ -0,0 +1,52 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": {} + }, + "bytecode": "H4sIAAAAAAAA/7WSYQrDIAyFq66ru01itMZ/u8pk9v5HWEsjyOa/2Qch+omRJ09Np+xeD1mrvYz0um+Z6jDdYabDbh02d9i9eb9KS39KJ1i9L9EVJHyBS5kD+JBXRsbA4e2YqLDnmHKKkNBTwS0k2uCUambBf8Jl3Cy40rMe6NkO9FyzcWhp/NdsGTmfJRvf/3PcsdOvPiwHCgvgAgAA", + "debug_symbols": "XYxLCoAwDAXvkrUn8Coi0k9aAqEpsRWk9O5+cCFdzhveNPBoa9woBdlhXhqwOFNI0k2tT2CVmCluw3wYJWMZPww1uZ8tZ8bhn1Uc+qr4lF7X134B", + "file_map": {}, + "names": [ + "main" + ], + "brillig_names": [] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..d8c5772cf2c --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_false_inliner_9223372036854775807.snap @@ -0,0 +1,52 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": {} + }, + "bytecode": "H4sIAAAAAAAA/7WSYQrDIAyFq66ru01itMZ/u8pk9v5HWEsjyOa/2Qch+omRJ09Np+xeD1mrvYz0um+Z6jDdYabDbh02d9i9eb9KS39KJ1i9L9EVJHyBS5kD+JBXRsbA4e2YqLDnmHKKkNBTwS0k2uCUambBf8Jl3Cy40rMe6NkO9FyzcWhp/NdsGTmfJRvf/3PcsdOvPiwHCgvgAgAA", + "debug_symbols": "XYxLCoAwDAXvkrUn8Coi0k9aAqEpsRWk9O5+cCFdzhveNPBoa9woBdlhXhqwOFNI0k2tT2CVmCluw3wYJWMZPww1uZ8tZ8bhn1Uc+qr4lF7X134B", + "file_map": {}, + "names": [ + "main" + ], + "brillig_names": [] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..356c1cf2f75 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap @@ -0,0 +1,68 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": { + "12049594436772143978": { + "error_kind": "string", + "string": "array ref-count underflow detected" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1ZzY7aMBCeBAcIu2hR+yIhCQ1HDt3fy0q9tT0FED301EPVSyvl0Yu1nvB5kqiVyGiVFZaQnczn+R/HNgG9tOnxF7ixcX1IzcaYjeuT89qyR16J1W2srG/Qo75aOoYD0HE0AB3NAHSMBqDjmPqtcdaR16cJvaxf9QMJkE02G0zrLFwgWhmAAyrXxwIfOJ6bnhwUC7l98l8n+T4mv/WsfxYDTwX+BfM3OvwTzpmPlc+fhNyRwMk5iLkFzG0H5g4wdx2Ye8Dcd2AeAPPQgXkEzGMH5gkwTwIzd+PgBKlt5/ho1Mcxf1fK8c/m5Mcc7WbZkY7sPBDyMB5IY/kzUq21ZSDksT7SP6Hwz0RHn4T5T5X4s71xi72YzxNh75WOPinn4gz0kbl4rSM7+99cZPkzoatWLl5TMzboH47TnDHVSZ9Y0EzVtINpEdA4vjbvnsE+pKE+uD5wri6omSust3LdpMp1s7zUTd0udQO0gddNrlw36aVu6napG6Bp1w3HWe7RWeYXGH8V8sMW+RgzuRfU2JsezwFb5XNA2hZPGWtT+bKRhvE04M9n4R+lc9JW+RyevqfuHOJ8mFRUt5HwJ/qIfTZFvKDFQDOVL2fmng3IQV6sRyTwn93zjevHMIfnL1rkj4V8T++Wd+gjyWvU8o7x9n7qkxtfuZ/NoV88h1RroF4D8Z6s7fvE8m+ouR7x3Ij8teI72FiK+bjeR8JWpXu3+uzHtpgOW1m3kJq+5zHay+++ud7G74/gJ795XWvqgpr+ZZy8t0Cc9fFPN37LPv7h+tf2sbwfwzm2hnlfYCqfvnHvkzNasT5djPMaGpF/X0NCfiTwv90z7q24P+ePkENRLg9ZeShX5X6f78p3gr9tIfipb/llka13ab4rtquszD78U/5fzDlg8xEdAAA=", + "debug_symbols": "ldRRC4MgEAfw73LPPuhlK/sqYwwrG4JYWA1G9N2nsbFYvdyL+Bd/KBx3C7Smnh9367t+hOq6gOsbPdnex7SsDOpgnbOP+/4YeFoUbvfHQfsUx0mHCSpRXhgY38ad4tF31hmocr7eGKiMLCRZFGcC86/Ay0GUZKGoQnBOJ4JOkE4yOpF0cl4V5F+C8kBKOlFkIjidCDpBOsnoRNLIGtNTB6trZz7d3s2+2TX/9BrM3xwYQt+Ydg4mTYTfMEi/LRQr1VaHGIRQTKDc/pUi5jEW8c347hs=", + "file_map": { + "50": { + "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n if (!!a) {\n if (!!a) {\n b[0]\n } else {\n b[0]\n }\n } else {\n b[0]\n }\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_0.snap new file mode 100644 index 00000000000..356c1cf2f75 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_0.snap @@ -0,0 +1,68 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": { + "12049594436772143978": { + "error_kind": "string", + "string": "array ref-count underflow detected" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1ZzY7aMBCeBAcIu2hR+yIhCQ1HDt3fy0q9tT0FED301EPVSyvl0Yu1nvB5kqiVyGiVFZaQnczn+R/HNgG9tOnxF7ixcX1IzcaYjeuT89qyR16J1W2srG/Qo75aOoYD0HE0AB3NAHSMBqDjmPqtcdaR16cJvaxf9QMJkE02G0zrLFwgWhmAAyrXxwIfOJ6bnhwUC7l98l8n+T4mv/WsfxYDTwX+BfM3OvwTzpmPlc+fhNyRwMk5iLkFzG0H5g4wdx2Ye8Dcd2AeAPPQgXkEzGMH5gkwTwIzd+PgBKlt5/ho1Mcxf1fK8c/m5Mcc7WbZkY7sPBDyMB5IY/kzUq21ZSDksT7SP6Hwz0RHn4T5T5X4s71xi72YzxNh75WOPinn4gz0kbl4rSM7+99cZPkzoatWLl5TMzboH47TnDHVSZ9Y0EzVtINpEdA4vjbvnsE+pKE+uD5wri6omSust3LdpMp1s7zUTd0udQO0gddNrlw36aVu6napG6Bp1w3HWe7RWeYXGH8V8sMW+RgzuRfU2JsezwFb5XNA2hZPGWtT+bKRhvE04M9n4R+lc9JW+RyevqfuHOJ8mFRUt5HwJ/qIfTZFvKDFQDOVL2fmng3IQV6sRyTwn93zjevHMIfnL1rkj4V8T++Wd+gjyWvU8o7x9n7qkxtfuZ/NoV88h1RroF4D8Z6s7fvE8m+ouR7x3Ij8teI72FiK+bjeR8JWpXu3+uzHtpgOW1m3kJq+5zHay+++ud7G74/gJ795XWvqgpr+ZZy8t0Cc9fFPN37LPv7h+tf2sbwfwzm2hnlfYCqfvnHvkzNasT5djPMaGpF/X0NCfiTwv90z7q24P+ePkENRLg9ZeShX5X6f78p3gr9tIfipb/llka13ab4rtquszD78U/5fzDlg8xEdAAA=", + "debug_symbols": "ldRRC4MgEAfw73LPPuhlK/sqYwwrG4JYWA1G9N2nsbFYvdyL+Bd/KBx3C7Smnh9367t+hOq6gOsbPdnex7SsDOpgnbOP+/4YeFoUbvfHQfsUx0mHCSpRXhgY38ad4tF31hmocr7eGKiMLCRZFGcC86/Ay0GUZKGoQnBOJ4JOkE4yOpF0cl4V5F+C8kBKOlFkIjidCDpBOsnoRNLIGtNTB6trZz7d3s2+2TX/9BrM3xwYQt+Ydg4mTYTfMEi/LRQr1VaHGIRQTKDc/pUi5jEW8c347hs=", + "file_map": { + "50": { + "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n if (!!a) {\n if (!!a) {\n b[0]\n } else {\n b[0]\n }\n } else {\n b[0]\n }\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..356c1cf2f75 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/nested_if_then_block_same_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap @@ -0,0 +1,68 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "a", + "type": { + "kind": "boolean" + }, + "visibility": "private" + }, + { + "name": "b", + "type": { + "kind": "array", + "length": 3, + "type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + } + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "array", + "length": 2, + "type": { + "kind": "boolean" + } + }, + "visibility": "public" + }, + "error_types": { + "12049594436772143978": { + "error_kind": "string", + "string": "array ref-count underflow detected" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1ZzY7aMBCeBAcIu2hR+yIhCQ1HDt3fy0q9tT0FED301EPVSyvl0Yu1nvB5kqiVyGiVFZaQnczn+R/HNgG9tOnxF7ixcX1IzcaYjeuT89qyR16J1W2srG/Qo75aOoYD0HE0AB3NAHSMBqDjmPqtcdaR16cJvaxf9QMJkE02G0zrLFwgWhmAAyrXxwIfOJ6bnhwUC7l98l8n+T4mv/WsfxYDTwX+BfM3OvwTzpmPlc+fhNyRwMk5iLkFzG0H5g4wdx2Ye8Dcd2AeAPPQgXkEzGMH5gkwTwIzd+PgBKlt5/ho1Mcxf1fK8c/m5Mcc7WbZkY7sPBDyMB5IY/kzUq21ZSDksT7SP6Hwz0RHn4T5T5X4s71xi72YzxNh75WOPinn4gz0kbl4rSM7+99cZPkzoatWLl5TMzboH47TnDHVSZ9Y0EzVtINpEdA4vjbvnsE+pKE+uD5wri6omSust3LdpMp1s7zUTd0udQO0gddNrlw36aVu6napG6Bp1w3HWe7RWeYXGH8V8sMW+RgzuRfU2JsezwFb5XNA2hZPGWtT+bKRhvE04M9n4R+lc9JW+RyevqfuHOJ8mFRUt5HwJ/qIfTZFvKDFQDOVL2fmng3IQV6sRyTwn93zjevHMIfnL1rkj4V8T++Wd+gjyWvU8o7x9n7qkxtfuZ/NoV88h1RroF4D8Z6s7fvE8m+ouR7x3Ij8teI72FiK+bjeR8JWpXu3+uzHtpgOW1m3kJq+5zHay+++ud7G74/gJ795XWvqgpr+ZZy8t0Cc9fFPN37LPv7h+tf2sbwfwzm2hnlfYCqfvnHvkzNasT5djPMaGpF/X0NCfiTwv90z7q24P+ePkENRLg9ZeShX5X6f78p3gr9tIfipb/llka13ab4rtquszD78U/5fzDlg8xEdAAA=", + "debug_symbols": "ldRRC4MgEAfw73LPPuhlK/sqYwwrG4JYWA1G9N2nsbFYvdyL+Bd/KBx3C7Smnh9367t+hOq6gOsbPdnex7SsDOpgnbOP+/4YeFoUbvfHQfsUx0mHCSpRXhgY38ad4tF31hmocr7eGKiMLCRZFGcC86/Ay0GUZKGoQnBOJ4JOkE4yOpF0cl4V5F+C8kBKOlFkIjidCDpBOsnoRNLIGtNTB6trZz7d3s2+2TX/9BrM3xwYQt+Ydg4mTYTfMEi/LRQr1VaHGIRQTKDc/pUi5jEW8c347hs=", + "file_map": { + "50": { + "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n if (!!a) {\n if (!!a) {\n b[0]\n } else {\n b[0]\n }\n } else {\n b[0]\n }\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} From bccc61d5072f2379fe8dfd3a890df00e879ae47d Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 11 Apr 2025 20:14:21 +0000 Subject: [PATCH 4/7] remove old snapshosts --- ...lig_true_inliner_-9223372036854775808.snap | 68 ------------------- ...__tests__force_brillig_true_inliner_0.snap | 68 ------------------- ...llig_true_inliner_9223372036854775807.snap | 68 ------------------- 3 files changed, 204 deletions(-) delete mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap delete mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_0.snap delete mode 100644 tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap deleted file mode 100644 index 14669d2d268..00000000000 --- a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap +++ /dev/null @@ -1,68 +0,0 @@ ---- -source: tooling/nargo_cli/tests/execute.rs -expression: artifact ---- -{ - "noir_version": "[noir_version]", - "hash": "[hash]", - "abi": { - "parameters": [ - { - "name": "a", - "type": { - "kind": "boolean" - }, - "visibility": "private" - }, - { - "name": "b", - "type": { - "kind": "array", - "length": 3, - "type": { - "kind": "array", - "length": 2, - "type": { - "kind": "boolean" - } - } - }, - "visibility": "private" - } - ], - "return_type": { - "abi_type": { - "kind": "array", - "length": 2, - "type": { - "kind": "boolean" - } - }, - "visibility": "public" - }, - "error_types": { - "12049594436772143978": { - "error_kind": "string", - "string": "array ref-count underflow detected" - }, - "17843811134343075018": { - "error_kind": "string", - "string": "Stack too deep" - } - } - }, - "bytecode": "H4sIAAAAAAAA/+1ZTW+bQBBd8IKNE8tW+0cw4OKjD83nJVJvbU/YrqWeeuiph6ocWqk/O15lBz+GJYlkJhGRV7J2Yd/Ox5uZBdaeemij/c+zY217XzUbYVa2j49r8w5lxca2UNher0N7pWz0e2DjoAc26h7YGPTAxlB1W+NkI+1PQ/Wwf1UXioFMsplgGrJwg3AKAAL+2z5ieM/KXHVEUMT0dil/GWfbSNVbx/anEcgUkJ+TfC0jP6ac+VjW5Sumd8BwfA1iLgBz0YK5BMxlC+YKMFctmGvAXLdgbgBz04K5Bcwtw0zs2DtAKt8pPhL1sc/fhXD804mqxxz9Jt2BjO7MY/owHjhH+sdKtNbmHtNH9nB+fMbPUMaemOSPhOSTv5HDX8znIfP3TMaehHJxDPbwXDyX0Z0+NxdJ/5jZKpWL56oZG+SH4jQhTHmwJ2Jzumz6QXMBzFF8Td7dgX84h/bg/kC5OlPNXCG7hesmEa6b+aluqnaqG5jred1kwnWTnOqmaqe6gTnpuqE483d00vkFxl+Zft+hH2PG3wUl3k333wFr4e+AxBVPHmtd1nXjHMZTA593jB+h76S18Hd48l615xDlw7BUVRswPpEj4myEeDYXwZwu63rG9lqDHpRFdgQM/9leT20fwhpaP3PoD5n+mt2Oe8gRlzVw3CO8OZ/6ZMdn9mdy6A+tUaI1UO2BeE7mej6R/qlq7kchm8N1wcv4EXM/NPiBOn3gH/Gcg4Dd+2Z7E5t/sKZtv8R7NJ45uPOZPsqfn7Y3+r/b8ZRhXPwKnVlW/BKXWrnzxAOfOfc0Rn/p3g/bu/jFZ89jzyMXv4TjZz6IMxz/tuO3zPEv2782x/xsEdeY/Y/eqXRZn1/Z+/ERLV8e/lSg50+g6mddiukPGP6vvcb3UuqP+RNplxfzXVrsikWx3Wab4h2Tb5oPPHWtv8jT5SbJNvl6kRbphyf13wOf+U+CTR4AAA==", - "debug_symbols": "ldTNqoQgAAXgd3Hdwp9M7VUul8HKBkEsrC5concfjWCGmdmcjXjED0Hl7GRw3Xa/+ThOC2l/dhKm3q5+ijntR0W65EPw99vrMqFlMPzcv8w2lrisNq2kZYZVxMWhzGT2ow+OtJIevxUxAhY1LCQsGlgoWGhYGFQwSnHCcMJx8vVNRK0uIiT7IA1OFE40TgxMGMUJwwnHydd34aa+CDf6gzQ4UTjRODEw4RQnDCccI0dOfzZ52wV3dfC4xf6lktf/2b2185ym3g1bcqWnnxVd+laZSpvz5+bAuKqY4OeFlShEjjKfmc99AA==", - "file_map": { - "50": { - "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n // let z = !!a;\n // println(z);\n let x = b[0];\n if (!!a) {\n if (!!a) {\n b[0]\n // x\n } else {\n b[0]\n // x\n }\n } else {\n b[0]\n // x\n }\n}", - "path": "" - } - }, - "names": [ - "main" - ], - "brillig_names": [ - "main" - ] -} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_0.snap deleted file mode 100644 index 14669d2d268..00000000000 --- a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_0.snap +++ /dev/null @@ -1,68 +0,0 @@ ---- -source: tooling/nargo_cli/tests/execute.rs -expression: artifact ---- -{ - "noir_version": "[noir_version]", - "hash": "[hash]", - "abi": { - "parameters": [ - { - "name": "a", - "type": { - "kind": "boolean" - }, - "visibility": "private" - }, - { - "name": "b", - "type": { - "kind": "array", - "length": 3, - "type": { - "kind": "array", - "length": 2, - "type": { - "kind": "boolean" - } - } - }, - "visibility": "private" - } - ], - "return_type": { - "abi_type": { - "kind": "array", - "length": 2, - "type": { - "kind": "boolean" - } - }, - "visibility": "public" - }, - "error_types": { - "12049594436772143978": { - "error_kind": "string", - "string": "array ref-count underflow detected" - }, - "17843811134343075018": { - "error_kind": "string", - "string": "Stack too deep" - } - } - }, - "bytecode": "H4sIAAAAAAAA/+1ZTW+bQBBd8IKNE8tW+0cw4OKjD83nJVJvbU/YrqWeeuiph6ocWqk/O15lBz+GJYlkJhGRV7J2Yd/Ox5uZBdaeemij/c+zY217XzUbYVa2j49r8w5lxca2UNher0N7pWz0e2DjoAc26h7YGPTAxlB1W+NkI+1PQ/Wwf1UXioFMsplgGrJwg3AKAAL+2z5ieM/KXHVEUMT0dil/GWfbSNVbx/anEcgUkJ+TfC0jP6ac+VjW5Sumd8BwfA1iLgBz0YK5BMxlC+YKMFctmGvAXLdgbgBz04K5Bcwtw0zs2DtAKt8pPhL1sc/fhXD804mqxxz9Jt2BjO7MY/owHjhH+sdKtNbmHtNH9nB+fMbPUMaemOSPhOSTv5HDX8znIfP3TMaehHJxDPbwXDyX0Z0+NxdJ/5jZKpWL56oZG+SH4jQhTHmwJ2Jzumz6QXMBzFF8Td7dgX84h/bg/kC5OlPNXCG7hesmEa6b+aluqnaqG5jred1kwnWTnOqmaqe6gTnpuqE483d00vkFxl+Zft+hH2PG3wUl3k333wFr4e+AxBVPHmtd1nXjHMZTA593jB+h76S18Hd48l615xDlw7BUVRswPpEj4myEeDYXwZwu63rG9lqDHpRFdgQM/9leT20fwhpaP3PoD5n+mt2Oe8gRlzVw3CO8OZ/6ZMdn9mdy6A+tUaI1UO2BeE7mej6R/qlq7kchm8N1wcv4EXM/NPiBOn3gH/Gcg4Dd+2Z7E5t/sKZtv8R7NJ45uPOZPsqfn7Y3+r/b8ZRhXPwKnVlW/BKXWrnzxAOfOfc0Rn/p3g/bu/jFZ89jzyMXv4TjZz6IMxz/tuO3zPEv2782x/xsEdeY/Y/eqXRZn1/Z+/ERLV8e/lSg50+g6mddiukPGP6vvcb3UuqP+RNplxfzXVrsikWx3Wab4h2Tb5oPPHWtv8jT5SbJNvl6kRbphyf13wOf+U+CTR4AAA==", - "debug_symbols": "ldTNqoQgAAXgd3Hdwp9M7VUul8HKBkEsrC5concfjWCGmdmcjXjED0Hl7GRw3Xa/+ThOC2l/dhKm3q5+ijntR0W65EPw99vrMqFlMPzcv8w2lrisNq2kZYZVxMWhzGT2ow+OtJIevxUxAhY1LCQsGlgoWGhYGFQwSnHCcMJx8vVNRK0uIiT7IA1OFE40TgxMGMUJwwnHydd34aa+CDf6gzQ4UTjRODEw4RQnDCccI0dOfzZ52wV3dfC4xf6lktf/2b2185ym3g1bcqWnnxVd+laZSpvz5+bAuKqY4OeFlShEjjKfmc99AA==", - "file_map": { - "50": { - "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n // let z = !!a;\n // println(z);\n let x = b[0];\n if (!!a) {\n if (!!a) {\n b[0]\n // x\n } else {\n b[0]\n // x\n }\n } else {\n b[0]\n // x\n }\n}", - "path": "" - } - }, - "names": [ - "main" - ], - "brillig_names": [ - "main" - ] -} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap deleted file mode 100644 index 14669d2d268..00000000000 --- a/tooling/nargo_cli/tests/snapshots/execution_success/return_array_witness_if_cond/execute__tests__force_brillig_true_inliner_9223372036854775807.snap +++ /dev/null @@ -1,68 +0,0 @@ ---- -source: tooling/nargo_cli/tests/execute.rs -expression: artifact ---- -{ - "noir_version": "[noir_version]", - "hash": "[hash]", - "abi": { - "parameters": [ - { - "name": "a", - "type": { - "kind": "boolean" - }, - "visibility": "private" - }, - { - "name": "b", - "type": { - "kind": "array", - "length": 3, - "type": { - "kind": "array", - "length": 2, - "type": { - "kind": "boolean" - } - } - }, - "visibility": "private" - } - ], - "return_type": { - "abi_type": { - "kind": "array", - "length": 2, - "type": { - "kind": "boolean" - } - }, - "visibility": "public" - }, - "error_types": { - "12049594436772143978": { - "error_kind": "string", - "string": "array ref-count underflow detected" - }, - "17843811134343075018": { - "error_kind": "string", - "string": "Stack too deep" - } - } - }, - "bytecode": "H4sIAAAAAAAA/+1ZTW+bQBBd8IKNE8tW+0cw4OKjD83nJVJvbU/YrqWeeuiph6ocWqk/O15lBz+GJYlkJhGRV7J2Yd/Ox5uZBdaeemij/c+zY217XzUbYVa2j49r8w5lxca2UNher0N7pWz0e2DjoAc26h7YGPTAxlB1W+NkI+1PQ/Wwf1UXioFMsplgGrJwg3AKAAL+2z5ieM/KXHVEUMT0dil/GWfbSNVbx/anEcgUkJ+TfC0jP6ac+VjW5Sumd8BwfA1iLgBz0YK5BMxlC+YKMFctmGvAXLdgbgBz04K5Bcwtw0zs2DtAKt8pPhL1sc/fhXD804mqxxz9Jt2BjO7MY/owHjhH+sdKtNbmHtNH9nB+fMbPUMaemOSPhOSTv5HDX8znIfP3TMaehHJxDPbwXDyX0Z0+NxdJ/5jZKpWL56oZG+SH4jQhTHmwJ2Jzumz6QXMBzFF8Td7dgX84h/bg/kC5OlPNXCG7hesmEa6b+aluqnaqG5jred1kwnWTnOqmaqe6gTnpuqE483d00vkFxl+Zft+hH2PG3wUl3k333wFr4e+AxBVPHmtd1nXjHMZTA593jB+h76S18Hd48l615xDlw7BUVRswPpEj4myEeDYXwZwu63rG9lqDHpRFdgQM/9leT20fwhpaP3PoD5n+mt2Oe8gRlzVw3CO8OZ/6ZMdn9mdy6A+tUaI1UO2BeE7mej6R/qlq7kchm8N1wcv4EXM/NPiBOn3gH/Gcg4Dd+2Z7E5t/sKZtv8R7NJ45uPOZPsqfn7Y3+r/b8ZRhXPwKnVlW/BKXWrnzxAOfOfc0Rn/p3g/bu/jFZ89jzyMXv4TjZz6IMxz/tuO3zPEv2782x/xsEdeY/Y/eqXRZn1/Z+/ERLV8e/lSg50+g6mddiukPGP6vvcb3UuqP+RNplxfzXVrsikWx3Wab4h2Tb5oPPHWtv8jT5SbJNvl6kRbphyf13wOf+U+CTR4AAA==", - "debug_symbols": "ldTNqoQgAAXgd3Hdwp9M7VUul8HKBkEsrC5concfjWCGmdmcjXjED0Hl7GRw3Xa/+ThOC2l/dhKm3q5+ijntR0W65EPw99vrMqFlMPzcv8w2lrisNq2kZYZVxMWhzGT2ow+OtJIevxUxAhY1LCQsGlgoWGhYGFQwSnHCcMJx8vVNRK0uIiT7IA1OFE40TgxMGMUJwwnHydd34aa+CDf6gzQ4UTjRODEw4RQnDCccI0dOfzZ52wV3dfC4xf6lktf/2b2185ym3g1bcqWnnxVd+laZSpvz5+bAuKqY4OeFlShEjjKfmc99AA==", - "file_map": { - "50": { - "source": "// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)\nfn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {\n // let z = !!a;\n // println(z);\n let x = b[0];\n if (!!a) {\n if (!!a) {\n b[0]\n // x\n } else {\n b[0]\n // x\n }\n } else {\n b[0]\n // x\n }\n}", - "path": "" - } - }, - "names": [ - "main" - ], - "brillig_names": [ - "main" - ] -} From cd6fc16c48a06d31aafe3adcb8ad1bb0b38f3bc3 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 11 Apr 2025 16:19:39 -0400 Subject: [PATCH 5/7] Reduce diff --- compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs index f50ef353e04..aec25a4b958 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -687,7 +687,6 @@ impl FunctionContext<'_> { /// ``` fn codegen_if(&mut self, if_expr: &ast::If) -> Result { let condition = self.codegen_non_tuple_expression(&if_expr.condition)?; - if let Some(result) = self.try_codegen_constant_if(condition, if_expr) { return result; } From a04008ffb9f2b08e36f9ad83e5ee627e1b0cec53 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Fri, 11 Apr 2025 16:19:54 -0400 Subject: [PATCH 6/7] Reduce diff --- compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs index 03cc257e306..da4f5a0014a 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs @@ -648,7 +648,6 @@ impl<'f> Context<'f> { self.inserter.function.dfg.make_constant(FieldElement::one(), NumericType::bool()) } }; - let enable_side_effects = Instruction::EnableSideEffectsIf { condition }; let call_stack = self.inserter.function.dfg.get_value_call_stack_id(condition); self.insert_instruction_with_typevars(enable_side_effects, None, call_stack); From ec4990138ff7552212049e05a657f8a92fe07290 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Mon, 14 Apr 2025 17:03:16 +0000 Subject: [PATCH 7/7] add flattening SSA gen test --- .../src/ssa/opt/flatten_cfg.rs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs index da4f5a0014a..727252e449a 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs @@ -1522,4 +1522,73 @@ mod test { } "); } + + #[test] + fn do_not_replace_else_condition_with_nested_if_same_then_cond() { + // When inserting an `IfElse` instruction we will attempt to simplify when the then condition + // of the inner if-else matches the parent's if-else then condition. + // e.g. such as the following pseudocode: + // ``` + // if cond { + // if cond { ... } else { ... } + // } else { + // ... + // } + // ``` + // In the SSA below we can see how the jmpif condition in b0 matches the jmpif condition in b1. + let src = " + acir(inline) pure fn main f0 { + b0(v0: u1, v1: [[u1; 2]; 3]): + v4 = not v0 + jmpif v0 then: b1, else: b2 + b1(): + v7 = not v0 + jmpif v0 then: b3, else: b4 + b2(): + v6 = array_get v1, index u32 0 -> [u1; 2] + jmp b5(v6) + b3(): + v9 = array_get v1, index u32 0 -> [u1; 2] + jmp b6(v9) + b4(): + v8 = array_get v1, index u32 0 -> [u1; 2] + jmp b6(v8) + b5(v2: [u1; 2]): + return v2 + b6(v3: [u1; 2]): + jmp b5(v3) + } + "; + + let ssa = Ssa::from_str(src).unwrap(); + let ssa = ssa.flatten_cfg(); + + // You will notice in the expected SSA that there is no nested if statement. This is because the + // final instruction `v12 = if v0 then v5 else (if v6) v10` used to have `v9` as its then block value. + // As they share the same then condition we can simplify the then value in the outer if-else statement to the inner if-else + // statement's then value. This is why the then value is `v5` in both if-else instructions below. + // We want to make sure that the else condition in the final instruction `v12 = if v0 then v5 else (if v6) v10` + // remains v6 and is not altered when performing this optimization. + assert_ssa_snapshot!(ssa, @r" + acir(inline) pure fn main f0 { + b0(v0: u1, v1: [[u1; 2]; 3]): + v2 = not v0 + enable_side_effects v0 + v3 = not v0 + enable_side_effects v0 + v5 = array_get v1, index u32 0 -> [u1; 2] + v6 = not v0 + v7 = unchecked_mul v0, v6 + enable_side_effects v7 + v8 = array_get v1, index u32 0 -> [u1; 2] + enable_side_effects v0 + v9 = if v0 then v5 else (if v7) v8 + enable_side_effects v6 + v10 = array_get v1, index u32 0 -> [u1; 2] + enable_side_effects u1 1 + v12 = if v0 then v5 else (if v6) v10 + return v12 + } + "); + } }