diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 8805e49d5..652095f85 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -1102,14 +1102,17 @@ pub fn parse( parse_program(revset_str, state) } +/// `Some` for rewritten expression, or `None` to reuse the original expression. +type TransformedExpression = Option>; + fn transform_expression_bottom_up( expression: &Rc, - mut f: impl FnMut(&Rc) -> Option>, -) -> Option> { + mut f: impl FnMut(&Rc) -> TransformedExpression, +) -> TransformedExpression { try_transform_expression_bottom_up(expression, |expression| Ok(f(expression))).unwrap() } -type TransformResult = Result>, RevsetResolutionError>; +type TransformResult = Result; /// Walks `expression` tree and applies `f` recursively from leaf nodes. /// @@ -1251,7 +1254,7 @@ fn try_transform_expression_bottom_up( /// help further optimization (e.g. combine `file(_)` matchers.) /// c. Wraps union of filter and set (e.g. `author(_) | heads()`), to /// ensure inner filter wouldn't need to evaluate all the input sets. -fn internalize_filter(expression: &Rc) -> Option> { +fn internalize_filter(expression: &Rc) -> TransformedExpression { fn is_filter(expression: &RevsetExpression) -> bool { matches!( expression, @@ -1281,7 +1284,7 @@ fn internalize_filter(expression: &Rc) -> Option, expression2: &Rc, - ) -> Option> { + ) -> TransformedExpression { let recurse = |e1, e2| intersect_down(e1, e2).unwrap_or_else(|| e1.intersection(e2)); match (expression1.as_ref(), expression2.as_ref()) { // Don't reorder 'f1 & f2' @@ -1326,7 +1329,7 @@ fn internalize_filter(expression: &Rc) -> Option) -> Option> { +fn fold_redundant_expression(expression: &Rc) -> TransformedExpression { transform_expression_bottom_up(expression, |expression| match expression.as_ref() { RevsetExpression::NotIn(outer) => match outer.as_ref() { RevsetExpression::NotIn(inner) => Some(inner.clone()), @@ -1345,7 +1348,7 @@ fn fold_redundant_expression(expression: &Rc) -> Option) -> Option> { +fn fold_difference(expression: &Rc) -> TransformedExpression { fn to_difference( expression: &Rc, complement: &Rc, @@ -1387,7 +1390,7 @@ fn fold_difference(expression: &Rc) -> Option) -> Option> { +fn unfold_difference(expression: &Rc) -> TransformedExpression { transform_expression_bottom_up(expression, |expression| match expression.as_ref() { // roots..heads -> :heads & ~(:roots) RevsetExpression::Range { @@ -1409,7 +1412,7 @@ fn unfold_difference(expression: &Rc) -> Option) -> Option> { +fn fold_ancestors(expression: &Rc) -> TransformedExpression { transform_expression_bottom_up(expression, |expression| match expression.as_ref() { RevsetExpression::Ancestors { heads,