summaryrefslogtreecommitdiff
path: root/serde_dhall
diff options
context:
space:
mode:
authorNadrieril2020-12-06 23:55:21 +0000
committerNadrieril2020-12-07 19:34:38 +0000
commitc785b7c0c6cd8b3b1cc15eb79caf982a757020ba (patch)
tree6d38e68385814073b8b22ee8a8956435546892dc /serde_dhall
parent6287b7a7f9e421877ee13fefa586395fec844c99 (diff)
Thread cx through normalization
Diffstat (limited to 'serde_dhall')
-rw-r--r--serde_dhall/src/options/de.rs40
-rw-r--r--serde_dhall/src/value.rs4
2 files changed, 23 insertions, 21 deletions
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<A>,
{
- 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.
diff --git a/serde_dhall/src/value.rs b/serde_dhall/src/value.rs
index 4b22158..e5f5acd 100644
--- a/serde_dhall/src/value.rs
+++ b/serde_dhall/src/value.rs
@@ -335,7 +335,7 @@ impl SimpleValue {
// Converts this to `Hir`, using the optional type annotation. Without the type, things like
// empty lists and unions will fail to convert.
- fn to_hir(&self, ty: Option<&SimpleType>) -> Result<Hir> {
+ fn to_hir<'cx>(&self, ty: Option<&SimpleType>) -> Result<Hir<'cx>> {
use SimpleType as T;
use SimpleValue as V;
let hir = |k| Hir::new(HirKind::Expr(k), Span::Artificial);
@@ -481,7 +481,7 @@ impl SimpleType {
})
}
- pub(crate) fn to_hir(&self) -> Hir {
+ pub(crate) fn to_hir<'cx>(&self) -> Hir<'cx> {
let hir = |k| Hir::new(HirKind::Expr(k), Span::Artificial);
hir(match self {
SimpleType::Bool => ExprKind::Builtin(Builtin::Bool),