summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
authorNadrieril2019-12-20 18:12:10 +0000
committerNadrieril2019-12-20 18:12:10 +0000
commite355984c3c83f8288eac36023c361db869643367 (patch)
treee8a65c2a3e962da51d9cd6bc5a3fdf996c883432 /dhall/src
parent78d066a44c5598794602effa4c10a09f80ed1e72 (diff)
s/ExprF/ExprKind/
Diffstat (limited to 'dhall/src')
-rw-r--r--dhall/src/semantics/core/value_kind.rs4
-rw-r--r--dhall/src/semantics/core/var.rs6
-rw-r--r--dhall/src/semantics/phase/normalize.rs76
-rw-r--r--dhall/src/semantics/phase/typecheck.rs45
-rw-r--r--dhall/src/semantics/to_expr.rs54
-rw-r--r--dhall/src/syntax/ast/expr.rs24
-rw-r--r--dhall/src/syntax/ast/visitor.rs47
-rw-r--r--dhall/src/syntax/binary/decode.rs12
-rw-r--r--dhall/src/syntax/binary/encode.rs14
-rw-r--r--dhall/src/syntax/text/parser.rs2
-rw-r--r--dhall/src/syntax/text/printer.rs20
11 files changed, 156 insertions, 148 deletions
diff --git a/dhall/src/semantics/core/value_kind.rs b/dhall/src/semantics/core/value_kind.rs
index 47df39d..35b2b23 100644
--- a/dhall/src/semantics/core/value_kind.rs
+++ b/dhall/src/semantics/core/value_kind.rs
@@ -5,7 +5,7 @@ use crate::semantics::core::var::{AlphaLabel, AlphaVar, Shift, Subst};
use crate::semantics::phase::{Normalized, NormalizedExpr};
use crate::semantics::to_expr;
use crate::syntax::{
- Builtin, Const, ExprF, Integer, InterpolatedTextContents, Label,
+ Builtin, Const, ExprKind, Integer, InterpolatedTextContents, Label,
NaiveDouble, Natural,
};
@@ -43,7 +43,7 @@ pub(crate) enum ValueKind {
TextLit(Vec<InterpolatedTextContents<Value>>),
Equivalence(Value, Value),
// Invariant: in whnf, this must not contain a value captured by one of the variants above.
- PartialExpr(ExprF<Value, Normalized>),
+ PartialExpr(ExprKind<Value, Normalized>),
}
impl ValueKind {
diff --git a/dhall/src/semantics/core/var.rs b/dhall/src/semantics/core/var.rs
index 77473f6..1548713 100644
--- a/dhall/src/semantics/core/var.rs
+++ b/dhall/src/semantics/core/var.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
-use crate::syntax::{ExprF, InterpolatedTextContents, Label, V};
+use crate::syntax::{ExprKind, InterpolatedTextContents, Label, V};
/// Stores a pair of variables: a normal one and one
/// that corresponds to the alpha-normalized version of the first one.
@@ -190,7 +190,7 @@ impl<T: Shift> Shift for std::cell::RefCell<T> {
}
}
-impl<T: Shift, E: Clone> Shift for ExprF<T, E> {
+impl<T: Shift, E: Clone> Shift for ExprKind<T, E> {
fn shift(&self, delta: isize, var: &AlphaVar) -> Option<Self> {
Some(self.traverse_ref_with_special_handling_of_binders(
|v| Ok(v.shift(delta, var)?),
@@ -262,7 +262,7 @@ impl<S, T: Subst<S>> Subst<S> for std::cell::RefCell<T> {
}
}
-impl<S: Shift, T: Subst<S>, E: Clone> Subst<S> for ExprF<T, E> {
+impl<S: Shift, T: Subst<S>, E: Clone> Subst<S> for ExprKind<T, E> {
fn subst_shift(&self, var: &AlphaVar, val: &S) -> Self {
self.map_ref_with_special_handling_of_binders(
|v| v.subst_shift(var, val),
diff --git a/dhall/src/semantics/phase/normalize.rs b/dhall/src/semantics/phase/normalize.rs
index 157d1f3..3e612aa 100644
--- a/dhall/src/semantics/phase/normalize.rs
+++ b/dhall/src/semantics/phase/normalize.rs
@@ -7,8 +7,8 @@ use crate::semantics::phase::Normalized;
use crate::syntax;
use crate::syntax::Const::Type;
use crate::syntax::{
- BinOp, Builtin, ExprF, InterpolatedText, InterpolatedTextContents, Label,
- NaiveDouble,
+ BinOp, Builtin, ExprKind, InterpolatedText, InterpolatedTextContents,
+ Label, NaiveDouble,
};
// Ad-hoc macro to help construct closures
@@ -46,7 +46,7 @@ macro_rules! make_closure {
ValueKind::NEOptionalLit(v).into_value_with_type(opt_v_type)
}};
(1 + $($rest:tt)*) => {
- ValueKind::PartialExpr(ExprF::BinOp(
+ ValueKind::PartialExpr(ExprKind::BinOp(
syntax::BinOp::NaturalPlus,
make_closure!($($rest)*),
Value::from_kind_and_type(
@@ -61,7 +61,7 @@ macro_rules! make_closure {
let head = make_closure!($($head)*);
let tail = make_closure!($($tail)*);
let list_type = tail.get_type_not_sort();
- ValueKind::PartialExpr(ExprF::BinOp(
+ ValueKind::PartialExpr(ExprKind::BinOp(
syntax::BinOp::ListAppend,
ValueKind::NEListLit(vec![head])
.into_value_with_type(list_type.clone()),
@@ -404,7 +404,7 @@ pub(crate) fn apply_any(f: Value, a: Value, ty: &Value) -> ValueKind {
}
_ => {
drop(f_borrow);
- ValueKind::PartialExpr(ExprF::App(f, a))
+ ValueKind::PartialExpr(ExprKind::App(f, a))
}
}
}
@@ -482,7 +482,7 @@ enum Ret<'a> {
ValueKind(ValueKind),
Value(Value),
ValueRef(&'a Value),
- Expr(ExprF<Value, Normalized>),
+ Expr(ExprKind<Value, Normalized>),
}
fn apply_binop<'a>(
@@ -590,7 +590,7 @@ fn apply_binop<'a>(
};
let kvs = merge_maps::<_, _, _, !>(kvs1, kvs2, |k, v1, v2| {
Ok(Value::from_kind_and_type(
- ValueKind::PartialExpr(ExprF::BinOp(
+ ValueKind::PartialExpr(ExprKind::BinOp(
RecursiveRecordMerge,
v1.clone(),
v2.clone(),
@@ -610,7 +610,7 @@ fn apply_binop<'a>(
}
pub(crate) fn normalize_one_layer(
- expr: ExprF<Value, Normalized>,
+ expr: ExprKind<Value, Normalized>,
ty: &Value,
) -> ValueKind {
use ValueKind::{
@@ -620,31 +620,31 @@ pub(crate) fn normalize_one_layer(
};
let ret = match expr {
- ExprF::Import(_) => unreachable!(
+ ExprKind::Import(_) => unreachable!(
"There should remain no imports in a resolved expression"
),
// Those cases have already been completely handled in the typechecking phase (using
// `RetWhole`), so they won't appear here.
- ExprF::Lam(_, _, _)
- | ExprF::Pi(_, _, _)
- | ExprF::Let(_, _, _, _)
- | ExprF::Embed(_)
- | ExprF::Const(_)
- | ExprF::Builtin(_)
- | ExprF::Var(_)
- | ExprF::Annot(_, _)
- | ExprF::RecordType(_)
- | ExprF::UnionType(_) => {
+ ExprKind::Lam(_, _, _)
+ | ExprKind::Pi(_, _, _)
+ | ExprKind::Let(_, _, _, _)
+ | ExprKind::Embed(_)
+ | ExprKind::Const(_)
+ | ExprKind::Builtin(_)
+ | ExprKind::Var(_)
+ | ExprKind::Annot(_, _)
+ | ExprKind::RecordType(_)
+ | ExprKind::UnionType(_) => {
unreachable!("This case should have been handled in typecheck")
}
- ExprF::Assert(_) => Ret::Expr(expr),
- ExprF::App(v, a) => Ret::Value(v.app(a)),
- ExprF::BoolLit(b) => Ret::ValueKind(BoolLit(b)),
- ExprF::NaturalLit(n) => Ret::ValueKind(NaturalLit(n)),
- ExprF::IntegerLit(n) => Ret::ValueKind(IntegerLit(n)),
- ExprF::DoubleLit(n) => Ret::ValueKind(DoubleLit(n)),
- ExprF::SomeLit(e) => Ret::ValueKind(NEOptionalLit(e)),
- ExprF::EmptyListLit(ref t) => {
+ ExprKind::Assert(_) => Ret::Expr(expr),
+ ExprKind::App(v, a) => Ret::Value(v.app(a)),
+ ExprKind::BoolLit(b) => Ret::ValueKind(BoolLit(b)),
+ ExprKind::NaturalLit(n) => Ret::ValueKind(NaturalLit(n)),
+ ExprKind::IntegerLit(n) => Ret::ValueKind(IntegerLit(n)),
+ ExprKind::DoubleLit(n) => Ret::ValueKind(DoubleLit(n)),
+ ExprKind::SomeLit(e) => Ret::ValueKind(NEOptionalLit(e)),
+ ExprKind::EmptyListLit(ref t) => {
// Check if the type is of the form `List x`
let t_borrow = t.as_whnf();
match &*t_borrow {
@@ -657,13 +657,13 @@ pub(crate) fn normalize_one_layer(
}
}
}
- ExprF::NEListLit(elts) => {
+ ExprKind::NEListLit(elts) => {
Ret::ValueKind(NEListLit(elts.into_iter().collect()))
}
- ExprF::RecordLit(kvs) => {
+ ExprKind::RecordLit(kvs) => {
Ret::ValueKind(RecordLit(kvs.into_iter().collect()))
}
- ExprF::TextLit(elts) => {
+ ExprKind::TextLit(elts) => {
use InterpolatedTextContents::Expr;
let elts: Vec<_> = squash_textlit(elts.into_iter());
// Simplify bare interpolation
@@ -673,7 +673,7 @@ pub(crate) fn normalize_one_layer(
Ret::ValueKind(TextLit(elts))
}
}
- ExprF::BoolIf(ref b, ref e1, ref e2) => {
+ ExprKind::BoolIf(ref b, ref e1, ref e2) => {
let b_borrow = b.as_whnf();
match &*b_borrow {
BoolLit(true) => Ret::ValueRef(e1),
@@ -695,15 +695,15 @@ pub(crate) fn normalize_one_layer(
}
}
}
- ExprF::BinOp(o, ref x, ref y) => match apply_binop(o, x, y, ty) {
+ ExprKind::BinOp(o, ref x, ref y) => match apply_binop(o, x, y, ty) {
Some(ret) => ret,
None => Ret::Expr(expr),
},
- ExprF::Projection(_, ref ls) if ls.is_empty() => {
+ ExprKind::Projection(_, ref ls) if ls.is_empty() => {
Ret::ValueKind(RecordLit(HashMap::new()))
}
- ExprF::Projection(ref v, ref ls) => {
+ ExprKind::Projection(ref v, ref ls) => {
let v_borrow = v.as_whnf();
match &*v_borrow {
RecordLit(kvs) => Ret::ValueKind(RecordLit(
@@ -719,7 +719,7 @@ pub(crate) fn normalize_one_layer(
}
}
}
- ExprF::Field(ref v, ref l) => {
+ ExprKind::Field(ref v, ref l) => {
let v_borrow = v.as_whnf();
match &*v_borrow {
RecordLit(kvs) => match kvs.get(l) {
@@ -738,11 +738,11 @@ pub(crate) fn normalize_one_layer(
}
}
}
- ExprF::ProjectionByExpr(_, _) => {
+ ExprKind::ProjectionByExpr(_, _) => {
unimplemented!("selection by expression")
}
- ExprF::Merge(ref handlers, ref variant, _) => {
+ ExprKind::Merge(ref handlers, ref variant, _) => {
let handlers_borrow = handlers.as_whnf();
let variant_borrow = variant.as_whnf();
match (&*handlers_borrow, &*variant_borrow) {
@@ -769,7 +769,7 @@ pub(crate) fn normalize_one_layer(
}
}
}
- ExprF::ToMap(_, _) => unimplemented!("toMap"),
+ ExprKind::ToMap(_, _) => unimplemented!("toMap"),
};
match ret {
diff --git a/dhall/src/semantics/phase/typecheck.rs b/dhall/src/semantics/phase/typecheck.rs
index 5041235..f83bb94 100644
--- a/dhall/src/semantics/phase/typecheck.rs
+++ b/dhall/src/semantics/phase/typecheck.rs
@@ -10,7 +10,8 @@ use crate::semantics::phase::normalize::merge_maps;
use crate::semantics::phase::Normalized;
use crate::syntax;
use crate::syntax::{
- Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, RawExpr, Span,
+ Builtin, Const, Expr, ExprKind, InterpolatedTextContents, Label, RawExpr,
+ Span,
};
fn tck_pi_type(
@@ -149,24 +150,24 @@ pub fn rc<E>(x: RawExpr<E>) -> Expr<E> {
// Ad-hoc macro to help construct the types of builtins
macro_rules! make_type {
- (Type) => { ExprF::Const(Const::Type) };
- (Bool) => { ExprF::Builtin(Builtin::Bool) };
- (Natural) => { ExprF::Builtin(Builtin::Natural) };
- (Integer) => { ExprF::Builtin(Builtin::Integer) };
- (Double) => { ExprF::Builtin(Builtin::Double) };
- (Text) => { ExprF::Builtin(Builtin::Text) };
+ (Type) => { ExprKind::Const(Const::Type) };
+ (Bool) => { ExprKind::Builtin(Builtin::Bool) };
+ (Natural) => { ExprKind::Builtin(Builtin::Natural) };
+ (Integer) => { ExprKind::Builtin(Builtin::Integer) };
+ (Double) => { ExprKind::Builtin(Builtin::Double) };
+ (Text) => { ExprKind::Builtin(Builtin::Text) };
($var:ident) => {
- ExprF::Var(syntax::V(stringify!($var).into(), 0))
+ ExprKind::Var(syntax::V(stringify!($var).into(), 0))
};
(Optional $ty:ident) => {
- ExprF::App(
- rc(ExprF::Builtin(Builtin::Optional)),
+ ExprKind::App(
+ rc(ExprKind::Builtin(Builtin::Optional)),
rc(make_type!($ty))
)
};
(List $($rest:tt)*) => {
- ExprF::App(
- rc(ExprF::Builtin(Builtin::List)),
+ ExprKind::App(
+ rc(ExprKind::Builtin(Builtin::List)),
rc(make_type!($($rest)*))
)
};
@@ -178,24 +179,24 @@ macro_rules! make_type {
rc(make_type!($ty)),
);
)*
- ExprF::RecordType(kts)
+ ExprKind::RecordType(kts)
}};
($ty:ident -> $($rest:tt)*) => {
- ExprF::Pi(
+ ExprKind::Pi(
"_".into(),
rc(make_type!($ty)),
rc(make_type!($($rest)*))
)
};
(($($arg:tt)*) -> $($rest:tt)*) => {
- ExprF::Pi(
+ ExprKind::Pi(
"_".into(),
rc(make_type!($($arg)*)),
rc(make_type!($($rest)*))
)
};
(forall ($var:ident : $($ty:tt)*) -> $($rest:tt)*) => {
- ExprF::Pi(
+ ExprKind::Pi(
stringify!($var).into(),
rc(make_type!($($ty)*)),
rc(make_type!($($rest)*))
@@ -304,7 +305,7 @@ fn type_with(
ctx: &TypecheckContext,
e: Expr<Normalized>,
) -> Result<Value, TypeError> {
- use syntax::ExprF::{Annot, Embed, Lam, Let, Pi, Var};
+ use syntax::ExprKind::{Annot, Embed, Lam, Let, Pi, Var};
let span = e.span();
Ok(match e.as_ref() {
@@ -359,13 +360,13 @@ fn type_with(
/// layer.
fn type_last_layer(
ctx: &TypecheckContext,
- e: ExprF<Value, Normalized>,
+ e: ExprKind<Value, Normalized>,
span: Span,
) -> Result<Value, TypeError> {
use syntax::BinOp::*;
use syntax::Builtin::*;
use syntax::Const::Type;
- use syntax::ExprF::*;
+ use syntax::ExprKind::*;
use TypeMessage::*;
let mkerr = |msg: TypeMessage| Err(TypeError::new(ctx, msg));
@@ -578,7 +579,7 @@ fn type_last_layer(
}
BinOp(RecursiveRecordMerge, l, r) => RetTypeOnly(type_last_layer(
ctx,
- ExprF::BinOp(
+ ExprKind::BinOp(
RecursiveRecordTypeMerge,
l.get_type()?,
r.get_type()?,
@@ -612,7 +613,7 @@ fn type_last_layer(
|_, l: &Value, r: &Value| {
type_last_layer(
ctx,
- ExprF::BinOp(
+ ExprKind::BinOp(
RecursiveRecordTypeMerge,
l.clone(),
r.clone(),
@@ -806,5 +807,5 @@ pub(crate) fn typecheck_with(
expr: Expr<Normalized>,
ty: Expr<Normalized>,
) -> Result<Value, TypeError> {
- typecheck(expr.rewrap(ExprF::Annot(expr.clone(), ty)))
+ typecheck(expr.rewrap(ExprKind::Annot(expr.clone(), ty)))
}
diff --git a/dhall/src/semantics/to_expr.rs b/dhall/src/semantics/to_expr.rs
index 74bd2fe..6099976 100644
--- a/dhall/src/semantics/to_expr.rs
+++ b/dhall/src/semantics/to_expr.rs
@@ -3,7 +3,7 @@ use crate::semantics::core::value_kind::ValueKind;
use crate::semantics::phase::typecheck::rc;
use crate::semantics::phase::NormalizedExpr;
use crate::syntax;
-use crate::syntax::{Builtin, ExprF};
+use crate::syntax::{Builtin, ExprKind};
#[derive(Copy, Clone)]
/// Controls conversion from `Value` to `Expr`
@@ -31,7 +31,7 @@ pub(crate) fn kind_to_expr(
opts: ToExprOptions,
) -> NormalizedExpr {
match kind {
- ValueKind::Lam(x, t, e) => rc(ExprF::Lam(
+ ValueKind::Lam(x, t, e) => rc(ExprKind::Lam(
x.to_label_maybe_alpha(opts.alpha),
t.to_expr(opts),
e.to_expr(opts),
@@ -39,59 +39,63 @@ pub(crate) fn kind_to_expr(
ValueKind::AppliedBuiltin(b, args) => args
.iter()
.map(|v| v.to_expr(opts))
- .fold(rc(ExprF::Builtin(*b)), |acc, v| rc(ExprF::App(acc, v))),
- ValueKind::Pi(x, t, e) => rc(ExprF::Pi(
+ .fold(rc(ExprKind::Builtin(*b)), |acc, v| {
+ rc(ExprKind::App(acc, v))
+ }),
+ ValueKind::Pi(x, t, e) => rc(ExprKind::Pi(
x.to_label_maybe_alpha(opts.alpha),
t.to_expr(opts),
e.to_expr(opts),
)),
- ValueKind::Var(v) => rc(ExprF::Var(v.to_var(opts.alpha))),
- ValueKind::Const(c) => rc(ExprF::Const(*c)),
- ValueKind::BoolLit(b) => rc(ExprF::BoolLit(*b)),
- ValueKind::NaturalLit(n) => rc(ExprF::NaturalLit(*n)),
- ValueKind::IntegerLit(n) => rc(ExprF::IntegerLit(*n)),
- ValueKind::DoubleLit(n) => rc(ExprF::DoubleLit(*n)),
- ValueKind::EmptyOptionalLit(n) => rc(ExprF::App(
- rc(ExprF::Builtin(Builtin::OptionalNone)),
+ ValueKind::Var(v) => rc(ExprKind::Var(v.to_var(opts.alpha))),
+ ValueKind::Const(c) => rc(ExprKind::Const(*c)),
+ ValueKind::BoolLit(b) => rc(ExprKind::BoolLit(*b)),
+ ValueKind::NaturalLit(n) => rc(ExprKind::NaturalLit(*n)),
+ ValueKind::IntegerLit(n) => rc(ExprKind::IntegerLit(*n)),
+ ValueKind::DoubleLit(n) => rc(ExprKind::DoubleLit(*n)),
+ ValueKind::EmptyOptionalLit(n) => rc(ExprKind::App(
+ rc(ExprKind::Builtin(Builtin::OptionalNone)),
n.to_expr(opts),
)),
- ValueKind::NEOptionalLit(n) => rc(ExprF::SomeLit(n.to_expr(opts))),
- ValueKind::EmptyListLit(n) => rc(ExprF::EmptyListLit(rc(ExprF::App(
- rc(ExprF::Builtin(Builtin::List)),
- n.to_expr(opts),
- )))),
- ValueKind::NEListLit(elts) => rc(ExprF::NEListLit(
+ ValueKind::NEOptionalLit(n) => rc(ExprKind::SomeLit(n.to_expr(opts))),
+ ValueKind::EmptyListLit(n) => {
+ rc(ExprKind::EmptyListLit(rc(ExprKind::App(
+ rc(ExprKind::Builtin(Builtin::List)),
+ n.to_expr(opts),
+ ))))
+ }
+ ValueKind::NEListLit(elts) => rc(ExprKind::NEListLit(
elts.iter().map(|n| n.to_expr(opts)).collect(),
)),
- ValueKind::RecordLit(kvs) => rc(ExprF::RecordLit(
+ ValueKind::RecordLit(kvs) => rc(ExprKind::RecordLit(
kvs.iter()
.map(|(k, v)| (k.clone(), v.to_expr(opts)))
.collect(),
)),
- ValueKind::RecordType(kts) => rc(ExprF::RecordType(
+ ValueKind::RecordType(kts) => rc(ExprKind::RecordType(
kts.iter()
.map(|(k, v)| (k.clone(), v.to_expr(opts)))
.collect(),
)),
- ValueKind::UnionType(kts) => rc(ExprF::UnionType(
+ ValueKind::UnionType(kts) => rc(ExprKind::UnionType(
kts.iter()
.map(|(k, v)| (k.clone(), v.as_ref().map(|v| v.to_expr(opts))))
.collect(),
)),
- ValueKind::UnionConstructor(l, kts) => rc(ExprF::Field(
+ ValueKind::UnionConstructor(l, kts) => rc(ExprKind::Field(
ValueKind::UnionType(kts.clone()).to_expr(opts),
l.clone(),
)),
- ValueKind::UnionLit(l, v, kts) => rc(ExprF::App(
+ ValueKind::UnionLit(l, v, kts) => rc(ExprKind::App(
ValueKind::UnionConstructor(l.clone(), kts.clone()).to_expr(opts),
v.to_expr(opts),
)),
- ValueKind::TextLit(elts) => rc(ExprF::TextLit(
+ ValueKind::TextLit(elts) => rc(ExprKind::TextLit(
elts.iter()
.map(|contents| contents.map_ref(|e| e.to_expr(opts)))
.collect(),
)),
- ValueKind::Equivalence(x, y) => rc(ExprF::BinOp(
+ ValueKind::Equivalence(x, y) => rc(ExprKind::BinOp(
syntax::BinOp::Equivalence,
x.to_expr(opts),
y.to_expr(opts),
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 5b9f401..7ac342d 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -1,5 +1,5 @@
use crate::syntax::map::{DupTreeMap, DupTreeSet};
-use crate::syntax::visitor::{self, ExprFMutVisitor, ExprFVisitor};
+use crate::syntax::visitor::{self, ExprKindMutVisitor, ExprKindVisitor};
use crate::syntax::*;
pub type Integer = isize;
@@ -144,7 +144,7 @@ pub enum Builtin {
#[derive(Debug, Clone)]
pub struct Expr<Embed>(Box<(RawExpr<Embed>, Span)>);
-pub type RawExpr<Embed> = ExprF<Expr<Embed>, Embed>;
+pub type RawExpr<Embed> = ExprKind<Expr<Embed>, Embed>;
impl<Embed: PartialEq> std::cmp::PartialEq for Expr<Embed> {
fn eq(&self, other: &Self) -> bool {
@@ -168,7 +168,7 @@ impl<Embed: std::hash::Hash> std::hash::Hash for Expr<Embed> {
// much more generic code and improves pattern-matching behind
// smart pointers.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub enum ExprF<SubExpr, Embed> {
+pub enum ExprKind<SubExpr, Embed> {
Const(Const),
/// `x`
/// `x@n`
@@ -231,12 +231,12 @@ pub enum ExprF<SubExpr, Embed> {
Embed(Embed),
}
-impl<SE, E> ExprF<SE, E> {
+impl<SE, E> ExprKind<SE, E> {
pub fn traverse_ref_with_special_handling_of_binders<'a, SE2, Err>(
&'a self,
visit_subexpr: impl FnMut(&'a SE) -> Result<SE2, Err>,
visit_under_binder: impl FnOnce(&'a Label, &'a SE) -> Result<SE2, Err>,
- ) -> Result<ExprF<SE2, E>, Err>
+ ) -> Result<ExprKind<SE2, E>, Err>
where
E: Clone,
{
@@ -250,7 +250,7 @@ impl<SE, E> ExprF<SE, E> {
fn traverse_ref<'a, SE2, Err>(
&'a self,
visit_subexpr: impl FnMut(&'a SE) -> Result<SE2, Err>,
- ) -> Result<ExprF<SE2, E>, Err>
+ ) -> Result<ExprKind<SE2, E>, Err>
where
E: Clone,
{
@@ -268,7 +268,7 @@ impl<SE, E> ExprF<SE, E> {
&'a self,
mut map_subexpr: impl FnMut(&'a SE) -> SE2,
mut map_under_binder: impl FnMut(&'a Label, &'a SE) -> SE2,
- ) -> ExprF<SE2, E>
+ ) -> ExprKind<SE2, E>
where
E: Clone,
{
@@ -281,7 +281,7 @@ impl<SE, E> ExprF<SE, E> {
pub fn map_ref<'a, SE2>(
&'a self,
mut map_subexpr: impl FnMut(&'a SE) -> SE2,
- ) -> ExprF<SE2, E>
+ ) -> ExprKind<SE2, E>
where
E: Clone,
{
@@ -321,8 +321,8 @@ impl<E> Expr<E> {
F1: FnMut(Import<Expr<E>>) -> Result<E, Err>,
{
match self.as_mut() {
- ExprF::BinOp(BinOp::ImportAlt, l, r) => {
- let garbage_expr = ExprF::BoolLit(false);
+ ExprKind::BinOp(BinOp::ImportAlt, l, r) => {
+ let garbage_expr = ExprKind::BoolLit(false);
let new_self = if l.traverse_resolve_mut(f).is_ok() {
l
} else {
@@ -334,7 +334,7 @@ impl<E> Expr<E> {
}
_ => {
self.as_mut().traverse_mut(|e| e.traverse_resolve_mut(f))?;
- if let ExprF::Import(import) = self.as_mut() {
+ if let ExprKind::Import(import) = self.as_mut() {
let garbage_import = Import {
mode: ImportMode::Code,
location: ImportLocation::Missing,
@@ -342,7 +342,7 @@ impl<E> Expr<E> {
};
// Move out of &mut import
let import = std::mem::replace(import, garbage_import);
- *self.as_mut() = ExprF::Embed(f(import)?);
+ *self.as_mut() = ExprKind::Embed(f(import)?);
}
}
}
diff --git a/dhall/src/syntax/ast/visitor.rs b/dhall/src/syntax/ast/visitor.rs
index b76d037..b557995 100644
--- a/dhall/src/syntax/ast/visitor.rs
+++ b/dhall/src/syntax/ast/visitor.rs
@@ -1,7 +1,7 @@
use crate::syntax::*;
use std::iter::FromIterator;
-/// A visitor trait that can be used to traverse `ExprF`s. We need this pattern so that Rust lets
+/// A visitor trait that can be used to traverse `ExprKind`s. We need this pattern so that Rust lets
/// us have as much mutability as we can.
/// For example, `traverse_ref_with_special_handling_of_binders` cannot be made using only
/// `traverse_ref`, because `traverse_ref` takes a `FnMut` so we would need to pass multiple
@@ -9,7 +9,7 @@ use std::iter::FromIterator;
/// 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 ExprFVisitor<'a, SE1, SE2, E1, E2>: Sized {
+pub trait ExprKindVisitor<'a, SE1, SE2, E1, E2>: Sized {
type Error;
fn visit_subexpr(&mut self, subexpr: &'a SE1) -> Result<SE2, Self::Error>;
@@ -25,14 +25,14 @@ pub trait ExprFVisitor<'a, SE1, SE2, E1, E2>: Sized {
fn visit(
self,
- input: &'a ExprF<SE1, E1>,
- ) -> Result<ExprF<SE2, E2>, Self::Error> {
+ input: &'a ExprKind<SE1, E1>,
+ ) -> Result<ExprKind<SE2, E2>, Self::Error> {
visit_ref(self, input)
}
}
-/// Like `ExprFVisitor`, but by mutable reference
-pub trait ExprFMutVisitor<'a, SE, E>: Sized {
+/// Like `ExprKindVisitor`, but by mutable reference
+pub trait ExprKindMutVisitor<'a, SE, E>: Sized {
type Error;
fn visit_subexpr(&mut self, subexpr: &'a mut SE)
@@ -49,17 +49,17 @@ pub trait ExprFMutVisitor<'a, SE, E>: Sized {
self.visit_subexpr(subexpr)
}
- fn visit(self, input: &'a mut ExprF<SE, E>) -> Result<(), Self::Error> {
+ fn visit(self, input: &'a mut ExprKind<SE, E>) -> Result<(), Self::Error> {
visit_mut(self, input)
}
}
fn visit_ref<'a, V, SE1, SE2, E1, E2>(
mut v: V,
- input: &'a ExprF<SE1, E1>,
-) -> Result<ExprF<SE2, E2>, V::Error>
+ input: &'a ExprKind<SE1, E1>,
+) -> Result<ExprKind<SE2, E2>, V::Error>
where
- V: ExprFVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
{
fn vec<'a, T, U, Err, F: FnMut(&'a T) -> Result<U, Err>>(
x: &'a [T],
@@ -83,7 +83,7 @@ where
where
SE1: 'a,
T: FromIterator<(Label, SE2)>,
- V: ExprFVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
{
x.into_iter()
.map(|(k, x)| Ok((k.clone(), v.visit_subexpr(x)?)))
@@ -96,7 +96,7 @@ where
where
SE1: 'a,
T: FromIterator<(Label, Option<SE2>)>,
- V: ExprFVisitor<'a, SE1, SE2, E1, E2>,
+ V: ExprKindVisitor<'a, SE1, SE2, E1, E2>,
{
x.into_iter()
.map(|(k, x)| {
@@ -111,7 +111,7 @@ where
.collect()
}
- use crate::syntax::ExprF::*;
+ use crate::syntax::ExprKind::*;
Ok(match input {
Var(v) => Var(v.clone()),
Lam(l, t, e) => {
@@ -172,14 +172,14 @@ where
fn visit_mut<'a, V, SE, E>(
mut v: V,
- input: &'a mut ExprF<SE, E>,
+ input: &'a mut ExprKind<SE, E>,
) -> Result<(), V::Error>
where
- V: ExprFMutVisitor<'a, SE, E>,
+ V: ExprKindMutVisitor<'a, SE, E>,
{
fn vec<'a, V, SE, E>(v: &mut V, x: &'a mut Vec<SE>) -> Result<(), V::Error>
where
- V: ExprFMutVisitor<'a, SE, E>,
+ V: ExprKindMutVisitor<'a, SE, E>,
{
for x in x {
v.visit_subexpr(x)?;
@@ -191,7 +191,7 @@ where
x: &'a mut Option<SE>,
) -> Result<(), V::Error>
where
- V: ExprFMutVisitor<'a, SE, E>,
+ V: ExprKindMutVisitor<'a, SE, E>,
{
if let Some(x) = x {
v.visit_subexpr(x)?;
@@ -204,7 +204,7 @@ where
) -> Result<(), V::Error>
where
SE: 'a,
- V: ExprFMutVisitor<'a, SE, E>,
+ V: ExprKindMutVisitor<'a, SE, E>,
{
for (_, x) in x {
v.visit_subexpr(x)?;
@@ -217,7 +217,7 @@ where
) -> Result<(), V::Error>
where
SE: 'a,
- V: ExprFMutVisitor<'a, SE, E>,
+ V: ExprKindMutVisitor<'a, SE, E>,
{
for (_, x) in x {
opt(&mut v, x)?;
@@ -225,7 +225,7 @@ where
Ok(())
}
- use crate::syntax::ExprF::*;
+ use crate::syntax::ExprKind::*;
match input {
Var(_) | Const(_) | Builtin(_) | BoolLit(_) | NaturalLit(_)
| IntegerLit(_) | DoubleLit(_) => {}
@@ -293,7 +293,7 @@ pub struct TraverseRefWithBindersVisitor<F1, F2> {
pub visit_under_binder: F2,
}
-impl<'a, SE, E, SE2, Err, F1, F2> ExprFVisitor<'a, SE, SE2, E, E>
+impl<'a, SE, E, SE2, Err, F1, F2> ExprKindVisitor<'a, SE, SE2, E, E>
for TraverseRefWithBindersVisitor<F1, F2>
where
SE: 'a,
@@ -322,7 +322,7 @@ pub struct TraverseRefVisitor<F1> {
pub visit_subexpr: F1,
}
-impl<'a, SE, E, SE2, Err, F1> ExprFVisitor<'a, SE, SE2, E, E>
+impl<'a, SE, E, SE2, Err, F1> ExprKindVisitor<'a, SE, SE2, E, E>
for TraverseRefVisitor<F1>
where
SE: 'a,
@@ -343,7 +343,8 @@ pub struct TraverseMutVisitor<F1> {
pub visit_subexpr: F1,
}
-impl<'a, SE, E, Err, F1> ExprFMutVisitor<'a, SE, E> for TraverseMutVisitor<F1>
+impl<'a, SE, E, Err, F1> ExprKindMutVisitor<'a, SE, E>
+ for TraverseMutVisitor<F1>
where
SE: 'a,
E: 'a,
diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs
index f452666..8b73e46 100644
--- a/dhall/src/syntax/binary/decode.rs
+++ b/dhall/src/syntax/binary/decode.rs
@@ -6,7 +6,7 @@ use crate::error::DecodeError;
use crate::semantics::phase::DecodedExpr;
use crate::syntax;
use crate::syntax::{
- Expr, ExprF, FilePath, FilePrefix, Hash, ImportLocation, ImportMode,
+ Expr, ExprKind, FilePath, FilePrefix, Hash, ImportLocation, ImportMode,
Integer, InterpolatedText, Label, Natural, RawExpr, Scheme, Span, URL, V,
};
@@ -25,10 +25,10 @@ fn rc<E>(x: RawExpr<E>) -> Expr<E> {
fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
use cbor::Value::*;
use syntax::{BinOp, Builtin, Const};
- use ExprF::*;
+ use ExprKind::*;
Ok(rc(match data {
String(s) => match Builtin::parse(s) {
- Some(b) => ExprF::Builtin(b),
+ Some(b) => ExprKind::Builtin(b),
None => match s.as_str() {
"True" => BoolLit(true),
"False" => BoolLit(false),
@@ -123,7 +123,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
}
[U64(4), t] => {
let t = cbor_value_to_dhall(&t)?;
- EmptyListLit(rc(App(rc(ExprF::Builtin(Builtin::List)), t)))
+ EmptyListLit(rc(App(rc(ExprKind::Builtin(Builtin::List)), t)))
}
[U64(4), Null, rest @ ..] => {
let rest = rest
@@ -139,14 +139,14 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
// Old-style optional literals
[U64(5), t] => {
let t = cbor_value_to_dhall(&t)?;
- App(rc(ExprF::Builtin(Builtin::OptionalNone)), t)
+ App(rc(ExprKind::Builtin(Builtin::OptionalNone)), t)
}
[U64(5), t, x] => {
let x = cbor_value_to_dhall(&x)?;
let t = cbor_value_to_dhall(&t)?;
Annot(
rc(SomeLit(x)),
- rc(App(rc(ExprF::Builtin(Builtin::Optional)), t)),
+ rc(App(rc(ExprKind::Builtin(Builtin::Optional)), t)),
)
}
[U64(6), x, y] => {
diff --git a/dhall/src/syntax/binary/encode.rs b/dhall/src/syntax/binary/encode.rs
index c1e7c4c..25a545c 100644
--- a/dhall/src/syntax/binary/encode.rs
+++ b/dhall/src/syntax/binary/encode.rs
@@ -5,8 +5,8 @@ use crate::error::EncodeError;
use crate::syntax;
use crate::syntax::map::DupTreeMap;
use crate::syntax::{
- Expr, ExprF, FilePrefix, Hash, Import, ImportLocation, ImportMode, Label,
- Scheme, V,
+ Expr, ExprKind, FilePrefix, Hash, Import, ImportLocation, ImportMode,
+ Label, Scheme, V,
};
/// Warning: will fail if `expr` contains an `Embed` node.
@@ -46,7 +46,7 @@ where
use cbor::Value::{String, I64, U64};
use std::iter::once;
use syntax::Builtin;
- use syntax::ExprF::*;
+ use syntax::ExprKind::*;
use self::Serialize::{RecordMap, UnionMap};
fn expr<E>(x: &Expr<E>) -> self::Serialize<'_, E> {
@@ -110,7 +110,9 @@ where
SomeLit(x) => ser_seq!(ser; tag(5), null(), expr(x)),
EmptyListLit(x) => match x.as_ref() {
App(f, a) => match f.as_ref() {
- ExprF::Builtin(Builtin::List) => ser_seq!(ser; tag(4), expr(a)),
+ ExprKind::Builtin(Builtin::List) => {
+ ser_seq!(ser; tag(4), expr(a))
+ }
_ => ser_seq!(ser; tag(28), expr(x)),
},
_ => ser_seq!(ser; tag(28), expr(x)),
@@ -284,7 +286,7 @@ fn collect_nested_applications<'a, 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> {
match e.as_ref() {
- ExprF::App(f, a) => {
+ ExprKind::App(f, a) => {
vec.push(a);
go(f, vec)
}
@@ -306,7 +308,7 @@ fn collect_nested_lets<'a, E>(
vec: &mut Vec<LetBinding<'a, E>>,
) -> &'a Expr<E> {
match e.as_ref() {
- ExprF::Let(l, t, v, e) => {
+ ExprKind::Let(l, t, v, e) => {
vec.push((l, t, v));
go(e, vec)
}
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index 617348b..e1bb469 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -8,7 +8,7 @@ use pest_consume::{match_nodes, Parser};
use crate::semantics::phase::Normalized;
use crate::syntax;
use crate::syntax::map::{DupTreeMap, DupTreeSet};
-use crate::syntax::ExprF::*;
+use crate::syntax::ExprKind::*;
use crate::syntax::{
Double, FilePath, FilePrefix, Hash, ImportLocation, ImportMode, Integer,
InterpolatedText, InterpolatedTextContents, Label, NaiveDouble, Natural,
diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs
index 7ccc708..75703d2 100644
--- a/dhall/src/syntax/text/printer.rs
+++ b/dhall/src/syntax/text/printer.rs
@@ -3,9 +3,9 @@ use itertools::Itertools;
use std::fmt::{self, Display};
/// Generic instance that delegates to subexpressions
-impl<SE: Display + Clone, E: Display> Display for ExprF<SE, E> {
+impl<SE: Display + Clone, E: Display> Display for ExprKind<SE, E> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- use crate::syntax::ExprF::*;
+ use crate::syntax::ExprKind::*;
match self {
Lam(a, b, c) => {
write!(f, "λ({} : {}) → {}", a, b, c)?;
@@ -53,10 +53,10 @@ impl<SE: Display + Clone, E: Display> Display for ExprF<SE, E> {
Assert(a) => {
write!(f, "assert : {}", a)?;
}
- ExprF::BinOp(op, a, b) => {
+ ExprKind::BinOp(op, a, b) => {
write!(f, "{} {} {}", a, op, b)?;
}
- ExprF::App(a, b) => {
+ ExprKind::App(a, b) => {
write!(f, "{} {}", a, b)?;
}
Field(a, b) => {
@@ -141,7 +141,7 @@ impl<A: Display + Clone> RawExpr<A> {
f: &mut fmt::Formatter,
phase: PrintPhase,
) -> Result<(), fmt::Error> {
- use crate::syntax::ExprF::*;
+ use crate::syntax::ExprKind::*;
use PrintPhase::*;
let needs_paren = match self {
@@ -160,8 +160,8 @@ impl<A: Display + Clone> RawExpr<A> {
true
}
// Precedence is magically handled by the ordering of BinOps.
- ExprF::BinOp(op, _, _) if phase > PrintPhase::BinOp(*op) => true,
- ExprF::App(_, _) if phase > PrintPhase::App => true,
+ ExprKind::BinOp(op, _, _) if phase > PrintPhase::BinOp(*op) => true,
+ ExprKind::App(_, _) if phase > PrintPhase::App => true,
Field(_, _) | Projection(_, _) | ProjectionByExpr(_, _)
if phase > PrintPhase::Import =>
{
@@ -189,13 +189,13 @@ impl<A: Display + Clone> RawExpr<A> {
b.map(|x| x.phase(PrintPhase::App)),
),
Annot(a, b) => Annot(a.phase(Operator), b),
- ExprF::BinOp(op, a, b) => ExprF::BinOp(
+ ExprKind::BinOp(op, a, b) => ExprKind::BinOp(
op,
a.phase(PrintPhase::BinOp(op)),
b.phase(PrintPhase::BinOp(op)),
),
SomeLit(e) => SomeLit(e.phase(PrintPhase::Import)),
- ExprF::App(f, a) => ExprF::App(
+ ExprKind::App(f, a) => ExprKind::App(
f.phase(PrintPhase::Import),
a.phase(PrintPhase::Import),
),
@@ -209,7 +209,7 @@ impl<A: Display + Clone> RawExpr<A> {
f.write_str("(")?;
}
- // Uses the ExprF<PhasedExpr<_>, _> instance
+ // Uses the ExprKind<PhasedExpr<_>, _> instance
phased_self.fmt(f)?;
if needs_paren {