From 7cbfc1a0d32766a383d1f48902502adaa2234d2f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 18 Feb 2020 19:12:31 +0000 Subject: Avoid re-typechecking after import --- dhall/src/error/mod.rs | 1 - dhall/src/lib.rs | 3 +++ dhall/src/semantics/nze/normalize.rs | 1 + dhall/src/semantics/resolve/env.rs | 8 ++++---- dhall/src/semantics/resolve/hir.rs | 7 ++++++- dhall/src/semantics/resolve/resolve.rs | 20 +++++++++++--------- dhall/src/semantics/tck/typecheck.rs | 1 + 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs index b8f2fca..8829d47 100644 --- a/dhall/src/error/mod.rs +++ b/dhall/src/error/mod.rs @@ -1,7 +1,6 @@ use std::io::Error as IOError; use crate::semantics::resolve::ImportStack; -use crate::semantics::Hir; use crate::syntax::{Import, ParseError}; mod builder; diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index c2f5020..9922144 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -123,6 +123,9 @@ impl Typed { self.hir.to_expr(ToExprOptions { alpha: false }) } + pub(crate) fn ty(&self) -> &Type { + &self.ty + } pub(crate) fn get_type(&self) -> Result { Ok(Normalized(self.ty.clone().into_nir())) } diff --git a/dhall/src/semantics/nze/normalize.rs b/dhall/src/semantics/nze/normalize.rs index 4c2aa33..604db8f 100644 --- a/dhall/src/semantics/nze/normalize.rs +++ b/dhall/src/semantics/nze/normalize.rs @@ -442,6 +442,7 @@ pub(crate) fn normalize_one_layer(expr: ExprKind, env: &NzEnv) -> NirKind { pub(crate) fn normalize_hir_whnf(env: &NzEnv, hir: &Hir) -> NirKind { match hir.kind() { HirKind::Var(var) => env.lookup_val(var), + HirKind::Import(hir, _) => normalize_hir_whnf(env, hir), HirKind::Expr(ExprKind::Lam(binder, annot, body)) => { let annot = annot.eval(env); NirKind::LamClosure { diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs index ff743d3..43676cc 100644 --- a/dhall/src/semantics/resolve/env.rs +++ b/dhall/src/semantics/resolve/env.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::error::{Error, ImportError}; -use crate::semantics::{AlphaVar, Hir, Import, VarEnv}; +use crate::semantics::{AlphaVar, Import, TypedHir, VarEnv}; use crate::syntax::{Label, V}; /// Environment for resolving names. @@ -10,7 +10,7 @@ pub(crate) struct NameEnv { names: Vec