From 45fb07f74f19919f742be6fe7793dc72d4022f26 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Aug 2019 19:16:40 +0200 Subject: Try to minimize untyped TypedThunks --- serde_dhall/src/lib.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'serde_dhall') diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index f400206..a277977 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -160,20 +160,21 @@ pub mod value { self.0.to_type() } - pub(crate) fn from_dhall_value(v: DhallValue) -> Self { - Value(Typed::from_value_untyped(v)) + /// Assumes that the given value has type `Type`. + pub(crate) fn make_simple_type(v: DhallValue) -> Self { + Value(Typed::from_value_and_type(v, Type::const_type())) } pub(crate) fn make_builtin_type(b: Builtin) -> Self { - Self::from_dhall_value(DhallValue::from_builtin(b)) + Self::make_simple_type(DhallValue::from_builtin(b)) } pub(crate) fn make_optional_type(t: Value) -> Self { - Self::from_dhall_value( + Self::make_simple_type( DhallValue::from_builtin(Builtin::Optional) .app_thunk(t.to_thunk()), ) } pub(crate) fn make_list_type(t: Value) -> Self { - Self::from_dhall_value( + Self::make_simple_type( DhallValue::from_builtin(Builtin::List).app_thunk(t.to_thunk()), ) } @@ -182,9 +183,9 @@ pub mod value { pub fn make_record_type( kts: impl Iterator, ) -> Self { - Self::from_dhall_value(DhallValue::RecordType( + Self::make_simple_type(DhallValue::RecordType( kts.map(|(k, t)| { - (k.into(), TypedThunk::from_thunk(t.to_thunk())) + (k.into(), TypedThunk::from_thunk_simple_type(t.to_thunk())) }) .collect(), )) @@ -193,9 +194,14 @@ pub mod value { pub fn make_union_type( kts: impl Iterator)>, ) -> Self { - Self::from_dhall_value(DhallValue::UnionType( + Self::make_simple_type(DhallValue::UnionType( kts.map(|(k, t)| { - (k.into(), t.map(|t| TypedThunk::from_thunk(t.to_thunk()))) + ( + k.into(), + t.map(|t| { + TypedThunk::from_thunk_simple_type(t.to_thunk()) + }), + ) }) .collect(), )) -- cgit v1.2.3