{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

-- |
-- Module      :   Grisette.Internal.SymPrim.Prim.Internal.Serialize
-- Copyright   :   (c) Sirui Lu 2024
-- License     :   BSD-3-Clause (see the LICENSE file)
--
-- Maintainer  :   siruilu@cs.washington.edu
-- Stability   :   Experimental
-- Portability :   GHC only
module Grisette.Internal.SymPrim.Prim.Internal.Serialize () where

import Control.Monad (replicateM, unless, when)
import Control.Monad.State (StateT, evalStateT)
import qualified Control.Monad.State as State
import qualified Data.Binary as Binary
import Data.Bytes.Get (MonadGet (getWord8))
import Data.Bytes.Put (MonadPut (putWord8))
import Data.Bytes.Serial (Serial (deserialize, serialize))
import Data.Foldable (traverse_)
import qualified Data.HashMap.Strict as HM
import qualified Data.HashSet as HS
import Data.Hashable (Hashable (hashWithSalt))
import Data.List (intercalate)
import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.Proxy (Proxy (Proxy))
import qualified Data.Serialize as Cereal
import Data.Word (Word8)
import GHC.Generics (Generic)
import GHC.Natural (Natural)
import GHC.Stack (HasCallStack)
import GHC.TypeNats (KnownNat, natVal, type (+), type (<=))
import Grisette.Internal.SymPrim.AlgReal (AlgReal)
import Grisette.Internal.SymPrim.BV (IntN, WordN)
import Grisette.Internal.SymPrim.FP
  ( FP,
    FPRoundingMode,
    ValidFP,
    checkDynamicValidFP,
    invalidFPMessage,
    withUnsafeValidFP,
  )
import Grisette.Internal.SymPrim.GeneralFun (type (-->) (GeneralFun))
import Grisette.Internal.SymPrim.Prim.Internal.Caches (Id)
import Grisette.Internal.SymPrim.Prim.Internal.Instances.BVPEval ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalBitCastTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalBitwiseTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalDivModIntegralTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalFloatingTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalFractionalTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalFromIntegralTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalIEEEFPConvertibleTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalNumTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalOrdTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalRotateTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.PEvalShiftTerm ()
import Grisette.Internal.SymPrim.Prim.Internal.Instances.SupportedPrim ()
import Grisette.Internal.SymPrim.Prim.Internal.Term
  ( FPBinaryOp,
    FPRoundingBinaryOp,
    FPRoundingUnaryOp,
    FPTrait,
    FPUnaryOp,
    IsSymbolKind (decideSymbolKind),
    ModelValue (ModelValue),
    PEvalBitCastTerm,
    PEvalBitwiseTerm,
    PEvalDivModIntegralTerm,
    PEvalFloatingTerm,
    PEvalFractionalTerm,
    PEvalFromIntegralTerm,
    PEvalIEEEFPConvertibleTerm,
    PEvalNumTerm,
    PEvalOrdTerm,
    PEvalRotateTerm,
    PEvalShiftTerm,
    SomeTypedAnySymbol,
    SomeTypedSymbol (SomeTypedSymbol),
    SupportedNonFuncPrim,
    SupportedPrim (primTypeRep, withPrim),
    Term,
    TypedAnySymbol,
    TypedConstantSymbol,
    TypedSymbol (TypedSymbol),
    absNumTerm,
    addNumTerm,
    andBitsTerm,
    andTerm,
    applyTerm,
    bitCastOrTerm,
    bitCastTerm,
    bvConcatTerm,
    bvExtendTerm,
    bvSelectTerm,
    complementBitsTerm,
    conTerm,
    distinctTerm,
    divIntegralTerm,
    eqTerm,
    existsTerm,
    fdivTerm,
    floatingUnaryTerm,
    forallTerm,
    fpBinaryTerm,
    fpFMATerm,
    fpRoundingBinaryTerm,
    fpRoundingUnaryTerm,
    fpTraitTerm,
    fpUnaryTerm,
    fromFPOrTerm,
    fromIntegralTerm,
    iteTerm,
    leOrdTerm,
    ltOrdTerm,
    modIntegralTerm,
    mulNumTerm,
    negNumTerm,
    notTerm,
    orBitsTerm,
    orTerm,
    powerTerm,
    quotIntegralTerm,
    recipTerm,
    remIntegralTerm,
    rotateLeftTerm,
    rotateRightTerm,
    shiftLeftTerm,
    shiftRightTerm,
    signumNumTerm,
    someTypedSymbol,
    symTerm,
    termId,
    toFPTerm,
    xorBitsTerm,
    pattern AbsNumTerm,
    pattern AddNumTerm,
    pattern AndBitsTerm,
    pattern AndTerm,
    pattern ApplyTerm,
    pattern BVConcatTerm,
    pattern BVExtendTerm,
    pattern BVSelectTerm,
    pattern BitCastOrTerm,
    pattern BitCastTerm,
    pattern ComplementBitsTerm,
    pattern ConTerm,
    pattern DistinctTerm,
    pattern DivIntegralTerm,
    pattern EqTerm,
    pattern ExistsTerm,
    pattern FPBinaryTerm,
    pattern FPFMATerm,
    pattern FPRoundingBinaryTerm,
    pattern FPRoundingUnaryTerm,
    pattern FPTraitTerm,
    pattern FPUnaryTerm,
    pattern FdivTerm,
    pattern FloatingUnaryTerm,
    pattern ForallTerm,
    pattern FromFPOrTerm,
    pattern FromIntegralTerm,
    pattern ITETerm,
    pattern LeOrdTerm,
    pattern LtOrdTerm,
    pattern ModIntegralTerm,
    pattern MulNumTerm,
    pattern NegNumTerm,
    pattern NotTerm,
    pattern OrBitsTerm,
    pattern OrTerm,
    pattern PowerTerm,
    pattern QuotIntegralTerm,
    pattern RecipTerm,
    pattern RemIntegralTerm,
    pattern RotateLeftTerm,
    pattern RotateRightTerm,
    pattern ShiftLeftTerm,
    pattern ShiftRightTerm,
    pattern SignumNumTerm,
    pattern SupportedTerm,
    pattern SymTerm,
    pattern ToFPTerm,
    pattern XorBitsTerm,
  )
import Grisette.Internal.SymPrim.Prim.SomeTerm
  ( SomeTerm (SomeTerm),
    someTerm,
  )
import Grisette.Internal.SymPrim.Prim.TermUtils (castTerm)
import Grisette.Internal.SymPrim.TabularFun (type (=->))
import Grisette.Internal.Utils.Parameterized
  ( KnownProof (KnownProof),
    LeqProof (LeqProof),
    NatRepr,
    SomeNatRepr (SomeNatRepr),
    SomePositiveNatRepr (SomePositiveNatRepr),
    mkNatRepr,
    mkPositiveNatRepr,
    unsafeAxiom,
    unsafeKnownProof,
    unsafeLeqProof,
  )
import Type.Reflection
  ( SomeTypeRep (SomeTypeRep),
    TypeRep,
    Typeable,
    eqTypeRep,
    someTypeRep,
    typeRep,
    pattern App,
    pattern Con,
    type (:~:) (Refl),
    type (:~~:) (HRefl),
  )

data KnownNonFuncType where
  BoolType :: KnownNonFuncType
  IntegerType :: KnownNonFuncType
  WordNType :: (KnownNat n, 1 <= n) => Proxy n -> KnownNonFuncType
  IntNType :: (KnownNat n, 1 <= n) => Proxy n -> KnownNonFuncType
  FPType :: (ValidFP eb sb) => Proxy eb -> Proxy sb -> KnownNonFuncType
  FPRoundingModeType :: KnownNonFuncType
  AlgRealType :: KnownNonFuncType

instance Eq KnownNonFuncType where
  KnownNonFuncType
BoolType == :: KnownNonFuncType -> KnownNonFuncType -> Bool
== KnownNonFuncType
BoolType = Bool
True
  KnownNonFuncType
IntegerType == KnownNonFuncType
IntegerType = Bool
True
  WordNType Proxy n
p == WordNType Proxy n
q = Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy n
p Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy n
q
  IntNType Proxy n
p == IntNType Proxy n
q = Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy n
p Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy n
q
  FPType Proxy eb
p Proxy sb
q == FPType Proxy eb
r Proxy sb
s = Proxy eb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy eb
p Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy eb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy eb
r Bool -> Bool -> Bool
&& Proxy sb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy sb
q Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy sb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy sb
s
  KnownNonFuncType
FPRoundingModeType == KnownNonFuncType
FPRoundingModeType = Bool
True
  KnownNonFuncType
AlgRealType == KnownNonFuncType
AlgRealType = Bool
True
  KnownNonFuncType
_ == KnownNonFuncType
_ = Bool
False

instance Hashable KnownNonFuncType where
  hashWithSalt :: Int -> KnownNonFuncType -> Int
hashWithSalt Int
s KnownNonFuncType
BoolType = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
0 :: Int)
  hashWithSalt Int
s KnownNonFuncType
IntegerType = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
1 :: Int)
  hashWithSalt Int
s (WordNType Proxy n
p) =
    Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
2 :: Int) Int -> Natural -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy n
p
  hashWithSalt Int
s (IntNType Proxy n
p) =
    Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
3 :: Int) Int -> Natural -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy n
p
  hashWithSalt Int
s (FPType Proxy eb
p Proxy sb
q) =
    Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
4 :: Int) Int -> Natural -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` Proxy eb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy eb
p Int -> Natural -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` Proxy sb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy sb
q
  hashWithSalt Int
s KnownNonFuncType
FPRoundingModeType = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
5 :: Int)
  hashWithSalt Int
s KnownNonFuncType
AlgRealType = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
6 :: Int)

data KnownNonFuncTypeWitness where
  KnownNonFuncTypeWitness ::
    ( SupportedNonFuncPrim a,
      Eq a,
      Show a,
      Hashable a,
      Typeable a,
      Serial a
    ) =>
    Proxy a ->
    KnownNonFuncTypeWitness

witnessKnownNonFuncType :: KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType :: KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
BoolType = Proxy Bool -> KnownNonFuncTypeWitness
forall eb.
(SupportedNonFuncPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownNonFuncTypeWitness
KnownNonFuncTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Bool)
witnessKnownNonFuncType KnownNonFuncType
IntegerType = Proxy Integer -> KnownNonFuncTypeWitness
forall eb.
(SupportedNonFuncPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownNonFuncTypeWitness
KnownNonFuncTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Integer)
witnessKnownNonFuncType (WordNType (Proxy n
Proxy :: Proxy n)) =
  Proxy (WordN n) -> KnownNonFuncTypeWitness
forall eb.
(SupportedNonFuncPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownNonFuncTypeWitness
KnownNonFuncTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(WordN n))
witnessKnownNonFuncType (IntNType (Proxy n
Proxy :: Proxy n)) =
  Proxy (IntN n) -> KnownNonFuncTypeWitness
forall eb.
(SupportedNonFuncPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownNonFuncTypeWitness
KnownNonFuncTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(IntN n))
witnessKnownNonFuncType (FPType (Proxy eb
Proxy :: Proxy eb) (Proxy sb
Proxy :: Proxy sb)) =
  Proxy (FP eb sb) -> KnownNonFuncTypeWitness
forall eb.
(SupportedNonFuncPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownNonFuncTypeWitness
KnownNonFuncTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(FP eb sb))
witnessKnownNonFuncType KnownNonFuncType
FPRoundingModeType =
  Proxy FPRoundingMode -> KnownNonFuncTypeWitness
forall eb.
(SupportedNonFuncPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownNonFuncTypeWitness
KnownNonFuncTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @FPRoundingMode)
witnessKnownNonFuncType KnownNonFuncType
AlgRealType = Proxy AlgReal -> KnownNonFuncTypeWitness
forall eb.
(SupportedNonFuncPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownNonFuncTypeWitness
KnownNonFuncTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @AlgReal)

data KnownType where
  NonFuncType :: KnownNonFuncType -> KnownType
  TabularFunType :: [KnownNonFuncType] -> KnownType
  GeneralFunType :: [KnownNonFuncType] -> KnownType
  deriving (KnownType -> KnownType -> Bool
(KnownType -> KnownType -> Bool)
-> (KnownType -> KnownType -> Bool) -> Eq KnownType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: KnownType -> KnownType -> Bool
== :: KnownType -> KnownType -> Bool
$c/= :: KnownType -> KnownType -> Bool
/= :: KnownType -> KnownType -> Bool
Eq, (forall x. KnownType -> Rep KnownType x)
-> (forall x. Rep KnownType x -> KnownType) -> Generic KnownType
forall x. Rep KnownType x -> KnownType
forall x. KnownType -> Rep KnownType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. KnownType -> Rep KnownType x
from :: forall x. KnownType -> Rep KnownType x
$cto :: forall x. Rep KnownType x -> KnownType
to :: forall x. Rep KnownType x -> KnownType
Generic, Eq KnownType
Eq KnownType =>
(Int -> KnownType -> Int)
-> (KnownType -> Int) -> Hashable KnownType
Int -> KnownType -> Int
KnownType -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> KnownType -> Int
hashWithSalt :: Int -> KnownType -> Int
$chash :: KnownType -> Int
hash :: KnownType -> Int
Hashable)

data KnownTypeWitness where
  KnownTypeWitness ::
    ( SupportedPrim a,
      Eq a,
      Show a,
      Hashable a,
      Typeable a,
      Serial a
    ) =>
    Proxy a ->
    KnownTypeWitness

witnessKnownType :: KnownType -> KnownTypeWitness
witnessKnownType :: KnownType -> KnownTypeWitness
witnessKnownType (NonFuncType KnownNonFuncType
nf) = case KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
nf of
  KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a) -> Proxy a -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @a)
witnessKnownType (TabularFunType [KnownNonFuncType
a, KnownNonFuncType
b]) =
  case (KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a, KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b)
      ) -> Proxy (a =-> a) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a =-> b))
witnessKnownType (TabularFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c)
      ) -> Proxy (a =-> (a =-> a)) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a =-> b =-> c))
witnessKnownType (TabularFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d)
      ) -> Proxy (a =-> (a =-> (a =-> a))) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a =-> b =-> c =-> d))
witnessKnownType (TabularFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d, KnownNonFuncType
e]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
e
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy e)
      ) -> Proxy (a =-> (a =-> (a =-> (a =-> a)))) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a =-> b =-> c =-> d =-> e))
witnessKnownType (TabularFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d, KnownNonFuncType
e, KnownNonFuncType
f]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
e,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
f
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy e),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy f)
      ) -> Proxy (a =-> (a =-> (a =-> (a =-> (a =-> a))))) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a =-> b =-> c =-> d =-> e =-> f))
witnessKnownType (TabularFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d, KnownNonFuncType
e, KnownNonFuncType
f, KnownNonFuncType
g]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
e,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
f,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
g
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy e),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy f),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy g)
      ) -> Proxy (a =-> (a =-> (a =-> (a =-> (a =-> (a =-> a))))))
-> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a =-> b =-> c =-> d =-> e =-> f =-> g))
witnessKnownType (TabularFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d, KnownNonFuncType
e, KnownNonFuncType
f, KnownNonFuncType
g, KnownNonFuncType
h]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
e,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
f,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
g,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
h
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy e),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy f),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy g),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy h)
      ) ->
        Proxy (a =-> (a =-> (a =-> (a =-> (a =-> (a =-> (a =-> a)))))))
-> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a =-> b =-> c =-> d =-> e =-> f =-> g =-> h))
witnessKnownType (GeneralFunType [KnownNonFuncType
a, KnownNonFuncType
b]) =
  case (KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a, KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b)
      ) -> Proxy (a --> a) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a --> b))
witnessKnownType (GeneralFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c)
      ) -> Proxy (a --> (a --> a)) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a --> b --> c))
witnessKnownType (GeneralFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d)
      ) -> Proxy (a --> (a --> (a --> a))) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a --> b --> c --> d))
witnessKnownType (GeneralFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d, KnownNonFuncType
e]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
e
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy e)
      ) -> Proxy (a --> (a --> (a --> (a --> a)))) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a --> b --> c --> d --> e))
witnessKnownType (GeneralFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d, KnownNonFuncType
e, KnownNonFuncType
f]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
e,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
f
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy e),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy f)
      ) -> Proxy (a --> (a --> (a --> (a --> (a --> a))))) -> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a --> b --> c --> d --> e --> f))
witnessKnownType (GeneralFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d, KnownNonFuncType
e, KnownNonFuncType
f, KnownNonFuncType
g]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
e,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
f,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
g
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy e),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy f),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy g)
      ) -> Proxy (a --> (a --> (a --> (a --> (a --> (a --> a))))))
-> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a --> b --> c --> d --> e --> f --> g))
witnessKnownType (GeneralFunType [KnownNonFuncType
a, KnownNonFuncType
b, KnownNonFuncType
c, KnownNonFuncType
d, KnownNonFuncType
e, KnownNonFuncType
f, KnownNonFuncType
g, KnownNonFuncType
h]) =
  case ( KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
a,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
b,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
c,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
d,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
e,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
f,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
g,
         KnownNonFuncType -> KnownNonFuncTypeWitness
witnessKnownNonFuncType KnownNonFuncType
h
       ) of
    ( KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy b),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy c),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy d),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy e),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy f),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy g),
      KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy h)
      ) ->
        Proxy (a --> (a --> (a --> (a --> (a --> (a --> (a --> a)))))))
-> KnownTypeWitness
forall eb.
(SupportedPrim eb, Eq eb, Show eb, Hashable eb, Typeable eb,
 Serial eb) =>
Proxy eb -> KnownTypeWitness
KnownTypeWitness (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(a --> b --> c --> d --> e --> f --> g --> h))
witnessKnownType KnownType
l = [Char] -> KnownTypeWitness
forall a. HasCallStack => [Char] -> a
error ([Char] -> KnownTypeWitness) -> [Char] -> KnownTypeWitness
forall a b. (a -> b) -> a -> b
$ [Char]
"witnessKnownType: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> KnownType -> [Char]
forall a. Show a => a -> [Char]
show KnownType
l

instance Show KnownNonFuncType where
  show :: KnownNonFuncType -> [Char]
show KnownNonFuncType
BoolType = [Char]
"Bool"
  show KnownNonFuncType
IntegerType = [Char]
"Integer"
  show (WordNType (Proxy n
_ :: p n)) = [Char]
"WordN " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Natural -> [Char]
forall a. Show a => a -> [Char]
show (Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n))
  show (IntNType (Proxy n
_ :: p n)) = [Char]
"IntN " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Natural -> [Char]
forall a. Show a => a -> [Char]
show (Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n))
  show (FPType (Proxy eb
_ :: p eb) (Proxy sb
_ :: q sb)) =
    [Char]
"FP "
      [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Natural -> [Char]
forall a. Show a => a -> [Char]
show (Proxy eb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @eb))
      [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
" "
      [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Natural -> [Char]
forall a. Show a => a -> [Char]
show (Proxy sb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @sb))
  show KnownNonFuncType
FPRoundingModeType = [Char]
"FPRoundingMode"
  show KnownNonFuncType
AlgRealType = [Char]
"AlgReal"

instance Show KnownType where
  show :: KnownType -> [Char]
show (NonFuncType KnownNonFuncType
t) = KnownNonFuncType -> [Char]
forall a. Show a => a -> [Char]
show KnownNonFuncType
t
  show (TabularFunType [KnownNonFuncType]
ts) = [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
" =-> " ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ KnownNonFuncType -> [Char]
forall a. Show a => a -> [Char]
show (KnownNonFuncType -> [Char]) -> [KnownNonFuncType] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [KnownNonFuncType]
ts
  show (GeneralFunType [KnownNonFuncType]
ts) = [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
" --> " ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ KnownNonFuncType -> [Char]
forall a. Show a => a -> [Char]
show (KnownNonFuncType -> [Char]) -> [KnownNonFuncType] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [KnownNonFuncType]
ts

knownNonFuncType ::
  forall a p. (SupportedNonFuncPrim a) => p a -> KnownNonFuncType
knownNonFuncType :: forall a (p :: * -> *).
SupportedNonFuncPrim a =>
p a -> KnownNonFuncType
knownNonFuncType p a
_ =
  case TypeRep a
tr of
    TypeRep a
_ | TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
SomeTypeRep TypeRep a
tr SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy Bool -> SomeTypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> SomeTypeRep
someTypeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Bool) -> KnownNonFuncType
BoolType
    TypeRep a
_ | TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
SomeTypeRep TypeRep a
tr SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy Integer -> SomeTypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> SomeTypeRep
someTypeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Integer) -> KnownNonFuncType
IntegerType
    TypeRep a
_
      | TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
SomeTypeRep TypeRep a
tr SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy FPRoundingMode -> SomeTypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> SomeTypeRep
someTypeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @FPRoundingMode) ->
          KnownNonFuncType
FPRoundingModeType
    TypeRep a
_ | TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
SomeTypeRep TypeRep a
tr SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy AlgReal -> SomeTypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> SomeTypeRep
someTypeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @AlgReal) -> KnownNonFuncType
AlgRealType
    App (ta :: TypeRep a
ta@(Con TyCon
_) :: TypeRep w) (TypeRep b
_ :: TypeRep n) ->
      case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
             TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
           ) of
        (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  KnownNonFuncType)
 -> KnownNonFuncType)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    KnownNonFuncType)
-> KnownNonFuncType
forall a b. (a -> b) -> a -> b
$ Proxy b -> KnownNonFuncType
forall (eb :: Natural).
(KnownNat eb, 1 <= eb) =>
Proxy eb -> KnownNonFuncType
WordNType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n)
        (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  KnownNonFuncType)
 -> KnownNonFuncType)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    KnownNonFuncType)
-> KnownNonFuncType
forall a b. (a -> b) -> a -> b
$ Proxy b -> KnownNonFuncType
forall (eb :: Natural).
(KnownNat eb, 1 <= eb) =>
Proxy eb -> KnownNonFuncType
IntNType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n)
        (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> KnownNonFuncType
err
    App (App (TypeRep a
tf :: TypeRep f) (TypeRep b
_ :: TypeRep a0)) (TypeRep b
_ :: TypeRep a1) ->
      case TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tf (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP) of
        Just a :~~: FP
HRefl -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  KnownNonFuncType)
 -> KnownNonFuncType)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    KnownNonFuncType)
-> KnownNonFuncType
forall a b. (a -> b) -> a -> b
$ Proxy b -> Proxy b -> KnownNonFuncType
forall (eb :: Natural) (sb :: Natural).
ValidFP eb sb =>
Proxy eb -> Proxy sb -> KnownNonFuncType
FPType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @a0) (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @a1)
        Maybe (a :~~: FP)
_ -> KnownNonFuncType
err
    TypeRep a
_ -> KnownNonFuncType
err
  where
    tr :: TypeRep a
tr = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: KnownNonFuncType
err = [Char] -> KnownNonFuncType
forall a. HasCallStack => [Char] -> a
error ([Char] -> KnownNonFuncType) -> [Char] -> KnownNonFuncType
forall a b. (a -> b) -> a -> b
$ [Char]
"knownNonFuncType: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
tr

knownType ::
  forall a p. (SupportedPrim a) => p a -> KnownType
knownType :: forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType p a
_ =
  case TypeRep a
tr of
    TypeRep a
_ | TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
SomeTypeRep TypeRep a
tr SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy Bool -> SomeTypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> SomeTypeRep
someTypeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Bool) -> KnownNonFuncType -> KnownType
NonFuncType KnownNonFuncType
BoolType
    TypeRep a
_
      | TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
SomeTypeRep TypeRep a
tr SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy Integer -> SomeTypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> SomeTypeRep
someTypeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Integer) ->
          KnownNonFuncType -> KnownType
NonFuncType KnownNonFuncType
IntegerType
    TypeRep a
_
      | TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
SomeTypeRep TypeRep a
tr SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy FPRoundingMode -> SomeTypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> SomeTypeRep
someTypeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @FPRoundingMode) ->
          KnownNonFuncType -> KnownType
NonFuncType KnownNonFuncType
FPRoundingModeType
    TypeRep a
_
      | TypeRep a -> SomeTypeRep
forall k (a :: k). TypeRep a -> SomeTypeRep
SomeTypeRep TypeRep a
tr SomeTypeRep -> SomeTypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy AlgReal -> SomeTypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> SomeTypeRep
someTypeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @AlgReal) ->
          KnownNonFuncType -> KnownType
NonFuncType KnownNonFuncType
AlgRealType
    App (ta :: TypeRep a
ta@(Con TyCon
_) :: TypeRep w) (TypeRep b
_ :: TypeRep n) ->
      case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
             TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
           ) of
        (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  KnownType)
 -> KnownType)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    KnownType)
-> KnownType
forall a b. (a -> b) -> a -> b
$ KnownNonFuncType -> KnownType
NonFuncType (KnownNonFuncType -> KnownType) -> KnownNonFuncType -> KnownType
forall a b. (a -> b) -> a -> b
$ Proxy b -> KnownNonFuncType
forall (eb :: Natural).
(KnownNat eb, 1 <= eb) =>
Proxy eb -> KnownNonFuncType
WordNType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n)
        (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  KnownType)
 -> KnownType)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    KnownType)
-> KnownType
forall a b. (a -> b) -> a -> b
$ KnownNonFuncType -> KnownType
NonFuncType (KnownNonFuncType -> KnownType) -> KnownNonFuncType -> KnownType
forall a b. (a -> b) -> a -> b
$ Proxy b -> KnownNonFuncType
forall (eb :: Natural).
(KnownNat eb, 1 <= eb) =>
Proxy eb -> KnownNonFuncType
IntNType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n)
        (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> KnownType
err
    App (App (TypeRep a
tf :: TypeRep f) (TypeRep b
_ :: TypeRep a0)) (TypeRep b
_ :: TypeRep a1) ->
      case ( TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tf (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP),
             TypeRep a -> TypeRep (=->) -> Maybe (a :~~: (=->))
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tf (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: * -> * -> *). Typeable a => TypeRep a
typeRep @(=->)),
             TypeRep a -> TypeRep (-->) -> Maybe (a :~~: (-->))
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tf (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: * -> * -> *). Typeable a => TypeRep a
typeRep @(-->))
           ) of
        (Just a :~~: FP
HRefl, Maybe (a :~~: (=->))
_, Maybe (a :~~: (-->))
_) ->
          forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  KnownType)
 -> KnownType)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    KnownType)
-> KnownType
forall a b. (a -> b) -> a -> b
$ KnownNonFuncType -> KnownType
NonFuncType (KnownNonFuncType -> KnownType) -> KnownNonFuncType -> KnownType
forall a b. (a -> b) -> a -> b
$ Proxy b -> Proxy b -> KnownNonFuncType
forall (eb :: Natural) (sb :: Natural).
ValidFP eb sb =>
Proxy eb -> Proxy sb -> KnownNonFuncType
FPType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @a0) (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @a1)
        (Maybe (a :~~: FP)
_, Just a :~~: (=->)
HRefl, Maybe (a :~~: (-->))
_) ->
          forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  KnownType)
 -> KnownType)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    KnownType)
-> KnownType
forall a b. (a -> b) -> a -> b
$
            let arg :: KnownType
arg = Proxy b -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @a0)
                ret :: KnownType
ret = Proxy b -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @a1)
             in case KnownType
arg of
                  NonFuncType KnownNonFuncType
n -> case KnownType
ret of
                    NonFuncType KnownNonFuncType
m -> [KnownNonFuncType] -> KnownType
TabularFunType [KnownNonFuncType
n, KnownNonFuncType
m]
                    TabularFunType [KnownNonFuncType]
ns -> [KnownNonFuncType] -> KnownType
TabularFunType (KnownNonFuncType
n KnownNonFuncType -> [KnownNonFuncType] -> [KnownNonFuncType]
forall a. a -> [a] -> [a]
: [KnownNonFuncType]
ns)
                    KnownType
_ -> KnownType
err
                  KnownType
_ -> KnownType
err
        (Maybe (a :~~: FP)
_, Maybe (a :~~: (=->))
_, Just a :~~: (-->)
HRefl) ->
          forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  KnownType)
 -> KnownType)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    KnownType)
-> KnownType
forall a b. (a -> b) -> a -> b
$
            let arg :: KnownType
arg = Proxy b -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @a0)
                ret :: KnownType
ret = Proxy b -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType (forall (t :: k1). Proxy t
forall {k} (t :: k). Proxy t
Proxy @a1)
             in case KnownType
arg of
                  NonFuncType KnownNonFuncType
n -> case KnownType
ret of
                    NonFuncType KnownNonFuncType
m -> [KnownNonFuncType] -> KnownType
GeneralFunType [KnownNonFuncType
n, KnownNonFuncType
m]
                    GeneralFunType [KnownNonFuncType]
ns -> [KnownNonFuncType] -> KnownType
GeneralFunType (KnownNonFuncType
n KnownNonFuncType -> [KnownNonFuncType] -> [KnownNonFuncType]
forall a. a -> [a] -> [a]
: [KnownNonFuncType]
ns)
                    KnownType
_ -> KnownType
err
                  KnownType
_ -> KnownType
err
        (Maybe (a :~~: FP), Maybe (a :~~: (=->)), Maybe (a :~~: (-->)))
_ -> KnownType
err
    TypeRep a
_ -> KnownType
err
  where
    tr :: TypeRep a
tr = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: KnownType
err = [Char] -> KnownType
forall a. HasCallStack => [Char] -> a
error ([Char] -> KnownType) -> [Char] -> KnownType
forall a b. (a -> b) -> a -> b
$ [Char]
"knownType: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
tr

-- Bool: 0
-- Integer: 1
-- WordN: 2
-- IntN: 3
-- FP: 4
-- FPRoundingMode: 5
-- AlgReal: 6
serializeKnownNonFuncType :: (MonadPut m) => KnownNonFuncType -> m ()
serializeKnownNonFuncType :: forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serializeKnownNonFuncType KnownNonFuncType
BoolType = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
0
serializeKnownNonFuncType KnownNonFuncType
IntegerType = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
1
serializeKnownNonFuncType (WordNType (Proxy n
Proxy :: Proxy n)) =
  Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
2 m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Natural -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n))
serializeKnownNonFuncType (IntNType (Proxy n
Proxy :: Proxy n)) =
  Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
3 m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Natural -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n))
serializeKnownNonFuncType (FPType (Proxy eb
Proxy :: Proxy eb) (Proxy sb
Proxy :: Proxy sb)) =
  Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
4 m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Natural -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Proxy eb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @eb)) m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Natural -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Proxy sb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @sb))
serializeKnownNonFuncType KnownNonFuncType
FPRoundingModeType = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
5
serializeKnownNonFuncType KnownNonFuncType
AlgRealType = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
6

serializeKnownType :: (MonadPut m) => KnownType -> m ()
serializeKnownType :: forall (m :: * -> *). MonadPut m => KnownType -> m ()
serializeKnownType (NonFuncType KnownNonFuncType
t) = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
0 m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> KnownNonFuncType -> m ()
forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serializeKnownNonFuncType KnownNonFuncType
t
serializeKnownType (TabularFunType [KnownNonFuncType]
ts) =
  Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
1
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ [KnownNonFuncType] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [KnownNonFuncType]
ts)
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (KnownNonFuncType -> m ()) -> [KnownNonFuncType] -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ KnownNonFuncType -> m ()
forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serializeKnownNonFuncType [KnownNonFuncType]
ts
serializeKnownType (GeneralFunType [KnownNonFuncType]
ts) =
  Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
2
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ [KnownNonFuncType] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [KnownNonFuncType]
ts)
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (KnownNonFuncType -> m ()) -> [KnownNonFuncType] -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ KnownNonFuncType -> m ()
forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serializeKnownNonFuncType [KnownNonFuncType]
ts

deserializeKnownNonFuncType :: (MonadGet m) => m KnownNonFuncType
deserializeKnownNonFuncType :: forall (m :: * -> *). MonadGet m => m KnownNonFuncType
deserializeKnownNonFuncType = do
  tag <- m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8
  case tag of
    Word8
0 -> KnownNonFuncType -> m KnownNonFuncType
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return KnownNonFuncType
BoolType
    Word8
1 -> KnownNonFuncType -> m KnownNonFuncType
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return KnownNonFuncType
IntegerType
    Word8
2 -> do
      n <- forall a (m :: * -> *). (Serial a, MonadGet m) => m a
deserialize @Natural
      when (n == 0) $ fail "deserializeKnownNonFuncType: WordN 0 is not allowed"
      case mkPositiveNatRepr n of
        SomePositiveNatRepr (NatRepr n
_ :: NatRepr n) -> KnownNonFuncType -> m KnownNonFuncType
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (KnownNonFuncType -> m KnownNonFuncType)
-> KnownNonFuncType -> m KnownNonFuncType
forall a b. (a -> b) -> a -> b
$ Proxy n -> KnownNonFuncType
forall (eb :: Natural).
(KnownNat eb, 1 <= eb) =>
Proxy eb -> KnownNonFuncType
WordNType (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n)
    Word8
3 -> do
      n <- forall a (m :: * -> *). (Serial a, MonadGet m) => m a
deserialize @Natural
      when (n == 0) $ fail "deserializeKnownNonFuncType: IntN 0 is not allowed"
      case mkPositiveNatRepr n of
        SomePositiveNatRepr (NatRepr n
_ :: NatRepr n) -> KnownNonFuncType -> m KnownNonFuncType
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (KnownNonFuncType -> m KnownNonFuncType)
-> KnownNonFuncType -> m KnownNonFuncType
forall a b. (a -> b) -> a -> b
$ Proxy n -> KnownNonFuncType
forall (eb :: Natural).
(KnownNat eb, 1 <= eb) =>
Proxy eb -> KnownNonFuncType
IntNType (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n)
    Word8
4 -> do
      eb <- forall a (m :: * -> *). (Serial a, MonadGet m) => m a
deserialize @Natural
      sb <- deserialize @Natural
      unless (checkDynamicValidFP eb sb) $ fail invalidFPMessage
      case (mkPositiveNatRepr eb, mkPositiveNatRepr sb) of
        ( SomePositiveNatRepr (NatRepr n
_ :: NatRepr eb),
          SomePositiveNatRepr (NatRepr n
_ :: NatRepr sb)
          ) ->
            forall (eb :: Natural) (sb :: Natural) r.
(KnownNat eb, KnownNat sb) =>
(ValidFP eb sb => r) -> r
withUnsafeValidFP @eb @sb ((ValidFP n n => m KnownNonFuncType) -> m KnownNonFuncType)
-> (ValidFP n n => m KnownNonFuncType) -> m KnownNonFuncType
forall a b. (a -> b) -> a -> b
$ KnownNonFuncType -> m KnownNonFuncType
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (KnownNonFuncType -> m KnownNonFuncType)
-> KnownNonFuncType -> m KnownNonFuncType
forall a b. (a -> b) -> a -> b
$ Proxy n -> Proxy n -> KnownNonFuncType
forall (eb :: Natural) (sb :: Natural).
ValidFP eb sb =>
Proxy eb -> Proxy sb -> KnownNonFuncType
FPType (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @eb) (forall (t :: Natural). Proxy t
forall {k} (t :: k). Proxy t
Proxy @sb)
    Word8
5 -> KnownNonFuncType -> m KnownNonFuncType
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return KnownNonFuncType
FPRoundingModeType
    Word8
6 -> KnownNonFuncType -> m KnownNonFuncType
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return KnownNonFuncType
AlgRealType
    Word8
_ -> [Char] -> m KnownNonFuncType
forall a. [Char] -> m a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"deserializeKnownNonFuncType: Unknown type tag"

deserializeKnownType :: (MonadGet m) => m KnownType
deserializeKnownType :: forall (m :: * -> *). MonadGet m => m KnownType
deserializeKnownType = do
  tag <- m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8
  case tag of
    Word8
0 -> KnownNonFuncType -> KnownType
NonFuncType (KnownNonFuncType -> KnownType)
-> m KnownNonFuncType -> m KnownType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m KnownNonFuncType
forall (m :: * -> *). MonadGet m => m KnownNonFuncType
deserializeKnownNonFuncType
    Word8
1 -> do
      n <- m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8
      nfs <- replicateM (fromIntegral n) deserializeKnownNonFuncType
      return $ TabularFunType nfs
    Word8
2 -> do
      n <- m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8
      nfs <- replicateM (fromIntegral n) deserializeKnownNonFuncType
      return $ GeneralFunType nfs
    Word8
_ -> [Char] -> m KnownType
forall a. [Char] -> m a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"deserializeKnownType: Unknown type tag"

instance Serial KnownType where
  serialize :: forall (m :: * -> *). MonadPut m => KnownType -> m ()
serialize = KnownType -> m ()
forall (m :: * -> *). MonadPut m => KnownType -> m ()
serializeKnownType
  deserialize :: forall (m :: * -> *). MonadGet m => m KnownType
deserialize = m KnownType
forall (m :: * -> *). MonadGet m => m KnownType
deserializeKnownType

instance Cereal.Serialize KnownType where
  put :: Putter KnownType
put = Putter KnownType
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => KnownType -> m ()
serialize
  get :: Get KnownType
get = Get KnownType
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m KnownType
deserialize

instance Binary.Binary KnownType where
  put :: KnownType -> Put
put = KnownType -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => KnownType -> m ()
serialize
  get :: Get KnownType
get = Get KnownType
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m KnownType
deserialize

instance Serial KnownNonFuncType where
  serialize :: forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serialize = KnownNonFuncType -> m ()
forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serializeKnownNonFuncType
  deserialize :: forall (m :: * -> *). MonadGet m => m KnownNonFuncType
deserialize = m KnownNonFuncType
forall (m :: * -> *). MonadGet m => m KnownNonFuncType
deserializeKnownNonFuncType

instance Cereal.Serialize KnownNonFuncType where
  put :: Putter KnownNonFuncType
put = Putter KnownNonFuncType
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serialize
  get :: Get KnownNonFuncType
get = Get KnownNonFuncType
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m KnownNonFuncType
deserialize

instance Binary.Binary KnownNonFuncType where
  put :: KnownNonFuncType -> Put
put = KnownNonFuncType -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serialize
  get :: Get KnownNonFuncType
get = Get KnownNonFuncType
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m KnownNonFuncType
deserialize

instance (IsSymbolKind knd) => Serial (SomeTypedSymbol knd) where
  serialize :: forall (m :: * -> *). MonadPut m => SomeTypedSymbol knd -> m ()
serialize (SomeTypedSymbol tsb :: TypedSymbol knd t
tsb@(TypedSymbol Symbol
sb)) =
    case forall (knd :: SymbolKind).
IsSymbolKind knd =>
Either (knd :~~: 'ConstantKind) (knd :~~: 'AnyKind)
decideSymbolKind @knd of
      Left knd :~~: 'ConstantKind
HRefl -> do
        KnownNonFuncType -> m ()
forall (m :: * -> *). MonadPut m => KnownNonFuncType -> m ()
serializeKnownNonFuncType (KnownNonFuncType -> m ()) -> KnownNonFuncType -> m ()
forall a b. (a -> b) -> a -> b
$ TypedSymbol knd t -> KnownNonFuncType
forall a (p :: * -> *).
SupportedNonFuncPrim a =>
p a -> KnownNonFuncType
knownNonFuncType TypedSymbol knd t
tsb
        Symbol -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Symbol -> m ()
serialize Symbol
sb
      Right knd :~~: 'AnyKind
HRefl -> do
        KnownType -> m ()
forall (m :: * -> *). MonadPut m => KnownType -> m ()
serializeKnownType (KnownType -> m ()) -> KnownType -> m ()
forall a b. (a -> b) -> a -> b
$ TypedSymbol knd t -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType TypedSymbol knd t
tsb
        Symbol -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Symbol -> m ()
serialize Symbol
sb
  deserialize :: forall (m :: * -> *). MonadGet m => m (SomeTypedSymbol knd)
deserialize = case forall (knd :: SymbolKind).
IsSymbolKind knd =>
Either (knd :~~: 'ConstantKind) (knd :~~: 'AnyKind)
decideSymbolKind @knd of
    Left knd :~~: 'ConstantKind
HRefl -> do
      kt <- m KnownNonFuncType
forall (m :: * -> *). MonadGet m => m KnownNonFuncType
deserializeKnownNonFuncType
      case witnessKnownNonFuncType kt of
        KnownNonFuncTypeWitness (Proxy a
Proxy :: Proxy a) -> do
          sb <- m Symbol
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m Symbol
deserialize
          return $ SomeTypedSymbol $ TypedSymbol @a sb
    Right knd :~~: 'AnyKind
HRefl -> do
      kt <- m KnownType
forall (m :: * -> *). MonadGet m => m KnownType
deserializeKnownType
      case witnessKnownType kt of
        KnownTypeWitness (Proxy a
Proxy :: Proxy a) -> do
          sb <- m Symbol
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m Symbol
deserialize
          return $ SomeTypedSymbol $ TypedSymbol @a sb

instance (IsSymbolKind knd) => Cereal.Serialize (SomeTypedSymbol knd) where
  put :: Putter (SomeTypedSymbol knd)
put = Putter (SomeTypedSymbol knd)
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => SomeTypedSymbol knd -> m ()
serialize
  get :: Get (SomeTypedSymbol knd)
get = Get (SomeTypedSymbol knd)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (SomeTypedSymbol knd)
deserialize

instance (IsSymbolKind knd) => Binary.Binary (SomeTypedSymbol knd) where
  put :: SomeTypedSymbol knd -> Put
