diff options
-rw-r--r-- | dhall/src/error.rs | 6 | ||||
-rw-r--r-- | dhall/src/traits/dynamic_type.rs | 12 | ||||
-rw-r--r-- | dhall/src/typecheck.rs | 37 |
3 files changed, 27 insertions, 28 deletions
diff --git a/dhall/src/error.rs b/dhall/src/error.rs index 0a02816..1243c94 100644 --- a/dhall/src/error.rs +++ b/dhall/src/error.rs @@ -6,7 +6,7 @@ pub enum Error { Parse(dhall_core::ParseError), Decode(crate::binary::DecodeError), Resolve(crate::imports::ImportError), - Typecheck(crate::typecheck::TypeError<dhall_core::X>), + Typecheck(crate::typecheck::TypeError), Deserialize(String), } @@ -44,8 +44,8 @@ impl From<crate::imports::ImportError> for Error { Error::Resolve(err) } } -impl From<crate::typecheck::TypeError<dhall_core::X>> for Error { - fn from(err: crate::typecheck::TypeError<dhall_core::X>) -> Error { +impl From<crate::typecheck::TypeError> for Error { + fn from(err: crate::typecheck::TypeError) -> Error { Error::Typecheck(err) } } diff --git a/dhall/src/traits/dynamic_type.rs b/dhall/src/traits/dynamic_type.rs index 66af320..d03f8cd 100644 --- a/dhall/src/traits/dynamic_type.rs +++ b/dhall/src/traits/dynamic_type.rs @@ -2,21 +2,21 @@ use crate::expr::*; use crate::traits::StaticType; use crate::typecheck::{TypeError, TypeMessage}; use dhall_core::context::Context; -use dhall_core::{Const, ExprF, X}; +use dhall_core::{Const, ExprF}; use std::borrow::Cow; pub trait DynamicType { - fn get_type<'a>(&'a self) -> Result<Cow<'a, Type>, TypeError<X>>; + fn get_type<'a>(&'a self) -> Result<Cow<'a, Type>, TypeError>; } impl<T: StaticType> DynamicType for T { - fn get_type<'a>(&'a self) -> Result<Cow<'a, Type>, TypeError<X>> { + fn get_type<'a>(&'a self) -> Result<Cow<'a, Type>, TypeError> { Ok(Cow::Owned(T::get_static_type())) } } impl DynamicType for Type { - fn get_type(&self) -> Result<Cow<'_, Type>, TypeError<X>> { + fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { use TypeInternal::*; match &self.0 { Expr(e) => e.get_type(), @@ -30,7 +30,7 @@ impl DynamicType for Type { } impl DynamicType for Normalized { - fn get_type(&self) -> Result<Cow<'_, Type>, TypeError<X>> { + fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { match &self.1 { Some(t) => Ok(Cow::Borrowed(t)), None => Err(TypeError::new( @@ -43,7 +43,7 @@ impl DynamicType for Normalized { } impl DynamicType for Typed { - fn get_type(&self) -> Result<Cow<'_, Type>, TypeError<X>> { + fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { match &self.1 { Some(t) => Ok(Cow::Borrowed(t)), None => Err(TypeError::new( diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index ab4142b..4881972 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -12,10 +12,10 @@ use dhall_generator as dhall; use self::TypeMessage::*; impl Resolved { - pub fn typecheck(self) -> Result<Typed, TypeError<X>> { + pub fn typecheck(self) -> Result<Typed, TypeError> { type_of(self.0.clone()) } - pub fn typecheck_with(self, ty: &Type) -> Result<Typed, TypeError<X>> { + pub fn typecheck_with(self, ty: &Type) -> Result<Typed, TypeError> { let expr: SubExpr<_, _> = self.0.clone(); let ty: SubExpr<_, _> = ty.as_normalized()?.as_expr().absurd(); type_of(dhall::subexpr!(expr: ty)) @@ -26,7 +26,7 @@ impl Resolved { } } impl Typed { - fn get_type_move(self) -> Result<Type, TypeError<X>> { + fn get_type_move(self) -> Result<Type, TypeError> { self.1.ok_or(TypeError::new( &Context::new(), self.0, @@ -45,7 +45,7 @@ impl Normalized { } } impl Type { - pub fn as_normalized(&self) -> Result<&Normalized, TypeError<X>> { + pub fn as_normalized(&self) -> Result<&Normalized, TypeError> { use TypeInternal::*; match &self.0 { Expr(e) => Ok(e), @@ -56,7 +56,7 @@ impl Type { )), } } - pub(crate) fn into_normalized(self) -> Result<Normalized, TypeError<X>> { + pub(crate) fn into_normalized(self) -> Result<Normalized, TypeError> { use TypeInternal::*; match self.0 { Expr(e) => Ok(*e), @@ -68,7 +68,7 @@ impl Type { } } // Expose the outermost constructor - fn unroll_ref(&self) -> Result<&Expr<X, X>, TypeError<X>> { + fn unroll_ref(&self) -> Result<&Expr<X, X>, TypeError> { Ok(self.as_normalized()?.unroll_ref()) } fn shift(&self, delta: isize, var: &V<Label>) -> Self { @@ -296,11 +296,11 @@ macro_rules! ensure_is_const { pub fn type_with( ctx: &Context<Label, Type>, e: SubExpr<X, Normalized>, -) -> Result<Typed, TypeError<X>> { +) -> Result<Typed, TypeError> { use dhall_core::BinOp::*; use dhall_core::Const::*; use dhall_core::ExprF::*; - let mkerr = |msg: TypeMessage<_>| TypeError::new(ctx, e.clone(), msg); + let mkerr = |msg: TypeMessage| TypeError::new(ctx, e.clone(), msg); let mktype = |ctx, x: SubExpr<X, Normalized>| { Ok(type_with(ctx, x)?.normalize().into_type()) @@ -600,7 +600,7 @@ pub fn type_with( /// `typeOf` is the same as `type_with` with an empty context, meaning that the /// expression must be closed (i.e. no free variables), otherwise type-checking /// will fail. -pub fn type_of(e: SubExpr<X, Normalized>) -> Result<Typed, TypeError<X>> { +pub fn type_of(e: SubExpr<X, Normalized>) -> Result<Typed, TypeError> { let ctx = Context::new(); let e = type_with(&ctx, e)?; // Ensure the inferred type isn't SuperType @@ -610,7 +610,7 @@ pub fn type_of(e: SubExpr<X, Normalized>) -> Result<Typed, TypeError<X>> { /// The specific type error #[derive(Debug)] -pub enum TypeMessage<S> { +pub enum TypeMessage { UnboundVariable, InvalidInputType(Normalized), InvalidOutputType(Normalized), @@ -633,23 +633,22 @@ pub enum TypeMessage<S> { BinOpTypeMismatch(BinOp, Typed), NoDependentLet(Normalized, Normalized), NoDependentTypes(Normalized, Normalized), - MustCombineARecord(SubExpr<S, X>, SubExpr<S, X>), Unimplemented, } /// A structured type error that includes context #[derive(Debug)] -pub struct TypeError<S> { +pub struct TypeError { pub context: Context<Label, Type>, - pub current: SubExpr<S, Normalized>, - pub type_message: TypeMessage<S>, + pub current: SubExpr<X, Normalized>, + pub type_message: TypeMessage, } -impl<S> TypeError<S> { +impl TypeError { pub fn new( context: &Context<Label, Type>, - current: SubExpr<S, Normalized>, - type_message: TypeMessage<S>, + current: SubExpr<X, Normalized>, + type_message: TypeMessage, ) -> Self { TypeError { context: context.clone(), @@ -659,7 +658,7 @@ impl<S> TypeError<S> { } } -impl<S: fmt::Debug> ::std::error::Error for TypeMessage<S> { +impl ::std::error::Error for TypeMessage { fn description(&self) -> &str { match *self { UnboundVariable => "Unbound variable", @@ -672,7 +671,7 @@ impl<S: fmt::Debug> ::std::error::Error for TypeMessage<S> { } } -impl<S> fmt::Display for TypeMessage<S> { +impl fmt::Display for TypeMessage { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match self { UnboundVariable => { |