#![allow(non_snake_case)] use std::borrow::Borrow; use std::borrow::Cow; use std::collections::BTreeMap; use std::fmt; use crate::phase::normalize::{ AlphaVar, NormalizationContext, Thunk, TypeThunk, Value, }; use crate::phase::*; use crate::traits::DynamicType; use dhall_proc_macros as dhall; use dhall_syntax; use dhall_syntax::context::Context; use dhall_syntax::*; use self::TypeMessage::*; impl TypeThunk { fn to_type(&self, ctx: &TypecheckContext) -> Result { match self { TypeThunk::Type(t) => Ok(t.clone()), TypeThunk::Thunk(th) => { // TODO: rule out statically mktype(ctx, th.normalize_to_expr().embed_absurd().note_absurd()) } } } } #[derive(Debug, Clone)] pub(crate) enum EnvItem { Type(AlphaVar, Type), Value(Normalized), } impl EnvItem { fn shift(&self, delta: isize, var: &AlphaVar) -> Self { use EnvItem::*; match self { Type(v, e) => Type(v.shift(delta, var), e.shift(delta, var)), Value(e) => Value(e.shift(delta, var)), } } } #[derive(Debug, Clone)] pub(crate) struct TypecheckContext(pub(crate) Context); impl TypecheckContext { pub(crate) fn new() -> Self { TypecheckContext(Context::new()) } pub(crate) fn insert_type(&self, x: &Label, t: Type) -> Self { TypecheckContext( self.0.map(|_, e| e.shift(1, &x.into())).insert( x.clone(), EnvItem::Type(x.into(), t.shift(1, &x.into())), ), ) } pub(crate) fn insert_value(&self, x: &Label, t: Normalized) -> Self { TypecheckContext(self.0.insert(x.clone(), EnvItem::Value(t))) } pub(crate) fn lookup(&self, var: &V