put = SomeTypedSymbol knd -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => SomeTypedSymbol knd -> m ()
serialize
  get :: Get (SomeTypedSymbol knd)
get = Get (SomeTypedSymbol knd)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (SomeTypedSymbol knd)
deserialize

instance (IsSymbolKind knd, Typeable a) => Serial (TypedSymbol knd a) where
  serialize :: forall (m :: * -> *). MonadPut m => TypedSymbol knd a -> m ()
serialize TypedSymbol knd a
tsb = SomeTypedSymbol knd -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => SomeTypedSymbol knd -> m ()
serialize (SomeTypedSymbol knd -> m ()) -> SomeTypedSymbol knd -> m ()
forall a b. (a -> b) -> a -> b
$ TypedSymbol knd a -> SomeTypedSymbol knd
forall (knd :: SymbolKind) t.
TypedSymbol knd t -> SomeTypedSymbol knd
someTypedSymbol TypedSymbol knd a
tsb
  deserialize :: forall (m :: * -> *). MonadGet m => m (TypedSymbol knd a)
deserialize = do
    SomeTypedSymbol (tsb@TypedSymbol {} :: TypedSymbol knd b) <- m (SomeTypedSymbol knd)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (SomeTypedSymbol knd)
deserialize
    case eqTypeRep (typeRep @a) (primTypeRep @b) of
      Just a :~~: t
