From 7848c8e8d3147ebe428290558aa6c0efcbf59ee5 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 18 Mar 2020 18:58:51 +0000 Subject: Brutally make all of dhall pub --- dhall/README.md | 9 ++++---- dhall/src/error/builder.rs | 2 +- dhall/src/error/mod.rs | 14 ++++++------ dhall/src/lib.rs | 30 ++++++++++++------------ dhall/src/semantics/builtins.rs | 6 ++--- dhall/src/semantics/mod.rs | 8 +++---- dhall/src/semantics/nze/env.rs | 6 ++--- dhall/src/semantics/nze/mod.rs | 8 +++---- dhall/src/semantics/nze/nir.rs | 42 +++++++++++++++++----------------- dhall/src/semantics/nze/normalize.rs | 10 ++++---- dhall/src/semantics/nze/var.rs | 4 ++-- dhall/src/semantics/parse.rs | 10 ++++---- dhall/src/semantics/resolve/env.rs | 8 +++---- dhall/src/semantics/resolve/hir.rs | 8 +++---- dhall/src/semantics/resolve/mod.rs | 6 ++--- dhall/src/semantics/resolve/resolve.rs | 10 ++++---- dhall/src/semantics/tck/env.rs | 4 ++-- dhall/src/semantics/tck/mod.rs | 6 ++--- dhall/src/semantics/tck/tir.rs | 6 ++--- dhall/src/semantics/tck/typecheck.rs | 10 ++++---- dhall/src/simple.rs | 8 +++---- dhall/src/syntax/ast/expr.rs | 10 ++++---- dhall/src/syntax/ast/mod.rs | 2 +- dhall/src/syntax/ast/span.rs | 12 +++++----- dhall/src/syntax/ast/visitor.rs | 2 +- dhall/src/syntax/binary/decode.rs | 2 +- dhall/src/syntax/binary/encode.rs | 2 +- dhall/src/syntax/binary/mod.rs | 4 ++-- 28 files changed, 125 insertions(+), 124 deletions(-) diff --git a/dhall/README.md b/dhall/README.md index 82b3e6a..25f11f7 100644 --- a/dhall/README.md +++ b/dhall/README.md @@ -1,10 +1,11 @@ # `dhall` Implementation of the Dhall configuration language. -This is an internal crate used for [`serde_dhall`], you probably want to use -that instead. -The API is very unstable and does not respect semver; -use at your own risk. +WARNING: This is an internal crate used for [`serde_dhall`], you probably want +to use that instead. + +WARNING: The API is very unstable and does not respect semver; use at your own +risk. [`serde_dhall`]: https://docs.rs/serde_dhall diff --git a/dhall/src/error/builder.rs b/dhall/src/error/builder.rs index c0bacb5..3ee65fb 100644 --- a/dhall/src/error/builder.rs +++ b/dhall/src/error/builder.rs @@ -6,7 +6,7 @@ use annotate_snippets::{ use crate::syntax::{ParsedSpan, Span}; #[derive(Debug, Clone, Default)] -pub(crate) struct ErrorBuilder { +pub struct ErrorBuilder { title: FreeAnnotation, annotations: Vec, footer: Vec, diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs index e28b98b..ef4d41f 100644 --- a/dhall/src/error/mod.rs +++ b/dhall/src/error/mod.rs @@ -4,7 +4,7 @@ use crate::semantics::resolve::{ImportLocation, ImportStack}; use crate::syntax::{Import, ParseError}; mod builder; -pub(crate) use builder::*; +pub use builder::*; pub type Result = std::result::Result; @@ -15,7 +15,7 @@ pub struct Error { #[derive(Debug)] #[non_exhaustive] -pub(crate) enum ErrorKind { +pub enum ErrorKind { IO(IOError), Parse(ParseError), Decode(DecodeError), @@ -25,7 +25,7 @@ pub(crate) enum ErrorKind { } #[derive(Debug)] -pub(crate) enum ImportError { +pub enum ImportError { Missing, MissingEnvVar, SanityCheck, @@ -53,21 +53,21 @@ pub struct TypeError { /// The specific type error #[derive(Debug)] -pub(crate) enum TypeMessage { +pub enum TypeMessage { Custom(String), } impl Error { - pub(crate) fn new(kind: ErrorKind) -> Self { + pub fn new(kind: ErrorKind) -> Self { Error { kind } } - pub(crate) fn kind(&self) -> &ErrorKind { + pub fn kind(&self) -> &ErrorKind { &self.kind } } impl TypeError { - pub(crate) fn new(message: TypeMessage) -> Self { + pub fn new(message: TypeMessage) -> Self { TypeError { message } } } diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index caaf260..34a9bac 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -26,17 +26,17 @@ use crate::syntax::Expr; pub use crate::simple::{STyKind, SValKind, SimpleType, SimpleValue}; #[derive(Debug, Clone)] -pub(crate) struct Parsed(Expr, ImportLocation); +pub struct Parsed(Expr, ImportLocation); /// An expression where all imports have been resolved /// /// Invariant: there must be no `Import` nodes or `ImportAlt` operations left. #[derive(Debug, Clone)] -pub(crate) struct Resolved(Hir); +pub struct Resolved(Hir); /// A typed expression #[derive(Debug, Clone)] -pub(crate) struct Typed { +pub struct Typed { hir: Hir, ty: Type, } @@ -45,23 +45,23 @@ pub(crate) struct Typed { /// /// This is actually a lie, because the expression will only get normalized on demand. #[derive(Debug, Clone)] -pub(crate) struct Normalized(Nir); +pub struct Normalized(Nir); /// A Dhall value. #[derive(Debug, Clone)] pub struct Value { /// Invariant: in normal form - pub(crate) hir: Hir, + pub hir: Hir, /// Cached conversions because they are annoying to construct from Hir. - pub(crate) as_simple_val: Option, - pub(crate) as_simple_ty: Option, + pub as_simple_val: Option, + pub as_simple_ty: Option, } /// Controls conversion from `Nir` to `Expr` #[derive(Copy, Clone, Default)] -pub(crate) struct ToExprOptions { +pub struct ToExprOptions { /// Whether to convert all variables to `_` - pub(crate) alpha: bool, + pub alpha: bool, } impl Parsed { @@ -96,7 +96,7 @@ impl Resolved { pub fn typecheck(&self) -> Result { Ok(Typed::from_tir(typecheck(&self.0)?)) } - pub(crate) fn typecheck_with(self, ty: &Hir) -> Result { + pub fn typecheck_with(self, ty: &Hir) -> Result { Ok(Typed::from_tir(typecheck_with(&self.0, ty)?)) } /// Converts a value back to the corresponding AST expression. @@ -122,10 +122,10 @@ impl Typed { self.hir.to_expr(ToExprOptions { alpha: false }) } - pub(crate) fn ty(&self) -> &Type { + pub fn ty(&self) -> &Type { &self.ty } - pub(crate) fn get_type(&self) -> Result { + pub fn get_type(&self) -> Result { Ok(Normalized(self.ty.clone().into_nir())) } } @@ -144,11 +144,11 @@ impl Normalized { self.0.to_expr(ToExprOptions::default()) } /// Converts a value back to the corresponding Hir expression. - pub(crate) fn to_hir(&self) -> Hir { + pub fn to_hir(&self) -> Hir { self.0.to_hir_noenv() } /// Converts a value back to the corresponding AST expression, alpha-normalizing in the process. - pub(crate) fn to_expr_alpha(&self) -> Expr { + pub fn to_expr_alpha(&self) -> Expr { self.0.to_expr(ToExprOptions { alpha: true }) } } @@ -178,7 +178,7 @@ impl Value { } /// Converts a value back to the corresponding AST expression. - pub(crate) fn to_expr(&self) -> Expr { + pub fn to_expr(&self) -> Expr { self.hir.to_expr(ToExprOptions::default()) } } diff --git a/dhall/src/semantics/builtins.rs b/dhall/src/semantics/builtins.rs index ef375b8..fa22bd0 100644 --- a/dhall/src/semantics/builtins.rs +++ b/dhall/src/semantics/builtins.rs @@ -14,7 +14,7 @@ use std::convert::TryInto; /// A partially applied builtin. /// Invariant: the evaluation of the given args must not be able to progress further #[derive(Debug, Clone)] -pub(crate) struct BuiltinClosure { +pub struct BuiltinClosure { env: NzEnv, b: Builtin, /// Arguments applied to the closure so far. @@ -43,7 +43,7 @@ impl BuiltinClosure { } } -pub(crate) fn rc(x: UnspannedExpr) -> Expr { +pub fn rc(x: UnspannedExpr) -> Expr { Expr::new(x, Span::Artificial) } @@ -103,7 +103,7 @@ macro_rules! make_type { }; } -pub(crate) fn type_of_builtin(b: Builtin) -> Hir { +pub fn type_of_builtin(b: Builtin) -> Hir { use Builtin::*; let expr = match b { Bool | Natural | Integer | Double | Text => make_type!(Type), diff --git a/dhall/src/semantics/mod.rs b/dhall/src/semantics/mod.rs index 87033c9..468d8b1 100644 --- a/dhall/src/semantics/mod.rs +++ b/dhall/src/semantics/mod.rs @@ -3,7 +3,7 @@ pub mod nze; pub mod parse; pub mod resolve; pub mod tck; -pub(crate) use self::builtins::*; -pub(crate) use self::nze::*; -pub(crate) use self::resolve::*; -pub(crate) use self::tck::*; +pub use self::builtins::*; +pub use self::nze::*; +pub use self::resolve::*; +pub use self::tck::*; diff --git a/dhall/src/semantics/nze/env.rs b/dhall/src/semantics/nze/env.rs index ef2bee6..ec99dbe 100644 --- a/dhall/src/semantics/nze/env.rs +++ b/dhall/src/semantics/nze/env.rs @@ -1,7 +1,7 @@ use crate::semantics::{AlphaVar, Nir, NirKind}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) enum NzVar { +pub enum NzVar { /// Reverse-debruijn index: counts number of binders from the bottom of the stack. Bound(usize), /// Fake fresh variable generated for expression equality checking. @@ -17,11 +17,11 @@ enum EnvItem { } #[derive(Debug, Clone)] -pub(crate) struct ValEnv { +pub struct ValEnv { items: Vec>, } -pub(crate) type NzEnv = ValEnv<()>; +pub type NzEnv = ValEnv<()>; impl NzVar { pub fn new(idx: usize) -> Self { diff --git a/dhall/src/semantics/nze/mod.rs b/dhall/src/semantics/nze/mod.rs index 2648339..23022e0 100644 --- a/dhall/src/semantics/nze/mod.rs +++ b/dhall/src/semantics/nze/mod.rs @@ -3,7 +3,7 @@ pub mod lazy; pub mod nir; pub mod normalize; pub mod var; -pub(crate) use env::*; -pub(crate) use nir::*; -pub(crate) use normalize::*; -pub(crate) use var::*; +pub use env::*; +pub use nir::*; +pub use normalize::*; +pub use var::*; diff --git a/dhall/src/semantics/nze/nir.rs b/dhall/src/semantics/nze/nir.rs index 5fccbf1..e0d227e 100644 --- a/dhall/src/semantics/nze/nir.rs +++ b/dhall/src/semantics/nze/nir.rs @@ -19,7 +19,7 @@ use crate::ToExprOptions; /// normalize as needed. /// Stands for "Normalized intermediate representation" #[derive(Clone)] -pub(crate) struct Nir(Rc); +pub struct Nir(Rc); #[derive(Debug)] struct NirInternal { @@ -28,7 +28,7 @@ struct NirInternal { /// An unevaluated subexpression #[derive(Debug, Clone)] -pub(crate) enum Thunk { +pub enum Thunk { /// A completely unnormalized expression. Thunk { env: NzEnv, body: Hir }, /// A partially normalized expression that may need to go through `normalize_one_layer`. @@ -37,7 +37,7 @@ pub(crate) enum Thunk { /// An unevaluated subexpression that takes an argument. #[derive(Debug, Clone)] -pub(crate) enum Closure { +pub enum Closure { /// Normal closure Closure { env: NzEnv, body: Hir }, /// Closure that ignores the argument passed @@ -48,7 +48,7 @@ pub(crate) enum Closure { // Invariant: this must not contain interpolations that are themselves TextLits, and contiguous // text values must be merged. #[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) struct TextLit(Vec>); +pub struct TextLit(Vec>); /// This represents a value in Weak Head Normal Form (WHNF). This means that the value is /// normalized up to the first constructor, but subexpressions may not be fully normalized. @@ -58,7 +58,7 @@ pub(crate) struct TextLit(Vec>); /// In particular, this means that once we get a `NirKind`, it can be considered immutable, and /// we only need to recursively normalize its sub-`Nir`s to get to the NF. #[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) enum NirKind { +pub enum NirKind { /// Closures LamClosure { binder: Binder, @@ -97,34 +97,34 @@ pub(crate) enum NirKind { impl Nir { /// Construct a Nir from a completely unnormalized expression. - pub(crate) fn new_thunk(env: NzEnv, hir: Hir) -> Nir { + pub fn new_thunk(env: NzEnv, hir: Hir) -> Nir { NirInternal::from_thunk(Thunk::new(env, hir)).into_nir() } /// Construct a Nir from a partially normalized expression that's not in WHNF. - pub(crate) fn from_partial_expr(e: ExprKind) -> Nir { + pub fn from_partial_expr(e: ExprKind) -> Nir { // TODO: env let env = NzEnv::new(); NirInternal::from_thunk(Thunk::from_partial_expr(env, e)).into_nir() } /// Make a Nir from a NirKind - pub(crate) fn from_kind(v: NirKind) -> Nir { + pub fn from_kind(v: NirKind) -> Nir { NirInternal::from_whnf(v).into_nir() } - pub(crate) fn from_const(c: Const) -> Self { + pub fn from_const(c: Const) -> Self { let v = NirKind::Const(c); NirInternal::from_whnf(v).into_nir() } - pub(crate) fn from_builtin(b: Builtin) -> Self { + pub fn from_builtin(b: Builtin) -> Self { Self::from_builtin_env(b, &NzEnv::new()) } - pub(crate) fn from_builtin_env(b: Builtin, env: &NzEnv) -> Self { + pub fn from_builtin_env(b: Builtin, env: &NzEnv) -> Self { Nir::from_kind(NirKind::from_builtin_env(b, env.clone())) } - pub(crate) fn from_text(txt: impl ToString) -> Self { + pub fn from_text(txt: impl ToString) -> Self { Nir::from_kind(NirKind::TextLit(TextLit::from_text(txt.to_string()))) } - pub(crate) fn as_const(&self) -> Option { + pub fn as_const(&self) -> Option { match &*self.kind() { NirKind::Const(c) => Some(*c), _ => None, @@ -132,22 +132,22 @@ impl Nir { } /// This is what you want if you want to pattern-match on the value. - pub(crate) fn kind(&self) -> &NirKind { + pub fn kind(&self) -> &NirKind { self.0.kind() } - pub(crate) fn to_type(&self, u: impl Into) -> Type { + pub fn to_type(&self, u: impl Into) -> Type { Type::new(self.clone(), u.into()) } /// Converts a value back to the corresponding AST expression. - pub(crate) fn to_expr(&self, opts: ToExprOptions) -> Expr { + pub fn to_expr(&self, opts: ToExprOptions) -> Expr { self.to_hir_noenv().to_expr(opts) } - pub(crate) fn to_expr_tyenv(&self, tyenv: &TyEnv) -> Expr { + pub fn to_expr_tyenv(&self, tyenv: &TyEnv) -> Expr { self.to_hir(tyenv.as_varenv()).to_expr_tyenv(tyenv) } - pub(crate) fn app(&self, v: Nir) -> Nir { + pub fn app(&self, v: Nir) -> Nir { Nir::from_kind(apply_any(self.clone(), v)) } @@ -286,14 +286,14 @@ impl NirInternal { } impl NirKind { - pub(crate) fn into_nir(self) -> Nir { + pub fn into_nir(self) -> Nir { Nir::from_kind(self) } - pub(crate) fn from_builtin(b: Builtin) -> NirKind { + pub fn from_builtin(b: Builtin) -> NirKind { NirKind::from_builtin_env(b, NzEnv::new()) } - pub(crate) fn from_builtin_env(b: Builtin, env: NzEnv) -> NirKind { + pub fn from_builtin_env(b: Builtin, env: NzEnv) -> NirKind { BuiltinClosure::new(b, env) } } diff --git a/dhall/src/semantics/nze/normalize.rs b/dhall/src/semantics/nze/normalize.rs index 46d8fb5..570e106 100644 --- a/dhall/src/semantics/nze/normalize.rs +++ b/dhall/src/semantics/nze/normalize.rs @@ -5,7 +5,7 @@ use crate::semantics::NzEnv; use crate::semantics::{Binder, Closure, Hir, HirKind, Nir, NirKind, TextLit}; use crate::syntax::{BinOp, ExprKind, InterpolatedTextContents, NumKind}; -pub(crate) fn apply_any(f: Nir, a: Nir) -> NirKind { +pub fn apply_any(f: Nir, a: Nir) -> NirKind { match f.kind() { NirKind::LamClosure { closure, .. } => closure.apply(a).kind().clone(), NirKind::AppliedBuiltin(closure) => closure.apply(a), @@ -16,7 +16,7 @@ pub(crate) fn apply_any(f: Nir, a: Nir) -> NirKind { } } -pub(crate) fn squash_textlit( +pub fn squash_textlit( elts: impl Iterator>, ) -> Vec> { use std::mem::replace; @@ -54,7 +54,7 @@ pub(crate) fn squash_textlit( ret } -pub(crate) fn merge_maps( +pub fn merge_maps( map1: &HashMap, map2: &HashMap, mut f: F, @@ -207,7 +207,7 @@ fn apply_binop<'a>(o: BinOp, x: &'a Nir, y: &'a Nir) -> Option> { } #[allow(clippy::cognitive_complexity)] -pub(crate) fn normalize_one_layer(expr: ExprKind, env: &NzEnv) -> NirKind { +pub fn normalize_one_layer(expr: ExprKind, env: &NzEnv) -> NirKind { use NirKind::{ EmptyListLit, EmptyOptionalLit, NEListLit, NEOptionalLit, Num, PartialExpr, RecordLit, RecordType, UnionConstructor, UnionLit, @@ -464,7 +464,7 @@ pub(crate) fn normalize_one_layer(expr: ExprKind, env: &NzEnv) -> NirKind { } /// Normalize Hir into WHNF -pub(crate) fn normalize_hir_whnf(env: &NzEnv, hir: &Hir) -> NirKind { +pub fn normalize_hir_whnf(env: &NzEnv, hir: &Hir) -> NirKind { match hir.kind() { HirKind::Var(var) => env.lookup_val(*var), HirKind::Import(hir, _) => normalize_hir_whnf(env, hir), diff --git a/dhall/src/semantics/nze/var.rs b/dhall/src/semantics/nze/var.rs index 413c759..302dbb7 100644 --- a/dhall/src/semantics/nze/var.rs +++ b/dhall/src/semantics/nze/var.rs @@ -8,10 +8,10 @@ pub struct Binder { } impl Binder { - pub(crate) fn new(name: Label) -> Self { + pub fn new(name: Label) -> Self { Binder { name } } - pub(crate) fn to_label(&self) -> Label { + pub fn to_label(&self) -> Label { self.clone().into() } } diff --git a/dhall/src/semantics/parse.rs b/dhall/src/semantics/parse.rs index 45860d0..2326471 100644 --- a/dhall/src/semantics/parse.rs +++ b/dhall/src/semantics/parse.rs @@ -9,33 +9,33 @@ use crate::syntax::binary; use crate::syntax::parse_expr; use crate::Parsed; -pub(crate) fn parse_file(f: &Path) -> Result { +pub fn parse_file(f: &Path) -> Result { let text = std::fs::read_to_string(f)?; let expr = parse_expr(&text)?; let root = ImportLocation::Local(f.to_owned()); Ok(Parsed(expr, root)) } -pub(crate) fn parse_remote(url: Url) -> Result { +pub fn parse_remote(url: Url) -> Result { let body = reqwest::blocking::get(url.clone()).unwrap().text().unwrap(); let expr = parse_expr(&body)?; let root = ImportLocation::Remote(url); 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 = ImportLocation::Missing; Ok(Parsed(expr, root)) } -pub(crate) fn parse_binary(data: &[u8]) -> Result { +pub fn parse_binary(data: &[u8]) -> Result { let expr = binary::decode(data)?; let root = ImportLocation::Missing; 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 = binary::decode(&buffer)?; diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs index fe8c178..d5bb15b 100644 --- a/dhall/src/semantics/resolve/env.rs +++ b/dhall/src/semantics/resolve/env.rs @@ -6,16 +6,16 @@ use crate::syntax::{Label, V}; /// Environment for resolving names. #[derive(Debug, Clone)] -pub(crate) struct NameEnv { +pub struct NameEnv { names: Vec