Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build on ghc-9.2.4 #307

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ghc: ["8.10.7"]
ghc: ["8.10.7", "9.2.4"]
os: [ubuntu-latest, macos-latest, windows-latest]

env:
Expand Down
2 changes: 1 addition & 1 deletion base-deriving-via/base-deriving-via.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ library
Data.DerivingVia.GHC.Generics.Monoid
Data.DerivingVia.GHC.Generics.Semigroup

build-depends: base >= 4.14
build-depends: base
2 changes: 1 addition & 1 deletion binary/cardano-binary.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ flag development
default: False
manual: True

common base { build-depends: base >= 4.14 && < 4.15 }
common base { build-depends: base >= 4.14 && < 4.17 }

common project-config
default-language: Haskell2010
Expand Down
12 changes: 10 additions & 2 deletions binary/src/Cardano/Binary/FromCBOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import Codec.CBOR.ByteArray as BA
import qualified Codec.CBOR.Read as CBOR.Read
import qualified Data.ByteString.Lazy as BS.Lazy
import qualified Data.ByteString.Short as SBS
import qualified Data.ByteString.Short.Internal as SBS
import qualified Data.Primitive.ByteArray as Prim
import Data.ByteString.Short.Internal (ShortByteString (SBS))
import Data.Fixed (Fixed(..), Nano, Pico)
import qualified Data.Map as M
import qualified Data.Set as S
Expand Down Expand Up @@ -297,7 +297,7 @@ instance FromCBOR LByteString where
instance FromCBOR SBS.ShortByteString where
fromCBOR = do
BA.BA (Prim.ByteArray ba) <- D.decodeByteArray
return $ SBS.SBS ba
return $ SBS ba

instance FromCBOR a => FromCBOR [a] where
fromCBOR = decodeListWith fromCBOR
Expand Down Expand Up @@ -477,3 +477,11 @@ instance FromCBOR UTCTime where
return $ UTCTime
(fromOrdinalDate year dayOfYear)
(picosecondsToDiffTime timeOfDayPico)

-- -- | Convert an 'Either'-encoded failure to a 'cborg' decoder failure
-- toCborError :: B.Buildable e => Either e a -> D.Decoder s a
-- toCborError = either cborError pure

-- -- | Convert a @Buildable@ error into a 'cborg' decoder error
-- cborError :: B.Buildable e => e -> D.Decoder s a
-- cborError = fail . formatToString build
4 changes: 2 additions & 2 deletions binary/src/Cardano/Binary/ToCBOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import Codec.CBOR.Encoding as E
import Codec.CBOR.ByteArray.Sliced as BAS
import qualified Data.ByteString.Lazy as BS.Lazy
import qualified Data.ByteString.Short as SBS
import qualified Data.ByteString.Short.Internal as SBS
import Data.ByteString.Short.Internal (ShortByteString (SBS))
import qualified Data.Primitive.ByteArray as Prim
import Data.Fixed (E12, Fixed(..), Nano, Pico, resolution)
#if MIN_VERSION_recursion_schemes(5,2,0)
Expand Down Expand Up @@ -574,7 +574,7 @@ instance ToCBOR Text.Text where
in bsLength + apMono "withWordSize" withWordSize bsLength

instance ToCBOR SBS.ShortByteString where
toCBOR sbs@(SBS.SBS ba) =
toCBOR sbs@(SBS ba) =
E.encodeByteArray $ BAS.SBA (Prim.ByteArray ba) 0 (SBS.length sbs)

encodedSizeExpr size _ =
Expand Down
2 changes: 1 addition & 1 deletion binary/test/cardano-binary-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ flag development
default: False
manual: True

common base { build-depends: base >= 4.14 && < 4.15 }
common base { build-depends: base >= 4.14 && < 4.17 }

common project-config
default-language: Haskell2010
Expand Down
58 changes: 55 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
index-state: 2022-02-18T00:00:00Z
index-state: 2022-09-10T00:00:00Z

-- Ensures colourized output from tasty
test-show-details: direct
Expand All @@ -10,6 +10,7 @@ packages:
cardano-crypto-class
cardano-crypto-praos
cardano-crypto-tests
heapwords
measures
orphans-deriving-via
slotting
Expand All @@ -19,11 +20,21 @@ packages:
package cardano-crypto
tests: False

source-repository-package
type: git
location: https://github.com/well-typed/canonical-json
tag: 8a37c22f0ce4759b4d534a4019a473e8225f3477

source-repository-package
type: git
location: https://github.com/input-output-hk/nothunks
tag: 45d066c4f47400e645bda7dc0ffe5070bd2baf42

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-prelude
tag: fd773f7a58412131512b9f694ab95653ac430852
--sha256: 02jddik1yw0222wd6q0vv10f7y8rdgrlqaiy83ph002f9kjx7mh6
tag: 2f40068cc2162683f47637a75f4594496f0f33a0
--sha256: 04h8n0m93rgr8xcynypjh6mc7kmb450c17cfvpyzpa36yld599fy
subdir:
cardano-prelude
cardano-prelude-test
Expand All @@ -33,3 +44,44 @@ source-repository-package
location: https://github.com/input-output-hk/cardano-crypto
tag: 2547ad1e80aeabca2899951601079408becbc92c
--sha256: 1p2kg2w02q5w1cvqzhfhqmxviy4xrzada3mmb096j2n6hfr20kri