HRefl -> TypedSymbol knd a -> m (TypedSymbol knd a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return TypedSymbol knd a
TypedSymbol knd t
tsb
      Maybe (a :~~: t)
Nothing -> [Char] -> m (TypedSymbol knd a)
forall a. [Char] -> m a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"deserialize TypedSymbol: type mismatch"

instance
  (IsSymbolKind knd, Typeable a) =>
  Cereal.Serialize (TypedSymbol knd a)
  where
  put :: Putter (TypedSymbol knd a)
put = Putter (TypedSymbol knd a)
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedSymbol knd a -> m ()
serialize
  get :: Get (TypedSymbol knd a)
get = Get (TypedSymbol knd a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedSymbol knd a)
deserialize

instance
  (IsSymbolKind knd, Typeable a) =>
  Binary.Binary (TypedSymbol knd a)
  where
  put :: TypedSymbol knd a -> Put
put = TypedSymbol knd a -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedSymbol knd a -> m ()
serialize
  get :: Get (TypedSymbol knd a)
get = Get (TypedSymbol knd a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedSymbol knd a)
deserialize

conTermTag :: Word8
conTermTag :: Word8
conTermTag = Word8
0

symTermTag :: Word8
symTermTag :: Word8
symTermTag = Word8
1

forallTermTag :: Word8
forallTermTag :: Word8
forallTermTag = Word8
2

existsTermTag :: Word8
existsTermTag :: Word8
existsTermTag = Word8
3

notTermTag :: Word8
notTermTag :: Word8
notTermTag = Word8
4

orTermTag :: Word8
orTermTag :: Word8
orTermTag = Word8
5

andTermTag :: Word8
andTermTag :: Word8
andTermTag = Word8
6

eqTermTag :: Word8
eqTermTag :: Word8
eqTermTag = Word8
7

distinctTermTag :: Word8
distinctTermTag :: Word8
distinctTermTag = Word8
8

iteTermTag :: Word8
iteTermTag :: Word8
iteTermTag = Word8
9

addNumTermTag :: Word8
addNumTermTag :: Word8
addNumTermTag = Word8
10

negNumTermTag :: Word8
negNumTermTag :: Word8
negNumTermTag = Word8
11

mulNumTermTag :: Word8
mulNumTermTag :: Word8
mulNumTermTag = Word8
12

absNumTermTag :: Word8
absNumTermTag :: Word8
absNumTermTag = Word8
13

signumNumTermTag :: Word8
signumNumTermTag :: Word8
signumNumTermTag = Word8
14

ltOrdTermTag :: Word8
ltOrdTermTag :: Word8
ltOrdTermTag = Word8
15

leOrdTermTag :: Word8
leOrdTermTag :: Word8
leOrdTermTag = Word8
16

andBitsTermTag :: Word8
andBitsTermTag :: Word8
andBitsTermTag = Word8
17

orBitsTermTag :: Word8
orBitsTermTag :: Word8
orBitsTermTag = Word8
18

xorBitsTermTag :: Word8
xorBitsTermTag :: Word8
xorBitsTermTag = Word8
19

complementBitsTermTag :: Word8
complementBitsTermTag :: Word8
complementBitsTermTag = Word8
20

shiftLeftTermTag :: Word8
shiftLeftTermTag :: Word8
shiftLeftTermTag = Word8
21

shiftRightTermTag :: Word8
shiftRightTermTag :: Word8
shiftRightTermTag = Word8
22

rotateLeftTermTag :: Word8
rotateLeftTermTag :: Word8
rotateLeftTermTag = Word8
23

rotateRightTermTag :: Word8
rotateRightTermTag :: Word8
rotateRightTermTag = Word8
24

bitCastTermTag :: Word8
bitCastTermTag :: Word8
bitCastTermTag = Word8
25

bitCastOrTermTag :: Word8
bitCastOrTermTag :: Word8
bitCastOrTermTag = Word8
26

bvConcatTermTag :: Word8
bvConcatTermTag :: Word8
bvConcatTermTag = Word8
27

bvSelectTermTag :: Word8
bvSelectTermTag :: Word8
bvSelectTermTag = Word8
28

bvExtendTermTag :: Word8
bvExtendTermTag :: Word8
bvExtendTermTag = Word8
29

applyTermTag :: Word8
applyTermTag :: Word8
applyTermTag = Word8
30

divIntegralTermTag :: Word8
divIntegralTermTag :: Word8
divIntegralTermTag = Word8
31

modIntegralTermTag :: Word8
modIntegralTermTag :: Word8
modIntegralTermTag = Word8
32

quotIntegralTermTag :: Word8
quotIntegralTermTag :: Word8
quotIntegralTermTag = Word8
33

remIntegralTermTag :: Word8
remIntegralTermTag :: Word8
remIntegralTermTag = Word8
34

fpTraitTermTag :: Word8
fpTraitTermTag :: Word8
fpTraitTermTag = Word8
35

fdivTermTag :: Word8
fdivTermTag :: Word8
fdivTermTag = Word8
36

recipTermTag :: Word8
recipTermTag :: Word8
recipTermTag = Word8
37

floatingUnaryTermTag :: Word8
floatingUnaryTermTag :: Word8
floatingUnaryTermTag = Word8
38

powerTermTag :: Word8
powerTermTag :: Word8
powerTermTag = Word8
39

fpUnaryTermTag :: Word8
fpUnaryTermTag :: Word8
fpUnaryTermTag = Word8
40

fpBinaryTermTag :: Word8
fpBinaryTermTag :: Word8
fpBinaryTermTag = Word8
41

fpRoundingUnaryTermTag :: Word8
fpRoundingUnaryTermTag :: Word8
fpRoundingUnaryTermTag = Word8
42

fpRoundingBinaryTermTag :: Word8
fpRoundingBinaryTermTag :: Word8
fpRoundingBinaryTermTag = Word8
43

fpFMATermTag :: Word8
fpFMATermTag :: Word8
fpFMATermTag = Word8
44

fromIntegralTermTag :: Word8
fromIntegralTermTag :: Word8
fromIntegralTermTag = Word8
45

fromFPOrTermTag :: Word8
fromFPOrTermTag :: Word8
fromFPOrTermTag = Word8
46

toFPTermTag :: Word8
toFPTermTag :: Word8
toFPTermTag = Word8
47

terminalTag :: Word8
terminalTag :: Word8
terminalTag = Word8
255

asBoolTerm :: (HasCallStack) => SomeTerm -> Term Bool
asBoolTerm :: HasCallStack => SomeTerm -> Term Bool
asBoolTerm (SomeTerm (Term a
t :: Term a)) =
  case TypeRep Bool -> TypeRep a -> Maybe (Bool :~~: a)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep (forall t. SupportedPrim t => TypeRep t
primTypeRep @Bool) (forall t. SupportedPrim t => TypeRep t
primTypeRep @a) of
    Just Bool :~~: a
HRefl -> Term a
Term Bool
t
    Maybe (Bool :~~: a)
Nothing -> [Char] -> Term Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"asBoolTerm: type mismatch"

asSameTypeNonEmptyTermList ::
  (HasCallStack) =>
  NonEmpty SomeTerm ->
  (forall b. NonEmpty (Term b) -> r) ->
  r
asSameTypeNonEmptyTermList :: forall r.
HasCallStack =>
NonEmpty SomeTerm -> (forall b. NonEmpty (Term b) -> r) -> r
asSameTypeNonEmptyTermList (SomeTerm (Term a
t :: Term a) :| [SomeTerm]
ts) forall b. NonEmpty (Term b) -> r
f =
  NonEmpty (Term a) -> r
forall b. NonEmpty (Term b) -> r
f (NonEmpty (Term a) -> r) -> NonEmpty (Term a) -> r
forall a b. (a -> b) -> a -> b
$ Term a
t Term a -> [Term a] -> NonEmpty (Term a)
forall a. a -> [a] -> NonEmpty a
:| (SomeTerm -> Term a) -> [SomeTerm] -> [Term a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Term a -> SomeTerm -> Term a
unsafeCastTerm Term a
t) [SomeTerm]
ts
  where
    unsafeCastTerm :: Term a -> SomeTerm -> Term a
    unsafeCastTerm :: Term a -> SomeTerm -> Term a
unsafeCastTerm Term a
_ (SomeTerm Term a
b) =
      case Term a -> Maybe (Term a)
forall a b. Typeable b => Term a -> Maybe (Term b)
castTerm Term a
b of
        Just Term a
r -> Term a
r
        Maybe (Term a)
Nothing -> [Char] -> Term a
forall a. HasCallStack => [Char] -> a
error [Char]
"asSameTypeNonEmptyTermList: type mismatch"

asNumTypeTerm ::
  (HasCallStack) =>
  SomeTerm ->
  (forall n. (PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) => Term n -> r) ->
  r
asNumTypeTerm :: forall r.
HasCallStack =>
SomeTerm
-> (forall n.
    (PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
    Term n -> r)
-> r
asNumTypeTerm (SomeTerm (Term a
t1 :: Term a)) forall n.
(PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
Term n -> r
f =
  case ( TypeRep a -> TypeRep Integer -> Maybe (a :~~: Integer)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @Integer),
         TypeRep a -> TypeRep AlgReal -> Maybe (a :~~: AlgReal)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @AlgReal)
       ) of
    (Just a :~~: Integer
HRefl, Maybe (a :~~: AlgReal)
_) -> Term a -> r
forall n.
(PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
Term n -> r
f Term a
t1
    (Maybe (a :~~: Integer)
_, Just a :~~: AlgReal
HRefl) -> Term a -> r
forall n.
(PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
Term n -> r
f Term a
t1
    (Maybe (a :~~: Integer), Maybe (a :~~: AlgReal))
_ ->
      case TypeRep a
ta of
        App (ta :: TypeRep a
ta@(Con TyCon
_) :: TypeRep w) (TypeRep b
_ :: TypeRep n) ->
          case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
                 TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
               ) of
            (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n.
(PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
Term n -> r
f Term a
t1
            (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n.
(PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
Term n -> r
f Term a
t1
            (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> r
err
        App (App (TypeRep a
tf :: TypeRep f) (TypeRep b
_ :: TypeRep a0)) (TypeRep b
_ :: TypeRep a1) ->
          case TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tf (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP) of
            Just a :~~: FP
HRefl ->
              forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n.
(PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
Term n -> r
f Term a
t1
            Maybe (a :~~: FP)
_ -> r
err
        TypeRep a
_ -> r
err
  where
    ta :: TypeRep a
ta = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: r
err = [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$ [Char]
"asNumTypeTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
ta

asOrdTypeTerm ::
  (HasCallStack) => SomeTerm -> (forall n. (PEvalOrdTerm n) => Term n -> r) -> r
asOrdTypeTerm :: forall r.
HasCallStack =>
SomeTerm -> (forall n. PEvalOrdTerm n => Term n -> r) -> r
asOrdTypeTerm (SomeTerm (Term a
t1 :: Term a)) forall n. PEvalOrdTerm n => Term n -> r
f =
  case ( TypeRep a -> TypeRep Integer -> Maybe (a :~~: Integer)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @Integer),
         TypeRep a -> TypeRep AlgReal -> Maybe (a :~~: AlgReal)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @AlgReal),
         TypeRep a
-> TypeRep FPRoundingMode -> Maybe (a :~~: FPRoundingMode)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @FPRoundingMode)
       ) of
    (Just a :~~: Integer
HRefl, Maybe (a :~~: AlgReal)
_, Maybe (a :~~: FPRoundingMode)
_) -> Term a -> r
forall n. PEvalOrdTerm n => Term n -> r
f Term a
t1
    (Maybe (a :~~: Integer)
_, Just a :~~: AlgReal
HRefl, Maybe (a :~~: FPRoundingMode)
_) -> Term a -> r
forall n. PEvalOrdTerm n => Term n -> r
f Term a
t1
    (Maybe (a :~~: Integer)
_, Maybe (a :~~: AlgReal)
_, Just a :~~: FPRoundingMode
HRefl) -> Term a -> r
forall n. PEvalOrdTerm n => Term n -> r
f Term a
t1
    (Maybe (a :~~: Integer), Maybe (a :~~: AlgReal),
 Maybe (a :~~: FPRoundingMode))
_ ->
      case TypeRep a
ta of
        App (ta :: TypeRep a
ta@(Con TyCon
_) :: TypeRep w) (TypeRep b
_ :: TypeRep n) ->
          case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
                 TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
               ) of
            (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n. PEvalOrdTerm n => Term n -> r
f Term a
t1
            (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n. PEvalOrdTerm n => Term n -> r
f Term a
t1
            (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> r
err
        App (App (TypeRep a
tf :: TypeRep f) (TypeRep b
_ :: TypeRep a0)) (TypeRep b
_ :: TypeRep a1) ->
          case TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tf (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP) of
            Just a :~~: FP
HRefl ->
              forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n. PEvalOrdTerm n => Term n -> r
f Term a
t1
            Maybe (a :~~: FP)
_ -> r
err
        TypeRep a
_ -> r
err
  where
    ta :: TypeRep a
ta = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: r
err = [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$ [Char]
"asOrdTypeTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
ta

asBitsTypeTerm ::
  (HasCallStack) =>
  SomeTerm ->
  ( forall n.
    (PEvalBitwiseTerm n, PEvalShiftTerm n, PEvalRotateTerm n) =>
    Term n ->
    r
  ) ->
  r
asBitsTypeTerm :: forall r.
HasCallStack =>
SomeTerm
-> (forall n.
    (PEvalBitwiseTerm n, PEvalShiftTerm n, PEvalRotateTerm n) =>
    Term n -> r)
-> r
asBitsTypeTerm (SomeTerm (Term a
t1 :: Term a)) forall n.
(PEvalBitwiseTerm n, PEvalShiftTerm n, PEvalRotateTerm n) =>
Term n -> r
f =
  case TypeRep a
ta of
    App (ta :: TypeRep a
ta@(Con TyCon
_) :: TypeRep w) (TypeRep b
_ :: TypeRep n) ->
      case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
             TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
           ) of
        (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n.
(PEvalBitwiseTerm n, PEvalShiftTerm n, PEvalRotateTerm n) =>
Term n -> r
f Term a
t1
        (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n.
(PEvalBitwiseTerm n, PEvalShiftTerm n, PEvalRotateTerm n) =>
Term n -> r
f Term a
t1
        (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> r
err
    TypeRep a
_ -> r
err
  where
    ta :: TypeRep a
ta = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: r
err = [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$ [Char]
"asBitsTypeTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
ta

asIntegralTypeTerm ::
  (HasCallStack) =>
  SomeTerm ->
  (forall n. (PEvalDivModIntegralTerm n) => Term n -> r) ->
  r
asIntegralTypeTerm :: forall r.
HasCallStack =>
SomeTerm
-> (forall n. PEvalDivModIntegralTerm n => Term n -> r) -> r
asIntegralTypeTerm (SomeTerm (Term a
t1 :: Term a)) forall n. PEvalDivModIntegralTerm n => Term n -> r
f =
  case TypeRep a -> TypeRep Integer -> Maybe (a :~~: Integer)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @Integer) of
    Just a :~~: Integer
HRefl -> Term a -> r
forall n. PEvalDivModIntegralTerm n => Term n -> r
f Term a
t1
    Maybe (a :~~: Integer)
_ -> case TypeRep a
ta of
      App (ta :: TypeRep a
ta@(Con TyCon
_) :: TypeRep w) (TypeRep b
_ :: TypeRep n) ->
        case (TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN), TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)) of
          (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n. PEvalDivModIntegralTerm n => Term n -> r
f Term a
t1
          (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n. PEvalDivModIntegralTerm n => Term n -> r
f Term a
t1
          (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> r
err
      TypeRep a
_ -> r
err
  where
    ta :: TypeRep a
ta = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: r
err = [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$ [Char]
"asOrdTypeTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
ta

asFloatingFractionalTypeTerm ::
  (HasCallStack) =>
  SomeTerm ->
  (forall n. (PEvalFloatingTerm n, PEvalFractionalTerm n) => Term n -> r) ->
  r
asFloatingFractionalTypeTerm :: forall r.
HasCallStack =>
SomeTerm
-> (forall n.
    (PEvalFloatingTerm n, PEvalFractionalTerm n) =>
    Term n -> r)
-> r
asFloatingFractionalTypeTerm (SomeTerm (Term a
t1 :: Term a)) forall n.
(PEvalFloatingTerm n, PEvalFractionalTerm n) =>
Term n -> r
f =
  case TypeRep a -> TypeRep AlgReal -> Maybe (a :~~: AlgReal)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @AlgReal) of
    Just a :~~: AlgReal
HRefl -> Term a -> r
forall n.
(PEvalFloatingTerm n, PEvalFractionalTerm n) =>
Term n -> r
f Term a
t1
    Maybe (a :~~: AlgReal)
_ -> case TypeRep a
ta of
      App (App (TypeRep a
tf :: TypeRep f) (TypeRep b
_ :: TypeRep a0)) (TypeRep b
_ :: TypeRep a1) ->
        case TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tf (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP) of
          Just a :~~: FP
HRefl -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term a -> r
forall n.
(PEvalFloatingTerm n, PEvalFractionalTerm n) =>
Term n -> r
f Term a
t1
          Maybe (a :~~: FP)
_ -> r
err
      TypeRep a
_ -> r
err
  where
    ta :: TypeRep a
ta = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: r
err = [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$ [Char]
"asFloatingFractionalTypeTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
ta

asFPTypeTerm ::
  (HasCallStack) =>
  SomeTerm ->
  (forall eb sb. (ValidFP eb sb) => Term (FP eb sb) -> r) ->
  r
asFPTypeTerm :: forall r.
HasCallStack =>
SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb) -> r)
-> r
asFPTypeTerm (SomeTerm (Term a
t1 :: Term a)) forall (eb :: Natural) (sb :: Natural).
ValidFP eb sb =>
Term (FP eb sb) -> r
f =
  case TypeRep a
ta of
    App (App (TypeRep a
tf :: TypeRep f) (TypeRep b
_ :: TypeRep a0)) (TypeRep b
_ :: TypeRep a1) ->
      case TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tf (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP) of
        Just a :~~: FP
HRefl -> forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  r)
 -> r)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    r)
-> r
forall a b. (a -> b) -> a -> b
$ Term (FP b b) -> r
forall (eb :: Natural) (sb :: Natural).
ValidFP eb sb =>
Term (FP eb sb) -> r
f Term a
Term (FP b b)
t1
        Maybe (a :~~: FP)
_ -> r
err
    TypeRep a
_ -> r
err
  where
    ta :: TypeRep a
ta = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: r
err = [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$ [Char]
"asFPTypeTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
ta

asSameType ::
  (HasCallStack) => Term a -> SomeTerm -> (Term a -> r) -> r
asSameType :: forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType (Term a
SupportedTerm :: Term a) (SomeTerm (Term a
t2 :: Term b)) Term a -> r
f =
  case TypeRep a -> TypeRep a -> Maybe (a :~~: a)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep (forall t. SupportedPrim t => TypeRep t
primTypeRep @a) (forall t. SupportedPrim t => TypeRep t
primTypeRep @b) of
    Just a :~~: a
HRefl -> Term a -> r
f Term a
Term a
t2
    Maybe (a :~~: a)
Nothing -> [Char] -> r
forall a. HasCallStack => [Char] -> a
error [Char]
"asSameType: type mismatch"

asFPRoundingTerm ::
  (HasCallStack) => SomeTerm -> (Term FPRoundingMode -> r) -> r
asFPRoundingTerm :: forall r.
HasCallStack =>
SomeTerm -> (Term FPRoundingMode -> r) -> r
asFPRoundingTerm (SomeTerm (Term a
t1 :: Term a)) Term FPRoundingMode -> r
f =
  case TypeRep a
-> TypeRep FPRoundingMode -> Maybe (a :~~: FPRoundingMode)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @FPRoundingMode) of
    Just a :~~: FPRoundingMode
HRefl -> Term FPRoundingMode -> r
f Term a
Term FPRoundingMode
t1
    Maybe (a :~~: FPRoundingMode)
_ -> r
err
  where
    ta :: TypeRep a
ta = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: r
err = [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$ [Char]
"asFPRoundingTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
ta

constructBitCastOrTerm :: (HasCallStack) => SomeTerm -> SomeTerm -> SomeTerm
constructBitCastOrTerm :: HasCallStack => SomeTerm -> SomeTerm -> SomeTerm
constructBitCastOrTerm (SomeTerm (Term a
td :: Term d)) (SomeTerm (Term a
tv :: Term v)) =
  forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @d (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
    forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @v (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
      case (TypeRep a
trv, TypeRep a
trd) of
        ( App
            (App (trfp :: TypeRep a
trfp@(Con TyCon
_) :: TypeRep fp) (TypeRep b
treb :: TypeRep eb))
            (TypeRep b
trsb :: TypeRep sb),
          App (trbv :: TypeRep a
trbv@(Con TyCon
_) :: TypeRep bv) (TypeRep b
trn :: TypeRep n)
          ) ->
            case ( TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trfp (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP),
                   TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
                   TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
                 ) of
              (Just a :~~: FP
HRefl, Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) ->
                if TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
treb Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trsb Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
== TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn
                  then case forall (a :: k1) (b :: k1). a :~: b
forall {k} (a :: k) (b :: k). a :~: b
unsafeAxiom @n @(eb + sb) of
                    b :~: (b + b)
Refl -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a -> Term a
forall a b. PEvalBitCastOrTerm a b => Term b -> Term a -> Term b
bitCastOrTerm Term a
td Term a
tv :: Term d)
                  else SomeTerm
forall r. r
err
              (Just a :~~: FP
HRefl, Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) ->
                if TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
treb Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trsb Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
== TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn
                  then case forall (a :: k1) (b :: k1). a :~: b
forall {k} (a :: k) (b :: k). a :~: b
unsafeAxiom @n @(eb + sb) of
                    b :~: (b + b)
Refl -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a -> Term a
forall a b. PEvalBitCastOrTerm a b => Term b -> Term a -> Term b
bitCastOrTerm Term a
td Term a
tv :: Term d)
                  else SomeTerm
forall r. r
err
              (Maybe (a :~~: FP), Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> SomeTerm
forall r. r
err
        (TypeRep a, TypeRep a)
_ -> SomeTerm
forall r. r
err
  where
    trd :: TypeRep a
trd = forall t. SupportedPrim t => TypeRep t
primTypeRep @d
    trv :: TypeRep a
trv = forall t. SupportedPrim t => TypeRep t
primTypeRep @v
    err :: r
    err :: forall r. r
err =
      [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$
        [Char]
"constructBitCastOrTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
trd [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
trv

constructBitCastTerm :: (HasCallStack) => SomeTerm -> KnownType -> SomeTerm
constructBitCastTerm :: HasCallStack => SomeTerm -> KnownType -> SomeTerm
constructBitCastTerm (SomeTerm (Term a
t1 :: Term a)) KnownType
retType =
  case KnownType -> KnownTypeWitness
witnessKnownType KnownType
retType of
    KnownTypeWitness (Proxy a
_ :: Proxy b) -> do
      let tb :: TypeRep a
tb = forall t. SupportedPrim t => TypeRep t
primTypeRep @b
      forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$ forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @b (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$ case (TypeRep a -> TypeRep Bool -> Maybe (a :~~: Bool)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
ta (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @Bool), TypeRep a
ta) of
        (Just a :~~: Bool
HRefl, TypeRep a
_) -> case TypeRep a
tb of
          App (tw :: TypeRep a
tw@(Con TyCon
_) :: TypeRep w) (TypeRep b
tn :: TypeRep n) ->
            case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
                   TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN),
                   TypeRep b -> TypeRep 1 -> Maybe (b :~~: 1)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep b
tn (forall (a :: Natural). Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @1)
                 ) of
              (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_, Just b :~~: 1
HRefl) -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a
forall a b.
(PEvalBitCastTerm a b, SupportedPrim b) =>
Term a -> Term b
bitCastTerm Term a
t1 :: Term b)
              (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl, Just b :~~: 1
HRefl) -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a
forall a b.
(PEvalBitCastTerm a b, SupportedPrim b) =>
Term a -> Term b
bitCastTerm Term a
t1 :: Term b)
              (Maybe (a :~~: WordN), Maybe (a :~~: IntN), Maybe (b :~~: 1))
_ -> SomeTerm
forall r. r
err
          TypeRep a
_ -> SomeTerm
forall r. r
err
        (Maybe (a :~~: Bool)
_, App (tw :: TypeRep a
tw@(Con TyCon
_) :: TypeRep w) (TypeRep b
tn :: TypeRep n)) ->
          case (TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN), TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)) of
            (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> Term (WordN b)
-> TypeRep b -> TypeRep a -> TypeRep IntN -> SomeTerm
forall (bv :: Natural -> *) (n :: Natural) b (bv2 :: Natural -> *).
(forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalBitCastTerm (bv n) (bv2 n),
 PEvalBitCastTerm (bv 1) Bool,
 forall (n :: Natural) (eb :: Natural) (sb :: Natural).
 (KnownNat n, 1 <= n, ValidFP eb sb, (eb + sb) ~ n) =>
 PEvalBitCastTerm (bv n) (FP eb sb),
 KnownNat n, 1 <= n, SupportedPrim b,
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 SupportedPrim (bv2 n)) =>
Term (bv n) -> TypeRep n -> TypeRep b -> TypeRep bv2 -> SomeTerm
fromBV Term a
Term (WordN b)
t1 TypeRep b
TypeRep b
tn TypeRep a
tb (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
            (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> Term (IntN b)
-> TypeRep b -> TypeRep a -> TypeRep WordN -> SomeTerm
forall (bv :: Natural -> *) (n :: Natural) b (bv2 :: Natural -> *).
(forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalBitCastTerm (bv n) (bv2 n),
 PEvalBitCastTerm (bv 1) Bool,
 forall (n :: Natural) (eb :: Natural) (sb :: Natural).
 (KnownNat n, 1 <= n, ValidFP eb sb, (eb + sb) ~ n) =>
 PEvalBitCastTerm (bv n) (FP eb sb),
 KnownNat n, 1 <= n, SupportedPrim b,
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 SupportedPrim (bv2 n)) =>
Term (bv n) -> TypeRep n -> TypeRep b -> TypeRep bv2 -> SomeTerm
fromBV Term a
Term (IntN b)
t1 TypeRep b
TypeRep b
tn TypeRep a
tb (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN)
            (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> SomeTerm
forall r. r
err
        (Maybe (a :~~: Bool), TypeRep a)
_ -> SomeTerm
forall r. r
err
  where
    ta :: TypeRep a
ta = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: r
    err :: forall r. r
err =
      [Char] -> r
forall a. HasCallStack => [Char] -> a
error ([Char] -> r) -> [Char] -> r
forall a b. (a -> b) -> a -> b
$
        [Char]
"constructBitCastTerm: unsupported type: "
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
ta
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> KnownType -> [Char]
forall a. Show a => a -> [Char]
show KnownType
retType
    fromBV ::
      forall bv n b bv2.
      ( forall n. (KnownNat n, 1 <= n) => PEvalBitCastTerm (bv n) (bv2 n),
        PEvalBitCastTerm (bv 1) Bool,
        forall n eb sb.
        (KnownNat n, 1 <= n, ValidFP eb sb, (eb + sb) ~ n) =>
        PEvalBitCastTerm (bv n) (FP eb sb),
        KnownNat n,
        1 <= n,
        SupportedPrim b,
        forall n. (KnownNat n, 1 <= n) => SupportedPrim (bv2 n)
      ) =>
      Term (bv n) ->
      TypeRep n ->
      TypeRep b ->
      TypeRep bv2 ->
      SomeTerm
    fromBV :: forall (bv :: Natural -> *) (n :: Natural) b (bv2 :: Natural -> *).
(forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalBitCastTerm (bv n) (bv2 n),
 PEvalBitCastTerm (bv 1) Bool,
 forall (n :: Natural) (eb :: Natural) (sb :: Natural).
 (KnownNat n, 1 <= n, ValidFP eb sb, (eb + sb) ~ n) =>
 PEvalBitCastTerm (bv n) (FP eb sb),
 KnownNat n, 1 <= n, SupportedPrim b,
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 SupportedPrim (bv2 n)) =>
Term (bv n) -> TypeRep n -> TypeRep b -> TypeRep bv2 -> SomeTerm
fromBV Term (bv n)
t1 TypeRep n
tn TypeRep b
tb TypeRep bv2
tbv2 =
      case (TypeRep n -> TypeRep 1 -> Maybe (n :~~: 1)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep n
tn (forall (a :: Natural). Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @1), TypeRep b -> TypeRep Bool -> Maybe (b :~~: Bool)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep b
tb (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @Bool)) of
        (Just n :~~: 1
HRefl, Just b :~~: Bool
HRefl) -> Term b -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (bv n) -> Term b
forall a b.
(PEvalBitCastTerm a b, SupportedPrim b) =>
Term a -> Term b
bitCastTerm Term (bv n)
t1 :: Term b)
        (Maybe (n :~~: 1), Maybe (b :~~: Bool))
_ -> case TypeRep b
tb of
          (App (tw' :: TypeRep a
tw'@(Con TyCon
_) :: TypeRep w') (TypeRep b
tn' :: TypeRep n')) ->
            case ( TypeRep a -> TypeRep bv2 -> Maybe (a :~~: bv2)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw' TypeRep bv2
tbv2,
                   TypeRep n -> TypeRep b -> Maybe (n :~~: b)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep n
tn TypeRep b
tn'
                 ) of
              (Just a :~~: bv2
HRefl, Just n :~~: b
HRefl) ->
                Term b -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (bv n) -> Term b
forall a b.
(PEvalBitCastTerm a b, SupportedPrim b) =>
Term a -> Term b
bitCastTerm Term (bv n)
t1 :: Term b)
              (Maybe (a :~~: bv2), Maybe (n :~~: b))
_ -> SomeTerm
forall r. r
err
          ( App
              (App (TypeRep a
tw' :: TypeRep f) (TypeRep b
teb :: TypeRep eb))
              (TypeRep b
tsb :: TypeRep sb)
            ) ->
              forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @b (((PrimConstraint b, SMTDefinable (SBVType b),
   Mergeable (SBVType b), Typeable (SBVType b)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint b, SMTDefinable (SBVType b),
     Mergeable (SBVType b), Typeable (SBVType b)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
                case (TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw' (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP)) of
                  Just a :~~: FP
HRefl ->
                    if TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
teb Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
tsb Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
== TypeRep n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep n
tn
                      then case forall (a :: Natural) (b :: Natural). a :~: b
forall {k} (a :: k) (b :: k). a :~: b
unsafeAxiom @n @(eb + sb) of
                        n :~: (b + b)
Refl -> Term b -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (bv n) -> Term b
forall a b.
(PEvalBitCastTerm a b, SupportedPrim b) =>
Term a -> Term b
bitCastTerm Term (bv n)
t1 :: Term b)
                      else SomeTerm
forall r. r
err
                  Maybe (a :~~: FP)
_ -> SomeTerm
forall r. r
err
          TypeRep b
_ -> SomeTerm
forall r. r
err

constructBVConcatTerm :: (HasCallStack) => SomeTerm -> SomeTerm -> SomeTerm
constructBVConcatTerm :: HasCallStack => SomeTerm -> SomeTerm -> SomeTerm
constructBVConcatTerm (SomeTerm (Term a
ta :: Term a)) (SomeTerm (Term a
tb :: Term b)) =
  forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
    forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @b (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
      case (TypeRep a
tra, TypeRep a
trb) of
        ( App (trbv0 :: TypeRep a
trbv0@(Con TyCon
_) :: TypeRep bv0) (TypeRep b
trn0 :: TypeRep n0),
          App (trbv1 :: TypeRep a
trbv1@(Con TyCon
_) :: TypeRep bv1) (TypeRep b
trn1 :: TypeRep n1)
          ) ->
            case ( TypeRep a -> TypeRep a -> Maybe (a :~~: a)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv0 TypeRep a
trbv1,
                   TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv0 (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
                   TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv0 (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
                 ) of
              (Just a :~~: a
HRefl, Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) ->
                case ( forall (m :: Natural) (n :: Natural). LeqProof m n
unsafeLeqProof @1 @(n0 + n1),
                       forall (n :: Natural). Natural -> KnownProof n
unsafeKnownProof @(n0 + n1) (TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn0 Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn1)
                     ) of
                  (LeqProof 1 (b + b)
LeqProof, KnownProof (b + b)
KnownProof) -> Term (WordN (b + b)) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (WordN (b + b)) -> SomeTerm)
-> Term (WordN (b + b)) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term (WordN b) -> Term (WordN b) -> Term (WordN (b + b))
forall (bv :: Natural -> *) (l :: Natural) (r :: Natural).
(PEvalBVTerm bv, KnownNat l, KnownNat r, KnownNat (l + r), 1 <= l,
 1 <= r, 1 <= (l + r), SupportedPrim (bv (l + r))) =>
Term (bv l) -> Term (bv r) -> Term (bv (l + r))
bvConcatTerm Term a
Term (WordN b)
ta Term a
Term (WordN b)
tb
              (Just a :~~: a
HRefl, Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) ->
                case ( forall (m :: Natural) (n :: Natural). LeqProof m n
unsafeLeqProof @1 @(n0 + n1),
                       forall (n :: Natural). Natural -> KnownProof n
unsafeKnownProof @(n0 + n1) (TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn0 Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn1)
                     ) of
                  (LeqProof 1 (b + b)
LeqProof, KnownProof (b + b)
KnownProof) -> Term (IntN (b + b)) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (IntN (b + b)) -> SomeTerm)
-> Term (IntN (b + b)) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term (IntN b) -> Term (IntN b) -> Term (IntN (b + b))
forall (bv :: Natural -> *) (l :: Natural) (r :: Natural).
(PEvalBVTerm bv, KnownNat l, KnownNat r, KnownNat (l + r), 1 <= l,
 1 <= r, 1 <= (l + r), SupportedPrim (bv (l + r))) =>
Term (bv l) -> Term (bv r) -> Term (bv (l + r))
bvConcatTerm Term a
Term (IntN b)
ta Term a
Term (IntN b)
tb
              (Maybe (a :~~: a), Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> SomeTerm
err
        (TypeRep a, TypeRep a)
_ -> SomeTerm
err
  where
    tra :: TypeRep a
tra = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    trb :: TypeRep a
trb = forall t. SupportedPrim t => TypeRep t
primTypeRep @b
    err :: SomeTerm
    err :: SomeTerm
err =
      [Char] -> SomeTerm
forall a. HasCallStack => [Char] -> a
error ([Char] -> SomeTerm) -> [Char] -> SomeTerm
forall a b. (a -> b) -> a -> b
$
        [Char]
"constructBVConcatTerm: unsupported type: "
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show (forall t. SupportedPrim t => TypeRep t
primTypeRep @a)

constructBVSelectTerm ::
  (HasCallStack) => Natural -> Natural -> SomeTerm -> SomeTerm
constructBVSelectTerm :: HasCallStack => Natural -> Natural -> SomeTerm -> SomeTerm
constructBVSelectTerm Natural
ix Natural
w (SomeTerm (Term a
ta :: Term a)) =
  forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
    case TypeRep a
tra of
      (App (trbv :: TypeRep a
trbv@(Con TyCon
_) :: TypeRep bv) (TypeRep b
trn :: TypeRep n)) ->
        case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
               TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
             ) of
          (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> case (Natural -> SomeNatRepr
mkNatRepr Natural
ix, Natural -> SomePositiveNatRepr
mkPositiveNatRepr Natural
w) of
            ( SomeNatRepr (NatRepr n
nix :: NatRepr ix),
              SomePositiveNatRepr (NatRepr n
nw :: NatRepr w)
              ) ->
                if Natural
ix Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ Natural
w Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
<= TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn
                  then case forall (m :: Natural) (n :: Natural). LeqProof m n
unsafeLeqProof @(ix + w) @n of
                    LeqProof (n + n) b
LeqProof -> Term (WordN n) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (WordN n) -> SomeTerm) -> Term (WordN n) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ NatRepr n -> NatRepr n -> Term (WordN b) -> Term (WordN n)
forall (bv :: Natural -> *) (n :: Natural) (ix :: Natural)
       (w :: Natural) (p :: Natural -> *) (q :: Natural -> *).
(PEvalBVTerm bv, KnownNat n, KnownNat ix, KnownNat w, 1 <= n,
 1 <= w, (ix + w) <= n, SupportedPrim (bv w)) =>
p ix -> q w -> Term (bv n) -> Term (bv w)
bvSelectTerm NatRepr n
nix NatRepr n
nw Term a
Term (WordN b)
ta
                  else SomeTerm
err
          (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> case (Natural -> SomeNatRepr
mkNatRepr Natural
ix, Natural -> SomePositiveNatRepr
mkPositiveNatRepr Natural
w) of
            ( SomeNatRepr (NatRepr n
nix :: NatRepr ix),
              SomePositiveNatRepr (NatRepr n
nw :: NatRepr w)
              ) ->
                if Natural
ix Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ Natural
w Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
<= TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn
                  then case forall (m :: Natural) (n :: Natural). LeqProof m n
unsafeLeqProof @(ix + w) @n of
                    LeqProof (n + n) b
LeqProof -> Term (IntN n) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (IntN n) -> SomeTerm) -> Term (IntN n) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ NatRepr n -> NatRepr n -> Term (IntN b) -> Term (IntN n)
forall (bv :: Natural -> *) (n :: Natural) (ix :: Natural)
       (w :: Natural) (p :: Natural -> *) (q :: Natural -> *).
(PEvalBVTerm bv, KnownNat n, KnownNat ix, KnownNat w, 1 <= n,
 1 <= w, (ix + w) <= n, SupportedPrim (bv w)) =>
p ix -> q w -> Term (bv n) -> Term (bv w)
bvSelectTerm NatRepr n
nix NatRepr n
nw Term a
Term (IntN b)
ta
                  else SomeTerm
err
          (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> SomeTerm
err
      TypeRep a
_ -> SomeTerm
err
  where
    tra :: TypeRep a
tra = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: SomeTerm
    err :: SomeTerm
err =
      [Char] -> SomeTerm
forall a. HasCallStack => [Char] -> a
error ([Char] -> SomeTerm) -> [Char] -> SomeTerm
forall a b. (a -> b) -> a -> b
$
        [Char]
"constructBVSelectTerm: unsupported type: "
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show (forall t. SupportedPrim t => TypeRep t
primTypeRep @a)

constructBVExtendTerm ::
  (HasCallStack) => Bool -> Natural -> SomeTerm -> SomeTerm
constructBVExtendTerm :: HasCallStack => Bool -> Natural -> SomeTerm -> SomeTerm
constructBVExtendTerm Bool
signed Natural
r (SomeTerm (Term a
ta :: Term a)) =
  forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
    case TypeRep a
tra of
      (App (trbv :: TypeRep a
trbv@(Con TyCon
_) :: TypeRep bv) (TypeRep b
trn :: TypeRep n)) ->
        case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
               TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
             ) of
          (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> case (Natural -> SomePositiveNatRepr
mkPositiveNatRepr Natural
r) of
            (SomePositiveNatRepr (NatRepr n
nr :: NatRepr r)) ->
              if TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
<= Natural
r
                then case forall (m :: Natural) (n :: Natural). LeqProof m n
unsafeLeqProof @n @r of
                  LeqProof b n
LeqProof -> Term (WordN n) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (WordN n) -> SomeTerm) -> Term (WordN n) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Bool -> NatRepr n -> Term (WordN b) -> Term (WordN n)
forall (bv :: Natural -> *) (l :: Natural) (r :: Natural)
       (proxy :: Natural -> *).
(PEvalBVTerm bv, KnownNat l, KnownNat r, 1 <= l, 1 <= r, l <= r,
 SupportedPrim (bv r)) =>
Bool -> proxy r -> Term (bv l) -> Term (bv r)
bvExtendTerm Bool
signed NatRepr n
nr Term a
Term (WordN b)
ta
                else SomeTerm
err
          (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> case (Natural -> SomePositiveNatRepr
mkPositiveNatRepr Natural
r) of
            (SomePositiveNatRepr (NatRepr n
nr :: NatRepr r)) ->
              if TypeRep b -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal TypeRep b
TypeRep b
trn Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
<= Natural
r
                then case forall (m :: Natural) (n :: Natural). LeqProof m n
unsafeLeqProof @n @r of
                  LeqProof b n
LeqProof -> Term (IntN n) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (IntN n) -> SomeTerm) -> Term (IntN n) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Bool -> NatRepr n -> Term (IntN b) -> Term (IntN n)
forall (bv :: Natural -> *) (l :: Natural) (r :: Natural)
       (proxy :: Natural -> *).
(PEvalBVTerm bv, KnownNat l, KnownNat r, 1 <= l, 1 <= r, l <= r,
 SupportedPrim (bv r)) =>
Bool -> proxy r -> Term (bv l) -> Term (bv r)
bvExtendTerm Bool
signed NatRepr n
nr Term a
Term (IntN b)
ta
                else SomeTerm
err
          (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> SomeTerm
err
      TypeRep a
_ -> SomeTerm
err
  where
    tra :: TypeRep a
tra = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: SomeTerm
    err :: SomeTerm
err =
      [Char] -> SomeTerm
forall a. HasCallStack => [Char] -> a
error ([Char] -> SomeTerm) -> [Char] -> SomeTerm
forall a b. (a -> b) -> a -> b
$
        [Char]
"constructBVExtendTerm: unsupported type: "
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show (forall t. SupportedPrim t => TypeRep t
primTypeRep @a)

constructApplyTerm ::
  (HasCallStack) => SomeTerm -> SomeTerm -> SomeTerm
constructApplyTerm :: HasCallStack => SomeTerm -> SomeTerm -> SomeTerm
constructApplyTerm (SomeTerm (Term a
tf :: Term f)) (SomeTerm (Term a
ta :: Term a)) =
  forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @f (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
    forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
      case TypeRep a
trf of
        (App (App (TypeRep a
trft :: TypeRep ft) (TypeRep b
trarg :: TypeRep arg)) TypeRep b
_) ->
          case ( TypeRep a -> TypeRep (=->) -> Maybe (a :~~: (=->))
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trft (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: * -> * -> *). Typeable a => TypeRep a
typeRep @(=->)),
                 TypeRep a -> TypeRep (-->) -> Maybe (a :~~: (-->))
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trft (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: * -> * -> *). Typeable a => TypeRep a
typeRep @(-->))
               ) of
            (Just a :~~: (=->)
HRefl, Maybe (a :~~: (-->))
_) -> case TypeRep b -> TypeRep a -> Maybe (b :~~: a)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep b
trarg TypeRep a
tra of
              Just b :~~: a
HRefl -> Term b -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term b -> SomeTerm) -> Term b -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> Term b
forall f a b.
(PEvalApplyTerm f a b, SupportedPrim b) =>
Term f -> Term a -> Term b
applyTerm Term a
tf Term a
ta
              Maybe (b :~~: a)
Nothing -> SomeTerm
err
            (Maybe (a :~~: (=->))
_, Just a :~~: (-->)
HRefl) -> case TypeRep b -> TypeRep a -> Maybe (b :~~: a)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep b
trarg TypeRep a
tra of
              Just b :~~: a
HRefl -> Term b -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term b -> SomeTerm) -> Term b -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> Term b
forall f a b.
(PEvalApplyTerm f a b, SupportedPrim b) =>
Term f -> Term a -> Term b
applyTerm Term a
tf Term a
ta
              Maybe (b :~~: a)
Nothing -> SomeTerm
err
            (Maybe (a :~~: (=->)), Maybe (a :~~: (-->)))
_ -> SomeTerm
err
        TypeRep a
_ -> SomeTerm
err
  where
    trf :: TypeRep a
trf = forall t. SupportedPrim t => TypeRep t
primTypeRep @f
    tra :: TypeRep a
tra = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: SomeTerm
    err :: SomeTerm
err =
      [Char] -> SomeTerm
forall a. HasCallStack => [Char] -> a
error ([Char] -> SomeTerm) -> [Char] -> SomeTerm
forall a b. (a -> b) -> a -> b
$
        [Char]
"constructApplyTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
trf [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
tra

constructFromIntegralTerm' ::
  forall a.
  ( HasCallStack,
    PEvalFromIntegralTerm a Integer,
    PEvalFromIntegralTerm a AlgReal,
    forall n. (KnownNat n, 1 <= n) => PEvalFromIntegralTerm a (WordN n),
    forall n. (KnownNat n, 1 <= n) => PEvalFromIntegralTerm a (IntN n),
    forall eb sb. (ValidFP eb sb) => PEvalFromIntegralTerm a (FP eb sb)
  ) =>
  Term a ->
  KnownType ->
  SomeTerm
constructFromIntegralTerm' :: forall a.
(HasCallStack, PEvalFromIntegralTerm a Integer,
 PEvalFromIntegralTerm a AlgReal,
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalFromIntegralTerm a (WordN n),
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalFromIntegralTerm a (IntN n),
 forall (eb :: Natural) (sb :: Natural).
 ValidFP eb sb =>
 PEvalFromIntegralTerm a (FP eb sb)) =>
Term a -> KnownType -> SomeTerm
constructFromIntegralTerm' ta :: Term a
ta@Term a
SupportedTerm KnownType
retType =
  case KnownType -> KnownTypeWitness
witnessKnownType KnownType
retType of
    KnownTypeWitness (Proxy a
_ :: Proxy b) -> do
      let tb :: TypeRep a
tb = forall t. SupportedPrim t => TypeRep t
primTypeRep @b
      forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
        forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @b (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
          case ( TypeRep a -> TypeRep Integer -> Maybe (a :~~: Integer)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tb (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @Integer),
                 TypeRep a -> TypeRep AlgReal -> Maybe (a :~~: AlgReal)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tb (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @AlgReal),
                 TypeRep a
tb
               ) of
            (Just a :~~: Integer
HRefl, Maybe (a :~~: AlgReal)
_, TypeRep a
_) -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a
forall a b.
(PEvalFromIntegralTerm a b, SupportedPrim b) =>
Term a -> Term b
fromIntegralTerm Term a
ta :: Term b)
            (Maybe (a :~~: Integer)
_, Just a :~~: AlgReal
HRefl, TypeRep a
_) -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a
forall a b.
(PEvalFromIntegralTerm a b, SupportedPrim b) =>
Term a -> Term b
fromIntegralTerm Term a
ta :: Term b)
            (Maybe (a :~~: Integer)
_, Maybe (a :~~: AlgReal)
_, App tw :: TypeRep a
tw@Con {} TypeRep b
_) ->
              case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
                     TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
                   ) of
                (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a
forall a b.
(PEvalFromIntegralTerm a b, SupportedPrim b) =>
Term a -> Term b
fromIntegralTerm Term a
ta :: Term b)
                (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a
forall a b.
(PEvalFromIntegralTerm a b, SupportedPrim b) =>
Term a -> Term b
fromIntegralTerm Term a
ta :: Term b)
                (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> SomeTerm
err
            (Maybe (a :~~: Integer)
_, Maybe (a :~~: AlgReal)
_, App (App tw :: TypeRep a
tw@Con {} TypeRep b
_) TypeRep b
_) ->
              case TypeRep a -> TypeRep FP -> Maybe (a :~~: FP)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tw (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> Natural -> *). Typeable a => TypeRep a
typeRep @FP) of
                Just a :~~: FP
HRefl -> Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> Term a
forall a b.
(PEvalFromIntegralTerm a b, SupportedPrim b) =>
Term a -> Term b
fromIntegralTerm Term a
ta :: Term b)
                Maybe (a :~~: FP)
_ -> SomeTerm
err
            (Maybe (a :~~: Integer), Maybe (a :~~: AlgReal), TypeRep a)
_ -> SomeTerm
err
  where
    err :: SomeTerm
    err :: SomeTerm
err =
      [Char] -> SomeTerm
forall a. HasCallStack => [Char] -> a
error ([Char] -> SomeTerm) -> [Char] -> SomeTerm
forall a b. (a -> b) -> a -> b
$
        [Char]
"constructFromIntegralTerm: unsupported type: "
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show (forall t. SupportedPrim t => TypeRep t
primTypeRep @a)
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> KnownType -> [Char]
forall a. Show a => a -> [Char]
show KnownType
retType

constructFromIntegralTerm ::
  (HasCallStack) => SomeTerm -> KnownType -> SomeTerm
constructFromIntegralTerm :: HasCallStack => SomeTerm -> KnownType -> SomeTerm
constructFromIntegralTerm (SomeTerm (Term a
t1 :: Term a)) KnownType
retType =
  forall t a.
SupportedPrim t =>
((PrimConstraint t, SMTDefinable (SBVType t),
  Mergeable (SBVType t), Typeable (SBVType t)) =>
 a)
-> a
withPrim @a (((PrimConstraint a, SMTDefinable (SBVType a),
   Mergeable (SBVType a), Typeable (SBVType a)) =>
  SomeTerm)
 -> SomeTerm)
-> ((PrimConstraint a, SMTDefinable (SBVType a),
     Mergeable (SBVType a), Typeable (SBVType a)) =>
    SomeTerm)
-> SomeTerm
forall a b. (a -> b) -> a -> b
$
    case (TypeRep a -> TypeRep Integer -> Maybe (a :~~: Integer)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
tra (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @Integer), TypeRep a
tra) of
      (Just a :~~: Integer
HRefl, TypeRep a
_) -> Term a -> KnownType -> SomeTerm
forall a.
(HasCallStack, PEvalFromIntegralTerm a Integer,
 PEvalFromIntegralTerm a AlgReal,
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalFromIntegralTerm a (WordN n),
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalFromIntegralTerm a (IntN n),
 forall (eb :: Natural) (sb :: Natural).
 ValidFP eb sb =>
 PEvalFromIntegralTerm a (FP eb sb)) =>
Term a -> KnownType -> SomeTerm
constructFromIntegralTerm' Term a
t1 KnownType
retType
      (Maybe (a :~~: Integer)
_, App (TypeRep a
trbv :: TypeRep bv) TypeRep b
_) ->
        case ( TypeRep a -> TypeRep WordN -> Maybe (a :~~: WordN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @WordN),
               TypeRep a -> TypeRep IntN -> Maybe (a :~~: IntN)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep TypeRep a
trbv (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Natural -> *). Typeable a => TypeRep a
typeRep @IntN)
             ) of
          (Just a :~~: WordN
HRefl, Maybe (a :~~: IntN)
_) -> Term a -> KnownType -> SomeTerm
forall a.
(HasCallStack, PEvalFromIntegralTerm a Integer,
 PEvalFromIntegralTerm a AlgReal,
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalFromIntegralTerm a (WordN n),
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalFromIntegralTerm a (IntN n),
 forall (eb :: Natural) (sb :: Natural).
 ValidFP eb sb =>
 PEvalFromIntegralTerm a (FP eb sb)) =>
Term a -> KnownType -> SomeTerm
constructFromIntegralTerm' Term a
t1 KnownType
retType
          (Maybe (a :~~: WordN)
_, Just a :~~: IntN
HRefl) -> Term a -> KnownType -> SomeTerm
forall a.
(HasCallStack, PEvalFromIntegralTerm a Integer,
 PEvalFromIntegralTerm a AlgReal,
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalFromIntegralTerm a (WordN n),
 forall (n :: Natural).
 (KnownNat n, 1 <= n) =>
 PEvalFromIntegralTerm a (IntN n),
 forall (eb :: Natural) (sb :: Natural).
 ValidFP eb sb =>
 PEvalFromIntegralTerm a (FP eb sb)) =>
Term a -> KnownType -> SomeTerm
constructFromIntegralTerm' Term a
t1 KnownType
retType
          (Maybe (a :~~: WordN), Maybe (a :~~: IntN))
_ -> SomeTerm
err
      (Maybe (a :~~: Integer), TypeRep a)
_ -> SomeTerm
err
  where
    tra :: TypeRep a
tra = forall t. SupportedPrim t => TypeRep t
primTypeRep @a
    err :: SomeTerm
    err :: SomeTerm
err = [Char] -> SomeTerm
forall a. HasCallStack => [Char] -> a
error ([Char] -> SomeTerm) -> [Char] -> SomeTerm
forall a b. (a -> b) -> a -> b
$ [Char]
"constructFromIntegralTerm: unsupported type: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> TypeRep a -> [Char]
forall a. Show a => a -> [Char]
show TypeRep a
tra

knownTypeTermId :: Term a -> (KnownType, Id)
knownTypeTermId :: forall a. Term a -> (KnownType, Id)
knownTypeTermId t :: Term a
t@Term a
SupportedTerm = (Term a -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType Term a
t, Term a -> Id
forall t. Term t -> Id
termId Term a
t)

statefulDeserializeSomeTerm ::
  (MonadGet m) =>
  StateT (HM.HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
statefulDeserializeSomeTerm :: forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
statefulDeserializeSomeTerm = do
  r <- do
    ktTmId <- StateT
  (HashMap (KnownType, Id) SomeTerm, SomeTerm) m (KnownType, Id)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (KnownType, Id)
deserialize
    tag <- getWord8
    if
      | tag == conTermTag -> do
          knownType <- deserializeKnownType
          case witnessKnownType knownType of
            KnownTypeWitness (Proxy a
Proxy :: Proxy a) -> do
              tm <- Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> SomeTerm) -> (a -> Term a) -> a -> SomeTerm
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Term a
forall t. SupportedPrim t => t -> Term t
conTerm (a -> SomeTerm)
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a (m :: * -> *). (Serial a, MonadGet m) => m a
deserialize @a
              return $ Just (tm, ktTmId)
      | tag == symTermTag -> do
          SomeTypedSymbol sb <- deserialize @SomeTypedAnySymbol
          return $ Just (someTerm $ symTerm sb, ktTmId)
      | tag == forallTermTag -> deserializeQuantified ktTmId forallTerm
      | tag == existsTermTag -> deserializeQuantified ktTmId existsTerm
      | tag == notTermTag -> do
          t <- deserializeTerm
          return $ Just (someTerm $ notTerm $ asBoolTerm t, ktTmId)
      | tag == orTermTag -> deserializeBoolBinary ktTmId orTerm
      | tag == andTermTag -> deserializeBoolBinary ktTmId andTerm
      | tag == eqTermTag -> do
          SomeTerm t1' <- deserializeTerm
          t2 <- deserializeTerm
          asSameType t1' t2 $ \Term a
t2' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term Bool -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term Bool -> SomeTerm) -> Term Bool -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> Term Bool
forall a. Term a -> Term a -> Term Bool
eqTerm Term a
t1' Term a
t2', (KnownType, Id)
ktTmId)
      | tag == distinctTermTag -> do
          ts <- deserializeNonEmptyTermList
          asSameTypeNonEmptyTermList ts $ \NonEmpty (Term b)
ts' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term Bool -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term Bool -> SomeTerm) -> Term Bool -> SomeTerm
forall a b. (a -> b) -> a -> b
$ NonEmpty (Term b) -> Term Bool
forall a. NonEmpty (Term a) -> Term Bool
distinctTerm NonEmpty (Term b)
ts', (KnownType, Id)
ktTmId)
      | tag == iteTermTag -> do
          t1 <- deserializeTerm
          SomeTerm t2' <- deserializeTerm
          t3 <- deserializeTerm
          asSameType t2' t3 $ \Term a
t3' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term a -> SomeTerm) -> Term a -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term Bool -> Term a -> Term a -> Term a
forall a. Term Bool -> Term a -> Term a -> Term a
iteTerm (HasCallStack => SomeTerm -> Term Bool
SomeTerm -> Term Bool
asBoolTerm SomeTerm
t1) Term a
t2' Term a
t3', (KnownType, Id)
ktTmId)
      | tag == addNumTermTag -> deserializeNumBinary ktTmId addNumTerm
      | tag == negNumTermTag -> deserializeNumUnary ktTmId negNumTerm
      | tag == mulNumTermTag -> deserializeNumBinary ktTmId mulNumTerm
      | tag == absNumTermTag -> deserializeNumUnary ktTmId absNumTerm
      | tag == signumNumTermTag -> deserializeNumUnary ktTmId signumNumTerm
      | tag == ltOrdTermTag -> deserializeOrdBinary ktTmId ltOrdTerm
      | tag == leOrdTermTag -> deserializeOrdBinary ktTmId leOrdTerm
      | tag == andBitsTermTag -> deserializeBitsBinary ktTmId andBitsTerm
      | tag == orBitsTermTag -> deserializeBitsBinary ktTmId orBitsTerm
      | tag == xorBitsTermTag -> deserializeBitsBinary ktTmId xorBitsTerm
      | tag == complementBitsTermTag ->
          deserializeBitsUnary ktTmId complementBitsTerm
      | tag == shiftLeftTermTag -> deserializeBitsBinary ktTmId shiftLeftTerm
      | tag == shiftRightTermTag -> deserializeBitsBinary ktTmId shiftRightTerm
      | tag == rotateLeftTermTag -> deserializeBitsBinary ktTmId rotateLeftTerm
      | tag == rotateRightTermTag -> deserializeBitsBinary ktTmId rotateRightTerm
      | tag == bitCastTermTag -> do
          kt <- deserializeKnownType
          t1 <- deserializeTerm
          return $ Just (constructBitCastTerm t1 kt, ktTmId)
      | tag == bitCastOrTermTag -> do
          td <- deserializeTerm
          tv <- deserializeTerm
          return $ Just (constructBitCastOrTerm td tv, ktTmId)
      | tag == bvConcatTermTag -> do
          t1 <- deserializeTerm
          t2 <- deserializeTerm
          return $ Just (constructBVConcatTerm t1 t2, ktTmId)
      | tag == bvSelectTermTag -> do
          ix <- deserialize @Natural
          w <- deserialize @Natural
          t1 <- deserializeTerm
          return $ Just (constructBVSelectTerm ix w t1, ktTmId)
      | tag == bvExtendTermTag -> do
          signed <- deserialize @Bool
          r <- deserialize @Natural
          t1 <- deserializeTerm
          return $ Just (constructBVExtendTerm signed r t1, ktTmId)
      | tag == applyTermTag -> do
          tf <- deserializeTerm
          ta <- deserializeTerm
          return $ Just (constructApplyTerm tf ta, ktTmId)
      | tag == divIntegralTermTag ->
          deserializeIntegralBinary ktTmId divIntegralTerm
      | tag == modIntegralTermTag ->
          deserializeIntegralBinary ktTmId modIntegralTerm
      | tag == quotIntegralTermTag ->
          deserializeIntegralBinary ktTmId quotIntegralTerm
      | tag == remIntegralTermTag ->
          deserializeIntegralBinary ktTmId remIntegralTerm
      | tag == terminalTag -> return Nothing
      | tag == fpTraitTermTag -> do
          trait <- deserialize @FPTrait
          t <- deserializeTerm
          asFPTypeTerm t $ \Term (FP eb sb)
t' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term Bool -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term Bool -> SomeTerm) -> Term Bool -> SomeTerm
forall a b. (a -> b) -> a -> b
$ FPTrait -> Term (FP eb sb) -> Term Bool
forall (eb :: Natural) (sb :: Natural)
       (fp :: Natural -> Natural -> *).
(ValidFP eb sb, SupportedPrim (fp eb sb), PEvalFPTerm fp) =>
FPTrait -> Term (fp eb sb) -> Term Bool
fpTraitTerm FPTrait
trait Term (FP eb sb)
t', (KnownType, Id)
ktTmId)
      | tag == fdivTermTag -> do
          t1 <- deserializeTerm
          t2 <- deserializeTerm
          asFloatingFractionalTypeTerm t1 $ \Term n
t1' -> Term n
-> SomeTerm
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term n
t1' SomeTerm
t2 ((Term n
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term n
t2' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n -> Term n
forall a. PEvalFractionalTerm a => Term a -> Term a -> Term a
fdivTerm Term n
t1' Term n
t2', (KnownType, Id)
ktTmId)
      | tag == recipTermTag -> do
          t <- deserializeTerm
          asFloatingFractionalTypeTerm t $ \Term n
t' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n
forall a. PEvalFractionalTerm a => Term a -> Term a
recipTerm Term n
t', (KnownType, Id)
ktTmId)
      | tag == floatingUnaryTermTag -> do
          op <- deserialize
          t <- deserializeTerm
          asFloatingFractionalTypeTerm t $ \Term n
t' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ FloatingUnaryOp -> Term n -> Term n
forall a.
PEvalFloatingTerm a =>
FloatingUnaryOp -> Term a -> Term a
floatingUnaryTerm FloatingUnaryOp
op Term n
t', (KnownType, Id)
ktTmId)
      | tag == powerTermTag -> do
          t1 <- deserializeTerm
          t2 <- deserializeTerm
          asFloatingFractionalTypeTerm t1 $ \Term n
t1' -> Term n
-> SomeTerm
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term n
t1' SomeTerm
t2 ((Term n
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term n
t2' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n -> Term n
forall a. PEvalFloatingTerm a => Term a -> Term a -> Term a
powerTerm Term n
t1' Term n
t2', (KnownType, Id)
ktTmId)
      | tag == fpUnaryTermTag -> do
          op <- deserialize @FPUnaryOp
          t <- deserializeTerm
          asFPTypeTerm t $ \Term (FP eb sb)
t' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term (FP eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (FP eb sb) -> SomeTerm) -> Term (FP eb sb) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ FPUnaryOp -> Term (FP eb sb) -> Term (FP eb sb)
forall (eb :: Natural) (sb :: Natural)
       (fp :: Natural -> Natural -> *).
(ValidFP eb sb, SupportedPrim (fp eb sb), PEvalFPTerm fp) =>
FPUnaryOp -> Term (fp eb sb) -> Term (fp eb sb)
fpUnaryTerm FPUnaryOp
op Term (FP eb sb)
t', (KnownType, Id)
ktTmId)
      | tag == fpBinaryTermTag -> do
          op <- deserialize @FPBinaryOp
          t1 <- deserializeTerm
          t2 <- deserializeTerm
          asFPTypeTerm t1 $ \Term (FP eb sb)
t1' -> Term (FP eb sb)
-> SomeTerm
-> (Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term (FP eb sb)
t1' SomeTerm
t2 ((Term (FP eb sb)
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term (FP eb sb)
t2' ->
            Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term (FP eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (FP eb sb) -> SomeTerm) -> Term (FP eb sb) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ FPBinaryOp -> Term (FP eb sb) -> Term (FP eb sb) -> Term (FP eb sb)
forall (eb :: Natural) (sb :: Natural)
       (fp :: Natural -> Natural -> *).
(ValidFP eb sb, SupportedPrim (fp eb sb), PEvalFPTerm fp) =>
FPBinaryOp -> Term (fp eb sb) -> Term (fp eb sb) -> Term (fp eb sb)
fpBinaryTerm FPBinaryOp
op Term (FP eb sb)
t1' Term (FP eb sb)
t2', (KnownType, Id)
ktTmId)
      | tag == fpRoundingUnaryTermTag -> do
          op <- deserialize @FPRoundingUnaryOp
          trd <- deserializeTerm
          t <- deserializeTerm
          asFPRoundingTerm trd $ \Term FPRoundingMode
trd' ->
            SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall r.
HasCallStack =>
SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb) -> r)
-> r
asFPTypeTerm SomeTerm
t ((forall (eb :: Natural) (sb :: Natural).
  ValidFP eb sb =>
  Term (FP eb sb)
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term (FP eb sb)
t' ->
              Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term (FP eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (FP eb sb) -> SomeTerm) -> Term (FP eb sb) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ FPRoundingUnaryOp
-> Term FPRoundingMode -> Term (FP eb sb) -> Term (FP eb sb)
forall (eb :: Natural) (sb :: Natural)
       (fp :: Natural -> Natural -> *).
(ValidFP eb sb, SupportedPrim (fp eb sb), PEvalFPTerm fp) =>
FPRoundingUnaryOp
-> Term FPRoundingMode -> Term (fp eb sb) -> Term (fp eb sb)
fpRoundingUnaryTerm FPRoundingUnaryOp
op Term FPRoundingMode
trd' Term (FP eb sb)
t', (KnownType, Id)
ktTmId)
      | tag == fpRoundingBinaryTermTag -> do
          op <- deserialize @FPRoundingBinaryOp
          trd <- deserializeTerm
          t1 <- deserializeTerm
          t2 <- deserializeTerm
          asFPRoundingTerm trd $ \Term FPRoundingMode
trd' ->
            SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall r.
HasCallStack =>
SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb) -> r)
-> r
asFPTypeTerm SomeTerm
t1 ((forall (eb :: Natural) (sb :: Natural).
  ValidFP eb sb =>
  Term (FP eb sb)
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term (FP eb sb)
t1' -> Term (FP eb sb)
-> SomeTerm
-> (Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term (FP eb sb)
t1' SomeTerm
t2 ((Term (FP eb sb)
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term (FP eb sb)
t2' ->
              Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$
                (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term (FP eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (FP eb sb) -> SomeTerm) -> Term (FP eb sb) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ FPRoundingBinaryOp
-> Term FPRoundingMode
-> Term (FP eb sb)
-> Term (FP eb sb)
-> Term (FP eb sb)
forall (eb :: Natural) (sb :: Natural)
       (fp :: Natural -> Natural -> *).
(ValidFP eb sb, SupportedPrim (fp eb sb), PEvalFPTerm fp) =>
FPRoundingBinaryOp
-> Term FPRoundingMode
-> Term (fp eb sb)
-> Term (fp eb sb)
-> Term (fp eb sb)
fpRoundingBinaryTerm FPRoundingBinaryOp
op Term FPRoundingMode
trd' Term (FP eb sb)
t1' Term (FP eb sb)
t2', (KnownType, Id)
ktTmId)
      | tag == fpFMATermTag -> do
          trd <- deserializeTerm
          t1 <- deserializeTerm
          t2 <- deserializeTerm
          t3 <- deserializeTerm
          asFPRoundingTerm trd $ \Term FPRoundingMode
trd' -> SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall r.
HasCallStack =>
SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb) -> r)
-> r
asFPTypeTerm SomeTerm
t1 ((forall (eb :: Natural) (sb :: Natural).
  ValidFP eb sb =>
  Term (FP eb sb)
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term (FP eb sb)
t1' ->
            Term (FP eb sb)
-> SomeTerm
-> (Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term (FP eb sb)
t1' SomeTerm
t2 ((Term (FP eb sb)
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term (FP eb sb)
t2' -> Term (FP eb sb)
-> SomeTerm
-> (Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term (FP eb sb)
t1' SomeTerm
t3 ((Term (FP eb sb)
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term (FP eb sb)
t3' ->
              Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term (FP eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term (FP eb sb) -> SomeTerm) -> Term (FP eb sb) -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode
-> Term (FP eb sb)
-> Term (FP eb sb)
-> Term (FP eb sb)
-> Term (FP eb sb)
forall (eb :: Natural) (sb :: Natural)
       (fp :: Natural -> Natural -> *).
(ValidFP eb sb, SupportedPrim (fp eb sb), PEvalFPTerm fp) =>
Term FPRoundingMode
-> Term (fp eb sb)
-> Term (fp eb sb)
-> Term (fp eb sb)
-> Term (fp eb sb)
fpFMATerm Term FPRoundingMode
trd' Term (FP eb sb)
t1' Term (FP eb sb)
t2' Term (FP eb sb)
t3', (KnownType, Id)
ktTmId)
      | tag == fromIntegralTermTag -> do
          kt <- deserializeKnownType
          t <- deserializeTerm
          return $ Just (constructFromIntegralTerm t kt, ktTmId)
      | tag == fromFPOrTermTag -> do
          td <- deserializeTerm
          trd <- deserializeTerm
          tt <- deserializeTerm
          asNumTypeTerm td $ \Term n
td' -> SomeTerm
-> (Term FPRoundingMode
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall r.
HasCallStack =>
SomeTerm -> (Term FPRoundingMode -> r) -> r
asFPRoundingTerm SomeTerm
trd ((Term FPRoundingMode
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (Term FPRoundingMode
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term FPRoundingMode
trd' ->
            SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall r.
HasCallStack =>
SomeTerm
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb) -> r)
-> r
asFPTypeTerm SomeTerm
tt ((forall (eb :: Natural) (sb :: Natural).
  ValidFP eb sb =>
  Term (FP eb sb)
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (forall (eb :: Natural) (sb :: Natural).
    ValidFP eb sb =>
    Term (FP eb sb)
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term (FP eb sb)
tt' ->
              Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term FPRoundingMode -> Term (FP eb sb) -> Term n
forall a (eb :: Natural) (sb :: Natural).
(PEvalIEEEFPConvertibleTerm a, ValidFP eb sb) =>
Term a -> Term FPRoundingMode -> Term (FP eb sb) -> Term a
fromFPOrTerm Term n
td' Term FPRoundingMode
trd' Term (FP eb sb)
tt', (KnownType, Id)
ktTmId)
      | tag == toFPTermTag -> do
          eb <- deserialize @Natural
          sb <- deserialize @Natural
          trd <- deserializeTerm
          tt <- deserializeTerm
          if checkDynamicValidFP eb sb
            then case (mkNatRepr eb, mkNatRepr sb) of
              ( SomeNatRepr (NatRepr n
_ :: NatRepr eb),
                SomeNatRepr (NatRepr n
_ :: NatRepr sb)
                ) ->
                  forall (eb :: Natural) (sb :: Natural) r.
(KnownNat eb, KnownNat sb) =>
(ValidFP eb sb => r) -> r
withUnsafeValidFP @eb @sb ((ValidFP n n =>
  StateT
    (HashMap (KnownType, Id) SomeTerm, SomeTerm)
    m
    (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (ValidFP n n =>
    StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$
                    SomeTerm
-> (Term FPRoundingMode
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall r.
HasCallStack =>
SomeTerm -> (Term FPRoundingMode -> r) -> r
asFPRoundingTerm SomeTerm
trd ((Term FPRoundingMode
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (Term FPRoundingMode
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term FPRoundingMode
trd' -> SomeTerm
-> (forall n.
    (PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
    Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall r.
HasCallStack =>
SomeTerm
-> (forall n.
    (PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
    Term n -> r)
-> r
asNumTypeTerm SomeTerm
tt ((forall n.
  (PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
  Term n
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, (KnownType, Id))))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> (forall n.
    (PEvalNumTerm n, PEvalIEEEFPConvertibleTerm n) =>
    Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, (KnownType, Id))))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$ \Term n
tt' ->
                      Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, (KnownType, Id))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, (KnownType, Id))))
-> Maybe (SomeTerm, (KnownType, Id))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, (KnownType, Id)))
forall a b. (a -> b) -> a -> b
$
                        (SomeTerm, (KnownType, Id)) -> Maybe (SomeTerm, (KnownType, Id))
forall a. a -> Maybe a
Just
                          ( Term (FP n n) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term FPRoundingMode -> Term n -> Term (FP n n)
forall a (eb :: Natural) (sb :: Natural).
(PEvalIEEEFPConvertibleTerm a, ValidFP eb sb,
 SupportedPrim (FP eb sb)) =>
Term FPRoundingMode -> Term a -> Term (FP eb sb)
toFPTerm Term FPRoundingMode
trd' Term n
tt' :: Term (FP eb sb)),
                            (KnownType, Id)
ktTmId
                          )
            else error "statefulDeserializeSomeTerm: invalid FP type"
      | otherwise ->
          error $ "statefulDeserializeSomeTerm: unknown tag: " <> show tag
  case r of
    Just (SomeTerm
tm, (KnownType, Id)
ktTmId) -> do
      ((HashMap (KnownType, Id) SomeTerm, SomeTerm)
 -> (HashMap (KnownType, Id) SomeTerm, SomeTerm))
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
State.modify' (((HashMap (KnownType, Id) SomeTerm, SomeTerm)
  -> (HashMap (KnownType, Id) SomeTerm, SomeTerm))
 -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m ())
-> ((HashMap (KnownType, Id) SomeTerm, SomeTerm)
    -> (HashMap (KnownType, Id) SomeTerm, SomeTerm))
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m ()
forall a b. (a -> b) -> a -> b
$ \(HashMap (KnownType, Id) SomeTerm
m, SomeTerm
_) -> ((KnownType, Id)
-> SomeTerm
-> HashMap (KnownType, Id) SomeTerm
-> HashMap (KnownType, Id) SomeTerm
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HM.insert (KnownType, Id)
ktTmId SomeTerm
tm HashMap (KnownType, Id) SomeTerm
m, SomeTerm
tm)
      StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
statefulDeserializeSomeTerm
    Maybe (SomeTerm, (KnownType, Id))
Nothing -> ((HashMap (KnownType, Id) SomeTerm, SomeTerm) -> SomeTerm)
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
State.gets (HashMap (KnownType, Id) SomeTerm, SomeTerm) -> SomeTerm
forall a b. (a, b) -> b
snd
  where
    deserializeNonEmptyTermList ::
      (MonadGet m) =>
      StateT
        (HM.HashMap (KnownType, Id) SomeTerm, SomeTerm)
        m
        (NonEmpty SomeTerm)
    deserializeNonEmptyTermList :: forall (m :: * -> *).
MonadGet m =>
StateT
  (HashMap (KnownType, Id) SomeTerm, SomeTerm) m (NonEmpty SomeTerm)
deserializeNonEmptyTermList = do
      ids <- forall a (m :: * -> *). (Serial a, MonadGet m) => m a
deserialize @[(KnownType, Id)]
      case ids of
        [] -> [Char]
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm) m (NonEmpty SomeTerm)
forall a.
[Char] -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"statefulDeserializeSomeTerm: empty list"
        ((KnownType, Id)
x : [(KnownType, Id)]
xs) -> do
          x' <- (KnownType, Id)
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
(KnownType, Id)
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
queryTerm (KnownType, Id)
x
          xs' <- traverse queryTerm xs
          return $ x' :| xs'
    deserializeTerm ::
      (MonadGet m) =>
      StateT (HM.HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
    deserializeTerm :: forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
deserializeTerm = do
      ktTmId <- StateT
  (HashMap (KnownType, Id) SomeTerm, SomeTerm) m (KnownType, Id)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (KnownType, Id)
deserialize
      queryTerm ktTmId
    queryTerm ::
      (MonadGet m) =>
      (KnownType, Id) ->
      StateT (HM.HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
    queryTerm :: forall (m :: * -> *).
MonadGet m =>
(KnownType, Id)
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
queryTerm (KnownType, Id)
ktTmId = do
      tm <- ((HashMap (KnownType, Id) SomeTerm, SomeTerm) -> Maybe SomeTerm)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm) m (Maybe SomeTerm)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
State.gets (((HashMap (KnownType, Id) SomeTerm, SomeTerm) -> Maybe SomeTerm)
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm) m (Maybe SomeTerm))
-> ((HashMap (KnownType, Id) SomeTerm, SomeTerm) -> Maybe SomeTerm)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm) m (Maybe SomeTerm)
forall a b. (a -> b) -> a -> b
$ (KnownType, Id)
-> HashMap (KnownType, Id) SomeTerm -> Maybe SomeTerm
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup (KnownType, Id)
ktTmId (HashMap (KnownType, Id) SomeTerm -> Maybe SomeTerm)
-> ((HashMap (KnownType, Id) SomeTerm, SomeTerm)
    -> HashMap (KnownType, Id) SomeTerm)
-> (HashMap (KnownType, Id) SomeTerm, SomeTerm)
-> Maybe SomeTerm
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (HashMap (KnownType, Id) SomeTerm, SomeTerm)
-> HashMap (KnownType, Id) SomeTerm
forall a b. (a, b) -> a
fst
      case tm of
        Maybe SomeTerm
Nothing -> [Char]
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall a.
[Char] -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"statefulDeserializeSomeTerm: unknown term id"
        Just SomeTerm
tm' -> SomeTerm
-> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return SomeTerm
tm'
    deserializeBoolBinary :: b
-> (Term Bool -> Term Bool -> Term a)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
deserializeBoolBinary b
tmId Term Bool -> Term Bool -> Term a
f = do
      t1 <- StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
deserializeTerm
      t2 <- deserializeTerm
      return $
        Just (someTerm $ f (asBoolTerm t1) (asBoolTerm t2), tmId)
    deserializeQuantified :: b
-> (forall t. TypedConstantSymbol t -> Term Bool -> Term Bool)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
deserializeQuantified
      b
tmId
      (forall t. TypedConstantSymbol t -> Term Bool -> Term Bool
f :: forall t. TypedConstantSymbol t -> Term Bool -> Term Bool) = do
        SomeTypedSymbol sb <- StateT
  (HashMap (KnownType, Id) SomeTerm, SomeTerm)
  m
  (SomeTypedSymbol 'ConstantKind)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (SomeTypedSymbol 'ConstantKind)
deserialize
        t <- deserializeTerm
        return $ Just (someTerm $ f sb $ asBoolTerm t, tmId)
    deserializeNumUnary :: b
-> (forall t. PEvalNumTerm t => Term t -> Term t)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
deserializeNumUnary
      b
tmId
      (forall t. PEvalNumTerm t => Term t -> Term t
f :: forall t. (PEvalNumTerm t) => Term t -> Term t) = do
        t1 <- StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
deserializeTerm
        asNumTypeTerm t1 $ \Term n
t1' -> Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, b)
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, b) -> Maybe (SomeTerm, b)
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n
forall t. PEvalNumTerm t => Term t -> Term t
f Term n
t1', b
tmId)
    deserializeBitsUnary :: b
-> (forall t. PEvalBitwiseTerm t => Term t -> Term t)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
deserializeBitsUnary
      b
tmId
      (forall t. PEvalBitwiseTerm t => Term t -> Term t
f :: forall t. (PEvalBitwiseTerm t) => Term t -> Term t) = do
        t1 <- StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
deserializeTerm
        asBitsTypeTerm t1 $ \Term n
t1' -> Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, b)
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, b) -> Maybe (SomeTerm, b)
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n
forall t. PEvalBitwiseTerm t => Term t -> Term t
f Term n
t1', b
tmId)
    deserializeNumBinary :: b
-> (forall t. PEvalNumTerm t => Term t -> Term t -> Term t)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
deserializeNumBinary
      b
tmId
      (forall t. PEvalNumTerm t => Term t -> Term t -> Term t
f :: forall t. (PEvalNumTerm t) => Term t -> Term t -> Term t) = do
        t1 <- StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
deserializeTerm
        t2 <- deserializeTerm
        asNumTypeTerm t1 $ \Term n
t1' -> Term n
-> SomeTerm
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, b)))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term n
t1' SomeTerm
t2 ((Term n
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, b)))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, b)))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ \Term n
t2' ->
          Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, b)
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, b) -> Maybe (SomeTerm, b)
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n -> Term n
forall t. PEvalNumTerm t => Term t -> Term t -> Term t
f Term n
t1' Term n
t2', b
tmId)
    deserializeOrdBinary :: b
