From 7680ff4d5ebe7b98cdc54bd0e90a8d22395f715f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 8 May 2019 00:33:49 +0200 Subject: shift on lookup instead of on insert --- dhall/src/core/context.rs | 77 ++++++++++++++++++++++++++++++++--------------- dhall/src/core/var.rs | 21 +++++++++++-- 2 files changed, 71 insertions(+), 27 deletions(-) diff --git a/dhall/src/core/context.rs b/dhall/src/core/context.rs index 73ad516..f07c638 100644 --- a/dhall/src/core/context.rs +++ b/dhall/src/core/context.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::rc::Rc; use dhall_syntax::{Label, V}; @@ -31,11 +32,7 @@ impl Context { where T: Shift + Clone, { - let mut vec: Vec<_> = self - .0 - .iter() - .map(|(l, i)| (l.clone(), i.shift(1, &x.into()))) - .collect(); + let mut vec = self.0.as_ref().clone(); vec.push((x.clone(), CtxItem::Kept(x.into(), t.shift(1, &x.into())))); Context(Rc::new(vec)) } @@ -47,18 +44,58 @@ impl Context { vec.push((x.clone(), CtxItem::Replaced(th, t))); Context(Rc::new(vec)) } - pub(crate) fn lookup(&self, var: &V