use std::collections::HashMap; use std::rc::Rc; use dhall_syntax::{Label, V}; use crate::core::thunk::Thunk; use crate::core::value::ValueF; use crate::core::var::{AlphaVar, Shift, Subst}; use crate::error::TypeError; use crate::phase::{Type, Typed}; #[derive(Debug, Clone)] enum CtxItem { Kept(AlphaVar, Type), Replaced(Thunk, Type), } #[derive(Debug, Clone)] pub(crate) struct TypecheckContext(Rc>); impl TypecheckContext { pub fn new() -> Self { TypecheckContext(Rc::new(Vec::new())) } pub fn insert_type(&self, x: &Label, t: Type) -> Self { let mut vec = self.0.as_ref().clone(); vec.push((x.clone(), CtxItem::Kept(x.into(), t.under_binder(x)))); TypecheckContext(Rc::new(vec)) } pub fn insert_value(&self, x: &Label, e: Typed) -> Result { let mut vec = self.0.as_ref().clone(); vec.push(( x.clone(), CtxItem::Replaced(e.to_thunk(), e.get_type()?.into_owned()), )); Ok(TypecheckContext(Rc::new(vec))) } pub fn lookup(&self, var: &V