From c13a4881b56bf2f5b2d5d4d0018a48927b45e7e0 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 2 May 2019 14:11:29 +0200 Subject: Store Thunk in Normalized --- dhall/src/expr.rs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'dhall/src/expr.rs') diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs index 1ddc4ba..a753ffd 100644 --- a/dhall/src/expr.rs +++ b/dhall/src/expr.rs @@ -45,11 +45,24 @@ pub(crate) struct Typed<'a>( #[derive(Debug, Clone)] pub(crate) struct Normalized<'a>( - pub(crate) SubExpr, + pub(crate) crate::normalize::Thunk, pub(crate) Option>, pub(crate) PhantomData<&'a ()>, ); -derive_other_traits!(Normalized); + +impl<'a> std::cmp::PartialEq for Normalized<'a> { + fn eq(&self, other: &Self) -> bool { + self.0.normalize_to_expr() == other.0.normalize_to_expr() + } +} + +impl<'a> std::cmp::Eq for Normalized<'a> {} + +impl<'a> std::fmt::Display for Normalized<'a> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + self.0.normalize_to_expr().fmt(f) + } +} /// A Dhall expression representing a simple type. /// @@ -102,21 +115,20 @@ impl<'a> From> for SimpleType<'a> { #[doc(hidden)] impl<'a> From> for Typed<'a> { fn from(x: Normalized<'a>) -> Typed<'a> { - Typed( - crate::normalize::Thunk::new( - crate::normalize::NormalizationContext::new(), - x.0.embed_absurd(), - ), - x.1, - x.2, - ) + Typed(x.0, x.1, x.2) } } -#[doc(hidden)] impl<'a> Normalized<'a> { - pub(crate) fn as_expr(&self) -> &SubExpr { - &self.0 + // Deprecated + pub(crate) fn as_expr(&self) -> SubExpr { + self.0.normalize_to_expr() + } + pub(crate) fn to_expr(&self) -> SubExpr { + self.0.normalize_to_expr() + } + pub(crate) fn to_value(&self) -> crate::normalize::Value { + self.0.normalize_nf().clone() } #[allow(dead_code)] pub(crate) fn unnote<'b>(self) -> Normalized<'b> { -- cgit v1.2.3