From a4332cfbd99a5a00563090a080e9bcb0cde9e963 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Nov 2020 17:45:12 +0000 Subject: Typed and TypedHir are the same --- dhall/src/semantics/resolve/cache.rs | 16 +++++++--------- dhall/src/semantics/resolve/env.rs | 13 +++++++------ dhall/src/semantics/resolve/resolve.rs | 30 ++++++++++++------------------ 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/dhall/src/semantics/resolve/cache.rs b/dhall/src/semantics/resolve/cache.rs index 2abe7a9..7763f18 100644 --- a/dhall/src/semantics/resolve/cache.rs +++ b/dhall/src/semantics/resolve/cache.rs @@ -4,8 +4,8 @@ use std::path::{Path, PathBuf}; use crate::error::{CacheError, Error}; use crate::parse::parse_binary; -use crate::semantics::TypedHir; use crate::syntax::{binary, Hash}; +use crate::Typed; use std::ffi::OsStr; use std::fs::File; @@ -52,7 +52,7 @@ impl Cache { self.cache_dir.join(filename_for_hash(hash)) } - pub fn get(&self, hash: &Hash) -> Result { + pub fn get(&self, hash: &Hash) -> Result { let path = self.entry_path(hash); let res = read_cache_file(&path, hash); if let Err(_) = res { @@ -64,14 +64,14 @@ impl Cache { res } - pub fn insert(&self, hash: &Hash, expr: &TypedHir) -> Result<(), Error> { + pub fn insert(&self, hash: &Hash, expr: &Typed) -> Result<(), Error> { let path = self.entry_path(hash); write_cache_file(&path, expr) } } /// Read a file from the cache, also checking that its hash is valid. -fn read_cache_file(path: &Path, hash: &Hash) -> Result { +fn read_cache_file(path: &Path, hash: &Hash) -> Result { let data = crate::utils::read_binary_file(path)?; match hash { @@ -83,14 +83,12 @@ fn read_cache_file(path: &Path, hash: &Hash) -> Result { } } - let crate::Typed { hir, ty } = - parse_binary(&data)?.skip_resolve()?.typecheck()?; - Ok((hir, ty)) + Ok(parse_binary(&data)?.skip_resolve()?.typecheck()?) } /// Write a file to the cache. -fn write_cache_file(path: &Path, expr: &TypedHir) -> Result<(), Error> { - let data = binary::encode(&expr.0.to_expr_noopts())?; +fn write_cache_file(path: &Path, expr: &Typed) -> Result<(), Error> { + let data = binary::encode(&expr.to_expr())?; File::create(path)?.write_all(data.as_slice())?; Ok(()) } diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs index 06e27a5..a24c274 100644 --- a/dhall/src/semantics/resolve/env.rs +++ b/dhall/src/semantics/resolve/env.rs @@ -1,8 +1,9 @@ use std::collections::HashMap; use crate::error::{Error, ImportError}; -use crate::semantics::{AlphaVar, Cache, ImportLocation, TypedHir, VarEnv}; +use crate::semantics::{AlphaVar, Cache, ImportLocation, VarEnv}; use crate::syntax::{Hash, Label, V}; +use crate::Typed; /// Environment for resolving names. #[derive(Debug, Clone, Default)] @@ -10,7 +11,7 @@ pub struct NameEnv { names: Vec