diff options
Diffstat (limited to 'dhall/src')
-rw-r--r-- | dhall/src/lib.rs | 22 | ||||
-rw-r--r-- | dhall/src/semantics/builtins.rs | 3 | ||||
-rw-r--r-- | dhall/src/semantics/nze/nir.rs | 10 | ||||
-rw-r--r-- | dhall/src/semantics/resolve/hir.rs | 14 | ||||
-rw-r--r-- | dhall/src/semantics/resolve/resolve.rs | 4 | ||||
-rw-r--r-- | dhall/src/semantics/tck/tir.rs | 7 | ||||
-rw-r--r-- | dhall/src/syntax/binary/decode.rs | 2 | ||||
-rw-r--r-- | dhall/src/tests.rs | 15 |
8 files changed, 32 insertions, 45 deletions
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 0e2ec82..799d86f 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -23,14 +23,10 @@ use crate::semantics::resolve::ImportLocation; use crate::semantics::{typecheck, typecheck_with, Hir, Nir, Tir, Type}; use crate::syntax::Expr; -pub(crate) type ParsedExpr = Expr; -pub(crate) type DecodedExpr = Expr; -pub(crate) type ResolvedExpr = Expr; -pub(crate) type NormalizedExpr = Expr; pub use crate::simple::{STyKind, SValKind, SimpleType, SimpleValue}; #[derive(Debug, Clone)] -pub(crate) struct Parsed(ParsedExpr, ImportLocation); +pub(crate) struct Parsed(Expr, ImportLocation); /// An expression where all imports have been resolved /// @@ -89,7 +85,7 @@ impl Parsed { } /// Converts a value back to the corresponding AST expression. - pub fn to_expr(&self) -> ParsedExpr { + pub fn to_expr(&self) -> Expr { self.0.clone() } } @@ -102,7 +98,7 @@ impl Resolved { Ok(Typed::from_tir(typecheck_with(&self.0, ty)?)) } /// Converts a value back to the corresponding AST expression. - pub fn to_expr(&self) -> ResolvedExpr { + pub fn to_expr(&self) -> Expr { self.0.to_expr_noopts() } } @@ -120,7 +116,7 @@ impl Typed { } /// Converts a value back to the corresponding AST expression. - fn to_expr(&self) -> ResolvedExpr { + fn to_expr(&self) -> Expr { self.hir.to_expr(ToExprOptions { alpha: false }) } @@ -142,7 +138,7 @@ impl Normalized { } /// Converts a value back to the corresponding AST expression. - pub fn to_expr(&self) -> NormalizedExpr { + pub fn to_expr(&self) -> Expr { self.0.to_expr(ToExprOptions::default()) } /// Converts a value back to the corresponding Hir expression. @@ -150,7 +146,7 @@ impl Normalized { self.0.to_hir_noenv() } /// Converts a value back to the corresponding AST expression, alpha-normalizing in the process. - pub(crate) fn to_expr_alpha(&self) -> NormalizedExpr { + pub(crate) fn to_expr_alpha(&self) -> Expr { self.0.to_expr(ToExprOptions { alpha: true }) } } @@ -180,7 +176,7 @@ impl Value { } /// Converts a value back to the corresponding AST expression. - pub(crate) fn to_expr(&self) -> NormalizedExpr { + pub(crate) fn to_expr(&self) -> Expr { self.hir.to_expr(ToExprOptions::default()) } } @@ -208,12 +204,12 @@ macro_rules! derive_traits_for_wrapper_struct { derive_traits_for_wrapper_struct!(Parsed); -impl From<Parsed> for NormalizedExpr { +impl From<Parsed> for Expr { fn from(other: Parsed) -> Self { other.to_expr() } } -impl From<Normalized> for NormalizedExpr { +impl From<Normalized> for Expr { fn from(other: Normalized) -> Self { other.to_expr() } diff --git a/dhall/src/semantics/builtins.rs b/dhall/src/semantics/builtins.rs index 8d17aed..eb50612 100644 --- a/dhall/src/semantics/builtins.rs +++ b/dhall/src/semantics/builtins.rs @@ -8,7 +8,6 @@ use crate::syntax::{ InterpolatedTextContents, Label, NaiveDouble, NumKind, Span, UnspannedExpr, V, }; -use crate::Normalized; use std::collections::HashMap; use std::convert::TryInto; @@ -340,7 +339,7 @@ fn apply_builtin(b: Builtin, args: Vec<Nir>, env: NzEnv) -> NirKind { TextLit(tlit) => { if let Some(s) = tlit.as_text() { // Printing InterpolatedText takes care of all the escaping - let txt: InterpolatedText<Normalized> = + let txt: InterpolatedText<Expr> = std::iter::once(InterpolatedTextContents::Text(s)) .collect(); Ret::Nir(Nir::from_text(txt)) diff --git a/dhall/src/semantics/nze/nir.rs b/dhall/src/semantics/nze/nir.rs index 6f482a8..7365463 100644 --- a/dhall/src/semantics/nze/nir.rs +++ b/dhall/src/semantics/nze/nir.rs @@ -7,10 +7,10 @@ use crate::semantics::{ BuiltinClosure, Hir, HirKind, NzEnv, NzVar, TyEnv, Type, Universe, VarEnv, }; use crate::syntax::{ - BinOp, Builtin, Const, ExprKind, InterpolatedTextContents, Label, NumKind, - Span, + BinOp, Builtin, Const, Expr, ExprKind, InterpolatedTextContents, Label, + NumKind, Span, }; -use crate::{NormalizedExpr, ToExprOptions}; +use crate::ToExprOptions; use crate::{STyKind, SValKind, SimpleType, SimpleValue}; /// Stores a possibly unevaluated value. Gets (partially) normalized on-demand, sharing computation @@ -137,10 +137,10 @@ impl Nir { Type::new(self.clone(), u.into()) } /// Converts a value back to the corresponding AST expression. - pub(crate) fn to_expr(&self, opts: ToExprOptions) -> NormalizedExpr { + pub(crate) fn to_expr(&self, opts: ToExprOptions) -> Expr { self.to_hir_noenv().to_expr(opts) } - pub(crate) fn to_expr_tyenv(&self, tyenv: &TyEnv) -> NormalizedExpr { + pub(crate) fn to_expr_tyenv(&self, tyenv: &TyEnv) -> Expr { self.to_hir(tyenv.as_varenv()).to_expr_tyenv(tyenv) } pub(crate) fn to_simple_value(&self) -> Option<SimpleValue> { diff --git a/dhall/src/semantics/resolve/hir.rs b/dhall/src/semantics/resolve/hir.rs index fa2989f..22abaaf 100644 --- a/dhall/src/semantics/resolve/hir.rs +++ b/dhall/src/semantics/resolve/hir.rs @@ -1,7 +1,7 @@ use crate::error::TypeError; use crate::semantics::{type_with, NameEnv, Nir, NzEnv, Tir, TyEnv, Type}; use crate::syntax::{Expr, ExprKind, Span, V}; -use crate::{NormalizedExpr, ToExprOptions}; +use crate::ToExprOptions; /// Stores an alpha-normalized variable. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -51,15 +51,15 @@ impl Hir { } /// Converts a closed Hir expr back to the corresponding AST expression. - pub fn to_expr(&self, opts: ToExprOptions) -> NormalizedExpr { + pub fn to_expr(&self, opts: ToExprOptions) -> Expr { hir_to_expr(self, opts, &mut NameEnv::new()) } /// Converts a closed Hir expr back to the corresponding AST expression. - pub fn to_expr_noopts(&self) -> NormalizedExpr { + pub fn to_expr_noopts(&self) -> Expr { let opts = ToExprOptions { alpha: false }; self.to_expr(opts) } - pub fn to_expr_tyenv(&self, env: &TyEnv) -> NormalizedExpr { + pub fn to_expr_tyenv(&self, env: &TyEnv) -> Expr { let opts = ToExprOptions { alpha: false }; let mut env = env.as_nameenv().clone(); hir_to_expr(self, opts, &mut env) @@ -93,11 +93,7 @@ impl Hir { } } -fn hir_to_expr( - hir: &Hir, - opts: ToExprOptions, - env: &mut NameEnv, -) -> NormalizedExpr { +fn hir_to_expr(hir: &Hir, opts: ToExprOptions, env: &mut NameEnv) -> Expr { let kind = match hir.kind() { HirKind::Var(v) if opts.alpha => ExprKind::Var(V("_".into(), v.idx())), HirKind::Var(v) => ExprKind::Var(env.label_var(*v)), diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs index f3fda4b..eb2f04f 100644 --- a/dhall/src/semantics/resolve/resolve.rs +++ b/dhall/src/semantics/resolve/resolve.rs @@ -13,7 +13,7 @@ use crate::syntax::{ BinOp, Builtin, Expr, ExprKind, FilePath, FilePrefix, ImportMode, ImportTarget, Span, UnspannedExpr, URL, }; -use crate::{Parsed, ParsedExpr, Resolved}; +use crate::{Parsed, Resolved}; // TODO: evaluate import headers pub(crate) type Import = syntax::Import<()>; @@ -333,7 +333,7 @@ pub(crate) fn resolve(parsed: Parsed) -> Result<Resolved, Error> { resolve_with_env(&mut ImportEnv::new(), parsed) } -pub(crate) fn skip_resolve(expr: &ParsedExpr) -> Result<Hir, Error> { +pub(crate) fn skip_resolve(expr: &Expr) -> Result<Hir, Error> { traverse_resolve_expr(&mut NameEnv::new(), expr, &mut |import| { Err(ImportError::UnexpectedImport(import).into()) }) diff --git a/dhall/src/semantics/tck/tir.rs b/dhall/src/semantics/tck/tir.rs index aeb7bf9..1865b8e 100644 --- a/dhall/src/semantics/tck/tir.rs +++ b/dhall/src/semantics/tck/tir.rs @@ -1,7 +1,6 @@ use crate::error::{ErrorBuilder, TypeError}; use crate::semantics::{mkerr, Hir, Nir, NirKind, NzEnv, TyEnv, VarEnv}; -use crate::syntax::{Builtin, Const, Span}; -use crate::NormalizedExpr; +use crate::syntax::{Builtin, Const, Expr, Span}; /// The type of a type. 0 is `Type`, 1 is `Kind`, etc... #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)] @@ -101,7 +100,7 @@ impl Type { pub fn to_hir(&self, venv: VarEnv) -> Hir { self.val.to_hir(venv) } - pub fn to_expr_tyenv(&self, tyenv: &TyEnv) -> NormalizedExpr { + pub fn to_expr_tyenv(&self, tyenv: &TyEnv) -> Expr { self.val.to_hir(tyenv.as_varenv()).to_expr_tyenv(tyenv) } } @@ -124,7 +123,7 @@ impl<'hir> Tir<'hir> { pub fn as_hir(&self) -> &Hir { &self.hir } - pub fn to_expr_tyenv(&self, env: &TyEnv) -> NormalizedExpr { + pub fn to_expr_tyenv(&self, env: &TyEnv) -> Expr { self.as_hir().to_expr_tyenv(env) } diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs index 05d5921..0fd358e 100644 --- a/dhall/src/syntax/binary/decode.rs +++ b/dhall/src/syntax/binary/decode.rs @@ -9,7 +9,7 @@ use crate::syntax::{ Integer, InterpolatedText, Label, Natural, NumKind, Scheme, Span, UnspannedExpr, URL, V, }; -use crate::DecodedExpr; +type DecodedExpr = Expr; pub(crate) fn decode(data: &[u8]) -> Result<DecodedExpr, DecodeError> { match serde_cbor::de::from_slice(data) { diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 659f6f7..2cd354f 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -10,8 +10,8 @@ use std::io::{Read, Write}; use std::path::PathBuf; use crate::error::{ErrorKind, Result}; -use crate::syntax::binary; -use crate::{Normalized, NormalizedExpr, Parsed, Resolved, Typed}; +use crate::syntax::{binary, Expr}; +use crate::{Normalized, Parsed, Resolved, Typed}; macro_rules! assert_eq_display { ($left:expr, $right:expr) => {{ @@ -111,7 +111,7 @@ impl TestFile { env::var("UPDATE_TEST_FILES") == Ok("1".to_string()) } /// Write the provided expression to the pointed file. - fn write_expr(&self, expr: impl Into<NormalizedExpr>) -> Result<()> { + fn write_expr(&self, expr: impl Into<Expr>) -> Result<()> { let expr = expr.into(); let path = self.path(); create_dir_all(path.parent().unwrap())?; @@ -142,7 +142,7 @@ impl TestFile { } /// Check that the provided expression matches the file contents. - pub fn compare(&self, expr: impl Into<NormalizedExpr>) -> Result<()> { + pub fn compare(&self, expr: impl Into<Expr>) -> Result<()> { let expr = expr.into(); if !self.path().is_file() { return self.write_expr(expr); @@ -159,7 +159,7 @@ impl TestFile { Ok(()) } /// Check that the provided expression matches the file contents. - pub fn compare_debug(&self, expr: impl Into<NormalizedExpr>) -> Result<()> { + pub fn compare_debug(&self, expr: impl Into<Expr>) -> Result<()> { let expr = expr.into(); if !self.path().is_file() { return self.write_expr(expr); @@ -176,10 +176,7 @@ impl TestFile { Ok(()) } /// Check that the provided expression matches the file contents. - pub fn compare_binary( - &self, - expr: impl Into<NormalizedExpr>, - ) -> Result<()> { + pub fn compare_binary(&self, expr: impl Into<Expr>) -> Result<()> { let expr = expr.into(); match self { TestFile::Binary(_) => {} |