From 4fd96b976f3d4bdd5375d217189bf83b7ce3080c Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Fri, 17 Feb 2023 10:10:17 -0600 Subject: [PATCH 1/2] Clone expression parser instead of using exponential recursion --- crates/noirc_frontend/src/parser/parser.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/noirc_frontend/src/parser/parser.rs b/crates/noirc_frontend/src/parser/parser.rs index 56e21f59f3..624700b214 100644 --- a/crates/noirc_frontend/src/parser/parser.rs +++ b/crates/noirc_frontend/src/parser/parser.rs @@ -592,14 +592,12 @@ where let next_precedence = if is_type_expression { precedence.next_type_precedence() } else { precedence.next() }; - expression_with_precedence(precedence.next(), expr_parser.clone(), is_type_expression) - .then( - then_commit( - operator_with_precedence(precedence), - expression_with_precedence(next_precedence, expr_parser, is_type_expression), - ) - .repeated(), - ) + let next_expr = + expression_with_precedence(next_precedence, expr_parser.clone(), is_type_expression); + + next_expr + .clone() + .then(then_commit(operator_with_precedence(precedence), next_expr).repeated()) .foldl(create_infix_expression) .boxed() .labelled("expression") From 1cf4322315939d423914d75f68aad52e93e6b03d Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Fri, 17 Feb 2023 10:32:50 -0600 Subject: [PATCH 2/2] Remove redundant clone --- crates/noirc_frontend/src/parser/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/noirc_frontend/src/parser/parser.rs b/crates/noirc_frontend/src/parser/parser.rs index 624700b214..e9198ad8f0 100644 --- a/crates/noirc_frontend/src/parser/parser.rs +++ b/crates/noirc_frontend/src/parser/parser.rs @@ -593,7 +593,7 @@ where if is_type_expression { precedence.next_type_precedence() } else { precedence.next() }; let next_expr = - expression_with_precedence(next_precedence, expr_parser.clone(), is_type_expression); + expression_with_precedence(next_precedence, expr_parser, is_type_expression); next_expr .clone()