From 711164a7a24ab832006b72cac162e78cf434861a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 4 Aug 2019 11:11:37 +0200 Subject: Remove old-style optional literals --- dhall/src/phase/normalize.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'dhall/src/phase/normalize.rs') 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> { pub fn normalize_one_layer(expr: ExprF) -> 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) -> 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))) -- cgit v1.2.3 From 2551e6f91110bfe385fa65dd63e576df637c26fa Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 5 Aug 2019 18:18:45 +0200 Subject: Add some tests --- dhall/src/phase/normalize.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'dhall/src/phase/normalize.rs') diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index f3684d1..d5bdc9e 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -72,6 +72,16 @@ pub fn apply_builtin(b: Builtin, args: Vec) -> Value { (TextShow, [v, r..]) => match &*v.as_value() { TextLit(elts) => { match elts.as_slice() { + // Empty string literal. + [] => { + // Printing InterpolatedText takes care of all the escaping + let txt: InterpolatedText = std::iter::empty().collect(); + let s = txt.to_string(); + Ok(( + r, + TextLit(vec![InterpolatedTextContents::Text(s)]), + )) + } // If there are no interpolations (invariants ensure that when there are no // interpolations, there is a single Text item) in the literal. [InterpolatedTextContents::Text(s)] => { -- cgit v1.2.3 From 749834cb5e166665476f2fbc83fdfec794d90cec Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 21:29:44 +0200 Subject: rustfmt --- dhall/src/phase/normalize.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dhall/src/phase/normalize.rs') diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index d5bdc9e..4bc0f04 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -75,7 +75,8 @@ pub fn apply_builtin(b: Builtin, args: Vec) -> Value { // Empty string literal. [] => { // Printing InterpolatedText takes care of all the escaping - let txt: InterpolatedText = std::iter::empty().collect(); + let txt: InterpolatedText = + std::iter::empty().collect(); let s = txt.to_string(); Ok(( r, -- cgit v1.2.3 From 705433487da3cd3b4517fcf74b0497c76dbb4080 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 22:36:43 +0200 Subject: Prepare for https://github.com/dhall-lang/dhall-lang/pull/630 --- dhall/src/phase/normalize.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'dhall/src/phase/normalize.rs') diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index 4bc0f04..2e9f258 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -622,9 +622,9 @@ fn apply_binop<'a>(o: BinOp, x: &'a Thunk, y: &'a Thunk) -> Option> { pub fn normalize_one_layer(expr: ExprF) -> Value { use Value::{ - BoolLit, DoubleLit, EmptyListLit, IntegerLit, Lam, NEListLit, - NEOptionalLit, NaturalLit, Pi, RecordLit, RecordType, TextLit, - UnionConstructor, UnionLit, UnionType, + AppliedBuiltin, BoolLit, DoubleLit, EmptyListLit, IntegerLit, Lam, + NEListLit, NEOptionalLit, NaturalLit, Pi, RecordLit, RecordType, + TextLit, UnionConstructor, UnionLit, UnionType, }; let ret = match expr { @@ -651,8 +651,20 @@ pub fn normalize_one_layer(expr: ExprF) -> Value { ExprF::IntegerLit(n) => Ret::Value(IntegerLit(n)), ExprF::DoubleLit(n) => Ret::Value(DoubleLit(n)), ExprF::SomeLit(e) => Ret::Value(NEOptionalLit(e)), - ExprF::EmptyListLit(t) => { - Ret::Value(EmptyListLit(TypeThunk::from_thunk(t))) + ExprF::EmptyListLit(ref t) => { + // Check if the type is of the form `List x` + let t_borrow = t.as_value(); + match &*t_borrow { + AppliedBuiltin(Builtin::List, args) if args.len() == 1 => { + Ret::Value(EmptyListLit(TypeThunk::from_thunk( + args[0].clone(), + ))) + } + _ => { + drop(t_borrow); + Ret::Expr(expr) + } + } } ExprF::NEListLit(elts) => { Ret::Value(NEListLit(elts.into_iter().collect())) -- cgit v1.2.3 From d248762095908246951b6aa6c211587c6e333c0e Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 21:05:01 +0200 Subject: Remove union literals from the language --- dhall/src/phase/normalize.rs | 7 ------- 1 file changed, 7 deletions(-) (limited to 'dhall/src/phase/normalize.rs') diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index 2e9f258..3e45240 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -677,13 +677,6 @@ pub fn normalize_one_layer(expr: ExprF) -> Value { .map(|(k, t)| (k, TypeThunk::from_thunk(t))) .collect(), )), - ExprF::UnionLit(l, x, kts) => Ret::Value(UnionLit( - l, - x, - kts.into_iter() - .map(|(k, t)| (k, t.map(|t| TypeThunk::from_thunk(t)))) - .collect(), - )), ExprF::UnionType(kts) => Ret::Value(UnionType( kts.into_iter() .map(|(k, t)| (k, t.map(|t| TypeThunk::from_thunk(t)))) -- cgit v1.2.3 From 51c4f79fe092191d670ffa2f9098693079dbc1be Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 21:18:11 +0200 Subject: Add truncated Natural subtraction --- dhall/src/phase/normalize.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'dhall/src/phase/normalize.rs') diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index 3e45240..395cf28 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -47,6 +47,16 @@ pub fn apply_builtin(b: Builtin, args: Vec) -> Value { )), _ => Err(()), }, + (NaturalSubtract, [a, b, r..]) => { + match (&*a.as_value(), &*b.as_value()) { + (NaturalLit(a), NaturalLit(b)) => { + Ok((r, NaturalLit(if b > a { b - a } else { 0 }))) + } + (NaturalLit(0), b) => Ok((r, b.clone())), + (_, NaturalLit(0)) => Ok((r, NaturalLit(0))), + _ => Err(()), + } + } (IntegerShow, [n, r..]) => match &*n.as_value() { IntegerLit(n) => { let s = if *n < 0 { -- cgit v1.2.3 From 071ba528cd8c6a222be345ddec7560bb45cca6be Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 8 Aug 2019 19:33:07 +0200 Subject: Add support for dependent types --- dhall/src/phase/normalize.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'dhall/src/phase/normalize.rs') diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index 395cf28..ecad063 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -508,9 +508,9 @@ where fn apply_binop<'a>(o: BinOp, x: &'a Thunk, y: &'a Thunk) -> Option> { use BinOp::{ - BoolAnd, BoolEQ, BoolNE, BoolOr, ListAppend, NaturalPlus, NaturalTimes, - RecursiveRecordMerge, RecursiveRecordTypeMerge, RightBiasedRecordMerge, - TextAppend, + BoolAnd, BoolEQ, BoolNE, BoolOr, Equivalence, ListAppend, NaturalPlus, + NaturalTimes, RecursiveRecordMerge, RecursiveRecordTypeMerge, + RightBiasedRecordMerge, TextAppend, }; use Value::{ BoolLit, EmptyListLit, NEListLit, NaturalLit, RecordLit, RecordType, @@ -626,6 +626,11 @@ fn apply_binop<'a>(o: BinOp, x: &'a Thunk, y: &'a Thunk) -> Option> { Ret::Value(RecordType(kvs)) } + (Equivalence, _, _) => Ret::Value(Value::Equivalence( + TypeThunk::from_thunk(x.clone()), + TypeThunk::from_thunk(y.clone()), + )), + _ => return None, }) } @@ -641,6 +646,7 @@ pub fn normalize_one_layer(expr: ExprF) -> Value { ExprF::Embed(_) => unreachable!(), ExprF::Var(_) => unreachable!(), ExprF::Annot(x, _) => Ret::Thunk(x), + ExprF::Assert(_) => Ret::Expr(expr), ExprF::Lam(x, t, e) => { Ret::Value(Lam(x.into(), TypeThunk::from_thunk(t), e)) } -- cgit v1.2.3 From 4d94c3bbf955c5c32cee0651820484c4e4b6cd90 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 8 Aug 2019 19:45:52 +0200 Subject: Update dhall-lang submodule --- dhall/src/phase/normalize.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'dhall/src/phase/normalize.rs') diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index ecad063..405677a 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -54,6 +54,7 @@ pub fn apply_builtin(b: Builtin, args: Vec) -> Value { } (NaturalLit(0), b) => Ok((r, b.clone())), (_, NaturalLit(0)) => Ok((r, NaturalLit(0))), + _ if a == b => Ok((r, NaturalLit(0))), _ => Err(()), } } -- cgit v1.2.3