From 5f0d69671b44ba1dff6becb9ebc7f6e74241e3e2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Aug 2019 18:14:55 +0200 Subject: Remove dead code --- serde_dhall/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'serde_dhall') diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 71674a9..f400206 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -168,7 +168,8 @@ pub mod value { } pub(crate) fn make_optional_type(t: Value) -> Self { Self::from_dhall_value( - DhallValue::from_builtin(Builtin::Optional).app_thunk(t.to_thunk()), + DhallValue::from_builtin(Builtin::Optional) + .app_thunk(t.to_thunk()), ) } pub(crate) fn make_list_type(t: Value) -> Self { -- cgit v1.2.3 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 From e0f5216215ccb7a4df85d80e11dd265cdb52a44f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Aug 2019 19:47:36 +0200 Subject: s/Value/ValueF/ --- serde_dhall/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'serde_dhall') diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index a277977..49fd40e 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -125,7 +125,7 @@ pub use value::Value; // A Dhall value. pub mod value { use dhall::core::thunk::{Thunk, TypedThunk}; - use dhall::core::value::Value as DhallValue; + use dhall::core::value::ValueF as DhallValue; use dhall::phase::{NormalizedSubExpr, Parsed, Type, Typed}; use dhall_syntax::Builtin; @@ -162,7 +162,7 @@ pub mod value { /// 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())) + Value(Typed::from_valuef_and_type(v, Type::const_type())) } pub(crate) fn make_builtin_type(b: Builtin) -> Self { Self::make_simple_type(DhallValue::from_builtin(b)) -- cgit v1.2.3 From 6753a1f97bb674d91dd4d42f2ddb25a8119e070d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 17 Aug 2019 19:00:43 +0200 Subject: s/Thunk/Value/ --- serde_dhall/src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'serde_dhall') diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 49fd40e..48f311e 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -124,8 +124,9 @@ pub use value::Value; // A Dhall value. pub mod value { - use dhall::core::thunk::{Thunk, TypedThunk}; - use dhall::core::value::ValueF as DhallValue; + use dhall::core::value::TypedValue as TypedThunk; + use dhall::core::value::Value as Thunk; + use dhall::core::valuef::ValueF as DhallValue; use dhall::phase::{NormalizedSubExpr, Parsed, Type, Typed}; use dhall_syntax::Builtin; @@ -153,8 +154,8 @@ pub mod value { pub(crate) fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() } - pub(crate) fn to_thunk(&self) -> Thunk { - self.0.to_thunk() + pub(crate) fn to_value(&self) -> Thunk { + self.0.to_value() } pub(crate) fn to_type(&self) -> Type { self.0.to_type() @@ -170,12 +171,12 @@ pub mod value { pub(crate) fn make_optional_type(t: Value) -> Self { Self::make_simple_type( DhallValue::from_builtin(Builtin::Optional) - .app_thunk(t.to_thunk()), + .app_value(t.to_value()), ) } pub(crate) fn make_list_type(t: Value) -> Self { Self::make_simple_type( - DhallValue::from_builtin(Builtin::List).app_thunk(t.to_thunk()), + DhallValue::from_builtin(Builtin::List).app_value(t.to_value()), ) } // Made public for the StaticType derive macro @@ -185,7 +186,7 @@ pub mod value { ) -> Self { Self::make_simple_type(DhallValue::RecordType( kts.map(|(k, t)| { - (k.into(), TypedThunk::from_thunk_simple_type(t.to_thunk())) + (k.into(), TypedThunk::from_value_simple_type(t.to_value())) }) .collect(), )) @@ -199,7 +200,7 @@ pub mod value { ( k.into(), t.map(|t| { - TypedThunk::from_thunk_simple_type(t.to_thunk()) + TypedThunk::from_value_simple_type(t.to_value()) }), ) }) -- cgit v1.2.3 From 26a1fd0f0861038a76a0f9b09eaef16d808d4139 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 19 Aug 2019 21:52:26 +0200 Subject: Use TypedValue instead of Typed in normalize and typecheck Now Typed is only used in dhall::phase, similarly to Parsed/Resolved/Normalized --- serde_dhall/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'serde_dhall') diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 48f311e..31643d0 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -127,7 +127,7 @@ pub mod value { use dhall::core::value::TypedValue as TypedThunk; use dhall::core::value::Value as Thunk; use dhall::core::valuef::ValueF as DhallValue; - use dhall::phase::{NormalizedSubExpr, Parsed, Type, Typed}; + use dhall::phase::{NormalizedSubExpr, Parsed, Typed}; use dhall_syntax::Builtin; use super::de::{Error, Result}; @@ -147,7 +147,7 @@ pub mod value { let resolved = Parsed::parse_str(s)?.resolve()?; let typed = match ty { None => resolved.typecheck()?, - Some(t) => resolved.typecheck_with(&t.to_type())?, + Some(t) => resolved.typecheck_with(t.as_typed())?, }; Ok(Value(typed)) } @@ -157,13 +157,13 @@ pub mod value { pub(crate) fn to_value(&self) -> Thunk { self.0.to_value() } - pub(crate) fn to_type(&self) -> Type { - self.0.to_type() + pub(crate) fn as_typed(&self) -> &Typed { + &self.0 } /// Assumes that the given value has type `Type`. pub(crate) fn make_simple_type(v: DhallValue) -> Self { - Value(Typed::from_valuef_and_type(v, Type::const_type())) + Value(Typed::from_valuef_and_type(v, Typed::const_type())) } pub(crate) fn make_builtin_type(b: Builtin) -> Self { Self::make_simple_type(DhallValue::from_builtin(b)) -- cgit v1.2.3 From 07a276c1d6ee892b93abbd7a73c78c96d56f4fe7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 19 Aug 2019 22:26:17 +0200 Subject: Reduce untyped construction of Values --- serde_dhall/src/lib.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'serde_dhall') diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 31643d0..9d2ec85 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -186,7 +186,7 @@ pub mod value { ) -> Self { Self::make_simple_type(DhallValue::RecordType( kts.map(|(k, t)| { - (k.into(), TypedThunk::from_value_simple_type(t.to_value())) + (k.into(), TypedThunk::from_value(t.to_value())) }) .collect(), )) @@ -197,12 +197,7 @@ pub mod value { ) -> Self { Self::make_simple_type(DhallValue::UnionType( kts.map(|(k, t)| { - ( - k.into(), - t.map(|t| { - TypedThunk::from_value_simple_type(t.to_value()) - }), - ) + (k.into(), t.map(|t| TypedThunk::from_value(t.to_value()))) }) .collect(), )) -- cgit v1.2.3 From 730f2ebb146792994c7492b6c05f7d09d42cbccf Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 19 Aug 2019 23:00:49 +0200 Subject: Merge TypedValue and Value --- serde_dhall/src/lib.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'serde_dhall') diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 9d2ec85..cef11dd 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -124,9 +124,8 @@ pub use value::Value; // A Dhall value. pub mod value { - use dhall::core::value::TypedValue as TypedThunk; - use dhall::core::value::Value as Thunk; - use dhall::core::valuef::ValueF as DhallValue; + use dhall::core::value::Value as DhallValue; + use dhall::core::valuef::ValueF as DhallValueF; use dhall::phase::{NormalizedSubExpr, Parsed, Typed}; use dhall_syntax::Builtin; @@ -154,7 +153,7 @@ pub mod value { pub(crate) fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() } - pub(crate) fn to_value(&self) -> Thunk { + pub(crate) fn to_value(&self) -> DhallValue { self.0.to_value() } pub(crate) fn as_typed(&self) -> &Typed { @@ -162,21 +161,22 @@ pub mod value { } /// Assumes that the given value has type `Type`. - pub(crate) fn make_simple_type(v: DhallValue) -> Self { + pub(crate) fn make_simple_type(v: DhallValueF) -> Self { Value(Typed::from_valuef_and_type(v, Typed::const_type())) } pub(crate) fn make_builtin_type(b: Builtin) -> Self { - Self::make_simple_type(DhallValue::from_builtin(b)) + Self::make_simple_type(DhallValueF::from_builtin(b)) } pub(crate) fn make_optional_type(t: Value) -> Self { Self::make_simple_type( - DhallValue::from_builtin(Builtin::Optional) + DhallValueF::from_builtin(Builtin::Optional) .app_value(t.to_value()), ) } pub(crate) fn make_list_type(t: Value) -> Self { Self::make_simple_type( - DhallValue::from_builtin(Builtin::List).app_value(t.to_value()), + DhallValueF::from_builtin(Builtin::List) + .app_value(t.to_value()), ) } // Made public for the StaticType derive macro @@ -184,22 +184,17 @@ pub mod value { pub fn make_record_type( kts: impl Iterator, ) -> Self { - Self::make_simple_type(DhallValue::RecordType( - kts.map(|(k, t)| { - (k.into(), TypedThunk::from_value(t.to_value())) - }) - .collect(), + Self::make_simple_type(DhallValueF::RecordType( + kts.map(|(k, t)| (k.into(), t.to_value())).collect(), )) } #[doc(hidden)] pub fn make_union_type( kts: impl Iterator)>, ) -> Self { - Self::make_simple_type(DhallValue::UnionType( - kts.map(|(k, t)| { - (k.into(), t.map(|t| TypedThunk::from_value(t.to_value()))) - }) - .collect(), + Self::make_simple_type(DhallValueF::UnionType( + kts.map(|(k, t)| (k.into(), t.map(|t| t.to_value()))) + .collect(), )) } } -- cgit v1.2.3