From 5542797c77a9dfcdffec539f1a82341a450291a2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 27 Dec 2019 15:31:06 +0000 Subject: s/TypecheckContext/TyCtx/ --- dhall/src/semantics/phase/typecheck.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'dhall/src/semantics/phase') diff --git a/dhall/src/semantics/phase/typecheck.rs b/dhall/src/semantics/phase/typecheck.rs index 3960146..16eabea 100644 --- a/dhall/src/semantics/phase/typecheck.rs +++ b/dhall/src/semantics/phase/typecheck.rs @@ -3,7 +3,7 @@ use std::cmp::max; use std::collections::HashMap; use crate::error::{TypeError, TypeMessage}; -use crate::semantics::core::context::TypecheckContext; +use crate::semantics::core::context::TyCtx; use crate::semantics::core::value::Value; use crate::semantics::core::value::ValueKind; use crate::semantics::core::var::{Shift, Subst}; @@ -16,7 +16,7 @@ use crate::syntax::{ }; fn tck_pi_type( - ctx: &TypecheckContext, + ctx: &TyCtx, x: Label, tx: Value, te: Value, @@ -48,7 +48,7 @@ fn tck_pi_type( } fn tck_record_type( - ctx: &TypecheckContext, + ctx: &TyCtx, kts: impl IntoIterator>, ) -> Result { use std::collections::hash_map::Entry; @@ -79,10 +79,7 @@ fn tck_record_type( )) } -fn tck_union_type( - ctx: &TypecheckContext, - kts: Iter, -) -> Result +fn tck_union_type(ctx: &TyCtx, kts: Iter) -> Result where Iter: IntoIterator), TypeError>>, { @@ -294,7 +291,7 @@ fn type_of_builtin(b: Builtin) -> Expr { } pub(crate) fn builtin_to_value(b: Builtin) -> Value { - let ctx = TypecheckContext::new(); + let ctx = TyCtx::new(); Value::from_kind_and_type( ValueKind::from_builtin(b), type_with(&ctx, type_of_builtin(b)).unwrap(), @@ -305,10 +302,7 @@ pub(crate) fn builtin_to_value(b: Builtin) -> Value { /// succeeded, or an error if type-checking failed. /// Some normalization is done while typechecking, so the returned expression might be partially /// normalized as well. -fn type_with( - ctx: &TypecheckContext, - e: Expr, -) -> Result { +fn type_with(ctx: &TyCtx, e: Expr) -> Result { use syntax::ExprKind::{Annot, Embed, Lam, Let, Pi, Var}; let span = e.span(); @@ -364,7 +358,7 @@ fn type_with( /// When all sub-expressions have been typed, check the remaining toplevel /// layer. fn type_last_layer( - ctx: &TypecheckContext, + ctx: &TyCtx, e: ExprKind, span: Span, ) -> Result { @@ -827,7 +821,7 @@ fn type_last_layer( /// expression must be closed (i.e. no free variables), otherwise type-checking /// will fail. pub(crate) fn typecheck(e: Expr) -> Result { - type_with(&TypecheckContext::new(), e) + type_with(&TyCtx::new(), e) } pub(crate) fn typecheck_with( -- cgit v1.3.1 From ce706817dcb5cb951c566410de92a4f85aae5361 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 27 Dec 2019 15:36:10 +0000 Subject: Tiny clarification --- dhall/src/semantics/phase/typecheck.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'dhall/src/semantics/phase') diff --git a/dhall/src/semantics/phase/typecheck.rs b/dhall/src/semantics/phase/typecheck.rs index 16eabea..c8d934d 100644 --- a/dhall/src/semantics/phase/typecheck.rs +++ b/dhall/src/semantics/phase/typecheck.rs @@ -306,23 +306,23 @@ fn type_with(ctx: &TyCtx, e: Expr) -> Result { use syntax::ExprKind::{Annot, Embed, Lam, Let, Pi, Var}; let span = e.span(); - Ok(match e.as_ref() { + match e.as_ref() { Lam(var, annot, body) => { let annot = type_with(ctx, annot.clone())?; annot.normalize_nf(); let ctx2 = ctx.insert_type(var, annot.clone()); let body = type_with(&ctx2, body.clone())?; let body_type = body.get_type()?; - Value::from_kind_and_type( + Ok(Value::from_kind_and_type( ValueKind::Lam(var.clone().into(), annot.clone(), body), tck_pi_type(ctx, var.clone(), annot, body_type)?, - ) + )) } Pi(x, ta, tb) => { let ta = type_with(ctx, ta.clone())?; let ctx2 = ctx.insert_type(x, ta.clone()); let tb = type_with(&ctx2, tb.clone())?; - return tck_pi_type(ctx, x.clone(), ta, tb); + tck_pi_type(ctx, x.clone(), ta, tb) } Let(x, t, v, e) => { let v = if let Some(t) = t { @@ -332,16 +332,13 @@ fn type_with(ctx: &TyCtx, e: Expr) -> Result { }; let v = type_with(ctx, v)?; - return type_with(&ctx.insert_value(x, v.clone())?, e.clone()); + type_with(&ctx.insert_value(x, v.clone())?, e.clone()) } - Embed(p) => p.clone().into_typed().into_value(), + Embed(p) => Ok(p.clone().into_typed().into_value()), Var(var) => match ctx.lookup(&var) { - Some(typed) => typed.clone(), + Some(typed) => Ok(typed.clone()), None => { - return Err(TypeError::new( - ctx, - TypeMessage::UnboundVariable(span), - )) + Err(TypeError::new(ctx, TypeMessage::UnboundVariable(span))) } }, e => { @@ -350,9 +347,9 @@ fn type_with(ctx: &TyCtx, e: Expr) -> Result { |e| type_with(ctx, e.clone()), |_, _| unreachable!(), )?; - type_last_layer(ctx, expr, span)? + type_last_layer(ctx, expr, span) } - }) + } } /// When all sub-expressions have been typed, check the remaining toplevel -- cgit v1.3.1 From 015b76ce47af5b1b31661a934aee13843215c6b0 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 27 Dec 2019 16:48:33 +0000 Subject: Construct T/Build closures in Expr space --- dhall/src/semantics/core/var.rs | 6 -- dhall/src/semantics/phase/normalize.rs | 113 +++++++++++++++++---------------- dhall/src/semantics/phase/typecheck.rs | 3 +- 3 files changed, 58 insertions(+), 64 deletions(-) (limited to 'dhall/src/semantics/phase') diff --git a/dhall/src/semantics/core/var.rs b/dhall/src/semantics/core/var.rs index 1548713..017a689 100644 --- a/dhall/src/semantics/core/var.rs +++ b/dhall/src/semantics/core/var.rs @@ -62,12 +62,6 @@ impl AlphaVar { self.normal.clone() } } - pub(crate) fn from_var_and_alpha(normal: V