summaryrefslogtreecommitdiff
path: root/dhall/src/phase
diff options
context:
space:
mode:
authorFintan Halpenny2019-09-06 12:43:52 +0200
committerFintan Halpenny2019-09-06 12:43:52 +0200
commit4424d3ece5db10527ae446a685a579ae768ef943 (patch)
tree688d29c25f12c2c5347e3d24db8b9b7fb83c7b04 /dhall/src/phase
parent52c91e08db68e05f760ebfd465b84fe4107731df (diff)
parentbcaeab3b7b114d8782be9589ad673ab9ab8c59fd (diff)
Merge remote-tracking branch 'origin/master' into fintan/canonicalize
Diffstat (limited to '')
-rw-r--r--dhall/src/phase/mod.rs4
-rw-r--r--dhall/src/phase/resolve.rs41
2 files changed, 24 insertions, 21 deletions
diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs
index 2c5505c..337ce3d 100644
--- a/dhall/src/phase/mod.rs
+++ b/dhall/src/phase/mod.rs
@@ -16,8 +16,8 @@ pub(crate) mod parse;
pub(crate) mod resolve;
pub(crate) mod typecheck;
-pub type ParsedExpr = Expr<!>;
-pub type DecodedExpr = Expr<!>;
+pub type ParsedExpr = Expr<Normalized>;
+pub type DecodedExpr = Expr<Normalized>;
pub type ResolvedExpr = Expr<Normalized>;
pub type NormalizedExpr = Expr<Normalized>;
diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs
index 4034a5c..cccc7a7 100644
--- a/dhall/src/phase/resolve.rs
+++ b/dhall/src/phase/resolve.rs
@@ -59,18 +59,16 @@ fn load_import(
}
fn do_resolve_expr(
- Parsed(expr, root): Parsed,
+ parsed: Parsed,
import_cache: &mut ImportCache,
import_stack: &ImportStack,
) -> Result<Resolved, ImportError> {
- let resolve = |import: &Import| -> Result<Normalized, ImportError> {
- if import_stack.contains(import) {
- return Err(ImportError::ImportCycle(
- import_stack.clone(),
- import.clone(),
- ));
+ let Parsed(mut expr, root) = parsed;
+ let mut resolve = |import: Import| -> Result<Normalized, ImportError> {
+ if import_stack.contains(&import) {
+ return Err(ImportError::ImportCycle(import_stack.clone(), import));
}
- match import_cache.get(import) {
+ match import_cache.get(&import) {
Some(expr) => Ok(expr.clone()),
None => {
// Copy the import stack and push the current import
@@ -78,16 +76,20 @@ fn do_resolve_expr(
import_stack.push(import.clone());
// Resolve the import recursively
- let expr =
- resolve_import(import, &root, import_cache, &import_stack)?;
+ let expr = resolve_import(
+ &import,
+ &root,
+ import_cache,
+ &import_stack,
+ )?;
// Add the import to the cache
- import_cache.insert(import.clone(), expr.clone());
+ import_cache.insert(import, expr.clone());
Ok(expr)
}
}
};
- let expr = expr.traverse_resolve(resolve)?;
+ expr.traverse_resolve_mut(&mut resolve)?;
Ok(Resolved(expr))
}
@@ -96,12 +98,13 @@ pub(crate) fn resolve(e: Parsed) -> Result<Resolved, ImportError> {
}
pub(crate) fn skip_resolve_expr(
- Parsed(expr, _root): Parsed,
+ parsed: Parsed,
) -> Result<Resolved, ImportError> {
- let resolve = |import: &Import| -> Result<Normalized, ImportError> {
- Err(ImportError::UnexpectedImport(import.clone()))
+ let mut expr = parsed.0;
+ let mut resolve = |import: Import| -> Result<Normalized, ImportError> {
+ Err(ImportError::UnexpectedImport(import))
};
- let expr = expr.traverse_resolve(resolve)?;
+ expr.traverse_resolve_mut(&mut resolve)?;
Ok(Resolved(expr))
}
@@ -201,9 +204,9 @@ mod spec_tests {
// import_success!(success_alternativeEnvNatural, "alternativeEnvNatural");
// import_success!(success_alternativeEnvSimple, "alternativeEnvSimple");
// import_success!(success_alternativeHashMismatch, "alternativeHashMismatch");
- // import_success!(success_alternativeNatural, "alternativeNatural");
- // import_success!(success_alternativeParseError, "alternativeParseError");
- // import_success!(success_alternativeTypeError, "alternativeTypeError");
+ import_success!(success_alternativeNatural, "alternativeNatural");
+ import_success!(success_alternativeParseError, "alternativeParseError");
+ import_success!(success_alternativeTypeError, "alternativeTypeError");
// import_success!(success_asLocation, "asLocation");
// import_success!(success_asText, "asText");
// import_success!(success_customHeaders, "customHeaders");