From 7abd49772643ee4e131ef47de66db22ba7c1e037 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 15 Dec 2019 19:47:20 +0000 Subject: Move contents of dhall under a semantics submodule --- dhall/src/semantics/error/mod.rs | 179 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 dhall/src/semantics/error/mod.rs (limited to 'dhall/src/semantics/error') diff --git a/dhall/src/semantics/error/mod.rs b/dhall/src/semantics/error/mod.rs new file mode 100644 index 0000000..1d58e6f --- /dev/null +++ b/dhall/src/semantics/error/mod.rs @@ -0,0 +1,179 @@ +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; + +pub type Result = std::result::Result; + +#[derive(Debug)] +#[non_exhaustive] +pub enum Error { + IO(IOError), + Parse(ParseError), + Decode(DecodeError), + Encode(EncodeError), + Resolve(ImportError), + Typecheck(TypeError), +} + +#[derive(Debug)] +pub enum ImportError { + Recursive(Import, Box), + UnexpectedImport(Import), + ImportCycle(ImportStack, Import), +} + +#[derive(Debug)] +pub enum DecodeError { + CBORError(serde_cbor::error::Error), + WrongFormatError(String), +} + +#[derive(Debug)] +pub enum EncodeError { + CBORError(serde_cbor::error::Error), +} + +/// A structured type error that includes context +#[derive(Debug)] +pub struct TypeError { + message: TypeMessage, + context: TypecheckContext, +} + +/// The specific type error +#[derive(Debug)] +pub(crate) enum TypeMessage { + UnboundVariable(Span), + InvalidInputType(Value), + InvalidOutputType(Value), + NotAFunction(Value), + TypeMismatch(Value, Value, Value), + AnnotMismatch(Value, Value), + InvalidListElement(usize, Value, Value), + InvalidListType(Value), + InvalidOptionalType(Value), + InvalidPredicate(Value), + IfBranchMismatch(Value, Value), + IfBranchMustBeTerm(bool, Value), + InvalidFieldType(Label, Value), + NotARecord(Label, Value), + MustCombineRecord(Value), + MissingRecordField(Label, Value), + MissingUnionField(Label, Value), + BinOpTypeMismatch(BinOp, Value), + InvalidTextInterpolation(Value), + Merge1ArgMustBeRecord(Value), + Merge2ArgMustBeUnion(Value), + MergeEmptyNeedsAnnotation, + MergeHandlerMissingVariant(Label), + MergeVariantMissingHandler(Label), + MergeAnnotMismatch, + MergeHandlerTypeMismatch, + MergeHandlerReturnTypeMustNotBeDependent, + ProjectionMustBeRecord, + ProjectionMissingEntry, + Sort, + RecordTypeDuplicateField, + RecordTypeMergeRequiresRecordType(Value), + UnionTypeDuplicateField, + EquivalenceArgumentMustBeTerm(bool, Value), + EquivalenceTypeMismatch(Value, Value), + AssertMismatch(Value, Value), + AssertMustTakeEquivalence, +} + +impl TypeError { + pub(crate) fn new( + context: &TypecheckContext, + message: TypeMessage, + ) -> Self { + TypeError { + context: context.clone(), + message, + } + } +} + +impl std::fmt::Display for TypeError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + use TypeMessage::*; + let msg = match &self.message { + UnboundVariable(span) => span.error("Type error: Unbound variable"), + InvalidInputType(v) => { + v.span().error("Type error: Invalid function input") + } + InvalidOutputType(v) => { + v.span().error("Type error: Invalid function output") + } + NotAFunction(v) => v.span().error("Type error: Not a function"), + TypeMismatch(x, y, z) => { + x.span() + .error("Type error: Wrong type of function argument") + + "\n" + + &z.span().error(format!( + "This argument has type {:?}", + z.get_type().unwrap() + )) + + "\n" + + &y.span().error(format!( + "But the function expected an argument of type {:?}", + y + )) + } + _ => "Type error: Unhandled error".to_string(), + }; + write!(f, "{}", msg) + } +} + +impl std::error::Error for TypeError {} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Error::IO(err) => write!(f, "{}", err), + Error::Parse(err) => write!(f, "{}", err), + Error::Decode(err) => write!(f, "{:?}", err), + Error::Encode(err) => write!(f, "{:?}", err), + Error::Resolve(err) => write!(f, "{:?}", err), + Error::Typecheck(err) => write!(f, "{}", err), + } + } +} + +impl std::error::Error for Error {} +impl From for Error { + fn from(err: IOError) -> Error { + Error::IO(err) + } +} +impl From for Error { + fn from(err: ParseError) -> Error { + Error::Parse(err) + } +} +impl From for Error { + fn from(err: DecodeError) -> Error { + Error::Decode(err) + } +} +impl From for Error { + fn from(err: EncodeError) -> Error { + Error::Encode(err) + } +} +impl From for Error { + fn from(err: ImportError) -> Error { + Error::Resolve(err) + } +} +impl From for Error { + fn from(err: TypeError) -> Error { + Error::Typecheck(err) + } +} -- cgit v1.3.1 From 0105e3c31dbb2984e5c4b9d51cc3b27767e7683c Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 15 Dec 2019 19:56:54 +0000 Subject: Avoid mention of `crate::` outside of top-level imports --- dhall/src/semantics/core/context.rs | 3 +-- dhall/src/semantics/core/value.rs | 3 +-- dhall/src/semantics/core/valuef.rs | 12 ++++----- dhall/src/semantics/core/var.rs | 10 ++++---- dhall/src/semantics/error/mod.rs | 3 +-- dhall/src/semantics/phase/binary.rs | 18 ++++++------- dhall/src/semantics/phase/mod.rs | 8 +++--- dhall/src/semantics/phase/normalize.rs | 18 ++++++------- dhall/src/semantics/phase/parse.rs | 8 +++--- dhall/src/semantics/phase/resolve.rs | 7 ++--- dhall/src/semantics/phase/typecheck.rs | 47 +++++++++++++++------------------- 11 files changed, 63 insertions(+), 74 deletions(-) (limited to 'dhall/src/semantics/error') 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 Shift for std::cell::RefCell { } } -impl Shift for crate::syntax::ExprF { +impl Shift for ExprF { fn shift(&self, delta: isize, var: &AlphaVar) -> Option { Some(self.traverse_ref_with_special_handling_of_binders( |v| Ok(v.shift(delta, var)?), @@ -222,7 +222,7 @@ where } } -impl Shift for crate::syntax::InterpolatedTextContents { +impl Shift for InterpolatedTextContents { fn shift(&self, delta: isize, var: &AlphaVar) -> Option { Some(self.traverse_ref(|x| Ok(x.shift(delta, var)?))?) } @@ -262,7 +262,7 @@ impl> Subst for std::cell::RefCell { } } -impl, E: Clone> Subst for crate::syntax::ExprF { +impl, E: Clone> Subst for ExprF { 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> Subst for Vec { } } -impl> Subst for crate::syntax::InterpolatedTextContents { +impl> Subst for InterpolatedTextContents { 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 = std::result::Result; 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 { match serde_cbor::de::from_slice(data) { Ok(v) => cbor_value_to_dhall(&v), @@ -31,8 +31,8 @@ pub fn rc(x: RawExpr) -> Expr { } fn cbor_value_to_dhall(data: &cbor::Value) -> Result { - 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 { "import/type".to_owned(), ))?, }; - Import(crate::syntax::Import { + Import(syntax::Import { mode, hash, location, @@ -472,10 +472,10 @@ fn serialize_subexpr(ser: S, e: &Expr) -> Result 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(x: &Expr) -> 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, EncodeError> { - crate::phase::binary::encode(&self.0) + binary::encode(&self.0) } } @@ -172,7 +170,7 @@ impl Typed { impl Normalized { pub fn encode(&self) -> Result, 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, 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 { let mut buffer = String::new(); @@ -23,7 +23,7 @@ pub(crate) fn parse_str(s: &str) -> Result { } pub(crate) fn parse_binary(data: &[u8]) -> Result { - 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 { pub(crate) 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)?; + 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; +type Import = syntax::Import; /// A root from which to resolve relative imports. #[derive(Debug, Clone, PartialEq, Eq)] @@ -24,8 +25,8 @@ fn resolve_import( import_stack: &ImportStack, ) -> Result { 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 { - 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>, ) -> Result { - 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( where Iter: IntoIterator), 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(b: Builtin) -> Expr { - 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, ) -> Result { - 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, span: Span, ) -> Result { - 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 { -- cgit v1.3.1 From b11a2cd6ca50d5a4dfa71ae8cd0642fb1c75e1cf Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 15 Dec 2019 20:01:35 +0000 Subject: Refer to semantics module properly --- dhall/src/lib.rs | 2 -- dhall/src/semantics/core/context.rs | 8 ++++---- dhall/src/semantics/core/value.rs | 14 +++++++------- dhall/src/semantics/core/valuef.rs | 8 ++++---- dhall/src/semantics/error/mod.rs | 8 ++++---- dhall/src/semantics/phase/binary.rs | 4 ++-- dhall/src/semantics/phase/mod.rs | 8 ++++---- dhall/src/semantics/phase/normalize.rs | 8 ++++---- dhall/src/semantics/phase/parse.rs | 8 ++++---- dhall/src/semantics/phase/resolve.rs | 4 ++-- dhall/src/semantics/phase/typecheck.rs | 14 +++++++------- dhall/src/tests.rs | 4 ++-- serde_dhall/src/lib.rs | 6 +++--- serde_dhall/src/serde.rs | 2 +- 14 files changed, 48 insertions(+), 50 deletions(-) (limited to 'dhall/src/semantics/error') diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 3c0159a..86af98f 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -13,8 +13,6 @@ mod tests; pub mod semantics; -pub use crate::semantics::*; - pub mod syntax { pub use dhall_syntax::*; } diff --git a/dhall/src/semantics/core/context.rs b/dhall/src/semantics/core/context.rs index c3da823..d150e56 100644 --- a/dhall/src/semantics/core/context.rs +++ b/dhall/src/semantics/core/context.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use std::rc::Rc; -use crate::core::value::Value; -use crate::core::valuef::ValueF; -use crate::core::var::{AlphaVar, Shift, Subst}; -use crate::error::TypeError; +use crate::semantics::core::value::Value; +use crate::semantics::core::valuef::ValueF; +use crate::semantics::core::var::{AlphaVar, Shift, Subst}; +use crate::semantics::error::TypeError; use crate::syntax::{Label, V}; #[derive(Debug, Clone)] diff --git a/dhall/src/semantics/core/value.rs b/dhall/src/semantics/core/value.rs index 68b879b..6e6739f 100644 --- a/dhall/src/semantics/core/value.rs +++ b/dhall/src/semantics/core/value.rs @@ -1,13 +1,13 @@ use std::cell::{Ref, RefCell, RefMut}; use std::rc::Rc; -use crate::core::context::TypecheckContext; -use crate::core::valuef::ValueF; -use crate::core::var::{AlphaVar, Shift, Subst}; -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::semantics::core::context::TypecheckContext; +use crate::semantics::core::valuef::ValueF; +use crate::semantics::core::var::{AlphaVar, Shift, Subst}; +use crate::semantics::error::{TypeError, TypeMessage}; +use crate::semantics::phase::normalize::{apply_any, normalize_whnf}; +use crate::semantics::phase::typecheck::{builtin_to_value, const_to_value}; +use crate::semantics::phase::{NormalizedExpr, Typed}; use crate::syntax::{Builtin, Const, Span}; #[derive(Debug, Clone, Copy)] diff --git a/dhall/src/semantics/core/valuef.rs b/dhall/src/semantics/core/valuef.rs index e11d5d7..73c715a 100644 --- a/dhall/src/semantics/core/valuef.rs +++ b/dhall/src/semantics/core/valuef.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; -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::semantics::core::value::{ToExprOptions, Value}; +use crate::semantics::core::var::{AlphaLabel, AlphaVar, Shift, Subst}; +use crate::semantics::phase::typecheck::rc; +use crate::semantics::phase::{Normalized, NormalizedExpr}; use crate::syntax; use crate::syntax::{ Builtin, Const, ExprF, Integer, InterpolatedTextContents, Label, diff --git a/dhall/src/semantics/error/mod.rs b/dhall/src/semantics/error/mod.rs index b2f799d..1288c12 100644 --- a/dhall/src/semantics/error/mod.rs +++ b/dhall/src/semantics/error/mod.rs @@ -1,9 +1,9 @@ use std::io::Error as IOError; -use crate::core::context::TypecheckContext; -use crate::core::value::Value; -use crate::phase::resolve::ImportStack; -use crate::phase::NormalizedExpr; +use crate::semantics::core::context::TypecheckContext; +use crate::semantics::core::value::Value; +use crate::semantics::phase::resolve::ImportStack; +use crate::semantics::phase::NormalizedExpr; use crate::syntax::{BinOp, Import, Label, ParseError, Span}; pub type Result = std::result::Result; diff --git a/dhall/src/semantics/phase/binary.rs b/dhall/src/semantics/phase/binary.rs index a38f08a..9fe31ad 100644 --- a/dhall/src/semantics/phase/binary.rs +++ b/dhall/src/semantics/phase/binary.rs @@ -3,8 +3,8 @@ 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::semantics::error::{DecodeError, EncodeError}; +use crate::semantics::phase::DecodedExpr; use crate::syntax; use crate::syntax::map::DupTreeMap; use crate::syntax::{ diff --git a/dhall/src/semantics/phase/mod.rs b/dhall/src/semantics/phase/mod.rs index 9f38308..0d8fc75 100644 --- a/dhall/src/semantics/phase/mod.rs +++ b/dhall/src/semantics/phase/mod.rs @@ -1,10 +1,10 @@ use std::fmt::Display; use std::path::Path; -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::semantics::core::value::{ToExprOptions, Value}; +use crate::semantics::core::valuef::ValueF; +use crate::semantics::core::var::{AlphaVar, Shift, Subst}; +use crate::semantics::error::{EncodeError, Error, ImportError, TypeError}; use crate::syntax::{Builtin, Const, Expr}; use resolve::ImportRoot; diff --git a/dhall/src/semantics/phase/normalize.rs b/dhall/src/semantics/phase/normalize.rs index 59531bd..81c3ce1 100644 --- a/dhall/src/semantics/phase/normalize.rs +++ b/dhall/src/semantics/phase/normalize.rs @@ -1,9 +1,9 @@ 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::semantics::core::value::Value; +use crate::semantics::core::valuef::ValueF; +use crate::semantics::core::var::{AlphaLabel, AlphaVar, Shift, Subst}; +use crate::semantics::phase::Normalized; use crate::syntax; use crate::syntax::Const::Type; use crate::syntax::{ diff --git a/dhall/src/semantics/phase/parse.rs b/dhall/src/semantics/phase/parse.rs index 601e93d..6e8e8bd 100644 --- a/dhall/src/semantics/phase/parse.rs +++ b/dhall/src/semantics/phase/parse.rs @@ -2,10 +2,10 @@ use std::fs::File; use std::io::Read; use std::path::Path; -use crate::error::Error; -use crate::phase::binary; -use crate::phase::resolve::ImportRoot; -use crate::phase::Parsed; +use crate::semantics::error::Error; +use crate::semantics::phase::binary; +use crate::semantics::phase::resolve::ImportRoot; +use crate::semantics::phase::Parsed; use crate::syntax::parse_expr; pub(crate) fn parse_file(f: &Path) -> Result { diff --git a/dhall/src/semantics/phase/resolve.rs b/dhall/src/semantics/phase/resolve.rs index d0563c0..86dc7ae 100644 --- a/dhall/src/semantics/phase/resolve.rs +++ b/dhall/src/semantics/phase/resolve.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; -use crate::error::{Error, ImportError}; -use crate::phase::{Normalized, NormalizedExpr, Parsed, Resolved}; +use crate::semantics::error::{Error, ImportError}; +use crate::semantics::phase::{Normalized, NormalizedExpr, Parsed, Resolved}; use crate::syntax; use crate::syntax::{FilePath, ImportLocation, URL}; diff --git a/dhall/src/semantics/phase/typecheck.rs b/dhall/src/semantics/phase/typecheck.rs index cc524c4..59380a3 100644 --- a/dhall/src/semantics/phase/typecheck.rs +++ b/dhall/src/semantics/phase/typecheck.rs @@ -1,13 +1,13 @@ use std::cmp::max; use std::collections::HashMap; -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::semantics::core::context::TypecheckContext; +use crate::semantics::core::value::Value; +use crate::semantics::core::valuef::ValueF; +use crate::semantics::core::var::{Shift, Subst}; +use crate::semantics::error::{TypeError, TypeMessage}; +use crate::semantics::phase::normalize::merge_maps; +use crate::semantics::phase::Normalized; use crate::syntax; use crate::syntax::{ Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, RawExpr, Span, diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 1037ef9..9e5c744 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -47,8 +47,8 @@ use std::fs::File; use std::io::{Read, Write}; use std::path::PathBuf; -use crate::error::{Error, Result}; -use crate::phase::Parsed; +use crate::semantics::error::{Error, Result}; +use crate::semantics::phase::Parsed; #[allow(dead_code)] #[derive(Clone)] diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 91b47e5..80ebaf8 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -122,7 +122,7 @@ pub use value::Value; // A Dhall value. pub mod value { - use dhall::phase::{NormalizedExpr, Parsed, Typed}; + use dhall::semantics::phase::{NormalizedExpr, Parsed, Typed}; use dhall::syntax::Builtin; use super::de::{Error, Result}; @@ -138,7 +138,7 @@ pub mod value { fn from_str_using_dhall_error_type( s: &str, ty: Option<&Value>, - ) -> dhall::error::Result { + ) -> dhall::semantics::error::Result { let resolved = Parsed::parse_str(s)?.resolve()?; let typed = match ty { None => resolved.typecheck()?, @@ -193,7 +193,7 @@ pub mod de { pub use error::{Error, Result}; mod error { - use dhall::error::Error as DhallError; + use dhall::semantics::error::Error as DhallError; pub type Result = std::result::Result; diff --git a/serde_dhall/src/serde.rs b/serde_dhall/src/serde.rs index 2972ea2..9006a08 100644 --- a/serde_dhall/src/serde.rs +++ b/serde_dhall/src/serde.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use dhall::phase::NormalizedExpr; +use dhall::semantics::phase::NormalizedExpr; use dhall::syntax::ExprF; use crate::de::{Deserialize, Error, Result}; -- cgit v1.3.1