From d3f4a32d1e3d39c8d42306e5ca5ad4bb256edcd8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 8 Mar 2019 22:46:39 +0100 Subject: Rename Expr back to its true name --- dhall/src/imports.rs | 6 +- dhall/src/lib.rs | 2 +- dhall/src/main.rs | 2 +- dhall/src/normalize.rs | 10 +-- dhall/src/typecheck.rs | 146 +++++++++++++++++----------------- dhall/tests/macros.rs | 2 +- dhall_core/src/core.rs | 175 ++++++++++++++++++++--------------------- dhall_core/src/grammar_util.rs | 2 +- dhall_core/src/parser.rs | 76 +++++++++--------- dhall_generator/src/lib.rs | 12 +-- 10 files changed, 216 insertions(+), 217 deletions(-) diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index 4240b5e..ad0ae0f 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -1,11 +1,11 @@ // use dhall_core::{Expr, FilePrefix, Import, ImportLocation, ImportMode, X}; -use dhall_core::{Expr_, StringLike, Import, X}; +use dhall_core::{Expr, StringLike, Import, X}; // use std::path::Path; // use std::path::PathBuf; pub fn resolve_imports( - expr: &Expr_, -) -> Expr_ { + expr: &Expr, +) -> Expr { let no_import = |_: &Import| -> X { panic!("ahhh import") }; expr.map_embed(&no_import) } diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 66d132e..95f7f6f 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -44,7 +44,7 @@ pub fn load_dhall_file<'i, 'a: 'i>( f: &Path, source_pool: &'a mut Vec, _resolve_imports: bool, -) -> Result, DhallError> { +) -> Result, DhallError> { source_pool.push(String::new()); let mut buffer = source_pool.last_mut().unwrap(); File::open(f)?.read_to_string(&mut buffer)?; diff --git a/dhall/src/main.rs b/dhall/src/main.rs index b571996..23c8108 100644 --- a/dhall/src/main.rs +++ b/dhall/src/main.rs @@ -65,7 +65,7 @@ fn main() { } }; - let expr: Expr_ = imports::resolve_imports(&expr.take_ownership_of_labels()); + let expr: Expr = imports::resolve_imports(&expr.take_ownership_of_labels()); let type_expr = match typecheck::type_of(&expr) { Err(e) => { diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs index 4f07d9a..3b8099a 100644 --- a/dhall/src/normalize.rs +++ b/dhall/src/normalize.rs @@ -13,8 +13,8 @@ use std::fmt; /// leave ill-typed sub-expressions unevaluated. /// pub fn normalize( - e: &Expr_, -) -> Expr_ + e: &Expr, +) -> Expr where S: Clone + fmt::Debug, T: Clone + fmt::Debug, @@ -22,7 +22,7 @@ where { use dhall_core::BinOp::*; use dhall_core::Builtin::*; - use dhall_core::Expr_::*; + use dhall_core::Expr::*; match e { // Matches that don't normalize everything right away Let(f, _, r, b) => { @@ -96,7 +96,7 @@ where // normalize(&dhall!(k (List a0) (λ(a : a0) -> λ(as : List a1) -> [ a ] # as) ([] : List a0))) // } (App(box App(box App(box App(box Builtin(ListFold), _), box ListLit(_, xs)), _), cons), nil) => { - let e2: Expr_<_, _, _> = xs.into_iter().rev().fold(nil, |y, ys| { + let e2: Expr<_, _, _> = xs.into_iter().rev().fold(nil, |y, ys| { let y = bx(y); let ys = bx(ys); dhall!(cons y ys) @@ -133,7 +133,7 @@ where ] */ (App(box App(box App(box App(box Builtin(OptionalFold), _), box OptionalLit(_, xs)), _), just), nothing) => { - let e2: Expr_<_, _, _> = xs.into_iter().fold(nothing, |y, _| { + let e2: Expr<_, _, _> = xs.into_iter().fold(nothing, |y, _| { let y = bx(y); dhall!(just y) }); diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index 1c15d88..b5bdee8 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -8,9 +8,9 @@ use dhall_core::context::Context; use dhall_core::core; use dhall_core::core::Builtin::*; use dhall_core::core::Const::*; -use dhall_core::core::Expr_::*; +use dhall_core::core::Expr::*; use dhall_core::core::{app, pi}; -use dhall_core::core::{bx, shift, subst, Expr, Expr_, V, X, StringLike}; +use dhall_core::core::{bx, shift, subst, Expr, V, X, StringLike}; use self::TypeMessage::*; @@ -48,15 +48,15 @@ fn match_vars(vl: &V, vr: &V, ctx: &[(L, L)]) -> bool { } } -fn prop_equal(eL0: &Expr_, eR0: &Expr_) -> bool +fn prop_equal(eL0: &Expr, eR0: &Expr) -> bool where S: Clone + ::std::fmt::Debug, T: Clone + ::std::fmt::Debug, { fn go( ctx: &mut Vec<(L, L)>, - el: &Expr_, - er: &Expr_, + el: &Expr, + er: &Expr, ) -> bool where S: Clone + ::std::fmt::Debug, @@ -146,16 +146,16 @@ where } fn op2_type, S, EF>( - ctx: &Context>, - e: &Expr_, + ctx: &Context>, + e: &Expr, t: core::Builtin, ef: EF, - l: &Expr_, - r: &Expr_, -) -> Result, TypeError> + l: &Expr, + r: &Expr, +) -> Result, TypeError> where S: Clone + ::std::fmt::Debug, - EF: FnOnce(Expr_, Expr_) -> TypeMessage, + EF: FnOnce(Expr, Expr) -> TypeMessage, { let tl = normalize(&type_with(ctx, l)?); match tl { @@ -179,14 +179,14 @@ where /// is not necessary for just type-checking. If you actually care about the /// returned type then you may want to `normalize` it afterwards. pub fn type_with, S>( - ctx: &Context>, - e: &Expr_, -) -> Result, TypeError> + ctx: &Context>, + e: &Expr, +) -> Result, TypeError> where S: Clone + ::std::fmt::Debug, { use dhall_core::BinOp::*; - use dhall_core::Expr_; + use dhall_core::Expr; match *e { Const(c) => axiom(c).map(Const), //.map(Cow::Owned), Var(V(ref x, n)) => { @@ -418,7 +418,7 @@ where } ListLit(ref t, ref xs) => { let mut iter = xs.iter().enumerate(); - let t: Box> = match t { + let t: Box> = match t { Some(t) => t.clone(), None => { let (_, first_x) = iter.next().unwrap(); @@ -488,14 +488,14 @@ where pi("_", app(List, "a"), app(Optional, "a")), ).take_ownership_of_labels()), Builtin(ListIndexed) => { - let mut m: BTreeMap> = BTreeMap::new(); + let mut m: BTreeMap> = BTreeMap::new(); m.insert("index".to_owned().into(), Builtin(Natural)); - let var: Expr_ = Var(V(Label::from("a".to_owned()), 0)); + let var: Expr = Var(V(Label::from("a".to_owned()), 0)); m.insert("value".to_owned().into(), var.clone()); let underscore: Label = Label::from("_".to_owned()); - let innerinner: Expr_ = app(List, Record(m)); - let innerinner2: Expr_ = app(List, var); - let inner: Expr_ = Pi(underscore, bx(innerinner2), bx(innerinner)); + let innerinner: Expr = app(List, Record(m)); + let innerinner2: Expr = app(List, var); + let inner: Expr = Pi(underscore, bx(innerinner2), bx(innerinner)); Ok(Pi( Label::from("a".to_owned()), bx(Const(Type)), @@ -509,7 +509,7 @@ where ).take_ownership_of_labels()), OptionalLit(ref t, ref xs) => { let mut iter = xs.iter(); - let t: Box> = match t { + let t: Box> = match t { Some(t) => t.clone(), None => { let first_x = iter.next().unwrap(); @@ -714,8 +714,8 @@ where /// expression must be closed (i.e. no free variables), otherwise type-checking /// will fail. pub fn type_of, S: Clone + ::std::fmt::Debug>( - e: &Expr_, -) -> Result, TypeError> { + e: &Expr, +) -> Result, TypeError> { let ctx = Context::new(); type_with(&ctx, e) //.map(|e| e.into_owned()) } @@ -724,83 +724,83 @@ pub fn type_of, S: Clone + ::std::fmt::Debug>( #[derive(Debug)] pub enum TypeMessage { UnboundVariable, - InvalidInputType(Expr_), - InvalidOutputType(Expr_), - NotAFunction(Expr_, Expr_), + InvalidInputType(Expr), + InvalidOutputType(Expr), + NotAFunction(Expr, Expr), TypeMismatch( - Expr_, - Expr_, - Expr_, - Expr_, + Expr, + Expr, + Expr, + Expr, ), - AnnotMismatch(Expr_, Expr_, Expr_), + AnnotMismatch(Expr, Expr, Expr), Untyped, InvalidListElement( usize, - Expr_, - Expr_, - Expr_, + Expr, + Expr, + Expr, ), - InvalidListType(Expr_), + InvalidListType(Expr), InvalidOptionalElement( - Expr_, - Expr_, - Expr_, + Expr, + Expr, + Expr, ), InvalidOptionalLiteral(usize), - InvalidOptionalType(Expr_), - InvalidPredicate(Expr_, Expr_), + InvalidOptionalType(Expr), + InvalidPredicate(Expr, Expr), IfBranchMismatch( - Expr_, - Expr_, - Expr_, - Expr_, + Expr, + Expr, + Expr, + Expr, ), IfBranchMustBeTerm( bool, - Expr_, - Expr_, - Expr_, + Expr, + Expr, + Expr, ), - InvalidField(Label, Expr_), - InvalidFieldType(Label, Expr_), - InvalidAlternative(Label, Expr_), - InvalidAlternativeType(Label, Expr_), + InvalidField(Label, Expr), + InvalidFieldType(Label, Expr), + InvalidAlternative(Label, Expr), + InvalidAlternativeType(Label, Expr), DuplicateAlternative(Label), - MustCombineARecord(Expr_, Expr_), + MustCombineARecord(Expr, Expr), FieldCollision(Label), - MustMergeARecord(Expr_, Expr_), - MustMergeUnion(Expr_, Expr_), + MustMergeARecord(Expr, Expr), + MustMergeUnion(Expr, Expr), UnusedHandler(HashSet