From 0682a84eadc383e1d5747576298c9160737e0e99 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 18 Apr 2019 22:20:40 +0200 Subject: Label is redundant in EnvItem::Skip --- dhall/src/normalize.rs | 52 +++++++++++++++++++++++--------------------------- dhall/src/typecheck.rs | 5 +++-- 2 files changed, 27 insertions(+), 30 deletions(-) (limited to 'dhall/src') diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs index 4dc5156..7a9ca2f 100644 --- a/dhall/src/normalize.rs +++ b/dhall/src/normalize.rs @@ -216,34 +216,10 @@ where Continue(ExprF::App(ret, rest)) } -// Small enum to help with being DRY -enum WhatNext<'a, N, E> { - // Recurse on this expression - Continue(Expr), - // The following expression is the normal form - Done(Expr), - DoneRef(&'a Expr), - DoneSub(SubExpr), - DoneRefSub(&'a SubExpr), - // The current expression is already in normal form - DoneAsIs, -} - #[derive(Debug, Clone)] enum EnvItem { Expr(SubExpr), - Skip(Label, usize), -} - -impl EnvItem { - fn shift0(&self, delta: isize, label: &Label) -> Self { - use EnvItem::*; - match self { - Expr(e) => Expr(shift0(delta, label, e)), - Skip(l, n) if l == label => Skip(l.clone(), *n + 1), - Skip(l, n) => Skip(l.clone(), *n), - } - } + Skip(usize), } struct NormalizationContext(Context); @@ -258,20 +234,40 @@ impl NormalizationContext { fn skip(&self, x: &Label) -> NormalizationContext { NormalizationContext( self.0 - .map(|e| e.shift0(1, x)) - .insert(x.clone(), EnvItem::Skip(x.clone(), 0)), + .map(|l, e| { + use EnvItem::*; + match e { + Expr(e) => Expr(shift0(1, x, e)), + Skip(n) if l == x => Skip(*n + 1), + Skip(n) => Skip(*n), + } + }) + .insert(x.clone(), EnvItem::Skip(0)), ) } fn lookup(&self, var: &V