From 6287b7a7f9e421877ee13fefa586395fec844c99 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 6 Dec 2020 21:41:03 +0000 Subject: Thread cx through typecheck --- dhall/src/builtins.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'dhall/src/builtins.rs') diff --git a/dhall/src/builtins.rs b/dhall/src/builtins.rs index cc426dd..f92f1c3 100644 --- a/dhall/src/builtins.rs +++ b/dhall/src/builtins.rs @@ -11,6 +11,7 @@ use crate::syntax::{ Const, Expr, ExprKind, InterpolatedText, InterpolatedTextContents, Label, NaiveDouble, NumKind, Span, UnspannedExpr, V, }; +use crate::Ctxt; /// Built-ins #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -98,12 +99,14 @@ pub struct BuiltinClosure { impl BuiltinClosure { pub fn new(b: Builtin, env: NzEnv) -> NirKind { - apply_builtin(b, Vec::new(), env) + // TODO: thread cx + Ctxt::with_new(|cx| apply_builtin(cx, b, Vec::new(), env)) } pub fn apply(&self, a: Nir) -> NirKind { use std::iter::once; let args = self.args.iter().cloned().chain(once(a)).collect(); - apply_builtin(self.b, args, self.env.clone()) + // TODO: thread cx + Ctxt::with_new(|cx| apply_builtin(cx, self.b, args, self.env.clone())) } pub fn to_hirkind(&self, venv: VarEnv) -> HirKind { HirKind::Expr(self.args.iter().fold( @@ -307,7 +310,12 @@ macro_rules! make_closure { } #[allow(clippy::cognitive_complexity)] -fn apply_builtin(b: Builtin, args: Vec, env: NzEnv) -> NirKind { +fn apply_builtin( + cx: Ctxt<'_>, + b: Builtin, + args: Vec, + env: NzEnv, +) -> NirKind { use NirKind::*; use NumKind::{Bool, Double, Integer, Natural}; @@ -318,7 +326,7 @@ fn apply_builtin(b: Builtin, args: Vec, env: NzEnv) -> NirKind { DoneAsIs, } let make_closure = |e| { - typecheck(&skip_resolve_expr(&e).unwrap()) + typecheck(cx, &skip_resolve_expr(&e).unwrap()) .unwrap() .eval(env.clone()) }; -- cgit v1.2.3