From f4a50a5da10eb2de1d7cf00ad6f6765605da366d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 18 Apr 2019 17:29:17 +0200 Subject: Make normalize manipulate SubExprs more directly --- dhall/src/normalize.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'dhall/src') diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs index 1561f01..80c2e9a 100644 --- a/dhall/src/normalize.rs +++ b/dhall/src/normalize.rs @@ -150,7 +150,7 @@ where ), // // fold/build fusion // (ListFold, [_, App(box Builtin(ListBuild), [_, x, rest..]), rest..]) => { - // normalize_ref(&App(bx(x.clone()), rest.to_vec())) + // normalize_value(&App(bx(x.clone()), rest.to_vec())) // } (OptionalFold, [_, NEOptionalLit(x), _, just, _, rest..]) => { let x = x.clone(); @@ -162,7 +162,7 @@ where } // // fold/build fusion // (OptionalFold, [_, App(box Builtin(OptionalBuild), [_, x, rest..]), rest..]) => { - // normalize_ref(&App(bx(x.clone()), rest.to_vec())) + // normalize_value(&App(bx(x.clone()), rest.to_vec())) // } (NaturalBuild, [g, rest..]) => { 'ret: { @@ -226,12 +226,12 @@ enum WhatNext<'a, N, E> { DoneAsIs, } -fn normalize_ref(expr: &Expr>) -> Expr { +fn normalize_value(expr: SubExpr>) -> SubExpr { use dhall_core::BinOp::*; use dhall_core::ExprF::*; // Recursively normalize all subexpressions let expr: ExprF, Label, X, Normalized<'static>> = - expr.map_ref_simple(|e| normalize_ref(e.as_ref())); + expr.as_ref().map_ref_simple(|e| normalize_value(e.clone()).unroll()); use WhatNext::*; // TODO: match by move @@ -325,17 +325,17 @@ fn normalize_ref(expr: &Expr>) -> Expr { }; match what_next { - Continue(e) => normalize_ref(&e.embed_absurd()), - ContinueSub(e) => normalize_ref(e.embed_absurd().as_ref()), - Done(e) => e, - DoneRef(e) => e.clone(), - DoneRefSub(e) => e.unroll(), - DoneAsIs => expr.map_ref_simple(ExprF::roll).map_ref( + Continue(e) => normalize_value(e.embed_absurd().roll()), + ContinueSub(e) => normalize_value(e.embed_absurd()), + Done(e) => e.roll(), + DoneRef(e) => e.roll(), + DoneRefSub(e) => e.clone(), + DoneAsIs => rc(expr.map_ref_simple(ExprF::roll).map_ref( SubExpr::clone, X::clone, |_| unreachable!(), Label::clone, - ), + )), } } @@ -349,7 +349,7 @@ fn normalize_ref(expr: &Expr>) -> Expr { /// leave ill-typed sub-expressions unevaluated. /// fn normalize(e: SubExpr>) -> SubExpr { - normalize_ref(e.as_ref()).roll() + normalize_value(e) } #[cfg(test)] -- cgit v1.2.3 From 588127bf4105d8d4629304521abc3d992326a63a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 18 Apr 2019 19:34:38 +0200 Subject: subst_shift in a single pass --- dhall/src/typecheck.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'dhall/src') diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index 5aaeb08..186384d 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -44,9 +44,9 @@ impl<'a> Normalized<'a> { fn unroll_ref(&self) -> &Expr { self.as_expr().as_ref() } - fn shift(&self, delta: isize, var: &V