-> (forall t. PEvalOrdTerm t => Term t -> Term t -> Term Bool)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
deserializeOrdBinary
      b
tmId
      (forall t. PEvalOrdTerm t => Term t -> Term t -> Term Bool
f :: forall t. (PEvalOrdTerm t) => Term t -> Term t -> Term Bool) = do
        t1 <- StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
deserializeTerm
        t2 <- deserializeTerm
        asOrdTypeTerm t1 $ \Term n
t1' -> Term n
-> SomeTerm
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, b)))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term n
t1' SomeTerm
t2 ((Term n
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, b)))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, b)))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ \Term n
t2' ->
          Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, b)
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, b) -> Maybe (SomeTerm, b)
forall a. a -> Maybe a
Just (Term Bool -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term Bool -> SomeTerm) -> Term Bool -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n -> Term Bool
forall t. PEvalOrdTerm t => Term t -> Term t -> Term Bool
f Term n
t1' Term n
t2', b
tmId)
    deserializeBitsBinary :: b
-> (forall t.
    (PEvalBitwiseTerm t, PEvalShiftTerm t, PEvalRotateTerm t) =>
    Term t -> Term t -> Term t)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
deserializeBitsBinary
      b
tmId
      ( forall t.
(PEvalBitwiseTerm t, PEvalShiftTerm t, PEvalRotateTerm t) =>
Term t -> Term t -> Term t
f ::
          forall t.
          ( PEvalBitwiseTerm t,
            PEvalShiftTerm t,
            PEvalRotateTerm t
          ) =>
          Term t ->
          Term t ->
          Term t
        ) = do
        t1 <- StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
