summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dhall/src/lib.rs8
-rw-r--r--dhall/src/semantics/builtins.rs2
-rw-r--r--dhall/src/semantics/hir.rs8
-rw-r--r--dhall/src/semantics/nze/normalize.rs6
-rw-r--r--dhall/src/semantics/nze/value.rs16
-rw-r--r--dhall/src/semantics/resolve.rs4
-rw-r--r--dhall/src/semantics/tck/tyexpr.rs3
-rw-r--r--dhall/src/semantics/tck/typecheck.rs7
-rw-r--r--dhall/src/syntax/ast/expr.rs58
-rw-r--r--dhall/src/syntax/ast/visitor.rs30
-rw-r--r--dhall/src/syntax/binary/decode.rs2
-rw-r--r--dhall/src/syntax/binary/encode.rs44
-rw-r--r--dhall/src/syntax/text/parser.rs10
-rw-r--r--dhall/src/syntax/text/printer.rs17
-rw-r--r--serde_dhall/src/serde.rs2
15 files changed, 80 insertions, 137 deletions
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index 2d261f9..2f0ed4b 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -28,10 +28,10 @@ use crate::semantics::{
use crate::syntax::binary;
use crate::syntax::{Builtin, Expr};
-pub type ParsedExpr = Expr<Normalized>;
-pub type DecodedExpr = Expr<Normalized>;
-pub type ResolvedExpr = Expr<Normalized>;
-pub type NormalizedExpr = Expr<Normalized>;
+pub type ParsedExpr = Expr;
+pub type DecodedExpr = Expr;
+pub type ResolvedExpr = Expr;
+pub type NormalizedExpr = Expr;
#[derive(Debug, Clone)]
pub struct Parsed(ParsedExpr, ImportRoot);
diff --git a/dhall/src/semantics/builtins.rs b/dhall/src/semantics/builtins.rs
index d9a3599..cbb5a6e 100644
--- a/dhall/src/semantics/builtins.rs
+++ b/dhall/src/semantics/builtins.rs
@@ -55,7 +55,7 @@ impl BuiltinClosure<Value> {
}
}
-pub(crate) fn rc<E>(x: UnspannedExpr<E>) -> Expr<E> {
+pub(crate) fn rc(x: UnspannedExpr) -> Expr {
Expr::new(x, Span::Artificial)
}
diff --git a/dhall/src/semantics/hir.rs b/dhall/src/semantics/hir.rs
index b45851f..288031c 100644
--- a/dhall/src/semantics/hir.rs
+++ b/dhall/src/semantics/hir.rs
@@ -1,7 +1,7 @@
#![allow(dead_code)]
use crate::semantics::{NameEnv, NzEnv, TyEnv, Value};
-use crate::syntax::{ExprKind, Span, V};
-use crate::{Expr, Normalized, NormalizedExpr, ToExprOptions};
+use crate::syntax::{Expr, ExprKind, Span, V};
+use crate::{NormalizedExpr, ToExprOptions};
/// Stores an alpha-normalized variable.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -13,8 +13,8 @@ pub struct AlphaVar {
pub(crate) enum HirKind {
/// A resolved variable (i.e. a DeBruijn index)
Var(AlphaVar),
- // Forbidden ExprKind variants: Var, Import, Embed
- Expr(ExprKind<Hir, Normalized>),
+ // Forbidden ExprKind variants: Var, Import
+ Expr(ExprKind<Hir>),
}
// An expression with resolved variables and imports.
diff --git a/dhall/src/semantics/nze/normalize.rs b/dhall/src/semantics/nze/normalize.rs
index d12146a..03b91a5 100644
--- a/dhall/src/semantics/nze/normalize.rs
+++ b/dhall/src/semantics/nze/normalize.rs
@@ -6,7 +6,6 @@ use crate::semantics::{
Binder, BuiltinClosure, Closure, Hir, HirKind, TextLit, Value, ValueKind,
};
use crate::syntax::{BinOp, Builtin, ExprKind, InterpolatedTextContents};
-use crate::Normalized;
pub(crate) fn apply_any(f: Value, a: Value) -> ValueKind {
match f.kind() {
@@ -90,7 +89,7 @@ enum Ret<'a> {
ValueKind(ValueKind),
Value(Value),
ValueRef(&'a Value),
- Expr(ExprKind<Value, Normalized>),
+ Expr(ExprKind<Value>),
}
fn apply_binop<'a>(o: BinOp, x: &'a Value, y: &'a Value) -> Option<Ret<'a>> {
@@ -215,7 +214,7 @@ fn apply_binop<'a>(o: BinOp, x: &'a Value, y: &'a Value) -> Option<Ret<'a>> {
}
pub(crate) fn normalize_one_layer(
- expr: ExprKind<Value, Normalized>,
+ expr: ExprKind<Value>,
env: &NzEnv,
) -> ValueKind {
use ValueKind::{
@@ -233,7 +232,6 @@ pub(crate) fn normalize_one_layer(
ExprKind::Lam(..)
| ExprKind::Pi(..)
| ExprKind::Let(..)
- | ExprKind::Embed(_)
| ExprKind::Var(_) => {
unreachable!("This case should have been handled in typecheck")
}
diff --git a/dhall/src/semantics/nze/value.rs b/dhall/src/semantics/nze/value.rs
index a60be9d..0df3c74 100644
--- a/dhall/src/semantics/nze/value.rs
+++ b/dhall/src/semantics/nze/value.rs
@@ -12,7 +12,7 @@ use crate::syntax::{
BinOp, Builtin, Const, ExprKind, Integer, InterpolatedTextContents, Label,
NaiveDouble, Natural, Span,
};
-use crate::{Normalized, NormalizedExpr, ToExprOptions};
+use crate::{NormalizedExpr, ToExprOptions};
/// Stores a possibly unevaluated value. Gets (partially) normalized on-demand, sharing computation
/// automatically. Uses a Rc<RefCell> to share computation.
@@ -34,10 +34,7 @@ pub(crate) enum Thunk {
/// A completely unnormalized expression.
Thunk { env: NzEnv, body: Hir },
/// A partially normalized expression that may need to go through `normalize_one_layer`.
- PartialExpr {
- env: NzEnv,
- expr: ExprKind<Value, Normalized>,
- },
+ PartialExpr { env: NzEnv, expr: ExprKind<Value> },
}
/// An unevaluated subexpression that takes an argument.
@@ -96,7 +93,7 @@ pub(crate) enum ValueKind {
TextLit(TextLit),
Equivalence(Value, Value),
/// Invariant: evaluation must not be able to progress with `normalize_one_layer`?
- PartialExpr(ExprKind<Value, Normalized>),
+ PartialExpr(ExprKind<Value>),
}
impl Value {
@@ -106,7 +103,7 @@ impl Value {
ValueInternal::from_thunk(Thunk::new(env, hir), span).into_value()
}
/// Construct a Value from a partially normalized expression that's not in WHNF.
- pub(crate) fn from_partial_expr(e: ExprKind<Value, Normalized>) -> Value {
+ pub(crate) fn from_partial_expr(e: ExprKind<Value>) -> Value {
// TODO: env
let env = NzEnv::new();
ValueInternal::from_thunk(
@@ -389,10 +386,7 @@ impl Thunk {
fn new(env: NzEnv, body: Hir) -> Self {
Thunk::Thunk { env, body }
}
- fn from_partial_expr(
- env: NzEnv,
- expr: ExprKind<Value, Normalized>,
- ) -> Self {
+ fn from_partial_expr(env: NzEnv, expr: ExprKind<Value>) -> Self {
Thunk::PartialExpr { env, expr }
}
fn eval(self) -> ValueKind {
diff --git a/dhall/src/semantics/resolve.rs b/dhall/src/semantics/resolve.rs
index 80e5132..fac88d2 100644
--- a/dhall/src/semantics/resolve.rs
+++ b/dhall/src/semantics/resolve.rs
@@ -6,7 +6,7 @@ use crate::error::{Error, ImportError};
use crate::semantics::{mkerr, Hir, HirKind, NameEnv};
use crate::syntax;
use crate::syntax::{BinOp, Expr, ExprKind, FilePath, ImportLocation, URL};
-use crate::{Normalized, Parsed, ParsedExpr, Resolved};
+use crate::{Parsed, ParsedExpr, Resolved};
type Import = syntax::Import<Hir>;
@@ -102,7 +102,7 @@ fn load_import(env: &mut ResolveEnv, f: &Path) -> Result<Hir, Error> {
/// found imports to the provided function.
fn traverse_resolve_expr(
name_env: &mut NameEnv,
- expr: &Expr<Normalized>,
+ expr: &Expr,
f: &mut impl FnMut(Import) -> Result<Hir, Error>,
) -> Result<Hir, Error> {
let kind = match expr.kind() {
diff --git a/dhall/src/semantics/tck/tyexpr.rs b/dhall/src/semantics/tck/tyexpr.rs
index a1666a4..d46ab87 100644
--- a/dhall/src/semantics/tck/tyexpr.rs
+++ b/dhall/src/semantics/tck/tyexpr.rs
@@ -1,7 +1,6 @@
use crate::error::{TypeError, TypeMessage};
use crate::semantics::{AlphaVar, Hir, HirKind, NzEnv, Value};
use crate::syntax::{ExprKind, Span};
-use crate::Normalized;
use crate::{NormalizedExpr, ToExprOptions};
pub(crate) type Type = Value;
@@ -10,7 +9,7 @@ pub(crate) type Type = Value;
pub(crate) enum TyExprKind {
Var(AlphaVar),
// Forbidden ExprKind variants: Var, Import, Embed
- Expr(ExprKind<TyExpr, Normalized>),
+ Expr(ExprKind<TyExpr>),
}
// An expression with inferred types at every node and resolved variables.
diff --git a/dhall/src/semantics/tck/typecheck.rs b/dhall/src/semantics/tck/typecheck.rs
index 4e45637..f9ff3d3 100644
--- a/dhall/src/semantics/tck/typecheck.rs
+++ b/dhall/src/semantics/tck/typecheck.rs
@@ -11,7 +11,6 @@ use crate::semantics::{
use crate::syntax::{
BinOp, Builtin, Const, ExprKind, InterpolatedTextContents, Span,
};
-use crate::Normalized;
fn type_of_recordtype<'a>(
span: Span,
@@ -51,7 +50,7 @@ pub fn mkerr<T, S: ToString>(x: S) -> Result<T, TypeError> {
/// layer.
fn type_one_layer(
env: &TyEnv,
- ekind: ExprKind<TyExpr, Normalized>,
+ ekind: ExprKind<TyExpr>,
span: Span,
) -> Result<TyExpr, TypeError> {
let span_err = |msg: &str| {
@@ -66,9 +65,7 @@ fn type_one_layer(
ExprKind::Import(..) => unreachable!(
"There should remain no imports in a resolved expression"
),
- ExprKind::Var(..)
- | ExprKind::Const(Const::Sort)
- | ExprKind::Embed(..) => unreachable!(), // Handled in type_with
+ ExprKind::Var(..) | ExprKind::Const(Const::Sort) => unreachable!(), // Handled in type_with
ExprKind::Lam(binder, annot, body) => {
let body_ty = body.get_type()?;
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 420df5b..722630f 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -96,19 +96,19 @@ pub enum Builtin {
// Each node carries an annotation.
#[derive(Debug, Clone)]
-pub struct Expr<Embed> {
- kind: Box<ExprKind<Expr<Embed>, Embed>>,
+pub struct Expr {
+ kind: Box<ExprKind<Expr>>,
span: Span,
}
-pub type UnspannedExpr<Embed> = ExprKind<Expr<Embed>, Embed>;
+pub type UnspannedExpr = ExprKind<Expr>;
/// Syntax tree for expressions
// Having the recursion out of the enum definition enables writing
// much more generic code and improves pattern-matching behind
// smart pointers.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub enum ExprKind<SubExpr, Embed> {
+pub enum ExprKind<SubExpr> {
Const(Const),
/// `x`
/// `x@n`
@@ -169,18 +169,13 @@ pub enum ExprKind<SubExpr, Embed> {
Completion(SubExpr, SubExpr),
/// `./some/path`
Import(Import<SubExpr>),
- /// Embeds the result of resolving an import
- Embed(Embed),
}
-impl<SE, E> ExprKind<SE, E> {
+impl<SE> ExprKind<SE> {
pub fn traverse_ref_maybe_binder<'a, SE2, Err>(
&'a self,
visit: impl FnMut(Option<&'a Label>, &'a SE) -> Result<SE2, Err>,
- ) -> Result<ExprKind<SE2, E>, Err>
- where
- E: Clone,
- {
+ ) -> Result<ExprKind<SE2>, Err> {
visitor::TraverseRefMaybeBinderVisitor(visit).visit(self)
}
@@ -188,10 +183,7 @@ impl<SE, E> ExprKind<SE, E> {
&'a self,
mut visit_subexpr: impl FnMut(&'a SE) -> Result<SE2, Err>,
mut visit_under_binder: impl FnMut(&'a Label, &'a SE) -> Result<SE2, Err>,
- ) -> Result<ExprKind<SE2, E>, Err>
- where
- E: Clone,
- {
+ ) -> Result<ExprKind<SE2>, Err> {
self.traverse_ref_maybe_binder(|l, x| match l {
None => visit_subexpr(x),
Some(l) => visit_under_binder(l, x),
@@ -201,20 +193,14 @@ impl<SE, E> ExprKind<SE, E> {
pub(crate) fn traverse_ref<'a, SE2, Err>(
&'a self,
mut visit_subexpr: impl FnMut(&'a SE) -> Result<SE2, Err>,
- ) -> Result<ExprKind<SE2, E>, Err>
- where
- E: Clone,
- {
+ ) -> Result<ExprKind<SE2>, Err> {
self.traverse_ref_maybe_binder(|_, e| visit_subexpr(e))
}
pub fn map_ref_maybe_binder<'a, SE2>(
&'a self,
mut map: impl FnMut(Option<&'a Label>, &'a SE) -> SE2,
- ) -> ExprKind<SE2, E>
- where
- E: Clone,
- {
+ ) -> ExprKind<SE2> {
trivial_result(self.traverse_ref_maybe_binder(|l, x| Ok(map(l, x))))
}
@@ -222,10 +208,7 @@ impl<SE, E> ExprKind<SE, E> {
&'a self,
mut map_subexpr: impl FnMut(&'a SE) -> SE2,
mut map_under_binder: impl FnMut(&'a Label, &'a SE) -> SE2,
- ) -> ExprKind<SE2, E>
- where
- E: Clone,
- {
+ ) -> ExprKind<SE2> {
self.map_ref_maybe_binder(|l, x| match l {
None => map_subexpr(x),
Some(l) => map_under_binder(l, x),
@@ -235,33 +218,30 @@ impl<SE, E> ExprKind<SE, E> {
pub fn map_ref<'a, SE2>(
&'a self,
mut map_subexpr: impl FnMut(&'a SE) -> SE2,
- ) -> ExprKind<SE2, E>
- where
- E: Clone,
- {
+ ) -> ExprKind<SE2> {
self.map_ref_maybe_binder(|_, e| map_subexpr(e))
}
}
-impl<E> Expr<E> {
- pub fn as_ref(&self) -> &UnspannedExpr<E> {
+impl Expr {
+ pub fn as_ref(&self) -> &UnspannedExpr {
&self.kind
}
- pub fn kind(&self) -> &UnspannedExpr<E> {
+ pub fn kind(&self) -> &UnspannedExpr {
&self.kind
}
pub fn span(&self) -> Span {
self.span.clone()
}
- pub fn new(kind: UnspannedExpr<E>, span: Span) -> Self {
+ pub fn new(kind: UnspannedExpr, span: Span) -> Self {
Expr {
kind: Box::new(kind),
span,
}
}
- pub fn rewrap<E2>(&self, kind: UnspannedExpr<E2>) -> Expr<E2> {
+ pub fn rewrap(&self, kind: UnspannedExpr) -> Expr {
Expr {
kind: Box::new(kind),
span: self.span.clone(),
@@ -317,15 +297,15 @@ impl From<Label> for V {
}
}
-impl<Embed: PartialEq> std::cmp::PartialEq for Expr<Embed> {
+impl std::cmp::PartialEq for Expr {
fn eq(&self, other: &Self) -> bool {
self.kind == other.kind
}
}
-impl<Embed: Eq> std::cmp::Eq for Expr<Embed> {}
+impl std::cmp::Eq for Expr {}
-impl<Embed: std::hash::Hash> std::hash::Hash for Expr<Embed> {
+impl std::hash::Hash for Expr {
fn hash<H>(&self, state: &mut H)
where
H: std::hash::Hasher,
diff --git a/dhall/src/syntax/ast/visitor.rs b/dhall/src/syntax/ast/visitor.rs
index c09b8d4..fc90efd 100644
--- a/dhall/src/syntax/ast/visitor.rs
+++ b/dhall/src/syntax/ast/visitor.rs
@@ -10,11 +10,10 @@ use crate::syntax::*;
/// preventing exactly this ! So we have to be more clever. The visitor pattern allows us to have
/// only one mutable thing the whole time: the visitor itself. The visitor can then carry around
/// multiple closures or just one, and Rust is ok with either. See for example TraverseRefVisitor.
-pub trait ExprKindVisitor<'a, SE1, SE2, E1, E2>: Sized {
+pub trait ExprKindVisitor<'a, SE1, SE2>: Sized {
type Error;
fn visit_subexpr(&mut self, subexpr: &'a SE1) -> Result<SE2, Self::Error>;
- fn visit_embed(self, embed: &'a E1) -> Result<E2, Self::Error>;
fn visit_subexpr_under_binder(
mut self,
@@ -26,18 +25,18 @@ pub trait ExprKindVisitor<'a, SE1, SE2, E1, E2>: Sized {
fn visit(
self,
- input: &'a ExprKind<SE1, E1>,
- ) -> Result<ExprKind<SE2, E2>, Self::Error> {
+ input: &'a ExprKind<SE1>,
+ ) -> Result<ExprKind<SE2>, Self::Error> {
visit_ref(self, input)
}
}
-fn visit_ref<'a, V, SE1, SE2, E1, E2>(
+fn visit_ref<'a, V, SE1, SE2>(
mut v: V,
- input: &'a ExprKind<SE1, E1>,
-) -> Result<ExprKind<SE2, E2>, V::Error>
+ input: &'a ExprKind<SE1>,
+) -> Result<ExprKind<SE2>, V::Error>
where
- V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2>,
{
fn vec<'a, T, U, Err, F: FnMut(&'a T) -> Result<U, Err>>(
x: &'a [T],
@@ -54,27 +53,27 @@ where
None => None,
})
}
- fn dupmap<'a, V, SE1, SE2, E1, E2, T>(
+ fn dupmap<'a, V, SE1, SE2, T>(
x: impl IntoIterator<Item = (&'a Label, &'a SE1)>,
mut v: V,
) -> Result<T, V::Error>
where
SE1: 'a,
T: FromIterator<(Label, SE2)>,
- V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2>,
{
x.into_iter()
.map(|(k, x)| Ok((k.clone(), v.visit_subexpr(x)?)))
.collect()
}
- fn optdupmap<'a, V, SE1, SE2, E1, E2, T>(
+ fn optdupmap<'a, V, SE1, SE2, T>(
x: impl IntoIterator<Item = (&'a Label, &'a Option<SE1>)>,
mut v: V,
) -> Result<T, V::Error>
where
SE1: 'a,
T: FromIterator<(Label, Option<SE2>)>,
- V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2>,
{
x.into_iter()
.map(|(k, x)| {
@@ -147,17 +146,15 @@ where
}
Assert(e) => Assert(v.visit_subexpr(e)?),
Import(i) => Import(i.traverse_ref(|e| v.visit_subexpr(e))?),
- Embed(a) => Embed(v.visit_embed(a)?),
})
}
pub struct TraverseRefMaybeBinderVisitor<F>(pub F);
-impl<'a, SE, E, SE2, Err, F> ExprKindVisitor<'a, SE, SE2, E, E>
+impl<'a, SE, SE2, Err, F> ExprKindVisitor<'a, SE, SE2>
for TraverseRefMaybeBinderVisitor<F>
where
SE: 'a,
- E: 'a + Clone,
F: FnMut(Option<&'a Label>, &'a SE) -> Result<SE2, Err>,
{
type Error = Err;
@@ -172,7 +169,4 @@ where
) -> Result<SE2, Self::Error> {
(self.0)(Some(label), subexpr)
}
- fn visit_embed(self, embed: &'a E) -> Result<E, Self::Error> {
- Ok(embed.clone())
- }
}
diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs
index 52b699c..6fbcc10 100644
--- a/dhall/src/syntax/binary/decode.rs
+++ b/dhall/src/syntax/binary/decode.rs
@@ -19,7 +19,7 @@ pub(crate) fn decode(data: &[u8]) -> Result<DecodedExpr, DecodeError> {
}
// Should probably rename this
-fn rc<E>(x: UnspannedExpr<E>) -> Expr<E> {
+fn rc(x: UnspannedExpr) -> Expr {
Expr::new(x, Span::Decoded)
}
diff --git a/dhall/src/syntax/binary/encode.rs b/dhall/src/syntax/binary/encode.rs
index 5e79f2d..686f737 100644
--- a/dhall/src/syntax/binary/encode.rs
+++ b/dhall/src/syntax/binary/encode.rs
@@ -9,17 +9,16 @@ use crate::syntax::{
Label, Scheme, V,
};
-/// Warning: will fail if `expr` contains an `Embed` node.
-pub(crate) fn encode<E>(expr: &Expr<E>) -> Result<Vec<u8>, EncodeError> {
+pub(crate) fn encode(expr: &Expr) -> Result<Vec<u8>, EncodeError> {
serde_cbor::ser::to_vec(&Serialize::Expr(expr))
.map_err(|e| EncodeError::CBORError(e))
}
-enum Serialize<'a, E> {
- Expr(&'a Expr<E>),
+enum Serialize<'a> {
+ Expr(&'a Expr),
CBOR(cbor::Value),
- RecordMap(&'a DupTreeMap<Label, Expr<E>>),
- UnionMap(&'a DupTreeMap<Label, Option<Expr<E>>>),
+ RecordMap(&'a DupTreeMap<Label, Expr>),
+ UnionMap(&'a DupTreeMap<Label, Option<Expr>>),
}
macro_rules! count {
@@ -39,7 +38,7 @@ macro_rules! ser_seq {
}};
}
-fn serialize_subexpr<S, E>(ser: S, e: &Expr<E>) -> Result<S::Ok, S::Error>
+fn serialize_subexpr<S>(ser: S, e: &Expr) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
@@ -49,11 +48,11 @@ where
use syntax::ExprKind::*;
use self::Serialize::{RecordMap, UnionMap};
- fn expr<E>(x: &Expr<E>) -> self::Serialize<'_, E> {
+ fn expr(x: &Expr) -> self::Serialize<'_> {
self::Serialize::Expr(x)
}
let cbor =
- |v: cbor::Value| -> self::Serialize<'_, E> { self::Serialize::CBOR(v) };
+ |v: cbor::Value| -> self::Serialize<'_> { self::Serialize::CBOR(v) };
let tag = |x: u64| cbor(U64(x));
let null = || cbor(cbor::Value::Null);
let label = |l: &Label| cbor(cbor::Value::String(l.into()));
@@ -166,16 +165,10 @@ where
}
Completion(x, y) => ser_seq!(ser; tag(3), tag(13), expr(x), expr(y)),
Import(import) => serialize_import(ser, import),
- Embed(_) => unimplemented!(
- "An expression with resolved imports cannot be binary-encoded"
- ),
}
}
-fn serialize_import<S, E>(
- ser: S,
- import: &Import<Expr<E>>,
-) -> Result<S::Ok, S::Error>
+fn serialize_import<S>(ser: S, import: &Import<Expr>) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
@@ -256,7 +249,7 @@ where
ser_seq.end()
}
-impl<'a, E> serde::ser::Serialize for Serialize<'a, E> {
+impl<'a> serde::ser::Serialize for Serialize<'a> {
fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
@@ -282,10 +275,8 @@ impl<'a, E> serde::ser::Serialize for Serialize<'a, E> {
}
}
-fn collect_nested_applications<'a, E>(
- e: &'a Expr<E>,
-) -> (&'a Expr<E>, Vec<&'a Expr<E>>) {
- fn go<'a, E>(e: &'a Expr<E>, vec: &mut Vec<&'a Expr<E>>) -> &'a Expr<E> {
+fn collect_nested_applications<'a>(e: &'a Expr) -> (&'a Expr, Vec<&'a Expr>) {
+ fn go<'a>(e: &'a Expr, vec: &mut Vec<&'a Expr>) -> &'a Expr {
match e.as_ref() {
ExprKind::App(f, a) => {
vec.push(a);
@@ -299,15 +290,10 @@ fn collect_nested_applications<'a, E>(
(e, vec)
}
-type LetBinding<'a, E> = (&'a Label, &'a Option<Expr<E>>, &'a Expr<E>);
+type LetBinding<'a> = (&'a Label, &'a Option<Expr>, &'a Expr);
-fn collect_nested_lets<'a, E>(
- e: &'a Expr<E>,
-) -> (&'a Expr<E>, Vec<LetBinding<'a, E>>) {
- fn go<'a, E>(
- e: &'a Expr<E>,
- vec: &mut Vec<LetBinding<'a, E>>,
- ) -> &'a Expr<E> {
+fn collect_nested_lets<'a>(e: &'a Expr) -> (&'a Expr, Vec<LetBinding<'a>>) {
+ fn go<'a>(e: &'a Expr, vec: &mut Vec<LetBinding<'a>>) -> &'a Expr {
match e.as_ref() {
ExprKind::Let(l, t, v, e) => {
vec.push((l, t, v));
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index 8d571c0..0ff1363 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -5,23 +5,19 @@ use std::rc::Rc;
use pest_consume::{match_nodes, Parser};
-use crate::syntax;
use crate::syntax::map::{DupTreeMap, DupTreeSet};
use crate::syntax::ExprKind::*;
use crate::syntax::{
- Double, FilePath, FilePrefix, Hash, ImportLocation, ImportMode, Integer,
- InterpolatedText, InterpolatedTextContents, Label, NaiveDouble, Natural,
- Scheme, Span, URL, V,
+ Double, Expr, FilePath, FilePrefix, Hash, ImportLocation, ImportMode,
+ Integer, InterpolatedText, InterpolatedTextContents, Label, NaiveDouble,
+ Natural, Scheme, Span, UnspannedExpr, URL, V,
};
-use crate::Normalized;
// This file consumes the parse tree generated by pest and turns it into
// our own AST. All those custom macros should eventually moved into
// their own crate because they are quite general and useful. For now they
// are here and hopefully you can figure out how they work.
-type Expr = syntax::Expr<Normalized>;
-type UnspannedExpr = syntax::UnspannedExpr<Normalized>;
type ParsedText = InterpolatedText<Expr>;
type ParsedTextContents = InterpolatedTextContents<Expr>;
type ParseInput<'input> = pest_consume::Node<'input, Rule, Rc<str>>;
diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs
index 06dd70f..d1c9588 100644
--- a/dhall/src/syntax/text/printer.rs
+++ b/dhall/src/syntax/text/printer.rs
@@ -19,17 +19,17 @@ enum PrintPhase {
// Wraps an Expr with a phase, so that phase selection can be done separate from the actual
// printing.
#[derive(Clone)]
-struct PhasedExpr<'a, E>(&'a Expr<E>, PrintPhase);
+struct PhasedExpr<'a>(&'a Expr, PrintPhase);
-impl<'a, E: Display + Clone> PhasedExpr<'a, E> {
- fn phase(self, phase: PrintPhase) -> PhasedExpr<'a, E> {
+impl<'a> PhasedExpr<'a> {
+ fn phase(self, phase: PrintPhase) -> PhasedExpr<'a> {
PhasedExpr(self.0, phase)
}
}
-impl<E: Display + Clone> UnspannedExpr<E> {
+impl UnspannedExpr {
// Annotate subexpressions with the appropriate phase, defaulting to Base
- fn annotate_with_phases<'a>(&'a self) -> ExprKind<PhasedExpr<'a, E>, E> {
+ fn annotate_with_phases<'a>(&'a self) -> ExprKind<PhasedExpr<'a>> {
use crate::syntax::ExprKind::*;
use PrintPhase::*;
let with_base = self.map_ref(|e| PhasedExpr(e, Base));
@@ -134,7 +134,7 @@ where
}
/// Generic instance that delegates to subexpressions
-impl<SE: Display + Clone, E: Display> Display for ExprKind<SE, E> {
+impl<SE: Display + Clone> Display for ExprKind<SE> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use crate::syntax::ExprKind::*;
match self {
@@ -232,19 +232,18 @@ impl<SE: Display + Clone, E: Display> Display for ExprKind<SE, E> {
write!(f, "{}::{}", a, b)?;
}
Import(a) => a.fmt(f)?,
- Embed(a) => a.fmt(f)?,
}
Ok(())
}
}
-impl<E: Display + Clone> Display for Expr<E> {
+impl Display for Expr {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.as_ref().fmt_phase(f, PrintPhase::Base)
}
}
-impl<'a, E: Display + Clone> Display for PhasedExpr<'a, E> {
+impl<'a> Display for PhasedExpr<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.0.as_ref().fmt_phase(f, self.1)
}
diff --git a/serde_dhall/src/serde.rs b/serde_dhall/src/serde.rs
index 3e78987..92a0015 100644
--- a/serde_dhall/src/serde.rs
+++ b/serde_dhall/src/serde.rs
@@ -115,7 +115,7 @@ impl<'de: 'a, 'a> serde::Deserializer<'de> for Deserializer<'a> {
| Assert(..) | Builtin(..) | BinOp(..) | BoolIf(..)
| RecordType(..) | UnionType(..) | Merge(..) | ToMap(..)
| Projection(..) | ProjectionByExpr(..) | Completion(..)
- | Import(..) | Embed(..) => not_serde_compatible(),
+ | Import(..) => not_serde_compatible(),
}
}