From 89003e1652a41419a1b6dd14f0a8a0769911a7cc Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 27 Dec 2019 15:21:37 +0000 Subject: TypecheckContext doesn't need Rc It's almost never cloned anymore --- dhall/src/semantics/core/context.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'dhall') diff --git a/dhall/src/semantics/core/context.rs b/dhall/src/semantics/core/context.rs index 79f2737..c198e8e 100644 --- a/dhall/src/semantics/core/context.rs +++ b/dhall/src/semantics/core/context.rs @@ -1,5 +1,4 @@ use std::collections::HashMap; -use std::rc::Rc; use crate::error::TypeError; use crate::semantics::core::value::Value; @@ -14,21 +13,24 @@ enum CtxItem { } #[derive(Debug, Clone)] -pub(crate) struct TypecheckContext(Rc>); +pub(crate) struct TypecheckContext(Vec<(Label, CtxItem)>); impl TypecheckContext { pub fn new() -> Self { - TypecheckContext(Rc::new(Vec::new())) + TypecheckContext(Vec::new()) + } + fn with_vec(&self, vec: Vec<(Label, CtxItem)>) -> Self { + TypecheckContext(vec) } pub fn insert_type(&self, x: &Label, t: Value) -> Self { - let mut vec = self.0.as_ref().clone(); + let mut vec = self.0.clone(); vec.push((x.clone(), CtxItem::Kept(x.into(), t.under_binder(x)))); - TypecheckContext(Rc::new(vec)) + self.with_vec(vec) } pub fn insert_value(&self, x: &Label, e: Value) -> Result { - let mut vec = self.0.as_ref().clone(); + let mut vec = self.0.clone(); vec.push((x.clone(), CtxItem::Replaced(e))); - Ok(TypecheckContext(Rc::new(vec))) + Ok(self.with_vec(vec)) } pub fn lookup(&self, var: &V