allow-newer:
*:base,
*:basement,
*:containers,
-- *:ghc-prim,
*:memory,
*:protolude,

source-repository-package
type: git
location: https://github.com/protolude/protolude
tag: cd83ebec004a6d44b60a2c87e13759365ff2d9a5

source-repository-package
type: git
location: https://github.com/well-typed/cborg
tag: c31a1c007a00dc1c393580e7702a9ac6b73b8225
subdir:
cborg
serialise

source-repository-package
type: git
location: https://github.com/haskell-foundation/foundation
tag: 39985b94b4de4d02e8decb5e378b53ad3f72c0cc
subdir:
basement

package process
ghc-options: -Wno-error
-- tests: False

-- source-repository-package
-- type: git
-- location: https://github.com/newhoggy/process
-- tag: f20cf8fa19dc9c63f3490135f1b652e4d95a0cd5
-- post-checkout-command: autoreconf -i

package cardano-crypto-class
ghc-options: -Wno-unused-packages
15 changes: 11 additions & 4 deletions cardano-crypto-class/cardano-crypto-class.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ flag secp256k1-support
default: True
manual: True

common base
build-depends: base ^>=4.14
common base { build-depends: base >= 4.14 && < 4.17 }

common project-config
default-language: Haskell2010
Expand Down Expand Up @@ -102,16 +101,24 @@ library
, cardano-prelude
, cryptonite
, deepseq
, ghc-prim
, integer-gmp
-- , ghc-prim
-- , integer-gmp
, heapwords
, memory
, nothunks
, primitive
, serialise
-- , strict-containers
, template-haskell
, th-compat
, text
, transformers
, vector

if impl(ghc < 9.0.0)
build-depends:
integer-gmp

pkgconfig-depends: libsodium -any

if flag(secp256k1-support)
Expand Down
42 changes: 41 additions & 1 deletion cardano-crypto-class/src/Cardano/Crypto/Hash/Class.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
Expand Down Expand Up @@ -71,6 +73,8 @@ import Data.String (IsString(..))
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Language.Haskell.TH.Syntax (Q, TExp(..))
import Language.Haskell.TH.Syntax.Compat (examineSplice)

import Data.Aeson (FromJSON(..), FromJSONKey(..), ToJSON(..), ToJSONKey(..))
import qualified Data.Aeson as Aeson
Expand All @@ -83,10 +87,12 @@ import NoThunks.Class (NoThunks)
import Cardano.Binary (Encoding, FromCBOR(..), Size, ToCBOR(..), decodeBytes,
serializeEncoding')
import Cardano.Crypto.PackedBytes
import Cardano.Prelude (HeapWords (..))
import Cardano.HeapWords (HeapWords (..))

import qualified Data.ByteString.Short.Internal as SBSI

import Cardano.Crypto.Util (decodeHexString)

class (KnownNat (SizeHash h), Typeable h) => HashAlgorithm h where
--TODO: eliminate this Typeable constraint needed only for the ToCBOR
-- the ToCBOR should not need it either
Expand All @@ -105,10 +111,44 @@ sizeHash _ = fromInteger (natVal (Proxy @(SizeHash h)))
newtype Hash h a = UnsafeHashRep (PackedBytes (SizeHash h))
deriving (Eq, Ord, Generic, NoThunks, NFData)

-- | This instance is meant to be used with @TemplateHaskell@
--
-- >>> import Cardano.Crypto.Hash.Class (Hash)
-- >>> import Cardano.Crypto.Hash.Short (ShortHash)
-- >>> :set -XTemplateHaskell
-- >>> :set -XOverloadedStrings
-- >>> let hash = $$("0xBADC0FFEE0DDF00D") :: Hash ShortHash ()
-- >>> print hash
-- "badc0ffee0ddf00d"
-- >>> let hash = $$("0123456789abcdef") :: Hash ShortHash ()
-- >>> print hash
-- "0123456789abcdef"
-- >>> let hash = $$("deadbeef") :: Hash ShortHash ()
-- <interactive>:5:15: error:
-- • <Hash blake2b_prefix_8>: Expected in decoded form to be: 8 bytes, but got: 4
-- • In the Template Haskell splice $$("deadbeef")
-- In the expression: $$("deadbeef") :: Hash ShortHash ()
-- In an equation for ‘hash’:
-- hash = $$("deadbeef") :: Hash ShortHash ()
-- >>> let hash = $$("123") :: Hash ShortHash ()
-- <interactive>:6:15: error:
-- • <Hash blake2b_prefix_8>: Malformed hex: invalid bytestring size
-- • In the Template Haskell splice $$("123")
-- In the expression: $$("123") :: Hash ShortHash ()
-- In an equation for ‘hash’: hash = $$("123") :: Hash ShortHash ()
instance HashAlgorithm h => IsString (Q (TExp (Hash h a))) where
fromString hexStr = do
let n = fromInteger $ natVal (Proxy @(SizeHash h))
case decodeHexString hexStr n of
Left err -> fail $ "<Hash " ++ hashAlgorithmName (Proxy :: Proxy h) ++ ">: " ++ err
Right _ -> examineSplice [|| either error (UnsafeHashRep . packPinnedBytes) (decodeHexString hexStr n) ||]


pattern UnsafeHash :: forall h a. HashAlgorithm h => ShortByteString -> Hash h a
pattern UnsafeHash bytes <- UnsafeHashRep (unpackBytes -> bytes)
where
UnsafeHash bytes =

case hashFromBytesShort bytes of
Nothing ->
error "UnsafeHash: mismatched size of the supplied ShortByteString and the expected digest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module Cardano.Crypto.KES.CompactSingle (
) where

