summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-08-04 11:11:37 +0200
committerNadrieril2019-08-06 21:40:24 +0200
commit711164a7a24ab832006b72cac162e78cf434861a (patch)
treecdb2097aa25e20c2953cd5d0192ce66274def33b /dhall
parentcc03ada4e713f145f2eb1bbf0f131a4c5746cf74 (diff)
Remove old-style optional literals
Diffstat (limited to '')
m---------dhall-lang0
-rw-r--r--dhall/src/phase/binary.rs16
-rw-r--r--dhall/src/phase/normalize.rs10
-rw-r--r--dhall/src/phase/typecheck.rs27
-rw-r--r--dhall_generated_parser/src/dhall.pest.visibility2
-rw-r--r--dhall_syntax/src/core/expr.rs4
-rw-r--r--dhall_syntax/src/core/visitor.rs4
-rw-r--r--dhall_syntax/src/parser.rs18
-rw-r--r--dhall_syntax/src/printer.rs8
9 files changed, 19 insertions, 70 deletions
diff --git a/dhall-lang b/dhall-lang
-Subproject b1f98152c404b661233db9a834d8e31ab270447
+Subproject b1992297d702c67d2e1b1597af5c533af293430
diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs
index 874b4fb..dcf60bb 100644
--- a/dhall/src/phase/binary.rs
+++ b/dhall/src/phase/binary.rs
@@ -115,18 +115,22 @@ fn cbor_value_to_dhall(
.collect::<Result<Vec<_>, _>>()?;
NEListLit(rest)
}
- [U64(5), t] => {
- let t = cbor_value_to_dhall(&t)?;
- OldOptionalLit(None, t)
- }
[U64(5), Null, x] => {
let x = cbor_value_to_dhall(&x)?;
SomeLit(x)
}
+ // Old-style optional literals
+ [U64(5), t] => {
+ let t = cbor_value_to_dhall(&t)?;
+ App(rc(ExprF::Builtin(Builtin::OptionalNone)), t)
+ }
[U64(5), t, x] => {
let x = cbor_value_to_dhall(&x)?;
let t = cbor_value_to_dhall(&t)?;
- OldOptionalLit(Some(x), t)
+ Annot(
+ rc(SomeLit(x)),
+ rc(App(rc(ExprF::Builtin(Builtin::Optional)), t)),
+ )
}
[U64(6), x, y] => {
let x = cbor_value_to_dhall(&x)?;
@@ -460,8 +464,6 @@ where
)
}
Annot(x, y) => ser_seq!(ser; tag(26), expr(x), expr(y)),
- OldOptionalLit(None, t) => ser_seq!(ser; tag(5), expr(t)),
- OldOptionalLit(Some(x), t) => ser_seq!(ser; tag(5), expr(t), expr(x)),
SomeLit(x) => ser_seq!(ser; tag(5), null(), expr(x)),
EmptyListLit(x) => ser_seq!(ser; tag(4), expr(x)),
NEListLit(xs) => ser.collect_seq(
diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs
index 35d32cb..f3684d1 100644
--- a/dhall/src/phase/normalize.rs
+++ b/dhall/src/phase/normalize.rs
@@ -611,9 +611,9 @@ fn apply_binop<'a>(o: BinOp, x: &'a Thunk, y: &'a Thunk) -> Option<Ret<'a>> {
pub fn normalize_one_layer(expr: ExprF<Thunk, X>) -> Value {
use Value::{
- BoolLit, DoubleLit, EmptyListLit, EmptyOptionalLit, IntegerLit, Lam,
- NEListLit, NEOptionalLit, NaturalLit, Pi, RecordLit, RecordType,
- TextLit, UnionConstructor, UnionLit, UnionType,
+ BoolLit, DoubleLit, EmptyListLit, IntegerLit, Lam, NEListLit,
+ NEOptionalLit, NaturalLit, Pi, RecordLit, RecordType, TextLit,
+ UnionConstructor, UnionLit, UnionType,
};
let ret = match expr {
@@ -639,10 +639,6 @@ pub fn normalize_one_layer(expr: ExprF<Thunk, X>) -> Value {
ExprF::NaturalLit(n) => Ret::Value(NaturalLit(n)),
ExprF::IntegerLit(n) => Ret::Value(IntegerLit(n)),
ExprF::DoubleLit(n) => Ret::Value(DoubleLit(n)),
- ExprF::OldOptionalLit(None, t) => {
- Ret::Value(EmptyOptionalLit(TypeThunk::from_thunk(t)))
- }
- ExprF::OldOptionalLit(Some(e), _) => Ret::Value(NEOptionalLit(e)),
ExprF::SomeLit(e) => Ret::Value(NEOptionalLit(e)),
ExprF::EmptyListLit(t) => {
Ret::Value(EmptyListLit(TypeThunk::from_thunk(t)))
diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs
index efdc2bb..8551503 100644
--- a/dhall/src/phase/typecheck.rs
+++ b/dhall/src/phase/typecheck.rs
@@ -329,9 +329,7 @@ fn type_with(
ctx: &TypecheckContext,
e: SubExpr<Span, Normalized>,
) -> Result<Typed, TypeError> {
- use dhall_syntax::ExprF::{
- Annot, App, Embed, Lam, Let, OldOptionalLit, Pi, SomeLit, Var,
- };
+ use dhall_syntax::ExprF::{Annot, Embed, Lam, Let, Pi, Var};
use Ret::*;
Ok(match e.as_ref() {
@@ -364,18 +362,6 @@ fn type_with(
let v = type_with(ctx, v)?;
return type_with(&ctx.insert_value(x, v.clone())?, e.clone());
}
- OldOptionalLit(None, t) => {
- let none = SubExpr::from_builtin(Builtin::OptionalNone);
- let e = e.rewrap(App(none, t.clone()));
- return type_with(ctx, e);
- }
- OldOptionalLit(Some(x), t) => {
- let optional = SubExpr::from_builtin(Builtin::Optional);
- let x = x.rewrap(SomeLit(x.clone()));
- let t = t.rewrap(App(optional, t.clone()));
- let e = e.rewrap(Annot(x, t));
- return type_with(ctx, e);
- }
Embed(p) => p.clone().into_typed(),
Var(var) => match ctx.lookup(&var) {
Some(typed) => typed,
@@ -423,12 +409,9 @@ fn type_last_layer(
let mkerr = |msg: TypeMessage| TypeError::new(ctx, msg);
match e {
- Lam(_, _, _)
- | Pi(_, _, _)
- | Let(_, _, _, _)
- | OldOptionalLit(_, _)
- | Embed(_)
- | Var(_) => unreachable!(),
+ Lam(_, _, _) | Pi(_, _, _) | Let(_, _, _, _) | Embed(_) | Var(_) => {
+ unreachable!()
+ }
App(f, a) => {
let tf = f.get_type()?;
let (x, tx, tb) = match &tf.to_value() {
@@ -1296,8 +1279,6 @@ mod spec_tests {
ti_success!(ti_success_unit_NaturalShow, "unit/NaturalShow");
ti_success!(ti_success_unit_NaturalToInteger, "unit/NaturalToInteger");
ti_success!(ti_success_unit_None, "unit/None");
- ti_success!(ti_success_unit_OldOptionalNone, "unit/OldOptionalNone");
- ti_success!(ti_success_unit_OldOptionalTrue, "unit/OldOptionalTrue");
ti_success!(ti_success_unit_OperatorAnd, "unit/OperatorAnd");
ti_success!(ti_success_unit_OperatorAndNormalizeArguments, "unit/OperatorAndNormalizeArguments");
ti_success!(ti_success_unit_OperatorEqual, "unit/OperatorEqual");
diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility
index 60de54d..0c48656 100644
--- a/dhall_generated_parser/src/dhall.pest.visibility
+++ b/dhall_generated_parser/src/dhall.pest.visibility
@@ -134,8 +134,6 @@ import
expression
annotated_expression
let_binding
-empty_collection
-non_empty_optional
# operator_expression
import_alt_expression
or_expression
diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs
index da9465d..df2dc97 100644
--- a/dhall_syntax/src/core/expr.rs
+++ b/dhall_syntax/src/core/expr.rs
@@ -194,10 +194,6 @@ pub enum ExprF<SubExpr, Embed> {
EmptyListLit(SubExpr),
/// `[x, y, z]`
NEListLit(Vec<SubExpr>),
- /// Deprecated Optional literal form
- /// `[] : Optional a`
- /// `[x] : Optional a`
- OldOptionalLit(Option<SubExpr>, SubExpr),
/// `Some e`
SomeLit(SubExpr),
/// `{ k1 : t1, k2 : t1 }`
diff --git a/dhall_syntax/src/core/visitor.rs b/dhall_syntax/src/core/visitor.rs
index 99a9c11..1745fdb 100644
--- a/dhall_syntax/src/core/visitor.rs
+++ b/dhall_syntax/src/core/visitor.rs
@@ -137,10 +137,6 @@ where
),
EmptyListLit(t) => EmptyListLit(v.visit_subexpr(t)?),
NEListLit(es) => NEListLit(vec(es, |e| v.visit_subexpr(e))?),
- OldOptionalLit(x, t) => OldOptionalLit(
- opt(x, |e| v.visit_subexpr(e))?,
- v.visit_subexpr(t)?,
- ),
SomeLit(e) => SomeLit(v.visit_subexpr(e)?),
RecordType(kts) => RecordType(dupmap(kts, v)?),
RecordLit(kvs) => RecordLit(dupmap(kvs, v)?),
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs
index 9d9a374..db1699b 100644
--- a/dhall_syntax/src/parser.rs
+++ b/dhall_syntax/src/parser.rs
@@ -724,6 +724,9 @@ make_parser! {
[merge(()), expression(x), expression(y), expression(z)] => {
spanned(span, Merge(x, y, Some(z)))
},
+ [List(()), expression(x)] => {
+ spanned(span, EmptyListLit(x))
+ },
[expression(e)] => e,
));
@@ -738,21 +741,6 @@ make_parser! {
token_rule!(List<()>);
token_rule!(Optional<()>);
- rule!(empty_collection<ParsedSubExpr> as expression; span; children!(
- [List(_), expression(t)] => {
- spanned(span, EmptyListLit(t))
- },
- [Optional(_), expression(t)] => {
- spanned(span, OldOptionalLit(None, t))
- },
- ));
-
- rule!(non_empty_optional<ParsedSubExpr> as expression; span; children!(
- [expression(x), Optional(_), expression(t)] => {
- spanned(span, OldOptionalLit(Some(x), t))
- }
- ));
-
rule!(import_alt_expression<ParsedSubExpr> as expression; children!(
[expression(e)] => e,
[expression(first), expression(rest)..] => {
diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs
index dbed55d..b585a5b 100644
--- a/dhall_syntax/src/printer.rs
+++ b/dhall_syntax/src/printer.rs
@@ -32,12 +32,6 @@ impl<SE: Display + Clone, E: Display> Display for ExprF<SE, E> {
NEListLit(es) => {
fmt_list("[", ", ", "]", es, f, Display::fmt)?;
}
- OldOptionalLit(None, t) => {
- write!(f, "[] : Optional {}", t)?;
- }
- OldOptionalLit(Some(x), t) => {
- write!(f, "[{}] : Optional {}", x, t)?;
- }
SomeLit(e) => {
write!(f, "Some {}", e)?;
}
@@ -154,7 +148,6 @@ impl<S: Clone, A: Display + Clone> Expr<S, A> {
| Let(_, _, _, _)
| EmptyListLit(_)
| NEListLit(_)
- | OldOptionalLit(_, _)
| SomeLit(_)
| Merge(_, _, _)
| Annot(_, _)
@@ -190,7 +183,6 @@ impl<S: Clone, A: Display + Clone> Expr<S, A> {
b.phase(PrintPhase::BinOp(op)),
),
EmptyListLit(t) => EmptyListLit(t.phase(Import)),
- OldOptionalLit(x, t) => OldOptionalLit(x, t.phase(Import)),
SomeLit(e) => SomeLit(e.phase(Import)),
ExprF::App(f, a) => ExprF::App(f.phase(Import), a.phase(Import)),
Field(a, b) => Field(a.phase(Primitive), b),