From 627287185118482ceb7132f6dedad7111dccf972 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 6 Apr 2019 00:06:13 +0200 Subject: Give up on laziness and greatly simplify normalization --- dhall_core/src/core.rs | 63 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 10 deletions(-) (limited to 'dhall_core') diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 0d4789a..db83a1e 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -287,6 +287,15 @@ impl Expr { let recurse = |e: &Self| -> Self { e.map_label(map_label) }; self.map_shallow(recurse, |x| x.clone(), |x| x.clone(), map_label) } + + #[inline(always)] + pub fn roll(&self) -> SubExpr + where + S: Clone, + A: Clone, + { + rc(ExprF::clone(self)) + } } impl Expr> { @@ -433,8 +442,8 @@ impl ExprF { } #[inline(always)] - pub fn map_ref( - &self, + pub fn map_ref<'a, SE2, L2, N2, E2, F1, F2, F3, F4, F5>( + &'a self, map_subexpr: F1, map_under_binder: F2, map_note: F3, @@ -444,11 +453,11 @@ impl ExprF { where L: Ord, L2: Ord, - F1: FnMut(&SE) -> SE2, - F2: FnOnce(&L, &SE) -> SE2, - F3: FnOnce(&N) -> N2, - F4: FnOnce(&E) -> E2, - F5: FnMut(&L) -> L2, + F1: FnMut(&'a SE) -> SE2, + F2: FnOnce(&'a L, &'a SE) -> SE2, + F3: FnOnce(&'a N) -> N2, + F4: FnOnce(&'a E) -> E2, + F5: FnMut(&'a L) -> L2, { // Not optimal: reallocates all the Vecs and BTreeMaps for nothing. self.as_ref().map( @@ -460,6 +469,27 @@ impl ExprF { ) } + #[inline(always)] + pub fn map_ref_simple<'a, SE2, F1>( + &'a self, + map_subexpr: F1, + ) -> ExprF + where + L: Ord, + L: Clone, + N: Clone, + E: Clone, + F1: Fn(&'a SE) -> SE2, + { + self.map_ref( + &map_subexpr, + |_, e| map_subexpr(e), + N::clone, + E::clone, + L::clone, + ) + } + // #[inline(always)] // pub fn zip( // self, @@ -510,10 +540,14 @@ impl SubExpr { self.0.as_ref() } - pub fn map_ref(&self, map_expr: F1, map_under_binder: F2) -> Self + pub fn map_ref<'a, F1, F2>( + &'a self, + map_expr: F1, + map_under_binder: F2, + ) -> Self where - F1: FnMut(&Self) -> Self, - F2: FnOnce(&Label, &Self) -> Self, + F1: FnMut(&'a Self) -> Self, + F2: FnOnce(&'a Label, &'a Self) -> Self, { match self.as_ref() { ExprF::Embed(_) => SubExpr::clone(self), @@ -536,6 +570,15 @@ impl SubExpr { { self.map_ref(&map_expr, |_, e| map_expr(e)) } + + #[inline(always)] + pub fn unroll(&self) -> Expr + where + N: Clone, + E: Clone, + { + ExprF::clone(self.as_ref()) + } } impl Clone for SubExpr { -- cgit v1.2.3