summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadrieril2019-12-15 19:56:54 +0000
committerNadrieril2019-12-15 19:56:54 +0000
commit0105e3c31dbb2984e5c4b9d51cc3b27767e7683c (patch)
tree0e0a5eff865529fec1709201d241bd99ca14baba
parentec761bbd0de807bf1cb0da9389d714e3d812dd6d (diff)
Avoid mention of `crate::` outside of top-level imports
-rw-r--r--dhall/src/semantics/core/context.rs3
-rw-r--r--dhall/src/semantics/core/value.rs3
-rw-r--r--dhall/src/semantics/core/valuef.rs12
-rw-r--r--dhall/src/semantics/core/var.rs10
-rw-r--r--dhall/src/semantics/error/mod.rs3
-rw-r--r--dhall/src/semantics/phase/binary.rs18
-rw-r--r--dhall/src/semantics/phase/mod.rs8
-rw-r--r--dhall/src/semantics/phase/normalize.rs18
-rw-r--r--dhall/src/semantics/phase/parse.rs8
-rw-r--r--dhall/src/semantics/phase/resolve.rs7
-rw-r--r--dhall/src/semantics/phase/typecheck.rs47
11 files changed, 63 insertions, 74 deletions
diff --git a/dhall/src/semantics/core/context.rs b/dhall/src/semantics/core/context.rs
index 00e1493..c3da823 100644
--- a/dhall/src/semantics/core/context.rs
+++ b/dhall/src/semantics/core/context.rs
@@ -1,12 +1,11 @@
use std::collections::HashMap;
use std::rc::Rc;
-use crate::syntax::{Label, V};
-
use crate::core::value::Value;
use crate::core::valuef::ValueF;
use crate::core::var::{AlphaVar, Shift, Subst};
use crate::error::TypeError;
+use crate::syntax::{Label, V};
#[derive(Debug, Clone)]
enum CtxItem {
diff --git a/dhall/src/semantics/core/value.rs b/dhall/src/semantics/core/value.rs
index bd7a9b9..68b879b 100644
--- a/dhall/src/semantics/core/value.rs
+++ b/dhall/src/semantics/core/value.rs
@@ -1,8 +1,6 @@
use std::cell::{Ref, RefCell, RefMut};
use std::rc::Rc;
-use crate::syntax::{Builtin, Const, Span};
-
use crate::core::context::TypecheckContext;
use crate::core::valuef::ValueF;
use crate::core::var::{AlphaVar, Shift, Subst};
@@ -10,6 +8,7 @@ use crate::error::{TypeError, TypeMessage};
use crate::phase::normalize::{apply_any, normalize_whnf};
use crate::phase::typecheck::{builtin_to_value, const_to_value};
use crate::phase::{NormalizedExpr, Typed};
+use crate::syntax::{Builtin, Const, Span};
#[derive(Debug, Clone, Copy)]
pub(crate) enum Form {
diff --git a/dhall/src/semantics/core/valuef.rs b/dhall/src/semantics/core/valuef.rs
index e9ac391..e11d5d7 100644
--- a/dhall/src/semantics/core/valuef.rs
+++ b/dhall/src/semantics/core/valuef.rs
@@ -1,14 +1,14 @@
use std::collections::HashMap;
-use crate::syntax::{
- Builtin, Const, ExprF, Integer, InterpolatedTextContents, Label,
- NaiveDouble, Natural,
-};
-
use crate::core::value::{ToExprOptions, Value};
use crate::core::var::{AlphaLabel, AlphaVar, Shift, Subst};
use crate::phase::typecheck::rc;
use crate::phase::{Normalized, NormalizedExpr};
+use crate::syntax;
+use crate::syntax::{
+ Builtin, Const, ExprF, Integer, InterpolatedTextContents, Label,
+ NaiveDouble, Natural,
+};
/// A semantic value. Subexpressions are Values, which are partially evaluated expressions that are
/// normalized on-demand.
@@ -117,7 +117,7 @@ impl ValueF {
.collect(),
)),
ValueF::Equivalence(x, y) => rc(ExprF::BinOp(
- crate::syntax::BinOp::Equivalence,
+ syntax::BinOp::Equivalence,
x.to_expr(opts),
y.to_expr(opts),
)),
diff --git a/dhall/src/semantics/core/var.rs b/dhall/src/semantics/core/var.rs
index f9d3478..184a372 100644
--- a/dhall/src/semantics/core/var.rs
+++ b/dhall/src/semantics/core/var.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
-use crate::syntax::{Label, V};
+use crate::syntax::{ExprF, InterpolatedTextContents, Label, V};
/// Stores a pair of variables: a normal one and one
/// that corresponds to the alpha-normalized version of the first one.
@@ -190,7 +190,7 @@ impl<T: Shift> Shift for std::cell::RefCell<T> {
}
}
-impl<T: Shift, E: Clone> Shift for crate::syntax::ExprF<T, E> {
+impl<T: Shift, E: Clone> Shift for ExprF<T, E> {
fn shift(&self, delta: isize, var: &AlphaVar) -> Option<Self> {
Some(self.traverse_ref_with_special_handling_of_binders(
|v| Ok(v.shift(delta, var)?),
@@ -222,7 +222,7 @@ where
}
}
-impl<T: Shift> Shift for crate::syntax::InterpolatedTextContents<T> {
+impl<T: Shift> Shift for InterpolatedTextContents<T> {
fn shift(&self, delta: isize, var: &AlphaVar) -> Option<Self> {
Some(self.traverse_ref(|x| Ok(x.shift(delta, var)?))?)
}
@@ -262,7 +262,7 @@ impl<S, T: Subst<S>> Subst<S> for std::cell::RefCell<T> {
}
}
-impl<S: Shift, T: Subst<S>, E: Clone> Subst<S> for crate::syntax::ExprF<T, E> {
+impl<S: Shift, T: Subst<S>, E: Clone> Subst<S> for ExprF<T, E> {
fn subst_shift(&self, var: &AlphaVar, val: &S) -> Self {
self.map_ref_with_special_handling_of_binders(
|v| v.subst_shift(var, val),
@@ -277,7 +277,7 @@ impl<S, T: Subst<S>> Subst<S> for Vec<T> {
}
}
-impl<S, T: Subst<S>> Subst<S> for crate::syntax::InterpolatedTextContents<T> {
+impl<S, T: Subst<S>> Subst<S> for InterpolatedTextContents<T> {
fn subst_shift(&self, var: &AlphaVar, val: &S) -> Self {
self.map_ref(|x| x.subst_shift(var, val))
}
diff --git a/dhall/src/semantics/error/mod.rs b/dhall/src/semantics/error/mod.rs
index 1d58e6f..b2f799d 100644
--- a/dhall/src/semantics/error/mod.rs
+++ b/dhall/src/semantics/error/mod.rs
@@ -1,11 +1,10 @@
use std::io::Error as IOError;
-use crate::syntax::{BinOp, Import, Label, ParseError, Span};
-
use crate::core::context::TypecheckContext;
use crate::core::value::Value;
use crate::phase::resolve::ImportStack;
use crate::phase::NormalizedExpr;
+use crate::syntax::{BinOp, Import, Label, ParseError, Span};
pub type Result<T> = std::result::Result<T, Error>;
diff --git a/dhall/src/semantics/phase/binary.rs b/dhall/src/semantics/phase/binary.rs
index 1fc41d4..a38f08a 100644
--- a/dhall/src/semantics/phase/binary.rs
+++ b/dhall/src/semantics/phase/binary.rs
@@ -3,6 +3,9 @@ use serde_cbor::value::value as cbor;
use std::iter::FromIterator;
use std::vec;
+use crate::error::{DecodeError, EncodeError};
+use crate::phase::DecodedExpr;
+use crate::syntax;
use crate::syntax::map::DupTreeMap;
use crate::syntax::{
Expr, ExprF, FilePath, FilePrefix, Hash, Import, ImportLocation,
@@ -10,9 +13,6 @@ use crate::syntax::{
Span, URL, V,
};
-use crate::error::{DecodeError, EncodeError};
-use crate::phase::DecodedExpr;
-
pub(crate) fn decode(data: &[u8]) -> Result<DecodedExpr, DecodeError> {
match serde_cbor::de::from_slice(data) {
Ok(v) => cbor_value_to_dhall(&v),
@@ -31,8 +31,8 @@ pub fn rc<E>(x: RawExpr<E>) -> Expr<E> {
}
fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
- use crate::syntax::{BinOp, Builtin, Const};
use cbor::Value::*;
+ use syntax::{BinOp, Builtin, Const};
use ExprF::*;
Ok(rc(match data {
String(s) => match Builtin::parse(s) {
@@ -350,7 +350,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
"import/type".to_owned(),
))?,
};
- Import(crate::syntax::Import {
+ Import(syntax::Import {
mode,
hash,
location,
@@ -472,10 +472,10 @@ fn serialize_subexpr<S, E>(ser: S, e: &Expr<E>) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
- use crate::syntax::Builtin;
- use crate::syntax::ExprF::*;
use cbor::Value::{String, I64, U64};
use std::iter::once;
+ use syntax::Builtin;
+ use syntax::ExprF::*;
use self::Serialize::{RecordMap, UnionMap};
fn expr<E>(x: &Expr<E>) -> self::Serialize<'_, E> {
@@ -548,7 +548,7 @@ where
once(tag(4)).chain(once(null())).chain(xs.iter().map(expr)),
),
TextLit(xs) => {
- use crate::syntax::InterpolatedTextContents::{Expr, Text};
+ use syntax::InterpolatedTextContents::{Expr, Text};
ser.collect_seq(once(tag(18)).chain(xs.iter().map(|x| match x {
Expr(x) => expr(x),
Text(x) => cbor(String(x.clone())),
@@ -559,7 +559,7 @@ where
UnionType(map) => ser_seq!(ser; tag(11), UnionMap(map)),
Field(x, l) => ser_seq!(ser; tag(9), expr(x), label(l)),
BinOp(op, x, y) => {
- use crate::syntax::BinOp::*;
+ use syntax::BinOp::*;
let op = match op {
BoolOr => 0,
BoolAnd => 1,
diff --git a/dhall/src/semantics/phase/mod.rs b/dhall/src/semantics/phase/mod.rs
index 918c4d0..9f38308 100644
--- a/dhall/src/semantics/phase/mod.rs
+++ b/dhall/src/semantics/phase/mod.rs
@@ -1,13 +1,11 @@
use std::fmt::Display;
use std::path::Path;
-use crate::syntax::{Builtin, Const, Expr};
-
use crate::core::value::{ToExprOptions, Value};
use crate::core::valuef::ValueF;
use crate::core::var::{AlphaVar, Shift, Subst};
use crate::error::{EncodeError, Error, ImportError, TypeError};
-
+use crate::syntax::{Builtin, Const, Expr};
use resolve::ImportRoot;
pub(crate) mod binary;
@@ -62,7 +60,7 @@ impl Parsed {
}
pub fn encode(&self) -> Result<Vec<u8>, EncodeError> {
- crate::phase::binary::encode(&self.0)
+ binary::encode(&self.0)
}
}
@@ -172,7 +170,7 @@ impl Typed {
impl Normalized {
pub fn encode(&self) -> Result<Vec<u8>, EncodeError> {
- crate::phase::binary::encode(&self.to_expr())
+ binary::encode(&self.to_expr())
}
pub(crate) fn to_expr(&self) -> NormalizedExpr {
diff --git a/dhall/src/semantics/phase/normalize.rs b/dhall/src/semantics/phase/normalize.rs
index 3ed53f4..59531bd 100644
--- a/dhall/src/semantics/phase/normalize.rs
+++ b/dhall/src/semantics/phase/normalize.rs
@@ -1,21 +1,21 @@
use std::collections::HashMap;
+use crate::core::value::Value;
+use crate::core::valuef::ValueF;
+use crate::core::var::{AlphaLabel, AlphaVar, Shift, Subst};
+use crate::phase::Normalized;
+use crate::syntax;
use crate::syntax::Const::Type;
use crate::syntax::{
BinOp, Builtin, ExprF, InterpolatedText, InterpolatedTextContents, Label,
NaiveDouble,
};
-use crate::core::value::Value;
-use crate::core::valuef::ValueF;
-use crate::core::var::{AlphaLabel, Shift, Subst};
-use crate::phase::Normalized;
-
// Ad-hoc macro to help construct closures
macro_rules! make_closure {
(#$var:ident) => { $var.clone() };
(var($var:ident, $n:expr, $($ty:tt)*)) => {{
- let var = crate::core::var::AlphaVar::from_var_and_alpha(
+ let var = AlphaVar::from_var_and_alpha(
Label::from(stringify!($var)).into(),
$n
);
@@ -47,7 +47,7 @@ macro_rules! make_closure {
}};
(1 + $($rest:tt)*) => {
ValueF::PartialExpr(ExprF::BinOp(
- crate::syntax::BinOp::NaturalPlus,
+ syntax::BinOp::NaturalPlus,
make_closure!($($rest)*),
Value::from_valuef_and_type(
ValueF::NaturalLit(1),
@@ -62,7 +62,7 @@ macro_rules! make_closure {
let tail = make_closure!($($tail)*);
let list_type = tail.get_type_not_sort();
ValueF::PartialExpr(ExprF::BinOp(
- crate::syntax::BinOp::ListAppend,
+ syntax::BinOp::ListAppend,
ValueF::NEListLit(vec![head])
.into_value_with_type(list_type.clone()),
tail,
@@ -76,7 +76,7 @@ pub(crate) fn apply_builtin(
args: Vec<Value>,
ty: &Value,
) -> ValueF {
- use crate::syntax::Builtin::*;
+ use syntax::Builtin::*;
use ValueF::*;
// Small helper enum
diff --git a/dhall/src/semantics/phase/parse.rs b/dhall/src/semantics/phase/parse.rs
index e277e54..601e93d 100644
--- a/dhall/src/semantics/phase/parse.rs
+++ b/dhall/src/semantics/phase/parse.rs
@@ -2,11 +2,11 @@ use std::fs::File;
use std::io::Read;
use std::path::Path;
-use crate::syntax::parse_expr;
-
use crate::error::Error;
+use crate::phase::binary;
use crate::phase::resolve::ImportRoot;
use crate::phase::Parsed;
+use crate::syntax::parse_expr;
pub(crate) fn parse_file(f: &Path) -> Result<Parsed, Error> {
let mut buffer = String::new();
@@ -23,7 +23,7 @@ pub(crate) fn parse_str(s: &str) -> Result<Parsed, Error> {
}
pub(crate) fn parse_binary(data: &[u8]) -> Result<Parsed, Error> {
- let expr = crate::phase::binary::decode(data)?;
+ let expr = binary::decode(data)?;
let root = ImportRoot::LocalDir(std::env::current_dir()?);
Ok(Parsed(expr, root))
}
@@ -31,7 +31,7 @@ pub(crate) fn parse_binary(data: &[u8]) -> Result<Parsed, Error> {
pub(crate) 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)?;
+ let expr = binary::decode(&buffer)?;
let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned());
Ok(Parsed(expr, root))
}
diff --git a/dhall/src/semantics/phase/resolve.rs b/dhall/src/semantics/phase/resolve.rs
index 5920f82..d0563c0 100644
--- a/dhall/src/semantics/phase/resolve.rs
+++ b/dhall/src/semantics/phase/resolve.rs
@@ -3,9 +3,10 @@ use std::path::{Path, PathBuf};
use crate::error::{Error, ImportError};
use crate::phase::{Normalized, NormalizedExpr, Parsed, Resolved};
+use crate::syntax;
use crate::syntax::{FilePath, ImportLocation, URL};
-type Import = crate::syntax::Import<NormalizedExpr>;
+type Import = syntax::Import<NormalizedExpr>;
/// A root from which to resolve relative imports.
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -24,8 +25,8 @@ fn resolve_import(
import_stack: &ImportStack,
) -> Result<Normalized, ImportError> {
use self::ImportRoot::*;
- use crate::syntax::FilePrefix::*;
- use crate::syntax::ImportLocation::*;
+ use syntax::FilePrefix::*;
+ use syntax::ImportLocation::*;
let cwd = match root {
LocalDir(cwd) => cwd,
};
diff --git a/dhall/src/semantics/phase/typecheck.rs b/dhall/src/semantics/phase/typecheck.rs
index 97a29ca..cc524c4 100644
--- a/dhall/src/semantics/phase/typecheck.rs
+++ b/dhall/src/semantics/phase/typecheck.rs
@@ -1,16 +1,17 @@
use std::cmp::max;
use std::collections::HashMap;
-use crate::syntax::{
- Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, RawExpr, Span,
-};
-
use crate::core::context::TypecheckContext;
use crate::core::value::Value;
use crate::core::valuef::ValueF;
use crate::core::var::{Shift, Subst};
use crate::error::{TypeError, TypeMessage};
+use crate::phase::normalize::merge_maps;
use crate::phase::Normalized;
+use crate::syntax;
+use crate::syntax::{
+ Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, RawExpr, Span,
+};
fn tck_pi_type(
ctx: &TypecheckContext,
@@ -18,7 +19,7 @@ fn tck_pi_type(
tx: Value,
te: Value,
) -> Result<Value, TypeError> {
- use crate::error::TypeMessage::*;
+ use TypeMessage::*;
let ctx2 = ctx.insert_type(&x, tx.clone());
let ka = match tx.get_type()?.as_const() {
@@ -48,8 +49,8 @@ fn tck_record_type(
ctx: &TypecheckContext,
kts: impl IntoIterator<Item = Result<(Label, Value), TypeError>>,
) -> Result<Value, TypeError> {
- use crate::error::TypeMessage::*;
use std::collections::hash_map::Entry;
+ use TypeMessage::*;
let mut new_kts = HashMap::new();
// An empty record type has type Type
let mut k = Const::Type;
@@ -83,8 +84,8 @@ fn tck_union_type<Iter>(
where
Iter: IntoIterator<Item = Result<(Label, Option<Value>), TypeError>>,
{
- use crate::error::TypeMessage::*;
use std::collections::hash_map::Entry;
+ use TypeMessage::*;
let mut new_kts = HashMap::new();
// Check that all types are the same const
let mut k = None;
@@ -155,7 +156,7 @@ macro_rules! make_type {
(Double) => { ExprF::Builtin(Builtin::Double) };
(Text) => { ExprF::Builtin(Builtin::Text) };
($var:ident) => {
- ExprF::Var(crate::syntax::V(stringify!($var).into(), 0))
+ ExprF::Var(syntax::V(stringify!($var).into(), 0))
};
(Optional $ty:ident) => {
ExprF::App(
@@ -170,7 +171,7 @@ macro_rules! make_type {
)
};
({ $($label:ident : $ty:ident),* }) => {{
- let mut kts = crate::syntax::map::DupTreeMap::new();
+ let mut kts = syntax::map::DupTreeMap::new();
$(
kts.insert(
Label::from(stringify!($label)),
@@ -203,7 +204,7 @@ macro_rules! make_type {
}
fn type_of_builtin<E>(b: Builtin) -> Expr<E> {
- use crate::syntax::Builtin::*;
+ use syntax::Builtin::*;
rc(match b {
Bool | Natural | Integer | Double | Text => make_type!(Type),
List | Optional => make_type!(
@@ -303,7 +304,7 @@ fn type_with(
ctx: &TypecheckContext,
e: Expr<Normalized>,
) -> Result<Value, TypeError> {
- use crate::syntax::ExprF::{Annot, Embed, Lam, Let, Pi, Var};
+ use syntax::ExprF::{Annot, Embed, Lam, Let, Pi, Var};
let span = e.span();
Ok(match e.as_ref() {
@@ -361,11 +362,11 @@ fn type_last_layer(
e: ExprF<Value, Normalized>,
span: Span,
) -> Result<Value, TypeError> {
- use crate::error::TypeMessage::*;
- use crate::syntax::BinOp::*;
- use crate::syntax::Builtin::*;
- use crate::syntax::Const::Type;
- use crate::syntax::ExprF::*;
+ use syntax::BinOp::*;
+ use syntax::Builtin::*;
+ use syntax::Const::Type;
+ use syntax::ExprF::*;
+ use TypeMessage::*;
let mkerr = |msg: TypeMessage| Err(TypeError::new(ctx, msg));
/// Intermediary return type
@@ -434,7 +435,7 @@ fn type_last_layer(
}
EmptyListLit(t) => {
match &*t.as_whnf() {
- ValueF::AppliedBuiltin(crate::syntax::Builtin::List, args)
+ ValueF::AppliedBuiltin(syntax::Builtin::List, args)
if args.len() == 1 => {}
_ => return mkerr(InvalidListType(t.clone())),
}
@@ -457,9 +458,7 @@ fn type_last_layer(
return mkerr(InvalidListType(t));
}
- RetTypeOnly(
- Value::from_builtin(crate::syntax::Builtin::List).app(t),
- )
+ RetTypeOnly(Value::from_builtin(syntax::Builtin::List).app(t))
}
SomeLit(x) => {
let t = x.get_type()?;
@@ -467,9 +466,7 @@ fn type_last_layer(
return mkerr(InvalidOptionalType(t));
}
- RetTypeOnly(
- Value::from_builtin(crate::syntax::Builtin::Optional).app(t),
- )
+ RetTypeOnly(Value::from_builtin(syntax::Builtin::Optional).app(t))
}
RecordType(kts) => RetWhole(tck_record_type(
ctx,
@@ -550,8 +547,6 @@ fn type_last_layer(
RetTypeOnly(text_type)
}
BinOp(RightBiasedRecordMerge, l, r) => {
- use crate::phase::normalize::merge_maps;
-
let l_type = l.get_type()?;
let r_type = r.get_type()?;
@@ -591,8 +586,6 @@ fn type_last_layer(
Span::Artificial,
)?),
BinOp(RecursiveRecordTypeMerge, l, r) => {
- use crate::phase::normalize::merge_maps;
-
// Extract the LHS record type
let borrow_l = l.as_whnf();
let kts_x = match &*borrow_l {