diff --git a/package.yaml b/package.yaml index 6106a7921..6856ee957 100644 --- a/package.yaml +++ b/package.yaml @@ -56,7 +56,7 @@ library: - bytestring - Cabal - containers - - dhall + - dhall >= 1.28.0 - directory >= 1.3.4.0 - either - exceptions diff --git a/src/Spago/Config.hs b/src/Spago/Config.hs index e4bc8e70b..c5f4efed4 100644 --- a/src/Spago/Config.hs +++ b/src/Spago/Config.hs @@ -71,13 +71,13 @@ isLocationType (Dhall.Union kvs) | locationUnionMap == Dhall.Map.toMap kvs = Tru isLocationType _ = False -dependenciesType :: Dhall.Type [PackageName] -dependenciesType = Dhall.list (Dhall.auto :: Dhall.Type PackageName) +dependenciesType :: Dhall.Decoder [PackageName] +dependenciesType = Dhall.list (Dhall.auto :: Dhall.Decoder PackageName) parsePackage :: (MonadIO m, MonadThrow m, MonadReader env m, HasLogFunc env) => ResolvedExpr -> m Package parsePackage (Dhall.RecordLit ks) = do - repo <- Dhall.requireTypedKey ks "repo" (Dhall.auto :: Dhall.Type PackageSet.Repo) + repo <- Dhall.requireTypedKey ks "repo" (Dhall.auto :: Dhall.Decoder PackageSet.Repo) version <- Dhall.requireTypedKey ks "version" Dhall.strictText dependencies <- Dhall.requireTypedKey ks "dependencies" dependenciesType let location = PackageSet.Remote{..} @@ -121,7 +121,7 @@ parseConfig = do $ traverse parsePackage pkgs something -> throwM $ Dhall.PackagesIsNotRecord something) - let sourcesType = Dhall.list (Dhall.auto :: Dhall.Type Purs.SourcePath) + let sourcesType = Dhall.list (Dhall.auto :: Dhall.Decoder Purs.SourcePath) name <- Dhall.requireTypedKey ks "name" Dhall.strictText dependencies <- Dhall.requireTypedKey ks "dependencies" dependenciesType configSourcePaths <- Dhall.requireTypedKey ks "sources" sourcesType diff --git a/src/Spago/Dhall.hs b/src/Spago/Dhall.hs index 101e346cb..e1c401b3d 100644 --- a/src/Spago/Dhall.hs +++ b/src/Spago/Dhall.hs @@ -11,7 +11,7 @@ import qualified Data.Text as Text import qualified Data.Text.Prettyprint.Doc as Pretty import qualified Data.Text.Prettyprint.Doc.Render.Text as PrettyText import Dhall -import Dhall.Core as Dhall hiding (Type, pretty) +import Dhall.Core as Dhall hiding (pretty) import qualified Dhall.Format import qualified Dhall.Import import qualified Dhall.Map @@ -83,7 +83,7 @@ readRawExpr pathText = do if exists then (do packageSetText <- readTextFile $ pathFromText pathText - fmap Just $ throws $ Parser.exprAndHeaderFromText mempty packageSetText) + fmap (\(Header text, expr) -> Just (text, expr)) $ throws $ Parser.exprAndHeaderFromText mempty packageSetText) else pure Nothing @@ -124,24 +124,24 @@ requireKey ks name f = case Dhall.Map.lookup name ks of Nothing -> throwM (RequiredKeyMissing name ks) --- | Same as `requireKey`, but we give it a Dhall.Type to automagically decode from +-- | Same as `requireKey`, but we give it a Dhall.Decoder to automagically decode from requireTypedKey :: (MonadIO m, MonadThrow m) => Dhall.Map.Map Text (DhallExpr Void) -> Text - -> Dhall.Type a + -> Dhall.Decoder a -> m a requireTypedKey ks name typ = requireKey ks name $ \expr -> case Dhall.extract typ expr of Success v -> pure v Failure _ -> throwM $ RequiredKeyMissing name ks --- | Try to find a key from a Dhall.Map, and automagically decode the value with the given Dhall.Type +-- | Try to find a key from a Dhall.Map, and automagically decode the value with the given Dhall.Decode -- If not found, return `Nothing`, if type is incorrect throw error maybeTypedKey :: (MonadIO m, MonadThrow m) => Dhall.Map.Map Text (DhallExpr Void) -> Text - -> Dhall.Type a + -> Dhall.Decoder a -> m (Maybe a) maybeTypedKey ks name typ = typify `mapM` Dhall.Map.lookup name ks where @@ -150,14 +150,14 @@ maybeTypedKey ks name typ = typify `mapM` Dhall.Map.lookup name ks Failure a -> throwM a --- | Convert a Dhall expression to a given Dhall type +-- | Convert a Dhall expression to a given Dhall decoder -- --- We first annotate the expression with the Dhall type we want to get, +-- We first annotate the expression with the Dhall decoder we want to get, -- then try to typecheck it. We then need to run `Dhall.extract` on the -- result of the normalization (we need to normalize so that extract can work) -- and return a `Right` only if both typecheck and normalization succeeded. coerceToType - :: Type a -> DhallExpr Void -> Either (ReadError Void) a + :: Dhall.Decoder a -> DhallExpr Void -> Either (ReadError Void) a coerceToType typ expr = do let annot = Dhall.Annot expr $ Dhall.expected typ let checkedType = typeOf annot @@ -169,7 +169,7 @@ coerceToType typ expr = do -- | Spago configuration cannot be read data ReadError a where -- | a package has the wrong type - WrongType :: Typeable a => Dhall.Type b -> DhallExpr a -> ReadError a + WrongType :: Typeable a => Dhall.Decoder b -> DhallExpr a -> ReadError a -- | the toplevel value is not a record ConfigIsNotRecord :: Typeable a => DhallExpr a -> ReadError a -- | the "packages" key is not a record diff --git a/stack.yaml b/stack.yaml index 25f66bb0d..d6928daa6 100644 --- a/stack.yaml +++ b/stack.yaml @@ -2,7 +2,8 @@ resolver: lts-12.21 packages: - . extra-deps: -- dhall-1.27.0 +- dhall-1.28.0 +- atomic-write-0.2.0.7 - github-0.23 - async-pool-0.9.0.2@sha256:3aca5861a7b839d02a3f5c52ad6d1ce368631003f68c3d9cb6d711c29e9618db,1599 - binary-instances-1@sha256:cdef50410f2797de38f021d328d38c32b2f4abeaab86bfaf78e0657150863090,2613 diff --git a/stack.yaml.lock b/stack.yaml.lock index 626235c4e..34abb5701 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -5,12 +5,19 @@ packages: - completed: - hackage: dhall-1.27.0@sha256:b522d6b534949e65771ed0179afc1488e4de2b185af5ed38e4806a6720db51bf,30519 + hackage: dhall-1.28.0@sha256:a0b38be83ab76c59adf6d67868b9b183591edc68d2c3727d38598ddc12c36c95,31625 pantry-tree: - size: 232998 - sha256: 3f79ba6a3eeb0f59c1cf41663d65eebe71f5780f5765169e3d52406789a6f286 + size: 241424 + sha256: 8c92a349408edf2c72760025740b4950cd0a1d2ce0ba393333332c1bbc469967 original: - hackage: dhall-1.27.0 + hackage: dhall-1.28.0 +- completed: + hackage: atomic-write-0.2.0.7@sha256:3b626dfbc288cd070f1ac31b1c15ddd49822a923778ffe21f92b2116ffc72dc3,4584 + pantry-tree: + size: 2237 + sha256: b49d642f11c9eade41fac2c52dc34aadb093fd48139418c001e19d7ab1ae6696 + original: + hackage: atomic-write-0.2.0.7 - completed: hackage: github-0.23@sha256:07671c92da7142668ecdeaa5669ddda629ae85f25acd2ecadd49f9a119a5eac6,6965 pantry-tree: