{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
-- Needed for a ToADTArbitrary on VCObjectHash
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Inferno.Types.VersionControl where

import Control.DeepSeq (NFData)
import Crypto.Hash (Context, Digest, digestFromByteString, hash, hashFinalize, hashInit, hashUpdate)
import Crypto.Hash.Algorithms (SHA256)
import Data.Aeson (FromJSON (..), FromJSONKey, ToJSON (..), ToJSONKey, withText)
import Data.ByteArray (ByteArrayAccess, convert)
import Data.ByteArray.Pack (fill, putStorable)
import Data.ByteString (ByteString, pack)
import qualified Data.ByteString.Base64.URL as Base64
import qualified Data.ByteString.Char8 as Char8
import Data.Data (Data)
import Data.Hashable (Hashable (hashWithSalt))
import Data.Int (Int32, Int64)
import qualified Data.IntMap as IntMap
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Text (Text, unpack)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Data.Word (Word32, Word64)
import Foreign.C.Types (CTime (..))
import Foreign.Storable (sizeOf)
import GHC.Generics (C1, Constructor, D1, Generic, K1 (..), M1 (..), Rec1 (..), Rep, S1, U1, conName, from, (:*:) (..), (:+:) (..))
import Inferno.Types.Syntax
  ( Comment (..),
    Expr (..),
    ExtIdent (..),
    Fixity,
    IStr (..),
    Ident (..),
    ImplExpl (..),
    Import (..),
    InfixFixity,
    Lit (..),
    ModuleName (..),
    Pat (..),
    Scoped (..),
    SomeIStr (..),
    TList,
    tListToList,
  )
import Inferno.Types.Type
  ( BaseType (..),
    ImplType (..),
    InfernoType (..),
    Namespace,
    TCScheme (..),
    TV (..),
    TypeClass (..),
    TypeMetadata (..),
  )
import Servant.API (FromHttpApiData (..), ToHttpApiData (..))
import Test.QuickCheck.Arbitrary (Arbitrary (..))
import Test.QuickCheck.Arbitrary.ADT
import Text.Megaparsec (SourcePos)

newtype VCObjectHash = VCObjectHash {VCObjectHash -> Digest SHA256
vcObjectHashDigest :: Digest SHA256}
  deriving stock (forall x. Rep VCObjectHash x -> VCObjectHash
forall x. VCObjectHash -> Rep VCObjectHash x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VCObjectHash x -> VCObjectHash
$cfrom :: forall x. VCObjectHash -> Rep VCObjectHash x
Generic, Typeable VCObjectHash
VCObjectHash -> DataType
VCObjectHash -> Constr
(forall b. Data b => b -> b) -> VCObjectHash -> VCObjectHash
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> VCObjectHash -> u
forall u. (forall d. Data d => d -> u) -> VCObjectHash -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VCObjectHash -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VCObjectHash -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VCObjectHash -> m VCObjectHash
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VCObjectHash -> m VCObjectHash
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VCObjectHash
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VCObjectHash -> c VCObjectHash
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VCObjectHash)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VCObjectHash)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VCObjectHash -> m VCObjectHash
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VCObjectHash -> m VCObjectHash
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VCObjectHash -> m VCObjectHash
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VCObjectHash -> m VCObjectHash
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VCObjectHash -> m VCObjectHash
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VCObjectHash -> m VCObjectHash
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> VCObjectHash -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> VCObjectHash -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> VCObjectHash -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> VCObjectHash -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VCObjectHash -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VCObjectHash -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VCObjectHash -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VCObjectHash -> r
gmapT :: (forall b. Data b => b -> b) -> VCObjectHash -> VCObjectHash
$cgmapT :: (forall b. Data b => b -> b) -> VCObjectHash -> VCObjectHash
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VCObjectHash)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VCObjectHash)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VCObjectHash)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VCObjectHash)
dataTypeOf :: VCObjectHash -> DataType
$cdataTypeOf :: VCObjectHash -> DataType
toConstr :: VCObjectHash -> Constr
$ctoConstr :: VCObjectHash -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VCObjectHash
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VCObjectHash
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VCObjectHash -> c VCObjectHash
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VCObjectHash -> c VCObjectHash
Data)
  deriving anyclass (ToJSONKeyFunction [VCObjectHash]
ToJSONKeyFunction VCObjectHash
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
toJSONKeyList :: ToJSONKeyFunction [VCObjectHash]
$ctoJSONKeyList :: ToJSONKeyFunction [VCObjectHash]
toJSONKey :: ToJSONKeyFunction VCObjectHash
$ctoJSONKey :: ToJSONKeyFunction VCObjectHash
ToJSONKey, FromJSONKeyFunction [VCObjectHash]
FromJSONKeyFunction VCObjectHash
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
fromJSONKeyList :: FromJSONKeyFunction [VCObjectHash]
$cfromJSONKeyList :: FromJSONKeyFunction [VCObjectHash]
fromJSONKey :: FromJSONKeyFunction VCObjectHash
$cfromJSONKey :: FromJSONKeyFunction VCObjectHash
FromJSONKey, VCObjectHash -> ()
forall a. (a -> ()) -> NFData a
rnf :: VCObjectHash -> ()
$crnf :: VCObjectHash -> ()
NFData, Proxy VCObjectHash -> Gen (ADTArbitrarySingleton VCObjectHash)
Proxy VCObjectHash -> Gen (ADTArbitrary VCObjectHash)
forall a.
(Proxy a -> Gen (ADTArbitrarySingleton a))
-> (Proxy a -> Gen (ADTArbitrary a)) -> ToADTArbitrary a
toADTArbitrary :: Proxy VCObjectHash -> Gen (ADTArbitrary VCObjectHash)
$ctoADTArbitrary :: Proxy VCObjectHash -> Gen (ADTArbitrary VCObjectHash)
toADTArbitrarySingleton :: Proxy VCObjectHash -> Gen (ADTArbitrarySingleton VCObjectHash)
$ctoADTArbitrarySingleton :: Proxy VCObjectHash -> Gen (ADTArbitrarySingleton VCObjectHash)
ToADTArbitrary)
  deriving newtype (VCObjectHash -> VCObjectHash -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VCObjectHash -> VCObjectHash -> Bool
$c/= :: VCObjectHash -> VCObjectHash -> Bool
== :: VCObjectHash -> VCObjectHash -> Bool
$c== :: VCObjectHash -> VCObjectHash -> Bool
Eq, Eq VCObjectHash
VCObjectHash -> VCObjectHash -> Bool
VCObjectHash -> VCObjectHash -> Ordering
VCObjectHash -> VCObjectHash -> VCObjectHash
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: VCObjectHash -> VCObjectHash -> VCObjectHash
$cmin :: VCObjectHash -> VCObjectHash -> VCObjectHash
max :: VCObjectHash -> VCObjectHash -> VCObjectHash
$cmax :: VCObjectHash -> VCObjectHash -> VCObjectHash
>= :: VCObjectHash -> VCObjectHash -> Bool
$c>= :: VCObjectHash -> VCObjectHash -> Bool
> :: VCObjectHash -> VCObjectHash -> Bool
$c> :: VCObjectHash -> VCObjectHash -> Bool
<= :: VCObjectHash -> VCObjectHash -> Bool
$c<= :: VCObjectHash -> VCObjectHash -> Bool
< :: VCObjectHash -> VCObjectHash -> Bool
$c< :: VCObjectHash -> VCObjectHash -> Bool
compare :: VCObjectHash -> VCObjectHash -> Ordering
$ccompare :: VCObjectHash -> VCObjectHash -> Ordering
Ord, ReadPrec [VCObjectHash]
ReadPrec VCObjectHash
Int -> ReadS VCObjectHash
ReadS [VCObjectHash]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VCObjectHash]
$creadListPrec :: ReadPrec [VCObjectHash]
readPrec :: ReadPrec VCObjectHash
$creadPrec :: ReadPrec VCObjectHash
readList :: ReadS [VCObjectHash]
$creadList :: ReadS [VCObjectHash]
readsPrec :: Int -> ReadS VCObjectHash
$creadsPrec :: Int -> ReadS VCObjectHash
Read, VCObjectHash -> Int
forall p. VCObjectHash -> Ptr p -> IO ()
forall ba.
(ba -> Int)
-> (forall p a. ba -> (Ptr p -> IO a) -> IO a)
-> (forall p. ba -> Ptr p -> IO ())
-> ByteArrayAccess ba
forall p a. VCObjectHash -> (Ptr p -> IO a) -> IO a
copyByteArrayToPtr :: forall p. VCObjectHash -> Ptr p -> IO ()
$ccopyByteArrayToPtr :: forall p. VCObjectHash -> Ptr p -> IO ()
withByteArray :: forall p a. VCObjectHash -> (Ptr p -> IO a) -> IO a
$cwithByteArray :: forall p a. VCObjectHash -> (Ptr p -> IO a) -> IO a
length :: VCObjectHash -> Int
$clength :: VCObjectHash -> Int
ByteArrayAccess)

