diff options
author | Nadrieril | 2019-12-27 15:29:59 +0000 |
---|---|---|
committer | Nadrieril | 2020-01-17 10:06:00 +0000 |
commit | e97e0c8e9905582aef826504b59a1844c8f67613 (patch) | |
tree | 930dad8c248c6bb989f8adc41cf8862aec00a05e | |
parent | 89003e1652a41419a1b6dd14f0a8a0769911a7cc (diff) |
Make TypecheckContext a named struct
Diffstat (limited to '')
-rw-r--r-- | dhall/src/semantics/core/context.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/dhall/src/semantics/core/context.rs b/dhall/src/semantics/core/context.rs index c198e8e..5a0c320 100644 --- a/dhall/src/semantics/core/context.rs +++ b/dhall/src/semantics/core/context.rs @@ -13,29 +13,31 @@ enum CtxItem { } #[derive(Debug, Clone)] -pub(crate) struct TypecheckContext(Vec<(Label, CtxItem)>); +pub(crate) struct TypecheckContext { + ctx: Vec<(Label, CtxItem)>, +} impl TypecheckContext { pub fn new() -> Self { - TypecheckContext(Vec::new()) + TypecheckContext { ctx: Vec::new() } } fn with_vec(&self, vec: Vec<(Label, CtxItem)>) -> Self { - TypecheckContext(vec) + TypecheckContext { ctx: vec } } pub fn insert_type(&self, x: &Label, t: Value) -> Self { - let mut vec = self.0.clone(); + let mut vec = self.ctx.clone(); vec.push((x.clone(), CtxItem::Kept(x.into(), t.under_binder(x)))); self.with_vec(vec) } pub fn insert_value(&self, x: &Label, e: Value) -> Result<Self, TypeError> { - let mut vec = self.0.clone(); + let mut vec = self.ctx.clone(); vec.push((x.clone(), CtxItem::Replaced(e))); Ok(self.with_vec(vec)) } pub fn lookup(&self, var: &V<Label>) -> Option<Value> { let mut var = var.clone(); let mut shift_map: HashMap<Label, _> = HashMap::new(); - for (l, i) in self.0.iter().rev() { + for (l, i) in self.ctx.iter().rev() { match var.over_binder(l) { None => { let i = i.under_multiple_binders(&shift_map); @@ -65,9 +67,9 @@ impl TypecheckContext { mut f: impl FnMut(&AlphaVar, &CtxItem) -> Result<CtxItem, E>, ) -> Result<Self, E> { let mut vec = Vec::new(); - vec.reserve(self.0.len()); + vec.reserve(self.ctx.len()); let mut var = var.clone(); - let mut iter = self.0.iter().rev(); + let mut iter = self.ctx.iter().rev(); for (l, i) in iter.by_ref() { vec.push((l.clone(), f(&var, i)?)); if let CtxItem::Kept(_, _) = i { @@ -89,7 +91,7 @@ impl TypecheckContext { } else { Some( self.with_vec( - self.0 + self.ctx .iter() .map(|(l, i)| Ok((l.clone(), i.shift(delta, &var)?))) .collect::<Result<_, _>>()?, |