diff options
author | Nadrieril | 2019-05-09 23:18:55 +0200 |
---|---|---|
committer | Nadrieril | 2019-05-09 23:23:49 +0200 |
commit | 33c1aa4bd1d5b83361eb52d00beb8d8c762225cd (patch) | |
tree | 1219c3305d9b113b10308bb30dc257acc06bc105 /dhall/src/phase | |
parent | 7ac061b5ddf15ffe3fc4f36b64138b7431429758 (diff) |
Make visibilities more consistent
Diffstat (limited to 'dhall/src/phase')
-rw-r--r-- | dhall/src/phase/mod.rs | 64 | ||||
-rw-r--r-- | dhall/src/phase/normalize.rs | 17 | ||||
-rw-r--r-- | dhall/src/phase/parse.rs | 6 | ||||
-rw-r--r-- | dhall/src/phase/resolve.rs | 6 | ||||
-rw-r--r-- | dhall/src/phase/typecheck.rs | 15 |
5 files changed, 51 insertions, 57 deletions
diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index d7cec67..abf4fe7 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -19,20 +19,20 @@ pub(crate) mod parse; pub(crate) mod resolve; pub(crate) mod typecheck; -pub(crate) type ParsedSubExpr = SubExpr<Span, Import>; -pub(crate) type ResolvedSubExpr = SubExpr<Span, Normalized>; -pub(crate) type NormalizedSubExpr = SubExpr<X, X>; +pub type ParsedSubExpr = SubExpr<Span, Import>; +pub type ResolvedSubExpr = SubExpr<Span, Normalized>; +pub type NormalizedSubExpr = SubExpr<X, X>; #[derive(Debug, Clone)] -pub(crate) struct Parsed(pub(crate) ParsedSubExpr, pub(crate) ImportRoot); +pub struct Parsed(ParsedSubExpr, ImportRoot); /// An expression where all imports have been resolved #[derive(Debug, Clone)] -pub(crate) struct Resolved(pub(crate) ResolvedSubExpr); +pub struct Resolved(ResolvedSubExpr); /// A typed expression #[derive(Debug, Clone)] -pub(crate) enum Typed { +pub enum Typed { // Any value, along with (optionally) its type Untyped(Thunk), Typed(Thunk, Box<Type>), @@ -47,10 +47,10 @@ pub(crate) enum Typed { /// /// Invariant: the contained Typed expression must be in normal form, #[derive(Debug, Clone)] -pub(crate) struct Normalized(pub(crate) Typed); +pub struct Normalized(Typed); #[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) struct Type(pub(crate) Typed); +pub struct Type(Typed); impl Parsed { pub fn parse_file(f: &Path) -> Result<Parsed, Error> { @@ -109,57 +109,57 @@ impl Typed { Normalized(self) } - pub(crate) fn from_thunk_and_type(th: Thunk, t: Type) -> Self { + pub fn from_thunk_and_type(th: Thunk, t: Type) -> Self { Typed::Typed(th, Box::new(t)) } - pub(crate) fn from_thunk_untyped(th: Thunk) -> Self { + pub fn from_thunk_untyped(th: Thunk) -> Self { Typed::Untyped(th) } - pub(crate) fn from_const(c: Const) -> Self { + pub fn from_const(c: Const) -> Self { Typed::Const(c) } - pub(crate) fn from_value_untyped(v: Value) -> Self { + pub fn from_value_untyped(v: Value) -> Self { Typed::Untyped(Thunk::from_value(v)) } - pub(crate) fn from_normalized_expr_untyped(e: NormalizedSubExpr) -> Self { + pub fn from_normalized_expr_untyped(e: NormalizedSubExpr) -> Self { Typed::from_thunk_untyped(Thunk::from_normalized_expr(e)) } // TODO: Avoid cloning if possible - pub(crate) fn to_value(&self) -> Value { + pub fn to_value(&self) -> Value { match self { Typed::Untyped(th) | Typed::Typed(th, _) => th.to_value(), Typed::Const(c) => Value::Const(*c), } } - pub(crate) fn to_expr(&self) -> NormalizedSubExpr { + pub fn to_expr(&self) -> NormalizedSubExpr { self.to_value().normalize_to_expr() } - pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub fn to_expr_alpha(&self) -> NormalizedSubExpr { self.to_value().normalize_to_expr_maybe_alpha(true) } - pub(crate) fn to_thunk(&self) -> Thunk { + 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)), } } // Deprecated - pub(crate) fn to_type(&self) -> Type { + pub fn to_type(&self) -> Type { self.clone().into_type() } - pub(crate) fn into_type(self) -> Type { + pub fn into_type(self) -> Type { Type(self) } - pub(crate) fn normalize_mut(&mut self) { + pub fn normalize_mut(&mut self) { match self { Typed::Untyped(th) | Typed::Typed(th, _) => th.normalize_mut(), Typed::Const(_) => {} } } - pub(crate) fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { + pub fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { match self { Typed::Untyped(_) => Err(TypeError::new( &TypecheckContext::new(), @@ -173,46 +173,46 @@ impl Typed { impl Type { // Deprecated - pub(crate) fn to_normalized(&self) -> Normalized { + pub fn to_normalized(&self) -> Normalized { self.0.clone().normalize() } - pub(crate) fn to_expr(&self) -> NormalizedSubExpr { + pub fn to_expr(&self) -> NormalizedSubExpr { self.0.to_expr() } - pub(crate) fn to_value(&self) -> Value { + pub fn to_value(&self) -> Value { self.0.to_value() } - pub(crate) fn to_typed(&self) -> Typed { + pub fn to_typed(&self) -> Typed { self.0.clone() } - pub(crate) fn as_const(&self) -> Option<Const> { + pub fn as_const(&self) -> Option<Const> { // TODO: avoid clone match &self.to_value() { Value::Const(c) => Some(*c), _ => None, } } - pub(crate) fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { + pub fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { self.0.get_type() } - pub(crate) fn from_const(c: Const) -> Self { + pub fn from_const(c: Const) -> Self { Type(Typed::from_const(c)) } } impl Normalized { #[allow(dead_code)] - pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub fn to_expr_alpha(&self) -> NormalizedSubExpr { self.0.to_expr_alpha() } - pub(crate) fn to_value(&self) -> Value { + pub fn to_value(&self) -> Value { self.0.to_value() } - pub(crate) fn into_typed(self) -> Typed { + pub fn into_typed(self) -> Typed { self.0 } - pub(crate) fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { + pub fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { self.0.get_type() } } diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index 64de2a7..2253ae0 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -11,10 +11,10 @@ use crate::core::value::Value; use crate::core::var::Subst; use crate::phase::{NormalizedSubExpr, ResolvedSubExpr, Typed}; -pub(crate) type InputSubExpr = ResolvedSubExpr; -pub(crate) type OutputSubExpr = NormalizedSubExpr; +pub type InputSubExpr = ResolvedSubExpr; +pub type OutputSubExpr = NormalizedSubExpr; -pub(crate) fn apply_builtin(b: Builtin, args: Vec<Thunk>) -> Value { +pub fn apply_builtin(b: Builtin, args: Vec<Thunk>) -> Value { use dhall_syntax::Builtin::*; use Value::*; @@ -246,7 +246,7 @@ pub(crate) fn apply_builtin(b: Builtin, args: Vec<Thunk>) -> Value { } } -pub(crate) fn apply_any(f: Thunk, a: Thunk) -> Value { +pub fn apply_any(f: Thunk, a: Thunk) -> Value { let fallback = |f: Thunk, a: Thunk| Value::PartialExpr(ExprF::App(f, a)); let f_borrow = f.as_value(); @@ -302,7 +302,7 @@ pub(crate) fn apply_any(f: Thunk, a: Thunk) -> Value { } } -pub(crate) fn squash_textlit( +pub fn squash_textlit( elts: impl Iterator<Item = InterpolatedTextContents<Thunk>>, ) -> Vec<InterpolatedTextContents<Thunk>> { use std::mem::replace; @@ -345,10 +345,7 @@ pub(crate) fn squash_textlit( } /// Reduces the imput expression to a Value. Evaluates as little as possible. -pub(crate) fn normalize_whnf( - ctx: NormalizationContext, - expr: InputSubExpr, -) -> Value { +pub fn normalize_whnf(ctx: NormalizationContext, expr: InputSubExpr) -> Value { match expr.as_ref() { ExprF::Embed(e) => return e.to_value(), ExprF::Var(v) => return ctx.lookup(v), @@ -520,7 +517,7 @@ fn apply_binop<'a>(o: BinOp, x: &'a Thunk, y: &'a Thunk) -> Option<Ret<'a>> { }) } -pub(crate) fn normalize_one_layer(expr: ExprF<Thunk, X>) -> Value { +pub fn normalize_one_layer(expr: ExprF<Thunk, X>) -> Value { use Ret::{RetExpr, RetThunk, RetThunkRef, RetValue}; use Value::{ BoolLit, DoubleLit, EmptyListLit, EmptyOptionalLit, IntegerLit, Lam, diff --git a/dhall/src/phase/parse.rs b/dhall/src/phase/parse.rs index d5cb9f5..765fc09 100644 --- a/dhall/src/phase/parse.rs +++ b/dhall/src/phase/parse.rs @@ -8,7 +8,7 @@ use crate::error::Error; use crate::phase::resolve::ImportRoot; use crate::phase::Parsed; -pub(crate) fn parse_file(f: &Path) -> Result<Parsed, Error> { +pub fn parse_file(f: &Path) -> Result<Parsed, Error> { let mut buffer = String::new(); File::open(f)?.read_to_string(&mut buffer)?; let expr = parse_expr(&*buffer)?; @@ -16,13 +16,13 @@ pub(crate) fn parse_file(f: &Path) -> Result<Parsed, Error> { Ok(Parsed(expr, root)) } -pub(crate) fn parse_str(s: &str) -> Result<Parsed, Error> { +pub fn parse_str(s: &str) -> Result<Parsed, Error> { let expr = parse_expr(s)?; let root = ImportRoot::LocalDir(std::env::current_dir()?); Ok(Parsed(expr, root)) } -pub(crate) fn parse_binary_file(f: &Path) -> Result<Parsed, Error> { +pub fn parse_binary_file(f: &Path) -> Result<Parsed, Error> { let mut buffer = Vec::new(); File::open(f)?.read_to_end(&mut buffer)?; let expr = crate::phase::binary::decode(&buffer)?; diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index 5ab03ac..7e446eb 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -14,7 +14,7 @@ pub enum ImportRoot { type ImportCache = HashMap<Import, Normalized>; -pub(crate) type ImportStack = Vec<Import>; +pub type ImportStack = Vec<Import>; fn resolve_import( import: &Import, @@ -89,11 +89,11 @@ fn do_resolve_expr( Ok(Resolved(expr)) } -pub(crate) fn resolve(e: Parsed) -> Result<Resolved, ImportError> { +pub fn resolve(e: Parsed) -> Result<Resolved, ImportError> { do_resolve_expr(e, &mut HashMap::new(), &Vec::new()) } -pub(crate) fn skip_resolve_expr( +pub fn skip_resolve_expr( Parsed(expr, _root): Parsed, ) -> Result<Resolved, ImportError> { let resolve = |import: &Import| -> Result<Normalized, ImportError> { diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index 7f988c8..c2d9da3 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -218,7 +218,7 @@ where eL0.borrow().to_value() == eR0.borrow().to_value() } -pub(crate) fn type_of_const(c: Const) -> Result<Type, TypeError> { +pub fn type_of_const(c: Const) -> Result<Type, TypeError> { match c { Const::Type => Ok(Type::from_const(Const::Kind)), Const::Kind => Ok(Type::from_const(Const::Sort)), @@ -317,14 +317,14 @@ fn type_of_builtin(b: Builtin) -> Expr<X, X> { /// Takes an expression that is meant to contain a Type /// and turn it into a type, typechecking it along the way. -pub(crate) fn mktype( +pub fn mktype( ctx: &TypecheckContext, e: SubExpr<Span, Normalized>, ) -> Result<Type, TypeError> { Ok(type_with(ctx, e)?.to_type()) } -pub(crate) fn builtin_to_type(b: Builtin) -> Result<Type, TypeError> { +pub fn builtin_to_type(b: Builtin) -> Result<Type, TypeError> { mktype(&TypecheckContext::new(), SubExpr::from_builtin(b)) } @@ -777,19 +777,16 @@ fn type_of(e: SubExpr<Span, Normalized>) -> Result<Typed, TypeError> { Ok(e) } -pub(crate) fn typecheck(e: Resolved) -> Result<Typed, TypeError> { +pub fn typecheck(e: Resolved) -> Result<Typed, TypeError> { type_of(e.0) } -pub(crate) fn typecheck_with( - e: Resolved, - ty: &Type, -) -> Result<Typed, TypeError> { +pub fn typecheck_with(e: Resolved, ty: &Type) -> Result<Typed, TypeError> { let expr: SubExpr<_, _> = e.0; let ty: SubExpr<_, _> = ty.to_expr().absurd(); type_of(expr.rewrap(ExprF::Annot(expr.clone(), ty))) } -pub(crate) fn skip_typecheck(e: Resolved) -> Typed { +pub fn skip_typecheck(e: Resolved) -> Typed { Typed::from_thunk_untyped(Thunk::new(NormalizationContext::new(), e.0)) } |