summaryrefslogtreecommitdiff
path: root/dhall/src/traits
diff options
context:
space:
mode:
authorNadrieril2019-05-02 17:23:40 +0200
committerNadrieril2019-05-02 17:23:40 +0200
commit9d3c0d6aa23e4123515a1d7e949fc71509db803c (patch)
treed657fd50678dd8a562621d91c3caecbb2396fc7a /dhall/src/traits
parent9042db26ced0c56714c48bf2f6322e0a1c2a6973 (diff)
parent17ab417aeb5aea6cd21240a491607b9017194737 (diff)
Merge branch 'refactor-typechecking'
Diffstat (limited to 'dhall/src/traits')
-rw-r--r--dhall/src/traits/deserialize.rs2
-rw-r--r--dhall/src/traits/dynamic_type.rs33
-rw-r--r--dhall/src/traits/static_type.rs13
3 files changed, 14 insertions, 34 deletions
diff --git a/dhall/src/traits/deserialize.rs b/dhall/src/traits/deserialize.rs
index 43eb2ac..99ca5ee 100644
--- a/dhall/src/traits/deserialize.rs
+++ b/dhall/src/traits/deserialize.rs
@@ -48,6 +48,6 @@ impl<'de: 'a, 'a> Deserialize<'de> for Normalized<'a> {
impl<'de: 'a, 'a> Deserialize<'de> for Type<'a> {
fn from_str(s: &'de str, ty: Option<&Type>) -> Result<Self> {
- Ok(Normalized::from_str(s, ty)?.into_type())
+ Ok(Normalized::from_str(s, ty)?.to_type())
}
}
diff --git a/dhall/src/traits/dynamic_type.rs b/dhall/src/traits/dynamic_type.rs
index d4faf45..74c2e0a 100644
--- a/dhall/src/traits/dynamic_type.rs
+++ b/dhall/src/traits/dynamic_type.rs
@@ -1,7 +1,8 @@
use crate::expr::*;
use crate::traits::StaticType;
-use crate::typecheck::{type_of_const, TypeError, TypeMessage};
-use dhall_core::context::Context;
+#[allow(unused_imports)]
+use crate::typecheck::{TypeError, TypeMessage, TypecheckContext};
+#[allow(unused_imports)]
use dhall_core::{Const, ExprF};
use std::borrow::Cow;
@@ -17,40 +18,18 @@ impl<T: StaticType> DynamicType for T {
impl<'a> DynamicType for Type<'a> {
fn get_type(&self) -> Result<Cow<'_, Type<'static>>, TypeError> {
- match &self.0 {
- TypeInternal::Expr(e) => e.get_type(),
- TypeInternal::Const(c) => Ok(Cow::Owned(type_of_const(*c))),
- TypeInternal::SuperType => Err(TypeError::new(
- &Context::new(),
- dhall_core::rc(ExprF::Const(Const::Sort)),
- TypeMessage::Untyped,
- )),
- }
+ self.get_type()
}
}
impl<'a> DynamicType for Normalized<'a> {
fn get_type(&self) -> Result<Cow<'_, Type<'static>>, TypeError> {
- match &self.1 {
- Some(t) => Ok(Cow::Borrowed(t)),
- None => Err(TypeError::new(
- &Context::new(),
- self.0.embed_absurd(),
- TypeMessage::Untyped,
- )),
- }
+ self.0.get_type()
}
}
impl<'a> DynamicType for Typed<'a> {
fn get_type(&self) -> Result<Cow<'_, Type<'static>>, TypeError> {
- match &self.1 {
- Some(t) => Ok(Cow::Borrowed(t)),
- None => Err(TypeError::new(
- &Context::new(),
- self.0.clone(),
- TypeMessage::Untyped,
- )),
- }
+ self.0.get_type()
}
}
diff --git a/dhall/src/traits/static_type.rs b/dhall/src/traits/static_type.rs
index e92ce78..df6a177 100644
--- a/dhall/src/traits/static_type.rs
+++ b/dhall/src/traits/static_type.rs
@@ -33,17 +33,18 @@ pub trait SimpleStaticType {
}
fn mktype<'a>(x: SubExpr<X, X>) -> SimpleType<'a> {
- SimpleType(x, std::marker::PhantomData)
+ x.into()
}
impl<T: SimpleStaticType> StaticType for T {
fn get_static_type() -> Type<'static> {
- crate::expr::Normalized(
- T::get_simple_static_type().into(),
- Some(Type::const_type()),
- std::marker::PhantomData,
+ crate::expr::Normalized::from_thunk_and_type(
+ crate::normalize::Thunk::from_normalized_expr(
+ T::get_simple_static_type().into(),
+ ),
+ Type::const_type(),
)
- .into_type()
+ .to_type()
}
}