From 77198a2833297289770867acdaf31db0e2011ea9 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 30 Apr 2019 15:35:13 +0200 Subject: Merge Typed and PartiallyNormalized --- dhall/src/typecheck.rs | 137 ++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 75 deletions(-) (limited to 'dhall/src/typecheck.rs') diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index 85de42a..f22925a 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -68,8 +68,8 @@ impl<'a> Normalized<'a> { // TODO: wasteful type_with(ctx, self.0.embed_absurd())?.normalize_to_type() } - _ => Type(TypeInternal::PNzed(Box::new(PartiallyNormalized( - Value::Expr(self.0), + _ => Type(TypeInternal::Typed(Box::new(Typed( + Value::Expr(self.0).into_thunk(), self.1, self.2, )))), @@ -86,11 +86,12 @@ impl Normalized<'static> { rc(ExprF::Embed(self)) } } -impl<'a> PartiallyNormalized<'a> { +impl<'a> Typed<'a> { fn normalize_to_type(self) -> Type<'a> { - match &self.0 { + // TODO: avoid cloning Value + match &self.normalize_whnf() { Value::Const(c) => Type(TypeInternal::Const(*c)), - _ => Type(TypeInternal::PNzed(Box::new(self))), + _ => Type(TypeInternal::Typed(Box::new(self))), } } } @@ -103,18 +104,16 @@ impl<'a> Type<'a> { pub(crate) fn into_normalized(self) -> Result, TypeError> { self.0.into_normalized() } - fn normalize_whnf(self) -> Result { + pub(crate) fn normalize_whnf(&self) -> Result { self.0.normalize_whnf() } - pub(crate) fn partially_normalize( - self, - ) -> Result, TypeError> { - self.0.partially_normalize() + pub(crate) fn as_typed(&self) -> Result, TypeError> { + self.0.as_typed() } fn internal(&self) -> &TypeInternal<'a> { &self.0 } - fn internal_whnf(&self) -> Option<&Value> { + fn internal_whnf(&self) -> Option { self.0.whnf() } pub(crate) fn shift0(&self, delta: isize, label: &Label) -> Self { @@ -126,7 +125,7 @@ impl<'a> Type<'a> { pub(crate) fn subst_shift( &self, var: &V