diff options
author | Nadrieril | 2020-03-13 16:16:56 +0000 |
---|---|---|
committer | Nadrieril | 2020-03-31 21:44:01 +0100 |
commit | 6fdae6f8026fe9357de63c5557676f4def3eaf92 (patch) | |
tree | 2281e9894a18a183980d4b033e00e95d9a633a05 | |
parent | 60425d58151fef142b066d523dc4d5e832070b9c (diff) |
Remove Normalized and friends from public API
-rw-r--r-- | dhall/src/lib.rs | 42 | ||||
-rw-r--r-- | dhall/src/simple.rs | 7 | ||||
-rw-r--r-- | dhall/src/tests.rs | 2 | ||||
-rw-r--r-- | serde_dhall/src/lib.rs | 2 |
4 files changed, 21 insertions, 32 deletions
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 60b7a0e..7300d88 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -26,31 +26,31 @@ use crate::semantics::{ use crate::syntax::binary; use crate::syntax::{Builtin, Expr}; -pub type ParsedExpr = Expr; -pub type DecodedExpr = Expr; -pub type ResolvedExpr = Expr; -pub type NormalizedExpr = Expr; +pub(crate) type ParsedExpr = Expr; +pub(crate) type DecodedExpr = Expr; +pub(crate) type ResolvedExpr = Expr; +pub(crate) type NormalizedExpr = Expr; pub use crate::simple::{STyKind, SValKind, SimpleType, SimpleValue}; #[derive(Debug, Clone)] -pub struct Parsed(ParsedExpr, ImportLocation); +pub(crate) struct Parsed(ParsedExpr, ImportLocation); /// 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(Hir); +pub(crate) struct Resolved(Hir); /// A typed expression #[derive(Debug, Clone)] -pub struct Typed { +pub(crate) struct Typed { hir: Hir, ty: Type, } /// A normalized expression. #[derive(Debug, Clone)] -pub struct Normalized(Nir); +pub(crate) struct Normalized(Nir); /// A Dhall value. #[derive(Debug, Clone)] @@ -81,6 +81,7 @@ impl Parsed { pub fn parse_binary_file(f: &Path) -> Result<Parsed, Error> { parse::parse_binary_file(f) } + #[allow(dead_code)] pub fn parse_binary(data: &[u8]) -> Result<Parsed, Error> { parse::parse_binary(data) } @@ -88,13 +89,6 @@ impl Parsed { pub fn resolve(self) -> Result<Resolved, Error> { resolve::resolve(self) } - pub fn skip_resolve(self) -> Result<Resolved, Error> { - Ok(Resolved(resolve::skip_resolve(&self.0)?)) - } - - pub fn encode(&self) -> Result<Vec<u8>, EncodeError> { - binary::encode(&self.0) - } /// Converts a value back to the corresponding AST expression. pub fn to_expr(&self) -> ParsedExpr { @@ -156,14 +150,6 @@ impl Normalized { pub fn to_expr(&self) -> NormalizedExpr { self.0.to_expr(ToExprOptions::default()) } - /// Converts a value into a SimpleValue. - pub fn to_simple_value(&self) -> Result<SimpleValue, Expr> { - self.0.to_simple_value().ok_or_else(|| self.to_expr()) - } - /// Converts a value into a SimpleType. - pub fn to_simple_type(&self) -> Result<SimpleType, Expr> { - self.0.to_simple_type().ok_or_else(|| self.to_expr()) - } /// Converts a value back to the corresponding Hir expression. pub(crate) fn to_hir(&self) -> Hir { self.0.to_hir_noenv() @@ -186,25 +172,25 @@ impl Normalized { Normalized(th) } - pub fn make_builtin_type(b: Builtin) -> Self { + pub(crate) fn make_builtin_type(b: Builtin) -> Self { Normalized::from_nir(Nir::from_builtin(b)) } - pub fn make_optional_type(t: Normalized) -> Self { + pub(crate) fn make_optional_type(t: Normalized) -> Self { Normalized::from_nir( Nir::from_builtin(Builtin::Optional).app(t.to_nir()), ) } - pub fn make_list_type(t: Normalized) -> Self { + pub(crate) fn make_list_type(t: Normalized) -> Self { Normalized::from_nir(Nir::from_builtin(Builtin::List).app(t.to_nir())) } - pub fn make_record_type( + pub(crate) fn make_record_type( kts: impl Iterator<Item = (String, Normalized)>, ) -> Self { Normalized::from_kind(NirKind::RecordType( kts.map(|(k, t)| (k.into(), t.into_nir())).collect(), )) } - pub fn make_union_type( + pub(crate) fn make_union_type( kts: impl Iterator<Item = (String, Option<Normalized>)>, ) -> Self { Normalized::from_kind(NirKind::UnionType( diff --git a/dhall/src/simple.rs b/dhall/src/simple.rs index 9d3846e..014053e 100644 --- a/dhall/src/simple.rs +++ b/dhall/src/simple.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use crate::syntax::{Builtin, LitKind}; -use crate::Normalized; +use crate::{Normalized, Value}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct SimpleValue { @@ -56,7 +56,10 @@ impl SimpleType { pub fn kind(&self) -> &STyKind { self.kind.as_ref() } - pub fn into_normalized(self) -> Normalized { + pub fn to_value(&self) -> Value { + self.clone().into_normalized().to_value() + } + fn into_normalized(self) -> Normalized { match *self.kind { STyKind::Bool => Normalized::make_builtin_type(Builtin::Bool), STyKind::Natural => Normalized::make_builtin_type(Builtin::Natural), diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index a5a278c..659f6f7 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -302,7 +302,7 @@ fn run_test(test: Test) -> Result<()> { expected.compare(expr)?; } ImportFailure(expr, expected) => { - let err = expr.parse()?.resolve().unwrap_err(); + let err = expr.resolve().unwrap_err(); expected.compare_ui(err)?; } TypeInferenceSuccess(expr, expected) => { diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 1f7ecf8..103fdc3 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -238,7 +238,7 @@ pub mod ty { impl Type { pub(crate) fn to_dhall_value(&self) -> dhall::Value { - self.0.clone().into_normalized().to_value() + self.0.to_value() } pub(crate) fn from_simple_type(ty: SimpleType) -> Self { |