summaryrefslogtreecommitdiff
path: root/dhall/src/phase
diff options
context:
space:
mode:
authorNadrieril2019-05-09 21:54:45 +0200
committerNadrieril2019-05-09 21:54:45 +0200
commitdae106b3de0888e8a704c0efa3f9d991590f7858 (patch)
tree750daf7cb5b44bed4772ace3457c583c0ef86e4d /dhall/src/phase
parent6444faa2dee271e6d22226dc30b659e13fa8aead (diff)
Rewrite the StaticType trait and everything around it
Diffstat (limited to 'dhall/src/phase')
-rw-r--r--dhall/src/phase/mod.rs57
-rw-r--r--dhall/src/phase/typecheck.rs2
2 files changed, 12 insertions, 47 deletions
diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs
index af39eb6..5262a27 100644
--- a/dhall/src/phase/mod.rs
+++ b/dhall/src/phase/mod.rs
@@ -49,19 +49,6 @@ pub(crate) enum Typed {
#[derive(Debug, Clone)]
pub(crate) struct Normalized(pub(crate) Typed);
-/// A Dhall expression representing a simple type.
-///
-/// This captures what is usually simply called a "type", like
-/// `Bool`, `{ x: Integer }` or `Natural -> Text`.
-///
-/// For a more general notion of "type", see [Type].
-#[derive(Debug, Clone)]
-pub struct SimpleType(pub(crate) NormalizedSubExpr);
-
-/// A Dhall expression representing a (possibly higher-kinded) type.
-///
-/// This includes [SimpleType]s but also higher-kinded expressions like
-/// `Type`, `Kind` and `{ x: Type }`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Type(pub(crate) Typed);
@@ -131,6 +118,12 @@ impl Typed {
pub(crate) fn from_const(c: Const) -> Self {
Typed::Const(c)
}
+ pub(crate) fn from_value_untyped(v: Value) -> Self {
+ Typed::Untyped(Thunk::from_value(v))
+ }
+ pub(crate) fn from_normalized_expr_untyped(e: NormalizedSubExpr) -> Self {
+ Typed::from_thunk_untyped(Thunk::from_normalized_expr(e))
+ }
// TODO: Avoid cloning if possible
pub(crate) fn to_value(&self) -> Value {
@@ -179,6 +172,7 @@ impl Typed {
}
impl Type {
+ // Deprecated
pub(crate) fn to_normalized(&self) -> Normalized {
self.0.clone().normalize()
}
@@ -202,19 +196,12 @@ impl Type {
self.0.get_type()
}
- pub(crate) fn const_type() -> Self {
- Type::from_const(Const::Type)
- }
pub(crate) fn from_const(c: Const) -> Self {
Type(Typed::from_const(c))
}
}
impl Normalized {
- pub(crate) fn from_thunk_and_type(th: Thunk, t: Type) -> Self {
- Normalized(Typed::from_thunk_and_type(th, t))
- }
-
pub(crate) fn to_expr(&self) -> NormalizedSubExpr {
self.0.to_expr()
}
@@ -225,9 +212,12 @@ impl Normalized {
pub(crate) fn to_value(&self) -> Value {
self.0.to_value()
}
- pub(crate) fn to_type(self) -> Type {
+ pub(crate) fn to_type(&self) -> Type {
self.0.to_type()
}
+ pub(crate) fn into_typed(self) -> Typed {
+ self.0
+ }
pub(crate) fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> {
self.0.get_type()
}
@@ -301,7 +291,6 @@ macro_rules! derive_traits_for_wrapper_struct {
derive_traits_for_wrapper_struct!(Parsed);
derive_traits_for_wrapper_struct!(Resolved);
derive_traits_for_wrapper_struct!(Normalized);
-derive_traits_for_wrapper_struct!(SimpleType);
impl Eq for Typed {}
impl PartialEq for Typed {
@@ -321,27 +310,3 @@ impl Display for Type {
self.to_normalized().fmt(f)
}
}
-
-// Exposed for the macros
-#[doc(hidden)]
-impl From<SimpleType> for NormalizedSubExpr {
- fn from(x: SimpleType) -> NormalizedSubExpr {
- x.0
- }
-}
-
-// Exposed for the macros
-#[doc(hidden)]
-impl From<NormalizedSubExpr> for SimpleType {
- fn from(x: NormalizedSubExpr) -> SimpleType {
- SimpleType(x)
- }
-}
-
-// Exposed for the macros
-#[doc(hidden)]
-impl From<Normalized> for Typed {
- fn from(x: Normalized) -> Typed {
- x.0
- }
-}
diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs
index e1dffb0..7f988c8 100644
--- a/dhall/src/phase/typecheck.rs
+++ b/dhall/src/phase/typecheck.rs
@@ -391,7 +391,7 @@ fn type_with(
let e = e.rewrap(Annot(x, t));
return type_with(ctx, e);
}
- Embed(p) => p.clone().into(),
+ Embed(p) => p.clone().into_typed(),
Var(var) => match ctx.lookup(&var) {
Some(typed) => typed,
None => {