From 1a702c9c8e6addd481fff49f970cc5c2ef7b5d56 Mon Sep 17 00:00:00 2001 From: Basile Henry Date: Sun, 1 Mar 2020 18:58:10 +0100 Subject: Enable ProjectionByType tests --- dhall/build.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/dhall/build.rs b/dhall/build.rs index 3ac2901..d9bceeb 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -281,13 +281,6 @@ fn generate_tests() -> std::io::Result<()> { path == "simple/integerToDouble" // Too slow || path == "remoteSystems" - // TODO: projection by expression - || path == "unit/RecordProjectionByTypeEmpty" - || path == "unit/RecordProjectionByTypeNonEmpty" - || path == "unit/RecordProjectionByTypeNormalizeProjection" - || path == "unit/RecordProjectionByTypeWithinFieldSelection" - || path == "unit/RecursiveRecordMergeWithinFieldSelection1" - || path == "unit/NestedRecordProjectionByType" // TODO: fix Double/show || path == "prelude/JSON/number/1" // TODO: doesn't typecheck @@ -298,8 +291,8 @@ fn generate_tests() -> std::io::Result<()> { || path == "simplifications/rightBiasedMergeWithinRecordProjectionWithinFieldSelection1" || path == "simplifications/rightBiasedMergeWithinRecursiveRecordMergeWithinFieldselection" || path == "simplifications/issue661" - || path == "unit/RecordProjectionWithinFieldSelection" || path == "unit/RecursiveRecordMergeWithinFieldSelection0" + || path == "unit/RecursiveRecordMergeWithinFieldSelection1" || path == "unit/RecursiveRecordMergeWithinFieldSelection2" || path == "unit/RecursiveRecordMergeWithinFieldSelection3" }), -- cgit v1.2.3 From d5874d9dcedc15eaccb942cc8f45f26b2335ed2d Mon Sep 17 00:00:00 2001 From: Basile Henry Date: Mon, 2 Mar 2020 10:24:18 +0100 Subject: Normalization for ProjectionByExpr --- dhall/src/semantics/nze/normalize.rs | 37 +++++++++++++++++++++++++++++++++--- dhall/src/syntax/ast/expr.rs | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/dhall/src/semantics/nze/normalize.rs b/dhall/src/semantics/nze/normalize.rs index 604db8f..dedd659 100644 --- a/dhall/src/semantics/nze/normalize.rs +++ b/dhall/src/semantics/nze/normalize.rs @@ -372,11 +372,42 @@ pub(crate) fn normalize_one_layer(expr: ExprKind, env: &NzEnv) -> NirKind { }, _ => Ret::Expr(expr), }, + PartialExpr(ExprKind::Projection(v2, _)) => { + return normalize_one_layer( + ExprKind::Field(v2.clone(), l.clone()), + env, + ) + } _ => Ret::Expr(expr), }, - ExprKind::ProjectionByExpr(_, _) => { - unimplemented!("selection by expression") - } + + ExprKind::ProjectionByExpr(ref v, ref t) => match dbg!(v).kind() { + RecordLit(kvs) => match dbg!(t).kind() { + RecordType(kts) => Ret::NirKind(RecordLit( + kts.iter() + .filter_map(|(l, _)| { + kvs.get(l).map(|x| (l.clone(), x.clone())) + }) + .collect(), + )), + _ => Ret::Expr(expr), + }, + _ => match dbg!(t).kind() { + RecordType(kts) => { + use crate::syntax::map::DupTreeSet; + use std::iter::FromIterator; + + let ts = DupTreeSet::from_iter( + kts.iter().map(|(l, _)| l.clone()), + ); + return normalize_one_layer( + ExprKind::Projection(v.clone(), ts), + env, + ); + } + _ => Ret::Expr(expr), + }, + }, ExprKind::Merge(ref handlers, ref variant, _) => { match handlers.kind() { diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs index ce0a3d2..bb1a5b3 100644 --- a/dhall/src/syntax/ast/expr.rs +++ b/dhall/src/syntax/ast/expr.rs @@ -178,7 +178,7 @@ pub enum ExprKind { Field(SubExpr, Label), /// `e.{ x, y, z }` Projection(SubExpr, DupTreeSet