From 66260f8e386f7a447352bd8ccbda064b00b698bc Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 23:44:52 +0200 Subject: Implement inline headers parsing --- dhall/src/phase/resolve.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'dhall/src/phase/resolve.rs') diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index abcee7e..52353e4 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; -use dhall_syntax::Import; - use crate::error::{Error, ImportError}; -use crate::phase::{Normalized, Parsed, Resolved}; +use crate::phase::{Normalized, NormalizedSubExpr, Parsed, Resolved}; + +type Import = dhall_syntax::Import; /// A root from which to resolve relative imports. #[derive(Debug, Clone, PartialEq, Eq)] @@ -28,7 +28,7 @@ fn resolve_import( let cwd = match root { LocalDir(cwd) => cwd, }; - match &import.location_hashed.location { + match &import.location { Local(prefix, path) => { let path: PathBuf = path.iter().cloned().collect(); let path = match prefix { -- cgit v1.3.1 From 816f616479cfa277e19b2e69be6c41bc8210e032 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 15 Aug 2019 22:12:06 +0200 Subject: Disable some unused unstable features --- dhall/src/lib.rs | 6 ------ dhall/src/phase/normalize.rs | 2 +- dhall/src/phase/resolve.rs | 3 +-- dhall/src/phase/typecheck.rs | 2 +- dhall/src/tests.rs | 2 +- serde_dhall/tests/traits.rs | 1 - 6 files changed, 4 insertions(+), 12 deletions(-) (limited to 'dhall/src/phase/resolve.rs') diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index c360323..d40fbda 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -1,13 +1,7 @@ #![feature(trace_macros)] -#![feature(proc_macro_hygiene)] #![feature(slice_patterns)] -#![feature(label_break_value)] #![feature(non_exhaustive)] -#![feature(bind_by_move_pattern_guards)] -#![feature(try_trait)] -#![feature(inner_deref)] #![feature(never_type)] -#![cfg_attr(test, feature(custom_inner_attributes))] #![allow( clippy::type_complexity, clippy::infallible_destructuring_match, diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index f11269e..02406f2 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -752,7 +752,7 @@ pub fn normalize_one_layer(expr: ExprF) -> Value { None => Ret::Expr(expr), }, - ExprF::Projection(_, ls) if ls.is_empty() => { + ExprF::Projection(_, ref ls) if ls.is_empty() => { Ret::Value(RecordLit(HashMap::new())) } ExprF::Projection(ref v, ref ls) => { diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index 52353e4..dabecf2 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -105,9 +105,8 @@ pub fn skip_resolve_expr( } #[cfg(test)] +#[rustfmt::skip] mod spec_tests { - #![rustfmt::skip] - macro_rules! import_success { ($name:ident, $path:expr) => { make_spec_test!(Import, Success, $name, &("../dhall-lang/tests/import/success/".to_owned() + $path)); diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index 89e2da8..5eab8da 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -438,7 +438,7 @@ fn type_last_layer( } Assert(t) => { match t.to_value() { - Value::Equivalence(x, y) if x == y => {} + Value::Equivalence(ref x, ref y) if x == y => {} Value::Equivalence(x, y) => { return Err(mkerr(AssertMismatch( x.to_typed(), diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 15bc97a..d269523 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -204,7 +204,7 @@ pub fn run_test( match feature { Parser => { let err = parse_file_str(&file_path).unwrap_err(); - match err { + match &err { Error::Parse(_) => {} Error::IO(e) if e.kind() == std::io::ErrorKind::InvalidData => {} diff --git a/serde_dhall/tests/traits.rs b/serde_dhall/tests/traits.rs index 55be63b..15a91ed 100644 --- a/serde_dhall/tests/traits.rs +++ b/serde_dhall/tests/traits.rs @@ -1,4 +1,3 @@ -#![feature(proc_macro_hygiene)] use serde_dhall::{from_str, StaticType, Value}; #[test] -- cgit v1.3.1 From 88ebc0f9d561a2541aad84a3152511a0439db8b4 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Aug 2019 17:56:19 +0200 Subject: Reduce api surface of dhall crate Helps detect unused code --- dhall/src/core/context.rs | 8 +++---- dhall/src/core/thunk.rs | 56 ++++++++++++++++++++++---------------------- dhall/src/core/value.rs | 19 +++++---------- dhall/src/core/var.rs | 14 +++++------ dhall/src/phase/binary.rs | 4 ++-- dhall/src/phase/mod.rs | 41 ++++++++++++++------------------ dhall/src/phase/normalize.rs | 14 +++++------ dhall/src/phase/parse.rs | 8 +++---- dhall/src/phase/resolve.rs | 8 +++---- dhall/src/phase/typecheck.rs | 12 +++++----- serde_dhall/src/lib.rs | 14 +++++------ 11 files changed, 92 insertions(+), 106 deletions(-) (limited to 'dhall/src/phase/resolve.rs') diff --git a/dhall/src/core/context.rs b/dhall/src/core/context.rs index 8d14415..9230a2e 100644 --- a/dhall/src/core/context.rs +++ b/dhall/src/core/context.rs @@ -10,19 +10,19 @@ use crate::error::TypeError; use crate::phase::{Type, Typed}; #[derive(Debug, Clone)] -pub enum CtxItem { +enum CtxItem { Kept(AlphaVar, T), Replaced(Thunk, T), } #[derive(Debug, Clone)] -pub struct Context(Rc)>>); +struct Context(Rc)>>); #[derive(Debug, Clone)] -pub struct NormalizationContext(Context<()>); +pub(crate) struct NormalizationContext(Context<()>); #[derive(Debug, Clone)] -pub struct TypecheckContext(Context); +pub(crate) struct TypecheckContext(Context); impl Context { pub fn new() -> Self { diff --git a/dhall/src/core/thunk.rs b/dhall/src/core/thunk.rs index 14d8792..54a5442 100644 --- a/dhall/src/core/thunk.rs +++ b/dhall/src/core/thunk.rs @@ -115,21 +115,21 @@ impl ThunkInternal { } impl Thunk { - pub fn new(ctx: NormalizationContext, e: InputSubExpr) -> Thunk { + pub(crate) fn new(ctx: NormalizationContext, e: InputSubExpr) -> Thunk { ThunkInternal::Unnormalized(ctx, e).into_thunk() } - pub fn from_value(v: Value) -> Thunk { + pub(crate) fn from_value(v: Value) -> Thunk { ThunkInternal::Value(WHNF, v).into_thunk() } - pub fn from_partial_expr(e: ExprF) -> Thunk { + pub(crate) fn from_partial_expr(e: ExprF) -> Thunk { ThunkInternal::PartialExpr(e).into_thunk() } // Normalizes contents to normal form; faster than `normalize_nf` if // no one else shares this thunk - pub fn normalize_mut(&mut self) { + pub(crate) fn normalize_mut(&mut self) { match Rc::get_mut(&mut self.0) { // Mutate directly if sole owner Some(refcell) => RefCell::get_mut(refcell).normalize_nf(), @@ -167,37 +167,37 @@ impl Thunk { // WARNING: avoid normalizing any thunk while holding on to this ref // or you could run into BorrowMut panics - pub fn normalize_nf(&self) -> Ref { + pub(crate) fn normalize_nf(&self) -> Ref { self.do_normalize_nf(); Ref::map(self.0.borrow(), ThunkInternal::as_nf) } // WARNING: avoid normalizing any thunk while holding on to this ref // or you could run into BorrowMut panics - pub fn as_value(&self) -> Ref { + pub(crate) fn as_value(&self) -> Ref { self.do_normalize_whnf(); Ref::map(self.0.borrow(), ThunkInternal::as_whnf) } - pub fn to_value(&self) -> Value { + pub(crate) fn to_value(&self) -> Value { self.as_value().clone() } - pub fn normalize_to_expr_maybe_alpha(&self, alpha: bool) -> OutputSubExpr { + pub(crate) fn normalize_to_expr_maybe_alpha(&self, alpha: bool) -> OutputSubExpr { self.normalize_nf().normalize_to_expr_maybe_alpha(alpha) } - pub fn app_val(&self, val: Value) -> Value { + pub(crate) fn app_val(&self, val: Value) -> Value { self.app_thunk(val.into_thunk()) } - pub fn app_thunk(&self, th: Thunk) -> Value { + pub(crate) fn app_thunk(&self, th: Thunk) -> Value { apply_any(self.clone(), th) } } impl TypedThunk { - pub fn from_value(v: Value) -> TypedThunk { + pub(crate) fn from_value(v: Value) -> TypedThunk { TypedThunk::from_thunk(Thunk::from_value(v)) } @@ -205,11 +205,11 @@ impl TypedThunk { TypedThunk::from_thunk_untyped(th) } - pub fn from_type(t: Type) -> TypedThunk { + pub(crate) fn from_type(t: Type) -> TypedThunk { t.into_typethunk() } - pub fn normalize_nf(&self) -> Value { + pub(crate) fn normalize_nf(&self) -> Value { match self { TypedThunk::Const(c) => Value::Const(*c), TypedThunk::Untyped(thunk) | TypedThunk::Typed(thunk, _) => { @@ -218,53 +218,53 @@ impl TypedThunk { } } - pub fn to_typed(&self) -> Typed { + pub(crate) fn to_typed(&self) -> Typed { self.clone().into_typed() } - pub fn normalize_to_expr_maybe_alpha(&self, alpha: bool) -> OutputSubExpr { + pub(crate) fn normalize_to_expr_maybe_alpha(&self, alpha: bool) -> OutputSubExpr { self.normalize_nf().normalize_to_expr_maybe_alpha(alpha) } - pub fn from_thunk_and_type(th: Thunk, t: Type) -> Self { + pub(crate) fn from_thunk_and_type(th: Thunk, t: Type) -> Self { TypedThunk::Typed(th, Box::new(t)) } - pub fn from_thunk_untyped(th: Thunk) -> Self { + pub(crate) fn from_thunk_untyped(th: Thunk) -> Self { TypedThunk::Untyped(th) } - pub fn from_const(c: Const) -> Self { + pub(crate) fn from_const(c: Const) -> Self { TypedThunk::Const(c) } - pub fn from_value_untyped(v: Value) -> Self { + pub(crate) fn from_value_untyped(v: Value) -> Self { TypedThunk::from_thunk_untyped(Thunk::from_value(v)) } // TODO: Avoid cloning if possible - pub fn to_value(&self) -> Value { + pub(crate) fn to_value(&self) -> Value { match self { TypedThunk::Untyped(th) | TypedThunk::Typed(th, _) => th.to_value(), TypedThunk::Const(c) => Value::Const(*c), } } - pub fn to_expr(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr(&self) -> NormalizedSubExpr { self.to_value().normalize_to_expr() } - pub fn to_expr_alpha(&self) -> NormalizedSubExpr { + pub(crate) fn to_expr_alpha(&self) -> NormalizedSubExpr { self.to_value().normalize_to_expr_maybe_alpha(true) } - pub fn to_thunk(&self) -> Thunk { + pub(crate) fn to_thunk(&self) -> Thunk { match self { TypedThunk::Untyped(th) | TypedThunk::Typed(th, _) => th.clone(), TypedThunk::Const(c) => Thunk::from_value(Value::Const(*c)), } } - pub fn to_type(&self) -> Type { + pub(crate) fn to_type(&self) -> Type { self.clone().into_typed().into_type() } - pub fn into_typed(self) -> Typed { + pub(crate) fn into_typed(self) -> Typed { Typed::from_typethunk(self) } - pub fn as_const(&self) -> Option { + pub(crate) fn as_const(&self) -> Option { // TODO: avoid clone match &self.to_value() { Value::Const(c) => Some(*c), @@ -272,7 +272,7 @@ impl TypedThunk { } } - pub fn normalize_mut(&mut self) { + pub(crate) fn normalize_mut(&mut self) { match self { TypedThunk::Untyped(th) | TypedThunk::Typed(th, _) => { th.normalize_mut() @@ -281,7 +281,7 @@ impl TypedThunk { } } - pub fn get_type(&self) -> Result, TypeError> { + pub(crate) fn get_type(&self) -> Result, TypeError> { match self { TypedThunk::Untyped(_) => Err(TypeError::new( &TypecheckContext::new(), diff --git a/dhall/src/core/value.rs b/dhall/src/core/value.rs index 19be56a..61a8eea 100644 --- a/dhall/src/core/value.rs +++ b/dhall/src/core/value.rs @@ -56,17 +56,17 @@ pub enum Value { } impl Value { - pub fn into_thunk(self) -> Thunk { + pub(crate) fn into_thunk(self) -> Thunk { Thunk::from_value(self) } /// Convert the value to a fully normalized syntactic expression - pub fn normalize_to_expr(&self) -> OutputSubExpr { + pub(crate) fn normalize_to_expr(&self) -> OutputSubExpr { self.normalize_to_expr_maybe_alpha(false) } /// Convert the value to a fully normalized syntactic expression. Also alpha-normalize /// if alpha is `true` - pub fn normalize_to_expr_maybe_alpha(&self, alpha: bool) -> OutputSubExpr { + pub(crate) fn normalize_to_expr_maybe_alpha(&self, alpha: bool) -> OutputSubExpr { match self { Value::Lam(x, t, e) => rc(ExprF::Lam( x.to_label_maybe_alpha(alpha), @@ -179,14 +179,7 @@ impl Value { } } - // Deprecated - pub fn normalize(&self) -> Value { - let mut v = self.clone(); - v.normalize_mut(); - v - } - - pub fn normalize_mut(&mut self) { + pub(crate) fn normalize_mut(&mut self) { match self { Value::Var(_) | Value::Const(_) @@ -264,12 +257,12 @@ impl Value { } /// Apply to a value - pub fn app(self, val: Value) -> Value { + pub(crate) fn app(self, val: Value) -> Value { self.app_val(val) } /// Apply to a value - pub fn app_val(self, val: Value) -> Value { + pub(crate) fn app_val(self, val: Value) -> Value { self.app_thunk(val.into_thunk()) } diff --git a/dhall/src/core/var.rs b/dhall/src/core/var.rs index d53c194..4ef1b93 100644 --- a/dhall/src/core/var.rs +++ b/dhall/src/core/var.rs @@ -16,7 +16,7 @@ pub struct AlphaVar { #[derive(Clone, Eq)] pub struct AlphaLabel(Label); -pub trait Shift: Sized { +pub(crate) trait Shift: Sized { // Shift an expression to move it around binders without changing the meaning of its free // variables. Shift by 1 to move an expression under a binder. Shift by -1 to extract an // expression from under a binder, if the expression does not refer to that bound variable. @@ -50,24 +50,24 @@ pub trait Shift: Sized { } } -pub trait Subst { +pub(crate) trait Subst { fn subst_shift(&self, var: &AlphaVar, val: &T) -> Self; } impl AlphaVar { - pub fn to_var(&self, alpha: bool) -> V