summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
authorNadrieril2019-08-13 19:31:23 +0200
committerNadrieril2019-08-13 19:31:23 +0200
commit5895c3aa6552f75d7e5202be561f9734fe8945e7 (patch)
tree80c4258ce94e82af29bf6a09f483c38601a16b34 /dhall/src
parentcbd62bb57bcc94e0133c57437488a5af22a0b1c2 (diff)
No need to track the absence of `Span`s at the type level
Diffstat (limited to 'dhall/src')
-rw-r--r--dhall/src/phase/binary.rs45
-rw-r--r--dhall/src/phase/mod.rs10
-rw-r--r--dhall/src/phase/parse.rs4
-rw-r--r--dhall/src/phase/typecheck.rs16
4 files changed, 36 insertions, 39 deletions
diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs
index f4a9cc1..3292617 100644
--- a/dhall/src/phase/binary.rs
+++ b/dhall/src/phase/binary.rs
@@ -631,14 +631,12 @@ where
ImportLocation::Remote(url) => {
match &url.headers {
None => ser_seq.serialize_element(&Null)?,
- Some(location_hashed) => {
- ser_seq.serialize_element(&self::Serialize::Expr(
- &SubExpr::from_expr_no_note(ExprF::Embed(Import {
- mode: ImportMode::Code,
- location_hashed: location_hashed.as_ref().clone(),
- })),
- ))?
- }
+ Some(location_hashed) => ser_seq.serialize_element(
+ &self::Serialize::Expr(&rc(ExprF::Embed(Import {
+ mode: ImportMode::Code,
+ location_hashed: location_hashed.as_ref().clone(),
+ }))),
+ )?,
};
ser_seq.serialize_element(&url.authority)?;
for p in &url.path {
@@ -689,13 +687,13 @@ impl<'a> serde::ser::Serialize for Serialize<'a> {
}
}
-fn collect_nested_applications<'a, N, E>(
- e: &'a SubExpr<N, E>,
-) -> (&'a SubExpr<N, E>, Vec<&'a SubExpr<N, E>>) {
- fn go<'a, N, E>(
- e: &'a SubExpr<N, E>,
- vec: &mut Vec<&'a SubExpr<N, E>>,
- ) -> &'a SubExpr<N, E> {
+fn collect_nested_applications<'a, E>(
+ e: &'a SubExpr<E>,
+) -> (&'a SubExpr<E>, Vec<&'a SubExpr<E>>) {
+ fn go<'a, E>(
+ e: &'a SubExpr<E>,
+ vec: &mut Vec<&'a SubExpr<E>>,
+ ) -> &'a SubExpr<E> {
match e.as_ref() {
ExprF::App(f, a) => {
vec.push(a);
@@ -709,16 +707,15 @@ fn collect_nested_applications<'a, N, E>(
(e, vec)
}
-type LetBinding<'a, N, E> =
- (&'a Label, &'a Option<SubExpr<N, E>>, &'a SubExpr<N, E>);
+type LetBinding<'a, E> = (&'a Label, &'a Option<SubExpr<E>>, &'a SubExpr<E>);
-fn collect_nested_lets<'a, N, E>(
- e: &'a SubExpr<N, E>,
-) -> (&'a SubExpr<N, E>, Vec<LetBinding<'a, N, E>>) {
- fn go<'a, N, E>(
- e: &'a SubExpr<N, E>,
- vec: &mut Vec<LetBinding<'a, N, E>>,
- ) -> &'a SubExpr<N, E> {
+fn collect_nested_lets<'a, E>(
+ e: &'a SubExpr<E>,
+) -> (&'a SubExpr<E>, Vec<LetBinding<'a, E>>) {
+ fn go<'a, E>(
+ e: &'a SubExpr<E>,
+ vec: &mut Vec<LetBinding<'a, E>>,
+ ) -> &'a SubExpr<E> {
match e.as_ref() {
ExprF::Let(l, t, v, e) => {
vec.push((l, t, v));
diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs
index 27a6901..8c93889 100644
--- a/dhall/src/phase/mod.rs
+++ b/dhall/src/phase/mod.rs
@@ -2,7 +2,7 @@ use std::borrow::Cow;
use std::fmt::Display;
use std::path::Path;
-use dhall_syntax::{Const, Import, Span, SubExpr, X};
+use dhall_syntax::{Const, Import, SubExpr, X};
use crate::core::thunk::{Thunk, TypedThunk};
use crate::core::value::Value;
@@ -17,10 +17,10 @@ pub(crate) mod parse;
pub(crate) mod resolve;
pub(crate) mod typecheck;
-pub type ParsedSubExpr = SubExpr<Span, Import>;
-pub type DecodedSubExpr = SubExpr<X, Import>;
-pub type ResolvedSubExpr = SubExpr<Span, Normalized>;
-pub type NormalizedSubExpr = SubExpr<X, X>;
+pub type ParsedSubExpr = SubExpr<Import>;
+pub type DecodedSubExpr = SubExpr<Import>;
+pub type ResolvedSubExpr = SubExpr<Normalized>;
+pub type NormalizedSubExpr = SubExpr<X>;
#[derive(Debug, Clone)]
pub struct Parsed(ParsedSubExpr, ImportRoot);
diff --git a/dhall/src/phase/parse.rs b/dhall/src/phase/parse.rs
index 734f6e1..9f3f2f4 100644
--- a/dhall/src/phase/parse.rs
+++ b/dhall/src/phase/parse.rs
@@ -25,7 +25,7 @@ pub fn parse_str(s: &str) -> Result<Parsed, Error> {
pub fn parse_binary(data: &[u8]) -> Result<Parsed, Error> {
let expr = crate::phase::binary::decode(data)?;
let root = ImportRoot::LocalDir(std::env::current_dir()?);
- Ok(Parsed(expr.note_absurd(), root))
+ Ok(Parsed(expr, root))
}
pub fn parse_binary_file(f: &Path) -> Result<Parsed, Error> {
@@ -33,5 +33,5 @@ pub fn parse_binary_file(f: &Path) -> Result<Parsed, Error> {
File::open(f)?.read_to_end(&mut buffer)?;
let expr = crate::phase::binary::decode(&buffer)?;
let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned());
- Ok(Parsed(expr.note_absurd(), root))
+ Ok(Parsed(expr, root))
}
diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs
index a19e1ca..ecf9793 100644
--- a/dhall/src/phase/typecheck.rs
+++ b/dhall/src/phase/typecheck.rs
@@ -1,8 +1,8 @@
use std::collections::HashMap;
use dhall_syntax::{
- rc, Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, Span,
- SubExpr, X,
+ rc, Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, SubExpr,
+ X,
};
use crate::core::context::{NormalizationContext, TypecheckContext};
@@ -214,7 +214,7 @@ macro_rules! make_type {
};
}
-fn type_of_builtin(b: Builtin) -> Expr<X, X> {
+fn type_of_builtin(b: Builtin) -> Expr<X> {
use dhall_syntax::Builtin::*;
match b {
Bool | Natural | Integer | Double | Text => make_type!(Type),
@@ -303,7 +303,7 @@ fn type_of_builtin(b: Builtin) -> Expr<X, X> {
/// and turn it into a type, typechecking it along the way.
pub fn mktype(
ctx: &TypecheckContext,
- e: SubExpr<Span, Normalized>,
+ e: SubExpr<Normalized>,
) -> Result<Type, TypeError> {
Ok(type_with(ctx, e)?.to_type())
}
@@ -326,7 +326,7 @@ enum Ret {
/// normalized as well.
fn type_with(
ctx: &TypecheckContext,
- e: SubExpr<Span, Normalized>,
+ e: SubExpr<Normalized>,
) -> Result<Typed, TypeError> {
use dhall_syntax::ExprF::{Annot, Embed, Lam, Let, Pi, Var};
@@ -1002,7 +1002,7 @@ fn type_last_layer(
/// `typeOf` is the same as `type_with` with an empty context, meaning that the
/// expression must be closed (i.e. no free variables), otherwise type-checking
/// will fail.
-fn type_of(e: SubExpr<Span, Normalized>) -> Result<Typed, TypeError> {
+fn type_of(e: SubExpr<Normalized>) -> Result<Typed, TypeError> {
let ctx = TypecheckContext::new();
let e = type_with(&ctx, e)?;
// Ensure `e` has a type (i.e. `e` is not `Sort`)
@@ -1015,8 +1015,8 @@ pub fn typecheck(e: Resolved) -> Result<Typed, TypeError> {
}
pub fn typecheck_with(e: Resolved, ty: &Type) -> Result<Typed, TypeError> {
- let expr: SubExpr<_, _> = e.0;
- let ty: SubExpr<_, _> = ty.to_expr().absurd();
+ let expr: SubExpr<_> = e.0;
+ let ty: SubExpr<_> = ty.to_expr().absurd();
type_of(expr.rewrap(ExprF::Annot(expr.clone(), ty)))
}
pub fn skip_typecheck(e: Resolved) -> Typed {