import Data.Proxy (Proxy(..))
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
import qualified Data.ByteString as BS
Expand All @@ -70,7 +69,7 @@ deriving newtype instance NFData (SignKeyDSIGN d) => NFData (SignKeyKES (Compact

deriving anyclass instance (NFData (SigDSIGN d), NFData (VerKeyDSIGN d)) => NFData (SigKES (CompactSingleKES d))

instance (DSIGNAlgorithm d, Typeable d) => KESAlgorithm (CompactSingleKES d) where
instance DSIGNAlgorithm d => KESAlgorithm (CompactSingleKES d) where
type SeedSizeKES (CompactSingleKES d) = SeedSizeDSIGN d

--
Expand Down
15 changes: 7 additions & 8 deletions cardano-crypto-class/src/Cardano/Crypto/KES/CompactSum.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ module Cardano.Crypto.KES.CompactSum (
) where

import Data.Proxy (Proxy(..))
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import qualified Data.ByteString as BS
import Control.Monad (guard)
Expand Down Expand Up @@ -131,7 +130,7 @@ instance (NFData (SigKES d), NFData (VerKeyKES d)) =>
instance (NFData (SignKeyKES d), NFData (VerKeyKES d)) =>
NFData (SignKeyKES (CompactSumKES h d)) where

instance (OptimizedKESAlgorithm d, HashAlgorithm h, Typeable d)
instance (OptimizedKESAlgorithm d, HashAlgorithm h)
=> KESAlgorithm (CompactSumKES h d) where

type SeedSizeKES (CompactSumKES h d) = SeedSizeKES d
Expand Down Expand Up @@ -329,12 +328,12 @@ deriving instance Eq (VerKeyKES (CompactSumKES h d))

instance (KESAlgorithm d) => NoThunks (SignKeyKES (CompactSumKES h d))

instance (OptimizedKESAlgorithm d, HashAlgorithm h, Typeable d)
instance (OptimizedKESAlgorithm d, HashAlgorithm h)
=> ToCBOR (VerKeyKES (CompactSumKES h d)) where
toCBOR = encodeVerKeyKES
encodedSizeExpr _size = encodedVerKeyKESSizeExpr

instance (OptimizedKESAlgorithm d, HashAlgorithm h, Typeable d)
instance (OptimizedKESAlgorithm d, HashAlgorithm h)
=> FromCBOR (VerKeyKES (CompactSumKES h d)) where
fromCBOR = decodeVerKeyKES

Expand All @@ -347,12 +346,12 @@ deriving instance KESAlgorithm d => Show (SignKeyKES (CompactSumKES h d))

instance (OptimizedKESAlgorithm d) => NoThunks (VerKeyKES (CompactSumKES h d))

instance (OptimizedKESAlgorithm d, HashAlgorithm h, Typeable d)
instance (OptimizedKESAlgorithm d, HashAlgorithm h)
=> ToCBOR (SignKeyKES (CompactSumKES h d)) where
toCBOR = encodeSignKeyKES
encodedSizeExpr _size = encodedSignKeyKESSizeExpr

instance (OptimizedKESAlgorithm d, HashAlgorithm h, Typeable d)
instance (OptimizedKESAlgorithm d, HashAlgorithm h)
=> FromCBOR (SignKeyKES (CompactSumKES h d)) where
fromCBOR = decodeSignKeyKES

Expand All @@ -366,11 +365,11 @@ deriving instance KESAlgorithm d => Eq (SigKES (CompactSumKES h d))

instance KESAlgorithm d => NoThunks (SigKES (CompactSumKES h d))

instance (OptimizedKESAlgorithm d, HashAlgorithm h, Typeable d)
instance (OptimizedKESAlgorithm d, HashAlgorithm h)
=> ToCBOR (SigKES (CompactSumKES h d)) where
toCBOR = encodeSigKES
encodedSizeExpr _size = encodedSigKESSizeExpr

instance (OptimizedKESAlgorithm d, HashAlgorithm h, Typeable d)
instance (OptimizedKESAlgorithm d, HashAlgorithm h)
=> FromCBOR (SigKES (CompactSumKES h d)) where
fromCBOR = decodeSigKES
Loading