-- Orphan Instance Required for ToADTArbitrary VCObjectHash
instance Arbitrary (Digest SHA256) where
  arbitrary :: Gen (Digest SHA256)
arbitrary = forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
hash forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteString
pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

instance Show VCObjectHash where
  show :: VCObjectHash -> String
show = ByteString -> String
Char8.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. VCObjectHash -> ByteString
vcObjectHashToByteString

instance ToJSON VCObjectHash where
  toJSON :: VCObjectHash -> Value
toJSON = forall a. ToJSON a => a -> Value
toJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
decodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. VCObjectHash -> ByteString
vcObjectHashToByteString

instance FromJSON VCObjectHash where
  parseJSON :: Value -> Parser VCObjectHash
parseJSON = forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"VCObjectHash" forall a b. (a -> b) -> a -> b
$ \Text
piece -> do
    ByteString
b64 <- forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ ByteString -> Either String ByteString
Base64.decode forall a b. (a -> b) -> a -> b
$ Text -> ByteString
encodeUtf8 Text
piece
    forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ Text -> String
unpack forall a b. (a -> b) -> a -> b
$ Text
"Cannot decode hash " forall a. Semigroup a => a -> a -> a
<> Text
piece) (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Digest SHA256 -> VCObjectHash
VCObjectHash) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ba.
(HashAlgorithm a, ByteArrayAccess ba) =>
ba -> Maybe (Digest a)
digestFromByteString forall a b. (a -> b) -> a -> b
$ ByteString
b64

