From 1ed3123aeb3c9272b6810605a7ee781c42095f09 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 17:20:35 +0200 Subject: Swap Typed and TypeThunk --- dhall/src/phase/mod.rs | 95 +++++++++++++------------------------------------- 1 file changed, 25 insertions(+), 70 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index ccedff2..0b05227 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -4,14 +4,12 @@ use std::path::Path; use dhall_syntax::{Const, Import, Span, SubExpr, X}; -use crate::core::context::TypecheckContext; -use crate::core::thunk::Thunk; +use crate::core::thunk::{Thunk, TypeThunk}; use crate::core::value::Value; use crate::core::var::{AlphaVar, Shift, Subst}; -use crate::error::{EncodeError, Error, ImportError, TypeError, TypeMessage}; +use crate::error::{EncodeError, Error, ImportError, TypeError}; use resolve::ImportRoot; -use typecheck::type_of_const; pub(crate) mod binary; pub(crate) mod normalize; @@ -33,16 +31,7 @@ pub struct Resolved(ResolvedSubExpr); /// A typed expression #[derive(Debug, Clone)] -pub enum Typed { - // Any value, along with (optionally) its type - Untyped(Thunk), - Typed(Thunk, Box), - // One of the base higher-kinded typed. - // Used to avoid storing the same tower ot Type->Kind->Sort - // over and over again. Also enables having Sort as a type - // even though it doesn't itself have a type. - Const(Const), -} +pub struct Typed(TypeThunk); /// A normalized expression. /// @@ -105,83 +94,63 @@ impl Typed { /// /// However, `normalize` will not fail if the expression is ill-typed and will /// leave ill-typed sub-expressions unevaluated. - pub fn normalize(self) -> Normalized { - match &self { - Typed::Const(_) => {} - Typed::Untyped(thunk) | Typed::Typed(thunk, _) => { - thunk.normalize_nf(); - } - } + pub fn normalize(mut self) -> Normalized { + self.normalize_mut(); Normalized(self) } pub fn from_thunk_and_type(th: Thunk, t: Type) -> Self { - Typed::Typed(th, Box::new(t)) + Typed(TypeThunk::from_thunk_and_type(th, t)) } pub fn from_thunk_untyped(th: Thunk) -> Self { - Typed::Untyped(th) + Typed(TypeThunk::from_thunk_untyped(th)) } pub fn from_const(c: Const) -> Self { - Typed::Const(c) + Typed(TypeThunk::from_const(c)) } pub fn from_value_untyped(v: Value) -> Self { - Typed::from_thunk_untyped(Thunk::from_value(v)) + Typed(TypeThunk::from_value_untyped(v)) + } + pub fn from_typethunk(th: TypeThunk) -> Self { + Typed(th) } - // TODO: Avoid cloning if possible pub fn to_value(&self) -> Value { - match self { - Typed::Untyped(th) | Typed::Typed(th, _) => th.to_value(), - Typed::Const(c) => Value::Const(*c), - } + self.0.to_value() } pub fn to_expr(&self) -> NormalizedSubExpr { - self.to_value().normalize_to_expr() + self.0.to_expr() } pub fn to_expr_alpha(&self) -> NormalizedSubExpr { - self.to_value().normalize_to_expr_maybe_alpha(true) + self.0.to_expr_alpha() } pub fn to_thunk(&self) -> Thunk { - match self { - Typed::Untyped(th) | Typed::Typed(th, _) => th.clone(), - Typed::Const(c) => Thunk::from_value(Value::Const(*c)), - } + self.0.to_thunk() } // Deprecated pub fn to_type(&self) -> Type { - self.clone().into_type() + self.clone() } // Deprecated pub fn into_type(self) -> Type { self } + pub fn into_typethunk(self) -> TypeThunk { + self.0 + } pub fn to_normalized(&self) -> Normalized { self.clone().normalize() } pub fn as_const(&self) -> Option { - // TODO: avoid clone - match &self.to_value() { - Value::Const(c) => Some(*c), - _ => None, - } + self.0.as_const() } pub fn normalize_mut(&mut self) { - match self { - Typed::Untyped(th) | Typed::Typed(th, _) => th.normalize_mut(), - Typed::Const(_) => {} - } + self.0.normalize_mut() } pub fn get_type(&self) -> Result, TypeError> { - match self { - Typed::Untyped(_) => Err(TypeError::new( - &TypecheckContext::new(), - TypeMessage::Untyped, - )), - Typed::Typed(_, t) => Ok(Cow::Borrowed(t)), - Typed::Const(c) => Ok(Cow::Owned(type_of_const(*c)?)), - } + self.0.get_type() } } @@ -208,14 +177,7 @@ impl Normalized { impl Shift for Typed { fn shift(&self, delta: isize, var: &AlphaVar) -> Option { - Some(match self { - Typed::Untyped(th) => Typed::Untyped(th.shift(delta, var)?), - Typed::Typed(th, t) => Typed::Typed( - th.shift(delta, var)?, - Box::new(t.shift(delta, var)?), - ), - Typed::Const(c) => Typed::Const(*c), - }) + Some(Typed(self.0.shift(delta, var)?)) } } @@ -227,14 +189,7 @@ impl Shift for Normalized { impl Subst for Typed { fn subst_shift(&self, var: &AlphaVar, val: &Typed) -> Self { - match self { - Typed::Untyped(th) => Typed::Untyped(th.subst_shift(var, val)), - Typed::Typed(th, t) => Typed::Typed( - th.subst_shift(var, val), - Box::new(t.subst_shift(var, val)), - ), - Typed::Const(c) => Typed::Const(*c), - } + Typed(self.0.subst_shift(var, val)) } } -- cgit v1.2.3 From fb0120dffe8e9552c3da7b994ad850f66dc612a3 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 17:21:54 +0200 Subject: s/TypeThunk/TypedThunk/g --- dhall/src/phase/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 0b05227..27a6901 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -4,7 +4,7 @@ use std::path::Path; use dhall_syntax::{Const, Import, Span, SubExpr, X}; -use crate::core::thunk::{Thunk, TypeThunk}; +use crate::core::thunk::{Thunk, TypedThunk}; use crate::core::value::Value; use crate::core::var::{AlphaVar, Shift, Subst}; use crate::error::{EncodeError, Error, ImportError, TypeError}; @@ -31,7 +31,7 @@ pub struct Resolved(ResolvedSubExpr); /// A typed expression #[derive(Debug, Clone)] -pub struct Typed(TypeThunk); +pub struct Typed(TypedThunk); /// A normalized expression. /// @@ -100,18 +100,18 @@ impl Typed { } pub fn from_thunk_and_type(th: Thunk, t: Type) -> Self { - Typed(TypeThunk::from_thunk_and_type(th, t)) + Typed(TypedThunk::from_thunk_and_type(th, t)) } pub fn from_thunk_untyped(th: Thunk) -> Self { - Typed(TypeThunk::from_thunk_untyped(th)) + Typed(TypedThunk::from_thunk_untyped(th)) } pub fn from_const(c: Const) -> Self { - Typed(TypeThunk::from_const(c)) + Typed(TypedThunk::from_const(c)) } pub fn from_value_untyped(v: Value) -> Self { - Typed(TypeThunk::from_value_untyped(v)) + Typed(TypedThunk::from_value_untyped(v)) } - pub fn from_typethunk(th: TypeThunk) -> Self { + pub fn from_typethunk(th: TypedThunk) -> Self { Typed(th) } @@ -135,7 +135,7 @@ impl Typed { pub fn into_type(self) -> Type { self } - pub fn into_typethunk(self) -> TypeThunk { + pub fn into_typethunk(self) -> TypedThunk { self.0 } pub fn to_normalized(&self) -> Normalized { -- cgit v1.2.3 From 5895c3aa6552f75d7e5202be561f9734fe8945e7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 19:31:23 +0200 Subject: No need to track the absence of `Span`s at the type level --- dhall/src/phase/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 27a6901..8c93889 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::fmt::Display; use std::path::Path; -use dhall_syntax::{Const, Import, Span, SubExpr, X}; +use dhall_syntax::{Const, Import, SubExpr, X}; use crate::core::thunk::{Thunk, TypedThunk}; use crate::core::value::Value; @@ -17,10 +17,10 @@ pub(crate) mod parse; pub(crate) mod resolve; pub(crate) mod typecheck; -pub type ParsedSubExpr = SubExpr; -pub type DecodedSubExpr = SubExpr; -pub type ResolvedSubExpr = SubExpr; -pub type NormalizedSubExpr = SubExpr; +pub type ParsedSubExpr = SubExpr; +pub type DecodedSubExpr = SubExpr; +pub type ResolvedSubExpr = SubExpr; +pub type NormalizedSubExpr = SubExpr; #[derive(Debug, Clone)] pub struct Parsed(ParsedSubExpr, ImportRoot); -- cgit v1.2.3 From 77af0bbc171618f48531cc6b1d77e18089928885 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 20:54:15 +0200 Subject: Stop tracking the absence of Embed values at the type level --- dhall/src/phase/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 8c93889..7364949 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::fmt::Display; use std::path::Path; -use dhall_syntax::{Const, Import, SubExpr, X}; +use dhall_syntax::{Const, Import, SubExpr}; use crate::core::thunk::{Thunk, TypedThunk}; use crate::core::value::Value; @@ -20,7 +20,7 @@ pub(crate) mod typecheck; pub type ParsedSubExpr = SubExpr; pub type DecodedSubExpr = SubExpr; pub type ResolvedSubExpr = SubExpr; -pub type NormalizedSubExpr = SubExpr; +pub type NormalizedSubExpr = SubExpr; #[derive(Debug, Clone)] pub struct Parsed(ParsedSubExpr, ImportRoot); -- cgit v1.2.3 From 8d45d633dfa60e8d64c9e6e742de4e33496bf0fa Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 22:11:45 +0200 Subject: Store Imports in their own node instead of in Embed --- dhall/src/phase/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 7364949..a1e3f29 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::fmt::Display; use std::path::Path; -use dhall_syntax::{Const, Import, SubExpr}; +use dhall_syntax::{Const, SubExpr, Void}; use crate::core::thunk::{Thunk, TypedThunk}; use crate::core::value::Value; @@ -17,8 +17,8 @@ pub(crate) mod parse; pub(crate) mod resolve; pub(crate) mod typecheck; -pub type ParsedSubExpr = SubExpr; -pub type DecodedSubExpr = SubExpr; +pub type ParsedSubExpr = SubExpr; +pub type DecodedSubExpr = SubExpr; pub type ResolvedSubExpr = SubExpr; pub type NormalizedSubExpr = SubExpr; @@ -26,6 +26,8 @@ pub type NormalizedSubExpr = SubExpr; pub struct Parsed(ParsedSubExpr, ImportRoot); /// An expression where all imports have been resolved +/// +/// Invariant: there must be no `Import` nodes or `ImportAlt` operations left. #[derive(Debug, Clone)] pub struct Resolved(ResolvedSubExpr); -- cgit v1.2.3 From c600bae72198350b78fe19cf993b7f4c6f35225a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 23:08:48 +0200 Subject: Implement Hash for ParsedSubExpr --- dhall/src/phase/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index a1e3f29..b73597c 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -157,6 +157,10 @@ impl Typed { } impl Normalized { + pub fn encode(&self) -> Result, EncodeError> { + crate::phase::binary::encode(&self.to_expr()) + } + #[allow(dead_code)] pub fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() @@ -220,6 +224,18 @@ derive_traits_for_wrapper_struct!(Parsed); derive_traits_for_wrapper_struct!(Resolved); derive_traits_for_wrapper_struct!(Normalized); +impl std::hash::Hash for Normalized { + fn hash(&self, state: &mut H) + where + H: std::hash::Hasher, + { + match self.encode() { + Ok(vec) => vec.hash(state), + Err(_) => {} + } + } +} + impl Eq for Typed {} impl PartialEq for Typed { fn eq(&self, other: &Self) -> bool { -- cgit v1.2.3 From 509743469035582d916e6a2f331fd5018c81447e Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Aug 2019 11:11:28 +0200 Subject: Use `!` type instead of custom empty type --- dhall/src/phase/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index b73597c..2700e99 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::fmt::Display; use std::path::Path; -use dhall_syntax::{Const, SubExpr, Void}; +use dhall_syntax::{Const, SubExpr}; use crate::core::thunk::{Thunk, TypedThunk}; use crate::core::value::Value; @@ -17,8 +17,8 @@ pub(crate) mod parse; pub(crate) mod resolve; pub(crate) mod typecheck; -pub type ParsedSubExpr = SubExpr; -pub type DecodedSubExpr = SubExpr; +pub type ParsedSubExpr = SubExpr; +pub type DecodedSubExpr = SubExpr; pub type ResolvedSubExpr = SubExpr; pub type NormalizedSubExpr = SubExpr; -- cgit v1.2.3 From 88ebc0f9d561a2541aad84a3152511a0439db8b4 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Aug 2019 17:56:19 +0200 Subject: Reduce api surface of dhall crate Helps detect unused code --- dhall/src/phase/mod.rs | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 2700e99..778f990 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -50,11 +50,9 @@ impl Parsed { pub fn parse_str(s: &str) -> Result { parse::parse_str(s) } - #[allow(dead_code)] pub fn parse_binary_file(f: &Path) -> Result { parse::parse_binary_file(f) } - #[allow(dead_code)] pub fn parse_binary(data: &[u8]) -> Result { parse::parse_binary(data) } @@ -62,12 +60,10 @@ impl Parsed { pub fn resolve(self) -> Result { resolve::resolve(self) } - #[allow(dead_code)] pub fn skip_resolve(self) -> Result { resolve::skip_resolve_expr(self) } - #[allow(dead_code)] pub fn encode(&self) -> Result, EncodeError> { crate::phase::binary::encode(&self.0) } @@ -82,7 +78,7 @@ impl Resolved { } /// Pretends this expression has been typechecked. Use with care. #[allow(dead_code)] - pub fn skip_typecheck(self) -> Typed { + pub(crate) fn skip_typecheck(self) -> Typed { typecheck::skip_typecheck(self) } } @@ -101,29 +97,29 @@ impl Typed { Normalized(self) } - pub fn from_thunk_and_type(th: Thunk, t: Type) -> Self { + pub(crate) fn from_thunk_and_type(th: Thunk, t: Type) -> Self { Typed(TypedThunk::from_thunk_and_type(th, t)) } - pub fn from_thunk_untyped(th: Thunk) -> Self { + pub(crate) fn from_thunk_untyped(th: Thunk) -> Self { Typed(TypedThunk::from_thunk_untyped(th)) } - pub fn from_const(c: Const) -> Self { + pub(crate) fn from_const(c: Const) -> Self { Typed(TypedThunk::from_const(c)) } pub fn from_value_untyped(v: Value) -> Self { Typed(TypedThunk::from_value_untyped(v)) } - pub fn from_typethunk(th: TypedThunk) -> Self { + pub(crate) fn from_typethunk(th: TypedThunk) -> Self { Typed(th) } - pub fn to_value(&self) -> Value { + pub(crate) fn to_value(&self) -> Value { self.0.to_value() } pub fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() } - pub fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { self.0.to_expr_alpha() } pub fn to_thunk(&self) -> Thunk { @@ -134,24 +130,24 @@ impl Typed { self.clone() } // Deprecated - pub fn into_type(self) -> Type { + pub(crate) fn into_type(self) -> Type { self } - pub fn into_typethunk(self) -> TypedThunk { + pub(crate) fn into_typethunk(self) -> TypedThunk { self.0 } - pub fn to_normalized(&self) -> Normalized { + pub(crate) fn to_normalized(&self) -> Normalized { self.clone().normalize() } - pub fn as_const(&self) -> Option { + pub(crate) fn as_const(&self) -> Option { self.0.as_const() } - pub fn normalize_mut(&mut self) { + pub(crate) fn normalize_mut(&mut self) { self.0.normalize_mut() } - pub fn get_type(&self) -> Result, TypeError> { + pub(crate) fn get_type(&self) -> Result, TypeError> { self.0.get_type() } } @@ -161,22 +157,21 @@ impl Normalized { crate::phase::binary::encode(&self.to_expr()) } - #[allow(dead_code)] - pub fn to_expr(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() } #[allow(dead_code)] - pub fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { self.0.to_expr_alpha() } #[allow(dead_code)] - pub fn to_type(&self) -> Type { + pub(crate) fn to_type(&self) -> Type { self.0.to_type() } - pub fn to_value(&self) -> Value { + pub(crate) fn to_value(&self) -> Value { self.0.to_value() } - pub fn into_typed(self) -> Typed { + pub(crate) fn into_typed(self) -> Typed { self.0 } } -- cgit v1.2.3 From 5f0d69671b44ba1dff6becb9ebc7f6e74241e3e2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Aug 2019 18:14:55 +0200 Subject: Remove dead code --- dhall/src/phase/mod.rs | 8 -------- 1 file changed, 8 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 778f990..5a6d4db 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -76,11 +76,6 @@ impl Resolved { pub fn typecheck_with(self, ty: &Type) -> Result { typecheck::typecheck_with(self, ty) } - /// Pretends this expression has been typechecked. Use with care. - #[allow(dead_code)] - pub(crate) fn skip_typecheck(self) -> Typed { - typecheck::skip_typecheck(self) - } } impl Typed { @@ -168,9 +163,6 @@ impl Normalized { pub(crate) fn to_type(&self) -> Type { self.0.to_type() } - pub(crate) fn to_value(&self) -> Value { - self.0.to_value() - } pub(crate) fn into_typed(self) -> Typed { self.0 } -- 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 --- dhall/src/phase/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 5a6d4db..adf749c 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -101,12 +101,15 @@ impl Typed { pub(crate) fn from_const(c: Const) -> Self { Typed(TypedThunk::from_const(c)) } - pub fn from_value_untyped(v: Value) -> Self { - Typed(TypedThunk::from_value_untyped(v)) + pub fn from_value_and_type(v: Value, t: Type) -> Self { + Typed(TypedThunk::from_value_and_type(v, t)) } pub(crate) fn from_typethunk(th: TypedThunk) -> Self { Typed(th) } + pub fn const_type() -> Self { + Typed::from_const(Const::Type) + } pub(crate) fn to_value(&self) -> Value { self.0.to_value() -- 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/ --- dhall/src/phase/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index adf749c..7e74f95 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -5,7 +5,7 @@ use std::path::Path; use dhall_syntax::{Const, SubExpr}; use crate::core::thunk::{Thunk, TypedThunk}; -use crate::core::value::Value; +use crate::core::value::ValueF; use crate::core::var::{AlphaVar, Shift, Subst}; use crate::error::{EncodeError, Error, ImportError, TypeError}; @@ -101,8 +101,8 @@ impl Typed { pub(crate) fn from_const(c: Const) -> Self { Typed(TypedThunk::from_const(c)) } - pub fn from_value_and_type(v: Value, t: Type) -> Self { - Typed(TypedThunk::from_value_and_type(v, t)) + pub fn from_valuef_and_type(v: ValueF, t: Type) -> Self { + Typed(TypedThunk::from_valuef_and_type(v, t)) } pub(crate) fn from_typethunk(th: TypedThunk) -> Self { Typed(th) @@ -111,8 +111,8 @@ impl Typed { Typed::from_const(Const::Type) } - pub(crate) fn to_value(&self) -> Value { - self.0.to_value() + pub(crate) fn to_valuef(&self) -> ValueF { + self.0.to_valuef() } pub fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() @@ -229,7 +229,7 @@ impl std::hash::Hash for Normalized { impl Eq for Typed {} impl PartialEq for Typed { fn eq(&self, other: &Self) -> bool { - self.to_value() == other.to_value() + self.to_valuef() == other.to_valuef() } } -- 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/ --- dhall/src/phase/mod.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 7e74f95..c18f976 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -4,8 +4,8 @@ use std::path::Path; use dhall_syntax::{Const, SubExpr}; -use crate::core::thunk::{Thunk, TypedThunk}; -use crate::core::value::ValueF; +use crate::core::value::{TypedValue, Value}; +use crate::core::valuef::ValueF; use crate::core::var::{AlphaVar, Shift, Subst}; use crate::error::{EncodeError, Error, ImportError, TypeError}; @@ -33,7 +33,7 @@ pub struct Resolved(ResolvedSubExpr); /// A typed expression #[derive(Debug, Clone)] -pub struct Typed(TypedThunk); +pub struct Typed(TypedValue); /// A normalized expression. /// @@ -92,19 +92,19 @@ impl Typed { Normalized(self) } - pub(crate) fn from_thunk_and_type(th: Thunk, t: Type) -> Self { - Typed(TypedThunk::from_thunk_and_type(th, t)) + pub(crate) fn from_value_and_type(th: Value, t: Type) -> Self { + Typed(TypedValue::from_value_and_type(th, t)) } - pub(crate) fn from_thunk_untyped(th: Thunk) -> Self { - Typed(TypedThunk::from_thunk_untyped(th)) + pub(crate) fn from_value_untyped(th: Value) -> Self { + Typed(TypedValue::from_value_untyped(th)) } pub(crate) fn from_const(c: Const) -> Self { - Typed(TypedThunk::from_const(c)) + Typed(TypedValue::from_const(c)) } pub fn from_valuef_and_type(v: ValueF, t: Type) -> Self { - Typed(TypedThunk::from_valuef_and_type(v, t)) + Typed(TypedValue::from_valuef_and_type(v, t)) } - pub(crate) fn from_typethunk(th: TypedThunk) -> Self { + pub(crate) fn from_typedvalue(th: TypedValue) -> Self { Typed(th) } pub fn const_type() -> Self { @@ -120,8 +120,8 @@ impl Typed { pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { self.0.to_expr_alpha() } - pub fn to_thunk(&self) -> Thunk { - self.0.to_thunk() + pub fn to_value(&self) -> Value { + self.0.to_value() } // Deprecated pub fn to_type(&self) -> Type { @@ -131,7 +131,7 @@ impl Typed { pub(crate) fn into_type(self) -> Type { self } - pub(crate) fn into_typethunk(self) -> TypedThunk { + pub(crate) fn into_typedvalue(self) -> TypedValue { self.0 } pub(crate) fn to_normalized(&self) -> Normalized { -- cgit v1.2.3 From 29016b78736dca857e4e7f7c4dc68ed5e30c28bb Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 19 Aug 2019 12:25:09 +0200 Subject: s/to_valuef/to_whnf/ and avoid cloning ValueFs when possible --- dhall/src/phase/mod.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index c18f976..a38e9d3 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -1,4 +1,5 @@ use std::borrow::Cow; +use std::cell::Ref; use std::fmt::Display; use std::path::Path; @@ -111,8 +112,13 @@ impl Typed { Typed::from_const(Const::Type) } - pub(crate) fn to_valuef(&self) -> ValueF { - self.0.to_valuef() + /// WARNING: drop this ref before normalizing the same value or you will run into BorrowMut + /// panics. + pub(crate) fn as_whnf(&self) -> Ref { + self.0.as_whnf() + } + pub(crate) fn to_whnf(&self) -> ValueF { + self.0.to_whnf() } pub fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() @@ -134,9 +140,6 @@ impl Typed { pub(crate) fn into_typedvalue(self) -> TypedValue { self.0 } - pub(crate) fn to_normalized(&self) -> Normalized { - self.clone().normalize() - } pub(crate) fn as_const(&self) -> Option { self.0.as_const() } @@ -229,7 +232,7 @@ impl std::hash::Hash for Normalized { impl Eq for Typed {} impl PartialEq for Typed { fn eq(&self, other: &Self) -> bool { - self.to_valuef() == other.to_valuef() + self.0 == other.0 } } -- 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 --- dhall/src/phase/mod.rs | 51 ++++++++++---------------------------------------- 1 file changed, 10 insertions(+), 41 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index a38e9d3..e58e689 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -1,5 +1,4 @@ use std::borrow::Cow; -use std::cell::Ref; use std::fmt::Display; use std::path::Path; @@ -42,8 +41,6 @@ pub struct Typed(TypedValue); #[derive(Debug, Clone)] pub struct Normalized(Typed); -pub type Type = Typed; - impl Parsed { pub fn parse_file(f: &Path) -> Result { parse::parse_file(f) @@ -72,10 +69,10 @@ impl Parsed { impl Resolved { pub fn typecheck(self) -> Result { - typecheck::typecheck(self) + Ok(typecheck::typecheck(self.0)?.into_typed()) } - pub fn typecheck_with(self, ty: &Type) -> Result { - typecheck::typecheck_with(self, ty) + pub fn typecheck_with(self, ty: &Typed) -> Result { + Ok(typecheck::typecheck_with(self.0, ty.to_expr())?.into_typed()) } } @@ -93,17 +90,11 @@ impl Typed { Normalized(self) } - pub(crate) fn from_value_and_type(th: Value, t: Type) -> Self { - Typed(TypedValue::from_value_and_type(th, t)) - } - pub(crate) fn from_value_untyped(th: Value) -> Self { - Typed(TypedValue::from_value_untyped(th)) - } pub(crate) fn from_const(c: Const) -> Self { Typed(TypedValue::from_const(c)) } - pub fn from_valuef_and_type(v: ValueF, t: Type) -> Self { - Typed(TypedValue::from_valuef_and_type(v, t)) + pub fn from_valuef_and_type(v: ValueF, t: Typed) -> Self { + Typed(TypedValue::from_valuef_and_type(v, t.into_typedvalue())) } pub(crate) fn from_typedvalue(th: TypedValue) -> Self { Typed(th) @@ -112,14 +103,6 @@ impl Typed { Typed::from_const(Const::Type) } - /// WARNING: drop this ref before normalizing the same value or you will run into BorrowMut - /// panics. - pub(crate) fn as_whnf(&self) -> Ref { - self.0.as_whnf() - } - pub(crate) fn to_whnf(&self) -> ValueF { - self.0.to_whnf() - } pub fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() } @@ -129,27 +112,17 @@ impl Typed { pub fn to_value(&self) -> Value { self.0.to_value() } - // Deprecated - pub fn to_type(&self) -> Type { - self.clone() - } - // Deprecated - pub(crate) fn into_type(self) -> Type { - self - } pub(crate) fn into_typedvalue(self) -> TypedValue { self.0 } - pub(crate) fn as_const(&self) -> Option { - self.0.as_const() - } pub(crate) fn normalize_mut(&mut self) { self.0.normalize_mut() } - pub(crate) fn get_type(&self) -> Result, TypeError> { - self.0.get_type() + #[allow(dead_code)] + pub(crate) fn get_type(&self) -> Result, TypeError> { + Ok(Cow::Owned(self.0.get_type()?.into_owned().into_typed())) } } @@ -165,10 +138,6 @@ impl Normalized { pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { self.0.to_expr_alpha() } - #[allow(dead_code)] - pub(crate) fn to_type(&self) -> Type { - self.0.to_type() - } pub(crate) fn into_typed(self) -> Typed { self.0 } @@ -186,8 +155,8 @@ impl Shift for Normalized { } } -impl Subst for Typed { - fn subst_shift(&self, var: &AlphaVar, val: &Typed) -> Self { +impl Subst for Typed { + fn subst_shift(&self, var: &AlphaVar, val: &TypedValue) -> Self { Typed(self.0.subst_shift(var, val)) } } -- 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 --- dhall/src/phase/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index e58e689..91d64c3 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -4,7 +4,7 @@ use std::path::Path; use dhall_syntax::{Const, SubExpr}; -use crate::core::value::{TypedValue, Value}; +use crate::core::value::Value; use crate::core::valuef::ValueF; use crate::core::var::{AlphaVar, Shift, Subst}; use crate::error::{EncodeError, Error, ImportError, TypeError}; @@ -33,7 +33,7 @@ pub struct Resolved(ResolvedSubExpr); /// A typed expression #[derive(Debug, Clone)] -pub struct Typed(TypedValue); +pub struct Typed(Value); /// A normalized expression. /// @@ -91,12 +91,12 @@ impl Typed { } pub(crate) fn from_const(c: Const) -> Self { - Typed(TypedValue::from_const(c)) + Typed(Value::from_const(c)) } pub fn from_valuef_and_type(v: ValueF, t: Typed) -> Self { - Typed(TypedValue::from_valuef_and_type(v, t.into_typedvalue())) + Typed(Value::from_valuef_and_type(v, t.into_value())) } - pub(crate) fn from_typedvalue(th: TypedValue) -> Self { + pub(crate) fn from_value(th: Value) -> Self { Typed(th) } pub fn const_type() -> Self { @@ -112,7 +112,7 @@ impl Typed { pub fn to_value(&self) -> Value { self.0.to_value() } - pub(crate) fn into_typedvalue(self) -> TypedValue { + pub(crate) fn into_value(self) -> Value { self.0 } @@ -155,8 +155,8 @@ impl Shift for Normalized { } } -impl Subst for Typed { - fn subst_shift(&self, var: &AlphaVar, val: &TypedValue) -> Self { +impl Subst for Typed { + fn subst_shift(&self, var: &AlphaVar, val: &Value) -> Self { Typed(self.0.subst_shift(var, val)) } } -- cgit v1.2.3 From caf36246a517b884d7cfcf7c31e1b5d8fce60dfa Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 20 Aug 2019 13:49:13 +0200 Subject: Cleanup --- dhall/src/phase/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 91d64c3..1f7e5f0 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -110,7 +110,7 @@ impl Typed { self.0.to_expr_alpha() } pub fn to_value(&self) -> Value { - self.0.to_value() + self.0.clone() } pub(crate) fn into_value(self) -> Value { self.0 -- cgit v1.2.3 From c157df5e66fb80ff6184cb3934e5b0883f0fdbf0 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 20 Aug 2019 18:11:05 +0200 Subject: No need for Cow in return type of get_type --- dhall/src/phase/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 1f7e5f0..1f80791 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -1,4 +1,3 @@ -use std::borrow::Cow; use std::fmt::Display; use std::path::Path; @@ -121,8 +120,8 @@ impl Typed { } #[allow(dead_code)] - pub(crate) fn get_type(&self) -> Result, TypeError> { - Ok(Cow::Owned(self.0.get_type()?.into_owned().into_typed())) + pub(crate) fn get_type(&self) -> Result { + Ok(self.0.get_type()?.into_typed()) } } -- cgit v1.2.3 From 8c1ffc5b68489be4694fff922ca48afeb0d45fc4 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 20 Aug 2019 23:02:56 +0200 Subject: Move type construction fns from serde_dhall to dhall --- dhall/src/phase/mod.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 1f80791..b5b7b64 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use std::path::Path; -use dhall_syntax::{Const, SubExpr}; +use dhall_syntax::{Builtin, Const, SubExpr}; use crate::core::value::Value; use crate::core::valuef::ValueF; @@ -123,6 +123,39 @@ impl Typed { pub(crate) fn get_type(&self) -> Result { Ok(self.0.get_type()?.into_typed()) } + + pub fn make_builtin_type(b: Builtin) -> Self { + Typed::from_value(Value::from_builtin(b)) + } + pub fn make_optional_type(t: Typed) -> Self { + Typed::from_value( + Value::from_builtin(Builtin::Optional).app(t.to_value()), + ) + } + pub fn make_list_type(t: Typed) -> Self { + Typed::from_value(Value::from_builtin(Builtin::List).app(t.to_value())) + } + pub fn make_record_type( + kts: impl Iterator, + ) -> Self { + Typed::from_valuef_and_type( + ValueF::RecordType( + kts.map(|(k, t)| (k.into(), t.into_value())).collect(), + ), + Typed::const_type(), + ) + } + pub fn make_union_type( + kts: impl Iterator)>, + ) -> Self { + Typed::from_valuef_and_type( + ValueF::UnionType( + kts.map(|(k, t)| (k.into(), t.map(|t| t.into_value()))) + .collect(), + ), + Typed::const_type(), + ) + } } impl Normalized { -- cgit v1.2.3 From 6c006e122a050ebbe76c8c566e559bbf9f2301a7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 20 Aug 2019 23:06:14 +0200 Subject: Reduce API surface of dhall crate --- dhall/src/phase/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index b5b7b64..ecf04e9 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -92,13 +92,13 @@ impl Typed { pub(crate) fn from_const(c: Const) -> Self { Typed(Value::from_const(c)) } - pub fn from_valuef_and_type(v: ValueF, t: Typed) -> Self { + pub(crate) fn from_valuef_and_type(v: ValueF, t: Typed) -> Self { Typed(Value::from_valuef_and_type(v, t.into_value())) } pub(crate) fn from_value(th: Value) -> Self { Typed(th) } - pub fn const_type() -> Self { + pub(crate) fn const_type() -> Self { Typed::from_const(Const::Type) } @@ -108,7 +108,7 @@ impl Typed { pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { self.0.to_expr_alpha() } - pub fn to_value(&self) -> Value { + pub(crate) fn to_value(&self) -> Value { self.0.clone() } pub(crate) fn into_value(self) -> Value { -- cgit v1.2.3 From 2df5c09242375ca29b7e95ac76de427c4f1518ed Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 26 Aug 2019 20:12:40 +0200 Subject: Tweak tests to avoid double compilation --- dhall/src/phase/mod.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index ecf04e9..ed608df 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -119,7 +119,6 @@ impl Typed { self.0.normalize_mut() } - #[allow(dead_code)] pub(crate) fn get_type(&self) -> Result { Ok(self.0.get_type()?.into_typed()) } @@ -166,7 +165,6 @@ impl Normalized { pub(crate) fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() } - #[allow(dead_code)] pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { self.0.to_expr_alpha() } -- cgit v1.2.3 From a981afc465f4279a7a4d6ce3ac5844e04846613b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 27 Aug 2019 22:58:20 +0200 Subject: clippy --- dhall/src/phase/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index ed608df..bd8853a 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -221,9 +221,8 @@ impl std::hash::Hash for Normalized { where H: std::hash::Hasher, { - match self.encode() { - Ok(vec) => vec.hash(state), - Err(_) => {} + if let Ok(vec) = self.encode() { + vec.hash(state) } } } -- cgit v1.2.3 From a7363042a16364a6dafdd545f4069dcf04a4197e Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 27 Aug 2019 23:18:13 +0200 Subject: Rename SubExpr to Expr, and Expr to RawExpr For clarity, and consistency with Value --- dhall/src/phase/mod.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index bd8853a..ecc9213 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use std::path::Path; -use dhall_syntax::{Builtin, Const, SubExpr}; +use dhall_syntax::{Builtin, Const, Expr}; use crate::core::value::Value; use crate::core::valuef::ValueF; @@ -16,19 +16,19 @@ pub(crate) mod parse; pub(crate) mod resolve; pub(crate) mod typecheck; -pub type ParsedSubExpr = SubExpr; -pub type DecodedSubExpr = SubExpr; -pub type ResolvedSubExpr = SubExpr; -pub type NormalizedSubExpr = SubExpr; +pub type ParsedExpr = Expr; +pub type DecodedExpr = Expr; +pub type ResolvedExpr = Expr; +pub type NormalizedExpr = Expr; #[derive(Debug, Clone)] -pub struct Parsed(ParsedSubExpr, ImportRoot); +pub struct Parsed(ParsedExpr, ImportRoot); /// An expression where all imports have been resolved /// /// Invariant: there must be no `Import` nodes or `ImportAlt` operations left. #[derive(Debug, Clone)] -pub struct Resolved(ResolvedSubExpr); +pub struct Resolved(ResolvedExpr); /// A typed expression #[derive(Debug, Clone)] @@ -102,10 +102,10 @@ impl Typed { Typed::from_const(Const::Type) } - pub fn to_expr(&self) -> NormalizedSubExpr { + pub fn to_expr(&self) -> NormalizedExpr { self.0.to_expr() } - pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr_alpha(&self) -> NormalizedExpr { self.0.to_expr_alpha() } pub(crate) fn to_value(&self) -> Value { @@ -162,10 +162,10 @@ impl Normalized { crate::phase::binary::encode(&self.to_expr()) } - pub(crate) fn to_expr(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr(&self) -> NormalizedExpr { self.0.to_expr() } - pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr_alpha(&self) -> NormalizedExpr { self.0.to_expr_alpha() } pub(crate) fn into_typed(self) -> Typed { -- cgit v1.2.3 From 55c127e70eb484df486a45b25bcf03479eebda10 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 28 Aug 2019 13:49:27 +0200 Subject: Cleanup conversion of `Value` to `Expr` --- dhall/src/phase/mod.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'dhall/src/phase/mod.rs') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index ecc9213..2c5505c 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -3,7 +3,7 @@ use std::path::Path; use dhall_syntax::{Builtin, Const, Expr}; -use crate::core::value::Value; +use crate::core::value::{ToExprOptions, Value}; use crate::core::valuef::ValueF; use crate::core::var::{AlphaVar, Shift, Subst}; use crate::error::{EncodeError, Error, ImportError, TypeError}; @@ -71,7 +71,8 @@ impl Resolved { Ok(typecheck::typecheck(self.0)?.into_typed()) } pub fn typecheck_with(self, ty: &Typed) -> Result { - Ok(typecheck::typecheck_with(self.0, ty.to_expr())?.into_typed()) + Ok(typecheck::typecheck_with(self.0, ty.normalize_to_expr())? + .into_typed()) } } @@ -102,11 +103,23 @@ impl Typed { Typed::from_const(Const::Type) } - pub fn to_expr(&self) -> NormalizedExpr { - self.0.to_expr() - } - pub(crate) fn to_expr_alpha(&self) -> NormalizedExpr { - self.0.to_expr_alpha() + pub(crate) fn to_expr(&self) -> NormalizedExpr { + self.0.to_expr(ToExprOptions { + alpha: false, + normalize: false, + }) + } + pub fn normalize_to_expr(&self) -> NormalizedExpr { + self.0.to_expr(ToExprOptions { + alpha: false, + normalize: true, + }) + } + pub(crate) fn normalize_to_expr_alpha(&self) -> NormalizedExpr { + self.0.to_expr(ToExprOptions { + alpha: true, + normalize: true, + }) } pub(crate) fn to_value(&self) -> Value { self.0.clone() @@ -163,10 +176,10 @@ impl Normalized { } pub(crate) fn to_expr(&self) -> NormalizedExpr { - self.0.to_expr() + self.0.normalize_to_expr() } pub(crate) fn to_expr_alpha(&self) -> NormalizedExpr { - self.0.to_expr_alpha() + self.0.normalize_to_expr_alpha() } pub(crate) fn into_typed(self) -> Typed { self.0 -- cgit v1.2.3