From 697e93e0f56e3c063ce253983f703be88d468b47 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Dec 2020 11:56:00 +0000 Subject: Don't store internal structures of `dhall` in `serde_dhall` --- serde_dhall/src/options/de.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'serde_dhall/src/options') diff --git a/serde_dhall/src/options/de.rs b/serde_dhall/src/options/de.rs index 22fa7ba..39ab5ca 100644 --- a/serde_dhall/src/options/de.rs +++ b/serde_dhall/src/options/de.rs @@ -229,7 +229,7 @@ impl<'a, A> Deserializer<'a, A> { // self // } - fn _parse(&self) -> dhall::error::Result + fn _parse(&self) -> dhall::error::Result> where A: TypeAnnot, T: HasAnnot, @@ -246,9 +246,12 @@ impl<'a, A> Deserializer<'a, A> { }; let typed = match &T::get_annot(self.annot) { None => resolved.typecheck()?, - Some(ty) => resolved.typecheck_with(ty.to_value().as_hir())?, + Some(ty) => resolved.typecheck_with(&ty.to_hir())?, }; - Ok(Value::from_nir(typed.normalize().as_nir())) + Ok(Value::from_nir_and_ty( + typed.normalize().as_nir(), + typed.ty().as_nir(), + )) } /// Parses the chosen dhall value with the options provided. @@ -274,7 +277,7 @@ impl<'a, A> Deserializer<'a, A> { let val = self ._parse::() .map_err(ErrorKind::Dhall) - .map_err(Error)?; + .map_err(Error)??; T::from_dhall(&val) } } -- cgit v1.2.3 From c785b7c0c6cd8b3b1cc15eb79caf982a757020ba Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 6 Dec 2020 23:55:21 +0000 Subject: Thread cx through normalization --- serde_dhall/src/options/de.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'serde_dhall/src/options') diff --git a/serde_dhall/src/options/de.rs b/serde_dhall/src/options/de.rs index 39ab5ca..d57759a 100644 --- a/serde_dhall/src/options/de.rs +++ b/serde_dhall/src/options/de.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use dhall::Parsed; +use dhall::{Ctxt, Parsed}; use crate::options::{HasAnnot, ManualAnnot, NoAnnot, StaticAnnot, TypeAnnot}; use crate::SimpleType; @@ -234,24 +234,26 @@ impl<'a, A> Deserializer<'a, A> { A: TypeAnnot, T: HasAnnot, { - let parsed = match &self.source { - Source::Str(s) => Parsed::parse_str(s)?, - Source::File(p) => Parsed::parse_file(p.as_ref())?, - Source::BinaryFile(p) => Parsed::parse_binary_file(p.as_ref())?, - }; - let resolved = if self.allow_imports { - parsed.resolve()? - } else { - parsed.skip_resolve()? - }; - let typed = match &T::get_annot(self.annot) { - None => resolved.typecheck()?, - Some(ty) => resolved.typecheck_with(&ty.to_hir())?, - }; - Ok(Value::from_nir_and_ty( - typed.normalize().as_nir(), - typed.ty().as_nir(), - )) + Ctxt::with_new(|cx| { + let parsed = match &self.source { + Source::Str(s) => Parsed::parse_str(s)?, + Source::File(p) => Parsed::parse_file(p.as_ref())?, + Source::BinaryFile(p) => Parsed::parse_binary_file(p.as_ref())?, + }; + let resolved = if self.allow_imports { + parsed.resolve(cx)? + } else { + parsed.skip_resolve()? + }; + let typed = match &T::get_annot(self.annot) { + None => resolved.typecheck(cx)?, + Some(ty) => resolved.typecheck_with(cx, &ty.to_hir())?, + }; + Ok(Value::from_nir_and_ty( + typed.normalize(cx).as_nir(), + typed.ty().as_nir(), + )) + }) } /// Parses the chosen dhall value with the options provided. -- cgit v1.2.3 From 8c5b3ff15f2125e9d731fc199e194e1993c36b37 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Dec 2020 14:15:43 +0000 Subject: Thread cx everywhere else imports are read --- serde_dhall/src/options/de.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'serde_dhall/src/options') diff --git a/serde_dhall/src/options/de.rs b/serde_dhall/src/options/de.rs index d57759a..fc8c6dc 100644 --- a/serde_dhall/src/options/de.rs +++ b/serde_dhall/src/options/de.rs @@ -250,6 +250,7 @@ impl<'a, A> Deserializer<'a, A> { Some(ty) => resolved.typecheck_with(cx, &ty.to_hir())?, }; Ok(Value::from_nir_and_ty( + cx, typed.normalize(cx).as_nir(), typed.ty().as_nir(), )) -- cgit v1.2.3 From 922199ab322efa7b62bf4698cf5ed9e2d7a378c0 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Dec 2020 15:24:36 +0000 Subject: Unify `skip_resolve_expr` with normal resolution --- serde_dhall/src/options/de.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'serde_dhall/src/options') diff --git a/serde_dhall/src/options/de.rs b/serde_dhall/src/options/de.rs index fc8c6dc..30846a2 100644 --- a/serde_dhall/src/options/de.rs +++ b/serde_dhall/src/options/de.rs @@ -243,7 +243,7 @@ impl<'a, A> Deserializer<'a, A> { let resolved = if self.allow_imports { parsed.resolve(cx)? } else { - parsed.skip_resolve()? + parsed.skip_resolve(cx)? }; let typed = match &T::get_annot(self.annot) { None => resolved.typecheck(cx)?, -- cgit v1.2.3