Skip to content

Commit

Permalink
Fix dhall freeze --cache to support v21.0.0 (dhall-lang#2350)
Browse files Browse the repository at this point in the history
Fixes dhall-lang#2347

This now uses `missing sha256:…` for the frozen import so that the
import still succeeds even if the hash doesn't match (which was the
original intention of the `--cached` flag; otherwise it would be
useless).
  • Loading branch information
Gabriella439 authored Dec 15, 2021
1 parent c616a62 commit 0af9841
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
14 changes: 12 additions & 2 deletions dhall/src/Dhall/Freeze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ freezeExpression
-> IO (Expr s Import)
freezeExpression = freezeExpressionWithManager Dhall.Import.defaultNewManager

-- https://github.com/dhall-lang/dhall-haskell/issues/2347
toMissing :: Import -> Import
toMissing import_ =
import_ { importHashed = (importHashed import_) { importType = Missing } }


-- | See 'freezeExpression'.
freezeExpressionWithManager
:: IO Dhall.Import.Manager
Expand Down Expand Up @@ -315,17 +321,21 @@ freezeExpressionWithManager newManager directory scope intent expression = do
(Embed import_@(Import { importHashed = ImportHashed { hash = Nothing } })) = do
frozenImport <- freezeFunction import_

let frozenMissing = toMissing frozenImport

{- The two imports can be the same if the import is local and
`freezeFunction` only freezes remote imports by default
-}
if frozenImport /= import_
then return (ImportAlt (Embed frozenImport) (Embed import_))
then return (ImportAlt (Embed frozenMissing) (Embed import_))
else return (Embed import_)
cache
(Embed import_@(Import { importHashed = ImportHashed { hash = Just _ } })) = do
-- Regenerate the integrity check, just in case it's wrong
frozenImport <- freezeFunction import_

let frozenMissing = toMissing frozenImport

-- `dhall freeze --cache` also works the other way around, adding an
-- unprotected fallback import to imports that are already
-- protected
Expand All @@ -335,7 +345,7 @@ freezeExpressionWithManager newManager directory scope intent expression = do
}
}

return (ImportAlt (Embed frozenImport) (Embed thawedImport))
return (ImportAlt (Embed frozenMissing) (Embed thawedImport))
cache expression_ =
return expression_

Expand Down
2 changes: 1 addition & 1 deletion dhall/tests/freeze/cachedB.dhall
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
./True.dhall
missing
sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70
? ./True.dhall
2 changes: 1 addition & 1 deletion dhall/tests/freeze/incorrectHashB.dhall
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
./True.dhall
missing
sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70
? ./True.dhall
2 changes: 1 addition & 1 deletion dhall/tests/freeze/protectedB.dhall
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
./True.dhall
missing
sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70
? ./True.dhall
2 changes: 1 addition & 1 deletion dhall/tests/freeze/unprotectedB.dhall
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
./True.dhall
missing
sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70
? ./True.dhall
4 changes: 4 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ nix:
packages:
- ncurses
- zlib
flags:
# https://github.com/RyanGlScott/mintty/issues/4
mintty:
Win32-2-13-1: false

0 comments on commit 0af9841

Please sign in to comment.