From 33c1aa4bd1d5b83361eb52d00beb8d8c762225cd Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 9 May 2019 23:18:55 +0200 Subject: Make visibilities more consistent --- dhall/src/phase/mod.rs | 64 ++++++++++++++++++++++---------------------- dhall/src/phase/normalize.rs | 17 +++++------- dhall/src/phase/parse.rs | 6 ++--- dhall/src/phase/resolve.rs | 6 ++--- dhall/src/phase/typecheck.rs | 15 +++++------ 5 files changed, 51 insertions(+), 57 deletions(-) (limited to 'dhall/src/phase') 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; -pub(crate) type ResolvedSubExpr = SubExpr; -pub(crate) type NormalizedSubExpr = SubExpr; +pub type ParsedSubExpr = SubExpr; +pub type ResolvedSubExpr = SubExpr; +pub type NormalizedSubExpr = SubExpr; #[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), @@ -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 { @@ -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, TypeError> { + pub fn get_type(&self) -> Result, 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 { + pub fn as_const(&self) -> Option { // TODO: avoid clone match &self.to_value() { Value::Const(c) => Some(*c), _ => None, } } - pub(crate) fn get_type(&self) -> Result, TypeError> { + pub fn get_type(&self) -> Result, 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, TypeError> { + pub fn get_type(&self) -> Result, 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) -> Value { +pub fn apply_builtin(b: Builtin, args: Vec) -> Value { use dhall_syntax::Builtin::*; use Value::*; @@ -246,7 +246,7 @@ pub(crate) fn apply_builtin(b: Builtin, args: Vec) -> 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>, ) -> Vec> { 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> { }) } -pub(crate) fn normalize_one_layer(expr: ExprF) -> Value { +pub fn normalize_one_layer(expr: ExprF) -> 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 { +pub fn parse_file(f: &Path) -> Result { 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 { Ok(Parsed(expr, root)) } -pub(crate) fn parse_str(s: &str) -> Result { +pub fn parse_str(s: &str) -> Result { 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 { +pub fn parse_binary_file(f: &Path) -> Result { 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; -pub(crate) type ImportStack = Vec; +pub type ImportStack = Vec; fn resolve_import( import: &Import, @@ -89,11 +89,11 @@ fn do_resolve_expr( Ok(Resolved(expr)) } -pub(crate) fn resolve(e: Parsed) -> Result { +pub fn resolve(e: Parsed) -> Result { 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 { let resolve = |import: &Import| -> Result { 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 { +pub fn type_of_const(c: Const) -> Result { 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 { /// 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, ) -> Result { Ok(type_with(ctx, e)?.to_type()) } -pub(crate) fn builtin_to_type(b: Builtin) -> Result { +pub fn builtin_to_type(b: Builtin) -> Result { mktype(&TypecheckContext::new(), SubExpr::from_builtin(b)) } @@ -777,19 +777,16 @@ fn type_of(e: SubExpr) -> Result { Ok(e) } -pub(crate) fn typecheck(e: Resolved) -> Result { +pub fn typecheck(e: Resolved) -> Result { type_of(e.0) } -pub(crate) fn typecheck_with( - e: Resolved, - ty: &Type, -) -> Result { +pub fn typecheck_with(e: Resolved, ty: &Type) -> Result { 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)) } -- cgit v1.2.3