From 1cb13e7d75035fc1e7fcea76f57847f8dbbbac87 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 16 Apr 2019 18:04:22 +0200 Subject: Remove one more instance of duplicate typechecking --- dhall/src/expr.rs | 15 +++++++++++++++ dhall/src/typecheck.rs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'dhall') diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs index 9e89e3a..7c62a33 100644 --- a/dhall/src/expr.rs +++ b/dhall/src/expr.rs @@ -120,6 +120,9 @@ impl<'a> Normalized<'a> { pub(crate) fn into_expr(self) -> SubExpr { self.0 } + pub(crate) fn unnote<'b>(self) -> Normalized<'b> { + Normalized(self.0, self.1, PhantomData) + } pub(crate) fn into_type(self) -> Type<'a> { Type(match self.0.as_ref() { ExprF::Const(c) => TypeInternal::Const(*c), @@ -128,6 +131,18 @@ impl<'a> Normalized<'a> { } } +#[doc(hidden)] +impl<'a> Type<'a> { + pub(crate) fn unnote<'b>(self) -> Type<'b> { + use TypeInternal::*; + Type(match self.0 { + Expr(e) => Expr(Box::new(e.unnote())), + Const(c) => Const(c), + SuperType => SuperType, + }) + } +} + impl<'a> SimpleType<'a> { pub(crate) fn into_type(self) -> Type<'a> { Normalized(self.0, Some(Type::const_type()), PhantomData).into_type() diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index 195628b..c8929fe 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -22,7 +22,7 @@ impl<'a> Resolved<'a> { ty: &Type, ) -> Result, TypeError> { let expr: SubExpr<_, _> = self.0.unnote(); - let ty: SubExpr<_, _> = ty.as_normalized()?.as_expr().absurd(); + let ty: SubExpr<_, _> = ty.clone().unnote().embed()?; type_of(dhall::subexpr!(expr: ty)) } /// Pretends this expression has been typechecked. Use with care. -- cgit v1.2.3