From ab100be616932dab22a5309df86107b66e93db37 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 4 May 2019 18:41:22 +0200 Subject: Revert "Make SubExpr generic in the variable labels type" This reverts commit 4c159640e5ee77ffa48b85a5bffa56350cf933ef. --- dhall/src/binary.rs | 22 ++++++-------- dhall/src/expr.rs | 32 +++++++++----------- dhall/src/normalize.rs | 48 ++++++++++++++---------------- dhall/src/serde.rs | 2 +- dhall/src/traits/static_type.rs | 14 ++++----- dhall/src/typecheck.rs | 65 ++++++++++++++++++++--------------------- 6 files changed, 83 insertions(+), 100 deletions(-) (limited to 'dhall/src') diff --git a/dhall/src/binary.rs b/dhall/src/binary.rs index 0d9f28a..9c31d4c 100644 --- a/dhall/src/binary.rs +++ b/dhall/src/binary.rs @@ -2,7 +2,7 @@ use dhall_syntax::*; use itertools::*; use serde_cbor::value::value as cbor; -type ParsedExpr = SubExpr; +type ParsedExpr = SubExpr; #[derive(Debug)] pub enum DecodeError { @@ -18,32 +18,28 @@ pub fn decode(data: &[u8]) -> Result { } fn cbor_value_to_dhall(data: &cbor::Value) -> Result { - use cbor::Value::{Array, Bool, Null, Object, String, F64, I64, U64}; + use cbor::Value::*; use dhall_syntax::{BinOp, Builtin, Const}; - use ExprF::{ - Annot, App, BoolIf, BoolLit, DoubleLit, Embed, EmptyListLit, Field, - IntegerLit, Lam, Let, Merge, NEListLit, NaturalLit, OldOptionalLit, Pi, - RecordLit, RecordType, SomeLit, TextLit, UnionLit, UnionType, - }; + use ExprF::*; Ok(rc(match data { String(s) => match Builtin::parse(s) { Some(b) => ExprF::Builtin(b), None => match s.as_str() { "True" => BoolLit(true), "False" => BoolLit(false), - "Type" => ExprF::Const(Const::Type), - "Kind" => ExprF::Const(Const::Kind), - "Sort" => ExprF::Const(Const::Sort), + "Type" => Const(Const::Type), + "Kind" => Const(Const::Kind), + "Sort" => Const(Const::Sort), _ => Err(DecodeError::WrongFormatError("builtin".to_owned()))?, }, }, - U64(n) => ExprF::Var(Var(Label::from("_"), *n as usize)), + U64(n) => Var(V(Label::from("_"), *n as usize)), F64(x) => DoubleLit((*x).into()), Bool(b) => BoolLit(*b), Array(vec) => match vec.as_slice() { [String(l), U64(n)] => { let l = Label::from(l.as_str()); - ExprF::Var(Var(l, *n as usize)) + Var(V(l, *n as usize)) } [U64(0), f, args..] => { let mut f = cbor_value_to_dhall(&f)?; @@ -96,7 +92,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result { Err(DecodeError::WrongFormatError("binop".to_owned()))? } }; - ExprF::BinOp(op, x, y) + BinOp(op, x, y) } [U64(4), t] => { let t = cbor_value_to_dhall(&t)?; diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs index efc3928..5bde68f 100644 --- a/dhall/src/expr.rs +++ b/dhall/src/expr.rs @@ -23,17 +23,15 @@ macro_rules! derive_other_traits { }; } -type OutputSubExpr = SubExpr; - #[derive(Debug, Clone)] pub(crate) struct Parsed( - pub(crate) SubExpr, + pub(crate) SubExpr, pub(crate) ImportRoot, ); derive_other_traits!(Parsed); #[derive(Debug, Clone)] -pub(crate) struct Resolved(pub(crate) SubExpr); +pub(crate) struct Resolved(pub(crate) SubExpr); derive_other_traits!(Resolved); pub(crate) use self::typed::TypedInternal; @@ -59,12 +57,12 @@ impl std::fmt::Display for Normalized { } mod typed { - use super::{OutputSubExpr, Type, Typed}; + use super::{Type, Typed}; use crate::normalize::{Thunk, Value}; use crate::typecheck::{ TypeError, TypeInternal, TypeMessage, TypecheckContext, }; - use dhall_syntax::{Const, Label, Var}; + use dhall_syntax::{Const, Label, SubExpr, V, X}; use std::borrow::Cow; #[derive(Debug, Clone)] @@ -92,7 +90,7 @@ mod typed { } } - pub(crate) fn to_expr(&self) -> OutputSubExpr { + pub(crate) fn to_expr(&self) -> SubExpr { self.to_value().normalize_to_expr() } @@ -131,7 +129,7 @@ mod typed { } } - pub(crate) fn shift(&self, delta: isize, var: &Var