From 70508b6a6cff9cd1bb6383be939914edf1fc653a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Dec 2020 19:58:05 +0000 Subject: fix: fix import ordering issue --- dhall/src/semantics/resolve/resolve.rs | 14 +++++++------- dhall/tests/import/success/unit/DontCacheIfHashA.dhall | 2 ++ dhall/tests/import/success/unit/DontCacheIfHashB.dhall | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 dhall/tests/import/success/unit/DontCacheIfHashA.dhall create mode 100644 dhall/tests/import/success/unit/DontCacheIfHashB.dhall (limited to 'dhall') diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs index 116e1a5..2dc1ffe 100644 --- a/dhall/src/semantics/resolve/resolve.rs +++ b/dhall/src/semantics/resolve/resolve.rs @@ -381,13 +381,6 @@ fn fetch_import<'cx>( // If the import is in the in-memory cache, or the hash is in the on-disk cache, return // the cached contents. - if let Some(res_id) = env.get_from_mem_cache(&location) { - // The same location may be used with different or no hashes. Thus we need to check - // the hashes every time. - env.check_hash(import_id, res_id)?; - env.write_to_disk_cache(&import.hash, res_id); - return Ok(res_id); - } if let Some(typed) = env.get_from_disk_cache(&import.hash) { // No need to check the hash, it was checked before reading the file. // We also don't write to the in-memory cache, because the location might be completely @@ -397,6 +390,13 @@ fn fetch_import<'cx>( let res_id = cx.push_import_result(typed); return Ok(res_id); } + if let Some(res_id) = env.get_from_mem_cache(&location) { + // The same location may be used with different or no hashes. Thus we need to check + // the hashes every time. + env.check_hash(import_id, res_id)?; + env.write_to_disk_cache(&import.hash, res_id); + return Ok(res_id); + } // Resolve this import, making sure that recursive imports don't cycle back to the // current one. diff --git a/dhall/tests/import/success/unit/DontCacheIfHashA.dhall b/dhall/tests/import/success/unit/DontCacheIfHashA.dhall new file mode 100644 index 0000000..ed5ffad --- /dev/null +++ b/dhall/tests/import/success/unit/DontCacheIfHashA.dhall @@ -0,0 +1,2 @@ +let x = ../../data/simple.dhall +in ../../data/simple.dhall sha256:3871180b87ecaba8b53fffb2a8b52d3fce98098fab09a6f759358b9e8042eedc diff --git a/dhall/tests/import/success/unit/DontCacheIfHashB.dhall b/dhall/tests/import/success/unit/DontCacheIfHashB.dhall new file mode 100644 index 0000000..660a1cc --- /dev/null +++ b/dhall/tests/import/success/unit/DontCacheIfHashB.dhall @@ -0,0 +1 @@ +λ(_ : Type) → λ(_ : Optional _) → merge { `None` = True, `Some` = λ(_ : _@1) → False } _ -- cgit v1.2.3