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 +- dhall/build.rs | 8 ++++++++ dhall/src/phase/binary.rs | 29 ++++++++++++++--------------- dhall/src/phase/resolve.rs | 6 ++++++ dhall/src/phase/typecheck.rs | 1 + dhall_generated_parser/build.rs | 12 ++++++++++++ dhall_syntax/src/core/import.rs | 1 + 7 files changed, 43 insertions(+), 16 deletions(-) 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 diff --git a/dhall/build.rs b/dhall/build.rs index 3f09d47..5a99def 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -87,6 +87,9 @@ fn main() -> std::io::Result<()> { |path| { // Too slow in debug mode path == "success/largeExpression" + // TODO: Inline headers are not implemented + || path == "success/unit/import/parenthesizeUsing" + || path == "success/unit/import/inlineUsing" }, )?; @@ -100,6 +103,8 @@ fn main() -> std::io::Result<()> { path.starts_with("failure/") // Too slow in debug mode || path == "success/largeExpression" + // TODO: Inline headers are not implemented + || path == "success/unit/import/inlineUsing" }, )?; @@ -118,6 +123,9 @@ fn main() -> std::io::Result<()> { || path == "success/multilet" // 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" }, )?; diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index 1812131..874b4fb 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -216,18 +216,19 @@ fn cbor_value_to_dhall( }; let headers = match rest.next() { Some(Null) => None, - Some(x) => { - match cbor_value_to_dhall(&x)?.as_ref() { - Embed(import) => Some(Box::new( - import.location_hashed.clone(), - )), - _ => Err(DecodeError::WrongFormatError( - "import/remote/headers".to_owned(), - ))?, - } - } + // TODO + // Some(x) => { + // match cbor_value_to_dhall(&x)?.as_ref() { + // Embed(import) => Some(Box::new( + // import.location_hashed.clone(), + // )), + // _ => Err(DecodeError::WrongFormatError( + // "import/remote/headers".to_owned(), + // ))?, + // } + // } _ => Err(DecodeError::WrongFormatError( - "import/remote/headers".to_owned(), + "import/remote/headers is unimplemented".to_owned(), ))?, }; let authority = match rest.next() { @@ -378,7 +379,6 @@ enum Serialize<'a> { CBOR(cbor::Value), RecordMap(&'a DupTreeMap), UnionMap(&'a DupTreeMap>), - Import(&'a Import), } macro_rules! count { @@ -566,10 +566,10 @@ where match &url.headers { None => ser_seq.serialize_element(&Null)?, Some(location_hashed) => ser_seq.serialize_element( - &self::Serialize::Import(&Import { + &self::Serialize::Expr(&SubExpr::from_expr_no_note(ExprF::Embed(Import { mode: ImportMode::Code, location_hashed: location_hashed.as_ref().clone(), - }), + }))), )?, }; ser_seq.serialize_element(&url.authority)?; @@ -617,7 +617,6 @@ impl<'a> serde::ser::Serialize for Serialize<'a> { (cbor::Value::String(k.into()), v) })) } - Serialize::Import(import) => serialize_import(ser, import), } } } diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index c4d7e5f..8c561a3 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -122,12 +122,18 @@ mod spec_tests { // import_success!(success_alternativeEnvNatural, "alternativeEnvNatural"); // import_success!(success_alternativeEnvSimple, "alternativeEnvSimple"); + // import_success!(success_alternativeHashMismatch, "alternativeHashMismatch"); // import_success!(success_alternativeNatural, "alternativeNatural"); + // import_success!(success_alternativeParseError, "alternativeParseError"); // import_success!(success_asText, "asText"); + // import_success!(success_customHeaders, "customHeaders"); import_success!(success_fieldOrder, "fieldOrder"); + // import_success!(success_headerForwarding, "headerForwarding"); + // import_success!(success_noHeaderForwarding, "noHeaderForwarding"); // import_failure!(failure_alternativeEnv, "alternativeEnv"); // import_failure!(failure_alternativeEnvMissing, "alternativeEnvMissing"); // import_failure!(failure_cycle, "cycle"); + // import_failure!(failure_hashMismatch, "hashMismatch"); // import_failure!(failure_missing, "missing"); // import_failure!(failure_referentiallyInsane, "referentiallyInsane"); } diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index a3f676c..efdc2bb 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -1167,6 +1167,7 @@ mod spec_tests { // tc_failure!(tc_failure_importBoundary, "importBoundary"); tc_failure!(tc_failure_mixedUnions, "mixedUnions"); tc_failure!(tc_failure_preferMixedRecords, "preferMixedRecords"); + // tc_failure!(tc_failure_customHeadersUsingBoundVariable, "customHeadersUsingBoundVariable"); tc_failure!(tc_failure_unit_FunctionApplicationArgumentNotMatch, "unit/FunctionApplicationArgumentNotMatch"); tc_failure!(tc_failure_unit_FunctionApplicationIsNotFunction, "unit/FunctionApplicationIsNotFunction"); tc_failure!(tc_failure_unit_FunctionArgumentTypeNotAType, "unit/FunctionArgumentTypeNotAType"); diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs index eab48bf..744cb3d 100644 --- a/dhall_generated_parser/build.rs +++ b/dhall_generated_parser/build.rs @@ -26,6 +26,7 @@ fn main() -> std::io::Result<()> { rules.get_mut(&line[2..]).map(|x| x.silent = true); } } + rules.remove("http"); rules.remove("simple_label"); rules.remove("nonreserved_label"); @@ -41,6 +42,17 @@ fn main() -> std::io::Result<()> { | !keyword ~ simple_label_first_char ~ simple_label_next_char* }}" )?; + // TODO: this is a cheat; actually implement inline headers instead + writeln!( + &mut file, + "http = {{ + http_raw + ~ (whsp + ~ using + ~ whsp1 + ~ (import_hashed | ^\"(\" ~ whsp ~ import_hashed ~ whsp ~ ^\")\"))? + }}" + )?; writeln!( &mut file, "nonreserved_label = _{{ diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs index c328e34..306460b 100644 --- a/dhall_syntax/src/core/import.rs +++ b/dhall_syntax/src/core/import.rs @@ -26,6 +26,7 @@ pub struct URL { pub authority: String, pub path: Vec, pub query: Option, + // TODO: implement inline headers pub headers: Option>, } -- cgit v1.2.3 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(-) 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.2.3 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(-) 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.2.3 From 278cd9be7d93bc1eeecde05c964da5b097668016 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 4 Aug 2019 11:15:28 +0200 Subject: rustfmt --- dhall/src/phase/binary.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index dcf60bb..443af7e 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -232,7 +232,8 @@ fn cbor_value_to_dhall( // } // } _ => Err(DecodeError::WrongFormatError( - "import/remote/headers is unimplemented".to_owned(), + "import/remote/headers is unimplemented" + .to_owned(), ))?, }; let authority = match rest.next() { @@ -567,12 +568,14 @@ where ImportLocation::Remote(url) => { match &url.headers { None => ser_seq.serialize_element(&Null)?, - Some(location_hashed) => ser_seq.serialize_element( - &self::Serialize::Expr(&SubExpr::from_expr_no_note(ExprF::Embed(Import { - mode: ImportMode::Code, - location_hashed: location_hashed.as_ref().clone(), - }))), - )?, + Some(location_hashed) => { + ser_seq.serialize_element(&self::Serialize::Expr( + &SubExpr::from_expr_no_note(ExprF::Embed(Import { + mode: ImportMode::Code, + location_hashed: location_hashed.as_ref().clone(), + })), + ))? + } }; ser_seq.serialize_element(&url.authority)?; for p in &url.path { -- cgit v1.2.3 From 696efe66336a268054c475fab9fe6505bdfc7b60 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 4 Aug 2019 13:00:56 +0200 Subject: Add some new tests and implement import alternatives --- dhall/src/error/mod.rs | 2 +- dhall/src/phase/resolve.rs | 4 ++-- dhall/src/phase/typecheck.rs | 2 +- dhall_syntax/src/core/expr.rs | 39 +++++++++++++++++++++++++++++++++++++++ dhall_syntax/src/core/visitor.rs | 25 +++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 4 deletions(-) diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs index aed6ccd..a0ee30a 100644 --- a/dhall/src/error/mod.rs +++ b/dhall/src/error/mod.rs @@ -86,7 +86,7 @@ pub(crate) enum TypeMessage { RecordTypeMergeRequiresRecordType(Type), RecordTypeMismatch(Type, Type, Type, Type), UnionTypeDuplicateField, - Unimplemented, + // Unimplemented, } impl TypeError { diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index f1329aa..0609694 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -86,7 +86,7 @@ fn do_resolve_expr( } } }; - let expr = expr.traverse_embed(resolve)?; + let expr = expr.traverse_resolve(resolve)?; Ok(Resolved(expr)) } @@ -100,7 +100,7 @@ pub fn skip_resolve_expr( let resolve = |import: &Import| -> Result { Err(ImportError::UnexpectedImport(import.clone())) }; - let expr = expr.traverse_embed(resolve)?; + let expr = expr.traverse_resolve(resolve)?; Ok(Resolved(expr)) } diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index 8551503..753d25e 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -823,7 +823,7 @@ fn type_last_layer( RightBiasedRecordMerge => unreachable!(), RecursiveRecordMerge => unreachable!(), RecursiveRecordTypeMerge => unreachable!(), - _ => return Err(mkerr(Unimplemented)), + ImportAlt => unreachable!("There should remain no import alternatives in a resolved expression"), })?; ensure_equal!( diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index df2dc97..e33859b 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -307,6 +307,35 @@ impl Expr { { trivial_result(self.traverse_embed(|x| Ok(map_embed(x)))) } + + pub fn traverse_resolve( + &self, + visit_embed: impl FnMut(&E) -> Result, + ) -> Result, Err> + where + N: Clone, + { + self.traverse_resolve_with_visitor(&mut visitor::ResolveVisitor( + visit_embed, + )) + } + + pub(crate) fn traverse_resolve_with_visitor( + &self, + visitor: &mut visitor::ResolveVisitor, + ) -> Result, Err> + where + N: Clone, + F1: FnMut(&E) -> Result, + { + match self { + ExprF::BinOp(BinOp::ImportAlt, l, r) => l + .as_ref() + .traverse_resolve_with_visitor(visitor) + .or(r.as_ref().traverse_resolve_with_visitor(visitor)), + _ => self.visit(visitor), + } + } } impl Expr { @@ -383,6 +412,16 @@ impl SubExpr { )), } } + + pub fn traverse_resolve( + &self, + visit_embed: impl FnMut(&E) -> Result, + ) -> Result, Err> + where + N: Clone, + { + Ok(self.rewrap(self.as_ref().traverse_resolve(visit_embed)?)) + } } impl SubExpr { diff --git a/dhall_syntax/src/core/visitor.rs b/dhall_syntax/src/core/visitor.rs index 1745fdb..b02544f 100644 --- a/dhall_syntax/src/core/visitor.rs +++ b/dhall_syntax/src/core/visitor.rs @@ -358,6 +358,31 @@ where } } +pub struct ResolveVisitor(pub F1); + +impl<'a, 'b, N, E, E2, Err, F1> + ExprFFallibleVisitor<'a, SubExpr, SubExpr, E, E2> + for &'b mut ResolveVisitor +where + N: Clone + 'a, + F1: FnMut(&E) -> Result, +{ + type Error = Err; + + fn visit_subexpr( + &mut self, + subexpr: &'a SubExpr, + ) -> Result, Self::Error> { + Ok(subexpr.rewrap( + subexpr + .as_ref() + .traverse_resolve_with_visitor(&mut **self)?, + )) + } + fn visit_embed(self, embed: &'a E) -> Result { + (self.0)(embed) + } +} pub struct NoteAbsurdVisitor; impl<'a, 'b, N, E> -- cgit v1.2.3 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(-) 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.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-lang | 2 +- dhall/build.rs | 20 ++++++++++++++++++-- dhall/src/phase/normalize.rs | 10 ++++++++++ tests_buffer | 3 +++ 4 files changed, 32 insertions(+), 3 deletions(-) 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.2.3 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(-) 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.2.3 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(-) 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.2.3 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(-) 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.2.3 From f20970a24db223f171eac2a3752f840dbf45d72b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 21:15:20 +0200 Subject: Auto-generate typechecking tests list --- dhall/build.rs | 36 +++- dhall/src/phase/typecheck.rs | 395 ------------------------------------------- 2 files changed, 33 insertions(+), 398 deletions(-) diff --git a/dhall/build.rs b/dhall/build.rs index 2fa63c6..c78f8f9 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -87,7 +87,7 @@ fn main() -> std::io::Result<()> { |path| { // Too slow in debug mode path == "success/largeExpression" - // TODO: Inline headers are not implemented + // TODO: Inline headers || path == "success/unit/import/parenthesizeUsing" || path == "success/unit/import/inlineUsing" // TODO: projection by expression @@ -114,7 +114,7 @@ fn main() -> std::io::Result<()> { path.starts_with("failure/") // Too slow in debug mode || path == "success/largeExpression" - // TODO: Inline headers are not implemented + // TODO: Inline headers || path == "success/unit/import/inlineUsing" // TODO: projection by expression || path == "success/recordProjectionByExpression" @@ -143,7 +143,7 @@ fn main() -> std::io::Result<()> { || path == "success/multilet" // See https://github.com/pyfisch/cbor/issues/109 || path == "success/double" - // TODO: Inline headers are not implemented + // TODO: Inline headers || path == "success/unit/import/inlineUsing" // TODO: projection by expression || path == "success/recordProjectionByExpression" @@ -184,5 +184,35 @@ fn main() -> std::io::Result<()> { |_| false, )?; + make_test_module( + &mut file, + "typecheck", + &tests_dir.join("typecheck/"), + "Typecheck", + |path| { + false + || path == "failure/importBoundary" + // TODO: Inline headers + || path == "failure/customHeadersUsingBoundVariable" + // TODO: projection by expression + || path == "failure/unit/RecordProjectionByTypeFieldTypeMismatch" + || path == "failure/unit/RecordProjectionByTypeNotPresent" + }, + )?; + + make_test_module( + &mut file, + "type_inference", + &tests_dir.join("type-inference/"), + "TypeInference", + |path| { + false + // TODO: projection by expression + || path == "success/unit/RecordProjectionByType" + || path == "success/unit/RecordProjectionByTypeEmpty" + || path == "success/unit/RecordProjectionByTypeJudgmentalEquality" + }, + )?; + Ok(()) } diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index bd09b35..fc6c1da 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -968,398 +968,3 @@ pub fn typecheck_with(e: Resolved, ty: &Type) -> Result { pub fn skip_typecheck(e: Resolved) -> Typed { Typed::from_thunk_untyped(Thunk::new(NormalizationContext::new(), e.0)) } - -#[cfg(test)] -mod spec_tests { - #![rustfmt::skip] - - macro_rules! tc_success { - ($name:ident, $path:expr) => { - make_spec_test!(Typecheck, Success, $name, &("success/".to_owned() + $path)); - }; - } - macro_rules! tc_failure { - ($name:ident, $path:expr) => { - make_spec_test!(Typecheck, Failure, $name, &("failure/".to_owned() + $path)); - }; - } - - macro_rules! ti_success { - ($name:ident, $path:expr) => { - make_spec_test!(TypeInference, Success, $name, &("success/".to_owned() + $path)); - }; - } - // macro_rules! ti_failure { - // ($name:ident, $path:expr) => { - // make_spec_test!(TypeInference, Failure, $name, &("failure/".to_owned() + $path)); - // }; - // } - - // tc_success!(tc_success_accessEncodedType, "accessEncodedType"); - // tc_success!(tc_success_accessType, "accessType"); - tc_success!(tc_success_prelude_Bool_and_0, "prelude/Bool/and/0"); - tc_success!(tc_success_prelude_Bool_and_1, "prelude/Bool/and/1"); - tc_success!(tc_success_prelude_Bool_build_0, "prelude/Bool/build/0"); - tc_success!(tc_success_prelude_Bool_build_1, "prelude/Bool/build/1"); - tc_success!(tc_success_prelude_Bool_even_0, "prelude/Bool/even/0"); - tc_success!(tc_success_prelude_Bool_even_1, "prelude/Bool/even/1"); - tc_success!(tc_success_prelude_Bool_even_2, "prelude/Bool/even/2"); - tc_success!(tc_success_prelude_Bool_even_3, "prelude/Bool/even/3"); - tc_success!(tc_success_prelude_Bool_fold_0, "prelude/Bool/fold/0"); - tc_success!(tc_success_prelude_Bool_fold_1, "prelude/Bool/fold/1"); - tc_success!(tc_success_prelude_Bool_not_0, "prelude/Bool/not/0"); - tc_success!(tc_success_prelude_Bool_not_1, "prelude/Bool/not/1"); - tc_success!(tc_success_prelude_Bool_odd_0, "prelude/Bool/odd/0"); - tc_success!(tc_success_prelude_Bool_odd_1, "prelude/Bool/odd/1"); - tc_success!(tc_success_prelude_Bool_odd_2, "prelude/Bool/odd/2"); - tc_success!(tc_success_prelude_Bool_odd_3, "prelude/Bool/odd/3"); - tc_success!(tc_success_prelude_Bool_or_0, "prelude/Bool/or/0"); - tc_success!(tc_success_prelude_Bool_or_1, "prelude/Bool/or/1"); - tc_success!(tc_success_prelude_Bool_show_0, "prelude/Bool/show/0"); - tc_success!(tc_success_prelude_Bool_show_1, "prelude/Bool/show/1"); - tc_success!(tc_success_prelude_Double_show_0, "prelude/Double/show/0"); - tc_success!(tc_success_prelude_Double_show_1, "prelude/Double/show/1"); - tc_success!(tc_success_prelude_Integer_show_0, "prelude/Integer/show/0"); - tc_success!(tc_success_prelude_Integer_show_1, "prelude/Integer/show/1"); - tc_success!(tc_success_prelude_Integer_toDouble_0, "prelude/Integer/toDouble/0"); - tc_success!(tc_success_prelude_Integer_toDouble_1, "prelude/Integer/toDouble/1"); - tc_success!(tc_success_prelude_List_all_0, "prelude/List/all/0"); - tc_success!(tc_success_prelude_List_all_1, "prelude/List/all/1"); - tc_success!(tc_success_prelude_List_any_0, "prelude/List/any/0"); - tc_success!(tc_success_prelude_List_any_1, "prelude/List/any/1"); - tc_success!(tc_success_prelude_List_build_0, "prelude/List/build/0"); - tc_success!(tc_success_prelude_List_build_1, "prelude/List/build/1"); - tc_success!(tc_success_prelude_List_concat_0, "prelude/List/concat/0"); - tc_success!(tc_success_prelude_List_concat_1, "prelude/List/concat/1"); - tc_success!(tc_success_prelude_List_concatMap_0, "prelude/List/concatMap/0"); - tc_success!(tc_success_prelude_List_concatMap_1, "prelude/List/concatMap/1"); - tc_success!(tc_success_prelude_List_filter_0, "prelude/List/filter/0"); - tc_success!(tc_success_prelude_List_filter_1, "prelude/List/filter/1"); - tc_success!(tc_success_prelude_List_fold_0, "prelude/List/fold/0"); - tc_success!(tc_success_prelude_List_fold_1, "prelude/List/fold/1"); - tc_success!(tc_success_prelude_List_fold_2, "prelude/List/fold/2"); - tc_success!(tc_success_prelude_List_generate_0, "prelude/List/generate/0"); - tc_success!(tc_success_prelude_List_generate_1, "prelude/List/generate/1"); - tc_success!(tc_success_prelude_List_head_0, "prelude/List/head/0"); - tc_success!(tc_success_prelude_List_head_1, "prelude/List/head/1"); - tc_success!(tc_success_prelude_List_indexed_0, "prelude/List/indexed/0"); - tc_success!(tc_success_prelude_List_indexed_1, "prelude/List/indexed/1"); - tc_success!(tc_success_prelude_List_iterate_0, "prelude/List/iterate/0"); - tc_success!(tc_success_prelude_List_iterate_1, "prelude/List/iterate/1"); - tc_success!(tc_success_prelude_List_last_0, "prelude/List/last/0"); - tc_success!(tc_success_prelude_List_last_1, "prelude/List/last/1"); - tc_success!(tc_success_prelude_List_length_0, "prelude/List/length/0"); - tc_success!(tc_success_prelude_List_length_1, "prelude/List/length/1"); - tc_success!(tc_success_prelude_List_map_0, "prelude/List/map/0"); - tc_success!(tc_success_prelude_List_map_1, "prelude/List/map/1"); - tc_success!(tc_success_prelude_List_null_0, "prelude/List/null/0"); - tc_success!(tc_success_prelude_List_null_1, "prelude/List/null/1"); - tc_success!(tc_success_prelude_List_replicate_0, "prelude/List/replicate/0"); - tc_success!(tc_success_prelude_List_replicate_1, "prelude/List/replicate/1"); - tc_success!(tc_success_prelude_List_reverse_0, "prelude/List/reverse/0"); - tc_success!(tc_success_prelude_List_reverse_1, "prelude/List/reverse/1"); - tc_success!(tc_success_prelude_List_shifted_0, "prelude/List/shifted/0"); - tc_success!(tc_success_prelude_List_shifted_1, "prelude/List/shifted/1"); - tc_success!(tc_success_prelude_List_unzip_0, "prelude/List/unzip/0"); - tc_success!(tc_success_prelude_List_unzip_1, "prelude/List/unzip/1"); - tc_success!(tc_success_prelude_Monoid_00, "prelude/Monoid/00"); - tc_success!(tc_success_prelude_Monoid_01, "prelude/Monoid/01"); - tc_success!(tc_success_prelude_Monoid_02, "prelude/Monoid/02"); - tc_success!(tc_success_prelude_Monoid_03, "prelude/Monoid/03"); - tc_success!(tc_success_prelude_Monoid_04, "prelude/Monoid/04"); - tc_success!(tc_success_prelude_Monoid_05, "prelude/Monoid/05"); - tc_success!(tc_success_prelude_Monoid_06, "prelude/Monoid/06"); - tc_success!(tc_success_prelude_Monoid_07, "prelude/Monoid/07"); - tc_success!(tc_success_prelude_Monoid_08, "prelude/Monoid/08"); - tc_success!(tc_success_prelude_Monoid_09, "prelude/Monoid/09"); - tc_success!(tc_success_prelude_Monoid_10, "prelude/Monoid/10"); - tc_success!(tc_success_prelude_Natural_build_0, "prelude/Natural/build/0"); - tc_success!(tc_success_prelude_Natural_build_1, "prelude/Natural/build/1"); - tc_success!(tc_success_prelude_Natural_enumerate_0, "prelude/Natural/enumerate/0"); - tc_success!(tc_success_prelude_Natural_enumerate_1, "prelude/Natural/enumerate/1"); - tc_success!(tc_success_prelude_Natural_even_0, "prelude/Natural/even/0"); - tc_success!(tc_success_prelude_Natural_even_1, "prelude/Natural/even/1"); - tc_success!(tc_success_prelude_Natural_fold_0, "prelude/Natural/fold/0"); - tc_success!(tc_success_prelude_Natural_fold_1, "prelude/Natural/fold/1"); - tc_success!(tc_success_prelude_Natural_fold_2, "prelude/Natural/fold/2"); - tc_success!(tc_success_prelude_Natural_isZero_0, "prelude/Natural/isZero/0"); - tc_success!(tc_success_prelude_Natural_isZero_1, "prelude/Natural/isZero/1"); - tc_success!(tc_success_prelude_Natural_odd_0, "prelude/Natural/odd/0"); - tc_success!(tc_success_prelude_Natural_odd_1, "prelude/Natural/odd/1"); - tc_success!(tc_success_prelude_Natural_product_0, "prelude/Natural/product/0"); - tc_success!(tc_success_prelude_Natural_product_1, "prelude/Natural/product/1"); - tc_success!(tc_success_prelude_Natural_show_0, "prelude/Natural/show/0"); - tc_success!(tc_success_prelude_Natural_show_1, "prelude/Natural/show/1"); - tc_success!(tc_success_prelude_Natural_sum_0, "prelude/Natural/sum/0"); - tc_success!(tc_success_prelude_Natural_sum_1, "prelude/Natural/sum/1"); - tc_success!(tc_success_prelude_Natural_toDouble_0, "prelude/Natural/toDouble/0"); - tc_success!(tc_success_prelude_Natural_toDouble_1, "prelude/Natural/toDouble/1"); - tc_success!(tc_success_prelude_Natural_toInteger_0, "prelude/Natural/toInteger/0"); - tc_success!(tc_success_prelude_Natural_toInteger_1, "prelude/Natural/toInteger/1"); - tc_success!(tc_success_prelude_Optional_all_0, "prelude/Optional/all/0"); - tc_success!(tc_success_prelude_Optional_all_1, "prelude/Optional/all/1"); - tc_success!(tc_success_prelude_Optional_any_0, "prelude/Optional/any/0"); - tc_success!(tc_success_prelude_Optional_any_1, "prelude/Optional/any/1"); - tc_success!(tc_success_prelude_Optional_build_0, "prelude/Optional/build/0"); - tc_success!(tc_success_prelude_Optional_build_1, "prelude/Optional/build/1"); - tc_success!(tc_success_prelude_Optional_concat_0, "prelude/Optional/concat/0"); - tc_success!(tc_success_prelude_Optional_concat_1, "prelude/Optional/concat/1"); - tc_success!(tc_success_prelude_Optional_concat_2, "prelude/Optional/concat/2"); - tc_success!(tc_success_prelude_Optional_filter_0, "prelude/Optional/filter/0"); - tc_success!(tc_success_prelude_Optional_filter_1, "prelude/Optional/filter/1"); - tc_success!(tc_success_prelude_Optional_fold_0, "prelude/Optional/fold/0"); - tc_success!(tc_success_prelude_Optional_fold_1, "prelude/Optional/fold/1"); - tc_success!(tc_success_prelude_Optional_head_0, "prelude/Optional/head/0"); - tc_success!(tc_success_prelude_Optional_head_1, "prelude/Optional/head/1"); - tc_success!(tc_success_prelude_Optional_head_2, "prelude/Optional/head/2"); - tc_success!(tc_success_prelude_Optional_last_0, "prelude/Optional/last/0"); - tc_success!(tc_success_prelude_Optional_last_1, "prelude/Optional/last/1"); - tc_success!(tc_success_prelude_Optional_last_2, "prelude/Optional/last/2"); - tc_success!(tc_success_prelude_Optional_length_0, "prelude/Optional/length/0"); - tc_success!(tc_success_prelude_Optional_length_1, "prelude/Optional/length/1"); - tc_success!(tc_success_prelude_Optional_map_0, "prelude/Optional/map/0"); - tc_success!(tc_success_prelude_Optional_map_1, "prelude/Optional/map/1"); - tc_success!(tc_success_prelude_Optional_null_0, "prelude/Optional/null/0"); - tc_success!(tc_success_prelude_Optional_null_1, "prelude/Optional/null/1"); - tc_success!(tc_success_prelude_Optional_toList_0, "prelude/Optional/toList/0"); - tc_success!(tc_success_prelude_Optional_toList_1, "prelude/Optional/toList/1"); - tc_success!(tc_success_prelude_Optional_unzip_0, "prelude/Optional/unzip/0"); - tc_success!(tc_success_prelude_Optional_unzip_1, "prelude/Optional/unzip/1"); - tc_success!(tc_success_prelude_Text_concat_0, "prelude/Text/concat/0"); - tc_success!(tc_success_prelude_Text_concat_1, "prelude/Text/concat/1"); - tc_success!(tc_success_prelude_Text_concatMap_0, "prelude/Text/concatMap/0"); - tc_success!(tc_success_prelude_Text_concatMap_1, "prelude/Text/concatMap/1"); - // tc_success!(tc_success_prelude_Text_concatMapSep_0, "prelude/Text/concatMapSep/0"); - // tc_success!(tc_success_prelude_Text_concatMapSep_1, "prelude/Text/concatMapSep/1"); - // tc_success!(tc_success_prelude_Text_concatSep_0, "prelude/Text/concatSep/0"); - // tc_success!(tc_success_prelude_Text_concatSep_1, "prelude/Text/concatSep/1"); - tc_success!(tc_success_recordOfRecordOfTypes, "recordOfRecordOfTypes"); - tc_success!(tc_success_recordOfTypes, "recordOfTypes"); - // tc_success!(tc_success_simple_access_0, "simple/access/0"); - // tc_success!(tc_success_simple_access_1, "simple/access/1"); - // tc_success!(tc_success_simple_anonymousFunctionsInTypes, "simple/anonymousFunctionsInTypes"); - // tc_success!(tc_success_simple_fieldsAreTypes, "simple/fieldsAreTypes"); - // tc_success!(tc_success_simple_kindParameter, "simple/kindParameter"); - tc_success!(tc_success_simple_mergeEquivalence, "simple/mergeEquivalence"); - // tc_success!(tc_success_simple_mixedFieldAccess, "simple/mixedFieldAccess"); - tc_success!(tc_success_simple_unionsOfTypes, "simple/unionsOfTypes"); - - tc_failure!(tc_failure_combineMixedRecords, "combineMixedRecords"); - tc_failure!(tc_failure_duplicateFields, "duplicateFields"); - tc_failure!(tc_failure_hurkensParadox, "hurkensParadox"); - // tc_failure!(tc_failure_importBoundary, "importBoundary"); - tc_failure!(tc_failure_mixedUnions, "mixedUnions"); - tc_failure!(tc_failure_preferMixedRecords, "preferMixedRecords"); - // tc_failure!(tc_failure_customHeadersUsingBoundVariable, "customHeadersUsingBoundVariable"); - tc_failure!(tc_failure_unit_FunctionApplicationArgumentNotMatch, "unit/FunctionApplicationArgumentNotMatch"); - tc_failure!(tc_failure_unit_FunctionApplicationIsNotFunction, "unit/FunctionApplicationIsNotFunction"); - tc_failure!(tc_failure_unit_FunctionArgumentTypeNotAType, "unit/FunctionArgumentTypeNotAType"); - tc_failure!(tc_failure_unit_FunctionDependentType, "unit/FunctionDependentType"); - tc_failure!(tc_failure_unit_FunctionDependentType2, "unit/FunctionDependentType2"); - tc_failure!(tc_failure_unit_FunctionTypeArgumentTypeNotAType, "unit/FunctionTypeArgumentTypeNotAType"); - tc_failure!(tc_failure_unit_FunctionTypeKindSort, "unit/FunctionTypeKindSort"); - tc_failure!(tc_failure_unit_FunctionTypeTypeKind, "unit/FunctionTypeTypeKind"); - tc_failure!(tc_failure_unit_FunctionTypeTypeSort, "unit/FunctionTypeTypeSort"); - tc_failure!(tc_failure_unit_IfBranchesNotMatch, "unit/IfBranchesNotMatch"); - tc_failure!(tc_failure_unit_IfBranchesNotType, "unit/IfBranchesNotType"); - tc_failure!(tc_failure_unit_IfNotBool, "unit/IfNotBool"); - tc_failure!(tc_failure_unit_LetWithWrongAnnotation, "unit/LetWithWrongAnnotation"); - tc_failure!(tc_failure_unit_ListLiteralEmptyNotType, "unit/ListLiteralEmptyNotType"); - tc_failure!(tc_failure_unit_ListLiteralNotType, "unit/ListLiteralNotType"); - tc_failure!(tc_failure_unit_ListLiteralTypesNotMatch, "unit/ListLiteralTypesNotMatch"); - tc_failure!(tc_failure_unit_MergeAlternativeHasNoHandler, "unit/MergeAlternativeHasNoHandler"); - tc_failure!(tc_failure_unit_MergeAnnotationNotType, "unit/MergeAnnotationNotType"); - tc_failure!(tc_failure_unit_MergeEmptyWithoutAnnotation, "unit/MergeEmptyWithoutAnnotation"); - tc_failure!(tc_failure_unit_MergeHandlerNotFunction, "unit/MergeHandlerNotFunction"); - tc_failure!(tc_failure_unit_MergeHandlerNotInUnion, "unit/MergeHandlerNotInUnion"); - tc_failure!(tc_failure_unit_MergeHandlerNotMatchAlternativeType, "unit/MergeHandlerNotMatchAlternativeType"); - tc_failure!(tc_failure_unit_MergeHandlersWithDifferentType, "unit/MergeHandlersWithDifferentType"); - tc_failure!(tc_failure_unit_MergeLhsNotRecord, "unit/MergeLhsNotRecord"); - tc_failure!(tc_failure_unit_MergeRhsNotUnion, "unit/MergeRhsNotUnion"); - tc_failure!(tc_failure_unit_MergeWithWrongAnnotation, "unit/MergeWithWrongAnnotation"); - tc_failure!(tc_failure_unit_OperatorAndNotBool, "unit/OperatorAndNotBool"); - tc_failure!(tc_failure_unit_OperatorEqualNotBool, "unit/OperatorEqualNotBool"); - tc_failure!(tc_failure_unit_OperatorListConcatenateLhsNotList, "unit/OperatorListConcatenateLhsNotList"); - tc_failure!(tc_failure_unit_OperatorListConcatenateListsNotMatch, "unit/OperatorListConcatenateListsNotMatch"); - tc_failure!(tc_failure_unit_OperatorListConcatenateNotListsButMatch, "unit/OperatorListConcatenateNotListsButMatch"); - tc_failure!(tc_failure_unit_OperatorListConcatenateRhsNotList, "unit/OperatorListConcatenateRhsNotList"); - tc_failure!(tc_failure_unit_OperatorNotEqualNotBool, "unit/OperatorNotEqualNotBool"); - tc_failure!(tc_failure_unit_OperatorOrNotBool, "unit/OperatorOrNotBool"); - tc_failure!(tc_failure_unit_OperatorPlusNotNatural, "unit/OperatorPlusNotNatural"); - tc_failure!(tc_failure_unit_OperatorTextConcatenateLhsNotText, "unit/OperatorTextConcatenateLhsNotText"); - tc_failure!(tc_failure_unit_OperatorTextConcatenateRhsNotText, "unit/OperatorTextConcatenateRhsNotText"); - tc_failure!(tc_failure_unit_OperatorTimesNotNatural, "unit/OperatorTimesNotNatural"); - tc_failure!(tc_failure_unit_RecordMixedKinds, "unit/RecordMixedKinds"); - tc_failure!(tc_failure_unit_RecordMixedKinds2, "unit/RecordMixedKinds2"); - tc_failure!(tc_failure_unit_RecordMixedKinds3, "unit/RecordMixedKinds3"); - 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"); - tc_failure!(tc_failure_unit_RecordSelectionTypeNotUnionType, "unit/RecordSelectionTypeNotUnionType"); - tc_failure!(tc_failure_unit_RecordTypeMixedKinds, "unit/RecordTypeMixedKinds"); - tc_failure!(tc_failure_unit_RecordTypeMixedKinds2, "unit/RecordTypeMixedKinds2"); - tc_failure!(tc_failure_unit_RecordTypeMixedKinds3, "unit/RecordTypeMixedKinds3"); - tc_failure!(tc_failure_unit_RecordTypeValueMember, "unit/RecordTypeValueMember"); - tc_failure!(tc_failure_unit_RecursiveRecordMergeLhsNotRecord, "unit/RecursiveRecordMergeLhsNotRecord"); - tc_failure!(tc_failure_unit_RecursiveRecordMergeMixedKinds, "unit/RecursiveRecordMergeMixedKinds"); - tc_failure!(tc_failure_unit_RecursiveRecordMergeOverlapping, "unit/RecursiveRecordMergeOverlapping"); - tc_failure!(tc_failure_unit_RecursiveRecordMergeRhsNotRecord, "unit/RecursiveRecordMergeRhsNotRecord"); - tc_failure!(tc_failure_unit_RecursiveRecordTypeMergeLhsNotRecordType, "unit/RecursiveRecordTypeMergeLhsNotRecordType"); - tc_failure!(tc_failure_unit_RecursiveRecordTypeMergeOverlapping, "unit/RecursiveRecordTypeMergeOverlapping"); - tc_failure!(tc_failure_unit_RecursiveRecordTypeMergeRhsNotRecordType, "unit/RecursiveRecordTypeMergeRhsNotRecordType"); - tc_failure!(tc_failure_unit_RightBiasedRecordMergeLhsNotRecord, "unit/RightBiasedRecordMergeLhsNotRecord"); - tc_failure!(tc_failure_unit_RightBiasedRecordMergeMixedKinds, "unit/RightBiasedRecordMergeMixedKinds"); - tc_failure!(tc_failure_unit_RightBiasedRecordMergeMixedKinds2, "unit/RightBiasedRecordMergeMixedKinds2"); - tc_failure!(tc_failure_unit_RightBiasedRecordMergeMixedKinds3, "unit/RightBiasedRecordMergeMixedKinds3"); - tc_failure!(tc_failure_unit_RightBiasedRecordMergeRhsNotRecord, "unit/RightBiasedRecordMergeRhsNotRecord"); - tc_failure!(tc_failure_unit_SomeNotType, "unit/SomeNotType"); - tc_failure!(tc_failure_unit_Sort, "unit/Sort"); - 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"); - tc_failure!(tc_failure_unit_UnionTypeNotType, "unit/UnionTypeNotType"); - tc_failure!(tc_failure_unit_VariableFree, "unit/VariableFree"); - - ti_success!(ti_success_simple_alternativesAreTypes, "simple/alternativesAreTypes"); - ti_success!(ti_success_simple_kindParameter, "simple/kindParameter"); - ti_success!(ti_success_unit_Bool, "unit/Bool"); - ti_success!(ti_success_unit_Double, "unit/Double"); - ti_success!(ti_success_unit_DoubleLiteral, "unit/DoubleLiteral"); - ti_success!(ti_success_unit_DoubleShow, "unit/DoubleShow"); - ti_success!(ti_success_unit_False, "unit/False"); - ti_success!(ti_success_unit_Function, "unit/Function"); - ti_success!(ti_success_unit_FunctionApplication, "unit/FunctionApplication"); - ti_success!(ti_success_unit_FunctionNamedArg, "unit/FunctionNamedArg"); - ti_success!(ti_success_unit_FunctionTypeKindKind, "unit/FunctionTypeKindKind"); - ti_success!(ti_success_unit_FunctionTypeKindTerm, "unit/FunctionTypeKindTerm"); - ti_success!(ti_success_unit_FunctionTypeKindType, "unit/FunctionTypeKindType"); - ti_success!(ti_success_unit_FunctionTypeTermTerm, "unit/FunctionTypeTermTerm"); - ti_success!(ti_success_unit_FunctionTypeTypeTerm, "unit/FunctionTypeTypeTerm"); - ti_success!(ti_success_unit_FunctionTypeTypeType, "unit/FunctionTypeTypeType"); - ti_success!(ti_success_unit_FunctionTypeUsingArgument, "unit/FunctionTypeUsingArgument"); - ti_success!(ti_success_unit_If, "unit/If"); - ti_success!(ti_success_unit_IfNormalizeArguments, "unit/IfNormalizeArguments"); - ti_success!(ti_success_unit_Integer, "unit/Integer"); - ti_success!(ti_success_unit_IntegerLiteral, "unit/IntegerLiteral"); - ti_success!(ti_success_unit_IntegerShow, "unit/IntegerShow"); - ti_success!(ti_success_unit_IntegerToDouble, "unit/IntegerToDouble"); - ti_success!(ti_success_unit_Kind, "unit/Kind"); - ti_success!(ti_success_unit_Let, "unit/Let"); - ti_success!(ti_success_unit_LetNestedTypeSynonym, "unit/LetNestedTypeSynonym"); - ti_success!(ti_success_unit_LetTypeSynonym, "unit/LetTypeSynonym"); - ti_success!(ti_success_unit_LetWithAnnotation, "unit/LetWithAnnotation"); - ti_success!(ti_success_unit_List, "unit/List"); - ti_success!(ti_success_unit_ListBuild, "unit/ListBuild"); - ti_success!(ti_success_unit_ListFold, "unit/ListFold"); - ti_success!(ti_success_unit_ListHead, "unit/ListHead"); - ti_success!(ti_success_unit_ListIndexed, "unit/ListIndexed"); - ti_success!(ti_success_unit_ListLast, "unit/ListLast"); - ti_success!(ti_success_unit_ListLength, "unit/ListLength"); - ti_success!(ti_success_unit_ListLiteralEmpty, "unit/ListLiteralEmpty"); - ti_success!(ti_success_unit_ListLiteralNormalizeArguments, "unit/ListLiteralNormalizeArguments"); - ti_success!(ti_success_unit_ListLiteralOne, "unit/ListLiteralOne"); - ti_success!(ti_success_unit_ListReverse, "unit/ListReverse"); - ti_success!(ti_success_unit_MergeEmptyUnion, "unit/MergeEmptyUnion"); - ti_success!(ti_success_unit_MergeOne, "unit/MergeOne"); - ti_success!(ti_success_unit_MergeOneEmpty, "unit/MergeOneEmpty"); - ti_success!(ti_success_unit_MergeOneWithAnnotation, "unit/MergeOneWithAnnotation"); - ti_success!(ti_success_unit_Natural, "unit/Natural"); - ti_success!(ti_success_unit_NaturalBuild, "unit/NaturalBuild"); - ti_success!(ti_success_unit_NaturalEven, "unit/NaturalEven"); - ti_success!(ti_success_unit_NaturalFold, "unit/NaturalFold"); - ti_success!(ti_success_unit_NaturalIsZero, "unit/NaturalIsZero"); - ti_success!(ti_success_unit_NaturalLiteral, "unit/NaturalLiteral"); - ti_success!(ti_success_unit_NaturalOdd, "unit/NaturalOdd"); - 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_OperatorAnd, "unit/OperatorAnd"); - ti_success!(ti_success_unit_OperatorAndNormalizeArguments, "unit/OperatorAndNormalizeArguments"); - ti_success!(ti_success_unit_OperatorEqual, "unit/OperatorEqual"); - ti_success!(ti_success_unit_OperatorEqualNormalizeArguments, "unit/OperatorEqualNormalizeArguments"); - ti_success!(ti_success_unit_OperatorListConcatenate, "unit/OperatorListConcatenate"); - ti_success!(ti_success_unit_OperatorListConcatenateNormalizeArguments, "unit/OperatorListConcatenateNormalizeArguments"); - ti_success!(ti_success_unit_OperatorNotEqual, "unit/OperatorNotEqual"); - ti_success!(ti_success_unit_OperatorNotEqualNormalizeArguments, "unit/OperatorNotEqualNormalizeArguments"); - ti_success!(ti_success_unit_OperatorOr, "unit/OperatorOr"); - ti_success!(ti_success_unit_OperatorOrNormalizeArguments, "unit/OperatorOrNormalizeArguments"); - ti_success!(ti_success_unit_OperatorPlus, "unit/OperatorPlus"); - ti_success!(ti_success_unit_OperatorPlusNormalizeArguments, "unit/OperatorPlusNormalizeArguments"); - ti_success!(ti_success_unit_OperatorTextConcatenate, "unit/OperatorTextConcatenate"); - ti_success!(ti_success_unit_OperatorTextConcatenateNormalizeArguments, "unit/OperatorTextConcatenateNormalizeArguments"); - ti_success!(ti_success_unit_OperatorTimes, "unit/OperatorTimes"); - ti_success!(ti_success_unit_OperatorTimesNormalizeArguments, "unit/OperatorTimesNormalizeArguments"); - ti_success!(ti_success_unit_Optional, "unit/Optional"); - ti_success!(ti_success_unit_OptionalBuild, "unit/OptionalBuild"); - ti_success!(ti_success_unit_OptionalFold, "unit/OptionalFold"); - ti_success!(ti_success_unit_RecordEmpty, "unit/RecordEmpty"); - ti_success!(ti_success_unit_RecordNestedKind, "unit/RecordNestedKind"); - ti_success!(ti_success_unit_RecordNestedKindLike, "unit/RecordNestedKindLike"); - ti_success!(ti_success_unit_RecordNestedType, "unit/RecordNestedType"); - ti_success!(ti_success_unit_RecordNestedTypeLike, "unit/RecordNestedTypeLike"); - ti_success!(ti_success_unit_RecordOneKind, "unit/RecordOneKind"); - ti_success!(ti_success_unit_RecordOneType, "unit/RecordOneType"); - ti_success!(ti_success_unit_RecordOneValue, "unit/RecordOneValue"); - ti_success!(ti_success_unit_RecordProjectionEmpty, "unit/RecordProjectionEmpty"); - 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"); - ti_success!(ti_success_unit_RecordType, "unit/RecordType"); - ti_success!(ti_success_unit_RecordTypeEmpty, "unit/RecordTypeEmpty"); - ti_success!(ti_success_unit_RecordTypeKind, "unit/RecordTypeKind"); - ti_success!(ti_success_unit_RecordTypeKindLike, "unit/RecordTypeKindLike"); - ti_success!(ti_success_unit_RecordTypeNestedKind, "unit/RecordTypeNestedKind"); - ti_success!(ti_success_unit_RecordTypeNestedKindLike, "unit/RecordTypeNestedKindLike"); - ti_success!(ti_success_unit_RecordTypeType, "unit/RecordTypeType"); - ti_success!(ti_success_unit_RecursiveRecordMergeLhsEmpty, "unit/RecursiveRecordMergeLhsEmpty"); - ti_success!(ti_success_unit_RecursiveRecordMergeRecursively, "unit/RecursiveRecordMergeRecursively"); - ti_success!(ti_success_unit_RecursiveRecordMergeRecursivelyKinds, "unit/RecursiveRecordMergeRecursivelyKinds"); - ti_success!(ti_success_unit_RecursiveRecordMergeRecursivelyTypes, "unit/RecursiveRecordMergeRecursivelyTypes"); - ti_success!(ti_success_unit_RecursiveRecordMergeRhsEmpty, "unit/RecursiveRecordMergeRhsEmpty"); - ti_success!(ti_success_unit_RecursiveRecordMergeTwo, "unit/RecursiveRecordMergeTwo"); - ti_success!(ti_success_unit_RecursiveRecordMergeTwoKinds, "unit/RecursiveRecordMergeTwoKinds"); - ti_success!(ti_success_unit_RecursiveRecordMergeTwoTypes, "unit/RecursiveRecordMergeTwoTypes"); - ti_success!(ti_success_unit_RecursiveRecordTypeMergeRecursively, "unit/RecursiveRecordTypeMergeRecursively"); - ti_success!(ti_success_unit_RecursiveRecordTypeMergeRecursivelyKinds, "unit/RecursiveRecordTypeMergeRecursivelyKinds"); - ti_success!(ti_success_unit_RecursiveRecordTypeMergeRecursivelyTypes, "unit/RecursiveRecordTypeMergeRecursivelyTypes"); - ti_success!(ti_success_unit_RecursiveRecordTypeMergeRhsEmpty, "unit/RecursiveRecordTypeMergeRhsEmpty"); - ti_success!(ti_success_unit_RecursiveRecordTypeMergeTwo, "unit/RecursiveRecordTypeMergeTwo"); - ti_success!(ti_success_unit_RecursiveRecordTypeMergeTwoKinds, "unit/RecursiveRecordTypeMergeTwoKinds"); - ti_success!(ti_success_unit_RecursiveRecordTypeMergeTwoTypes, "unit/RecursiveRecordTypeMergeTwoTypes"); - ti_success!(ti_success_unit_RightBiasedRecordMergeRhsEmpty, "unit/RightBiasedRecordMergeRhsEmpty"); - ti_success!(ti_success_unit_RightBiasedRecordMergeTwo, "unit/RightBiasedRecordMergeTwo"); - ti_success!(ti_success_unit_RightBiasedRecordMergeTwoDifferent, "unit/RightBiasedRecordMergeTwoDifferent"); - ti_success!(ti_success_unit_RightBiasedRecordMergeTwoKinds, "unit/RightBiasedRecordMergeTwoKinds"); - ti_success!(ti_success_unit_RightBiasedRecordMergeTwoTypes, "unit/RightBiasedRecordMergeTwoTypes"); - ti_success!(ti_success_unit_SomeTrue, "unit/SomeTrue"); - ti_success!(ti_success_unit_Text, "unit/Text"); - ti_success!(ti_success_unit_TextLiteral, "unit/TextLiteral"); - ti_success!(ti_success_unit_TextLiteralNormalizeArguments, "unit/TextLiteralNormalizeArguments"); - ti_success!(ti_success_unit_TextLiteralWithInterpolation, "unit/TextLiteralWithInterpolation"); - ti_success!(ti_success_unit_TextShow, "unit/TextShow"); - ti_success!(ti_success_unit_True, "unit/True"); - ti_success!(ti_success_unit_Type, "unit/Type"); - ti_success!(ti_success_unit_TypeAnnotation, "unit/TypeAnnotation"); - ti_success!(ti_success_unit_TypeAnnotationSort, "unit/TypeAnnotationSort"); - ti_success!(ti_success_unit_UnionConstructorEmptyField, "unit/UnionConstructorEmptyField"); - ti_success!(ti_success_unit_UnionConstructorField, "unit/UnionConstructorField"); - ti_success!(ti_success_unit_UnionLiteralOne, "unit/UnionLiteralOne"); - ti_success!(ti_success_unit_UnionTypeEmpty, "unit/UnionTypeEmpty"); - ti_success!(ti_success_unit_UnionTypeKind, "unit/UnionTypeKind"); - ti_success!(ti_success_unit_UnionTypeOne, "unit/UnionTypeOne"); - ti_success!(ti_success_unit_UnionTypeType, "unit/UnionTypeType"); -} -- cgit v1.2.3 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(-) 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.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 ++- dhall_generated_parser/build.rs | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) 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, diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs index 2c1a8f5..5275097 100644 --- a/dhall_generated_parser/build.rs +++ b/dhall_generated_parser/build.rs @@ -55,10 +55,7 @@ fn main() -> std::io::Result<()> { }}" )?; // TODO: this is a cheat; properly support RFC3986 URLs instead - writeln!( - &mut file, - "url_path = _{{ path }}" - )?; + writeln!(&mut file, "url_path = _{{ path }}")?; writeln!( &mut file, "nonreserved_label = _{{ -- cgit v1.2.3 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(-) 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.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/core/value.rs | 8 +++-- dhall/src/phase/binary.rs | 11 +++++-- dhall/src/phase/normalize.rs | 22 ++++++++++--- dhall/src/phase/typecheck.rs | 75 +++++++++++++++++++++++--------------------- dhall_syntax/src/parser.rs | 3 +- dhall_syntax/src/printer.rs | 3 +- 6 files changed, 74 insertions(+), 48 deletions(-) diff --git a/dhall/src/core/value.rs b/dhall/src/core/value.rs index bc8fa34..f47f1b2 100644 --- a/dhall/src/core/value.rs +++ b/dhall/src/core/value.rs @@ -47,6 +47,7 @@ pub enum Value { DoubleLit(NaiveDouble), EmptyOptionalLit(TypeThunk), NEOptionalLit(Thunk), + // EmptyListLit(t) means `[] : List t` EmptyListLit(TypeThunk), NEListLit(Vec), RecordLit(HashMap), @@ -128,9 +129,10 @@ impl Value { Value::NEOptionalLit(n) => { rc(ExprF::SomeLit(n.normalize_to_expr_maybe_alpha(alpha))) } - Value::EmptyListLit(n) => { - rc(ExprF::EmptyListLit(n.normalize_to_expr_maybe_alpha(alpha))) - } + Value::EmptyListLit(n) => rc(ExprF::EmptyListLit(rc(ExprF::App( + rc(ExprF::Builtin(Builtin::List)), + n.normalize_to_expr_maybe_alpha(alpha), + )))), Value::NEListLit(elts) => rc(ExprF::NEListLit( elts.iter() .map(|n| n.normalize_to_expr_maybe_alpha(alpha)) diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index bab3fd8..66b235f 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -106,7 +106,7 @@ fn cbor_value_to_dhall( } [U64(4), t] => { let t = cbor_value_to_dhall(&t)?; - EmptyListLit(t) + EmptyListLit(rc(App(rc(ExprF::Builtin(Builtin::List)), t))) } [U64(4), Null, rest..] => { let rest = rest @@ -413,6 +413,7 @@ where S: serde::ser::Serializer, { use cbor::Value::{String, I64, U64}; + use dhall_syntax::Builtin; use dhall_syntax::ExprF::*; use std::iter::once; @@ -471,7 +472,13 @@ where } Annot(x, y) => ser_seq!(ser; tag(26), expr(x), expr(y)), SomeLit(x) => ser_seq!(ser; tag(5), null(), expr(x)), - EmptyListLit(x) => ser_seq!(ser; tag(4), 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)), + _ => unreachable!(), + }, + _ => unreachable!(), + }, NEListLit(xs) => ser.collect_seq( once(tag(4)).chain(once(null())).chain(xs.iter().map(expr)), ), 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())) diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index fc6c1da..35bf3a9 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -164,37 +164,6 @@ fn tck_union_type( )) } -fn tck_list_type(ctx: &TypecheckContext, t: Type) -> Result { - use crate::error::TypeMessage::*; - ensure_simple_type!( - t, - TypeError::new(ctx, InvalidListType(t.to_normalized())), - ); - Ok(Typed::from_thunk_and_type( - Value::from_builtin(Builtin::List) - .app(t.to_value()) - .into_thunk(), - Type::from_const(Const::Type), - )) -} - -fn tck_optional_type( - ctx: &TypecheckContext, - t: Type, -) -> Result { - use crate::error::TypeMessage::*; - ensure_simple_type!( - t, - TypeError::new(ctx, InvalidOptionalType(t.to_normalized())), - ); - Ok(Typed::from_thunk_and_type( - Value::from_builtin(Builtin::Optional) - .app(t.to_value()) - .into_thunk(), - Type::from_const(Const::Type), - )) -} - fn function_check(a: Const, b: Const) -> Result { use dhall_syntax::Const::*; match (a, b) { @@ -460,7 +429,17 @@ fn type_last_layer( } EmptyListLit(t) => { let t = t.to_type(); - Ok(RetTypeOnly(tck_list_type(ctx, t)?.to_type())) + match &t.to_value() { + Value::AppliedBuiltin(dhall_syntax::Builtin::List, args) + if args.len() == 1 => {} + _ => { + return Err(TypeError::new( + ctx, + InvalidListType(t.to_normalized()), + )) + } + } + Ok(RetTypeOnly(t)) } NEListLit(xs) => { let mut iter = xs.iter().enumerate(); @@ -476,12 +455,38 @@ fn type_last_layer( )) ); } - let t = x.get_type()?.into_owned(); - Ok(RetTypeOnly(tck_list_type(ctx, t)?.to_type())) + let t = x.get_type()?; + ensure_simple_type!( + t, + TypeError::new(ctx, InvalidListType(t.to_normalized())), + ); + + Ok(RetTypeOnly( + Typed::from_thunk_and_type( + Value::from_builtin(dhall_syntax::Builtin::List) + .app(t.to_value()) + .into_thunk(), + Type::from_const(dhall_syntax::Const::Type), + ) + .to_type(), + )) } SomeLit(x) => { let t = x.get_type()?.into_owned(); - Ok(RetTypeOnly(tck_optional_type(ctx, t)?.to_type())) + ensure_simple_type!( + t, + TypeError::new(ctx, InvalidOptionalType(t.to_normalized())), + ); + + Ok(RetTypeOnly( + Typed::from_thunk_and_type( + Value::from_builtin(dhall_syntax::Builtin::Optional) + .app(t.to_value()) + .into_thunk(), + Type::from_const(dhall_syntax::Const::Type), + ) + .to_type(), + )) } RecordType(kts) => Ok(RetWhole(tck_record_type( ctx, diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 8355ebf..0832af3 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -752,7 +752,8 @@ make_parser! { spanned(span, Merge(x, y, Some(z))) }, [List(()), expression(x)] => { - spanned(span, EmptyListLit(x)) + let list = unspanned(Builtin(crate::Builtin::List)); + spanned(span, EmptyListLit(unspanned(App(list, x)))) }, [expression(e)] => e, )); diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index 2b2bbcc..52d3d81 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -27,7 +27,7 @@ impl Display for ExprF { write!(f, " = {} in {}", c, d)?; } EmptyListLit(t) => { - write!(f, "[] : List {}", t)?; + write!(f, "[] : {}", t)?; } NEListLit(es) => { fmt_list("[", ", ", "]", es, f, Display::fmt)?; @@ -182,7 +182,6 @@ impl Expr { a.phase(PrintPhase::BinOp(op)), b.phase(PrintPhase::BinOp(op)), ), - EmptyListLit(t) => EmptyListLit(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), -- cgit v1.2.3 From a307a13738ccca538635ae796e6c998439025b9b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 22:43:40 +0200 Subject: Circumvent spec error --- dhall_generated_parser/build.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs index 5275097..1edce9e 100644 --- a/dhall_generated_parser/build.rs +++ b/dhall_generated_parser/build.rs @@ -30,6 +30,7 @@ fn main() -> std::io::Result<()> { rules.remove("url_path"); rules.remove("simple_label"); rules.remove("nonreserved_label"); + rules.remove("first_application_expression"); let mut file = File::create(pest_path)?; writeln!(&mut file, "// AUTO-GENERATED FILE. See build.rs.")?; @@ -54,6 +55,16 @@ 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: this is a cheat; properly support RFC3986 URLs instead writeln!(&mut file, "url_path = _{{ path }}")?; writeln!( -- cgit v1.2.3 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(-) 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.2.3 From 2755cb01092363062016bc51349870b1330d1d6f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 7 Aug 2019 15:58:57 +0200 Subject: Sort labels in projection expressions --- dhall_syntax/src/core/expr.rs | 4 +- dhall_syntax/src/core/map.rs | 95 +++++++++++++++++++++++++++++++++++++++++++ dhall_syntax/src/parser.rs | 6 +-- 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 14dc165..668ab45 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use crate::map::DupTreeMap; +use crate::map::{DupTreeMap, DupTreeSet}; use crate::visitor; use crate::*; @@ -209,7 +209,7 @@ pub enum ExprF { /// `e.x` Field(SubExpr, Label), /// `e.{ x, y, z }` - Projection(SubExpr, Vec