diff options
Diffstat (limited to 'dhall/src/semantics')
-rw-r--r-- | dhall/src/semantics/builtins.rs | 6 | ||||
-rw-r--r-- | dhall/src/semantics/mod.rs | 8 | ||||
-rw-r--r-- | dhall/src/semantics/nze/env.rs | 6 | ||||
-rw-r--r-- | dhall/src/semantics/nze/mod.rs | 8 | ||||
-rw-r--r-- | dhall/src/semantics/nze/nir.rs | 42 | ||||
-rw-r--r-- | dhall/src/semantics/nze/normalize.rs | 10 | ||||
-rw-r--r-- | dhall/src/semantics/nze/var.rs | 4 | ||||
-rw-r--r-- | dhall/src/semantics/parse.rs | 10 | ||||
-rw-r--r-- | dhall/src/semantics/resolve/env.rs | 8 | ||||
-rw-r--r-- | dhall/src/semantics/resolve/hir.rs | 8 | ||||
-rw-r--r-- | dhall/src/semantics/resolve/mod.rs | 6 | ||||
-rw-r--r-- | dhall/src/semantics/resolve/resolve.rs | 10 | ||||
-rw-r--r-- | dhall/src/semantics/tck/env.rs | 4 | ||||
-rw-r--r-- | dhall/src/semantics/tck/mod.rs | 6 | ||||
-rw-r--r-- | dhall/src/semantics/tck/tir.rs | 6 | ||||
-rw-r--r-- | dhall/src/semantics/tck/typecheck.rs | 10 |
16 files changed, 76 insertions, 76 deletions
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<Type> { } #[derive(Debug, Clone)] -pub(crate) struct ValEnv<Type> { +pub struct ValEnv<Type> { items: Vec<EnvItem<Type>>, } -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<NirInternal>); +pub struct Nir(Rc<NirInternal>); #[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<InterpolatedTextContents<Nir>>); +pub struct TextLit(Vec<InterpolatedTextContents<Nir>>); /// 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<InterpolatedTextContents<Nir>>); /// 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>) -> Nir { + pub fn from_partial_expr(e: ExprKind<Nir>) -> 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<Const> { + pub fn as_const(&self) -> Option<Const> { 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<Universe>) -> Type { + pub fn to_type(&self, u: impl Into<Universe>) -> 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<Item = InterpolatedTextContents<Nir>>, ) -> Vec<InterpolatedTextContents<Nir>> { use std::mem::replace; @@ -54,7 +54,7 @@ pub(crate) fn squash_textlit( ret } -pub(crate) fn merge_maps<K, V, F>( +pub fn merge_maps<K, V, F>( map1: &HashMap<K, V>, map2: &HashMap<K, V>, mut f: F, @@ -207,7 +207,7 @@ fn apply_binop<'a>(o: BinOp, x: &'a Nir, y: &'a Nir) -> Option<Ret<'a>> { } #[allow(clippy::cognitive_complexity)] -pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind { +pub fn normalize_one_layer(expr: ExprKind<Nir>, 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<Nir>, 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<Parsed, Error> { +pub fn parse_file(f: &Path) -> Result<Parsed, Error> { 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<Parsed, Error> { +pub fn parse_remote(url: Url) -> Result<Parsed, Error> { 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<Parsed, Error> { +pub fn parse_str(s: &str) -> Result<Parsed, Error> { let expr = parse_expr(s)?; let root = ImportLocation::Missing; Ok(Parsed(expr, root)) } -pub(crate) fn parse_binary(data: &[u8]) -> Result<Parsed, Error> { +pub fn parse_binary(data: &[u8]) -> Result<Parsed, Error> { let expr = binary::decode(data)?; let root = ImportLocation::Missing; 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 = 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<Label>, } -pub(crate) type ImportCache = HashMap<ImportLocation, TypedHir>; -pub(crate) type ImportStack = Vec<ImportLocation>; +pub type ImportCache = HashMap<ImportLocation, TypedHir>; +pub type ImportStack = Vec<ImportLocation>; /// Environment for resolving imports #[derive(Debug, Clone)] -pub(crate) struct ImportEnv { +pub struct ImportEnv { cache: ImportCache, stack: ImportStack, } diff --git a/dhall/src/semantics/resolve/hir.rs b/dhall/src/semantics/resolve/hir.rs index 3934bbb..9256425 100644 --- a/dhall/src/semantics/resolve/hir.rs +++ b/dhall/src/semantics/resolve/hir.rs @@ -10,7 +10,7 @@ pub struct AlphaVar { } #[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) enum HirKind { +pub enum HirKind { /// A resolved variable (i.e. a DeBruijn index) Var(AlphaVar), /// Result of resolving an import. @@ -21,16 +21,16 @@ pub(crate) enum HirKind { // An expression with resolved variables and imports. #[derive(Debug, Clone)] -pub(crate) struct Hir { +pub struct Hir { kind: Box<HirKind>, span: Span, } impl AlphaVar { - pub(crate) fn new(idx: usize) -> Self { + pub fn new(idx: usize) -> Self { AlphaVar { idx } } - pub(crate) fn idx(self) -> usize { + pub fn idx(self) -> usize { self.idx } } diff --git a/dhall/src/semantics/resolve/mod.rs b/dhall/src/semantics/resolve/mod.rs index 517907b..33b477e 100644 --- a/dhall/src/semantics/resolve/mod.rs +++ b/dhall/src/semantics/resolve/mod.rs @@ -1,6 +1,6 @@ pub mod env; pub mod hir; pub mod resolve; -pub(crate) use env::*; -pub(crate) use hir::*; -pub(crate) use resolve::*; +pub use env::*; +pub use hir::*; +pub use resolve::*; diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs index eb2f04f..07bd06c 100644 --- a/dhall/src/semantics/resolve/resolve.rs +++ b/dhall/src/semantics/resolve/resolve.rs @@ -16,14 +16,14 @@ use crate::syntax::{ use crate::{Parsed, Resolved}; // TODO: evaluate import headers -pub(crate) type Import = syntax::Import<()>; +pub type Import = syntax::Import<()>; /// Owned Hir with a type. Different from Tir because the Hir is owned. -pub(crate) type TypedHir = (Hir, Type); +pub type TypedHir = (Hir, Type); /// The location of some data, usually some dhall code. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub(crate) enum ImportLocation { +pub enum ImportLocation { /// Local file Local(PathBuf), /// Remote file @@ -329,11 +329,11 @@ fn resolve_with_env( Ok(Resolved(resolved)) } -pub(crate) fn resolve(parsed: Parsed) -> Result<Resolved, Error> { +pub fn resolve(parsed: Parsed) -> Result<Resolved, Error> { resolve_with_env(&mut ImportEnv::new(), parsed) } -pub(crate) fn skip_resolve(expr: &Expr) -> Result<Hir, Error> { +pub fn skip_resolve(expr: &Expr) -> Result<Hir, Error> { traverse_resolve_expr(&mut NameEnv::new(), expr, &mut |import| { Err(ImportError::UnexpectedImport(import).into()) }) diff --git a/dhall/src/semantics/tck/env.rs b/dhall/src/semantics/tck/env.rs index 6dd5076..f2ef00a 100644 --- a/dhall/src/semantics/tck/env.rs +++ b/dhall/src/semantics/tck/env.rs @@ -3,13 +3,13 @@ use crate::syntax::Label; /// Environment for indexing variables. #[derive(Debug, Clone, Copy)] -pub(crate) struct VarEnv { +pub struct VarEnv { size: usize, } /// Environment for typing expressions. #[derive(Debug, Clone)] -pub(crate) struct TyEnv { +pub struct TyEnv { names: NameEnv, items: ValEnv<Type>, } diff --git a/dhall/src/semantics/tck/mod.rs b/dhall/src/semantics/tck/mod.rs index 93c8f48..6dddfc5 100644 --- a/dhall/src/semantics/tck/mod.rs +++ b/dhall/src/semantics/tck/mod.rs @@ -1,6 +1,6 @@ pub mod env; pub mod tir; pub mod typecheck; -pub(crate) use env::*; -pub(crate) use tir::*; -pub(crate) use typecheck::*; +pub use env::*; +pub use tir::*; +pub use typecheck::*; diff --git a/dhall/src/semantics/tck/tir.rs b/dhall/src/semantics/tck/tir.rs index 1865b8e..89a8027 100644 --- a/dhall/src/semantics/tck/tir.rs +++ b/dhall/src/semantics/tck/tir.rs @@ -4,11 +4,11 @@ use crate::syntax::{Builtin, Const, Expr, Span}; /// The type of a type. 0 is `Type`, 1 is `Kind`, etc... #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)] -pub(crate) struct Universe(u8); +pub struct Universe(u8); /// An expression representing a type #[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) struct Type { +pub struct Type { val: Nir, univ: Universe, } @@ -16,7 +16,7 @@ pub(crate) struct Type { /// A hir expression plus its inferred type. /// Stands for "Typed intermediate representation" #[derive(Debug, Clone)] -pub(crate) struct Tir<'hir> { +pub struct Tir<'hir> { hir: &'hir Hir, ty: Type, } diff --git a/dhall/src/semantics/tck/typecheck.rs b/dhall/src/semantics/tck/typecheck.rs index 880ab22..205185f 100644 --- a/dhall/src/semantics/tck/typecheck.rs +++ b/dhall/src/semantics/tck/typecheck.rs @@ -53,11 +53,11 @@ fn function_check(a: Const, b: Const) -> Const { } } -pub(crate) fn mkerr<T, S: ToString>(msg: S) -> Result<T, TypeError> { +pub fn mkerr<T, S: ToString>(msg: S) -> Result<T, TypeError> { Err(TypeError::new(TypeMessage::Custom(msg.to_string()))) } -pub(crate) fn mk_span_err<T, S: ToString>( +pub fn mk_span_err<T, S: ToString>( span: Span, msg: S, ) -> Result<T, TypeError> { @@ -688,7 +688,7 @@ fn type_one_layer( /// `type_with` typechecks an expression in the provided environment. Optionally pass an annotation /// to compare with. -pub(crate) fn type_with<'hir>( +pub fn type_with<'hir>( env: &TyEnv, hir: &'hir Hir, annot: Option<Type>, @@ -785,12 +785,12 @@ pub(crate) fn type_with<'hir>( /// Typecheck an expression and return the expression annotated with types if type-checking /// succeeded, or an error if type-checking failed. -pub(crate) fn typecheck<'hir>(hir: &'hir Hir) -> Result<Tir<'hir>, TypeError> { +pub fn typecheck<'hir>(hir: &'hir Hir) -> Result<Tir<'hir>, TypeError> { type_with(&TyEnv::new(), hir, None) } /// Like `typecheck`, but additionally checks that the expression's type matches the provided type. -pub(crate) fn typecheck_with<'hir>( +pub fn typecheck_with<'hir>( hir: &'hir Hir, ty: &Hir, ) -> Result<Tir<'hir>, TypeError> { |