deserializeTerm
        t2 <- deserializeTerm
        asBitsTypeTerm t1 $ \Term n
t1' -> Term n
-> SomeTerm
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, b)))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term n
t1' SomeTerm
t2 ((Term n
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, b)))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, b)))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ \Term n
t2' ->
          Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, b)
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, b) -> Maybe (SomeTerm, b)
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n -> Term n
forall t.
(PEvalBitwiseTerm t, PEvalShiftTerm t, PEvalRotateTerm t) =>
Term t -> Term t -> Term t
f Term n
t1' Term n
t2', b
tmId)
    deserializeIntegralBinary :: b
-> (forall t.
    PEvalDivModIntegralTerm t =>
    Term t -> Term t -> Term t)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
deserializeIntegralBinary
      b
tmId
      ( forall t. PEvalDivModIntegralTerm t => Term t -> Term t -> Term t
f ::
          forall t.
          (PEvalDivModIntegralTerm t) =>
          Term t ->
          Term t ->
          Term t
        ) = do
        t1 <- StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
deserializeTerm
        t2 <- deserializeTerm
        asIntegralTypeTerm t1 $ \Term n
t1' -> Term n
-> SomeTerm
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, b)))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a r.
HasCallStack =>
Term a -> SomeTerm -> (Term a -> r) -> r
asSameType Term n
t1' SomeTerm
t2 ((Term n
  -> StateT
       (HashMap (KnownType, Id) SomeTerm, SomeTerm)
       m
       (Maybe (SomeTerm, b)))
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> (Term n
    -> StateT
         (HashMap (KnownType, Id) SomeTerm, SomeTerm)
         m
         (Maybe (SomeTerm, b)))
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ \Term n
t2' ->
          Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a.
a -> StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SomeTerm, b)
 -> StateT
      (HashMap (KnownType, Id) SomeTerm, SomeTerm)
      m
      (Maybe (SomeTerm, b)))
