From cc03ada4e713f145f2eb1bbf0f131a4c5746cf74 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 3 Aug 2019 22:55:51 +0200 Subject: Inline headers --- dhall-lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index ee528e5..b1f9815 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit ee528e5a89f78bce2c28167b5dfb7e7ea6b3d6c7 +Subproject commit b1f98152c404b661233db9a834d8e31ab2704479 -- cgit v1.3.1 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-lang | 2 +- dhall/src/phase/binary.rs | 16 ++++++++------ dhall/src/phase/normalize.rs | 10 +++------ dhall/src/phase/typecheck.rs | 27 ++++-------------------- dhall_generated_parser/src/dhall.pest.visibility | 2 -- dhall_syntax/src/core/expr.rs | 4 ---- dhall_syntax/src/core/visitor.rs | 4 ---- dhall_syntax/src/parser.rs | 18 +++------------- dhall_syntax/src/printer.rs | 8 ------- tests_buffer | 3 +++ 10 files changed, 23 insertions(+), 71 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index b1f9815..b199229 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit b1f98152c404b661233db9a834d8e31ab2704479 +Subproject commit b1992297d702c67d2e1b1597af5c533af2934300 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::, _>>()?; 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> { 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))) 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, ) -> Result { - 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 { EmptyListLit(SubExpr), /// `[x, y, z]` NEListLit(Vec), - /// Deprecated Optional literal form - /// `[] : Optional a` - /// `[x] : Optional a` - OldOptionalLit(Option, 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 as expression; span; children!( - [List(_), expression(t)] => { - spanned(span, EmptyListLit(t)) - }, - [Optional(_), expression(t)] => { - spanned(span, OldOptionalLit(None, t)) - }, - )); - - rule!(non_empty_optional as expression; span; children!( - [expression(x), Optional(_), expression(t)] => { - spanned(span, OldOptionalLit(Some(x), t)) - } - )); - rule!(import_alt_expression 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 Display for ExprF { 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 Expr { | Let(_, _, _, _) | EmptyListLit(_) | NEListLit(_) - | OldOptionalLit(_, _) | SomeLit(_) | Merge(_, _, _) | Annot(_, _) @@ -190,7 +183,6 @@ impl Expr { 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), diff --git a/tests_buffer b/tests_buffer index 1ea9a1c..deb245d 100644 --- a/tests_buffer +++ b/tests_buffer @@ -86,6 +86,8 @@ success/ failure/ ProjectionByExpressionNeedsParens r.{ x: T } +binary decoding: +decode old-style optional literals ? import: success/ @@ -104,6 +106,7 @@ variables across import boundaries typecheck: something that involves destructuring a recordtype after merge +failure on old-style optional literal success/ MergeEmptyAlternative merge { x = 1 } < x >.x MergeTrickyShadowing let _ = Bool in merge {_ = \(x: _) -> x} (<_: Bool>._ True) -- cgit v1.3.1 From 5f872a7a5de12898fce32c057818ac2efb90e3fb Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 4 Aug 2019 11:15:18 +0200 Subject: Update dhall-lang submodule --- dhall-lang | 2 +- dhall/src/phase/resolve.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index b199229..0396b67 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit b1992297d702c67d2e1b1597af5c533af2934300 +Subproject commit 0396b67639a6deaff480844e71b576db998717d3 diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index 8c561a3..f1329aa 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -128,6 +128,8 @@ mod spec_tests { // import_success!(success_asText, "asText"); // import_success!(success_customHeaders, "customHeaders"); import_success!(success_fieldOrder, "fieldOrder"); + // note: this one needs special setup with env variables + // import_success!(success_hashFromCache, "hashFromCache"); // import_success!(success_headerForwarding, "headerForwarding"); // import_success!(success_noHeaderForwarding, "noHeaderForwarding"); // import_failure!(failure_alternativeEnv, "alternativeEnv"); -- cgit v1.3.1 From e52f50080d8e0e6d6a05b1045e3e0e840acb50d0 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 4 Aug 2019 14:07:34 +0200 Subject: Braced escape sequences --- dhall-lang | 2 +- dhall_generated_parser/src/dhall.pest.visibility | 1 + dhall_syntax/src/parser.rs | 28 ++++++++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 0396b67..dbf4ebc 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 0396b67639a6deaff480844e71b576db998717d3 +Subproject commit dbf4ebcfabf499e87c27e75bec108d91929ccc31 diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility index 0c48656..2b7c477 100644 --- a/dhall_generated_parser/src/dhall.pest.visibility +++ b/dhall_generated_parser/src/dhall.pest.visibility @@ -21,6 +21,7 @@ label # any_label double_quote_chunk double_quote_escaped +# unicode_escape double_quote_char double_quote_literal single_quote_continue diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index db1699b..2450c76 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -402,11 +402,31 @@ make_parser! { "n" => "\n".to_owned(), "r" => "\r".to_owned(), "t" => "\t".to_owned(), + // "uXXXX" or "u{XXXXX}" _ => { - // "uXXXX" - use std::convert::TryFrom; - let c = u16::from_str_radix(&s[1..5], 16).unwrap(); - let c = char::try_from(u32::from(c)).unwrap(); + use std::convert::{TryFrom, TryInto}; + + let s = &s[1..]; + let s = if &s[0..1] == "{" { + &s[1..s.len()-1] + } else { + &s[0..s.len()] + }; + + if s.len() > 8 { + Err(format!("Escape sequences can't have more than 8 chars: \"{}\"", s))? + } + + // pad with zeroes + let s: String = std::iter::repeat('0') + .take(8 - s.len()) + .chain(s.chars()) + .collect(); + + // `s` has length 8, so `bytes` has length 4 + let bytes: &[u8] = &hex::decode(s).unwrap(); + let c = u32::from_be_bytes(bytes.try_into().unwrap()); + let c = char::try_from(c).unwrap(); std::iter::once(c).collect() } } -- cgit v1.3.1 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-lang | 2 +- dhall/build.rs | 20 ++++++++++++++++++-- dhall/src/phase/normalize.rs | 10 ++++++++++ tests_buffer | 3 +++ 4 files changed, 32 insertions(+), 3 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index dbf4ebc..e01c734 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit dbf4ebcfabf499e87c27e75bec108d91929ccc31 +Subproject commit e01c734e612daac327b06845e45c34552d65d9e1 diff --git a/dhall/build.rs b/dhall/build.rs index 5a99def..7e320c5 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -90,6 +90,10 @@ fn main() -> std::io::Result<()> { // TODO: Inline headers are not implemented || path == "success/unit/import/parenthesizeUsing" || path == "success/unit/import/inlineUsing" + // TODO: projection by expression + || path == "success/recordProjectionByExpression" + || path == "success/unit/recordProjectionByExpression" + || path == "success/unit/recordProjectionByExpressionEmpty" }, )?; @@ -105,6 +109,10 @@ fn main() -> std::io::Result<()> { || path == "success/largeExpression" // TODO: Inline headers are not implemented || path == "success/unit/import/inlineUsing" + // TODO: projection by expression + || path == "success/recordProjectionByExpression" + || path == "success/unit/recordProjectionByExpression" + || path == "success/unit/recordProjectionByExpressionEmpty" }, )?; @@ -124,8 +132,11 @@ fn main() -> std::io::Result<()> { // See https://github.com/pyfisch/cbor/issues/109 || path == "success/double" // TODO: Inline headers are not implemented - || path == "success/unit/import/parenthesizeUsing" || path == "success/unit/import/inlineUsing" + // TODO: projection by expression + || path == "success/recordProjectionByExpression" + || path == "success/unit/recordProjectionByExpression" + || path == "success/unit/recordProjectionByExpressionEmpty" }, )?; @@ -139,9 +150,14 @@ fn main() -> std::io::Result<()> { path == "success/simple/integerToDouble" // Too slow || path == "success/remoteSystems" - // TODO: selection by expression + // TODO: projection by expression || path == "success/unit/RecordProjectionTypeEmpty" || path == "success/unit/RecordProjectionTypeNonEmpty" + || path == "success/unit/RecordProjectionTypeNormalizeProjection" + // TODO: fix Double/show + || path == "success/prelude/JSON/number/1" + // the test is wrong + || path == "success/prelude/JSON/Type/0" }, )?; 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)] => { diff --git a/tests_buffer b/tests_buffer index deb245d..5234562 100644 --- a/tests_buffer +++ b/tests_buffer @@ -98,6 +98,8 @@ failure/ normalization: variables across import boundaries +Text/show "" +Double/show -1.5e-10 TextLitNested1 "${""}${x}" TextLitNested2 "${"${x}"}" TextLitNested3 "${"${""}"}${x}" @@ -106,6 +108,7 @@ variables across import boundaries typecheck: something that involves destructuring a recordtype after merge +add some of the more complicated Prelude tests back, like List/enumerate failure on old-style optional literal success/ MergeEmptyAlternative merge { x = 1 } < x >.x -- cgit v1.3.1 From 482be29e0f03e10c2469ef80bdd6ac7593207dc5 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 20:38:06 +0200 Subject: RFC3986 URLs --- dhall-lang | 2 +- dhall/build.rs | 20 ++++++++++++++++++-- dhall/src/phase/binary.rs | 8 +++++++- dhall_generated_parser/build.rs | 6 ++++++ dhall_generated_parser/src/dhall.pest.visibility | 1 + dhall_syntax/src/core/import.rs | 1 + dhall_syntax/src/parser.rs | 7 +++++++ dhall_syntax/src/printer.rs | 1 + tests_buffer | 1 + 9 files changed, 43 insertions(+), 4 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index e01c734..2c0f238 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit e01c734e612daac327b06845e45c34552d65d9e1 +Subproject commit 2c0f2389e11597131b8ce021344322e5ed3a9131 diff --git a/dhall/build.rs b/dhall/build.rs index 7e320c5..cdbd560 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -94,6 +94,12 @@ fn main() -> std::io::Result<()> { || path == "success/recordProjectionByExpression" || path == "success/unit/recordProjectionByExpression" || path == "success/unit/recordProjectionByExpressionEmpty" + // TODO: RFC3986 URLs + || path == "success/unit/import/urls/emptyPath0" + || path == "success/unit/import/urls/emptyPath1" + || path == "success/unit/import/urls/emptyPathSegment" + // Test is broken + || path == "success/unit/import/asLocation" }, )?; @@ -113,6 +119,12 @@ fn main() -> std::io::Result<()> { || path == "success/recordProjectionByExpression" || path == "success/unit/recordProjectionByExpression" || path == "success/unit/recordProjectionByExpressionEmpty" + // TODO: RFC3986 URLs + || path == "success/unit/import/urls/emptyPath0" + || path == "success/unit/import/urls/emptyPath1" + || path == "success/unit/import/urls/emptyPathSegment" + // Test is broken + || path == "success/unit/import/asLocation" }, )?; @@ -137,6 +149,12 @@ fn main() -> std::io::Result<()> { || path == "success/recordProjectionByExpression" || path == "success/unit/recordProjectionByExpression" || path == "success/unit/recordProjectionByExpressionEmpty" + // TODO: RFC3986 URLs + || path == "success/unit/import/urls/emptyPath0" + || path == "success/unit/import/urls/emptyPath1" + || path == "success/unit/import/urls/emptyPathSegment" + // Test is broken + || path == "success/unit/import/asLocation" }, )?; @@ -156,8 +174,6 @@ fn main() -> std::io::Result<()> { || path == "success/unit/RecordProjectionTypeNormalizeProjection" // TODO: fix Double/show || path == "success/prelude/JSON/number/1" - // the test is wrong - || path == "success/prelude/JSON/Type/0" }, )?; diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index 443af7e..bab3fd8 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -195,8 +195,13 @@ fn cbor_value_to_dhall( } [U64(24), hash, U64(mode), U64(scheme), rest..] => { let mode = match mode { + 0 => ImportMode::Code, 1 => ImportMode::RawText, - _ => ImportMode::Code, + 2 => ImportMode::Location, + _ => Err(DecodeError::WrongFormatError(format!( + "import/mode/unknown_mode: {:?}", + mode + )))?, }; let hash = match hash { Null => None, @@ -545,6 +550,7 @@ where let mode = match import.mode { ImportMode::Code => 0, ImportMode::RawText => 1, + ImportMode::Location => 2, }; ser_seq.serialize_element(&U64(mode))?; diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs index 744cb3d..2c1a8f5 100644 --- a/dhall_generated_parser/build.rs +++ b/dhall_generated_parser/build.rs @@ -27,6 +27,7 @@ fn main() -> std::io::Result<()> { } } rules.remove("http"); + rules.remove("url_path"); rules.remove("simple_label"); rules.remove("nonreserved_label"); @@ -53,6 +54,11 @@ fn main() -> std::io::Result<()> { ~ (import_hashed | ^\"(\" ~ whsp ~ import_hashed ~ whsp ~ ^\")\"))? }}" )?; + // TODO: this is a cheat; properly support RFC3986 URLs instead + writeln!( + &mut file, + "url_path = _{{ path }}" + )?; writeln!( &mut file, "nonreserved_label = _{{ diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility index 2b7c477..97d3a69 100644 --- a/dhall_generated_parser/src/dhall.pest.visibility +++ b/dhall_generated_parser/src/dhall.pest.visibility @@ -48,6 +48,7 @@ builtin Optional Text List +Location # Bool # True # False diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs index 306460b..d41eae2 100644 --- a/dhall_syntax/src/core/import.rs +++ b/dhall_syntax/src/core/import.rs @@ -41,6 +41,7 @@ pub enum Scheme { pub enum ImportMode { Code, RawText, + Location, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 2450c76..2c0cee9 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -697,6 +697,7 @@ make_parser! { )); token_rule!(Text<()>); + token_rule!(Location<()>); rule!(import as expression; span; children!( [import_hashed(location_hashed)] => { @@ -711,6 +712,12 @@ make_parser! { location_hashed })) }, + [import_hashed(location_hashed), Location(_)] => { + spanned(span, Embed(Import { + mode: ImportMode::Location, + location_hashed + })) + }, )); token_rule!(lambda<()>); diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index b585a5b..2b2bbcc 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -435,6 +435,7 @@ impl Display for Import { match self.mode { Code => {} RawText => write!(f, " as Text")?, + Location => write!(f, " as Location")?, } Ok(()) } diff --git a/tests_buffer b/tests_buffer index 5234562..ca578e4 100644 --- a/tests_buffer +++ b/tests_buffer @@ -6,6 +6,7 @@ remove `double` remove imports/parenthesizeUsing remove multilet selection by expression unit tests +split aslocation test into actual unit tests success/ imports/ Missing missing -- cgit v1.3.1 From 054121b427b5344b41a0fb230b69d81ea0b5cd0a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 20:52:25 +0200 Subject: Change some tests --- dhall-lang | 2 +- dhall/build.rs | 28 +++++++++++++--------------- dhall/src/phase/typecheck.rs | 5 +++++ 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 2c0f238..65aa743 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 2c0f2389e11597131b8ce021344322e5ed3a9131 +Subproject commit 65aa7435040141dd30d5983695b7ebdb4224b280 diff --git a/dhall/build.rs b/dhall/build.rs index cdbd560..db66e3c 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -92,14 +92,14 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/inlineUsing" // TODO: projection by expression || path == "success/recordProjectionByExpression" - || path == "success/unit/recordProjectionByExpression" - || path == "success/unit/recordProjectionByExpressionEmpty" + || path == "success/RecordProjectionByType" + || path == "success/unit/RecordProjectionByType" + || path == "success/unit/RecordProjectionByTypeEmpty" + || path == "success/unit/RecordProjectFields" // TODO: RFC3986 URLs || path == "success/unit/import/urls/emptyPath0" || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" - // Test is broken - || path == "success/unit/import/asLocation" }, )?; @@ -117,14 +117,13 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/inlineUsing" // TODO: projection by expression || path == "success/recordProjectionByExpression" - || path == "success/unit/recordProjectionByExpression" - || path == "success/unit/recordProjectionByExpressionEmpty" + || path == "success/RecordProjectionByType" + || path == "success/unit/RecordProjectionByType" + || path == "success/unit/RecordProjectionByTypeEmpty" // TODO: RFC3986 URLs || path == "success/unit/import/urls/emptyPath0" || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" - // Test is broken - || path == "success/unit/import/asLocation" }, )?; @@ -147,14 +146,13 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/inlineUsing" // TODO: projection by expression || path == "success/recordProjectionByExpression" - || path == "success/unit/recordProjectionByExpression" - || path == "success/unit/recordProjectionByExpressionEmpty" + || path == "success/RecordProjectionByType" + || path == "success/unit/RecordProjectionByType" + || path == "success/unit/RecordProjectionByTypeEmpty" // TODO: RFC3986 URLs || path == "success/unit/import/urls/emptyPath0" || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" - // Test is broken - || path == "success/unit/import/asLocation" }, )?; @@ -169,9 +167,9 @@ fn main() -> std::io::Result<()> { // Too slow || path == "success/remoteSystems" // TODO: projection by expression - || path == "success/unit/RecordProjectionTypeEmpty" - || path == "success/unit/RecordProjectionTypeNonEmpty" - || path == "success/unit/RecordProjectionTypeNormalizeProjection" + || path == "success/unit/RecordProjectionByTypeEmpty" + || path == "success/unit/RecordProjectionByTypeNonEmpty" + || path == "success/unit/RecordProjectionByTypeNormalizeProjection" // TODO: fix Double/show || path == "success/prelude/JSON/number/1" }, diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index 753d25e..bd09b35 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -1195,6 +1195,8 @@ mod spec_tests { tc_failure!(tc_failure_unit_RecordProjectionEmpty, "unit/RecordProjectionEmpty"); tc_failure!(tc_failure_unit_RecordProjectionNotPresent, "unit/RecordProjectionNotPresent"); tc_failure!(tc_failure_unit_RecordProjectionNotRecord, "unit/RecordProjectionNotRecord"); + // tc_failure!(tc_failure_unit_RecordProjectionByTypeFieldTypeMismatch, "unit/RecordProjectionByTypeFieldTypeMismatch"); + // tc_failure!(tc_failure_unit_RecordProjectionByTypeNotPresent, "unit/RecordProjectionByTypeNotPresent"); tc_failure!(tc_failure_unit_RecordSelectionEmpty, "unit/RecordSelectionEmpty"); tc_failure!(tc_failure_unit_RecordSelectionNotPresent, "unit/RecordSelectionNotPresent"); tc_failure!(tc_failure_unit_RecordSelectionNotRecord, "unit/RecordSelectionNotRecord"); @@ -1220,6 +1222,7 @@ mod spec_tests { tc_failure!(tc_failure_unit_TextLiteralInterpolateNotText, "unit/TextLiteralInterpolateNotText"); tc_failure!(tc_failure_unit_TypeAnnotationWrong, "unit/TypeAnnotationWrong"); tc_failure!(tc_failure_unit_UnionConstructorFieldNotPresent, "unit/UnionConstructorFieldNotPresent"); + tc_failure!(tc_failure_unit_UnionDeprecatedConstructorsKeyword, "unit/UnionDeprecatedConstructorsKeyword"); tc_failure!(tc_failure_unit_UnionTypeMixedKinds, "unit/UnionTypeMixedKinds"); tc_failure!(tc_failure_unit_UnionTypeMixedKinds2, "unit/UnionTypeMixedKinds2"); tc_failure!(tc_failure_unit_UnionTypeMixedKinds3, "unit/UnionTypeMixedKinds3"); @@ -1310,6 +1313,8 @@ mod spec_tests { ti_success!(ti_success_unit_RecordProjectionKind, "unit/RecordProjectionKind"); ti_success!(ti_success_unit_RecordProjectionType, "unit/RecordProjectionType"); ti_success!(ti_success_unit_RecordProjectionValue, "unit/RecordProjectionValue"); + // ti_success!(ti_success_unit_RecordProjectionByTypeEmpty, "unit/RecordProjectionByTypeEmpty"); + // ti_success!(ti_success_unit_RecordProjectionByTypeJudgmentalEquality, "unit/RecordProjectionByTypeJudgmentalEquality"); ti_success!(ti_success_unit_RecordSelectionKind, "unit/RecordSelectionKind"); ti_success!(ti_success_unit_RecordSelectionType, "unit/RecordSelectionType"); ti_success!(ti_success_unit_RecordSelectionValue, "unit/RecordSelectionValue"); -- cgit v1.3.1 From b3791e91b7cb73778cc21844a6999531bf537f77 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 20:59:28 +0200 Subject: Change URL parsing --- dhall-lang | 2 +- dhall/build.rs | 1 + dhall_generated_parser/src/dhall.pest.visibility | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 65aa743..40c3e57 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 65aa7435040141dd30d5983695b7ebdb4224b280 +Subproject commit 40c3e57a4f09448b5a7c9d203a81b64f50ed30bd diff --git a/dhall/build.rs b/dhall/build.rs index db66e3c..2fa63c6 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -100,6 +100,7 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/urls/emptyPath0" || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" + || path == "success/unit/import/urls/potPourri" }, )?; diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility index 97d3a69..24d0a87 100644 --- a/dhall_generated_parser/src/dhall.pest.visibility +++ b/dhall_generated_parser/src/dhall.pest.visibility @@ -10,6 +10,7 @@ # whsp1 # ALPHA # DIGIT +# ALPHANUM # HEXDIG # simple_label_first_char # simple_label_next_char @@ -118,7 +119,8 @@ authority # ls32 # IPv4address # dec_octet -# reg_name +# domain +# domainlabel # pchar query # pct_encoded -- cgit v1.3.1 From 3e157f0a05b0b93753ed377332597a37fa379541 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 21:28:12 +0200 Subject: Add toMap keyword --- dhall-lang | 2 +- dhall/build.rs | 21 +++++++++++++++++++++ dhall_generated_parser/src/dhall.pest.visibility | 1 + dhall_syntax/src/parser.rs | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 40c3e57..cd29db9 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 40c3e57a4f09448b5a7c9d203a81b64f50ed30bd +Subproject commit cd29db992660788fa5d75ccc465562fa3d96fcee diff --git a/dhall/build.rs b/dhall/build.rs index c78f8f9..2d75cbf 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -101,6 +101,8 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" || path == "success/unit/import/urls/potPourri" + // TODO: toMap + || path == "success/toMap" }, )?; @@ -125,6 +127,8 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/urls/emptyPath0" || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" + // TODO: toMap + || path == "success/toMap" }, )?; @@ -154,6 +158,9 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/urls/emptyPath0" || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" + || path == "success/unit/import/urls/potPourri" + // TODO: toMap + || path == "success/toMap" }, )?; @@ -173,6 +180,10 @@ fn main() -> std::io::Result<()> { || path == "success/unit/RecordProjectionByTypeNormalizeProjection" // TODO: fix Double/show || path == "success/prelude/JSON/number/1" + // TODO: toMap + || path == "success/unit/EmptyToMap" + || path == "success/unit/ToMap" + || path == "success/unit/ToMapWithType" }, )?; @@ -197,6 +208,14 @@ fn main() -> std::io::Result<()> { // TODO: projection by expression || path == "failure/unit/RecordProjectionByTypeFieldTypeMismatch" || path == "failure/unit/RecordProjectionByTypeNotPresent" + // TODO: toMap + || path == "failure/unit/EmptyToMap" + || path == "failure/unit/HeterogenousToMap" + || path == "failure/unit/MistypedToMap1" + || path == "failure/unit/MistypedToMap2" + || path == "failure/unit/MistypedToMap3" + || path == "failure/unit/MistypedToMap4" + || path == "failure/unit/NonRecordToMap" }, )?; @@ -211,6 +230,8 @@ fn main() -> std::io::Result<()> { || path == "success/unit/RecordProjectionByType" || path == "success/unit/RecordProjectionByTypeEmpty" || path == "success/unit/RecordProjectionByTypeJudgmentalEquality" + // TODO: toMap + || path == "success/unit/ToMap" }, )?; diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility index 24d0a87..3142ad5 100644 --- a/dhall_generated_parser/src/dhall.pest.visibility +++ b/dhall_generated_parser/src/dhall.pest.visibility @@ -44,6 +44,7 @@ missing # Infinity NaN Some_ +toMap # keyword builtin Optional diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 2c0cee9..8355ebf 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -861,6 +861,7 @@ make_parser! { )); token_rule!(Some_<()>); + token_rule!(toMap<()>); rule!(application_expression as expression; children!( [expression(e)] => e, -- cgit v1.3.1 From 0a1cf5554e8c06d05d24bdcdcf1eb71f0ac6d8f2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 21:33:18 +0200 Subject: Update dhall-lang submodule --- dhall-lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index cd29db9..1b587f8 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit cd29db992660788fa5d75ccc465562fa3d96fcee +Subproject commit 1b587f866a16ce4ae198d5ff51848a4ffc0f4cdc -- cgit v1.3.1 From f7b0c6b9c52f65624dc765fb9eaa7d0d94eeae76 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 23:03:01 +0200 Subject: Generalize empty list annotations --- dhall-lang | 2 +- dhall/build.rs | 2 ++ dhall/src/phase/binary.rs | 8 ++++++-- dhall_generated_parser/build.rs | 22 ++++++++++++++++++++++ dhall_syntax/src/core/expr.rs | 2 +- dhall_syntax/src/parser.rs | 10 ++++++---- 6 files changed, 38 insertions(+), 8 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 1b587f8..4d68c57 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 1b587f866a16ce4ae198d5ff51848a4ffc0f4cdc +Subproject commit 4d68c5708cfc5c3f5ff7e5a6c4df25c5fdfd96f4 diff --git a/dhall/build.rs b/dhall/build.rs index 2d75cbf..07da3f5 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -103,6 +103,8 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/urls/potPourri" // TODO: toMap || path == "success/toMap" + // Not a failure anymore + || path == "failure/unit/ListLitEmptyPrecedence" }, )?; diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index 66b235f..f88eee2 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -341,6 +341,10 @@ fn cbor_value_to_dhall( let y = cbor_value_to_dhall(&y)?; Annot(x, y) } + [U64(27), x] => { + let x = cbor_value_to_dhall(&x)?; + EmptyListLit(x) + } _ => Err(DecodeError::WrongFormatError(format!("{:?}", data)))?, }, _ => Err(DecodeError::WrongFormatError(format!("{:?}", data)))?, @@ -475,9 +479,9 @@ where EmptyListLit(x) => match x.as_ref() { App(f, a) => match f.as_ref() { ExprF::Builtin(Builtin::List) => ser_seq!(ser; tag(4), expr(a)), - _ => unreachable!(), + _ => ser_seq!(ser; tag(27), expr(x)), }, - _ => unreachable!(), + _ => ser_seq!(ser; tag(27), expr(x)), }, NEListLit(xs) => ser.collect_seq( once(tag(4)).chain(once(null())).chain(xs.iter().map(expr)), diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs index 1edce9e..7eba52c 100644 --- a/dhall_generated_parser/build.rs +++ b/dhall_generated_parser/build.rs @@ -31,6 +31,7 @@ fn main() -> std::io::Result<()> { rules.remove("simple_label"); rules.remove("nonreserved_label"); rules.remove("first_application_expression"); + rules.remove("expression"); let mut file = File::create(pest_path)?; writeln!(&mut file, "// AUTO-GENERATED FILE. See build.rs.")?; @@ -65,6 +66,27 @@ fn main() -> std::io::Result<()> { | import_expression }}" )?; + // TODO: hack; we'll need to upstream a change to the grammar + writeln!( + &mut file, + r#"expression = {{ + lambda ~ whsp ~ ^"(" ~ whsp ~ nonreserved_label ~ whsp ~ ^":" ~ whsp1 ~ expression ~ whsp ~ ^")" ~ whsp ~ arrow ~ whsp ~ expression + | if_ ~ whsp1 ~ expression ~ whsp ~ then ~ whsp1 ~ expression ~ whsp ~ else_ ~ whsp1 ~ expression + | let_binding+ ~ in_ ~ whsp1 ~ expression + | forall ~ whsp ~ ^"(" ~ whsp ~ nonreserved_label ~ whsp ~ ^":" ~ whsp1 ~ expression ~ whsp ~ ^")" ~ whsp ~ arrow ~ whsp ~ expression + | operator_expression ~ whsp ~ arrow ~ whsp ~ expression + | merge ~ whsp1 ~ import_expression ~ whsp1 ~ import_expression ~ whsp ~ ^":" ~ whsp1 ~ application_expression + | empty_list_literal + | toMap ~ whsp1 ~ import_expression ~ whsp ~ ^":" ~ whsp1 ~ application_expression + | annotated_expression + }}"# + )?; + writeln!( + &mut file, + r#"empty_list_literal = {{ + ^"[" ~ whsp ~ ^"]" ~ whsp ~ ^":" ~ whsp1 ~ application_expression + }}"# + )?; // TODO: this is a cheat; properly support RFC3986 URLs instead writeln!(&mut file, "url_path = _{{ path }}")?; writeln!( diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index e33859b..14dc165 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -190,7 +190,7 @@ pub enum ExprF { DoubleLit(Double), /// `"Some ${interpolated} text"` TextLit(InterpolatedText), - /// `[] : List t` + /// `[] : t` EmptyListLit(SubExpr), /// `[x, y, z]` NEListLit(Vec), diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 0832af3..8a84b00 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -727,6 +727,12 @@ make_parser! { token_rule!(if_<()>); token_rule!(in_<()>); + rule!(empty_list_literal as expression; span; children!( + [expression(e)] => { + spanned(span, EmptyListLit(e)) + }, + )); + rule!(expression as expression; span; children!( [lambda(()), label(l), expression(typ), arrow(()), expression(body)] => { @@ -751,10 +757,6 @@ make_parser! { [merge(()), expression(x), expression(y), expression(z)] => { spanned(span, Merge(x, y, Some(z))) }, - [List(()), expression(x)] => { - let list = unspanned(Builtin(crate::Builtin::List)); - spanned(span, EmptyListLit(unspanned(App(list, x)))) - }, [expression(e)] => e, )); -- cgit v1.3.1 From 7827d10b431061ca9d2ef83d04a5a4e9f4c7fd47 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 15:59:13 +0200 Subject: Update dhall-lang submodule --- dhall-lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 4d68c57..ee2fe7d 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 4d68c5708cfc5c3f5ff7e5a6c4df25c5fdfd96f4 +Subproject commit ee2fe7d9cbd699fc9f40ca4858abcc0f13105324 -- cgit v1.3.1 From d5c3e8f2ef7438b7ac84be34cfe019ce365ae529 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 16:22:00 +0200 Subject: Forbid surrogate pairs and non-characters --- dhall-lang | 2 +- dhall/src/tests.rs | 2 ++ dhall_generated_parser/src/dhall.pest.visibility | 1 + dhall_syntax/src/parser.rs | 23 +++++++++++++++++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index ee2fe7d..599f83b 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit ee2fe7d9cbd699fc9f40ca4858abcc0f13105324 +Subproject commit 599f83b9d5ed24f4357455aecc794f572234a69a diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 2f68dac..8b32fb4 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -195,6 +195,8 @@ pub fn run_test( let err = parse_file_str(&file_path).unwrap_err(); match err { Error::Parse(_) => {} + Error::IO(e) + if e.kind() == std::io::ErrorKind::InvalidData => {} e => panic!("Expected parse error, got: {:?}", e), } } diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility index 3142ad5..33018ae 100644 --- a/dhall_generated_parser/src/dhall.pest.visibility +++ b/dhall_generated_parser/src/dhall.pest.visibility @@ -1,4 +1,5 @@ # end_of_line +# valid_non_ascii # tab # block_comment # block_comment_char diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 5be8477..8336c74 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -425,8 +425,27 @@ make_parser! { // `s` has length 8, so `bytes` has length 4 let bytes: &[u8] = &hex::decode(s).unwrap(); - let c = u32::from_be_bytes(bytes.try_into().unwrap()); - let c = char::try_from(c).unwrap(); + let i = u32::from_be_bytes(bytes.try_into().unwrap()); + let c = char::try_from(i).unwrap(); + match i { + 0xD800..=0xDFFF => { + let c_ecapsed = c.escape_unicode(); + Err(format!("Escape sequences can't contain surrogate pairs: \"{}\"", c_ecapsed))? + }, + 0x0FFFE..=0x0FFFF | 0x1FFFE..=0x1FFFF | + 0x2FFFE..=0x2FFFF | 0x3FFFE..=0x3FFFF | + 0x4FFFE..=0x4FFFF | 0x5FFFE..=0x5FFFF | + 0x6FFFE..=0x6FFFF | 0x7FFFE..=0x7FFFF | + 0x8FFFE..=0x8FFFF | 0x9FFFE..=0x9FFFF | + 0xAFFFE..=0xAFFFF | 0xBFFFE..=0xBFFFF | + 0xCFFFE..=0xCFFFF | 0xDFFFE..=0xDFFFF | + 0xEFFFE..=0xEFFFF | 0xFFFFE..=0xFFFFF | + 0x10FFFE..=0x10FFFF => { + let c_ecapsed = c.escape_unicode(); + Err(format!("Escape sequences can't contain non-characters: \"{}\"", c_ecapsed))? + }, + _ => {} + } std::iter::once(c).collect() } } -- cgit v1.3.1 From 98e7751fb8deb22685b6991367404515c35f502f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 16:28:48 +0200 Subject: Various parsing tweaks --- dhall-lang | 2 +- dhall/build.rs | 4 ---- dhall/src/phase/binary.rs | 6 +++--- dhall_generated_parser/build.rs | 11 ----------- 4 files changed, 4 insertions(+), 19 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 599f83b..f4ee1fb 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 599f83b9d5ed24f4357455aecc794f572234a69a +Subproject commit f4ee1fb8f8165c6d68d5f7f4da609483839271db diff --git a/dhall/build.rs b/dhall/build.rs index 07da3f5..d3f63ad 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -100,11 +100,8 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/urls/emptyPath0" || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" - || path == "success/unit/import/urls/potPourri" // TODO: toMap || path == "success/toMap" - // Not a failure anymore - || path == "failure/unit/ListLitEmptyPrecedence" }, )?; @@ -160,7 +157,6 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/urls/emptyPath0" || path == "success/unit/import/urls/emptyPath1" || path == "success/unit/import/urls/emptyPathSegment" - || path == "success/unit/import/urls/potPourri" // TODO: toMap || path == "success/toMap" }, diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index f88eee2..e44b1e2 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -341,7 +341,7 @@ fn cbor_value_to_dhall( let y = cbor_value_to_dhall(&y)?; Annot(x, y) } - [U64(27), x] => { + [U64(28), x] => { let x = cbor_value_to_dhall(&x)?; EmptyListLit(x) } @@ -479,9 +479,9 @@ where EmptyListLit(x) => match x.as_ref() { App(f, a) => match f.as_ref() { ExprF::Builtin(Builtin::List) => ser_seq!(ser; tag(4), expr(a)), - _ => ser_seq!(ser; tag(27), expr(x)), + _ => ser_seq!(ser; tag(28), expr(x)), }, - _ => ser_seq!(ser; tag(27), expr(x)), + _ => ser_seq!(ser; tag(28), expr(x)), }, NEListLit(xs) => ser.collect_seq( once(tag(4)).chain(once(null())).chain(xs.iter().map(expr)), diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs index 7eba52c..74210bf 100644 --- a/dhall_generated_parser/build.rs +++ b/dhall_generated_parser/build.rs @@ -30,7 +30,6 @@ fn main() -> std::io::Result<()> { rules.remove("url_path"); rules.remove("simple_label"); rules.remove("nonreserved_label"); - rules.remove("first_application_expression"); rules.remove("expression"); let mut file = File::create(pest_path)?; @@ -56,16 +55,6 @@ fn main() -> std::io::Result<()> { ~ (import_hashed | ^\"(\" ~ whsp ~ import_hashed ~ whsp ~ ^\")\"))? }}" )?; - // TODO: hack while waiting to catch up on commit e7fdf9d of the spec - writeln!( - &mut file, - "first_application_expression = {{ - merge ~ whsp1 ~ import_expression ~ whsp1 ~ import_expression - | Some_ ~ whsp1 ~ import_expression - | toMap ~ whsp1 ~ import_expression - | import_expression - }}" - )?; // TODO: hack; we'll need to upstream a change to the grammar writeln!( &mut file, -- cgit v1.3.1 From 0c9831e6a851e8f91bddc33e7a163f49d60aa033 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 16:32:43 +0200 Subject: Update dhall-lang submodule --- dhall-lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index f4ee1fb..95cfb88 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit f4ee1fb8f8165c6d68d5f7f4da609483839271db +Subproject commit 95cfb88db2f79b3c4bf61c76d9e9869d149cdefd -- cgit v1.3.1 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-lang | 2 +- dhall/src/core/value.rs | 15 ++----- dhall/src/phase/binary.rs | 12 ++---- dhall/src/phase/normalize.rs | 7 ---- dhall/src/phase/typecheck.rs | 9 ----- dhall_generated_parser/src/dhall.pest.visibility | 6 +-- dhall_syntax/src/core/expr.rs | 2 - dhall_syntax/src/core/visitor.rs | 3 -- dhall_syntax/src/parser.rs | 51 ++---------------------- dhall_syntax/src/printer.rs | 10 ----- 10 files changed, 12 insertions(+), 105 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 95cfb88..f692f70 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 95cfb88db2f79b3c4bf61c76d9e9869d149cdefd +Subproject commit f692f70bafa0322da5d9c4b535b2d323a9c5ac61 diff --git a/dhall/src/core/value.rs b/dhall/src/core/value.rs index f47f1b2..d7b9149 100644 --- a/dhall/src/core/value.rs +++ b/dhall/src/core/value.rs @@ -178,19 +178,10 @@ impl Value { .collect(); rc(ExprF::Field(rc(ExprF::UnionType(kts)), l.clone())) } - Value::UnionLit(l, v, kts) => rc(ExprF::UnionLit( - l.clone(), + Value::UnionLit(l, v, kts) => rc(ExprF::App( + Value::UnionConstructor(l.clone(), kts.clone()) + .normalize_to_expr_maybe_alpha(alpha), v.normalize_to_expr_maybe_alpha(alpha), - kts.iter() - .map(|(k, v)| { - ( - k.clone(), - v.as_ref().map(|v| { - v.normalize_to_expr_maybe_alpha(alpha) - }), - ) - }) - .collect(), )), Value::TextLit(elts) => { use InterpolatedTextContents::{Expr, Text}; diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index e44b1e2..bfe217f 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -160,12 +160,9 @@ fn cbor_value_to_dhall( let map = cbor_map_to_dhall_opt_map(map)?; UnionType(map) } - [U64(12), String(l), x, Object(map)] => { - let map = cbor_map_to_dhall_opt_map(map)?; - let x = cbor_value_to_dhall(&x)?; - let l = Label::from(l.as_str()); - UnionLit(l, x, map) - } + [U64(12), ..] => Err(DecodeError::WrongFormatError( + "Union literals are not supported anymore".to_owned(), + ))?, [U64(14), x, y, z] => { let x = cbor_value_to_dhall(&x)?; let y = cbor_value_to_dhall(&y)?; @@ -496,9 +493,6 @@ where RecordType(map) => ser_seq!(ser; tag(7), RecordMap(map)), RecordLit(map) => ser_seq!(ser; tag(8), RecordMap(map)), UnionType(map) => ser_seq!(ser; tag(11), UnionMap(map)), - UnionLit(l, x, map) => { - ser_seq!(ser; tag(12), label(l), expr(x), UnionMap(map)) - } Field(x, l) => ser_seq!(ser; tag(9), expr(x), label(l)), BinOp(op, x, y) => { use dhall_syntax::BinOp::*; 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)))) diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index 35bf3a9..4b3a03f 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -505,15 +505,6 @@ fn type_last_layer( )? .into_type(), )), - UnionLit(x, v, kvs) => { - use std::iter::once; - let kts = kvs - .iter() - .map(|(x, v)| Ok((x.clone(), v.as_ref().map(|v| v.to_type())))); - let t = v.get_type()?.into_owned(); - let kts = kts.chain(once(Ok((x.clone(), Some(t))))); - Ok(RetTypeOnly(tck_union_type(ctx, kts)?.to_type())) - } Field(r, x) => { match &r.get_type()?.to_value() { Value::RecordType(kts) => match kts.get(&x) { diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility index 33018ae..dd54578 100644 --- a/dhall_generated_parser/src/dhall.pest.visibility +++ b/dhall_generated_parser/src/dhall.pest.visibility @@ -169,11 +169,9 @@ non_empty_record_type record_type_entry non_empty_record_literal record_literal_entry -union_type_or_literal +union_type empty_union_type -non_empty_union_type_or_literal -union_literal_variant_value +# non_empty_union_type union_type_entry -union_type_or_literal_variant_type non_empty_list_literal # complete_expression diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 668ab45..aab4b6a 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -202,8 +202,6 @@ pub enum ExprF { RecordLit(DupTreeMap), /// `< k1 : t1, k2 >` UnionType(DupTreeMap>), - /// `< k1 = t1, k2 : t2, k3 >` - UnionLit(Label, SubExpr, DupTreeMap>), /// `merge x y : t` Merge(SubExpr, SubExpr, Option), /// `e.x` diff --git a/dhall_syntax/src/core/visitor.rs b/dhall_syntax/src/core/visitor.rs index b02544f..68ad956 100644 --- a/dhall_syntax/src/core/visitor.rs +++ b/dhall_syntax/src/core/visitor.rs @@ -141,9 +141,6 @@ where RecordType(kts) => RecordType(dupmap(kts, v)?), RecordLit(kvs) => RecordLit(dupmap(kvs, v)?), UnionType(kts) => UnionType(optdupmap(kts, v)?), - UnionLit(k, x, kts) => { - UnionLit(k.clone(), v.visit_subexpr(x)?, optdupmap(kts, v)?) - } Merge(x, y, t) => Merge( v.visit_subexpr(x)?, v.visit_subexpr(y)?, diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 8336c74..a7f419a 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -976,67 +976,22 @@ make_parser! { [label(name), expression(expr)] => (name, expr) )); - rule!(union_type_or_literal as expression; span; children!( + rule!(union_type as expression; span; children!( [empty_union_type(_)] => { spanned(span, UnionType(Default::default())) }, - [non_empty_union_type_or_literal((Some((l, e)), entries))] => { - spanned(span, UnionLit(l, e, entries)) - }, - [non_empty_union_type_or_literal((None, entries))] => { - spanned(span, UnionType(entries)) + [union_type_entry(entries)..] => { + spanned(span, UnionType(entries.collect())) }, )); token_rule!(empty_union_type<()>); - rule!(non_empty_union_type_or_literal - <(Option<(Label, ParsedSubExpr)>, - DupTreeMap>)>; - children!( - [label(l), union_literal_variant_value((e, entries))] => { - (Some((l, e)), entries) - }, - [label(l), union_type_or_literal_variant_type((e, rest))] => { - let (x, mut entries) = rest; - entries.insert(l, e); - (x, entries) - }, - )); - - rule!(union_literal_variant_value - <(ParsedSubExpr, DupTreeMap>)>; - children!( - [expression(e), union_type_entry(entries)..] => { - (e, entries.collect()) - }, - )); - rule!(union_type_entry<(Label, Option)>; children!( [label(name), expression(expr)] => (name, Some(expr)), [label(name)] => (name, None), )); - // TODO: unary union variants - rule!(union_type_or_literal_variant_type - <(Option, - (Option<(Label, ParsedSubExpr)>, - DupTreeMap>))>; - children!( - [expression(e), non_empty_union_type_or_literal(rest)] => { - (Some(e), rest) - }, - [expression(e)] => { - (Some(e), (None, Default::default())) - }, - [non_empty_union_type_or_literal(rest)] => { - (None, rest) - }, - [] => { - (None, (None, Default::default())) - }, - )); - rule!(non_empty_list_literal as expression; span; children!( [expression(items)..] => spanned( diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index 52d3d81..db688bd 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -85,16 +85,6 @@ impl Display for ExprF { } Ok(()) })?, - UnionLit(a, b, c) => { - write!(f, "< {} = {}", a, b)?; - for (k, v) in c { - write!(f, " | {}", k)?; - if let Some(v) = v { - write!(f, ": {}", v)?; - } - } - f.write_str(" >")? - } Embed(a) => a.fmt(f)?, } Ok(()) -- cgit v1.3.1 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-lang | 2 +- dhall/src/phase/normalize.rs | 10 ++++++++++ dhall/src/phase/typecheck.rs | 1 + dhall_generated_parser/src/dhall.pest.visibility | 1 + dhall_syntax/src/core/expr.rs | 1 + dhall_syntax/src/parser.rs | 1 + dhall_syntax/src/printer.rs | 1 + 7 files changed, 16 insertions(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index f692f70..c7082d9 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit f692f70bafa0322da5d9c4b535b2d323a9c5ac61 +Subproject commit c7082d910d956bcedfdc51daae989659a2db67bd 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 { diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index 4b3a03f..2e4642c 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -212,6 +212,7 @@ fn type_of_builtin(b: Builtin) -> Expr { ), NaturalToInteger => dhall::expr!(Natural -> Integer), NaturalShow => dhall::expr!(Natural -> Text), + NaturalSubtract => dhall::expr!(Natural -> Natural -> Natural), IntegerToDouble => dhall::expr!(Integer -> Double), IntegerShow => dhall::expr!(Integer -> Text), diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility index dd54578..de6dc8d 100644 --- a/dhall_generated_parser/src/dhall.pest.visibility +++ b/dhall_generated_parser/src/dhall.pest.visibility @@ -71,6 +71,7 @@ Location # Natural_show # Integer_toDouble # Integer_show +# Natural_subtract # Double_show # List_build # List_fold diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index aab4b6a..b293357 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -119,6 +119,7 @@ pub enum Builtin { NaturalOdd, NaturalToInteger, NaturalShow, + NaturalSubtract, IntegerToDouble, IntegerShow, DoubleShow, diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index a7f419a..72dfcdd 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -80,6 +80,7 @@ impl crate::Builtin { "Natural/odd" => Some(NaturalOdd), "Natural/toInteger" => Some(NaturalToInteger), "Natural/show" => Some(NaturalShow), + "Natural/subtract" => Some(NaturalSubtract), "Integer/toDouble" => Some(IntegerToDouble), "Integer/show" => Some(IntegerShow), "Double/show" => Some(DoubleShow), diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index db688bd..1d6c113 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -449,6 +449,7 @@ impl Display for Builtin { NaturalOdd => "Natural/odd", NaturalToInteger => "Natural/toInteger", NaturalShow => "Natural/show", + NaturalSubtract => "Natural/subtract", IntegerToDouble => "Integer/toDouble", IntegerShow => "Integer/show", DoubleShow => "Double/show", -- cgit v1.3.1 From ea80deff5562fefb642924be1937d22447702d01 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 21:59:54 +0200 Subject: Update dhall-lang submodule --- dhall-lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index c7082d9..affafb9 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit c7082d910d956bcedfdc51daae989659a2db67bd +Subproject commit affafb9c674c7117e24634ceb5dbdaa1dc8dc0b0 -- cgit v1.3.1 From 6d166d3fe0dedb66b4302cc5fb67f696f6688b80 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 22:03:33 +0200 Subject: Normalize field selection further by inspecting the argument --- dhall-lang | 2 +- dhall/build.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index affafb9..ebda6c1 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit affafb9c674c7117e24634ceb5dbdaa1dc8dc0b0 +Subproject commit ebda6c150056f4e7a801ee11f611be86ce694e8a diff --git a/dhall/build.rs b/dhall/build.rs index 3d4611e..983fcad 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -196,6 +196,18 @@ fn main() -> std::io::Result<()> { || path == "success/unit/EmptyToMap" || path == "success/unit/ToMap" || path == "success/unit/ToMapWithType" + // Normalize field selection further by inspecting the argument + || path == "success/simplifications/rightBiasedMergeWithinRecordProjectionWithinFieldSelection0" + || path == "success/simplifications/rightBiasedMergeWithinRecordProjectionWithinFieldSelection1" + || path == "success/simplifications/rightBiasedMergeWithinRecursiveRecordMergeWithinFieldselection" + || path == "success/unit/RecordProjectionByTypeWithinFieldSelection" + || path == "success/unit/RecordProjectionWithinFieldSelection" + || path == "success/unit/RecursiveRecordMergeWithinFieldSelection0" + || path == "success/unit/RecursiveRecordMergeWithinFieldSelection1" + || path == "success/unit/RecursiveRecordMergeWithinFieldSelection2" + || path == "success/unit/RightBiasedMergeWithinFieldSelection0" + || path == "success/unit/RightBiasedMergeWithinFieldSelection1" + || path == "success/unit/RightBiasedMergeWithinFieldSelection2" }, )?; -- cgit v1.3.1 From c2cb7d38dfec05b6337aa5dcd0dc3068e73c9a58 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 22:25:35 +0200 Subject: Flatten nested let bindings --- dhall-lang | 2 +- dhall/build.rs | 3 +++ dhall/src/phase/binary.rs | 46 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 7 deletions(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index ebda6c1..95dd430 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit ebda6c150056f4e7a801ee11f611be86ce694e8a +Subproject commit 95dd43037ce516907b0919a6cf2e8a9089b67f73 diff --git a/dhall/build.rs b/dhall/build.rs index 983fcad..29e86e3 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -173,6 +173,9 @@ fn main() -> std::io::Result<()> { || path == "success/unit/recordProjectionByExpression" // TODO: test is wrong || path == "success/unit/BuiltinNaturalSubtract" + // TODO: toMap + || path == "success/unit/ToMap" + || path == "success/unit/ToMapAnnotated" }, )?; diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index cab3c8e..5e7eb40 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -477,12 +477,23 @@ where ser_seq!(ser; tag(2), expr(x), expr(y)) } Pi(l, x, y) => ser_seq!(ser; tag(2), label(l), expr(x), expr(y)), - // TODO: multilet - Let(l, None, x, y) => { - ser_seq!(ser; tag(25), label(l), null(), expr(x), expr(y)) - } - Let(l, Some(t), x, y) => { - ser_seq!(ser; tag(25), label(l), expr(t), expr(x), expr(y)) + Let(_, _, _, _) => { + let (bound_e, bindings) = collect_nested_lets(e); + let count = 1 + 3 * bindings.len() + 1; + + use serde::ser::SerializeSeq; + let mut ser_seq = ser.serialize_seq(Some(count))?; + ser_seq.serialize_element(&tag(25))?; + for (l, t, v) in bindings { + ser_seq.serialize_element(&label(l))?; + match t { + Some(t) => ser_seq.serialize_element(&expr(t))?, + None => ser_seq.serialize_element(&null())?, + } + ser_seq.serialize_element(&expr(v))?; + } + ser_seq.serialize_element(&expr(bound_e))?; + ser_seq.end() } App(_, _) => { let (f, args) = collect_nested_applications(e); @@ -677,3 +688,26 @@ fn collect_nested_applications<'a, N, E>( let e = go(e, &mut vec); (e, vec) } + +type LetBinding<'a, N, E> = + (&'a Label, &'a Option>, &'a SubExpr); + +fn collect_nested_lets<'a, N, E>( + e: &'a SubExpr, +) -> (&'a SubExpr, Vec>) { + fn go<'a, N, E>( + e: &'a SubExpr, + vec: &mut Vec>, + ) -> &'a SubExpr { + match e.as_ref() { + ExprF::Let(l, t, v, e) => { + vec.push((l, t, v)); + go(e, vec) + } + _ => e, + } + } + let mut vec = vec![]; + let e = go(e, &mut vec); + (e, vec) +} -- cgit v1.3.1 From e81ab9a553bf82f20fa0b0344926258176a21dac Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 22:28:36 +0200 Subject: Update dhall-lang submodule --- dhall-lang | 2 +- dhall/build.rs | 1 + dhall/src/phase/resolve.rs | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'dhall-lang') diff --git a/dhall-lang b/dhall-lang index 95dd430..9f259cd 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 95dd43037ce516907b0919a6cf2e8a9089b67f73 +Subproject commit 9f259cd68870b912fbf2f2a08cd63dc3ccba9dc3 diff --git a/dhall/build.rs b/dhall/build.rs index 29e86e3..b6df3d0 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -259,6 +259,7 @@ fn main() -> std::io::Result<()> { || path == "success/unit/RecordProjectionByTypeJudgmentalEquality" // TODO: toMap || path == "success/unit/ToMap" + || path == "success/unit/ToMapAnnotated" }, )?; diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index 0b29513..abcee7e 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -125,12 +125,15 @@ mod spec_tests { // import_success!(success_alternativeHashMismatch, "alternativeHashMismatch"); // import_success!(success_alternativeNatural, "alternativeNatural"); // import_success!(success_alternativeParseError, "alternativeParseError"); + // import_success!(success_alternativeTypeError, "alternativeTypeError"); + // import_success!(success_asLocation, "asLocation"); // import_success!(success_asText, "asText"); // import_success!(success_customHeaders, "customHeaders"); import_success!(success_fieldOrder, "fieldOrder"); // note: this one needs special setup with env variables // import_success!(success_hashFromCache, "hashFromCache"); // import_success!(success_headerForwarding, "headerForwarding"); + // import_success!(success_nestedHash, "nestedHash"); // import_success!(success_noHeaderForwarding, "noHeaderForwarding"); // import_failure!(failure_alternativeEnv, "alternativeEnv"); // import_failure!(failure_alternativeEnvMissing, "alternativeEnvMissing"); -- cgit v1.3.1