instance Arbitrary VCObjectHash where
  arbitrary :: Gen VCObjectHash
arbitrary = Digest SHA256 -> VCObjectHash
VCObjectHash forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
hash forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
Char8.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

instance Hashable VCObjectHash where
  hashWithSalt :: Int -> VCObjectHash -> Int
hashWithSalt Int
salt (VCObjectHash Digest SHA256
digest) =
    forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt forall a b. (a -> b) -> a -> b
$ forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert @(Digest SHA256) @ByteString Digest SHA256
digest

-- | Typeclass of hashable objects
class VCHashUpdate obj where
  (&<) :: Context SHA256 -> obj -> Context SHA256
  default (&<) :: (Generic obj, GenericVCHashUpdate (Rep obj)) => Context SHA256 -> obj -> Context SHA256
  Context SHA256
ctxt &< obj
o = forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
genHashUpdate Context SHA256
ctxt forall a b. (a -> b) -> a -> b
$ forall a x. Generic a => a -> Rep a x
from obj
o

hashUpdateVia :: ByteArrayAccess ba => (obj -> ba) -> Context SHA256 -> obj -> Context SHA256
hashUpdateVia :: forall ba obj.
ByteArrayAccess ba =>
(obj -> ba) -> Context SHA256 -> obj -> Context SHA256
hashUpdateVia obj -> ba
toBAA Context SHA256
ctxt obj
obj = Context SHA256
ctxt forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
Context a -> ba -> Context a
`hashUpdate` (obj -> ba
toBAA obj
obj)
{-# INLINE hashUpdateVia #-}

newtype VCHashUpdateViaShow a = VCHashUpdateViaShow {forall a. VCHashUpdateViaShow a -> a
unVCHashUpdateViaShow :: a}

instance Show a => VCHashUpdate (VCHashUpdateViaShow a) where
  &< :: Context SHA256 -> VCHashUpdateViaShow a -> Context SHA256
(&<) = forall ba obj.
ByteArrayAccess ba =>
(obj -> ba) -> Context SHA256 -> obj -> Context SHA256
hashUpdateVia forall a b. (a -> b) -> a -> b
$ String -> ByteString
Char8.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. VCHashUpdateViaShow a -> a
unVCHashUpdateViaShow

deriving via (VCHashUpdateViaShow ()) instance VCHashUpdate ()

deriving via (VCHashUpdateViaShow Int) instance VCHashUpdate Int

deriving via (VCHashUpdateViaShow InfixFixity) instance VCHashUpdate InfixFixity

deriving via (VCHashUpdateViaShow Fixity) instance VCHashUpdate Fixity

instance VCHashUpdate CTime where
  Context SHA256
ctxt &< :: Context SHA256 -> CTime -> Context SHA256
&< (CTime Int64
t) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (ByteString
"CTime" :: ByteString) forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< Int64
t

instance VCHashUpdate a => VCHashUpdate (Maybe a) where
  Context SHA256
ctxt &< :: Context SHA256 -> Maybe a -> Context SHA256
&< Maybe a
Nothing = Context SHA256
ctxt
  Context SHA256
ctxt &< (Just a
o) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< a
o

instance (VCHashUpdate a, VCHashUpdate b) => VCHashUpdate (a, b) where
  Context SHA256
ctxt &< :: Context SHA256 -> (a, b) -> Context SHA256
&< (a
a, b
b) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< a
a forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< b
b

instance (VCHashUpdate a, VCHashUpdate b, VCHashUpdate c) => VCHashUpdate (a, b, c) where
  Context SHA256
ctxt &< :: Context SHA256 -> (a, b, c) -> Context SHA256
&< (a
a, b
b, c
c) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< a
a forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< b
b forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< c
c

instance (VCHashUpdate a, VCHashUpdate b, VCHashUpdate c, VCHashUpdate d) => VCHashUpdate (a, b, c, d) where
  Context SHA256
ctxt &< :: Context SHA256 -> (a, b, c, d) -> Context SHA256
&< (a
a, b
b, c
c, d
d) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< a
a forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< b
b forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< c
c forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< d
d

instance (VCHashUpdate a, VCHashUpdate b, VCHashUpdate c, VCHashUpdate d, VCHashUpdate e) => VCHashUpdate (a, b, c, d, e) where
  Context SHA256
ctxt &< :: Context SHA256 -> (a, b, c, d, e) -> Context SHA256
&< (a
a, b
b, c
c, d
d, e
e) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< a
a forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< b
b forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< c
c forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< d
d forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< e
e

instance VCHashUpdate ByteString where
  &< :: Context SHA256 -> ByteString -> Context SHA256
(&<) = forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
Context a -> ba -> Context a
hashUpdate

instance VCHashUpdate Text where
  Context SHA256
ctxt &< :: Context SHA256 -> Text -> Context SHA256
&< Text
t = Context SHA256
ctxt forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
Context a -> ba -> Context a
`hashUpdate` Text -> ByteString
encodeUtf8 Text
t

instance VCHashUpdate a => VCHashUpdate [a] where
  Context SHA256
ctxt &< :: Context SHA256 -> [a] -> Context SHA256
&< [] = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (ByteString
"[]" :: ByteString)
  Context SHA256
ctxt &< (a
o : [a]
os) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (ByteString
":" :: ByteString) forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< a
o forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< [a]
os

instance VCHashUpdate ExtIdent where
  Context SHA256
ctxt &< :: Context SHA256 -> ExtIdent -> Context SHA256
&< (ExtIdent (Left Int
a)) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (ByteString
"var$" :: ByteString) forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< Int
a
  Context SHA256
ctxt &< (ExtIdent (Right Text
b)) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (ByteString
"reg$" :: ByteString) forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< Text
b

instance VCHashUpdate a => VCHashUpdate (NonEmpty.NonEmpty a) where
  Context SHA256
ctxt &< :: Context SHA256 -> NonEmpty a -> Context SHA256
&< NonEmpty a
xs = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (forall a. NonEmpty a -> [a]
NonEmpty.toList NonEmpty a
xs)

instance VCHashUpdate a => VCHashUpdate (Set.Set a) where
  Context SHA256
ctxt &< :: Context SHA256 -> Set a -> Context SHA256
&< Set a
xs = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (forall a. Set a -> [a]
Set.toList Set a
xs)

instance (VCHashUpdate k, VCHashUpdate a) => VCHashUpdate (Map.Map k a) where
  Context SHA256
ctxt &< :: Context SHA256 -> Map k a -> Context SHA256
&< Map k a
m = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (forall k a. Map k a -> [(k, a)]
Map.toList Map k a
m)

instance VCHashUpdate a => VCHashUpdate (IntMap.IntMap a) where
  Context SHA256
ctxt &< :: Context SHA256 -> IntMap a -> Context SHA256
&< IntMap a
m = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (forall a. IntMap a -> [(Int, a)]
IntMap.toList IntMap a
m)

class GenericVCHashUpdate f where
  genHashUpdate :: Context SHA256 -> f p -> Context SHA256

instance GenericVCHashUpdate U1 where
  genHashUpdate :: forall p. Context SHA256 -> U1 p -> Context SHA256
genHashUpdate Context SHA256
ctxt U1 p
_ = Context SHA256
ctxt

instance (VCHashUpdate a) => GenericVCHashUpdate (K1 i a) where
  genHashUpdate :: forall p. Context SHA256 -> K1 i a p -> Context SHA256
genHashUpdate Context SHA256
ctxt (K1 a
x) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< a
x

instance GenericVCHashUpdate f => GenericVCHashUpdate (D1 c f) where
  genHashUpdate :: forall p. Context SHA256 -> D1 c f p -> Context SHA256
genHashUpdate Context SHA256
ctxt (M1 f p
x) = forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
genHashUpdate Context SHA256
ctxt f p
x

instance (Constructor c, GenericVCHashUpdate f) => GenericVCHashUpdate (C1 c f) where
  genHashUpdate :: forall p. Context SHA256 -> C1 c f p -> Context SHA256
genHashUpdate Context SHA256
ctxt x :: C1 c f p
x@(M1 f p
y) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (String -> ByteString
Char8.pack forall a b. (a -> b) -> a -> b
$ forall {k} (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> String
conName C1 c f p
x) forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
`genHashUpdate` f p
y

instance GenericVCHashUpdate f => GenericVCHashUpdate (S1 c f) where
  genHashUpdate :: forall p. Context SHA256 -> S1 c f p -> Context SHA256
genHashUpdate Context SHA256
ctxt (M1 f p
x) = forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
genHashUpdate Context SHA256
ctxt f p
x

instance (GenericVCHashUpdate a, GenericVCHashUpdate b) => GenericVCHashUpdate (a :+: b) where
  genHashUpdate :: forall p. Context SHA256 -> (:+:) a b p -> Context SHA256
genHashUpdate Context SHA256
ctxt = \case
    L1 a p
a -> forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
genHashUpdate Context SHA256
ctxt a p
a
    R1 b p
b -> forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
genHashUpdate Context SHA256
ctxt b p
b

instance (GenericVCHashUpdate a, GenericVCHashUpdate b) => GenericVCHashUpdate (a :*: b) where
  genHashUpdate :: forall p. Context SHA256 -> (:*:) a b p -> Context SHA256
genHashUpdate Context SHA256
ctxt (a p
a :*: b p
b) = Context SHA256
ctxt forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
`genHashUpdate` a p
a forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
`genHashUpdate` b p
b

instance GenericVCHashUpdate f => GenericVCHashUpdate (Rec1 f) where
  genHashUpdate :: forall p. Context SHA256 -> Rec1 f p -> Context SHA256
genHashUpdate Context SHA256
ctxt (Rec1 f p
a) = forall (f :: * -> *) p.
GenericVCHashUpdate f =>
Context SHA256 -> f p -> Context SHA256
genHashUpdate Context SHA256
ctxt f p
a

deriving newtype instance VCHashUpdate Ident

deriving newtype instance VCHashUpdate ModuleName

instance VCHashUpdate VCObjectHash where
  Context SHA256
ctxt &< :: Context SHA256 -> VCObjectHash -> Context SHA256
&< (VCObjectHash Digest SHA256
h) = Context SHA256
ctxt forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
Context a -> ba -> Context a
`hashUpdate` Digest SHA256
h

deriving instance VCHashUpdate ImplExpl

instance VCHashUpdate Int64 where
  &< :: Context SHA256 -> Int64 -> Context SHA256
(&<) =
    forall ba obj.
ByteArrayAccess ba =>
(obj -> ba) -> Context SHA256 -> obj -> Context SHA256
hashUpdateVia forall a b. (a -> b) -> a -> b
$
      (\Int64
i64 -> forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. HasCallStack => String -> a
error (forall a. a -> a
id :: ByteString -> ByteString) forall a b. (a -> b) -> a -> b
$ forall byteArray a.
ByteArray byteArray =>
Int -> Packer a -> Either String byteArray
fill (forall a. Storable a => a -> Int
sizeOf Int64
i64) forall a b. (a -> b) -> a -> b
$ forall storable. Storable storable => storable -> Packer ()
putStorable Int64
i64)

instance VCHashUpdate Int32 where
  &< :: Context SHA256 -> Int32 -> Context SHA256
(&<) =
    forall ba obj.
ByteArrayAccess ba =>
(obj -> ba) -> Context SHA256 -> obj -> Context SHA256
hashUpdateVia forall a b. (a -> b) -> a -> b
$
      (\Int32
i32 -> forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. HasCallStack => String -> a
error (forall a. a -> a
id :: ByteString -> ByteString) forall a b. (a -> b) -> a -> b
$ forall byteArray a.
ByteArray byteArray =>
Int -> Packer a -> Either String byteArray
fill (forall a. Storable a => a -> Int
sizeOf Int32
i32) forall a b. (a -> b) -> a -> b
$ forall storable. Storable storable => storable -> Packer ()
putStorable Int32
i32)

instance VCHashUpdate Double where
  &< :: Context SHA256 -> Double -> Context SHA256
(&<) =
    forall ba obj.
ByteArrayAccess ba =>
(obj -> ba) -> Context SHA256 -> obj -> Context SHA256
hashUpdateVia forall a b. (a -> b) -> a -> b
$
      (\Double
d -> forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. HasCallStack => String -> a
error (forall a. a -> a
id :: ByteString -> ByteString) forall a b. (a -> b) -> a -> b
$ forall byteArray a.
ByteArray byteArray =>
Int -> Packer a -> Either String byteArray
fill (forall a. Storable a => a -> Int
sizeOf Double
d) forall a b. (a -> b) -> a -> b
$ forall storable. Storable storable => storable -> Packer ()
putStorable Double
d)

instance VCHashUpdate Word32 where
  &< :: Context SHA256 -> Word32 -> Context SHA256
(&<) =
    forall ba obj.
ByteArrayAccess ba =>
(obj -> ba) -> Context SHA256 -> obj -> Context SHA256
hashUpdateVia forall a b. (a -> b) -> a -> b
$
      (\Word32
w32 -> forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. HasCallStack => String -> a
error (forall a. a -> a
id :: ByteString -> ByteString) forall a b. (a -> b) -> a -> b
$ forall byteArray a.
ByteArray byteArray =>
Int -> Packer a -> Either String byteArray
fill (forall a. Storable a => a -> Int
sizeOf Word32
w32) forall a b. (a -> b) -> a -> b
$ forall storable. Storable storable => storable -> Packer ()
putStorable Word32
w32)

instance VCHashUpdate Word64 where
  &< :: Context SHA256 -> Word64 -> Context SHA256
(&<) =
    forall ba obj.
ByteArrayAccess ba =>
(obj -> ba) -> Context SHA256 -> obj -> Context SHA256
hashUpdateVia forall a b. (a -> b) -> a -> b
$
      (\Word64
w64 -> forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. HasCallStack => String -> a
error (forall a. a -> a
id :: ByteString -> ByteString) forall a b. (a -> b) -> a -> b
$ forall byteArray a.
ByteArray byteArray =>
Int -> Packer a -> Either String byteArray
fill (forall a. Storable a => a -> Int
sizeOf Word64
w64) forall a b. (a -> b) -> a -> b
$ forall storable. Storable storable => storable -> Packer ()
putStorable Word64
w64)

deriving instance VCHashUpdate Lit

instance VCHashUpdate e => VCHashUpdate (SomeIStr e) where
  Context SHA256
ctxt &< :: Context SHA256 -> SomeIStr e -> Context SHA256
&< (SomeIStr IStr f e
istr) = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< IStr f e
istr

instance VCHashUpdate e => VCHashUpdate (IStr f e) where
  Context SHA256
ctxt &< :: Context SHA256 -> IStr f e -> Context SHA256
&< IStr f e
istr = case IStr f e
istr of
    IStr f e
ISEmpty -> Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (ByteString
"ISEmpty" :: ByteString)
    ISStr Text
s IStr 'True e
is -> Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (ByteString
"ISStr" :: ByteString) forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< Text
s forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< IStr 'True e
is
    ISExpr e
e IStr f1 e
is -> Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (ByteString
"ISExpr" :: ByteString) forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< e
e forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< IStr f1 e
is

deriving instance VCHashUpdate a => VCHashUpdate (Comment a)

instance VCHashUpdate a => VCHashUpdate (TList a) where
  Context SHA256
ctxt &< :: Context SHA256 -> TList a -> Context SHA256
&< TList a
ts = Context SHA256
ctxt forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< (forall a. TList a -> [a]
tListToList TList a
ts)

deriving instance VCHashUpdate a => VCHashUpdate (Import a)

deriving instance (VCHashUpdate hash, VCHashUpdate a) => VCHashUpdate (Pat hash a)

deriving instance VCHashUpdate a => VCHashUpdate (Scoped a)

deriving instance (VCHashUpdate hash, VCHashUpdate a) => VCHashUpdate (Expr hash a)

deriving instance VCHashUpdate BaseType

deriving newtype instance VCHashUpdate TV

deriving instance VCHashUpdate InfernoType

deriving instance VCHashUpdate TypeClass

deriving instance VCHashUpdate ty => VCHashUpdate (TypeMetadata ty)

deriving instance VCHashUpdate ImplType

deriving instance VCHashUpdate Namespace

deriving instance VCHashUpdate TCScheme

deriving via (VCHashUpdateViaShow SourcePos) instance VCHashUpdate SourcePos

data Pinned a = Local | Builtin VCObjectHash | UnderVC a
  deriving (Int -> Pinned a -> ShowS
forall a. Show a => Int -> Pinned a -> ShowS
forall a. Show a => [Pinned a] -> ShowS
forall a. Show a => Pinned a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Pinned a] -> ShowS
$cshowList :: forall a. Show a => [Pinned a] -> ShowS
show :: Pinned a -> String
$cshow :: forall a. Show a => Pinned a -> String
showsPrec :: Int -> Pinned a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Pinned a -> ShowS
Show, Pinned a -> Pinned a -> Bool
forall a. Eq a => Pinned a -> Pinned a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Pinned a -> Pinned a -> Bool
$c/= :: forall a. Eq a => Pinned a -> Pinned a -> Bool
== :: Pinned a -> Pinned a -> Bool
$c== :: forall a. Eq a => Pinned a -> Pinned a -> Bool
Eq, Pinned a -> Pinned a -> Bool
Pinned a -> Pinned a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Pinned a)
forall a. Ord a => Pinned a -> Pinned a -> Bool
forall a. Ord a => Pinned a -> Pinned a -> Ordering
forall a. Ord a => Pinned a -> Pinned a -> Pinned a
min :: Pinned a -> Pinned a -> Pinned a
$cmin :: forall a. Ord a => Pinned a -> Pinned a -> Pinned a
max :: Pinned a -> Pinned a -> Pinned a
$cmax :: forall a. Ord a => Pinned a -> Pinned a -> Pinned a
>= :: Pinned a -> Pinned a -> Bool
$c>= :: forall a. Ord a => Pinned a -> Pinned a -> Bool
> :: Pinned a -> Pinned a -> Bool
$c> :: forall a. Ord a => Pinned a -> Pinned a -> Bool
<= :: Pinned a -> Pinned a -> Bool
$c<= :: forall a. Ord a => Pinned a -> Pinned a -> Bool
< :: Pinned a -> Pinned a -> Bool
$c< :: forall a. Ord a => Pinned a -> Pinned a -> Bool
compare :: Pinned a -> Pinned a -> Ordering
$ccompare :: forall a. Ord a => Pinned a -> Pinned a -> Ordering
Ord, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Pinned a) x -> Pinned a
forall a x. Pinned a -> Rep (Pinned a) x
$cto :: forall a x. Rep (Pinned a) x -> Pinned a
$cfrom :: forall a x. Pinned a -> Rep (Pinned a) x
Generic, forall a b. a -> Pinned b -> Pinned a
forall a b. (a -> b) -> Pinned a -> Pinned b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Pinned b -> Pinned a
$c<$ :: forall a b. a -> Pinned b -> Pinned a
fmap :: forall a b. (a -> b) -> Pinned a -> Pinned b
$cfmap :: forall a b. (a -> b) -> Pinned a -> Pinned b
Functor, Pinned a -> DataType
Pinned a -> Constr
forall {a}. Data a => Typeable (Pinned a)
forall a. Data a => Pinned a -> DataType
forall a. Data a => Pinned a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Pinned a -> Pinned a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Pinned a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Pinned a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Pinned a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Pinned a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Pinned a -> m (Pinned a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Pinned a -> m (Pinned a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Pinned a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pinned a -> c (Pinned a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Pinned a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Pinned a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Pinned a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pinned a -> c (Pinned a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Pinned a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pinned a -> m (Pinned a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Pinned a -> m (Pinned a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pinned a -> m (Pinned a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Pinned a -> m (Pinned a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Pinned a -> m (Pinned a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Pinned a -> m (Pinned a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Pinned a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Pinned a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Pinned a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Pinned a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Pinned a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Pinned a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Pinned a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Pinned a -> r
gmapT :: (forall b. Data b => b -> b) -> Pinned a -> Pinned a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Pinned a -> Pinned a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Pinned a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Pinned a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Pinned a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Pinned a))
dataTypeOf :: Pinned a -> DataType
$cdataTypeOf :: forall a. Data a => Pinned a -> DataType
toConstr :: Pinned a -> Constr
$ctoConstr :: forall a. Data a => Pinned a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Pinned a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Pinned a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pinned a -> c (Pinned a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pinned a -> c (Pinned a)
Data, forall a. ToJSON a => [Pinned a] -> Encoding
forall a. ToJSON a => [Pinned a] -> Value
forall a. ToJSON a => Pinned a -> Encoding
forall a. ToJSON a => Pinned a -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Pinned a] -> Encoding
$ctoEncodingList :: forall a. ToJSON a => [Pinned a] -> Encoding
toJSONList :: [Pinned a] -> Value
$ctoJSONList :: forall a. ToJSON a => [Pinned a] -> Value
toEncoding :: Pinned a -> Encoding
$ctoEncoding :: forall a. ToJSON a => Pinned a -> Encoding
toJSON :: Pinned a -> Value
$ctoJSON :: forall a. ToJSON a => Pinned a -> Value
ToJSON, forall a. FromJSON a => Value -> Parser [Pinned a]
forall a. FromJSON a => Value -> Parser (Pinned a)
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Pinned a]
$cparseJSONList :: forall a. FromJSON a => Value -> Parser [Pinned a]
parseJSON :: Value -> Parser (Pinned a)
$cparseJSON :: forall a. FromJSON a => Value -> Parser (Pinned a)
FromJSON, forall a.
VCHashUpdate a =>
Context SHA256 -> Pinned a -> Context SHA256
forall obj.
(Context SHA256 -> obj -> Context SHA256) -> VCHashUpdate obj
&< :: Context SHA256 -> Pinned a -> Context SHA256
$c&< :: forall a.
VCHashUpdate a =>
Context SHA256 -> Pinned a -> Context SHA256
VCHashUpdate)

pinnedToMaybe :: Pinned VCObjectHash -> Maybe VCObjectHash
pinnedToMaybe :: Pinned VCObjectHash -> Maybe VCObjectHash
pinnedToMaybe = \case
  Pinned VCObjectHash
Local -> forall a. Maybe a
Nothing
  Builtin VCObjectHash
h -> forall a. a -> Maybe a
Just VCObjectHash
h
  UnderVC VCObjectHash
h -> forall a. a -> Maybe a
Just VCObjectHash
h

pinnedUnderVCToMaybe :: Pinned a -> Maybe a
pinnedUnderVCToMaybe :: forall a. Pinned a -> Maybe a
pinnedUnderVCToMaybe = \case
  UnderVC a
h -> forall a. a -> Maybe a
Just a
h
  Pinned a
_ -> forall a. Maybe a
Nothing

vcObjectHashToByteString :: VCObjectHash -> ByteString
vcObjectHashToByteString :: VCObjectHash -> ByteString
vcObjectHashToByteString = ByteString -> ByteString
Base64.encode forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert forall b c a. (b -> c) -> (a -> b) -> a -> c
. VCObjectHash -> Digest SHA256
vcObjectHashDigest

byteStringToVCObjectHash :: ByteString -> Maybe VCObjectHash
byteStringToVCObjectHash :: ByteString -> Maybe VCObjectHash
byteStringToVCObjectHash ByteString
b = do
  ByteString
b64 <- forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const forall a. Maybe a
Nothing) forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ByteString -> Either String ByteString
Base64.decode ByteString
b
  Digest SHA256 -> VCObjectHash
VCObjectHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a ba.
(HashAlgorithm a, ByteArrayAccess ba) =>
ba -> Maybe (Digest a)
digestFromByteString ByteString
b64

vcHash :: VCHashUpdate obj => obj -> VCObjectHash
vcHash :: forall obj. VCHashUpdate obj => obj -> VCObjectHash
vcHash obj
o = Digest SHA256 -> VCObjectHash
VCObjectHash forall a b. (a -> b) -> a -> b
$ forall a. HashAlgorithm a => Context a -> Digest a
hashFinalize forall a b. (a -> b) -> a -> b
$ forall a. HashAlgorithm a => Context a
hashInit forall obj.
VCHashUpdate obj =>
Context SHA256 -> obj -> Context SHA256
&< obj
o

instance FromHttpApiData VCObjectHash where
  parseUrlPiece :: Text -> Either Text VCObjectHash
parseUrlPiece Text
t = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ Text
"Cannot decode hash " forall a. Semigroup a => a -> a -> a
<> Text
t) forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ ByteString -> Maybe VCObjectHash
byteStringToVCObjectHash forall a b. (a -> b) -> a -> b
$ Text -> ByteString
encodeUtf8 Text
t

instance ToHttpApiData VCObjectHash where
  toUrlPiece :: VCObjectHash -> Text
toUrlPiece = ByteString -> Text
decodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. VCObjectHash -> ByteString
vcObjectHashToByteString