-> Maybe (SomeTerm, b)
-> StateT
     (HashMap (KnownType, Id) SomeTerm, SomeTerm)
     m
     (Maybe (SomeTerm, b))
forall a b. (a -> b) -> a -> b
$ (SomeTerm, b) -> Maybe (SomeTerm, b)
forall a. a -> Maybe a
Just (Term n -> SomeTerm
forall a. Term a -> SomeTerm
someTerm (Term n -> SomeTerm) -> Term n -> SomeTerm
forall a b. (a -> b) -> a -> b
$ Term n -> Term n -> Term n
forall t. PEvalDivModIntegralTerm t => Term t -> Term t -> Term t
f Term n
t1' Term n
t2', b
tmId)

deserializeSomeTerm :: (MonadGet m) => m SomeTerm
deserializeSomeTerm :: forall (m :: * -> *). MonadGet m => m SomeTerm
deserializeSomeTerm =
  StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
-> (HashMap (KnownType, Id) SomeTerm, SomeTerm) -> m SomeTerm
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT
    StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
forall (m :: * -> *).
MonadGet m =>
StateT (HashMap (KnownType, Id) SomeTerm, SomeTerm) m SomeTerm
statefulDeserializeSomeTerm
    ( HashMap (KnownType, Id) SomeTerm
forall k v. HashMap k v
HM.empty,
      [Char] -> SomeTerm
forall a. HasCallStack => [Char] -> a
error ([Char] -> SomeTerm) -> [Char] -> SomeTerm
forall a b. (a -> b) -> a -> b
$
        [Char]
"deserializeSomeTerm: should not happen: started with the terminal "
          [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"value"
    )

serializeSingleSomeTerm ::
  (MonadPut m) => SomeTerm -> StateT (HS.HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm :: forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm (Term a
tm :: Term t)) = do
  st <- StateT (HashSet (KnownType, Id)) m (HashSet (KnownType, Id))
forall s (m :: * -> *). MonadState s m => m s
State.get
  let kt = Term a -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType Term a
tm
  let tmId = Term a -> Id
forall t. Term t -> Id
termId Term a
tm
  let ktTmId = (KnownType
kt, Id
tmId)
  if HS.member ktTmId st
    then return ()
    else do
      case tm of
        ConTerm (a
v :: v) -> do
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
conTermTag
          let kt :: KnownType
kt = Proxy a -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)
          case KnownType -> KnownTypeWitness
witnessKnownType KnownType
kt of
            KnownTypeWitness (Proxy a
Proxy :: Proxy v1) ->
              case TypeRep a -> TypeRep a -> Maybe (a :~~: a)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep (forall t. SupportedPrim t => TypeRep t
primTypeRep @v) (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @v1) of
                Just a :~~: a
HRefl -> do
                  KnownType -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *). MonadPut m => KnownType -> m ()
serializeKnownType KnownType
kt
                  a -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => a -> m ()
serialize a
v
                Maybe (a :~~: a)
Nothing ->
                  [Char] -> StateT (HashSet (KnownType, Id)) m ()
forall a. HasCallStack => [Char] -> a
error
                    [Char]
"serializeSingleSomeTerm: should not happen: type mismatch"
        SymTerm (TypedAnySymbol a
v :: TypedAnySymbol v) -> do
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
symTermTag
          SomeTypedAnySymbol -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => SomeTypedAnySymbol -> m ()
serialize (SomeTypedAnySymbol -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTypedAnySymbol -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ TypedAnySymbol a -> SomeTypedAnySymbol
forall (knd :: SymbolKind) t.
TypedSymbol knd t -> SomeTypedSymbol knd
someTypedSymbol TypedAnySymbol a
v
        ForallTerm TypedSymbol 'ConstantKind t
ts Term Bool
t -> (KnownType, Id)
-> Word8
-> TypedSymbol 'ConstantKind t
-> Term Bool
-> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *) v b.
MonadPut m =>
(KnownType, Id)
-> Word8
-> TypedConstantSymbol v
-> Term b
-> StateT (HashSet (KnownType, Id)) m ()
serializeQuantified (KnownType, Id)
ktTmId Word8
forallTermTag TypedSymbol 'ConstantKind t
ts Term Bool
t
        ExistsTerm TypedSymbol 'ConstantKind t
ts Term Bool
t -> (KnownType, Id)
-> Word8
-> TypedSymbol 'ConstantKind t
-> Term Bool
-> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *) v b.
MonadPut m =>
(KnownType, Id)
-> Word8
-> TypedConstantSymbol v
-> Term b
-> StateT (HashSet (KnownType, Id)) m ()
serializeQuantified (KnownType, Id)
ktTmId Word8
existsTermTag TypedSymbol 'ConstantKind t
ts Term Bool
t
        NotTerm Term Bool
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term Bool -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term Bool
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
notTermTag
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term Bool -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term Bool
t
        OrTerm Term Bool
t1 Term Bool
t2 -> (KnownType, Id)
-> Word8
-> Term Bool
-> Term Bool
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
orTermTag Term Bool
t1 Term Bool
t2
        AndTerm Term Bool
t1 Term Bool
t2 -> (KnownType, Id)
-> Word8
-> Term Bool
-> Term Bool
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
andTermTag Term Bool
t1 Term Bool
t2
        EqTerm Term t
t1 Term t
t2 -> (KnownType, Id)
-> Word8
-> Term t
-> Term t
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
eqTermTag Term t
t1 Term t
t2
        DistinctTerm NonEmpty (Term t)
ts -> do
          (Term t -> StateT (HashSet (KnownType, Id)) m ())
-> NonEmpty (Term t) -> StateT (HashSet (KnownType, Id)) m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> (Term t -> SomeTerm)
-> Term t
-> StateT (HashSet (KnownType, Id)) m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term t -> SomeTerm
forall a. Term a -> SomeTerm
someTerm) NonEmpty (Term t)
ts
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
distinctTermTag
          NonEmpty (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
NonEmpty (KnownType, Id) -> m ()
serialize (NonEmpty (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> NonEmpty (KnownType, Id)
-> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ (Term t -> (KnownType, Id))
-> NonEmpty (Term t) -> NonEmpty (KnownType, Id)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Term t -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId NonEmpty (Term t)
ts
        ITETerm Term Bool
t1 Term a
t2 Term a
t3 -> (KnownType, Id)
-> Word8
-> Term Bool
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a
-> a
-> Term a
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
serializeTernary (KnownType, Id)
ktTmId Word8
iteTermTag Term Bool
t1 Term a
t2 Term a
t3
        AddNumTerm Term a
t1 Term a
t2 -> (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
addNumTermTag Term a
t1 Term a
t2
        NegNumTerm Term a
t -> (KnownType, Id)
-> Word8 -> Term a -> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeUnary (KnownType, Id)
ktTmId Word8
negNumTermTag Term a
t
        MulNumTerm Term a
t1 Term a
t2 -> (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
mulNumTermTag Term a
t1 Term a
t2
        AbsNumTerm Term a
t -> (KnownType, Id)
-> Word8 -> Term a -> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeUnary (KnownType, Id)
ktTmId Word8
absNumTermTag Term a
t
        SignumNumTerm Term a
t -> (KnownType, Id)
-> Word8 -> Term a -> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeUnary (KnownType, Id)
ktTmId Word8
signumNumTermTag Term a
t
        LtOrdTerm Term t
t1 Term t
t2 -> (KnownType, Id)
-> Word8
-> Term t
-> Term t
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
ltOrdTermTag Term t
t1 Term t
t2
        LeOrdTerm Term t
t1 Term t
t2 -> (KnownType, Id)
-> Word8
-> Term t
-> Term t
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
leOrdTermTag Term t
t1 Term t
t2
        AndBitsTerm Term a
t1 Term a
t2 -> (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
andBitsTermTag Term a
t1 Term a
t2
        OrBitsTerm Term a
t1 Term a
t2 -> (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
orBitsTermTag Term a
t1 Term a
t2
        XorBitsTerm Term a
t1 Term a
t2 -> (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
xorBitsTermTag Term a
t1 Term a
t2
        ComplementBitsTerm Term a
t ->
          (KnownType, Id)
-> Word8 -> Term a -> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeUnary (KnownType, Id)
ktTmId Word8
complementBitsTermTag Term a
t
        ShiftLeftTerm Term a
t1 Term a
t2 ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
shiftLeftTermTag Term a
t1 Term a
t2
        ShiftRightTerm Term a
t1 Term a
t2 ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
shiftRightTermTag Term a
t1 Term a
t2
        RotateLeftTerm Term a
t1 Term a
t2 ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
rotateLeftTermTag Term a
t1 Term a
t2
        RotateRightTerm Term a
t1 Term a
t2 ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
rotateRightTermTag Term a
t1 Term a
t2
        BitCastTerm Term a
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
bitCastTermTag
          let kt :: KnownType
kt = Proxy a -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @t)
          KnownType -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *). MonadPut m => KnownType -> m ()
serializeKnownType KnownType
kt
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t
        BitCastOrTerm Term a
d Term a
t -> (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
bitCastOrTermTag Term a
d Term a
t
        BVConcatTerm Term (bv l)
t1 Term (bv r)
t2 -> (KnownType, Id)
-> Word8
-> Term (bv l)
-> Term (bv r)
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
bvConcatTermTag Term (bv l)
t1 Term (bv r)
t2
        BVSelectTerm Proxy ix
ix Proxy w
w Term (bv n)
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (bv n) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (bv n)
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
bvSelectTermTag
          Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Natural -> StateT (HashSet (KnownType, Id)) m ())
-> Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Proxy ix -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy ix
ix
          Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Natural -> StateT (HashSet (KnownType, Id)) m ())
-> Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Proxy w -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy w
w
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (bv n) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (bv n)
t
        BVExtendTerm Bool
signed Proxy r
r Term (bv l)
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (bv l) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (bv l)
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
bvExtendTermTag
          Bool -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Bool -> m ()
serialize Bool
signed
          Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Natural -> StateT (HashSet (KnownType, Id)) m ())
-> Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Proxy r -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy r
r
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (bv l) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (bv l)
t
        ApplyTerm Term f
f Term a
ts -> (KnownType, Id)
-> Word8
-> Term f
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
applyTermTag Term f
f Term a
ts
        DivIntegralTerm Term a
t1 Term a
t2 ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
divIntegralTermTag Term a
t1 Term a
t2
        ModIntegralTerm Term a
t1 Term a
t2 ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
modIntegralTermTag Term a
t1 Term a
t2
        QuotIntegralTerm Term a
t1 Term a
t2 ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
quotIntegralTermTag Term a
t1 Term a
t2
        RemIntegralTerm Term a
t1 Term a
t2 ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
remIntegralTermTag Term a
t1 Term a
t2
        FPTraitTerm FPTrait
trait Term (fp eb sb)
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
fpTraitTermTag
          FPTrait -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => FPTrait -> m ()
serialize FPTrait
trait
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t
        FdivTerm Term a
t1 Term a
t2 -> (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
fdivTermTag Term a
t1 Term a
t2
        RecipTerm Term a
t -> (KnownType, Id)
-> Word8 -> Term a -> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeUnary (KnownType, Id)
ktTmId Word8
recipTermTag Term a
t
        FloatingUnaryTerm FloatingUnaryOp
op Term a
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
floatingUnaryTermTag
          FloatingUnaryOp -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => FloatingUnaryOp -> m ()
serialize FloatingUnaryOp
op
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t
        PowerTerm Term a
t1 Term a
t2 -> (KnownType, Id)
-> Word8
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary (KnownType, Id)
ktTmId Word8
powerTermTag Term a
t1 Term a
t2
        FPUnaryTerm FPUnaryOp
op Term (fp eb sb)
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
fpUnaryTermTag
          FPUnaryOp -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => FPUnaryOp -> m ()
serialize FPUnaryOp
op
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t
        FPBinaryTerm FPBinaryOp
op Term (fp eb sb)
t1 Term (fp eb sb)
t2 -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t1
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t2
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
fpBinaryTermTag
          FPBinaryOp -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => FPBinaryOp -> m ()
serialize FPBinaryOp
op
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t1
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t2
        FPRoundingUnaryTerm FPRoundingUnaryOp
op Term FPRoundingMode
rd Term (fp eb sb)
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term FPRoundingMode
rd
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
fpRoundingUnaryTermTag
          FPRoundingUnaryOp -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => FPRoundingUnaryOp -> m ()
serialize FPRoundingUnaryOp
op
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term FPRoundingMode
rd
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t
        FPRoundingBinaryTerm FPRoundingBinaryOp
op Term FPRoundingMode
rd Term (fp eb sb)
t1 Term (fp eb sb)
t2 -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term FPRoundingMode
rd
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t1
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t2
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
fpRoundingBinaryTermTag
          FPRoundingBinaryOp -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => FPRoundingBinaryOp -> m ()
serialize FPRoundingBinaryOp
op
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term FPRoundingMode
rd
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t1
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t2
        FPFMATerm Term FPRoundingMode
rd Term (fp eb sb)
t1 Term (fp eb sb)
t2 Term (fp eb sb)
t3 -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term FPRoundingMode
rd
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t1
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t2
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term (fp eb sb)
t3
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
fpFMATermTag
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term FPRoundingMode
rd
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t1
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t2
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term (fp eb sb) -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term (fp eb sb)
t3
        FromIntegralTerm Term a
t -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
fromIntegralTermTag
          let kt :: KnownType
kt = Proxy a -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @t)
          KnownType -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *). MonadPut m => KnownType -> m ()
serializeKnownType KnownType
kt
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t
        FromFPOrTerm Term a
d Term FPRoundingMode
rd Term (FP eb sb)
t ->
          (KnownType, Id)
-> Word8
-> Term a
-> Term FPRoundingMode
-> Term (FP eb sb)
-> StateT (HashSet (KnownType, Id)) m ()
forall {m :: * -> *} {a} {a} {a} {a} {a}.
(MonadPut m, Serial a, Serial a) =>
a
-> a
-> Term a
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
serializeTernary (KnownType, Id)
ktTmId Word8
fromFPOrTermTag Term a
d Term FPRoundingMode
rd Term (FP eb sb)
t
        ToFPTerm Term FPRoundingMode
rd Term a
t Proxy eb
eb Proxy sb
sb -> do
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term FPRoundingMode
rd
          SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
          Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
toFPTermTag
          Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Natural -> StateT (HashSet (KnownType, Id)) m ())
-> Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Proxy eb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy eb
eb
          Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Natural -> m ()
serialize (Natural -> StateT (HashSet (KnownType, Id)) m ())
-> Natural -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Proxy sb -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
natVal Proxy sb
sb
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term FPRoundingMode -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term FPRoundingMode
rd
          (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t
  State.put $ HS.insert ktTmId st
  where
    serializeQuantified ::
      (MonadPut m) =>
      (KnownType, Id) ->
      Word8 ->
      TypedConstantSymbol v ->
      Term b ->
      StateT (HS.HashSet (KnownType, Id)) m ()
    serializeQuantified :: forall (m :: * -> *) v b.
MonadPut m =>
(KnownType, Id)
-> Word8
-> TypedConstantSymbol v
-> Term b
-> StateT (HashSet (KnownType, Id)) m ()
serializeQuantified (KnownType, Id)
ktTmId Word8
tag TypedConstantSymbol v
v Term b
t = do
      SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term b -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term b
t
      (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownType, Id)
ktTmId
      Word8 -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
serialize Word8
tag
      SomeTypedSymbol 'ConstantKind
-> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
SomeTypedSymbol 'ConstantKind -> m ()
serialize (SomeTypedSymbol 'ConstantKind
 -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTypedSymbol 'ConstantKind
-> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ TypedConstantSymbol v -> SomeTypedSymbol 'ConstantKind
forall (knd :: SymbolKind) t.
TypedSymbol knd t -> SomeTypedSymbol knd
someTypedSymbol TypedConstantSymbol v
v
      (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term b -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term b
t
    serializeUnary :: a -> a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeUnary a
ktTmId a
tag Term a
t1 = do
      SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t1
      a -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => a -> m ()
serialize a
ktTmId
      a -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => a -> m ()
serialize a
tag
      (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t1
    serializeBinary :: a -> a -> Term a -> Term a -> StateT (HashSet (KnownType, Id)) m ()
serializeBinary a
ktTmId a
tag Term a
t1 Term a
t2 = do
      SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t1
      SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t2
      a -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => a -> m ()
serialize a
ktTmId
      a -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => a -> m ()
serialize a
tag
      (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t1
      (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t2
    serializeTernary :: a
-> a
-> Term a
-> Term a
-> Term a
-> StateT (HashSet (KnownType, Id)) m ()
serializeTernary a
ktTmId a
tag Term a
t1 Term a
t2 Term a
t3 = do
      SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t1
      SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t2
      SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm (SomeTerm -> StateT (HashSet (KnownType, Id)) m ())
-> SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm Term a
t3
      a -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => a -> m ()
serialize a
ktTmId
      a -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => a -> m ()
serialize a
tag
      (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t1
      (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t2
      (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize ((KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ())
-> (KnownType, Id) -> StateT (HashSet (KnownType, Id)) m ()
forall a b. (a -> b) -> a -> b
$ Term a -> (KnownType, Id)
forall a. Term a -> (KnownType, Id)
knownTypeTermId Term a
t3

serializeSomeTerm :: (MonadPut m) => SomeTerm -> m ()
serializeSomeTerm :: forall (m :: * -> *). MonadPut m => SomeTerm -> m ()
serializeSomeTerm SomeTerm
t = do
  (StateT (HashSet (KnownType, Id)) m ()
 -> HashSet (KnownType, Id) -> m ())
-> HashSet (KnownType, Id)
-> StateT (HashSet (KnownType, Id)) m ()
-> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT (HashSet (KnownType, Id)) m ()
-> HashSet (KnownType, Id) -> m ()
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT HashSet (KnownType, Id)
forall a. HashSet a
HS.empty (StateT (HashSet (KnownType, Id)) m () -> m ())
-> StateT (HashSet (KnownType, Id)) m () -> m ()
forall a b. (a -> b) -> a -> b
$ SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
forall (m :: * -> *).
MonadPut m =>
SomeTerm -> StateT (HashSet (KnownType, Id)) m ()
serializeSingleSomeTerm SomeTerm
t
  (KnownType, Id) -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (KnownType, Id) -> m ()
serialize (KnownNonFuncType -> KnownType
NonFuncType KnownNonFuncType
BoolType, Id
0 :: Id)
  Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
terminalTag

instance Serial SomeTerm where
  serialize :: forall (m :: * -> *). MonadPut m => SomeTerm -> m ()
serialize = SomeTerm -> m ()
forall (m :: * -> *). MonadPut m => SomeTerm -> m ()
serializeSomeTerm
  deserialize :: forall (m :: * -> *). MonadGet m => m SomeTerm
deserialize = m SomeTerm
forall (m :: * -> *). MonadGet m => m SomeTerm
deserializeSomeTerm

instance Cereal.Serialize SomeTerm where
  put :: Putter SomeTerm
put = Putter SomeTerm
forall (m :: * -> *). MonadPut m => SomeTerm -> m ()
serializeSomeTerm
  get :: Get SomeTerm
get = Get SomeTerm
forall (m :: * -> *). MonadGet m => m SomeTerm
deserializeSomeTerm

instance Binary.Binary SomeTerm where
  put :: SomeTerm -> Put
put = SomeTerm -> Put
forall (m :: * -> *). MonadPut m => SomeTerm -> m ()
serializeSomeTerm
  get :: Get SomeTerm
get = Get SomeTerm
forall (m :: * -> *). MonadGet m => m SomeTerm
deserializeSomeTerm

instance (SupportedPrim a) => Serial (Term a) where
  serialize :: forall (m :: * -> *). MonadPut m => Term a -> m ()
serialize = SomeTerm -> m ()
forall (m :: * -> *). MonadPut m => SomeTerm -> m ()
serializeSomeTerm (SomeTerm -> m ()) -> (Term a -> SomeTerm) -> Term a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term a -> SomeTerm
forall a. Term a -> SomeTerm
someTerm
  deserialize :: forall (m :: * -> *). MonadGet m => m (Term a)
deserialize = do
    SomeTerm tm <- m SomeTerm
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m SomeTerm
deserialize
    case castTerm tm of
      Just Term a
r -> Term a -> m (Term a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Term a
r
      Maybe (Term a)
Nothing -> [Char] -> m (Term a)
forall a. [Char] -> m a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"deserialize Term: type mismatch"

instance (SupportedPrim a) => Cereal.Serialize (Term a) where
  put :: Putter (Term a)
put = Putter (Term a)
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Term a -> m ()
serialize
  get :: Get (Term a)
get = Get (Term a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (Term a)
deserialize

instance (SupportedPrim a) => Binary.Binary (Term a) where
  put :: Term a -> Put
put = Term a -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Term a -> m ()
serialize
  get :: Get (Term a)
get = Get (Term a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (Term a)
deserialize

instance Serial ModelValue where
  serialize :: forall (m :: * -> *). MonadPut m => ModelValue -> m ()
serialize (ModelValue (v
v :: v)) = do
    let kt :: KnownType
kt = Proxy v -> KnownType
forall a (p :: * -> *). SupportedPrim a => p a -> KnownType
knownType (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)
    KnownType -> m ()
forall (m :: * -> *). MonadPut m => KnownType -> m ()
serializeKnownType KnownType
kt
    case KnownType -> KnownTypeWitness
witnessKnownType KnownType
kt of
      KnownTypeWitness (Proxy a
Proxy :: Proxy v1) ->
        case TypeRep v -> TypeRep a -> Maybe (v :~~: a)
forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep (forall t. SupportedPrim t => TypeRep t
primTypeRep @v) (forall a. Typeable a => TypeRep a
forall {k} (a :: k). Typeable a => TypeRep a
typeRep @v1) of
          Just v :~~: a
HRefl -> v -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => v -> m ()
serialize v
v
          Maybe (v :~~: a)
Nothing ->
            [Char] -> m ()
forall a. HasCallStack => [Char] -> a
error
              [Char]
"serialize ModelValue: should not happen: type mismatch"
  deserialize :: forall (m :: * -> *). MonadGet m => m ModelValue
deserialize = do
    kt <- m KnownType
forall (m :: * -> *). MonadGet m => m KnownType
deserializeKnownType
    case witnessKnownType kt of
      KnownTypeWitness (Proxy a
Proxy :: Proxy v) -> do
        v <- forall a (m :: * -> *). (Serial a, MonadGet m) => m a
deserialize @v
        return $ ModelValue v

instance Cereal.Serialize ModelValue where
  put :: Putter ModelValue
put = Putter ModelValue
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => ModelValue -> m ()
serialize
  get :: Get ModelValue
get = Get ModelValue
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m ModelValue
deserialize

instance Binary.Binary ModelValue where
  put :: ModelValue -> Put
put = ModelValue -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => ModelValue -> m ()
serialize
  get :: Get ModelValue
get = Get ModelValue
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m ModelValue
deserialize

instance (GeneralFunArg a, GeneralFunArg b) => Serial (a --> b) where
  serialize :: forall (m :: * -> *). MonadPut m => (a --> b) -> m ()
serialize (GeneralFun TypedConstantSymbol a
ts Term b
tm) = TypedConstantSymbol a -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedConstantSymbol a -> m ()
serialize TypedConstantSymbol a
ts m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term b -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Term b -> m ()
serialize Term b
tm
  deserialize :: forall (m :: * -> *). MonadGet m => m (a --> b)
deserialize = TypedConstantSymbol a -> Term b -> a --> b
forall a b.
(SupportedNonFuncPrim a, SupportedPrim b) =>
TypedConstantSymbol a -> Term b -> a --> b
GeneralFun (TypedConstantSymbol a -> Term b -> a --> b)
-> m (TypedConstantSymbol a) -> m (Term b -> a --> b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (TypedConstantSymbol a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedConstantSymbol a)
deserialize m (Term b -> a --> b) -> m (Term b) -> m (a --> b)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Term b)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (Term b)
deserialize

instance (GeneralFunArg a, GeneralFunArg b) => Cereal.Serialize (a --> b) where
  put :: Putter (a --> b)
put = Putter (a --> b)
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (a --> b) -> m ()
serialize
  get :: Get (a --> b)
get = Get (a --> b)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (a --> b)
deserialize

instance (GeneralFunArg a, GeneralFunArg b) => Binary.Binary (a --> b) where
  put :: (a --> b) -> Put
put = (a --> b) -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (a --> b) -> m ()
serialize
  get :: Get (a --> b)
get = Get (a --> b)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (a --> b)
deserialize

type GeneralFunArg t = (SupportedNonFuncPrim t, Typeable t, Show t, Hashable t)

instance
  {-# OVERLAPPING #-}
  (GeneralFunArg a, GeneralFunArg b, GeneralFunArg c) =>
  Serial (a --> b --> c)
  where
  serialize :: forall (m :: * -> *). MonadPut m => (a --> (b --> c)) -> m ()
serialize (GeneralFun TypedConstantSymbol a
ts Term (b --> c)
tm) = TypedConstantSymbol a -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedConstantSymbol a -> m ()
serialize TypedConstantSymbol a
ts m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term (b --> c) -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Term (b --> c) -> m ()
serialize Term (b --> c)
tm
  deserialize :: forall (m :: * -> *). MonadGet m => m (a --> (b --> c))
deserialize = TypedConstantSymbol a -> Term (b --> c) -> a --> (b --> c)
forall a b.
(SupportedNonFuncPrim a, SupportedPrim b) =>
TypedConstantSymbol a -> Term b -> a --> b
GeneralFun (TypedConstantSymbol a -> Term (b --> c) -> a --> (b --> c))
-> m (TypedConstantSymbol a)
-> m (Term (b --> c) -> a --> (b --> c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (TypedConstantSymbol a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedConstantSymbol a)
deserialize m (Term (b --> c) -> a --> (b --> c))
-> m (Term (b --> c)) -> m (a --> (b --> c))
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Term (b --> c))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (Term (b --> c))
deserialize

instance
  {-# OVERLAPPING #-}
  (GeneralFunArg a, GeneralFunArg b, GeneralFunArg c) =>
  Cereal.Serialize (a --> b --> c)
  where
  put :: Putter (a --> (b --> c))
put = Putter (a --> (b --> c))
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (a --> (b --> c)) -> m ()
serialize
  get :: Get (a --> (b --> c))
get = Get (a --> (b --> c))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (a --> (b --> c))
deserialize

instance
  {-# OVERLAPPING #-}
  (GeneralFunArg a, GeneralFunArg b, GeneralFunArg c) =>
  Binary.Binary (a --> b --> c)
  where
  put :: (a --> (b --> c)) -> Put
put = (a --> (b --> c)) -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => (a --> (b --> c)) -> m ()
serialize
  get :: Get (a --> (b --> c))
get = Get (a --> (b --> c))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (a --> (b --> c))
deserialize

instance
  {-# OVERLAPPING #-}
  (GeneralFunArg a, GeneralFunArg b, GeneralFunArg c, GeneralFunArg d) =>
  Serial (a --> b --> c --> d)
  where
  serialize :: forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> d))) -> m ()
serialize (GeneralFun TypedConstantSymbol a
ts Term (b --> (c --> d))
tm) = TypedConstantSymbol a -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedConstantSymbol a -> m ()
serialize TypedConstantSymbol a
ts m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term (b --> (c --> d)) -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Term (b --> (c --> d)) -> m ()
serialize Term (b --> (c --> d))
tm
  deserialize :: forall (m :: * -> *). MonadGet m => m (a --> (b --> (c --> d)))
deserialize = TypedConstantSymbol a
-> Term (b --> (c --> d)) -> a --> (b --> (c --> d))
forall a b.
(SupportedNonFuncPrim a, SupportedPrim b) =>
TypedConstantSymbol a -> Term b -> a --> b
GeneralFun (TypedConstantSymbol a
 -> Term (b --> (c --> d)) -> a --> (b --> (c --> d)))
-> m (TypedConstantSymbol a)
-> m (Term (b --> (c --> d)) -> a --> (b --> (c --> d)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (TypedConstantSymbol a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedConstantSymbol a)
deserialize m (Term (b --> (c --> d)) -> a --> (b --> (c --> d)))
-> m (Term (b --> (c --> d))) -> m (a --> (b --> (c --> d)))
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Term (b --> (c --> d)))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (Term (b --> (c --> d)))
deserialize

instance
  {-# OVERLAPPING #-}
  (GeneralFunArg a, GeneralFunArg b, GeneralFunArg c, GeneralFunArg d) =>
  Cereal.Serialize (a --> b --> c --> d)
  where
  put :: Putter (a --> (b --> (c --> d)))
put = Putter (a --> (b --> (c --> d)))
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> d))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> d)))
get = Get (a --> (b --> (c --> d)))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (a --> (b --> (c --> d)))
deserialize

instance
  {-# OVERLAPPING #-}
  (GeneralFunArg a, GeneralFunArg b, GeneralFunArg c, GeneralFunArg d) =>
  Binary.Binary (a --> b --> c --> d)
  where
  put :: (a --> (b --> (c --> d))) -> Put
put = (a --> (b --> (c --> d))) -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> d))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> d)))
get = Get (a --> (b --> (c --> d)))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (a --> (b --> (c --> d)))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e
  ) =>
  Serial (a --> b --> c --> d --> e)
  where
  serialize :: forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> e)))) -> m ()
serialize (GeneralFun TypedConstantSymbol a
ts Term (b --> (c --> (d --> e)))
tm) = TypedConstantSymbol a -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedConstantSymbol a -> m ()
serialize TypedConstantSymbol a
ts m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term (b --> (c --> (d --> e))) -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
Term (b --> (c --> (d --> e))) -> m ()
serialize Term (b --> (c --> (d --> e)))
tm
  deserialize :: forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> e))))
deserialize = TypedConstantSymbol a
-> Term (b --> (c --> (d --> e)))
-> a --> (b --> (c --> (d --> e)))
forall a b.
(SupportedNonFuncPrim a, SupportedPrim b) =>
TypedConstantSymbol a -> Term b -> a --> b
GeneralFun (TypedConstantSymbol a
 -> Term (b --> (c --> (d --> e)))
 -> a --> (b --> (c --> (d --> e))))
-> m (TypedConstantSymbol a)
-> m (Term (b --> (c --> (d --> e)))
      -> a --> (b --> (c --> (d --> e))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (TypedConstantSymbol a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedConstantSymbol a)
deserialize m (Term (b --> (c --> (d --> e)))
   -> a --> (b --> (c --> (d --> e))))
-> m (Term (b --> (c --> (d --> e))))
-> m (a --> (b --> (c --> (d --> e))))
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Term (b --> (c --> (d --> e))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (Term (b --> (c --> (d --> e))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e
  ) =>
  Cereal.Serialize (a --> b --> c --> d --> e)
  where
  put :: Putter (a --> (b --> (c --> (d --> e))))
put = Putter (a --> (b --> (c --> (d --> e))))
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> e)))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> (d --> e))))
get = Get (a --> (b --> (c --> (d --> e))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> e))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e
  ) =>
  Binary.Binary (a --> b --> c --> d --> e)
  where
  put :: (a --> (b --> (c --> (d --> e)))) -> Put
