From f478bc16a3b8414770d84dd87f3e46b869d31750 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Dec 2020 17:16:06 +0000 Subject: Avoid storing an import before we checked its hash --- dhall/src/semantics/resolve/env.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'dhall/src/semantics/resolve/env.rs') diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs index 0d1952b..bde99d1 100644 --- a/dhall/src/semantics/resolve/env.rs +++ b/dhall/src/semantics/resolve/env.rs @@ -95,9 +95,12 @@ impl<'cx> ImportEnv<'cx> { Some(expr) } - /// Invariant: the import must have been fetched. - pub fn check_hash(&self, import: ImportId<'cx>) -> Result<(), Error> { - check_hash(self.cx(), import) + pub fn check_hash( + &self, + import: ImportId<'cx>, + result: ImportResultId<'cx>, + ) -> Result<(), Error> { + check_hash(self.cx(), import, result) } pub fn write_to_mem_cache( @@ -108,12 +111,14 @@ impl<'cx> ImportEnv<'cx> { self.mem_cache.insert(location, result); } - /// Invariant: the import must have been fetched. - pub fn write_to_disk_cache(&self, import: ImportId<'cx>) { - let import = &self.cx()[import]; + pub fn write_to_disk_cache( + &self, + hash: &Option, + result: ImportResultId<'cx>, + ) { if let Some(disk_cache) = self.disk_cache.as_ref() { - if let Some(hash) = &import.import.hash { - let expr = import.unwrap_result(); + if let Some(hash) = hash { + let expr = &self.cx()[result]; let _ = disk_cache.insert(self.cx(), hash, expr); } } -- cgit v1.2.3