From 26a1fd0f0861038a76a0f9b09eaef16d808d4139 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 19 Aug 2019 21:52:26 +0200 Subject: Use TypedValue instead of Typed in normalize and typecheck Now Typed is only used in dhall::phase, similarly to Parsed/Resolved/Normalized --- dhall/src/core/context.rs | 29 ++-- dhall/src/core/value.rs | 48 +++--- dhall/src/core/valuef.rs | 6 +- dhall/src/error/mod.rs | 55 +++--- dhall/src/phase/mod.rs | 51 ++---- dhall/src/phase/normalize.rs | 6 +- dhall/src/phase/typecheck.rs | 392 +++++++++++++++++++------------------------ dhall/src/tests.rs | 2 +- serde_dhall/src/lib.rs | 10 +- 9 files changed, 260 insertions(+), 339 deletions(-) diff --git a/dhall/src/core/context.rs b/dhall/src/core/context.rs index e1a23a9..851e4c4 100644 --- a/dhall/src/core/context.rs +++ b/dhall/src/core/context.rs @@ -3,16 +3,15 @@ use std::rc::Rc; use dhall_syntax::{Label, V}; -use crate::core::value::Value; +use crate::core::value::{TypedValue, Value}; use crate::core::valuef::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(Value, Type), + Kept(AlphaVar, TypedValue), + Replaced(Value, TypedValue), } #[derive(Debug, Clone)] @@ -22,12 +21,16 @@ impl TypecheckContext { pub fn new() -> Self { TypecheckContext(Rc::new(Vec::new())) } - pub fn insert_type(&self, x: &Label, t: Type) -> Self { + pub fn insert_type(&self, x: &Label, t: TypedValue) -> 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 { + pub fn insert_value( + &self, + x: &Label, + e: TypedValue, + ) -> Result { let mut vec = self.0.as_ref().clone(); vec.push(( x.clone(), @@ -35,7 +38,7 @@ impl TypecheckContext { )); Ok(TypecheckContext(Rc::new(vec))) } - pub fn lookup(&self, var: &V