put = (a --> (b --> (c --> (d --> e)))) -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> e)))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> (d --> e))))
get = Get (a --> (b --> (c --> (d --> e))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> e))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f
  ) =>
  Serial (a --> b --> c --> d --> e --> f)
  where
  serialize :: forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> f))))) -> m ()
serialize (GeneralFun TypedConstantSymbol a
ts Term (b --> (c --> (d --> (e --> f))))
tm) = TypedConstantSymbol a -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedConstantSymbol a -> m ()
serialize TypedConstantSymbol a
ts m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term (b --> (c --> (d --> (e --> f)))) -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
Term (b --> (c --> (d --> (e --> f)))) -> m ()
serialize Term (b --> (c --> (d --> (e --> f))))
tm
  deserialize :: forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> f)))))
deserialize = TypedConstantSymbol a
-> Term (b --> (c --> (d --> (e --> f))))
-> a --> (b --> (c --> (d --> (e --> f))))
forall a b.
(SupportedNonFuncPrim a, SupportedPrim b) =>
TypedConstantSymbol a -> Term b -> a --> b
GeneralFun (TypedConstantSymbol a
 -> Term (b --> (c --> (d --> (e --> f))))
 -> a --> (b --> (c --> (d --> (e --> f)))))
-> m (TypedConstantSymbol a)
-> m (Term (b --> (c --> (d --> (e --> f))))
      -> a --> (b --> (c --> (d --> (e --> f)))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (TypedConstantSymbol a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedConstantSymbol a)
deserialize m (Term (b --> (c --> (d --> (e --> f))))
   -> a --> (b --> (c --> (d --> (e --> f)))))
-> m (Term (b --> (c --> (d --> (e --> f)))))
-> m (a --> (b --> (c --> (d --> (e --> f)))))
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Term (b --> (c --> (d --> (e --> f)))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (Term (b --> (c --> (d --> (e --> f)))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f
  ) =>
  Cereal.Serialize (a --> b --> c --> d --> e --> f)
  where
  put :: Putter (a --> (b --> (c --> (d --> (e --> f)))))
put = Putter (a --> (b --> (c --> (d --> (e --> f)))))
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> f))))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> (d --> (e --> f)))))
get = Get (a --> (b --> (c --> (d --> (e --> f)))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> f)))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f
  ) =>
  Binary.Binary (a --> b --> c --> d --> e --> f)
  where
  put :: (a --> (b --> (c --> (d --> (e --> f))))) -> Put
put = (a --> (b --> (c --> (d --> (e --> f))))) -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> f))))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> (d --> (e --> f)))))
get = Get (a --> (b --> (c --> (d --> (e --> f)))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> f)))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g
  ) =>
  Serial (a --> b --> c --> d --> e --> f --> g)
  where
  serialize :: forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> g)))))) -> m ()
serialize (GeneralFun TypedConstantSymbol a
ts Term (b --> (c --> (d --> (e --> (f --> g)))))
tm) = TypedConstantSymbol a -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedConstantSymbol a -> m ()
serialize TypedConstantSymbol a
ts m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term (b --> (c --> (d --> (e --> (f --> g))))) -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
Term (b --> (c --> (d --> (e --> (f --> g))))) -> m ()
serialize Term (b --> (c --> (d --> (e --> (f --> g)))))
tm
  deserialize :: forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> g))))))
deserialize = TypedConstantSymbol a
-> Term (b --> (c --> (d --> (e --> (f --> g)))))
-> a --> (b --> (c --> (d --> (e --> (f --> g)))))
forall a b.
(SupportedNonFuncPrim a, SupportedPrim b) =>
TypedConstantSymbol a -> Term b -> a --> b
GeneralFun (TypedConstantSymbol a
 -> Term (b --> (c --> (d --> (e --> (f --> g)))))
 -> a --> (b --> (c --> (d --> (e --> (f --> g))))))
-> m (TypedConstantSymbol a)
-> m (Term (b --> (c --> (d --> (e --> (f --> g)))))
      -> a --> (b --> (c --> (d --> (e --> (f --> g))))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (TypedConstantSymbol a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedConstantSymbol a)
deserialize m (Term (b --> (c --> (d --> (e --> (f --> g)))))
   -> a --> (b --> (c --> (d --> (e --> (f --> g))))))
-> m (Term (b --> (c --> (d --> (e --> (f --> g))))))
-> m (a --> (b --> (c --> (d --> (e --> (f --> g))))))
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Term (b --> (c --> (d --> (e --> (f --> g))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (Term (b --> (c --> (d --> (e --> (f --> g))))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g
  ) =>
  Cereal.Serialize (a --> b --> c --> d --> e --> f --> g)
  where
  put :: Putter (a --> (b --> (c --> (d --> (e --> (f --> g))))))
put = Putter (a --> (b --> (c --> (d --> (e --> (f --> g))))))
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> g)))))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> (d --> (e --> (f --> g))))))
get = Get (a --> (b --> (c --> (d --> (e --> (f --> g))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> g))))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g
  ) =>
  Binary.Binary (a --> b --> c --> d --> e --> f --> g)
  where
  put :: (a --> (b --> (c --> (d --> (e --> (f --> g)))))) -> Put
put = (a --> (b --> (c --> (d --> (e --> (f --> g)))))) -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> g)))))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> (d --> (e --> (f --> g))))))
get = Get (a --> (b --> (c --> (d --> (e --> (f --> g))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> g))))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g,
    GeneralFunArg h
  ) =>
  Serial (a --> b --> c --> d --> e --> f --> g --> h)
  where
  serialize :: forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> (g --> h))))))) -> m ()
serialize (GeneralFun TypedConstantSymbol a
ts Term (b --> (c --> (d --> (e --> (f --> (g --> h))))))
tm) = TypedConstantSymbol a -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedConstantSymbol a -> m ()
serialize TypedConstantSymbol a
ts m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term (b --> (c --> (d --> (e --> (f --> (g --> h)))))) -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
Term (b --> (c --> (d --> (e --> (f --> (g --> h)))))) -> m ()
serialize Term (b --> (c --> (d --> (e --> (f --> (g --> h))))))
tm
  deserialize :: forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
deserialize = TypedConstantSymbol a
-> Term (b --> (c --> (d --> (e --> (f --> (g --> h))))))
-> a --> (b --> (c --> (d --> (e --> (f --> (g --> h))))))
forall a b.
(SupportedNonFuncPrim a, SupportedPrim b) =>
TypedConstantSymbol a -> Term b -> a --> b
GeneralFun (TypedConstantSymbol a
 -> Term (b --> (c --> (d --> (e --> (f --> (g --> h))))))
 -> a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
-> m (TypedConstantSymbol a)
-> m (Term (b --> (c --> (d --> (e --> (f --> (g --> h))))))
      -> a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (TypedConstantSymbol a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedConstantSymbol a)
deserialize m (Term (b --> (c --> (d --> (e --> (f --> (g --> h))))))
   -> a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
-> m (Term (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
-> m (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Term (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (Term (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g,
    GeneralFunArg h
  ) =>
  Cereal.Serialize (a --> b --> c --> d --> e --> f --> g --> h)
  where
  put :: Putter (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
put = Putter (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> (g --> h))))))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
get = Get (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g,
    GeneralFunArg h
  ) =>
  Binary.Binary (a --> b --> c --> d --> e --> f --> g --> h)
  where
  put :: (a --> (b --> (c --> (d --> (e --> (f --> (g --> h))))))) -> Put
put = (a --> (b --> (c --> (d --> (e --> (f --> (g --> h))))))) -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> (g --> h))))))) -> m ()
serialize
  get :: Get (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
get = Get (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> (g --> h)))))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g,
    GeneralFunArg h,
    GeneralFunArg i
  ) =>
  Serial (a --> b --> c --> d --> e --> f --> g --> h --> i)
  where
  serialize :: forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
-> m ()
serialize (GeneralFun TypedConstantSymbol a
ts Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
tm) = TypedConstantSymbol a -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => TypedConstantSymbol a -> m ()
serialize TypedConstantSymbol a
ts m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
-> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
-> m ()
serialize Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
tm
  deserialize :: forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
deserialize = TypedConstantSymbol a
-> Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
-> a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
forall a b.
(SupportedNonFuncPrim a, SupportedPrim b) =>
TypedConstantSymbol a -> Term b -> a --> b
GeneralFun (TypedConstantSymbol a
 -> Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
 -> a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
-> m (TypedConstantSymbol a)
-> m (Term
        (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
      -> a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (TypedConstantSymbol a)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (TypedConstantSymbol a)
deserialize m (Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i)))))))
   -> a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
-> m (Term
        (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
-> m (a
      --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (Term (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g,
    GeneralFunArg h,
    GeneralFunArg i
  ) =>
  Cereal.Serialize (a --> b --> c --> d --> e --> f --> g --> h --> i)
  where
  put :: Putter
  (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
put = Putter
  (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
-> m ()
serialize
  get :: Get
  (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
get = Get
  (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
deserialize

instance
  {-# OVERLAPPING #-}
  ( GeneralFunArg a,
    GeneralFunArg b,
    GeneralFunArg c,
    GeneralFunArg d,
    GeneralFunArg e,
    GeneralFunArg f,
    GeneralFunArg g,
    GeneralFunArg h,
    GeneralFunArg i
  ) =>
  Binary.Binary (a --> b --> c --> d --> e --> f --> g --> h --> i)
  where
  put :: (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
-> Put
put = (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
-> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *).
MonadPut m =>
(a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
-> m ()
serialize
  get :: Get
  (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
get = Get
  (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *).
MonadGet m =>
m (a --> (b --> (c --> (d --> (e --> (f --> (g --> (h --> i))))))))
deserialize