summaryrefslogtreecommitdiff
path: root/dhall/src/semantics/resolve/env.rs
diff options
context:
space:
mode:
authorNadrieril2020-04-06 11:48:28 +0100
committerGitHub2020-04-06 11:48:28 +0100
commitd35cb130d80d628807a4247ddf84a8d0230c87ab (patch)
treeb99dadebeab8094c129cc5d872cfd561f9aa78f3 /dhall/src/semantics/resolve/env.rs
parent4290615769fc26c5e4b70843e7fbfddf6359af41 (diff)
parent12b81d55e1343fc30138d1a13cd48fa2e05744df (diff)
Merge pull request #158 from Nadrieril/hash
Implement semantic hashing (but no caching yet)
Diffstat (limited to 'dhall/src/semantics/resolve/env.rs')
-rw-r--r--dhall/src/semantics/resolve/env.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs
index d7ff0ae..6346a6d 100644
--- a/dhall/src/semantics/resolve/env.rs
+++ b/dhall/src/semantics/resolve/env.rs
@@ -71,7 +71,7 @@ impl ImportEnv {
pub fn handle_import(
&mut self,
- location: ImportLocation,
+ mut location: ImportLocation,
do_resolve: impl FnOnce(&mut Self) -> Result<TypedHir, Error>,
) -> Result<TypedHir, Error> {
if self.stack.contains(&location) {
@@ -82,14 +82,16 @@ impl ImportEnv {
Ok(match self.cache.get(&location) {
Some(expr) => expr.clone(),
None => {
- // Push the current location on the stack
- self.stack.push(location);
-
- // Resolve the import recursively
- let expr = do_resolve(self)?;
-
- // Remove location from the stack.
- let location = self.stack.pop().unwrap();
+ let expr = {
+ // Push the current location on the stack
+ self.stack.push(location);
+ // Resolve the import recursively
+ // WARNING: do not propagate errors here or the stack will get messed up.
+ let result = do_resolve(self);
+ // Remove location from the stack.
+ location = self.stack.pop().unwrap();
+ result
+ }?;
// Add the resolved import to the cache
self.cache.insert(location, expr.clone());