From 32051979778436ea02cb406551f126fe22ea1636 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 9 May 2019 16:53:48 +0200 Subject: ExprF need not be generic in Label --- dhall_syntax/src/core/expr.rs | 74 ++++++++++++------------------------------- 1 file changed, 21 insertions(+), 53 deletions(-) (limited to 'dhall_syntax/src/core/expr.rs') diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 1a33ed1..3b73d88 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -150,14 +150,14 @@ impl std::cmp::PartialEq for SubExpr { impl std::cmp::Eq for SubExpr {} -pub type Expr = ExprF, Label, Embed>; +pub type Expr = ExprF, Embed>; /// Syntax tree for expressions // Having the recursion out of the enum definition enables writing // much more generic code and improves pattern-matching behind // smart pointers. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum ExprF { +pub enum ExprF { Const(Const), /// `x` /// `x@n` @@ -218,110 +218,79 @@ pub enum ExprF { Embed(Embed), } -impl ExprF { +impl ExprF { pub(crate) fn visit<'a, V, Return>(&'a self, v: V) -> Return where - V: visitor::GenericVisitor<&'a ExprF, Return>, + V: visitor::GenericVisitor<&'a ExprF, Return>, { v.visit(self) } - pub fn traverse_ref_with_special_handling_of_binders<'a, SE2, L2, E2, Err>( + pub fn traverse_ref_with_special_handling_of_binders<'a, SE2, E2, Err>( &'a self, visit_subexpr: impl FnMut(&'a SE) -> Result, - visit_under_binder: impl FnOnce(&'a L, &'a SE) -> Result, + visit_under_binder: impl FnOnce(&'a Label, &'a SE) -> Result, visit_embed: impl FnOnce(&'a E) -> Result, - visit_label: impl FnMut(&'a L) -> Result, - ) -> Result, Err> - where - L: Ord, - L2: Ord, - { + ) -> Result, Err> { self.visit(visitor::TraverseRefWithBindersVisitor { visit_subexpr, visit_under_binder, visit_embed, - visit_label, }) } - fn traverse_ref<'a, SE2, L2, E2, Err>( + fn traverse_ref<'a, SE2, E2, Err>( &'a self, visit_subexpr: impl FnMut(&'a SE) -> Result, visit_embed: impl FnOnce(&'a E) -> Result, - visit_label: impl FnMut(&'a L) -> Result, - ) -> Result, Err> - where - L: Ord, - L2: Ord, - { + ) -> Result, Err> { self.visit(visitor::TraverseRefVisitor { visit_subexpr, visit_embed, - visit_label, }) } - pub fn map_ref_with_special_handling_of_binders<'a, SE2, L2, E2>( + pub fn map_ref_with_special_handling_of_binders<'a, SE2, E2>( &'a self, mut map_subexpr: impl FnMut(&'a SE) -> SE2, - mut map_under_binder: impl FnMut(&'a L, &'a SE) -> SE2, + mut map_under_binder: impl FnMut(&'a Label, &'a SE) -> SE2, map_embed: impl FnOnce(&'a E) -> E2, - mut map_label: impl FnMut(&'a L) -> L2, - ) -> ExprF - where - L: Ord, - L2: Ord, - { + ) -> ExprF { trivial_result(self.traverse_ref_with_special_handling_of_binders( |x| Ok(map_subexpr(x)), |l, x| Ok(map_under_binder(l, x)), |x| Ok(map_embed(x)), - |x| Ok(map_label(x)), )) } - pub fn map_ref<'a, SE2, L2, E2>( + pub fn map_ref<'a, SE2, E2>( &'a self, mut map_subexpr: impl FnMut(&'a SE) -> SE2, map_embed: impl FnOnce(&'a E) -> E2, - mut map_label: impl FnMut(&'a L) -> L2, - ) -> ExprF - where - L: Ord, - L2: Ord, - { - trivial_result(self.traverse_ref( - |x| Ok(map_subexpr(x)), - |x| Ok(map_embed(x)), - |x| Ok(map_label(x)), - )) + ) -> ExprF { + trivial_result( + self.traverse_ref(|x| Ok(map_subexpr(x)), |x| Ok(map_embed(x))), + ) } pub fn traverse_ref_simple<'a, SE2, Err>( &'a self, visit_subexpr: impl FnMut(&'a SE) -> Result, - ) -> Result, Err> + ) -> Result, Err> where - L: Ord + Clone, E: Clone, { - self.traverse_ref( - visit_subexpr, - |x| Ok(E::clone(x)), - |x| Ok(L::clone(x)), - ) + self.traverse_ref(visit_subexpr, |x| Ok(E::clone(x))) } pub fn map_ref_simple<'a, SE2>( &'a self, map_subexpr: impl Fn(&'a SE) -> SE2, - ) -> ExprF + ) -> ExprF where - L: Ord + Clone, E: Clone, { - self.map_ref(map_subexpr, E::clone, L::clone) + self.map_ref(map_subexpr, E::clone) } } @@ -411,7 +380,6 @@ impl SubExpr { map_expr, map_under_binder, |_| unreachable!(), - Label::clone, )), } } -- cgit v1.2.3