diff options
Diffstat (limited to '')
-rw-r--r-- | dhall/src/semantics/phase/typecheck.rs (renamed from dhall/src/phase/typecheck.rs) | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/semantics/phase/typecheck.rs index ef8340d..59380a3 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/semantics/phase/typecheck.rs @@ -1,24 +1,25 @@ use std::cmp::max; use std::collections::HashMap; -use dhall_syntax::{ +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, }; -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::Normalized; - fn tck_pi_type( ctx: &TypecheckContext, x: Label, 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(dhall_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 = dhall_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 dhall_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 dhall_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 dhall_syntax::BinOp::*; - use dhall_syntax::Builtin::*; - use dhall_syntax::Const::Type; - use dhall_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(dhall_syntax::Builtin::List, args) + ValueF::AppliedBuiltin(syntax::Builtin::List, args) if args.len() == 1 => {} _ => return mkerr(InvalidListType(t.clone())), } @@ -457,7 +458,7 @@ fn type_last_layer( return mkerr(InvalidListType(t)); } - RetTypeOnly(Value::from_builtin(dhall_syntax::Builtin::List).app(t)) + RetTypeOnly(Value::from_builtin(syntax::Builtin::List).app(t)) } SomeLit(x) => { let t = x.get_type()?; @@ -465,9 +466,7 @@ fn type_last_layer( return mkerr(InvalidOptionalType(t)); } - RetTypeOnly( - Value::from_builtin(dhall_syntax::Builtin::Optional).app(t), - ) + RetTypeOnly(Value::from_builtin(syntax::Builtin::Optional).app(t)) } RecordType(kts) => RetWhole(tck_record_type( ctx, @@ -548,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()?; @@ -589,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 { |