-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Cryptol: The Language of Cryptography
--   
--   Cryptol is a domain-specific language for specifying cryptographic
--   algorithms. A Cryptol implementation of an algorithm resembles its
--   mathematical specification more closely than an implementation in a
--   general purpose language. For more, see
--   <a>http://www.cryptol.net/</a>.
@package cryptol
@version 3.0.0


-- | A TBox-based implementation of AES primitives, based on the AES
--   example code from SBV. Here we've stripped out everything except the
--   basic primitives needed, which essentially boil down to table table
--   lookups in most cases.
module Cryptol.AES

-- | AES state. The state consists of four 32-bit words, each of which is
--   in turn treated as four GF28's, i.e., 4 bytes. The T-Box
--   implementation keeps the four-bytes together for efficient
--   representation.
type State = [Word32]

-- | The key, which can be 128, 192, or 256 bits. Represented as a sequence
--   of 32-bit words.
type Key = [Word32]
keyExpansionWords :: Integer -> Key -> [Word32]

-- | The <tt>InvMixColumns</tt> transformation, as described in Section
--   5.3.3 of the standard. Note that this transformation is only used
--   explicitly during key-expansion in the T-Box implementation of AES.
invMixColumns :: State -> State
aesRound :: State -> State
aesFinalRound :: State -> State
aesInvRound :: State -> State
aesInvFinalRound :: State -> State


-- | Architecture-specific parts of the concrete evaluator go here.
module Cryptol.Backend.Arch

-- | This is the widest word we can have before gmp will fail to allocate
--   and bring down the whole program. According to
--   <a>https://gmplib.org/list-archives/gmp-bugs/2009-July/001538.html</a>
--   the sizes are 2^32-1 for 32-bit, and 2^37 for 64-bit, however
--   experiments show that it's somewhere under 2^37 at least on 64-bit Mac
--   OS X.
maxBigIntWidth :: Integer


module Cryptol.ModuleSystem.Fingerprint
data Fingerprint

-- | Compute a fingerprint for a bytestring.
fingerprint :: ByteString -> Fingerprint

-- | Attempt to compute the fingerprint of the file at the given path.
--   Returns <a>Nothing</a> in the case of an error.
fingerprintFile :: FilePath -> IO (Maybe Fingerprint)
fingerprintHexString :: Fingerprint -> String
instance GHC.Show.Show Cryptol.ModuleSystem.Fingerprint.Fingerprint
instance GHC.Classes.Eq Cryptol.ModuleSystem.Fingerprint.Fingerprint
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Fingerprint.Fingerprint


-- | Pure implementations of the SHA suite of hash functions. The
--   implementation is basically an unoptimized translation of FIPS 180-2
--   into Haskell. If you're looking for performance, you probably won't
--   find it here.
module Cryptol.SHA
data SHA256State
SHA256S :: !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> SHA256State
data SHA512State
SHA512S :: !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> SHA512State
data SHA256Block
SHA256Block :: !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> SHA256Block
data SHA512Block
SHA512Block :: !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> SHA512Block
processSHA512Block :: SHA512State -> SHA512Block -> SHA512State
processSHA256Block :: SHA256State -> SHA256Block -> SHA256State
initialSHA224State :: SHA256State
initialSHA256State :: SHA256State
initialSHA384State :: SHA512State
initialSHA512State :: SHA512State
toBigEndianSBS :: (Integral a, Bits a) => Int -> a -> ByteString
fromBigEndianSBS :: (Integral a, Bits a) => ByteString -> a
calc_k :: Word64 -> Word64 -> Word64 -> Word64
padSHA1 :: ByteString -> ByteString
padSHA512 :: ByteString -> ByteString
padSHA1Chunks :: Int -> [ByteString]
padSHA512Chunks :: Int -> [ByteString]


-- | Simple benchmarking of IO functions.
module Cryptol.Utils.Benchmark

-- | Statistics returned by <a>benchmark</a>.
--   
--   This is extremely crude compared to the full analysis that criterion
--   can do, but is enough for now.
data BenchmarkStats
BenchmarkStats :: !Double -> !Double -> !Int64 -> BenchmarkStats
[benchAvgTime] :: BenchmarkStats -> !Double
[benchAvgCpuTime] :: BenchmarkStats -> !Double
[benchAvgCycles] :: BenchmarkStats -> !Int64

-- | Benchmark the application of the given function to the given input and
--   the execution of the resulting IO action to WHNF, spending at least
--   the given amount of time in seconds to collect measurements.
benchmark :: Double -> (a -> IO b) -> a -> IO BenchmarkStats

-- | Convert a number of seconds to a string. The string will consist of
--   four decimal places, followed by a short description of the time
--   units.
secs :: Double -> String
instance GHC.Show.Show Cryptol.Utils.Benchmark.BenchmarkStats


module Cryptol.Utils.Fixity

-- | Information about associativity.
data Assoc
LeftAssoc :: Assoc
RightAssoc :: Assoc
NonAssoc :: Assoc
data Fixity
Fixity :: !Assoc -> !Int -> Fixity
[fAssoc] :: Fixity -> !Assoc
[fLevel] :: Fixity -> !Int

-- | The fixity used when none is provided.
defaultFixity :: Fixity
data FixityCmp
FCError :: FixityCmp
FCLeft :: FixityCmp
FCRight :: FixityCmp

-- | Let <tt>op1</tt> have fixity <tt>f1</tt> and <tt>op2</tt> have fixity
--   <tt>f2. Then </tt>compareFixity f1 f2<tt> determines how to parse the
--   infix expression </tt>x op1 y op2 z@.
--   
--   <ul>
--   <li><tt>FCLeft</tt>: <tt>(x op1 y) op2 z</tt></li>
--   <li><tt>FCRight</tt>: <tt>x op1 (y op2 z)</tt></li>
--   <li><tt>FCError</tt>: no parse</li>
--   </ul>
compareFixity :: Fixity -> Fixity -> FixityCmp
instance Control.DeepSeq.NFData Cryptol.Utils.Fixity.Assoc
instance GHC.Generics.Generic Cryptol.Utils.Fixity.Assoc
instance GHC.Classes.Ord Cryptol.Utils.Fixity.Assoc
instance GHC.Classes.Eq Cryptol.Utils.Fixity.Assoc
instance GHC.Show.Show Cryptol.Utils.Fixity.Assoc
instance GHC.Show.Show Cryptol.Utils.Fixity.Fixity
instance Control.DeepSeq.NFData Cryptol.Utils.Fixity.Fixity
instance GHC.Generics.Generic Cryptol.Utils.Fixity.Fixity
instance GHC.Classes.Ord Cryptol.Utils.Fixity.Fixity
instance GHC.Classes.Eq Cryptol.Utils.Fixity.Fixity
instance GHC.Classes.Eq Cryptol.Utils.Fixity.FixityCmp
instance GHC.Show.Show Cryptol.Utils.Fixity.FixityCmp


-- | A simple system so that the Cryptol driver can communicate with users
--   (or not).
module Cryptol.Utils.Logger

-- | A logger provides simple abstraction for sending messages.
data Logger

-- | Log to stdout.
stdoutLogger :: Logger

-- | Log to stderr.
stderrLogger :: Logger

-- | Log to the given handle.
handleLogger :: Handle -> Logger

-- | A logger that ignores all messages.
quietLogger :: Logger

-- | Just use this function for logging.
funLogger :: (String -> IO ()) -> Logger

-- | Send the given string to the log.
logPutStr :: Logger -> String -> IO ()

-- | Send the given string with a newline at the end.
logPutStrLn :: Logger -> String -> IO ()

-- | Send the given value using its <a>Show</a> instance. Adds a newline at
--   the end.
logPrint :: Show a => Logger -> a -> IO ()
instance Control.DeepSeq.NFData Cryptol.Utils.Logger.Logger


module Cryptol.Utils.Misc

-- | Apply a function to all elements of a container. Returns
--   <a>Nothing</a> if nothing changed, and <tt>Just container</tt>
--   otherwise.
anyJust :: Traversable t => (a -> Maybe a) -> t a -> Maybe (t a)

-- | Apply functions to both elements of a pair. Returns <a>Nothing</a> if
--   neither changed, and <tt>Just pair</tt> otherwise.
anyJust2 :: (a -> Maybe a) -> (b -> Maybe b) -> (a, b) -> Maybe (a, b)


module Cryptol.Utils.Panic

-- | Request a CallStack.
--   
--   NOTE: The implicit parameter <tt>?callStack :: CallStack</tt> is an
--   implementation detail and <b>should not</b> be considered part of the
--   <a>CallStack</a> API, we may decide to change the implementation in
--   the future.
type HasCallStack = ?callStack :: CallStack
type CryptolPanic = Panic Cryptol
data Cryptol

-- | The exception thrown when panicing.
data () => Panic a
panic :: HasCallStack => String -> [String] -> a
xxxTODO :: HasCallStack => String -> a
instance Panic.PanicComponent Cryptol.Utils.Panic.Cryptol


module Cryptol.Utils.Ident

-- | Idnetifies a possibly nested module
data ModPath
TopModule :: ModName -> ModPath
Nested :: ModPath -> Ident -> ModPath
apPathRoot :: (ModName -> ModName) -> ModPath -> ModPath

-- | Compute a common prefix between two module paths, if any. This is
--   basically "anti-unification" of the two paths, where we compute the
--   longest common prefix, and the remaining differences for each module.
modPathCommon :: ModPath -> ModPath -> Maybe (ModPath, [Ident], [Ident])

-- | Does the first module path contain the second? This returns true if
--   the paths are the same.
modPathIsOrContains :: ModPath -> ModPath -> Bool
topModuleFor :: ModPath -> ModName
modPathSplit :: ModPath -> (ModName, [Ident])
modPathIsNormal :: ModPath -> Bool

-- | Top-level Module names are just text.
data ModName
modNameToText :: ModName -> Text

-- | Make a normal module name out of text.
textToModName :: Text -> ModName

-- | Break up a module name on the separators, <a>String</a> version
modNameChunks :: ModName -> [String]

-- | Break up a module name on the separators, <a>Text</a> version.
modNameChunksText :: ModName -> [Text]
packModName :: [Text] -> ModName
preludeName :: ModName
preludeReferenceName :: ModName
undefinedModName :: ModName
floatName :: ModName
suiteBName :: ModName
arrayName :: ModName
primeECName :: ModName
interactiveName :: ModName
noModuleName :: ModName
exprModName :: ModName

-- | Change a normal module name to a module name to be used for an
--   anonnymous argument.
modNameArg :: ModName -> ModName

-- | Change a normal module name to a module name to be used for an
--   anonnymous interface.
modNameIfaceMod :: ModName -> ModName

-- | This is used when we check that the name of a module matches the file
--   where it is defined.
modNameToNormalModName :: ModName -> ModName

-- | This is useful when we want to hide anonymous modules.
modNameIsNormal :: ModName -> Bool

-- | The type of identifiers. * The boolean flag indicates whether or not
--   they're infix operators. The boolean is present just as cached
--   information from the lexer, and never used during comparisons. * The
--   MaybeAnon indicates if this is an anonymous name
data Ident

-- | Make a normal (i.e., not anonymous) identifier
packIdent :: String -> Ident

-- | Make a normal (i.e., not anonymous) identifier
packInfix :: String -> Ident
unpackIdent :: Ident -> String

-- | Make a normal (i.e., not anonymous) identifier
mkIdent :: Text -> Ident
mkInfix :: Text -> Ident
isInfixIdent :: Ident -> Bool
nullIdent :: Ident -> Bool
identText :: Ident -> Text
modParamIdent :: Ident -> Ident

-- | Make an anonymous identifier for the module corresponding to a `where`
--   block in a functor instantiation.
identAnonArg :: Ident -> Ident

-- | Make an anonymous identifier for the interface corresponding to a
--   <tt>parameter</tt> declaration.
identAnonIfaceMod :: Ident -> Ident
identIsNormal :: Ident -> Bool

-- | Namespaces for names
data Namespace
NSValue :: Namespace
NSType :: Namespace
NSModule :: Namespace
allNamespaces :: [Namespace]

-- | Identifies an entitiy
data OrigName
OrigName :: Namespace -> ModPath -> OrigSource -> Ident -> OrigName
[ogNamespace] :: OrigName -> Namespace
[ogModule] :: OrigName -> ModPath
[ogSource] :: OrigName -> OrigSource
[ogName] :: OrigName -> Ident

-- | Describes where a top-level name came from
data OrigSource
FromDefinition :: OrigSource
FromFunctorInst :: OrigSource
FromModParam :: Ident -> OrigSource

-- | Returns true iff the <a>ogSource</a> of the given <a>OrigName</a> is
--   <a>FromModParam</a>
ogFromModParam :: OrigName -> Bool

-- | A way to identify primitives: we used to use just <a>Ident</a>, but
--   this isn't good anymore as now we have primitives in multiple modules.
--   This is used as a key when we need to lookup details about a specific
--   primitive. Also, this is intended to mostly be used internally, so we
--   don't store the fixity flag of the <a>Ident</a>
data PrimIdent
PrimIdent :: ModName -> Text -> PrimIdent

-- | A shortcut to make (non-infix) primitives in the prelude.
prelPrim :: Text -> PrimIdent
floatPrim :: Text -> PrimIdent
arrayPrim :: Text -> PrimIdent
suiteBPrim :: Text -> PrimIdent
primeECPrim :: Text -> PrimIdent
instance GHC.Enum.Bounded Cryptol.Utils.Ident.Namespace
instance GHC.Enum.Enum Cryptol.Utils.Ident.Namespace
instance GHC.Classes.Ord Cryptol.Utils.Ident.Namespace
instance GHC.Classes.Eq Cryptol.Utils.Ident.Namespace
instance Control.DeepSeq.NFData Cryptol.Utils.Ident.Namespace
instance GHC.Show.Show Cryptol.Utils.Ident.Namespace
instance GHC.Generics.Generic Cryptol.Utils.Ident.Namespace
instance GHC.Generics.Generic Cryptol.Utils.Ident.MaybeAnon
instance GHC.Show.Show Cryptol.Utils.Ident.MaybeAnon
instance GHC.Classes.Ord Cryptol.Utils.Ident.MaybeAnon
instance GHC.Classes.Eq Cryptol.Utils.Ident.MaybeAnon
instance GHC.Generics.Generic Cryptol.Utils.Ident.Ident
instance GHC.Show.Show Cryptol.Utils.Ident.Ident
instance Control.DeepSeq.NFData Cryptol.Utils.Ident.OrigSource
instance GHC.Generics.Generic Cryptol.Utils.Ident.OrigSource
instance GHC.Show.Show Cryptol.Utils.Ident.OrigSource
instance GHC.Classes.Ord Cryptol.Utils.Ident.OrigSource
instance GHC.Classes.Eq Cryptol.Utils.Ident.OrigSource
instance GHC.Generics.Generic Cryptol.Utils.Ident.ModName
instance GHC.Show.Show Cryptol.Utils.Ident.ModName
instance GHC.Classes.Ord Cryptol.Utils.Ident.ModName
instance GHC.Classes.Eq Cryptol.Utils.Ident.ModName
instance Control.DeepSeq.NFData Cryptol.Utils.Ident.ModPath
instance GHC.Generics.Generic Cryptol.Utils.Ident.ModPath
instance GHC.Show.Show Cryptol.Utils.Ident.ModPath
instance GHC.Classes.Ord Cryptol.Utils.Ident.ModPath
instance GHC.Classes.Eq Cryptol.Utils.Ident.ModPath
instance Control.DeepSeq.NFData Cryptol.Utils.Ident.OrigName
instance GHC.Generics.Generic Cryptol.Utils.Ident.OrigName
instance GHC.Show.Show Cryptol.Utils.Ident.OrigName
instance GHC.Classes.Ord Cryptol.Utils.Ident.OrigName
instance GHC.Classes.Eq Cryptol.Utils.Ident.OrigName
instance GHC.Generics.Generic Cryptol.Utils.Ident.PrimIdent
instance GHC.Show.Show Cryptol.Utils.Ident.PrimIdent
instance GHC.Classes.Ord Cryptol.Utils.Ident.PrimIdent
instance GHC.Classes.Eq Cryptol.Utils.Ident.PrimIdent
instance Control.DeepSeq.NFData Cryptol.Utils.Ident.PrimIdent
instance Control.DeepSeq.NFData Cryptol.Utils.Ident.ModName
instance GHC.Classes.Eq Cryptol.Utils.Ident.Ident
instance GHC.Classes.Ord Cryptol.Utils.Ident.Ident
instance Data.String.IsString Cryptol.Utils.Ident.Ident
instance Control.DeepSeq.NFData Cryptol.Utils.Ident.Ident
instance Control.DeepSeq.NFData Cryptol.Utils.Ident.MaybeAnon


module Cryptol.Utils.PP

-- | How to pretty print things when evaluating
data PPOpts
PPOpts :: Bool -> Int -> Int -> Int -> PPFloatFormat -> FieldOrder -> PPOpts
[useAscii] :: PPOpts -> Bool
[useBase] :: PPOpts -> Int
[useInfLength] :: PPOpts -> Int
[useFPBase] :: PPOpts -> Int
[useFPFormat] :: PPOpts -> PPFloatFormat
[useFieldOrder] :: PPOpts -> FieldOrder
asciiMode :: PPOpts -> Integer -> Bool
data PPFloatFormat

-- | Use this many significant digis
FloatFixed :: Int -> PPFloatExp -> PPFloatFormat

-- | Show this many digits after floating point
FloatFrac :: Int -> PPFloatFormat

-- | Use the correct number of digits
FloatFree :: PPFloatExp -> PPFloatFormat
data PPFloatExp

-- | Always show an exponent
ForceExponent :: PPFloatExp

-- | Only show exponent when needed
AutoExponent :: PPFloatExp
data FieldOrder
DisplayOrder :: FieldOrder
CanonicalOrder :: FieldOrder
defaultPPOpts :: PPOpts

-- | How to display names, inspired by the GHC <tt>Outputable</tt> module.
--   Getting a value of <a>Nothing</a> from the NameDisp function indicates
--   that the display has no opinion on how this name should be displayed,
--   and some other display should be tried out.
data NameDisp
EmptyNameDisp :: NameDisp
NameDisp :: (OrigName -> Maybe NameFormat) -> NameDisp
data NameFormat
UnQualified :: NameFormat
Qualified :: !ModName -> NameFormat
NotInScope :: NameFormat

-- | Never qualify names from this module.
neverQualifyMod :: ModPath -> NameDisp
neverQualify :: NameDisp

-- | Compose two naming environments, preferring names from the left
--   environment.
extend :: NameDisp -> NameDisp -> NameDisp

-- | Get the format for a name.
getNameFormat :: OrigName -> NameDisp -> NameFormat

-- | Produce a document in the context of the current <a>NameDisp</a>.
withNameDisp :: (NameDisp -> Doc) -> Doc

-- | Produce a document in the context of the current configuration.
withPPCfg :: (PPCfg -> Doc) -> Doc

-- | Fix the way that names are displayed inside of a doc.
fixNameDisp :: NameDisp -> Doc -> Doc

-- | Fix the way that names are displayed inside of a doc.
fixPPCfg :: PPCfg -> Doc -> Doc
updPPCfg :: (PPCfg -> PPCfg) -> Doc -> Doc
debugShowUniques :: Doc -> Doc
data PPCfg
PPCfg :: NameDisp -> Bool -> PPCfg
[ppcfgNameDisp] :: PPCfg -> NameDisp
[ppcfgShowNameUniques] :: PPCfg -> Bool
defaultPPCfg :: PPCfg
newtype Doc
Doc :: (PPCfg -> Doc Void) -> Doc
runDocWith :: PPCfg -> Doc -> Doc Void
runDoc :: NameDisp -> Doc -> Doc Void
renderOneLine :: Doc -> String
class PP a
ppPrec :: PP a => Int -> a -> Doc
class PP a => PPName a

-- | Fixity information for infix operators
ppNameFixity :: PPName a => a -> Maybe Fixity

-- | Print a name in prefix: <tt>f a b</tt> or <tt>(+) a b)</tt>
ppPrefixName :: PPName a => a -> Doc

-- | Print a name as an infix operator: <tt>a + b</tt>
ppInfixName :: PPName a => a -> Doc
pp :: PP a => a -> Doc
pretty :: PP a => a -> String
optParens :: Bool -> Doc -> Doc

-- | Information about an infix expression of some sort.
data Infix op thing
Infix :: op -> thing -> thing -> Fixity -> Infix op thing

-- | operator
[ieOp] :: Infix op thing -> op

-- | left argument
[ieLeft] :: Infix op thing -> thing

-- | right argument
[ieRight] :: Infix op thing -> thing

-- | operator fixity
[ieFixity] :: Infix op thing -> Fixity

-- | Pretty print an infix expression of some sort.
ppInfix :: (PP thing, PP op) => Int -> (thing -> Maybe (Infix op thing)) -> Infix op thing -> Doc

-- | Display a numeric value as an ordinal (e.g., 2nd)
ordinal :: (Integral a, Show a, Eq a) => a -> Doc

-- | The suffix to use when displaying a number as an oridinal
ordSuffix :: (Integral a, Eq a) => a -> String
liftPP :: Doc Void -> Doc
liftPP1 :: (Doc Void -> Doc Void) -> Doc -> Doc
liftPP2 :: (Doc Void -> Doc Void -> Doc Void) -> Doc -> Doc -> Doc
liftSep :: ([Doc Void] -> Doc Void) -> [Doc] -> Doc
reflow :: Text -> Doc
(<.>) :: Doc -> Doc -> Doc
infixl 6 <.>
(<+>) :: Doc -> Doc -> Doc
infixl 6 <+>
(</>) :: Doc -> Doc -> Doc
infixl 6 </>
($$) :: Doc -> Doc -> Doc
infixl 5 $$
sep :: [Doc] -> Doc
fsep :: [Doc] -> Doc
hsep :: [Doc] -> Doc
hcat :: [Doc] -> Doc
vcat :: [Doc] -> Doc
vsep :: [Doc] -> Doc
group :: Doc -> Doc
hang :: Doc -> Int -> Doc -> Doc
nest :: Int -> Doc -> Doc
indent :: Int -> Doc -> Doc
align :: Doc -> Doc
parens :: Doc -> Doc
braces :: Doc -> Doc
brackets :: Doc -> Doc
quotes :: Doc -> Doc
commaSep :: [Doc] -> Doc

-- | Print a comma-separated list. Lay out each item on a single line if it
--   will fit. If an item requires multiple lines, then start it on its own
--   line.
commaSepFill :: [Doc] -> Doc
ppList :: [Doc] -> Doc
ppTuple :: [Doc] -> Doc
ppRecord :: [Doc] -> Doc
backticks :: Doc -> Doc
text :: String -> Doc
char :: Char -> Doc
integer :: Integer -> Doc
int :: Int -> Doc
comma :: Doc
colon :: Doc
pipe :: Doc
instance GHC.Show.Show Cryptol.Utils.PP.PPFloatExp
instance GHC.Show.Show Cryptol.Utils.PP.PPFloatFormat
instance GHC.Show.Show Cryptol.Utils.PP.FieldOrder
instance GHC.Read.Read Cryptol.Utils.PP.FieldOrder
instance GHC.Classes.Ord Cryptol.Utils.PP.FieldOrder
instance GHC.Classes.Eq Cryptol.Utils.PP.FieldOrder
instance GHC.Enum.Enum Cryptol.Utils.PP.FieldOrder
instance GHC.Enum.Bounded Cryptol.Utils.PP.FieldOrder
instance GHC.Show.Show Cryptol.Utils.PP.PPOpts
instance GHC.Show.Show Cryptol.Utils.PP.NameFormat
instance Control.DeepSeq.NFData Cryptol.Utils.PP.NameDisp
instance GHC.Generics.Generic Cryptol.Utils.PP.NameDisp
instance Control.DeepSeq.NFData Cryptol.Utils.PP.Doc
instance GHC.Generics.Generic Cryptol.Utils.PP.Doc
instance Cryptol.Utils.PP.PPName Cryptol.Utils.Ident.ModName
instance Cryptol.Utils.PP.PP Data.Text.Internal.Text
instance Cryptol.Utils.PP.PP Cryptol.Utils.Ident.Ident
instance Cryptol.Utils.PP.PP Cryptol.Utils.Ident.ModName
instance Cryptol.Utils.PP.PP Cryptol.Utils.Fixity.Assoc
instance Cryptol.Utils.PP.PP Cryptol.Utils.Fixity.Fixity
instance Cryptol.Utils.PP.PP Cryptol.Utils.Ident.ModPath
instance Cryptol.Utils.PP.PP Cryptol.Utils.Ident.OrigName
instance Cryptol.Utils.PP.PP Cryptol.Utils.Ident.Namespace
instance Cryptol.Utils.PP.PP Cryptol.Utils.Ident.PrimIdent
instance GHC.Base.Semigroup Cryptol.Utils.PP.Doc
instance GHC.Base.Monoid Cryptol.Utils.PP.Doc
instance GHC.Show.Show Cryptol.Utils.PP.Doc
instance Data.String.IsString Cryptol.Utils.PP.Doc
instance GHC.Show.Show Cryptol.Utils.PP.NameDisp
instance GHC.Base.Semigroup Cryptol.Utils.PP.NameDisp
instance GHC.Base.Monoid Cryptol.Utils.PP.NameDisp


module Cryptol.Utils.Debug
trace :: String -> b -> b
ppTrace :: Doc -> b -> b


module Cryptol.TypeCheck.PP
type NameMap = IntMap String

-- | This packages together a type with some names to be used to display
--   the variables. It is used for pretty printing types.
data WithNames a
WithNames :: a -> NameMap -> WithNames a
emptyNameMap :: NameMap
ppWithNamesPrec :: PP (WithNames a) => NameMap -> Int -> a -> Doc
ppWithNames :: PP (WithNames a) => NameMap -> a -> Doc

-- | Expand a list of base names into an infinite list of variations.
nameList :: [String] -> [String]
dump :: PP (WithNames a) => a -> String

module Cryptol.Parser.Token
data Token
Token :: !TokenT -> !Text -> Token
[tokenType] :: Token -> !TokenT
[tokenText] :: Token -> !Text

-- | Virtual tokens, inserted by layout processing.
data TokenV
VCurlyL :: TokenV
VCurlyR :: TokenV
VSemi :: TokenV
data TokenW
BlockComment :: TokenW
LineComment :: TokenW
Space :: TokenW
DocStr :: TokenW
data TokenKW
KW_else :: TokenKW
KW_fin :: TokenKW
KW_if :: TokenKW
KW_private :: TokenKW
KW_include :: TokenKW
KW_inf :: TokenKW
KW_lg2 :: TokenKW
KW_lengthFromThen :: TokenKW
KW_lengthFromThenTo :: TokenKW
KW_max :: TokenKW
KW_min :: TokenKW
KW_module :: TokenKW
KW_submodule :: TokenKW
KW_newtype :: TokenKW
KW_pragma :: TokenKW
KW_property :: TokenKW
KW_then :: TokenKW
KW_type :: TokenKW
KW_where :: TokenKW
KW_let :: TokenKW
KW_x :: TokenKW
KW_import :: TokenKW
KW_as :: TokenKW
KW_hiding :: TokenKW
KW_infixl :: TokenKW
KW_infixr :: TokenKW
KW_infix :: TokenKW
KW_primitive :: TokenKW
KW_parameter :: TokenKW
KW_constraint :: TokenKW
KW_interface :: TokenKW
KW_foreign :: TokenKW
KW_Prop :: TokenKW
KW_by :: TokenKW
KW_down :: TokenKW

-- | The named operators are a special case for parsing types, and
--   <a>Other</a> is used for all other cases that lexed as an operator.
data TokenOp
Plus :: TokenOp
Minus :: TokenOp
Mul :: TokenOp
Div :: TokenOp
Exp :: TokenOp
Mod :: TokenOp
Equal :: TokenOp
LEQ :: TokenOp
GEQ :: TokenOp
Complement :: TokenOp
Hash :: TokenOp
At :: TokenOp
Other :: [Text] -> Text -> TokenOp
data TokenSym
Bar :: TokenSym
ArrL :: TokenSym
ArrR :: TokenSym
FatArrR :: TokenSym
Lambda :: TokenSym
EqDef :: TokenSym
Comma :: TokenSym
Semi :: TokenSym
Dot :: TokenSym
DotDot :: TokenSym
DotDotDot :: TokenSym
DotDotLt :: TokenSym
DotDotGt :: TokenSym
Colon :: TokenSym
BackTick :: TokenSym
ParenL :: TokenSym
ParenR :: TokenSym
BracketL :: TokenSym
BracketR :: TokenSym
CurlyL :: TokenSym
CurlyR :: TokenSym
TriL :: TokenSym
TriR :: TokenSym
Lt :: TokenSym
Gt :: TokenSym
Underscore :: TokenSym
data TokenErr
UnterminatedComment :: TokenErr
UnterminatedString :: TokenErr
UnterminatedChar :: TokenErr
InvalidString :: TokenErr
InvalidChar :: TokenErr
LexicalError :: TokenErr
MalformedLiteral :: TokenErr
MalformedSelector :: TokenErr
InvalidIndentation :: TokenT -> TokenErr
data SelectorType
RecordSelectorTok :: Text -> SelectorType
TupleSelectorTok :: Int -> SelectorType
data TokenT

-- | value, base, number of digits
Num :: !Integer -> !Int -> !Int -> TokenT

-- | value, base.
Frac :: !Rational -> !Int -> TokenT

-- | character literal
ChrLit :: !Char -> TokenT

-- | (qualified) identifier
Ident :: ![Text] -> !Text -> TokenT

-- | string literal
StrLit :: !String -> TokenT

-- | .hello or .123
Selector :: !SelectorType -> TokenT

-- | keyword
KW :: !TokenKW -> TokenT

-- | operator
Op :: !TokenOp -> TokenT

-- | symbol
Sym :: !TokenSym -> TokenT

-- | virtual token (for layout)
Virt :: !TokenV -> TokenT

-- | white space token
White :: !TokenW -> TokenT

-- | error token
Err :: !TokenErr -> TokenT
EOF :: TokenT
instance Control.DeepSeq.NFData Cryptol.Parser.Token.TokenV
instance GHC.Generics.Generic Cryptol.Parser.Token.TokenV
instance GHC.Show.Show Cryptol.Parser.Token.TokenV
instance GHC.Classes.Eq Cryptol.Parser.Token.TokenV
instance Control.DeepSeq.NFData Cryptol.Parser.Token.TokenW
instance GHC.Generics.Generic Cryptol.Parser.Token.TokenW
instance GHC.Show.Show Cryptol.Parser.Token.TokenW
instance GHC.Classes.Eq Cryptol.Parser.Token.TokenW
instance Control.DeepSeq.NFData Cryptol.Parser.Token.TokenKW
instance GHC.Generics.Generic Cryptol.Parser.Token.TokenKW
instance GHC.Show.Show Cryptol.Parser.Token.TokenKW
instance GHC.Classes.Eq Cryptol.Parser.Token.TokenKW
instance Control.DeepSeq.NFData Cryptol.Parser.Token.TokenOp
instance GHC.Generics.Generic Cryptol.Parser.Token.TokenOp
instance GHC.Show.Show Cryptol.Parser.Token.TokenOp
instance GHC.Classes.Eq Cryptol.Parser.Token.TokenOp
instance Control.DeepSeq.NFData Cryptol.Parser.Token.TokenSym
instance GHC.Generics.Generic Cryptol.Parser.Token.TokenSym
instance GHC.Show.Show Cryptol.Parser.Token.TokenSym
instance GHC.Classes.Eq Cryptol.Parser.Token.TokenSym
instance Control.DeepSeq.NFData Cryptol.Parser.Token.SelectorType
instance GHC.Generics.Generic Cryptol.Parser.Token.SelectorType
instance GHC.Show.Show Cryptol.Parser.Token.SelectorType
instance GHC.Classes.Eq Cryptol.Parser.Token.SelectorType
instance Control.DeepSeq.NFData Cryptol.Parser.Token.TokenErr
instance GHC.Generics.Generic Cryptol.Parser.Token.TokenErr
instance GHC.Show.Show Cryptol.Parser.Token.TokenErr
instance GHC.Classes.Eq Cryptol.Parser.Token.TokenErr
instance Control.DeepSeq.NFData Cryptol.Parser.Token.TokenT
instance GHC.Generics.Generic Cryptol.Parser.Token.TokenT
instance GHC.Show.Show Cryptol.Parser.Token.TokenT
instance GHC.Classes.Eq Cryptol.Parser.Token.TokenT
instance Control.DeepSeq.NFData Cryptol.Parser.Token.Token
instance GHC.Generics.Generic Cryptol.Parser.Token.Token
instance GHC.Show.Show Cryptol.Parser.Token.Token
instance Cryptol.Utils.PP.PP Cryptol.Parser.Token.Token


module Cryptol.Parser.Position
data Located a
Located :: !Range -> !a -> Located a
[srcRange] :: Located a -> !Range
[thing] :: Located a -> !a
data Position
Position :: !Int -> !Int -> Position
[line] :: Position -> !Int
[col] :: Position -> !Int
data Range
Range :: !Position -> !Position -> FilePath -> Range
[from] :: Range -> !Position
[to] :: Range -> !Position
[source] :: Range -> FilePath

-- | Returns <a>True</a> if the first range is contained in the second one.
rangeWithin :: Range -> Range -> Bool

-- | An empty range.
--   
--   Caution: using this on the LHS of a use of rComb will cause the empty
--   source to propagate.
emptyRange :: Range
start :: Position
move :: Position -> Char -> Position
moves :: Position -> Text -> Position
rComb :: Range -> Range -> Range
rCombMaybe :: Maybe Range -> Maybe Range -> Maybe Range
rCombs :: [Range] -> Range
class HasLoc t
getLoc :: HasLoc t => t -> Maybe Range
class HasLoc t => AddLoc t
addLoc :: AddLoc t => t -> Range -> t
dropLoc :: AddLoc t => t -> t
at :: (HasLoc l, AddLoc t) => l -> t -> t
combLoc :: (a -> b -> c) -> Located a -> Located b -> Located c
instance Control.DeepSeq.NFData Cryptol.Parser.Position.Position
instance GHC.Generics.Generic Cryptol.Parser.Position.Position
instance GHC.Show.Show Cryptol.Parser.Position.Position
instance GHC.Classes.Ord Cryptol.Parser.Position.Position
instance GHC.Classes.Eq Cryptol.Parser.Position.Position
instance Control.DeepSeq.NFData Cryptol.Parser.Position.Range
instance GHC.Generics.Generic Cryptol.Parser.Position.Range
instance GHC.Show.Show Cryptol.Parser.Position.Range
instance GHC.Classes.Ord Cryptol.Parser.Position.Range
instance GHC.Classes.Eq Cryptol.Parser.Position.Range
instance Data.Traversable.Traversable Cryptol.Parser.Position.Located
instance Data.Foldable.Foldable Cryptol.Parser.Position.Located
instance GHC.Base.Functor Cryptol.Parser.Position.Located
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Cryptol.Parser.Position.Located a)
instance GHC.Generics.Generic (Cryptol.Parser.Position.Located a)
instance GHC.Show.Show a => GHC.Show.Show (Cryptol.Parser.Position.Located a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Cryptol.Parser.Position.Located a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Cryptol.Parser.Position.Located a)
instance Cryptol.Parser.Position.AddLoc (Cryptol.Parser.Position.Located a)
instance Cryptol.Parser.Position.HasLoc Cryptol.Parser.Position.Range
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.Position.Located a)
instance (Cryptol.Parser.Position.HasLoc a, Cryptol.Parser.Position.HasLoc b) => Cryptol.Parser.Position.HasLoc (a, b)
instance Cryptol.Parser.Position.HasLoc a => Cryptol.Parser.Position.HasLoc [a]
instance Cryptol.Utils.PP.PP a => Cryptol.Utils.PP.PP (Cryptol.Parser.Position.Located a)
instance Cryptol.Utils.PP.PPName a => Cryptol.Utils.PP.PPName (Cryptol.Parser.Position.Located a)
instance Cryptol.Utils.PP.PP Cryptol.Parser.Position.Range
instance Cryptol.Utils.PP.PP Cryptol.Parser.Position.Position


module Cryptol.Parser.Selector

-- | Selectors are used for projecting from various components. Each
--   selector has an option spec to specify the shape of the thing that is
--   being selected. Currently, there is no surface syntax for list
--   selectors, but they are used during the desugaring of patterns.
data Selector

-- | Zero-based tuple selection. Optionally specifies the shape of the
--   tuple (one-based).
TupleSel :: Int -> Maybe Int -> Selector

-- | Record selection. Optionally specifies the shape of the record.
RecordSel :: Ident -> Maybe [Ident] -> Selector

-- | List selection. Optionally specifies the length of the list.
ListSel :: Int -> Maybe Int -> Selector

-- | Display the thing selected by the selector, nicely.
ppSelector :: Selector -> Doc

-- | Show a list of selectors as they appear in a nested selector in an
--   update.
ppNestedSels :: [Selector] -> Doc

-- | The name of a selector (e.g., used in update code)
selName :: Selector -> Ident
instance Control.DeepSeq.NFData Cryptol.Parser.Selector.Selector
instance GHC.Generics.Generic Cryptol.Parser.Selector.Selector
instance GHC.Classes.Ord Cryptol.Parser.Selector.Selector
instance GHC.Show.Show Cryptol.Parser.Selector.Selector
instance GHC.Classes.Eq Cryptol.Parser.Selector.Selector
instance Cryptol.Utils.PP.PP Cryptol.Parser.Selector.Selector


-- | This module defines natural numbers with an additional infinity
--   element, and various arithmetic operators on them.
module Cryptol.TypeCheck.Solver.InfNat

-- | Natural numbers with an infinity element
data Nat'
Nat :: Integer -> Nat'
Inf :: Nat'
fromNat :: Nat' -> Maybe Integer
nAdd :: Nat' -> Nat' -> Nat'

-- | Some algebraic properties of interest:
--   
--   <pre>
--   1 * x = x
--   x * (y * z) = (x * y) * z
--   0 * x = 0
--   x * y = y * x
--   x * (a + b) = x * a + x * b
--   </pre>
nMul :: Nat' -> Nat' -> Nat'

-- | Some algebraic properties of interest:
--   
--   <pre>
--   x ^ 0        = 1
--   x ^ (n + 1)  = x * (x ^ n)
--   x ^ (m + n)  = (x ^ m) * (x ^ n)
--   x ^ (m * n)  = (x ^ m) ^ n
--   </pre>
nExp :: Nat' -> Nat' -> Nat'
nMin :: Nat' -> Nat' -> Nat'
nMax :: Nat' -> Nat' -> Nat'

-- | <tt>nSub x y = Just z</tt> iff <tt>z</tt> is the unique value such
--   that <tt>Add y z = Just x</tt>.
nSub :: Nat' -> Nat' -> Maybe Nat'

-- | Rounds down.
--   
--   <pre>
--   y * q + r = x
--   x / y     = q with remainder r
--   0 &lt;= r &amp;&amp; r &lt; y
--   </pre>
--   
--   We don't allow <a>Inf</a> in the first argument for two reasons: 1. It
--   matches the behavior of <a>nMod</a>, 2. The well-formedness
--   constraints can be expressed as a conjunction.
nDiv :: Nat' -> Nat' -> Maybe Nat'
nMod :: Nat' -> Nat' -> Maybe Nat'

-- | <tt>nCeilDiv msgLen blockSize</tt> computes the least <tt>n</tt> such
--   that <tt>msgLen &lt;= blockSize * n</tt>. It is undefined when
--   <tt>blockSize = 0</tt>, or when <tt>blockSize = inf</tt>. <tt>inf</tt>
--   divided by any positive finite value is <tt>inf</tt>.
nCeilDiv :: Nat' -> Nat' -> Maybe Nat'

-- | <tt>nCeilMod msgLen blockSize</tt> computes the least <tt>k</tt> such
--   that <tt>blockSize</tt> divides <tt>msgLen + k</tt>. It is undefined
--   when <tt>blockSize = 0</tt> or <tt>blockSize = inf</tt>. <tt>inf</tt>
--   modulus any positive finite value is <tt>0</tt>.
nCeilMod :: Nat' -> Nat' -> Maybe Nat'

-- | Rounds up. <tt>lg2 x = y</tt>, iff <tt>y</tt> is the smallest number
--   such that <tt>x &lt;= 2 ^ y</tt>
nLg2 :: Nat' -> Nat'

-- | <tt>nWidth n</tt> is number of bits needed to represent all numbers
--   from 0 to n, inclusive. <tt>nWidth x = nLg2 (x + 1)</tt>.
nWidth :: Nat' -> Nat'

-- | <pre>
--   length [ x, y .. z ]
--   </pre>
nLenFromThenTo :: Nat' -> Nat' -> Nat' -> Maybe Nat'

-- | Compute the logarithm of a number in the given base, rounded down to
--   the closest integer. The boolean indicates if we the result is exact
--   (i.e., True means no rounding happened, False means we rounded down).
--   The logarithm base is the second argument.
genLog :: Integer -> Integer -> Maybe (Integer, Bool)

-- | Compute the number of bits required to represent the given integer.
widthInteger :: Integer -> Integer

-- | Compute the exact root of a natural number. The second argument
--   specifies which root we are computing.
rootExact :: Integer -> Integer -> Maybe Integer

-- | Compute the the n-th root of a natural number, rounded down to the
--   closest natural number. The boolean indicates if the result is exact
--   (i.e., True means no rounding was done, False means rounded down). The
--   second argument specifies which root we are computing.
genRoot :: Integer -> Integer -> Maybe (Integer, Bool)
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Solver.InfNat.Nat'
instance GHC.Generics.Generic Cryptol.TypeCheck.Solver.InfNat.Nat'
instance GHC.Classes.Ord Cryptol.TypeCheck.Solver.InfNat.Nat'
instance GHC.Classes.Eq Cryptol.TypeCheck.Solver.InfNat.Nat'
instance GHC.Show.Show Cryptol.TypeCheck.Solver.InfNat.Nat'

module Cryptol.F2
pmult :: Int -> Integer -> Integer -> Integer
pdiv :: Int -> Integer -> Integer -> Integer
pmod :: Int -> Integer -> Integer -> Integer


module Cryptol.REPL.Trie

-- | Maps string names to values, allowing for partial key matches and
--   querying.
data Trie a
Node :: Map Char (Trie a) -> Maybe a -> Trie a
emptyTrie :: Trie a

-- | Insert a value into the Trie, forcing the key value to lower case.
--   Will call <a>panic</a> if a value already exists with that key.
insertTrie :: String -> a -> Trie a -> Trie a

-- | Return all matches with the given prefix.
lookupTrie :: String -> Trie a -> [a]

-- | Given a key, return either an exact match for that key, or all matches
--   with the given prefix.
lookupTrieExact :: String -> Trie a -> [a]

-- | Return all of the values from a Trie.
leaves :: Trie a -> [a]
instance GHC.Show.Show a => GHC.Show.Show (Cryptol.REPL.Trie.Trie a)


-- | Convert a literate source file into an ordinary source file.
module Cryptol.Parser.Unlit
unLit :: PreProc -> Text -> Text
data PreProc
None :: PreProc
Markdown :: PreProc
LaTeX :: PreProc
RST :: PreProc
guessPreProc :: FilePath -> PreProc
knownExts :: [String]


module Cryptol.Parser.Name

-- | Names that originate in the parser.
data PName

-- | Unqualified names like <tt>x</tt>, <tt>Foo</tt>, or <tt>+</tt>.
UnQual :: !Ident -> PName

-- | Qualified names like <tt>Foo::bar</tt> or <tt>module::!</tt>.
Qual :: !ModName -> !Ident -> PName

-- | Fresh names generated by a pass.
NewName :: !Pass -> !Int -> PName

-- | Passes that can generate fresh names.
data Pass
NoPat :: Pass
MonoValues :: Pass
ExpandPropGuards :: String -> Pass
mkUnqual :: Ident -> PName
mkQual :: ModName -> Ident -> PName
getModName :: PName -> Maybe ModName
getIdent :: PName -> Ident
isGeneratedName :: PName -> Bool
instance GHC.Generics.Generic Cryptol.Parser.Name.Pass
instance GHC.Show.Show Cryptol.Parser.Name.Pass
instance GHC.Classes.Ord Cryptol.Parser.Name.Pass
instance GHC.Classes.Eq Cryptol.Parser.Name.Pass
instance GHC.Generics.Generic Cryptol.Parser.Name.PName
instance GHC.Show.Show Cryptol.Parser.Name.PName
instance GHC.Classes.Ord Cryptol.Parser.Name.PName
instance GHC.Classes.Eq Cryptol.Parser.Name.PName
instance Control.DeepSeq.NFData Cryptol.Parser.Name.PName
instance Cryptol.Utils.PP.PP Cryptol.Parser.Name.PName
instance Cryptol.Utils.PP.PPName Cryptol.Parser.Name.PName
instance Control.DeepSeq.NFData Cryptol.Parser.Name.Pass

module Cryptol.Parser.Layout
layout :: Bool -> [Located Token] -> [Located Token]
data Block

-- | Virtual layout block
Virtual :: Int -> Block

-- | An explicit layout block, expecting this ending token.
Explicit :: TokenT -> Block

-- | These tokens start an implicit layout block
startsLayout :: TokenT -> Bool

-- | These tokens end an implicit layout block
endsLayout :: TokenT -> Bool

-- | These tokens start an explicit "paren" layout block. If so, the result
--   contains the corresponding closing paren.
startsParenBlock :: TokenT -> Maybe TokenT

-- | Make a virtual token of the given type
virt :: Range -> TokenV -> Located Token
errTok :: Range -> TokenErr -> Located Token
instance GHC.Show.Show Cryptol.Parser.Layout.Block


-- | At present Alex generates code with too many warnings.
module Cryptol.Parser.Lexer

-- | Returns the tokens and the last position of the input that we
--   processed. The tokens include whte space tokens.
primLexer :: Config -> Text -> ([Located Token], Position)

-- | Returns the tokens in the last position of the input that we
--   processed. White space is removed, and layout processing is done as
--   requested. This stream is fed to the parser.
lexer :: Config -> Text -> ([Located Token], Position)
data Layout
Layout :: Layout
NoLayout :: Layout
data Token
Token :: !TokenT -> !Text -> Token
[tokenType] :: Token -> !TokenT
[tokenText] :: Token -> !Text
data TokenT

-- | value, base, number of digits
Num :: !Integer -> !Int -> !Int -> TokenT

-- | value, base.
Frac :: !Rational -> !Int -> TokenT

-- | character literal
ChrLit :: !Char -> TokenT

-- | (qualified) identifier
Ident :: ![Text] -> !Text -> TokenT

-- | string literal
StrLit :: !String -> TokenT

-- | .hello or .123
Selector :: !SelectorType -> TokenT

-- | keyword
KW :: !TokenKW -> TokenT

-- | operator
Op :: !TokenOp -> TokenT

-- | symbol
Sym :: !TokenSym -> TokenT

-- | virtual token (for layout)
Virt :: !TokenV -> TokenT

-- | white space token
White :: !TokenW -> TokenT

-- | error token
Err :: !TokenErr -> TokenT
EOF :: TokenT

-- | Virtual tokens, inserted by layout processing.
data TokenV
VCurlyL :: TokenV
VCurlyR :: TokenV
VSemi :: TokenV
data TokenKW
KW_else :: TokenKW
KW_fin :: TokenKW
KW_if :: TokenKW
KW_private :: TokenKW
KW_include :: TokenKW
KW_inf :: TokenKW
KW_lg2 :: TokenKW
KW_lengthFromThen :: TokenKW
KW_lengthFromThenTo :: TokenKW
KW_max :: TokenKW
KW_min :: TokenKW
KW_module :: TokenKW
KW_submodule :: TokenKW
KW_newtype :: TokenKW
KW_pragma :: TokenKW
KW_property :: TokenKW
KW_then :: TokenKW
KW_type :: TokenKW
KW_where :: TokenKW
KW_let :: TokenKW
KW_x :: TokenKW
KW_import :: TokenKW
KW_as :: TokenKW
KW_hiding :: TokenKW
KW_infixl :: TokenKW
KW_infixr :: TokenKW
KW_infix :: TokenKW
KW_primitive :: TokenKW
KW_parameter :: TokenKW
KW_constraint :: TokenKW
KW_interface :: TokenKW
KW_foreign :: TokenKW
KW_Prop :: TokenKW
KW_by :: TokenKW
KW_down :: TokenKW
data TokenErr
UnterminatedComment :: TokenErr
UnterminatedString :: TokenErr
UnterminatedChar :: TokenErr
InvalidString :: TokenErr
InvalidChar :: TokenErr
LexicalError :: TokenErr
MalformedLiteral :: TokenErr
MalformedSelector :: TokenErr
InvalidIndentation :: TokenT -> TokenErr
data TokenSym
Bar :: TokenSym
ArrL :: TokenSym
ArrR :: TokenSym
FatArrR :: TokenSym
Lambda :: TokenSym
EqDef :: TokenSym
Comma :: TokenSym
Semi :: TokenSym
Dot :: TokenSym
DotDot :: TokenSym
DotDotDot :: TokenSym
DotDotLt :: TokenSym
DotDotGt :: TokenSym
Colon :: TokenSym
BackTick :: TokenSym
ParenL :: TokenSym
ParenR :: TokenSym
BracketL :: TokenSym
BracketR :: TokenSym
CurlyL :: TokenSym
CurlyR :: TokenSym
TriL :: TokenSym
TriR :: TokenSym
Lt :: TokenSym
Gt :: TokenSym
Underscore :: TokenSym
data TokenW
BlockComment :: TokenW
LineComment :: TokenW
Space :: TokenW
DocStr :: TokenW
data Located a
Located :: !Range -> !a -> Located a
[srcRange] :: Located a -> !Range
[thing] :: Located a -> !a
data Config
Config :: !FilePath -> !Position -> !Layout -> PreProc -> [FilePath] -> Bool -> Config

-- | File that we are working on
[cfgSource] :: Config -> !FilePath

-- | Starting position for the parser
[cfgStart] :: Config -> !Position

-- | Settings for layout processing
[cfgLayout] :: Config -> !Layout

-- | Preprocessor settings
[cfgPreProc] :: Config -> PreProc

-- | Implicit includes
[cfgAutoInclude] :: Config -> [FilePath]

-- | When we do layout processing should we add a vCurly (i.e., are we
--   parsing a list of things).
[cfgModuleScope] :: Config -> Bool
defaultConfig :: Config
dbgLex :: FilePath -> IO ()


module Cryptol.ModuleSystem.Name
data Name
data NameInfo
GlobalName :: NameSource -> OrigName -> NameInfo
LocalName :: Namespace -> Ident -> NameInfo
data NameSource
SystemName :: NameSource
UserName :: NameSource
nameUnique :: Name -> Int
nameIdent :: Name -> Ident
mapNameIdent :: (Ident -> Ident) -> Name -> Name
nameInfo :: Name -> NameInfo
nameLoc :: Name -> Range
nameFixity :: Name -> Maybe Fixity
nameNamespace :: Name -> Namespace

-- | Primtiives must be in a top level module, at least for now.
asPrim :: Name -> Maybe PrimIdent
asOrigName :: Name -> Maybe OrigName

-- | Get the module path for the given name. The name should be a top-level
--   name.
nameModPath :: Name -> ModPath

-- | Get the module path for the given name.
nameModPathMaybe :: Name -> Maybe ModPath

-- | Get the name of the top-level module that introduced this name. Works
--   only for top-level names (i.e., that have original names)
nameTopModule :: Name -> ModName

-- | Get the name of the top-level module that introduced this name.
nameTopModuleMaybe :: Name -> Maybe ModName

-- | Pretty-print a name with its source location information.
ppLocName :: Name -> Doc

-- | Namespaces for names
data Namespace
NSValue :: Namespace
NSType :: Namespace
NSModule :: Namespace

-- | Idnetifies a possibly nested module
data ModPath
TopModule :: ModName -> ModPath
Nested :: ModPath -> Ident -> ModPath

-- | Compare two names by the way they would be displayed. This is used to
--   order names nicely when showing what's in scope
cmpNameDisplay :: NameDisp -> Name -> Name -> Ordering

-- | Make a new name for a declaration.
mkDeclared :: Namespace -> ModPath -> NameSource -> Ident -> Maybe Fixity -> Range -> Supply -> (Name, Supply)

-- | Make a new parameter name.
mkLocal :: Namespace -> Ident -> Range -> Supply -> (Name, Supply)

-- | Make a local name derived from the given name. This is a bit
--   questionable, but it is used by the translation to SAW Core
asLocal :: Namespace -> Name -> Name
mkModParam :: ModPath -> Ident -> Range -> Name -> Supply -> (Name, Supply)
class Monad m => FreshM m
liftSupply :: FreshM m => (Supply -> (a, Supply)) -> m a

-- | Retrieve the next unique from the supply.
nextUniqueM :: FreshM m => m Int

-- | A monad for easing the use of the supply.
data SupplyT m a
runSupplyT :: Monad m => Supply -> SupplyT m a -> m (a, Supply)
runSupply :: Supply -> (forall m. FreshM m => m a) -> (a, Supply)
data Supply

-- | This should only be used once at library initialization, and threaded
--   through the rest of the session. The supply is started at 0x1000 to
--   leave us plenty of room for names that the compiler needs to know
--   about (wired-in constants).
emptySupply :: Supply
nextUnique :: Supply -> (Int, Supply)

-- | This is used when instantiating functors
freshNameFor :: ModPath -> Name -> Supply -> (Name, Supply)

-- | A mapping from an identifier defined in some module to its real name.
data PrimMap
PrimMap :: Map PrimIdent Name -> Map PrimIdent Name -> PrimMap
[primDecls] :: PrimMap -> Map PrimIdent Name
[primTypes] :: PrimMap -> Map PrimIdent Name

-- | It's assumed that we're looking things up that we know already exist,
--   so this will panic if it doesn't find the name.
lookupPrimDecl :: PrimIdent -> PrimMap -> Name

-- | It's assumed that we're looking things up that we know already exist,
--   so this will panic if it doesn't find the name.
lookupPrimType :: PrimIdent -> PrimMap -> Name
instance GHC.Classes.Eq Cryptol.ModuleSystem.Name.NameSource
instance GHC.Show.Show Cryptol.ModuleSystem.Name.NameSource
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Name.NameSource
instance GHC.Generics.Generic Cryptol.ModuleSystem.Name.NameSource
instance GHC.Show.Show Cryptol.ModuleSystem.Name.NameInfo
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Name.NameInfo
instance GHC.Generics.Generic Cryptol.ModuleSystem.Name.NameInfo
instance GHC.Show.Show Cryptol.ModuleSystem.Name.Name
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Name.Name
instance GHC.Generics.Generic Cryptol.ModuleSystem.Name.Name
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Name.Supply
instance GHC.Generics.Generic Cryptol.ModuleSystem.Name.Supply
instance GHC.Show.Show Cryptol.ModuleSystem.Name.Supply
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Name.PrimMap
instance GHC.Generics.Generic Cryptol.ModuleSystem.Name.PrimMap
instance GHC.Show.Show Cryptol.ModuleSystem.Name.PrimMap
instance GHC.Base.Semigroup Cryptol.ModuleSystem.Name.PrimMap
instance Cryptol.ModuleSystem.Name.FreshM m => Cryptol.ModuleSystem.Name.FreshM (MonadLib.ExceptionT i m)
instance (GHC.Base.Monoid i, Cryptol.ModuleSystem.Name.FreshM m) => Cryptol.ModuleSystem.Name.FreshM (MonadLib.WriterT i m)
instance Cryptol.ModuleSystem.Name.FreshM m => Cryptol.ModuleSystem.Name.FreshM (MonadLib.ReaderT i m)
instance Cryptol.ModuleSystem.Name.FreshM m => Cryptol.ModuleSystem.Name.FreshM (MonadLib.StateT i m)
instance GHC.Base.Monad m => Cryptol.ModuleSystem.Name.FreshM (Cryptol.ModuleSystem.Name.SupplyT m)
instance GHC.Base.Monad m => GHC.Base.Functor (Cryptol.ModuleSystem.Name.SupplyT m)
instance GHC.Base.Monad m => GHC.Base.Applicative (Cryptol.ModuleSystem.Name.SupplyT m)
instance GHC.Base.Monad m => GHC.Base.Monad (Cryptol.ModuleSystem.Name.SupplyT m)
instance MonadLib.MonadT Cryptol.ModuleSystem.Name.SupplyT
instance MonadLib.BaseM m n => MonadLib.BaseM (Cryptol.ModuleSystem.Name.SupplyT m) n
instance MonadLib.RunM m (a, Cryptol.ModuleSystem.Name.Supply) r => MonadLib.RunM (Cryptol.ModuleSystem.Name.SupplyT m) a (Cryptol.ModuleSystem.Name.Supply -> r)
instance GHC.Classes.Eq Cryptol.ModuleSystem.Name.Name
instance GHC.Classes.Ord Cryptol.ModuleSystem.Name.Name
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Name.Name
instance Cryptol.Utils.PP.PPName Cryptol.ModuleSystem.Name.Name

module Cryptol.TypeCheck.TCon

-- | This is used for pretty prinitng. XXX: it would be nice to just rely
--   in the info from the Prelude.
infixPrimTy :: TCon -> Maybe (Ident, Fixity)
builtInType :: Name -> Maybe TCon

-- | Kinds, classify types.
data Kind
KType :: Kind
KNum :: Kind
KProp :: Kind
(:->) :: Kind -> Kind -> Kind
infixr 5 :->
class HasKind t
kindOf :: HasKind t => t -> Kind

-- | Type constants.
data TCon
TC :: TC -> TCon
PC :: PC -> TCon
TF :: TFun -> TCon
TError :: Kind -> TCon

-- | Predicate symbols. If you add additional user-visible constructors,
--   please update <tt>primTys</tt>.
data PC

-- | <pre>
--   _ == _
--   </pre>
PEqual :: PC

-- | <pre>
--   _ /= _
--   </pre>
PNeq :: PC

-- | <pre>
--   _ &gt;= _
--   </pre>
PGeq :: PC

-- | <pre>
--   fin _
--   </pre>
PFin :: PC

-- | <pre>
--   prime _
--   </pre>
PPrime :: PC

-- | <tt>Has sel type field</tt> does not appear in schemas
PHas :: Selector -> PC

-- | <pre>
--   Zero _
--   </pre>
PZero :: PC

-- | <pre>
--   Logic _
--   </pre>
PLogic :: PC

-- | <pre>
--   Ring _
--   </pre>
PRing :: PC

-- | <pre>
--   Integral _
--   </pre>
PIntegral :: PC

-- | <pre>
--   Field _
--   </pre>
PField :: PC

-- | <pre>
--   Round _
--   </pre>
PRound :: PC

-- | <pre>
--   Eq _
--   </pre>
PEq :: PC

-- | <pre>
--   Cmp _
--   </pre>
PCmp :: PC

-- | <pre>
--   SignedCmp _
--   </pre>
PSignedCmp :: PC

-- | <pre>
--   Literal _ _
--   </pre>
PLiteral :: PC

-- | <pre>
--   LiteralLessThan _ _
--   </pre>
PLiteralLessThan :: PC

-- | <pre>
--   FLiteral _ _ _
--   </pre>
PFLiteral :: PC

-- | <tt>ValidFloat _ _</tt> constraints on supported floating point
--   representaitons
PValidFloat :: PC

-- | This is useful when simplifying things in place
PAnd :: PC

-- | Ditto
PTrue :: PC

-- | 1-1 constants. If you add additional user-visible constructors, please
--   update <tt>primTys</tt>.
data TC

-- | Numbers
TCNum :: Integer -> TC

-- | Inf
TCInf :: TC

-- | Bit
TCBit :: TC

-- | Integer
TCInteger :: TC

-- | Float
TCFloat :: TC

-- | <pre>
--   Z _
--   </pre>
TCIntMod :: TC

-- | <pre>
--   Rational
--   </pre>
TCRational :: TC

-- | <pre>
--   Array _ _
--   </pre>
TCArray :: TC

-- | <pre>
--   [_] _
--   </pre>
TCSeq :: TC

-- | <pre>
--   _ -&gt; _
--   </pre>
TCFun :: TC

-- | <pre>
--   (_, _, _)
--   </pre>
TCTuple :: Int -> TC

-- | An abstract type
TCAbstract :: UserTC -> TC
data UserTC
UserTC :: Name -> Kind -> UserTC

-- | Built-in type functions. If you add additional user-visible
--   constructors, please update <tt>primTys</tt> in
--   <a>Cryptol.Prims.Types</a>.
data TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCAdd :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCSub :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCMul :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCDiv :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCMod :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCExp :: TFun

-- | <pre>
--   : Num -&gt; Num
--   </pre>
TCWidth :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCMin :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCMax :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCCeilDiv :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCCeilMod :: TFun

-- | <tt> : Num -&gt; Num -&gt; Num -&gt; Num</tt> Example: <tt>[ 1, 5 .. 9
--   ] :: [lengthFromThenTo 1 5 9][b]</tt>
TCLenFromThenTo :: TFun
instance Control.DeepSeq.NFData Cryptol.TypeCheck.TCon.Kind
instance GHC.Generics.Generic Cryptol.TypeCheck.TCon.Kind
instance GHC.Show.Show Cryptol.TypeCheck.TCon.Kind
instance GHC.Classes.Ord Cryptol.TypeCheck.TCon.Kind
instance GHC.Classes.Eq Cryptol.TypeCheck.TCon.Kind
instance Control.DeepSeq.NFData Cryptol.TypeCheck.TCon.PC
instance GHC.Generics.Generic Cryptol.TypeCheck.TCon.PC
instance GHC.Classes.Ord Cryptol.TypeCheck.TCon.PC
instance GHC.Classes.Eq Cryptol.TypeCheck.TCon.PC
instance GHC.Show.Show Cryptol.TypeCheck.TCon.PC
instance Control.DeepSeq.NFData Cryptol.TypeCheck.TCon.UserTC
instance GHC.Generics.Generic Cryptol.TypeCheck.TCon.UserTC
instance GHC.Show.Show Cryptol.TypeCheck.TCon.UserTC
instance Control.DeepSeq.NFData Cryptol.TypeCheck.TCon.TC
instance GHC.Generics.Generic Cryptol.TypeCheck.TCon.TC
instance GHC.Classes.Ord Cryptol.TypeCheck.TCon.TC
instance GHC.Classes.Eq Cryptol.TypeCheck.TCon.TC
instance GHC.Show.Show Cryptol.TypeCheck.TCon.TC
instance Control.DeepSeq.NFData Cryptol.TypeCheck.TCon.TFun
instance GHC.Generics.Generic Cryptol.TypeCheck.TCon.TFun
instance GHC.Enum.Enum Cryptol.TypeCheck.TCon.TFun
instance GHC.Enum.Bounded Cryptol.TypeCheck.TCon.TFun
instance GHC.Classes.Ord Cryptol.TypeCheck.TCon.TFun
instance GHC.Classes.Eq Cryptol.TypeCheck.TCon.TFun
instance GHC.Show.Show Cryptol.TypeCheck.TCon.TFun
instance Control.DeepSeq.NFData Cryptol.TypeCheck.TCon.TCon
instance GHC.Generics.Generic Cryptol.TypeCheck.TCon.TCon
instance GHC.Classes.Ord Cryptol.TypeCheck.TCon.TCon
instance GHC.Classes.Eq Cryptol.TypeCheck.TCon.TCon
instance GHC.Show.Show Cryptol.TypeCheck.TCon.TCon
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.TCon.TCon
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.TCon.TCon
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.TCon.TFun
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.TCon.TFun
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.TCon.TC
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.TCon.TC
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.TCon.UserTC
instance GHC.Classes.Eq Cryptol.TypeCheck.TCon.UserTC
instance GHC.Classes.Ord Cryptol.TypeCheck.TCon.UserTC
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.TCon.UserTC
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.TCon.PC
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.TCon.PC
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.TCon.Kind

module Cryptol.ModuleSystem.Names

-- | A non-empty collection of names used by the renamer.
data Names
One :: Name -> Names

-- | Non-empty
Ambig :: Set Name -> Names
namesToList :: Names -> [Name]
anyOne :: Names -> Name
namesFromSet :: Set Name -> Names
unionManyNames :: [Names] -> Maybe Names
mapNames :: (Name -> Name) -> Names -> Names
filterNames :: (Name -> Bool) -> Names -> Maybe Names
travNames :: Applicative f => (Name -> f Name) -> Names -> f Names
diffNames :: Names -> Names -> Maybe Names
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Names.Names
instance GHC.Generics.Generic Cryptol.ModuleSystem.Names.Names
instance GHC.Show.Show Cryptol.ModuleSystem.Names.Names
instance GHC.Base.Semigroup Cryptol.ModuleSystem.Names.Names


-- | Errors from dynamic loading of shared libraries for FFI.
module Cryptol.Backend.FFI.Error
data FFILoadError
CantLoadFFISrc :: FilePath -> String -> FFILoadError
CantLoadFFIImpl :: String -> String -> FFILoadError
FFIDuplicates :: [Name] -> FFILoadError
FFIInFunctor :: Name -> FFILoadError
instance Control.DeepSeq.NFData Cryptol.Backend.FFI.Error.FFILoadError
instance GHC.Generics.Generic Cryptol.Backend.FFI.Error.FFILoadError
instance GHC.Show.Show Cryptol.Backend.FFI.Error.FFILoadError
instance Cryptol.Utils.PP.PP Cryptol.Backend.FFI.Error.FFILoadError


-- | The implementation of loading and calling external functions from
--   shared libraries.
module Cryptol.Backend.FFI

-- | A source from which we can retrieve implementations of foreign
--   functions.
data ForeignSrc

-- | Get the file path of the <a>ForeignSrc</a>.
getForeignSrcPath :: ForeignSrc -> Maybe FilePath

-- | Load a <a>ForeignSrc</a> for the given <b>Cryptol</b> file path. The
--   file path of the shared library that we try to load is the same as the
--   Cryptol file path except with a platform specific extension.
loadForeignSrc :: FilePath -> IO (Either FFILoadError ForeignSrc)

-- | Explicitly unload a <a>ForeignSrc</a> immediately instead of waiting
--   for the garbage collector to do it. This can be useful if you want to
--   immediately load the same library again to pick up new changes.
--   
--   The <a>ForeignSrc</a> <b>must not</b> be used in any way after this is
--   called, including calling <a>ForeignImpl</a>s loaded from it.
unloadForeignSrc :: ForeignSrc -> IO ()

-- | Given the path to a Cryptol module, compute the location of the shared
--   library we'd like to load.
foreignLibPath :: FilePath -> IO (Maybe FilePath)

-- | An implementation of a foreign function.
data ForeignImpl

-- | Load a <a>ForeignImpl</a> with the given name from the given
--   <a>ForeignSrc</a>.
loadForeignImpl :: ForeignSrc -> String -> IO (Either FFILoadError ForeignImpl)

-- | Types which can be converted into libffi arguments.
--   
--   The Storable constraint is so that we can put them in arrays.
class Storable a => FFIArg a

-- | Types which can be returned from libffi.
--   
--   The Storable constraint is so that we can put them in arrays.
class Storable a => FFIRet a

-- | Existential wrapper around a <a>FFIArg</a>.
data SomeFFIArg
SomeFFIArg :: a -> SomeFFIArg

-- | Call a <a>ForeignImpl</a> with the given arguments. The type parameter
--   decides how the return value should be converted into a Haskell value.
callForeignImpl :: forall a. FFIRet a => ForeignImpl -> [SomeFFIArg] -> IO a
instance Cryptol.Backend.FFI.FFIRet GHC.Word.Word8
instance Cryptol.Backend.FFI.FFIRet GHC.Word.Word16
instance Cryptol.Backend.FFI.FFIRet GHC.Word.Word32
instance Cryptol.Backend.FFI.FFIRet GHC.Word.Word64
instance Cryptol.Backend.FFI.FFIRet Foreign.C.Types.CFloat
instance Cryptol.Backend.FFI.FFIRet Foreign.C.Types.CDouble
instance Cryptol.Backend.FFI.FFIRet ()
instance Cryptol.Backend.FFI.FFIArg GHC.Word.Word8
instance Cryptol.Backend.FFI.FFIArg GHC.Word.Word16
instance Cryptol.Backend.FFI.FFIArg GHC.Word.Word32
instance Cryptol.Backend.FFI.FFIArg GHC.Word.Word64
instance Cryptol.Backend.FFI.FFIArg Foreign.C.Types.CFloat
instance Cryptol.Backend.FFI.FFIArg Foreign.C.Types.CDouble
instance Cryptol.Backend.FFI.FFIArg (GHC.Ptr.Ptr a)
instance Cryptol.Backend.FFI.FFIArg Foreign.C.Types.CSize
instance GHC.Show.Show Cryptol.Backend.FFI.ForeignSrc
instance Control.DeepSeq.NFData Cryptol.Backend.FFI.ForeignSrc

module Cryptol.Utils.Patterns
newtype Match b
Match :: (forall r. r -> (b -> r) -> r) -> Match b
type Pat a b = a -> Match b
(|||) :: Pat a b -> Pat a b -> Pat a b

-- | Check that a value satisfies multiple patterns. For example, an "as"
--   pattern is <tt>(__ &amp;&amp;&amp; p)</tt>.
(&&&) :: Pat a b -> Pat a c -> Pat a (b, c)

-- | Match a value, and modify the result.
(~>) :: Pat a b -> (b -> c) -> Pat a c

-- | Match a value, and return the given result
(~~>) :: Pat a b -> c -> Pat a c

-- | View pattern.
(<~) :: (a -> b) -> Pat b c -> Pat a c

-- | Variable pattern.
__ :: Pat a a

-- | Constant pattern.
succeed :: a -> Pat x a

-- | Predicate pattern
checkThat :: (a -> Bool) -> Pat a ()

-- | Check for exact value.
lit :: Eq a => a -> Pat a ()

-- | Match a pattern, using the given default if valure.
matchDefault :: a -> Match a -> a

-- | Match an irrefutable pattern. Crashes on faliure.
match :: Match a -> a
matchMaybe :: Match a -> Maybe a
list :: [Pat a b] -> Pat [a] [b]
(><) :: Pat a b -> Pat x y -> Pat (a, x) (b, y)
class Matches thing pats res | pats -> thing res
matches :: Matches thing pats res => thing -> pats -> Match res
instance (f GHC.Types.~ Cryptol.Utils.Patterns.Pat a a1', a1 GHC.Types.~ Cryptol.Utils.Patterns.Pat a1' r1) => Cryptol.Utils.Patterns.Matches a (f, a1) r1
instance (op GHC.Types.~ Cryptol.Utils.Patterns.Pat a (a1', a2'), a1 GHC.Types.~ Cryptol.Utils.Patterns.Pat a1' r1, a2 GHC.Types.~ Cryptol.Utils.Patterns.Pat a2' r2) => Cryptol.Utils.Patterns.Matches a (op, a1, a2) (r1, r2)
instance (op GHC.Types.~ Cryptol.Utils.Patterns.Pat a (a1', a2', a3'), a1 GHC.Types.~ Cryptol.Utils.Patterns.Pat a1' r1, a2 GHC.Types.~ Cryptol.Utils.Patterns.Pat a2' r2, a3 GHC.Types.~ Cryptol.Utils.Patterns.Pat a3' r3) => Cryptol.Utils.Patterns.Matches a (op, a1, a2, a3) (r1, r2, r3)
instance GHC.Base.Functor Cryptol.Utils.Patterns.Match
instance GHC.Base.Applicative Cryptol.Utils.Patterns.Match
instance GHC.Base.Monad Cryptol.Utils.Patterns.Match
instance Control.Monad.Fail.MonadFail Cryptol.Utils.Patterns.Match
instance GHC.Base.Alternative Cryptol.Utils.Patterns.Match
instance GHC.Base.MonadPlus Cryptol.Utils.Patterns.Match


-- | This module implements an "order insensitive" datastructure for record
--   types and values. For most purposes, we want to deal with record
--   fields in a canonical order; but for user interaction purposes, we
--   generally want to display the fields in the order they were specified
--   by the user (in source files, at the REPL, etc.).
module Cryptol.Utils.RecordMap

-- | An "order insensitive" datastructure. The fields can be accessed
--   either according to a "canonical" order, or based on a "display"
--   order, which matches the order in which the fields were originally
--   specified.
data RecordMap a b

-- | The order in which the fields originally appeared.
displayOrder :: RecordMap a b -> [a]

-- | Return a list of field/value pairs in canonical order.
canonicalFields :: RecordMap a b -> [(a, b)]

-- | Return a list of field/value pairs in display order.
displayFields :: (Show a, Ord a) => RecordMap a b -> [(a, b)]

-- | Retrieve the elements of the record in canonical order of the field
--   names
recordElements :: RecordMap a b -> [b]

-- | Retrieve the elements of the record in display order of the field
--   names.
displayElements :: (Show a, Ord a) => RecordMap a b -> [b]

-- | Return the fields in this record as a set.
fieldSet :: Ord a => RecordMap a b -> Set a

-- | Generate a record from a list of field/value pairs. Precondition: each
--   field identifier appears at most once in the given list.
recordFromFields :: (Show a, Ord a) => [(a, b)] -> RecordMap a b

-- | Generate a record from a list of field/value pairs. If any field name
--   is repeated, the first repeated name/value pair is returned. Otherwise
--   the constructed record is returned.
recordFromFieldsErr :: (Show a, Ord a) => [(a, b)] -> Either (a, b) (RecordMap a b)

-- | Generate a record from a list of field/value pairs, and also provide
--   the "display" order for the fields directly. Precondition: each field
--   identifier appears at most once in each list, and a field name appears
--   in the display order iff it appears in the field list.
recordFromFieldsWithDisplay :: (Show a, Ord a) => [a] -> [(a, b)] -> RecordMap a b

-- | Lookup the value of a field
lookupField :: Ord a => a -> RecordMap a b -> Maybe b

-- | Update the value of a field by applying the given function. If the
--   field is not present in the record, return Nothing.
adjustField :: forall a b. Ord a => a -> (b -> b) -> RecordMap a b -> Maybe (RecordMap a b)

-- | Traverse the elements of the given record map in canonical order,
--   applying the given action.
traverseRecordMap :: Applicative t => (a -> b -> t c) -> RecordMap a b -> t (RecordMap a c)

-- | Apply the given function to each element of a record.
mapWithFieldName :: (a -> b -> c) -> RecordMap a b -> RecordMap a c

-- | Zip together the fields of two records using the provided action. If
--   some field is present in one record, but not the other, an <tt>Either
--   a a</tt> will be returned, indicating which record is missing the
--   field, and returning the name of the missing field.
--   
--   The <tt>displayOrder</tt> of the resulting record will be taken from
--   the first argument (rather arbitrarily).
zipRecordsM :: forall t a b c d. (Ord a, Monad t) => (a -> b -> c -> t d) -> RecordMap a b -> RecordMap a c -> t (Either (Either a a) (RecordMap a d))

-- | Pure version of <a>zipRecordsM</a>
zipRecords :: forall a b c d. Ord a => (a -> b -> c -> d) -> RecordMap a b -> RecordMap a c -> Either (Either a a) (RecordMap a d)

-- | The function recordMapAccum threads an accumulating argument through
--   the map in canonical order of fields.
recordMapAccum :: (a -> b -> (a, c)) -> a -> RecordMap k b -> (a, RecordMap k c)
instance (GHC.Classes.Ord a, GHC.Classes.Eq b) => GHC.Classes.Eq (Cryptol.Utils.RecordMap.RecordMap a b)
instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (Cryptol.Utils.RecordMap.RecordMap a b)
instance (GHC.Show.Show a, GHC.Classes.Ord a, GHC.Show.Show b) => GHC.Show.Show (Cryptol.Utils.RecordMap.RecordMap a b)
instance (Control.DeepSeq.NFData a, Control.DeepSeq.NFData b) => Control.DeepSeq.NFData (Cryptol.Utils.RecordMap.RecordMap a b)
instance GHC.Base.Functor (Cryptol.Utils.RecordMap.RecordMap a)
instance Data.Foldable.Foldable (Cryptol.Utils.RecordMap.RecordMap a)
instance Data.Traversable.Traversable (Cryptol.Utils.RecordMap.RecordMap a)


module Cryptol.Parser.AST

-- | The type of identifiers. * The boolean flag indicates whether or not
--   they're infix operators. The boolean is present just as cached
--   information from the lexer, and never used during comparisons. * The
--   MaybeAnon indicates if this is an anonymous name
data Ident

-- | Make a normal (i.e., not anonymous) identifier
mkIdent :: Text -> Ident
mkInfix :: Text -> Ident
isInfixIdent :: Ident -> Bool
nullIdent :: Ident -> Bool
identText :: Ident -> Text

-- | Top-level Module names are just text.
data ModName
modRange :: Module name -> Range

-- | Names that originate in the parser.
data PName

-- | Unqualified names like <tt>x</tt>, <tt>Foo</tt>, or <tt>+</tt>.
UnQual :: !Ident -> PName

-- | Qualified names like <tt>Foo::bar</tt> or <tt>module::!</tt>.
Qual :: !ModName -> !Ident -> PName

-- | Fresh names generated by a pass.
NewName :: !Pass -> !Int -> PName
getModName :: PName -> Maybe ModName
getIdent :: PName -> Ident
mkUnqual :: Ident -> PName
mkQual :: ModName -> Ident -> PName
data Named a
Named :: Located Ident -> a -> Named a
[name] :: Named a -> Located Ident
[value] :: Named a -> a

-- | Passes that can generate fresh names.
data Pass
NoPat :: Pass
MonoValues :: Pass
ExpandPropGuards :: String -> Pass

-- | Information about associativity.
data Assoc
LeftAssoc :: Assoc
RightAssoc :: Assoc
NonAssoc :: Assoc
data Schema n
Forall :: [TParam n] -> [Prop n] -> Type n -> Maybe Range -> Schema n
data TParam n
TParam :: n -> Maybe Kind -> Maybe Range -> TParam n
[tpName] :: TParam n -> n
[tpKind] :: TParam n -> Maybe Kind
[tpRange] :: TParam n -> Maybe Range
data Kind
KProp :: Kind
KNum :: Kind
KType :: Kind
KFun :: Kind -> Kind -> Kind
data Type n

-- | <pre>
--   [8] -&gt; [8]
--   </pre>
TFun :: Type n -> Type n -> Type n

-- | <pre>
--   [8] a
--   </pre>
TSeq :: Type n -> Type n -> Type n

-- | <pre>
--   Bit
--   </pre>
TBit :: Type n

-- | <pre>
--   10
--   </pre>
TNum :: Integer -> Type n

-- | <pre>
--   <tt>a</tt>
--   </pre>
TChar :: Char -> Type n

-- | A type variable or synonym
TUser :: n -> [Type n] -> Type n

-- | <pre>
--   `{ x = [8], y = Integer }
--   </pre>
TTyApp :: [Named (Type n)] -> Type n

-- | <pre>
--   { x : [8], y : [32] }
--   </pre>
TRecord :: Rec (Type n) -> Type n

-- | <pre>
--   ([8], [32])
--   </pre>
TTuple :: [Type n] -> Type n

-- | <tt>_</tt>, just some type.
TWild :: Type n

-- | Location information
TLocated :: Type n -> Range -> Type n

-- | <pre>
--   (ty)
--   </pre>
TParens :: Type n -> Maybe Kind -> Type n

-- | <pre>
--   ty + ty
--   </pre>
TInfix :: Type n -> Located n -> Fixity -> Type n -> Type n

-- | A <a>Prop</a> is a <a>Type</a> that represents a type constraint.
newtype Prop n
CType :: Type n -> Prop n
tsName :: TySyn name -> Located name
psName :: PropSyn name -> Located name
tsFixity :: TySyn name -> Maybe Fixity
psFixity :: PropSyn name -> Maybe Fixity

-- | A top-level module
type Module = ModuleG ModName

-- | A module for the pre-typechecker phasese. The two parameters are:
--   
--   <ul>
--   <li><tt>mname</tt> the type of module names. This is because top-level
--   and nested modules use differnt types to identify a module.</li>
--   <li><tt>name</tt> the type of identifiers used by declarations. In the
--   parser this starts off as <a>PName</a> and after resolving names in
--   the renamer, this becomes <tt>Name</tt>.</li>
--   </ul>
data ModuleG mname name
Module :: Located mname -> ModuleDefinition name -> ModuleG mname name

-- | Name of the module
[mName] :: ModuleG mname name -> Located mname
[mDef] :: ModuleG mname name -> ModuleDefinition name
mDecls :: ModuleG mname name -> [TopDecl name]

-- | Imports of top-level (i.e. "file" based) modules.
mImports :: ModuleG mname name -> [Located Import]

-- | Get the module parameters of a module (new module system)
mModParams :: ModuleG mname name -> [ModParam name]
mIsFunctor :: ModuleG mname nmae -> Bool
isParamDecl :: TopDecl a -> Bool

-- | Different flavours of module we have.
data ModuleDefinition name
NormalModule :: [TopDecl name] -> ModuleDefinition name

-- | The instance is filled in by the renamer
FunctorInstance :: Located (ImpName name) -> ModuleInstanceArgs name -> ModuleInstance name -> ModuleDefinition name
InterfaceModule :: Signature name -> ModuleDefinition name

-- | All arguments in a functor instantiation
data ModuleInstanceArgs name

-- | Single parameter instantitaion
DefaultInstArg :: Located (ModuleInstanceArg name) -> ModuleInstanceArgs name

-- | Single parameter instantitaion using this anonymous module. (parser
--   only)
DefaultInstAnonArg :: [TopDecl name] -> ModuleInstanceArgs name
NamedInstArgs :: [ModuleInstanceNamedArg name] -> ModuleInstanceArgs name

-- | A named argument in a functor instantiation
data ModuleInstanceNamedArg name
ModuleInstanceNamedArg :: Located Ident -> Located (ModuleInstanceArg name) -> ModuleInstanceNamedArg name

-- | An argument in a functor instantiation
data ModuleInstanceArg name

-- | An argument that is a module
ModuleArg :: ImpName name -> ModuleInstanceArg name

-- | An argument that is a parameter
ParameterArg :: Ident -> ModuleInstanceArg name

-- | Arguments adds extra parameters to decls. ("backtick" import)
AddParams :: ModuleInstanceArg name

-- | Maps names in the original functor with names in the instnace. Does
--   *NOT* include the parameters, just names for the definitions. This
--   *DOES* include entrirs for all the name in the instantiated functor,
--   including names in modules nested inside the functor.
type ModuleInstance name = Map name name
emptyModuleInstance :: Ord name => ModuleInstance name
newtype Program name
Program :: [TopDecl name] -> Program name

-- | A declaration that may only appear at the top level of a module. The
--   module may be nested, however.
data TopDecl name
Decl :: TopLevel (Decl name) -> TopDecl name
DPrimType :: TopLevel (PrimType name) -> TopDecl name

-- | @newtype T as = t
TDNewtype :: TopLevel (Newtype name) -> TopDecl name

-- | <tt>include File</tt> (until NoInclude)
Include :: Located FilePath -> TopDecl name

-- | <tt>parameter ...</tt> (parser only)
DParamDecl :: Range -> Signature name -> TopDecl name

-- | <pre>
--   submodule M where ...
--   </pre>
DModule :: TopLevel (NestedModule name) -> TopDecl name

-- | <pre>
--   import X
--   </pre>
DImport :: Located (ImportG (ImpName name)) -> TopDecl name

-- | <pre>
--   import interface X ...
--   </pre>
DModParam :: ModParam name -> TopDecl name

-- | <pre>
--   interface constraint
--   </pre>
DInterfaceConstraint :: Maybe Text -> Located [Prop name] -> TopDecl name

-- | A simple declaration. Generally these are things that can appear both
--   at the top-level of a module and in `where` clauses.
data Decl name

-- | A type signature. Eliminated in NoPat--after NoPat signatures are in
--   their associated Bind
DSignature :: [Located name] -> Schema name -> Decl name

-- | A fixity declaration. Eliminated in NoPat---after NoPat fixities are
--   in their associated Bind
DFixity :: !Fixity -> [Located name] -> Decl name

-- | A pragma declaration. Eliminated in NoPat---after NoPat fixities are
--   in their associated Bind
DPragma :: [Located name] -> Pragma -> Decl name

-- | A non-recursive binding.
DBind :: Bind name -> Decl name

-- | A group of recursive bindings. Introduced by the renamer.
DRec :: [Bind name] -> Decl name

-- | A pattern binding. Eliminated in NoPat---after NoPat fixities are in
--   their associated Bind
DPatBind :: Pattern name -> Expr name -> Decl name

-- | A type synonym.
DType :: TySyn name -> Decl name

-- | A constraint synonym.
DProp :: PropSyn name -> Decl name

-- | Keeps track of the location of a declaration.
DLocated :: Decl name -> Range -> Decl name
data Fixity
Fixity :: !Assoc -> !Int -> Fixity
[fAssoc] :: Fixity -> !Assoc
[fLevel] :: Fixity -> !Int

-- | The fixity used when none is provided.
defaultFixity :: Fixity
data FixityCmp
FCError :: FixityCmp
FCLeft :: FixityCmp
FCRight :: FixityCmp

-- | Let <tt>op1</tt> have fixity <tt>f1</tt> and <tt>op2</tt> have fixity
--   <tt>f2. Then </tt>compareFixity f1 f2<tt> determines how to parse the
--   infix expression </tt>x op1 y op2 z@.
--   
--   <ul>
--   <li><tt>FCLeft</tt>: <tt>(x op1 y) op2 z</tt></li>
--   <li><tt>FCRight</tt>: <tt>x op1 (y op2 z)</tt></li>
--   <li><tt>FCError</tt>: no parse</li>
--   </ul>
compareFixity :: Fixity -> Fixity -> FixityCmp
data TySyn n
TySyn :: Located n -> Maybe Fixity -> [TParam n] -> Type n -> TySyn n
data PropSyn n
PropSyn :: Located n -> Maybe Fixity -> [TParam n] -> [Prop n] -> PropSyn n

-- | Bindings. Notes:
--   
--   <ul>
--   <li>The parser does not associate type signatures and pragmas with
--   their bindings: this is done in a separate pass, after de-sugaring
--   pattern bindings. In this way we can associate pragmas and type
--   signatures with the variables defined by pattern bindings as
--   well.</li>
--   <li>Currently, there is no surface syntax for defining monomorphic
--   bindings (i.e., bindings that will not be automatically generalized by
--   the type checker. However, they are useful when de-sugaring
--   patterns.</li>
--   </ul>
data Bind name
Bind :: Located name -> [Pattern name] -> Located (BindDef name) -> Maybe (Schema name) -> Bool -> Maybe Fixity -> [Pragma] -> Bool -> Maybe Text -> !ExportType -> Bind name

-- | Defined thing
[bName] :: Bind name -> Located name

-- | Parameters
[bParams] :: Bind name -> [Pattern name]

-- | Definition
[bDef] :: Bind name -> Located (BindDef name)

-- | Optional type sig
[bSignature] :: Bind name -> Maybe (Schema name)

-- | Infix operator?
[bInfix] :: Bind name -> Bool

-- | Optional fixity info
[bFixity] :: Bind name -> Maybe Fixity

-- | Optional pragmas
[bPragmas] :: Bind name -> [Pragma]

-- | Is this a monomorphic binding
[bMono] :: Bind name -> Bool

-- | Optional doc string
[bDoc] :: Bind name -> Maybe Text
[bExport] :: Bind name -> !ExportType
data BindDef name
DPrim :: BindDef name
DForeign :: BindDef name
DExpr :: Expr name -> BindDef name
DPropGuards :: [PropGuardCase name] -> BindDef name
type LBindDef = Located (BindDef PName)
data Pragma
PragmaNote :: String -> Pragma
PragmaProperty :: Pragma

-- | Export information for a declaration.
data ExportType
Public :: ExportType
Private :: ExportType

-- | A top-level module declaration.
data TopLevel a
TopLevel :: ExportType -> Maybe (Located Text) -> a -> TopLevel a
[tlExport] :: TopLevel a -> ExportType
[tlDoc] :: TopLevel a -> Maybe (Located Text)
[tlValue] :: TopLevel a -> a
type Import = ImportG ModName

-- | An import declaration.
data ImportG mname
Import :: !mname -> Maybe ModName -> Maybe ImportSpec -> !Maybe (ModuleInstanceArgs PName) -> ImportG mname
[iModule] :: ImportG mname -> !mname
[iAs] :: ImportG mname -> Maybe ModName
[iSpec] :: ImportG mname -> Maybe ImportSpec

-- | <a>iInst</a> exists only during parsing
[iInst] :: ImportG mname -> !Maybe (ModuleInstanceArgs PName)

-- | The list of names following an import.
data ImportSpec
Hiding :: [Ident] -> ImportSpec
Only :: [Ident] -> ImportSpec

-- | The name of an imported module
data ImpName name

-- | A top-level module
ImpTop :: ModName -> ImpName name

-- | The module in scope with the given name
ImpNested :: name -> ImpName name
data Newtype name
Newtype :: Located name -> [TParam name] -> !name -> Rec (Type name) -> Newtype name

-- | Type name
[nName] :: Newtype name -> Located name

-- | Type params
[nParams] :: Newtype name -> [TParam name]

-- | Constructor function name
[nConName] :: Newtype name -> !name

-- | Body
[nBody] :: Newtype name -> Rec (Type name)

-- | A declaration for a type with no implementation.
data PrimType name
PrimType :: Located name -> Located Kind -> ([TParam name], [Prop name]) -> Maybe Fixity -> PrimType name
[primTName] :: PrimType name -> Located name
[primTKind] :: PrimType name -> Located Kind

-- | parameters are in the order used by the type constructor.
[primTCts] :: PrimType name -> ([TParam name], [Prop name])
[primTFixity] :: PrimType name -> Maybe Fixity

-- | A type parameter for a module.
data ParameterType name
ParameterType :: Located name -> Kind -> Maybe Text -> Maybe Fixity -> !Int -> ParameterType name

-- | name of type parameter
[ptName] :: ParameterType name -> Located name

-- | kind of parameter
[ptKind] :: ParameterType name -> Kind

-- | optional documentation
[ptDoc] :: ParameterType name -> Maybe Text

-- | info for infix use
[ptFixity] :: ParameterType name -> Maybe Fixity

-- | number of the parameter
[ptNumber] :: ParameterType name -> !Int

-- | A value parameter for a module.
data ParameterFun name
ParameterFun :: Located name -> Schema name -> Maybe Text -> Maybe Fixity -> ParameterFun name

-- | name of value parameter
[pfName] :: ParameterFun name -> Located name

-- | schema for parameter
[pfSchema] :: ParameterFun name -> Schema name

-- | optional documentation
[pfDoc] :: ParameterFun name -> Maybe Text

-- | info for infix use
[pfFixity] :: ParameterFun name -> Maybe Fixity

-- | A nested module.
newtype NestedModule name
NestedModule :: ModuleG name name -> NestedModule name

-- | Interface Modules (aka types of functor arguments)
--   
--   IMPORTANT: Interface Modules are a language construct and are
--   different from the notion of "interface" in the Cryptol
--   implementation.
--   
--   Note that the names *defined* in an interface module are only really
--   used in the other members of the interface module. When an interface
--   module is "imported" as a functor parameter these names are
--   instantiated to new names, because there could be multiple paramers
--   using the same interface.
data Signature name
Signature :: ![Located (ImportG (ImpName name))] -> [ParameterType name] -> [Located (Prop name)] -> [SigDecl name] -> [ParameterFun name] -> Signature name

-- | Add things in scope
[sigImports] :: Signature name -> ![Located (ImportG (ImpName name))]

-- | Type parameters
[sigTypeParams] :: Signature name -> [ParameterType name]

-- | Constraints on the type parameters and type synonyms.
[sigConstraints] :: Signature name -> [Located (Prop name)]

-- | Type and constraint synonyms
[sigDecls] :: Signature name -> [SigDecl name]

-- | Value parameters
[sigFunParams] :: Signature name -> [ParameterFun name]

-- | A constraint or type synonym declared in an interface.
data SigDecl name
SigTySyn :: TySyn name -> Maybe Text -> SigDecl name
SigPropSyn :: PropSyn name -> Maybe Text -> SigDecl name

-- | A module parameter declaration.
--   
--   <pre>
--   import interface A
--   import interface A as B
--   </pre>
--   
--   The name of the parameter is derived from the <tt>as</tt> clause. If
--   there is no <tt>as</tt> clause then it is derived from the name of the
--   interface module.
--   
--   If there is no <tt>as</tt> clause, then the type/value parameters are
--   unqualified, and otherwise they are qualified.
data ModParam name
ModParam :: Located (ImpName name) -> Maybe ModName -> !Ident -> Maybe (Located Text) -> !Map name name -> ModParam name

-- | Signature for parameter
[mpSignature] :: ModParam name -> Located (ImpName name)

-- | Qualified for actual params
[mpAs] :: ModParam name -> Maybe ModName

-- | Parameter name (for inst.) Note that this is not resolved in the
--   renamer, and is only used when instantiating a functor.
[mpName] :: ModParam name -> !Ident

-- | Optional documentation
[mpDoc] :: ModParam name -> Maybe (Located Text)

-- | Filled in by the renamer. Maps the actual (value/type) parameter names
--   to the names in the interface module.
[mpRenaming] :: ModParam name -> !Map name name

-- | Things that maybe appear in an interface/parameter block. These only
--   exist during parsering.
data ParamDecl name

-- | <tt>parameter type T : #</tt> (parser only)
DParameterType :: ParameterType name -> ParamDecl name

-- | <tt>parameter someVal : [256]</tt> (parser only)
DParameterFun :: ParameterFun name -> ParamDecl name

-- | A delcaration in an interface
DParameterDecl :: SigDecl name -> ParamDecl name

-- | <pre>
--   parameter type constraint (fin T)
--   </pre>
DParameterConstraint :: [Located (Prop name)] -> ParamDecl name
data PropGuardCase name
PropGuardCase :: [Located (Prop name)] -> Expr name -> PropGuardCase name
[pgcProps] :: PropGuardCase name -> [Located (Prop name)]
[pgcExpr] :: PropGuardCase name -> Expr name

-- | Input at the REPL, which can be an expression, a <tt>let</tt>
--   statement, or empty (possibly a comment).
data ReplInput name
ExprInput :: Expr name -> ReplInput name
LetInput :: [Decl name] -> ReplInput name
EmptyInput :: ReplInput name
data Expr n

-- | <pre>
--   x
--   </pre>
EVar :: n -> Expr n

-- | <pre>
--   0x10
--   </pre>
ELit :: Literal -> Expr n

-- | <pre>
--   generate f
--   </pre>
EGenerate :: Expr n -> Expr n

-- | <pre>
--   (1,2,3)
--   </pre>
ETuple :: [Expr n] -> Expr n

-- | <pre>
--   { x = 1, y = 2 }
--   </pre>
ERecord :: Rec (Expr n) -> Expr n

-- | <pre>
--   e.l
--   </pre>
ESel :: Expr n -> Selector -> Expr n

-- | <pre>
--   { r | x = e }
--   </pre>
EUpd :: Maybe (Expr n) -> [UpdField n] -> Expr n

-- | <pre>
--   [1,2,3]
--   </pre>
EList :: [Expr n] -> Expr n

-- | <pre>
--   [1, 5 .. 117 : t]
--   </pre>
EFromTo :: Type n -> Maybe (Type n) -> Type n -> Maybe (Type n) -> Expr n

-- | <pre>
--   [1 .. 10 by 2 : t ]
--   </pre>
EFromToBy :: Bool -> Type n -> Type n -> Type n -> Maybe (Type n) -> Expr n

-- | <pre>
--   [10 .. 1 down by 2 : t ]
--   </pre>
EFromToDownBy :: Bool -> Type n -> Type n -> Type n -> Maybe (Type n) -> Expr n

-- | <pre>
--   [ 1 .. &lt; 10 : t ]
--   </pre>
EFromToLessThan :: Type n -> Type n -> Maybe (Type n) -> Expr n
EInfFrom :: Expr n -> Maybe (Expr n) -> Expr n

-- | <pre>
--   [ 1 | x &lt;- xs ]
--   </pre>
EComp :: Expr n -> [[Match n]] -> Expr n

-- | <pre>
--   f x
--   </pre>
EApp :: Expr n -> Expr n -> Expr n

-- | <pre>
--   f `{x = 8}, f`{8}
--   </pre>
EAppT :: Expr n -> [TypeInst n] -> Expr n

-- | <pre>
--   if ok then e1 else e2
--   </pre>
EIf :: Expr n -> Expr n -> Expr n -> Expr n

-- | <pre>
--   1 + x where { x = 2 }
--   </pre>
EWhere :: Expr n -> [Decl n] -> Expr n

-- | <pre>
--   1 : [8]
--   </pre>
ETyped :: Expr n -> Type n -> Expr n

-- | <tt> `(x + 1)</tt>, <tt>x</tt> is a type
ETypeVal :: Type n -> Expr n

-- | <pre>
--   \x y -&gt; x
--   </pre>
EFun :: FunDesc n -> [Pattern n] -> Expr n -> Expr n

-- | position annotation
ELocated :: Expr n -> Range -> Expr n

-- | <tt> splitAt x </tt> (Introduced by NoPat)
ESplit :: Expr n -> Expr n

-- | <tt> (e) </tt> (Removed by Fixity)
EParens :: Expr n -> Expr n
EInfix :: Expr n -> Located n -> Fixity -> Expr n -> Expr n

-- | <pre>
--   -1, ~1
--   </pre>
EPrefix :: PrefixOp -> Expr n -> Expr n

-- | Literals.
data Literal

-- | <tt>0x10</tt> (HexLit 2)
ECNum :: Integer -> NumInfo -> Literal

-- | <pre>
--   <tt>a</tt>
--   </pre>
ECChar :: Char -> Literal

-- | <pre>
--   1.2e3
--   </pre>
ECFrac :: Rational -> FracInfo -> Literal

-- | <pre>
--   "hello"
--   </pre>
ECString :: String -> Literal

-- | Infromation about the representation of a numeric constant.
data NumInfo

-- | n-digit binary literal
BinLit :: Text -> Int -> NumInfo

-- | n-digit octal literal
OctLit :: Text -> Int -> NumInfo

-- | overloaded decimal literal
DecLit :: Text -> NumInfo

-- | n-digit hex literal
HexLit :: Text -> Int -> NumInfo

-- | polynomial literal
PolyLit :: Int -> NumInfo

-- | Information about fractional literals.
data FracInfo
BinFrac :: Text -> FracInfo
OctFrac :: Text -> FracInfo
DecFrac :: Text -> FracInfo
HexFrac :: Text -> FracInfo
data Match name

-- | p &lt;- e
Match :: Pattern name -> Expr name -> Match name
MatchLet :: Bind name -> Match name
data Pattern n

-- | <pre>
--   x
--   </pre>
PVar :: Located n -> Pattern n

-- | <pre>
--   _
--   </pre>
PWild :: Pattern n

-- | <pre>
--   (x,y,z)
--   </pre>
PTuple :: [Pattern n] -> Pattern n

-- | <pre>
--   { x = (a,b,c), y = z }
--   </pre>
PRecord :: Rec (Pattern n) -> Pattern n

-- | <pre>
--   [ x, y, z ]
--   </pre>
PList :: [Pattern n] -> Pattern n

-- | <pre>
--   x : [8]
--   </pre>
PTyped :: Pattern n -> Type n -> Pattern n
PSplit :: Pattern n -> Pattern n -> Pattern n

-- | Location information
PLocated :: Pattern n -> Range -> Pattern n

-- | Selectors are used for projecting from various components. Each
--   selector has an option spec to specify the shape of the thing that is
--   being selected. Currently, there is no surface syntax for list
--   selectors, but they are used during the desugaring of patterns.
data Selector

-- | Zero-based tuple selection. Optionally specifies the shape of the
--   tuple (one-based).
TupleSel :: Int -> Maybe Int -> Selector

-- | Record selection. Optionally specifies the shape of the record.
RecordSel :: Ident -> Maybe [Ident] -> Selector

-- | List selection. Optionally specifies the length of the list.
ListSel :: Int -> Maybe Int -> Selector
data TypeInst name
NamedInst :: Named (Type name) -> TypeInst name
PosInst :: Type name -> TypeInst name
data UpdField n

-- | non-empty list <tt> x.y = e</tt>
UpdField :: UpdHow -> [Located Selector] -> Expr n -> UpdField n
data UpdHow
UpdSet :: UpdHow

-- | Are we setting or updating a field.
UpdFun :: UpdHow

-- | Description of functions. Only trivial information is provided here by
--   the parser. The NoPat pass fills this in as required.
data FunDesc n
FunDesc :: Maybe n -> Int -> FunDesc n

-- | Name of this function, if it has one
[funDescrName] :: FunDesc n -> Maybe n

-- | number of previous arguments to this function bound in surrounding
--   lambdas (defaults to 0)
[funDescrArgOffset] :: FunDesc n -> Int
emptyFunDesc :: FunDesc n

-- | Prefix operator.
data PrefixOp

-- | <pre>
--   -
--   </pre>
PrefixNeg :: PrefixOp

-- | <pre>
--   ~
--   </pre>
PrefixComplement :: PrefixOp
prefixFixity :: PrefixOp -> Fixity
asEApps :: Expr n -> (Expr n, [Expr n])
data Located a
Located :: !Range -> !a -> Located a
[srcRange] :: Located a -> !Range
[thing] :: Located a -> !a

-- | A name with location information.
type LPName = Located PName

-- | A string with location information.
type LString = Located String

-- | An identifier with location information.
type LIdent = Located Ident
class NoPos t
noPos :: NoPos t => t -> t

-- | <a>Conversational</a> printing of kinds (e.g., to use in error
--   messages)
cppKind :: Kind -> Doc

-- | Display the thing selected by the selector, nicely.
ppSelector :: Selector -> Doc
instance GHC.Classes.Ord name => GHC.Classes.Ord (Cryptol.Parser.AST.ImpName name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.ImpName name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ImpName name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ImpName name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ImpName name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ModuleInstanceArg name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ModuleInstanceArg name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ModuleInstanceArg name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ModuleInstanceNamedArg name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ModuleInstanceNamedArg name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ModuleInstanceNamedArg name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ModParam name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ModParam name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ModParam name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.ModParam name)
instance Control.DeepSeq.NFData Cryptol.Parser.AST.ImportSpec
instance GHC.Generics.Generic Cryptol.Parser.AST.ImportSpec
instance GHC.Show.Show Cryptol.Parser.AST.ImportSpec
instance GHC.Classes.Eq Cryptol.Parser.AST.ImportSpec
instance Control.DeepSeq.NFData Cryptol.Parser.AST.Pragma
instance GHC.Generics.Generic Cryptol.Parser.AST.Pragma
instance GHC.Show.Show Cryptol.Parser.AST.Pragma
instance GHC.Classes.Eq Cryptol.Parser.AST.Pragma
instance Control.DeepSeq.NFData Cryptol.Parser.AST.ExportType
instance GHC.Generics.Generic Cryptol.Parser.AST.ExportType
instance GHC.Classes.Ord Cryptol.Parser.AST.ExportType
instance GHC.Show.Show Cryptol.Parser.AST.ExportType
instance GHC.Classes.Eq Cryptol.Parser.AST.ExportType
instance Data.Traversable.Traversable Cryptol.Parser.AST.TopLevel
instance Data.Foldable.Foldable Cryptol.Parser.AST.TopLevel
instance GHC.Base.Functor Cryptol.Parser.AST.TopLevel
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Cryptol.Parser.AST.TopLevel a)
instance GHC.Generics.Generic (Cryptol.Parser.AST.TopLevel a)
instance GHC.Show.Show a => GHC.Show.Show (Cryptol.Parser.AST.TopLevel a)
instance Control.DeepSeq.NFData Cryptol.Parser.AST.NumInfo
instance GHC.Generics.Generic Cryptol.Parser.AST.NumInfo
instance GHC.Show.Show Cryptol.Parser.AST.NumInfo
instance GHC.Classes.Eq Cryptol.Parser.AST.NumInfo
instance Control.DeepSeq.NFData Cryptol.Parser.AST.FracInfo
instance GHC.Generics.Generic Cryptol.Parser.AST.FracInfo
instance GHC.Show.Show Cryptol.Parser.AST.FracInfo
instance GHC.Classes.Eq Cryptol.Parser.AST.FracInfo
instance Control.DeepSeq.NFData Cryptol.Parser.AST.Literal
instance GHC.Generics.Generic Cryptol.Parser.AST.Literal
instance GHC.Show.Show Cryptol.Parser.AST.Literal
instance GHC.Classes.Eq Cryptol.Parser.AST.Literal
instance Control.DeepSeq.NFData Cryptol.Parser.AST.PrefixOp
instance GHC.Generics.Generic Cryptol.Parser.AST.PrefixOp
instance GHC.Show.Show Cryptol.Parser.AST.PrefixOp
instance GHC.Classes.Eq Cryptol.Parser.AST.PrefixOp
instance GHC.Base.Functor Cryptol.Parser.AST.FunDesc
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.FunDesc n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.FunDesc n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.FunDesc n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.FunDesc n)
instance Control.DeepSeq.NFData Cryptol.Parser.AST.UpdHow
instance GHC.Generics.Generic Cryptol.Parser.AST.UpdHow
instance GHC.Show.Show Cryptol.Parser.AST.UpdHow
instance GHC.Classes.Eq Cryptol.Parser.AST.UpdHow
instance GHC.Base.Functor Cryptol.Parser.AST.Named
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Cryptol.Parser.AST.Named a)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Named a)
instance Data.Traversable.Traversable Cryptol.Parser.AST.Named
instance Data.Foldable.Foldable Cryptol.Parser.AST.Named
instance GHC.Show.Show a => GHC.Show.Show (Cryptol.Parser.AST.Named a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Cryptol.Parser.AST.Named a)
instance Control.DeepSeq.NFData Cryptol.Parser.AST.Kind
instance GHC.Generics.Generic Cryptol.Parser.AST.Kind
instance GHC.Show.Show Cryptol.Parser.AST.Kind
instance GHC.Classes.Eq Cryptol.Parser.AST.Kind
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ParameterType name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ParameterType name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ParameterType name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.ParameterType name)
instance GHC.Base.Functor Cryptol.Parser.AST.TParam
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.TParam n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.TParam n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.TParam n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.TParam n)
instance GHC.Base.Functor Cryptol.Parser.AST.Type
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.Type n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Type n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.Type n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.Type n)
instance GHC.Base.Functor Cryptol.Parser.AST.Pattern
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.Pattern n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Pattern n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.Pattern n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.Pattern n)
instance GHC.Base.Functor Cryptol.Parser.AST.TypeInst
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.TypeInst name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.TypeInst name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.TypeInst name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.TypeInst name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.Newtype name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Newtype name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.Newtype name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.Newtype name)
instance GHC.Base.Functor Cryptol.Parser.AST.TySyn
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.TySyn n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.TySyn n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.TySyn n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.TySyn n)
instance GHC.Base.Functor Cryptol.Parser.AST.Prop
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.Prop n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Prop n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.Prop n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.Prop n)
instance GHC.Base.Functor Cryptol.Parser.AST.Schema
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.Schema n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Schema n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.Schema n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.Schema n)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ParameterFun name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ParameterFun name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ParameterFun name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.ParameterFun name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.PrimType name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.PrimType name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.PrimType name)
instance GHC.Base.Functor Cryptol.Parser.AST.PropSyn
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.PropSyn n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.PropSyn n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.PropSyn n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.PropSyn n)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.SigDecl name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.SigDecl name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.SigDecl name)
instance GHC.Base.Functor Cryptol.Parser.AST.UpdField
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.UpdField n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.UpdField n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.UpdField n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.UpdField n)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.PropGuardCase name)
instance GHC.Base.Functor Cryptol.Parser.AST.PropGuardCase
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.PropGuardCase name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.PropGuardCase name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.PropGuardCase name)
instance GHC.Base.Functor Cryptol.Parser.AST.BindDef
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.BindDef name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.BindDef name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.BindDef name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.BindDef name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.Bind name)
instance GHC.Base.Functor Cryptol.Parser.AST.Bind
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.Bind name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Bind name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.Bind name)
instance GHC.Base.Functor Cryptol.Parser.AST.Match
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.Match name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Match name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.Match name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.Match name)
instance GHC.Base.Functor Cryptol.Parser.AST.Expr
instance Control.DeepSeq.NFData n => Control.DeepSeq.NFData (Cryptol.Parser.AST.Expr n)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Expr n)
instance GHC.Show.Show n => GHC.Show.Show (Cryptol.Parser.AST.Expr n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Cryptol.Parser.AST.Expr n)
instance GHC.Base.Functor Cryptol.Parser.AST.Decl
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.Decl name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Decl name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.Decl name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.Decl name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ReplInput name)
instance GHC.Classes.Eq name => GHC.Classes.Eq (Cryptol.Parser.AST.ReplInput name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ParamDecl name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ParamDecl name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ParamDecl name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ModuleDefinition name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ModuleDefinition name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ModuleDefinition name)
instance (Control.DeepSeq.NFData mname, Control.DeepSeq.NFData name) => Control.DeepSeq.NFData (Cryptol.Parser.AST.ModuleG mname name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ModuleG mname name)
instance (GHC.Show.Show mname, GHC.Show.Show name) => GHC.Show.Show (Cryptol.Parser.AST.ModuleG mname name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.NestedModule name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.NestedModule name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.NestedModule name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.Signature name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.Signature name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.Signature name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.ModuleInstanceArgs name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ModuleInstanceArgs name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.ModuleInstanceArgs name)
instance Control.DeepSeq.NFData mname => Control.DeepSeq.NFData (Cryptol.Parser.AST.ImportG mname)
instance GHC.Generics.Generic (Cryptol.Parser.AST.ImportG mname)
instance GHC.Show.Show mname => GHC.Show.Show (Cryptol.Parser.AST.ImportG mname)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.Parser.AST.TopDecl name)
instance GHC.Generics.Generic (Cryptol.Parser.AST.TopDecl name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.TopDecl name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.Parser.AST.Program name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.Position.Located t)
instance Cryptol.Parser.AST.NoPos t => Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Named t)
instance Cryptol.Parser.AST.NoPos Cryptol.Parser.Position.Range
instance Cryptol.Parser.AST.NoPos t => Cryptol.Parser.AST.NoPos [t]
instance Cryptol.Parser.AST.NoPos t => Cryptol.Parser.AST.NoPos (GHC.Maybe.Maybe t)
instance (Cryptol.Parser.AST.NoPos a, Cryptol.Parser.AST.NoPos b) => Cryptol.Parser.AST.NoPos (a, b)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Program name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.ModuleG mname name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.ModuleDefinition name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.ModuleInstanceArgs name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.ModuleInstanceNamedArg name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.NestedModule name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.TopDecl name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.ParamDecl name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Signature name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.SigDecl name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.ModParam name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.PrimType name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.ParameterType name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.ParameterFun x)
instance Cryptol.Parser.AST.NoPos a => Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.TopLevel a)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Decl name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Newtype name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Bind name)
instance Cryptol.Parser.AST.NoPos Cryptol.Parser.AST.Pragma
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.TySyn name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.PropSyn name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Expr name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.UpdField name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.TypeInst name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Match name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Pattern name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Schema name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.TParam name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Type name)
instance Cryptol.Parser.AST.NoPos (Cryptol.Parser.AST.Prop name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Program name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.TopDecl name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.ModuleG mname name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.NestedModule name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName mname, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ModuleG mname name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.NestedModule name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ModuleDefinition name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ModuleInstanceArgs name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.TopDecl name)
instance Cryptol.Utils.PP.PP mname => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ImportG mname)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.ParamDecl name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ParamDecl name)
instance Cryptol.Parser.Position.AddLoc (Cryptol.Parser.AST.Expr n)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Expr name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Bind name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Match name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Decl name)
instance Cryptol.Parser.Position.AddLoc (Cryptol.Parser.AST.Decl name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Decl name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Bind name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.BindDef name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Expr name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.UpdField name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Match name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.SigDecl name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.SigDecl name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.PropSyn name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.PropSyn name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.PrimType name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.PrimType name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.ParameterFun name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ParameterFun name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Schema name)
instance Cryptol.Parser.Position.AddLoc (Cryptol.Parser.AST.Schema name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Schema name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Prop name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP [Cryptol.Parser.AST.Prop name]
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.TySyn name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.TySyn name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Newtype name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Newtype name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.TypeInst name)
instance Cryptol.Parser.Position.AddLoc (Cryptol.Parser.AST.Pattern name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Pattern name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Pattern name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Type name)
instance Cryptol.Parser.Position.AddLoc (Cryptol.Parser.AST.Type name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.Type name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.TParam name)
instance Cryptol.Parser.Position.AddLoc (Cryptol.Parser.AST.TParam name)
instance Cryptol.Utils.PP.PPName name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.TParam name)
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.ParameterType name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ParameterType name)
instance Cryptol.Utils.PP.PP Cryptol.Parser.AST.Kind
instance Cryptol.Parser.Position.HasLoc a => Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.Named a)
instance Cryptol.Utils.PP.PP Cryptol.Parser.AST.UpdHow
instance Cryptol.Utils.PP.PP Cryptol.Parser.AST.Literal
instance Cryptol.Parser.Position.HasLoc a => Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.TopLevel a)
instance Cryptol.Utils.PP.PP a => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.TopLevel a)
instance Cryptol.Utils.PP.PP Cryptol.Parser.AST.Pragma
instance Cryptol.Utils.PP.PP Cryptol.Parser.AST.ImportSpec
instance Cryptol.Parser.Position.HasLoc (Cryptol.Parser.AST.ModParam name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ModParam name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ModuleInstanceNamedArg name)
instance (GHC.Show.Show name, Cryptol.Utils.PP.PPName name) => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ModuleInstanceArg name)
instance Cryptol.Utils.PP.PP name => Cryptol.Utils.PP.PP (Cryptol.Parser.AST.ImpName name)


-- | This module contains types related to typechecking and the output of
--   the typechecker. In particular, it should contain the types needed by
--   interface files (see <a>Interface</a>), which are (kind of) the output
--   of the typechker.
module Cryptol.TypeCheck.Type

-- | The internal representation of types. These are assumed to be kind
--   correct.
data Type

-- | Type constant with args
TCon :: !TCon -> ![Type] -> Type

-- | Type variable (free or bound)
TVar :: TVar -> Type

-- | This is just a type annotation, for a type that was written as a type
--   synonym. It is useful so that we can use it to report nicer errors.
--   Example: <tt>TUser T ts t</tt> is really just the type <tt>t</tt> that
--   was written as <tt>T ts</tt> by the user.
TUser :: !Name -> ![Type] -> !Type -> Type

-- | Record type
TRec :: !RecordMap Ident Type -> Type

-- | A newtype
TNewtype :: !Newtype -> ![Type] -> Type

-- | Type variables.
data TVar

-- | Unique, kind, ids of bound type variables that are in scope. The last
--   field gives us some info for nicer warnings/errors.
TVFree :: !Int -> Kind -> Set TParam -> TVarInfo -> TVar
TVBound :: {-# UNPACK #-} !TParam -> TVar
data ArgDescr
ArgDescr :: Maybe Name -> Maybe Int -> ArgDescr
[argDescrFun] :: ArgDescr -> Maybe Name
[argDescrNumber] :: ArgDescr -> Maybe Int

-- | The types of polymorphic values.
data Schema
Forall :: [TParam] -> [Prop] -> Type -> Schema
[sVars] :: Schema -> [TParam]
[sProps] :: Schema -> [Prop]
[sType] :: Schema -> Type

-- | Type parameters.
data TParam
TParam :: !Int -> Kind -> TPFlavor -> !TVarInfo -> TParam

-- | Parameter identifier
[tpUnique] :: TParam -> !Int

-- | Kind of parameter
[tpKind] :: TParam -> Kind

-- | What sort of type parameter is this
[tpFlav] :: TParam -> TPFlavor

-- | A description for better messages.
[tpInfo] :: TParam -> !TVarInfo

-- | The type is supposed to be of kind <a>KProp</a>.
type Prop = Type

-- | Type synonym.
data TySyn
TySyn :: Name -> [TParam] -> [Prop] -> Type -> !Maybe Text -> TySyn

-- | Name
[tsName] :: TySyn -> Name

-- | Parameters
[tsParams] :: TySyn -> [TParam]

-- | Ensure body is OK
[tsConstraints] :: TySyn -> [Prop]

-- | Definition
[tsDef] :: TySyn -> Type

-- | Documentation
[tsDoc] :: TySyn -> !Maybe Text

-- | Named records
data Newtype
Newtype :: Name -> [TParam] -> [Prop] -> !Name -> RecordMap Ident Type -> Maybe Text -> Newtype
[ntName] :: Newtype -> Name
[ntParams] :: Newtype -> [TParam]
[ntConstraints] :: Newtype -> [Prop]
[ntConName] :: Newtype -> !Name
[ntFields] :: Newtype -> RecordMap Ident Type
[ntDoc] :: Newtype -> Maybe Text

-- | A module parameter. Corresponds to a "signature import". A single
--   module parameter can bring multiple things in scope.
data ModParam
ModParam :: Ident -> !Maybe ModName -> ImpName Name -> ModParamNames -> ModParam

-- | The name of a functor parameter.
[mpName] :: ModParam -> Ident

-- | This is the qualifier for the parameter. We use it to derive parameter
--   names when doing `_` imports.
[mpQual] :: ModParam -> !Maybe ModName

-- | The interface corresponding to this parameter. This is thing in
--   `import interface`
[mpIface] :: ModParam -> ImpName Name

-- | These are the actual parameters, not the ones in the interface For
--   example if the same interface is used for multiple parameters the
--   <tt>ifmpParameters</tt> would all be different.
[mpParameters] :: ModParam -> ModParamNames

-- | Information about the names brought in through an "interface import".
--   This is also used to keep information about.
data ModParamNames
ModParamNames :: Map Name ModTParam -> !Map Name TySyn -> [Located Prop] -> Map Name ModVParam -> !Maybe Text -> ModParamNames

-- | Type parameters
[mpnTypes] :: ModParamNames -> Map Name ModTParam

-- | Type synonyms
[mpnTySyn] :: ModParamNames -> !Map Name TySyn

-- | Constraints on param. types
[mpnConstraints] :: ModParamNames -> [Located Prop]

-- | Value parameters
[mpnFuns] :: ModParamNames -> Map Name ModVParam

-- | Documentation about the interface.
[mpnDoc] :: ModParamNames -> !Maybe Text
class FVS t
fvs :: FVS t => t -> Set TVar
type FunctorParams = Map Ident ModParam

-- | A type parameter of a module.
data ModTParam
ModTParam :: Name -> Kind -> Maybe Text -> ModTParam
[mtpName] :: ModTParam -> Name
[mtpKind] :: ModTParam -> Kind
[mtpDoc] :: ModTParam -> Maybe Text

-- | A value parameter of a module.
data ModVParam
ModVParam :: Name -> Schema -> Maybe Text -> Maybe Fixity -> ModVParam
[mvpName] :: ModVParam -> Name
[mvpType] :: ModVParam -> Schema
[mvpDoc] :: ModVParam -> Maybe Text
[mvpFixity] :: ModVParam -> Maybe Fixity
data TVarInfo
TVarInfo :: !Range -> !TypeSource -> TVarInfo

-- | Source code that gave rise
[tvarSource] :: TVarInfo -> !Range

-- | Description
[tvarDesc] :: TVarInfo -> !TypeSource
data TPFlavor
TPModParam :: Name -> TPFlavor
TPUnifyVar :: TPFlavor
TPSchemaParam :: Name -> TPFlavor
TPTySynParam :: Name -> TPFlavor
TPPropSynParam :: Name -> TPFlavor
TPNewtypeParam :: Name -> TPFlavor
TPPrimParam :: Name -> TPFlavor

-- | Explains how this type came to be, for better error messages.
data TypeSource

-- | Name of module parameter
TVFromModParam :: Name -> TypeSource

-- | A variable in a signature
TVFromSignature :: Name -> TypeSource
TypeWildCard :: TypeSource
TypeOfRecordField :: Ident -> TypeSource
TypeOfTupleField :: Int -> TypeSource
TypeOfSeqElement :: TypeSource
LenOfSeq :: TypeSource
TypeParamInstNamed :: Name -> Ident -> TypeSource
TypeParamInstPos :: Name -> Int -> TypeSource
DefinitionOf :: Name -> TypeSource
LenOfCompGen :: TypeSource
TypeOfArg :: ArgDescr -> TypeSource
TypeOfRes :: TypeSource
FunApp :: TypeSource
TypeOfIfCondExpr :: TypeSource
TypeFromUserAnnotation :: TypeSource
GeneratorOfListComp :: TypeSource
TypeErrorPlaceHolder :: TypeSource

-- | A type annotated with information on how it came about.
data TypeWithSource
WithSource :: Type -> TypeSource -> !Maybe Range -> TypeWithSource
[twsType] :: TypeWithSource -> Type
[twsSource] :: TypeWithSource -> TypeSource
[twsRange] :: TypeWithSource -> !Maybe Range

-- | Information about an abstract type.
data AbstractType
AbstractType :: Name -> Kind -> ([TParam], [Prop]) -> Maybe Fixity -> Maybe Text -> AbstractType
[atName] :: AbstractType -> Name
[atKind] :: AbstractType -> Kind
[atCtrs] :: AbstractType -> ([TParam], [Prop])
[atFixitiy] :: AbstractType -> Maybe Fixity
[atDoc] :: AbstractType -> Maybe Text

-- | The type is "simple" (i.e., it contains no type functions).
type SType = Type

-- | Find the abstract types mentioned in a type.
class FreeAbstract t
freeAbstract :: FreeAbstract t => t -> Set UserTC
tArray :: Type -> Type -> Type
tSub :: Type -> Type -> Type
tMul :: Type -> Type -> Type
tDiv :: Type -> Type -> Type
tMod :: Type -> Type -> Type
tExp :: Type -> Type -> Type
tMin :: Type -> Type -> Type
tCeilDiv :: Type -> Type -> Type
tCeilMod :: Type -> Type -> Type
tLenFromThenTo :: Type -> Type -> Type -> Type
tpName :: TParam -> Maybe Name

-- | Equality for numeric types.
(=#=) :: Type -> Type -> Prop
infix 4 =#=

-- | Make a greater-than-or-equal-to constraint.
(>==) :: Type -> Type -> Prop
infix 4 >==

-- | Make a function type.
tFun :: Type -> Type -> Type
infixr 5 `tFun`

-- | Compute the names from all functor parameters
allParamNames :: FunctorParams -> ModParamNames

-- | This is how module parameters appear in actual types.
mtpParam :: ModTParam -> TParam
tMono :: Type -> Schema
isMono :: Schema -> Maybe Type
schemaParam :: Name -> TPFlavor
tySynParam :: Name -> TPFlavor
propSynParam :: Name -> TPFlavor
newtypeParam :: Name -> TPFlavor
modTyParam :: Name -> TPFlavor
tpfName :: TPFlavor -> Maybe Name
tvInfo :: TVar -> TVarInfo
tvUnique :: TVar -> Int
noArgDescr :: ArgDescr

-- | Get the names of something that is related to the tvar.
tvSourceName :: TypeSource -> Maybe Name
quickApply :: Kind -> [a] -> Kind
kindResult :: Kind -> Kind
tpVar :: TParam -> TVar

-- | Compute the set of all <tt>Prop</tt>s that are implied by the given
--   prop via superclass constraints.
superclassSet :: Prop -> Set Prop
pFin :: Type -> Prop
tTwo :: Type
newtypeConType :: Newtype -> Schema
abstractTypeTC :: AbstractType -> TCon
isFreeTV :: TVar -> Bool
isBoundTV :: TVar -> Bool
tIsError :: Type -> Maybe Type

-- | Eliminate outermost type synonyms.
tNoUser :: Type -> Type
tHasErrors :: Type -> Bool
tIsNat' :: Type -> Maybe Nat'
tIsNum :: Type -> Maybe Integer
tIsInf :: Type -> Bool
tIsVar :: Type -> Maybe TVar
tIsFun :: Type -> Maybe (Type, Type)
tIsSeq :: Type -> Maybe (Type, Type)
tIsBit :: Type -> Bool
tIsInteger :: Type -> Bool
tIsIntMod :: Type -> Maybe Type
tIsRational :: Type -> Bool
tIsFloat :: Type -> Maybe (Type, Type)
tIsTuple :: Type -> Maybe [Type]
tIsRec :: Type -> Maybe (RecordMap Ident Type)
tIsBinFun :: TFun -> Type -> Maybe (Type, Type)

-- | Split up repeated occurances of the given binary type-level function.
tSplitFun :: TFun -> Type -> [Type]
pIsFin :: Prop -> Maybe Type
pIsPrime :: Prop -> Maybe Type
pIsGeq :: Prop -> Maybe (Type, Type)
pIsEqual :: Prop -> Maybe (Type, Type)
pIsZero :: Prop -> Maybe Type
pIsLogic :: Prop -> Maybe Type
pIsRing :: Prop -> Maybe Type
pIsField :: Prop -> Maybe Type
pIsIntegral :: Prop -> Maybe Type
pIsRound :: Prop -> Maybe Type
pIsEq :: Prop -> Maybe Type
pIsCmp :: Prop -> Maybe Type
pIsSignedCmp :: Prop -> Maybe Type
pIsLiteral :: Prop -> Maybe (Type, Type)
pIsLiteralLessThan :: Prop -> Maybe (Type, Type)
pIsFLiteral :: Prop -> Maybe (Type, Type, Type, Type)
pIsTrue :: Prop -> Bool
pIsWidth :: Prop -> Maybe Type
pIsValidFloat :: Prop -> Maybe (Type, Type)
tNum :: Integral a => a -> Type
tZero :: Type
tOne :: Type
tInf :: Type
tNat' :: Nat' -> Type
tAbstract :: UserTC -> [Type] -> Type
tNewtype :: Newtype -> [Type] -> Type
tBit :: Type
tInteger :: Type
tRational :: Type
tFloat :: Type -> Type -> Type
tIntMod :: Type -> Type
tWord :: Type -> Type
tSeq :: Type -> Type -> Type
tChar :: Type
tString :: Int -> Type
tRec :: RecordMap Ident Type -> Type
tTuple :: [Type] -> Type

-- | Make an error value of the given type to replace the given malformed
--   type (the argument to the error function)
tError :: Type -> Type
tf1 :: TFun -> Type -> Type
tf2 :: TFun -> Type -> Type -> Type
tf3 :: TFun -> Type -> Type -> Type -> Type
(=/=) :: Type -> Type -> Prop
pZero :: Type -> Prop
pLogic :: Type -> Prop
pRing :: Type -> Prop
pIntegral :: Type -> Prop
pField :: Type -> Prop
pRound :: Type -> Prop
pEq :: Type -> Prop
pCmp :: Type -> Prop
pSignedCmp :: Type -> Prop
pLiteral :: Type -> Type -> Prop
pLiteralLessThan :: Type -> Type -> Prop

-- | A <tt>Has</tt> constraint, used for tuple and record selection.
pHas :: Selector -> Type -> Type -> Prop
pTrue :: Prop
pAnd :: [Prop] -> Prop
pSplitAnd :: Prop -> [Prop]
pValidFloat :: Type -> Type -> Type
pPrime :: Type -> Prop

-- | <a>pNegNumeric</a> negates a simple (i.e., not And, not prime, etc)
--   prop over numeric type vars. The result is a conjunction of
--   properties.
pNegNumeric :: Prop -> [Prop]
noFreeVariables :: FVS t => t -> Bool
freeParams :: FVS t => t -> Set TParam
addTNames :: [TParam] -> NameMap -> NameMap
ppNewtypeShort :: Newtype -> Doc
ppNewtypeFull :: Newtype -> Doc
pickTVarName :: Kind -> TypeSource -> Int -> Doc
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.ModTParam
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.ModTParam
instance GHC.Show.Show Cryptol.TypeCheck.Type.ModTParam
instance GHC.Show.Show Cryptol.TypeCheck.Type.TPFlavor
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.TPFlavor
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.TPFlavor
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.ArgDescr
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.ArgDescr
instance GHC.Show.Show Cryptol.TypeCheck.Type.ArgDescr
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.TypeSource
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.TypeSource
instance GHC.Show.Show Cryptol.TypeCheck.Type.TypeSource
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.TVarInfo
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.TVarInfo
instance GHC.Show.Show Cryptol.TypeCheck.Type.TVarInfo
instance GHC.Show.Show Cryptol.TypeCheck.Type.TParam
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.TParam
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.TParam
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.TVar
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.TVar
instance GHC.Show.Show Cryptol.TypeCheck.Type.TVar
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.Type
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.Type
instance GHC.Show.Show Cryptol.TypeCheck.Type.Type
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.Newtype
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.Newtype
instance GHC.Show.Show Cryptol.TypeCheck.Type.Newtype
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.TySyn
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.TySyn
instance GHC.Show.Show Cryptol.TypeCheck.Type.TySyn
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.Schema
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.Schema
instance GHC.Show.Show Cryptol.TypeCheck.Type.Schema
instance GHC.Classes.Eq Cryptol.TypeCheck.Type.Schema
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.ModVParam
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.ModVParam
instance GHC.Show.Show Cryptol.TypeCheck.Type.ModVParam
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.ModParamNames
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.ModParamNames
instance GHC.Show.Show Cryptol.TypeCheck.Type.ModParamNames
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.ModParam
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.ModParam
instance GHC.Show.Show Cryptol.TypeCheck.Type.ModParam
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Type.AbstractType
instance GHC.Generics.Generic Cryptol.TypeCheck.Type.AbstractType
instance GHC.Show.Show Cryptol.TypeCheck.Type.AbstractType
instance Cryptol.TypeCheck.Type.FreeAbstract a => Cryptol.TypeCheck.Type.FreeAbstract [a]
instance (Cryptol.TypeCheck.Type.FreeAbstract a, Cryptol.TypeCheck.Type.FreeAbstract b) => Cryptol.TypeCheck.Type.FreeAbstract (a, b)
instance Cryptol.TypeCheck.Type.FreeAbstract Cryptol.TypeCheck.TCon.TCon
instance Cryptol.TypeCheck.Type.FreeAbstract Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.Type.FVS Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.Type.FVS a => Cryptol.TypeCheck.Type.FVS (GHC.Maybe.Maybe a)
instance Cryptol.TypeCheck.Type.FVS a => Cryptol.TypeCheck.Type.FVS [a]
instance (Cryptol.TypeCheck.Type.FVS a, Cryptol.TypeCheck.Type.FVS b) => Cryptol.TypeCheck.Type.FVS (a, b)
instance Cryptol.TypeCheck.Type.FVS Cryptol.TypeCheck.Type.Schema
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.Type.AbstractType
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.ModParamNames
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.ModVParam
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.Schema
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Type.Schema)
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.Type.TySyn
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.TySyn
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Type.TySyn)
instance GHC.Classes.Eq Cryptol.TypeCheck.Type.Newtype
instance GHC.Classes.Ord Cryptol.TypeCheck.Type.Newtype
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.Type.Newtype
instance GHC.Classes.Eq Cryptol.TypeCheck.Type.Type
instance GHC.Classes.Ord Cryptol.TypeCheck.Type.Type
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.Newtype
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Type.Newtype)
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Type.Type)
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.Type.TVar
instance GHC.Classes.Eq Cryptol.TypeCheck.Type.TVar
instance GHC.Classes.Ord Cryptol.TypeCheck.Type.TVar
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Type.TVar)
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.TVar
instance Cryptol.TypeCheck.TCon.HasKind Cryptol.TypeCheck.Type.TParam
instance GHC.Classes.Eq Cryptol.TypeCheck.Type.TParam
instance GHC.Classes.Ord Cryptol.TypeCheck.Type.TParam
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.TParam
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Type.TParam)
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.TVarInfo
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.TypeSource
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.ArgDescr
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Type.ModTParam

module Cryptol.TypeCheck.TypePat
aInf :: Pat Type ()
aNat :: Pat Type Integer
aNat' :: Pat Type Nat'
anAdd :: Pat Type (Type, Type)
(|-|) :: Pat Type (Type, Type)
aMul :: Pat Type (Type, Type)
(|^|) :: Pat Type (Type, Type)
(|/|) :: Pat Type (Type, Type)
(|%|) :: Pat Type (Type, Type)
aMin :: Pat Type (Type, Type)
aMax :: Pat Type (Type, Type)
aWidth :: Pat Type Type
aCeilDiv :: Pat Type (Type, Type)
aCeilMod :: Pat Type (Type, Type)
aLenFromThenTo :: Pat Type (Type, Type, Type)
aLiteral :: Pat Prop (Type, Type)
aLiteralLessThan :: Pat Prop (Type, Type)
aLogic :: Pat Prop Type
aTVar :: Pat Type TVar
aFreeTVar :: Pat Type TVar
anAbstractType :: Pat Type UserTC
aBit :: Pat Type ()
aSeq :: Pat Type (Type, Type)
aWord :: Pat Type Type
aChar :: Pat Type ()
aTuple :: Pat Type [Type]
aRec :: Pat Type (RecordMap Ident Type)
(|->|) :: Pat Type (Type, Type)
aFin :: Pat Prop Type
(|=|) :: Pat Prop (Type, Type)
(|/=|) :: Pat Prop (Type, Type)
(|>=|) :: Pat Prop (Type, Type)
aAnd :: Pat Prop (Prop, Prop)
aTrue :: Pat Prop ()
anError :: Kind -> Pat Type ()

module Cryptol.TypeCheck.SimpType
tRebuild' :: Bool -> Type -> Type
tRebuild :: Type -> Type
tCon :: TCon -> [Type] -> Type
tAdd :: Type -> Type -> Type
tSub :: Type -> Type -> Type
tMul :: Type -> Type -> Type
tDiv :: Type -> Type -> Type
tMod :: Type -> Type -> Type
tCeilDiv :: Type -> Type -> Type
tCeilMod :: Type -> Type -> Type
tExp :: Type -> Type -> Type
tMin :: Type -> Type -> Type
tMax :: Type -> Type -> Type
tWidth :: Type -> Type
tLenFromThenTo :: Type -> Type -> Type -> Type
total :: ([Nat'] -> Nat') -> [Nat'] -> Maybe Nat'
op1 :: (a -> b) -> [a] -> b
op2 :: (a -> a -> b) -> [a] -> b
op3 :: (a -> a -> a -> b) -> [a] -> b

-- | Common checks: check for error, or simple full evaluation. We assume
--   that input kinds and the result kind are the same (i.e., Nat)
tOp :: TFun -> ([Nat'] -> Maybe Nat') -> [Type] -> Maybe Type


-- | This module defines a nicer intermediate representation of Cryptol
--   types allowed for the FFI, which the typechecker generates then stores
--   in the AST. This way the FFI evaluation code does not have to examine
--   the raw type signatures again.
module Cryptol.TypeCheck.FFI.FFIType

-- | Type of a foreign function.
data FFIFunType
FFIFunType :: [TParam] -> [FFIType] -> FFIType -> FFIFunType

-- | Note: any type variables within this function type must be bound here.
[ffiTParams] :: FFIFunType -> [TParam]
[ffiArgTypes] :: FFIFunType -> [FFIType]
[ffiRetType] :: FFIFunType -> FFIType

-- | Type of a value that can be passed to or returned from a foreign
--   function.
data FFIType
FFIBool :: FFIType
FFIBasic :: FFIBasicType -> FFIType

-- | <ul>
--   <li><i>n</i> [m][p]T --&gt; FFIArray [n, m, p] T</li>
--   </ul>
FFIArray :: [Type] -> FFIBasicType -> FFIType
FFITuple :: [FFIType] -> FFIType
FFIRecord :: RecordMap Ident FFIType -> FFIType

-- | Types which can be elements of FFI arrays.
data FFIBasicType
FFIBasicVal :: FFIBasicValType -> FFIBasicType
FFIBasicRef :: FFIBasicRefType -> FFIBasicType

-- | Basic type which is passed and returned directly by value.
data FFIBasicValType
FFIWord :: Integer -> FFIWordSize -> FFIBasicValType
FFIFloat :: Integer -> Integer -> FFIFloatSize -> FFIBasicValType
data FFIWordSize
FFIWord8 :: FFIWordSize
FFIWord16 :: FFIWordSize
FFIWord32 :: FFIWordSize
FFIWord64 :: FFIWordSize
data FFIFloatSize
FFIFloat32 :: FFIFloatSize
FFIFloat64 :: FFIFloatSize

-- | Basic type which is passed and returned by reference through a
--   parameter.
data FFIBasicRefType

-- | Modulus (Just for Z, Nothing for Integer)
FFIInteger :: Maybe Type -> FFIBasicRefType
FFIRational :: FFIBasicRefType
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.FFIType.FFIWordSize
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.FFIType.FFIWordSize
instance GHC.Show.Show Cryptol.TypeCheck.FFI.FFIType.FFIWordSize
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.FFIType.FFIFloatSize
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.FFIType.FFIFloatSize
instance GHC.Show.Show Cryptol.TypeCheck.FFI.FFIType.FFIFloatSize
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.FFIType.FFIBasicValType
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.FFIType.FFIBasicValType
instance GHC.Show.Show Cryptol.TypeCheck.FFI.FFIType.FFIBasicValType
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.FFIType.FFIBasicRefType
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.FFIType.FFIBasicRefType
instance GHC.Show.Show Cryptol.TypeCheck.FFI.FFIType.FFIBasicRefType
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.FFIType.FFIBasicType
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.FFIType.FFIBasicType
instance GHC.Show.Show Cryptol.TypeCheck.FFI.FFIType.FFIBasicType
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.FFIType.FFIType
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.FFIType.FFIType
instance GHC.Show.Show Cryptol.TypeCheck.FFI.FFIType.FFIType
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.FFIType.FFIFunType
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.FFIType.FFIFunType
instance GHC.Show.Show Cryptol.TypeCheck.FFI.FFIType.FFIFunType


-- | Utility functions that are also useful for translating programs from
--   previous Cryptol versions.
module Cryptol.Parser.Utils
translateExprToNumT :: Expr PName -> Maybe (Type PName)
widthIdent :: Ident


-- | This module defines the scoping rules for value- and type-level names
--   in Cryptol.
module Cryptol.Parser.Names

-- | The names defined by a newtype.
tnamesNT :: Newtype name -> ([Located name], ())

-- | Compute the type synonyms/type variables used by a type.
tnamesT :: Ord name => Type name -> Set name

-- | The type names used by a prop.
tnamesC :: Ord name => Prop name -> Set name

-- | The names defined and used by a single declarations.
namesD :: Ord name => Decl name -> ([Located name], Set name)

-- | The type names defined and used by a single declaration.
tnamesD :: Ord name => Decl name -> ([Located name], Set name)

-- | The names defined and used by a single binding.
namesB :: Ord name => Bind name -> ([Located name], Set name)

-- | The names defined by a pattern. These will always be unqualified
--   names.
namesP :: Pattern name -> [Located name]
namesNT :: Newtype name -> ([Located name], ())

-- | Remove some defined variables from a set of free variables.
boundNames :: Ord name => [name] -> Set name -> Set name

-- | Remove some defined variables from a set of free variables.
boundNamesSet :: Ord name => Set name -> Set name -> Set name


-- | The purpose of this module is to convert all patterns to variable
--   patterns. It also eliminates pattern bindings by de-sugaring them into
--   <a>Bind</a>. Furthermore, here we associate signatures, fixities, and
--   pragmas with the names to which they belong.
module Cryptol.Parser.NoPat
class RemovePatterns t

-- | Eliminate all patterns in a program.
removePatterns :: RemovePatterns t => t -> (t, [Error])
data Error
MultipleSignatures :: PName -> [Located (Schema PName)] -> Error
SignatureNoBind :: Located PName -> Schema PName -> Error
PragmaNoBind :: Located PName -> Pragma -> Error
MultipleFixities :: PName -> [Range] -> Error
FixityNoBind :: Located PName -> Error
MultipleDocs :: PName -> [Range] -> Error
instance Control.DeepSeq.NFData Cryptol.Parser.NoPat.Error
instance GHC.Generics.Generic Cryptol.Parser.NoPat.Error
instance GHC.Show.Show Cryptol.Parser.NoPat.Error
instance Cryptol.Parser.NoPat.RemovePatterns (Cryptol.Parser.AST.Program Cryptol.Parser.Name.PName)
instance Cryptol.Parser.NoPat.RemovePatterns (Cryptol.Parser.AST.Expr Cryptol.Parser.Name.PName)
instance Cryptol.Parser.NoPat.RemovePatterns (Cryptol.Parser.AST.ModuleG mname Cryptol.Parser.Name.PName)
instance Cryptol.Parser.NoPat.RemovePatterns [Cryptol.Parser.AST.Decl Cryptol.Parser.Name.PName]
instance Cryptol.Parser.NoPat.RemovePatterns (Cryptol.Parser.AST.NestedModule Cryptol.Parser.Name.PName)
instance GHC.Base.Functor Cryptol.Parser.NoPat.NoPatM
instance GHC.Base.Applicative Cryptol.Parser.NoPat.NoPatM
instance GHC.Base.Monad Cryptol.Parser.NoPat.NoPatM
instance Cryptol.Utils.PP.PP Cryptol.Parser.NoPat.Error


-- | Expands PropGuards into a top-level definition for each case, and
--   rewrites the body of each case to be an appropriate call to the
--   respectively generated function.
module Cryptol.Parser.ExpandPropGuards

-- | Monad
type ExpandPropGuardsM a = Either Error a
runExpandPropGuardsM :: ExpandPropGuardsM a -> Either Error a

-- | Error
data Error
NoSignature :: Located PName -> Error
expandPropGuards :: ModuleG mname PName -> ExpandPropGuardsM (ModuleG mname PName)
expandModuleDef :: ModuleDefinition PName -> ExpandPropGuardsM (ModuleDefinition PName)
expandTopDecl :: TopDecl PName -> ExpandPropGuardsM [TopDecl PName]
expandDecl :: Decl PName -> ExpandPropGuardsM [Decl PName]
expandBind :: Bind PName -> ExpandPropGuardsM [Bind PName]
patternToExpr :: Pattern PName -> Expr PName
newName :: Located PName -> [Prop PName] -> ExpandPropGuardsM (Located PName)
instance Control.DeepSeq.NFData Cryptol.Parser.ExpandPropGuards.Error
instance GHC.Generics.Generic Cryptol.Parser.ExpandPropGuards.Error
instance GHC.Show.Show Cryptol.Parser.ExpandPropGuards.Error
instance Cryptol.Utils.PP.PP Cryptol.Parser.ExpandPropGuards.Error


-- | We add implicit imports are for public nested modules. This allows
--   using definitions from nested modules without having to explicitly
--   import them, for example:
--   
--   module A where
--   
--   submodule B where x = 0x20
--   
--   y = x // This works because of the implicit import of <tt>B</tt>
--   
--   Restriction: ============
--   
--   We only add impicit imports of modules that are syntactically visiable
--   in the source code. Consider the following example:
--   
--   module A where submodule M = F {X} -- F,X are external modules (e.g.,
--   top-level)
--   
--   We will add an implicit import for <tt>M</tt>, but *NO* implicit
--   imports for any modules imported vial <tt>M</tt> as those are not
--   sytnactically visible in the source (i.e., we have to know what
--   <tt>F</tt> refers to).
--   
--   This restriction allows us to add implicit imports before doing the
--   <tt>Imports</tt> pass.
module Cryptol.ModuleSystem.Renamer.ImplicitImports

-- | Add additional imports for modules nested withing this one
addImplicitNestedImports :: [TopDecl PName] -> [TopDecl PName]


module Cryptol.ModuleSystem.Renamer.Error
data RenamerError

-- | Multiple imported symbols contain this name
MultipleSyms :: Located PName -> [Name] -> RenamerError

-- | Some name not bound to any definition
UnboundName :: Namespace -> Located PName -> RenamerError

-- | An environment has produced multiple overlapping symbols
OverlappingSyms :: [Name] -> RenamerError

-- | expected, actual. When a name is missing from the expected namespace,
--   but exists in another
WrongNamespace :: Namespace -> Namespace -> Located PName -> RenamerError

-- | When the fixity of two operators conflict
FixityError :: Located Name -> Fixity -> Located Name -> Fixity -> RenamerError

-- | When record updates overlap (e.g., <tt>{ r | x = e1, x.y = e2 }</tt>)
OverlappingRecordUpdate :: Located [Selector] -> Located [Selector] -> RenamerError

-- | Things that can't depend on each other
InvalidDependency :: [DepName] -> RenamerError

-- | Module parameters with the same name
MultipleModParams :: Ident -> [Range] -> RenamerError

-- | Can't import functors directly
InvalidFunctorImport :: ImpName Name -> RenamerError

-- | Nested modules were not supposed to appear here
UnexpectedNest :: Range -> PName -> RenamerError

-- | Exepcted one kind (first one) but found the other (second one)
ModuleKindMismatch :: Range -> ImpName Name -> ModKind -> ModKind -> RenamerError

-- | We use this to name dependencies. In addition to normal names we have
--   a way to refer to module parameters and top-level module constraints,
--   which have no explicit names
data DepName

-- | Something with a name
NamedThing :: Name -> DepName

-- | The module at this path
ModPath :: ModPath -> DepName

-- | Note that the range is important not just for error reporting but to
--   distinguish module parameters with the same name (e.g., in nested
--   functors)
ModParamName :: Range -> Ident -> DepName

-- | Identifed by location in source
ConstratintAt :: Range -> DepName
depNameLoc :: DepName -> Maybe Range
data ModKind
AFunctor :: ModKind
ASignature :: ModKind
AModule :: ModKind
data RenamerWarning
SymbolShadowed :: PName -> Name -> [Name] -> RenamerWarning
UnusedName :: Name -> RenamerWarning
PrefixAssocChanged :: PrefixOp -> Expr Name -> Located Name -> Fixity -> Expr Name -> RenamerWarning
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Renamer.Error.DepName
instance GHC.Generics.Generic Cryptol.ModuleSystem.Renamer.Error.DepName
instance GHC.Show.Show Cryptol.ModuleSystem.Renamer.Error.DepName
instance GHC.Classes.Ord Cryptol.ModuleSystem.Renamer.Error.DepName
instance GHC.Classes.Eq Cryptol.ModuleSystem.Renamer.Error.DepName
instance GHC.Classes.Ord Cryptol.ModuleSystem.Renamer.Error.ModKind
instance GHC.Classes.Eq Cryptol.ModuleSystem.Renamer.Error.ModKind
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Renamer.Error.ModKind
instance GHC.Generics.Generic Cryptol.ModuleSystem.Renamer.Error.ModKind
instance GHC.Show.Show Cryptol.ModuleSystem.Renamer.Error.ModKind
instance GHC.Classes.Ord Cryptol.ModuleSystem.Renamer.Error.RenamerError
instance GHC.Classes.Eq Cryptol.ModuleSystem.Renamer.Error.RenamerError
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Renamer.Error.RenamerError
instance GHC.Generics.Generic Cryptol.ModuleSystem.Renamer.Error.RenamerError
instance GHC.Show.Show Cryptol.ModuleSystem.Renamer.Error.RenamerError
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Renamer.Error.RenamerWarning
instance GHC.Generics.Generic Cryptol.ModuleSystem.Renamer.Error.RenamerWarning
instance GHC.Show.Show Cryptol.ModuleSystem.Renamer.Error.RenamerWarning
instance GHC.Classes.Eq Cryptol.ModuleSystem.Renamer.Error.RenamerWarning
instance GHC.Classes.Ord Cryptol.ModuleSystem.Renamer.Error.RenamerWarning
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Renamer.Error.RenamerWarning
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Renamer.Error.RenamerError
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Renamer.Error.ModKind
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Renamer.Error.DepName


module Cryptol.ModuleSystem.Interface
type Iface = IfaceG ModName

-- | The interface repersenting a typecheck top-level module.
data IfaceG name
Iface :: IfaceNames name -> FunctorParams -> IfaceDecls -> IfaceG name

-- | Info about names in this module
[ifNames] :: IfaceG name -> IfaceNames name

-- | Module parameters, if any
[ifParams] :: IfaceG name -> FunctorParams

-- | All things defines in the module (includes nested definitions)
[ifDefines] :: IfaceG name -> IfaceDecls

-- | Declarations in a module. Note that this includes things from nested
--   modules, but not things from nested functors, which are in
--   <a>ifFunctors</a>.
data IfaceDecls
IfaceDecls :: Map Name TySyn -> Map Name Newtype -> Map Name AbstractType -> Map Name IfaceDecl -> !Map Name (IfaceNames Name) -> !Map Name ModParamNames -> !Map Name (IfaceG Name) -> IfaceDecls
[ifTySyns] :: IfaceDecls -> Map Name TySyn
[ifNewtypes] :: IfaceDecls -> Map Name Newtype
[ifAbstractTypes] :: IfaceDecls -> Map Name AbstractType
[ifDecls] :: IfaceDecls -> Map Name IfaceDecl
[ifModules] :: IfaceDecls -> !Map Name (IfaceNames Name)
[ifSignatures] :: IfaceDecls -> !Map Name ModParamNames

-- | XXX: Maybe arg info? Also, with the current implementation we aim to
--   complete remove functors by essentially inlining them. To achieve this
--   with just interfaces we'd have to store here the entire module, not
--   just its interface. At the moment we work around this by passing all
--   loaded modules to the type checker, so it looks up functors there,
--   instead of in the interfaces, but we'd need to change this if we want
--   better support for separate compilation.
[ifFunctors] :: IfaceDecls -> !Map Name (IfaceG Name)
data IfaceDecl
IfaceDecl :: !Name -> Schema -> !Bool -> [Pragma] -> Bool -> Maybe Fixity -> Maybe Text -> IfaceDecl

-- | Name of thing
[ifDeclName] :: IfaceDecl -> !Name

-- | Type
[ifDeclSig] :: IfaceDecl -> Schema
[ifDeclIsPrim] :: IfaceDecl -> !Bool

-- | Pragmas
[ifDeclPragmas] :: IfaceDecl -> [Pragma]

-- | Is this an infix thing
[ifDeclInfix] :: IfaceDecl -> Bool

-- | Fixity information
[ifDeclFixity] :: IfaceDecl -> Maybe Fixity

-- | Documentation
[ifDeclDoc] :: IfaceDecl -> Maybe Text

-- | Information about the names in a module.
data IfaceNames name
IfaceNames :: name -> Set Name -> Set Name -> Set Name -> !Maybe Text -> IfaceNames name

-- | Name of this submodule
[ifsName] :: IfaceNames name -> name

-- | Things nested in this module
[ifsNested] :: IfaceNames name -> Set Name

-- | Things defined in this module
[ifsDefines] :: IfaceNames name -> Set Name

-- | Subset of <a>ifsDefines</a> that is public
[ifsPublic] :: IfaceNames name -> Set Name

-- | Documentation
[ifsDoc] :: IfaceNames name -> !Maybe Text

-- | Access the name of a module.
ifModName :: IfaceG name -> name
emptyIface :: ModName -> Iface

-- | Produce a PrimMap from an interface.
--   
--   NOTE: the map will expose <i>both</i> public and private names. NOTE:
--   this is a bit misnamed, as it is used to resolve known names that
--   Cryptol introduces (e.g., during type checking). These names need not
--   be primitives. A better way to do this in the future might be to use
--   original names instead (see #1522).
ifacePrimMap :: Iface -> PrimMap

-- | Remove the name of a module. This is useful for dealing with
--   collections of modules, as in `Map (ImpName Name) (IfaceG ())`.
ifaceForgetName :: IfaceG name -> IfaceG ()

-- | Is this interface for a functor.
ifaceIsFunctor :: IfaceG name -> Bool
filterIfaceDecls :: (Name -> Bool) -> IfaceDecls -> IfaceDecls
ifaceDeclsNames :: IfaceDecls -> Set Name

-- | Given an interface computing a map from original names to actual
--   names, grouped by namespace.
ifaceOrigNameMap :: IfaceG name -> Map Namespace (Map OrigName Name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.ModuleSystem.Interface.IfaceNames name)
instance GHC.Generics.Generic (Cryptol.ModuleSystem.Interface.IfaceNames name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.ModuleSystem.Interface.IfaceNames name)
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Interface.IfaceDecl
instance GHC.Generics.Generic Cryptol.ModuleSystem.Interface.IfaceDecl
instance GHC.Show.Show Cryptol.ModuleSystem.Interface.IfaceDecl
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.ModuleSystem.Interface.IfaceG name)
instance GHC.Generics.Generic (Cryptol.ModuleSystem.Interface.IfaceG name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.ModuleSystem.Interface.IfaceG name)
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Interface.IfaceDecls
instance GHC.Generics.Generic Cryptol.ModuleSystem.Interface.IfaceDecls
instance GHC.Show.Show Cryptol.ModuleSystem.Interface.IfaceDecls
instance GHC.Base.Semigroup Cryptol.ModuleSystem.Interface.IfaceDecls
instance GHC.Base.Monoid Cryptol.ModuleSystem.Interface.IfaceDecls

module Cryptol.ModuleSystem.Exports
exportedDecls :: Ord name => [TopDecl name] -> ExportSpec name
exportedNames :: Ord name => TopDecl name -> [ExportSpec name]
newtype ExportSpec name
ExportSpec :: Map Namespace (Set name) -> ExportSpec name
exportName :: Ord name => Namespace -> TopLevel name -> ExportSpec name
allExported :: Ord name => ExportSpec name -> Set name
exported :: Namespace -> ExportSpec name -> Set name

-- | Add a binding name to the export list, if it should be exported.
exportBind :: Ord name => TopLevel name -> ExportSpec name

-- | Add a type synonym name to the export list, if it should be exported.
exportType :: Ord name => TopLevel name -> ExportSpec name
isExported :: Ord name => Namespace -> name -> ExportSpec name -> Bool

-- | Check to see if a binding is exported.
isExportedBind :: Ord name => name -> ExportSpec name -> Bool

-- | Check to see if a type synonym is exported.
isExportedType :: Ord name => name -> ExportSpec name -> Bool
instance GHC.Generics.Generic (Cryptol.ModuleSystem.Exports.ExportSpec name)
instance GHC.Show.Show name => GHC.Show.Show (Cryptol.ModuleSystem.Exports.ExportSpec name)
instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Cryptol.ModuleSystem.Exports.ExportSpec name)
instance GHC.Classes.Ord name => GHC.Base.Semigroup (Cryptol.ModuleSystem.Exports.ExportSpec name)
instance GHC.Classes.Ord name => GHC.Base.Monoid (Cryptol.ModuleSystem.Exports.ExportSpec name)


module Cryptol.TypeCheck.AST
type Module = ModuleG ModName
data Expr

-- | List value (with type of elements)
EList :: [Expr] -> Type -> Expr

-- | Tuple value
ETuple :: [Expr] -> Expr

-- | Record value
ERec :: RecordMap Ident Expr -> Expr

-- | Elimination for tuple<i>record</i>list
ESel :: Expr -> Selector -> Expr

-- | Change the value of a field. The included type gives the type of the
--   record being updated
ESet :: Type -> Expr -> Selector -> Expr -> Expr

-- | If-then-else
EIf :: Expr -> Expr -> Expr -> Expr

-- | List comprehensions The types cache the length of the sequence and its
--   element type.
EComp :: Type -> Type -> Expr -> [[Match]] -> Expr

-- | Use of a bound variable
EVar :: Name -> Expr

-- | Function Value
ETAbs :: TParam -> Expr -> Expr

-- | Type application
ETApp :: Expr -> Type -> Expr

-- | Function application
EApp :: Expr -> Expr -> Expr

-- | Function value
EAbs :: Name -> Type -> Expr -> Expr

-- | Source location information
ELocated :: Range -> Expr -> Expr

-- | Proof abstraction. Because we don't keep proofs around we don't need
--   to name the assumption, but we still need to record the assumption.
--   The assumption is the <a>Type</a> term, which should be of kind
--   <a>KProp</a>.
EProofAbs :: Prop -> Expr -> Expr

-- | If <tt>e : p =&gt; t</tt>, then <tt>EProofApp e : t</tt>, as long as
--   we can prove <tt>p</tt>.
--   
--   We don't record the actual proofs, as they are not used for anything.
--   It may be nice to keep them around for sanity checking.
EProofApp :: Expr -> Expr
EWhere :: Expr -> [DeclGroup] -> Expr
EPropGuards :: [([Prop], Expr)] -> Type -> Expr
data Match

-- | Type arguments are the length and element type of the sequence
--   expression
From :: Name -> Type -> Type -> Expr -> Match
Let :: Decl -> Match

-- | A Cryptol module.
data ModuleG mname
Module :: !mname -> !Maybe Text -> ExportSpec Name -> Map Name ModTParam -> Map Name ModVParam -> [Located Prop] -> FunctorParams -> Map Name (ModuleG Name) -> !Set Name -> Map Name TySyn -> Map Name Newtype -> Map Name AbstractType -> [DeclGroup] -> Map Name (IfaceNames Name) -> !Map Name ModParamNames -> ModuleG mname
[mName] :: ModuleG mname -> !mname
[mDoc] :: ModuleG mname -> !Maybe Text
[mExports] :: ModuleG mname -> ExportSpec Name
[mParamTypes] :: ModuleG mname -> Map Name ModTParam
[mParamFuns] :: ModuleG mname -> Map Name ModVParam
[mParamConstraints] :: ModuleG mname -> [Located Prop]

-- | Parameters grouped by "import".
[mParams] :: ModuleG mname -> FunctorParams

-- | Functors directly nested in this module. Things further nested are in
--   the modules in the elements of the map.
[mFunctors] :: ModuleG mname -> Map Name (ModuleG Name)

-- | Submodules, functors, and interfaces nested directly in this module
[mNested] :: ModuleG mname -> !Set Name
[mTySyns] :: ModuleG mname -> Map Name TySyn
[mNewtypes] :: ModuleG mname -> Map Name Newtype
[mPrimTypes] :: ModuleG mname -> Map Name AbstractType
[mDecls] :: ModuleG mname -> [DeclGroup]
[mSubmodules] :: ModuleG mname -> Map Name (IfaceNames Name)
[mSignatures] :: ModuleG mname -> !Map Name ModParamNames
data Decl
Decl :: !Name -> Schema -> DeclDef -> [Pragma] -> !Bool -> Maybe Fixity -> Maybe Text -> Decl
[dName] :: Decl -> !Name
[dSignature] :: Decl -> Schema
[dDefinition] :: Decl -> DeclDef
[dPragmas] :: Decl -> [Pragma]
[dInfix] :: Decl -> !Bool
[dFixity] :: Decl -> Maybe Fixity
[dDoc] :: Decl -> Maybe Text
data TCTopEntity
TCTopModule :: ModuleG ModName -> TCTopEntity
TCTopSignature :: ModName -> ModParamNames -> TCTopEntity
data DeclGroup

-- | Mutually recursive declarations
Recursive :: [Decl] -> DeclGroup

-- | Non-recursive declaration
NonRecursive :: Decl -> DeclGroup
data DeclDef
DPrim :: DeclDef
DForeign :: FFIFunType -> DeclDef
DExpr :: Expr -> DeclDef
splitTApp :: Expr -> Maybe (Type, Expr)

-- | Find all the foreign declarations in the module and return their names
--   and FFIFunTypes.
findForeignDecls :: ModuleG mname -> [(Name, FFIFunType)]
splitApp :: Expr -> Maybe (Expr, Expr)
tcTopEntitytName :: TCTopEntity -> ModName

-- | Panics if the entity is not a module
tcTopEntityToModule :: TCTopEntity -> Module
emptyModule :: mname -> ModuleG mname

-- | Find all the foreign declarations that are in functors. This is used
--   to report an error
findForeignDeclsInFunctors :: ModuleG mname -> [Name]

-- | Is this a parameterized module?
isParametrizedModule :: ModuleG mname -> Bool
groupDecls :: DeclGroup -> [Decl]

-- | Construct a primitive, given a map to the unique primitive name.
ePrim :: PrimMap -> PrimIdent -> Expr

-- | Make an expression that is <tt>error</tt> pre-applied to a type and a
--   message.
eError :: PrimMap -> Type -> String -> Expr
eString :: PrimMap -> String -> Expr
eChar :: PrimMap -> Char -> Expr
splitWhile :: (a -> Maybe (b, a)) -> a -> ([b], a)
splitAbs :: Expr -> Maybe ((Name, Type), Expr)
ppLam :: NameMap -> Int -> [TParam] -> [Prop] -> [(Name, Type)] -> Expr -> Doc
splitProofAbs :: Expr -> Maybe (Prop, Expr)
splitTAbs :: Expr -> Maybe (TParam, Expr)
splitLoc :: Expr -> Maybe (Range, Expr)

-- | Remove outermost locations
dropLocs :: Expr -> Expr
splitProofApp :: Expr -> Maybe ((), Expr)

-- | Deconstruct an expression, typically polymorphic, into the types and
--   proofs to which it is applied. Since we don't store the proofs, we
--   just return the number of proof applications. The first type is the
--   one closest to the expr.
splitExprInst :: Expr -> (Expr, [Type], Int)
data Name

-- | Built-in type functions. If you add additional user-visible
--   constructors, please update <tt>primTys</tt> in
--   <a>Cryptol.Prims.Types</a>.
data TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCAdd :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCSub :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCMul :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCDiv :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCMod :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCExp :: TFun

-- | <pre>
--   : Num -&gt; Num
--   </pre>
TCWidth :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCMin :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCMax :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCCeilDiv :: TFun

-- | <pre>
--   : Num -&gt; Num -&gt; Num
--   </pre>
TCCeilMod :: TFun

-- | <tt> : Num -&gt; Num -&gt; Num -&gt; Num</tt> Example: <tt>[ 1, 5 .. 9
--   ] :: [lengthFromThenTo 1 5 9][b]</tt>
TCLenFromThenTo :: TFun

-- | Selectors are used for projecting from various components. Each
--   selector has an option spec to specify the shape of the thing that is
--   being selected. Currently, there is no surface syntax for list
--   selectors, but they are used during the desugaring of patterns.
data Selector

-- | Zero-based tuple selection. Optionally specifies the shape of the
--   tuple (one-based).
TupleSel :: Int -> Maybe Int -> Selector

-- | Record selection. Optionally specifies the shape of the record.
RecordSel :: Ident -> Maybe [Ident] -> Selector

-- | List selection. Optionally specifies the length of the list.
ListSel :: Int -> Maybe Int -> Selector
type Import = ImportG ModName

-- | An import declaration.
data ImportG mname
Import :: !mname -> Maybe ModName -> Maybe ImportSpec -> !Maybe (ModuleInstanceArgs PName) -> ImportG mname
[iModule] :: ImportG mname -> !mname
[iAs] :: ImportG mname -> Maybe ModName
[iSpec] :: ImportG mname -> Maybe ImportSpec

-- | <a>iInst</a> exists only during parsing
[iInst] :: ImportG mname -> !Maybe (ModuleInstanceArgs PName)

-- | The name of an imported module
data ImpName name

-- | A top-level module
ImpTop :: ModName -> ImpName name

-- | The module in scope with the given name
ImpNested :: name -> ImpName name

-- | The list of names following an import.
data ImportSpec
Hiding :: [Ident] -> ImportSpec
Only :: [Ident] -> ImportSpec

-- | Export information for a declaration.
data ExportType
Public :: ExportType
Private :: ExportType
newtype ExportSpec name
ExportSpec :: Map Namespace (Set name) -> ExportSpec name

-- | Check to see if a binding is exported.
isExportedBind :: Ord name => name -> ExportSpec name -> Bool

-- | Check to see if a type synonym is exported.
isExportedType :: Ord name => name -> ExportSpec name -> Bool
isExported :: Ord name => Namespace -> name -> ExportSpec name -> Bool
data Pragma
PragmaNote :: String -> Pragma
PragmaProperty :: Pragma
data Fixity
Fixity :: !Assoc -> !Int -> Fixity
[fAssoc] :: Fixity -> !Assoc
[fLevel] :: Fixity -> !Int

-- | A mapping from an identifier defined in some module to its real name.
data PrimMap
PrimMap :: Map PrimIdent Name -> Map PrimIdent Name -> PrimMap
[primDecls] :: PrimMap -> Map PrimIdent Name
[primTypes] :: PrimMap -> Map PrimIdent Name
instance Control.DeepSeq.NFData Cryptol.TypeCheck.AST.Match
instance GHC.Generics.Generic Cryptol.TypeCheck.AST.Match
instance GHC.Show.Show Cryptol.TypeCheck.AST.Match
instance GHC.Show.Show Cryptol.TypeCheck.AST.Decl
instance Control.DeepSeq.NFData Cryptol.TypeCheck.AST.Decl
instance GHC.Generics.Generic Cryptol.TypeCheck.AST.Decl
instance Control.DeepSeq.NFData Cryptol.TypeCheck.AST.DeclGroup
instance GHC.Generics.Generic Cryptol.TypeCheck.AST.DeclGroup
instance GHC.Show.Show Cryptol.TypeCheck.AST.DeclGroup
instance Control.DeepSeq.NFData Cryptol.TypeCheck.AST.Expr
instance GHC.Generics.Generic Cryptol.TypeCheck.AST.Expr
instance GHC.Show.Show Cryptol.TypeCheck.AST.Expr
instance Control.DeepSeq.NFData Cryptol.TypeCheck.AST.DeclDef
instance GHC.Generics.Generic Cryptol.TypeCheck.AST.DeclDef
instance GHC.Show.Show Cryptol.TypeCheck.AST.DeclDef
instance Control.DeepSeq.NFData mname => Control.DeepSeq.NFData (Cryptol.TypeCheck.AST.ModuleG mname)
instance GHC.Generics.Generic (Cryptol.TypeCheck.AST.ModuleG mname)
instance GHC.Show.Show mname => GHC.Show.Show (Cryptol.TypeCheck.AST.ModuleG mname)
instance Control.DeepSeq.NFData Cryptol.TypeCheck.AST.TCTopEntity
instance GHC.Generics.Generic Cryptol.TypeCheck.AST.TCTopEntity
instance GHC.Show.Show Cryptol.TypeCheck.AST.TCTopEntity
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.AST.TCTopEntity
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.AST.TCTopEntity)
instance Cryptol.Utils.PP.PP n => Cryptol.Utils.PP.PP (Cryptol.TypeCheck.AST.ModuleG n)
instance Cryptol.Utils.PP.PP n => Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames (Cryptol.TypeCheck.AST.ModuleG n))
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.AST.Expr)
instance Cryptol.Parser.Position.HasLoc Cryptol.TypeCheck.AST.Expr
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.AST.Expr
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.AST.Match)
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.AST.Match
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.AST.DeclGroup)
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.AST.DeclGroup
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.AST.Decl)
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.AST.DeclDef)
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.AST.Decl


module Cryptol.TypeCheck.TypeMap
data TypeMap a
TM :: Map TVar a -> Map TCon (List TypeMap a) -> Map [Ident] (List TypeMap a) -> Map Newtype (List TypeMap a) -> TypeMap a
[tvar] :: TypeMap a -> Map TVar a
[tcon] :: TypeMap a -> Map TCon (List TypeMap a)
[trec] :: TypeMap a -> Map [Ident] (List TypeMap a)
[tnewtype] :: TypeMap a -> Map Newtype (List TypeMap a)
type TypesMap = List TypeMap
class TrieMap m k | m -> k
emptyTM :: TrieMap m k => m a
nullTM :: TrieMap m k => m a -> Bool
lookupTM :: TrieMap m k => k -> m a -> Maybe a
alterTM :: TrieMap m k => k -> (Maybe a -> Maybe a) -> m a -> m a
unionTM :: TrieMap m k => (a -> a -> a) -> m a -> m a -> m a
toListTM :: TrieMap m k => m a -> [(k, a)]
mapMaybeWithKeyTM :: TrieMap m k => (k -> a -> Maybe b) -> m a -> m b
insertTM :: TrieMap m k => k -> a -> m a -> m a
insertWithTM :: TrieMap m k => (a -> a -> a) -> k -> a -> m a -> m a
membersTM :: TrieMap m k => m a -> [a]
mapTM :: TrieMap m k => (a -> b) -> m a -> m b
mapWithKeyTM :: TrieMap m k => (k -> a -> b) -> m a -> m b
mapMaybeTM :: TrieMap m k => (a -> Maybe b) -> m a -> m b
data List m a
L :: Maybe a -> m (List m a) -> List m a
[nil] :: List m a -> Maybe a
[cons] :: List m a -> m (List m a)
instance Data.Traversable.Traversable m => Data.Traversable.Traversable (Cryptol.TypeCheck.TypeMap.List m)
instance Data.Foldable.Foldable m => Data.Foldable.Foldable (Cryptol.TypeCheck.TypeMap.List m)
instance GHC.Base.Functor m => GHC.Base.Functor (Cryptol.TypeCheck.TypeMap.List m)
instance Data.Traversable.Traversable Cryptol.TypeCheck.TypeMap.TypeMap
instance Data.Foldable.Foldable Cryptol.TypeCheck.TypeMap.TypeMap
instance GHC.Base.Functor Cryptol.TypeCheck.TypeMap.TypeMap
instance Cryptol.TypeCheck.TypeMap.TrieMap Cryptol.TypeCheck.TypeMap.TypeMap Cryptol.TypeCheck.Type.Type
instance GHC.Show.Show a => GHC.Show.Show (Cryptol.TypeCheck.TypeMap.TypeMap a)
instance Cryptol.TypeCheck.TypeMap.TrieMap m a => Cryptol.TypeCheck.TypeMap.TrieMap (Cryptol.TypeCheck.TypeMap.List m) [a]
instance GHC.Classes.Ord a => Cryptol.TypeCheck.TypeMap.TrieMap (Data.Map.Internal.Map a) a


module Cryptol.TypeCheck.Solver.Utils

-- | All ways to split a type in the form: <tt>a + t1</tt>, where
--   <tt>a</tt> is a variable.
splitVarSummands :: Type -> [(TVar, Type)]

-- | Check if we can express a type in the form: <tt>a + t1</tt>.
splitVarSummand :: TVar -> Type -> Maybe Type

-- | Check if we can express a type in the form: <tt>k + t1</tt>, where
--   <tt>k</tt> is a constant &gt; 0. This assumes that the type has been
--   simplified already, so that constants are floated to the left.
splitConstSummand :: Type -> Maybe (Integer, Type)

-- | Check if we can express a type in the form: <tt>k * t1</tt>, where
--   <tt>k</tt> is a constant &gt; 1. This assumes that the type has been
--   simplified already, so that constants are floated to the left.
splitConstFactor :: Type -> Maybe (Integer, Type)


-- | An interval interpretation of types.
module Cryptol.TypeCheck.Solver.Numeric.Interval

-- | Only meaningful for numeric types
typeInterval :: Map TVar Interval -> Type -> Interval
tvarInterval :: Map TVar Interval -> TVar -> Interval
data IntervalUpdate
NoChange :: IntervalUpdate
InvalidInterval :: TVar -> IntervalUpdate
NewIntervals :: Map TVar Interval -> IntervalUpdate
updateInterval :: (TVar, Interval) -> Map TVar Interval -> IntervalUpdate
computePropIntervals :: Map TVar Interval -> [Prop] -> IntervalUpdate

-- | What we learn about variables from a single prop.
propInterval :: Map TVar Interval -> Prop -> [(TVar, Interval)]
data Interval
Interval :: Nat' -> Maybe Nat' -> Interval

-- | lower bound (inclusive)
[iLower] :: Interval -> Nat'

-- | upper bound (inclusive) If there is no upper bound, then all *natural*
--   numbers.
[iUpper] :: Interval -> Maybe Nat'
ppIntervals :: Map TVar Interval -> Doc
ppIntervalsWithNames :: NameMap -> Map TVar Interval -> Doc
ppInterval :: Interval -> Doc
iIsExact :: Interval -> Maybe Nat'
iIsFin :: Interval -> Bool

-- | Finite positive number. <tt>[1 .. inf)</tt>.
iIsPosFin :: Interval -> Bool

-- | Returns <a>True</a> when the intervals definitely overlap, and
--   <a>False</a> otherwise.
iOverlap :: Interval -> Interval -> Bool

-- | Intersect two intervals, yielding a new one that describes the space
--   where they overlap. If the two intervals are disjoint, the result will
--   be <a>Nothing</a>.
iIntersect :: Interval -> Interval -> Maybe Interval

-- | Any value
iAny :: Interval

-- | Any finite value
iAnyFin :: Interval

-- | Exactly this value
iConst :: Nat' -> Interval
iAdd :: Interval -> Interval -> Interval
iMul :: Interval -> Interval -> Interval
iExp :: Interval -> Interval -> Interval
iMin :: Interval -> Interval -> Interval
iMax :: Interval -> Interval -> Interval
iSub :: Interval -> Interval -> Interval
iDiv :: Interval -> Interval -> Interval
iMod :: Interval -> Interval -> Interval
iCeilDiv :: Interval -> Interval -> Interval
iCeilMod :: Interval -> Interval -> Interval
iWidth :: Interval -> Interval
iLenFromThenTo :: Interval -> Interval -> Interval -> Interval
instance GHC.Show.Show Cryptol.TypeCheck.Solver.Numeric.Interval.Interval
instance GHC.Classes.Eq Cryptol.TypeCheck.Solver.Numeric.Interval.Interval
instance GHC.Show.Show Cryptol.TypeCheck.Solver.Numeric.Interval.IntervalUpdate

module Cryptol.TypeCheck.Solver.Types
data Ctxt
SolverCtxt :: Map TVar Interval -> Set Prop -> Ctxt
[intervals] :: Ctxt -> Map TVar Interval
[saturatedAsmps] :: Ctxt -> Set Prop
data Solved

-- | Solved, assuming the sub-goals.
SolvedIf :: [Prop] -> Solved

-- | We could not solve the goal.
Unsolved :: Solved

-- | The goal can never be solved.
Unsolvable :: Solved
elseTry :: Solved -> Solved -> Solved
solveOpts :: [Solved] -> Solved
matchThen :: Maybe a -> (a -> Solved) -> Solved
guarded :: Bool -> Solved -> Solved
instance GHC.Show.Show Cryptol.TypeCheck.Solver.Types.Solved
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Solver.Types.Solved
instance GHC.Base.Semigroup Cryptol.TypeCheck.Solver.Types.Ctxt
instance GHC.Base.Monoid Cryptol.TypeCheck.Solver.Types.Ctxt


-- | Solving class constraints. If you make changes to this file, please
--   update the documenation in RefMan.md
module Cryptol.TypeCheck.Solver.Class

-- | Solve a Zero constraint by instance, if possible.
solveZeroInst :: Type -> Solved

-- | Solve a Logic constraint by instance, if possible.
solveLogicInst :: Type -> Solved

-- | Solve a Ring constraint by instance, if possible.
solveRingInst :: Type -> Solved

-- | Solve a Field constraint by instance, if possible.
solveFieldInst :: Type -> Solved

-- | Solve an Integral constraint by instance, if possible.
solveIntegralInst :: Type -> Solved

-- | Solve a Round constraint by instance, if possible.
solveRoundInst :: Type -> Solved

-- | Solve Eq constraints.
solveEqInst :: Type -> Solved

-- | Solve Cmp constraints.
solveCmpInst :: Type -> Solved

-- | Solve SignedCmp constraints.
solveSignedCmpInst :: Type -> Solved

-- | Solve Literal constraints.
solveLiteralInst :: Type -> Type -> Solved

-- | Solve Literal constraints.
solveLiteralLessThanInst :: Type -> Type -> Solved

-- | Solving fractional literal constraints.
solveFLiteralInst :: Type -> Type -> Type -> Type -> Solved

-- | This places constraints on the floating point numbers that we can work
--   with. This is a bit of an odd check, as it is really a limitiation of
--   the backend, and not the language itself.
--   
--   On the other hand, it helps us give sane results if one accidentally
--   types a polymorphic float at the REPL. Hopefully, most users will
--   stick to particular FP sizes, so this should be quite transparent.
solveValidFloat :: Type -> Type -> Solved


-- | Simplification of <tt>fin</tt> constraints.
module Cryptol.TypeCheck.Solver.Numeric.Fin
cryIsFin :: Ctxt -> Prop -> Solved
cryIsFinType :: Ctxt -> Type -> Solved

module Cryptol.TypeCheck.Solver.Numeric

-- | Try to solve <tt>t1 = t2</tt>
cryIsEqual :: Ctxt -> Type -> Type -> Solved

-- | Try to solve <tt>t1 /= t2</tt>
cryIsNotEqual :: Ctxt -> Type -> Type -> Solved

-- | Try to solve <tt>t1 &gt;= t2</tt>
cryIsGeq :: Ctxt -> Type -> Type -> Solved
cryIsPrime :: Ctxt -> Type -> Solved
primeTable :: Integer :->: Bool

module Cryptol.TypeCheck.SimpleSolver
simplify :: Ctxt -> Prop -> Prop
simplifyStep :: Ctxt -> Prop -> Solved


module Cryptol.TypeCheck.Subst

-- | A <a>Subst</a> value represents a substitution that maps each
--   <a>Type</a> to a <a>Type</a>.
--   
--   Invariant 1: If there is a mapping from <tt>TVFree _ _ tps _</tt> to a
--   type <tt>t</tt>, then <tt>t</tt> must not mention (directly or
--   indirectly) any type parameter that is not in <tt>tps</tt>. In
--   particular, if <tt>t</tt> contains a variable <tt>TVFree _ _ tps2
--   _</tt>, then <tt>tps2</tt> must be a subset of <tt>tps</tt>. This
--   ensures that applying the substitution will not permit any type
--   parameter to escape from its scope.
--   
--   Invariant 2: The substitution must be idempotent, in that applying a
--   substitution to any <a>Type</a> in the map should leave that
--   <a>Type</a> unchanged. In other words, <a>Type</a> values in the range
--   of a <a>Subst</a> should not mention any <a>Type</a> in the domain of
--   the <a>Subst</a>. In particular, this implies that a substitution must
--   not contain any recursive variable mappings.
--   
--   Invariant 3: The substitution must be kind correct: Each <a>Type</a>
--   in the substitution must map to a <a>Type</a> of the same kind.
data Subst
emptySubst :: Subst

-- | Reasons to reject a single-variable substitution.
data SubstError

-- | <a>Type</a> maps to a type containing the same variable.
SubstRecursive :: SubstError

-- | <a>Type</a> maps to a type containing one or more out-of-scope bound
--   variables.
SubstEscaped :: [TParam] -> SubstError

-- | <a>Type</a> maps to a type with a different kind.
SubstKindMismatch :: Kind -> Kind -> SubstError
singleSubst :: TVar -> Type -> Either SubstError Subst
singleTParamSubst :: TParam -> Type -> Subst
uncheckedSingleSubst :: TVar -> Type -> Subst
(@@) :: Subst -> Subst -> Subst

-- | A defaulting substitution maps all otherwise-unmapped free variables
--   to a kind-appropriate default type (<tt>Bit</tt> for value types and
--   <tt>0</tt> for numeric types).
defaultingSubst :: Subst -> Subst

-- | Makes a substitution out of a list. WARNING: We do not validate the
--   list in any way, so the caller should ensure that we end up with a
--   valid (e.g., idempotent) substitution.
listSubst :: [(TVar, Type)] -> Subst

-- | Makes a substitution out of a list. WARNING: We do not validate the
--   list in any way, so the caller should ensure that we end up with a
--   valid (e.g., idempotent) substitution.
listParamSubst :: [(TParam, Type)] -> Subst
isEmptySubst :: Subst -> Bool
class FVS t
fvs :: FVS t => t -> Set TVar

-- | Apply a substitution. Returns <a>Nothing</a> if nothing changed.
apSubstMaybe :: Subst -> Type -> Maybe Type
class TVars t

-- | Replaces free variables. To prevent space leaks when used with large
--   <a>Subst</a> values, every instance of <a>apSubst</a> should satisfy a
--   strictness property: Forcing evaluation of <tt><a>apSubst</a> s x</tt>
--   should also force the evaluation of all recursive calls to
--   <tt><a>apSubst</a> s</tt>. This ensures that unevaluated thunks will
--   not cause <a>Subst</a> values to be retained on the heap.
apSubst :: TVars t => Subst -> t -> t

-- | Apply the substitution to the keys of a type map.
apSubstTypeMapKeys :: Subst -> TypeMap a -> TypeMap a
substBinds :: Subst -> Set TVar
applySubstToVar :: Subst -> TVar -> Maybe Type
substToList :: Subst -> [(TVar, Type)]

-- | Strict variant of <a>fmap</a>.
fmap' :: Traversable t => (a -> b) -> t a -> t b

-- | Left-associative variant of the strict application operator <a>$!</a>.
(!$) :: (a -> b) -> a -> b
infixl 0 !$

-- | Left-associative variant of the application operator <a>$</a>.
(.$) :: (a -> b) -> a -> b
infixl 0 .$
mergeDistinctSubst :: [Subst] -> Subst
instance GHC.Show.Show Cryptol.TypeCheck.Subst.Subst
instance Data.Traversable.Traversable Cryptol.TypeCheck.Subst.Done
instance Data.Foldable.Foldable Cryptol.TypeCheck.Subst.Done
instance GHC.Base.Functor Cryptol.TypeCheck.Subst.Done
instance Cryptol.TypeCheck.Subst.TVars t => Cryptol.TypeCheck.Subst.TVars (GHC.Maybe.Maybe t)
instance Cryptol.TypeCheck.Subst.TVars t => Cryptol.TypeCheck.Subst.TVars [t]
instance (Cryptol.TypeCheck.Subst.TVars s, Cryptol.TypeCheck.Subst.TVars t) => Cryptol.TypeCheck.Subst.TVars (s, t)
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.Type.Type
instance (Data.Traversable.Traversable m, Cryptol.TypeCheck.Subst.TVars a) => Cryptol.TypeCheck.Subst.TVars (Cryptol.TypeCheck.TypeMap.List m a)
instance Cryptol.TypeCheck.Subst.TVars a => Cryptol.TypeCheck.Subst.TVars (Cryptol.TypeCheck.TypeMap.TypeMap a)
instance Cryptol.TypeCheck.Subst.TVars a => Cryptol.TypeCheck.Subst.TVars (Data.Map.Internal.Map k a)
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.Type.TySyn
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.Type.Schema
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.AST.Expr
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.AST.Match
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.AST.DeclGroup
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.AST.Decl
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.AST.DeclDef
instance Cryptol.TypeCheck.Subst.TVars (Cryptol.TypeCheck.AST.ModuleG names)
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.AST.TCTopEntity
instance GHC.Base.Applicative Cryptol.TypeCheck.Subst.Done
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Subst.Subst)
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Subst.Subst


module Cryptol.TypeCheck.Unify

-- | The most general unifier is a substitution and a set of constraints on
--   bound variables.
type MGU = (Subst, [Prop])
type Result a = Writer [(Path, UnificationError)] a
runResult :: Result a -> (a, [(Path, UnificationError)])
data UnificationError
UniTypeMismatch :: Type -> Type -> UnificationError
UniKindMismatch :: Kind -> Kind -> UnificationError
UniTypeLenMismatch :: Int -> Int -> UnificationError
UniRecursive :: TVar -> Type -> UnificationError
UniNonPolyDepends :: TVar -> [TParam] -> UnificationError
UniNonPoly :: TVar -> Type -> UnificationError
uniError :: Path -> UnificationError -> Result MGU
newtype Path
Path :: [PathElement] -> Path
data PathElement
TConArg :: TC -> Int -> PathElement
TNewtypeArg :: Newtype -> Int -> PathElement
TRecArg :: Ident -> PathElement
rootPath :: Path
isRootPath :: Path -> Bool
extPath :: Path -> PathElement -> Path
emptyMGU :: MGU
doMGU :: Type -> Type -> Result MGU
mgu :: Path -> Type -> Type -> Result MGU
mguMany :: Path -> [Path] -> [Type] -> [Type] -> Result MGU
bindVar :: Path -> TVar -> Type -> Result MGU
ppPathEl :: PathElement -> Int -> (Int -> Doc) -> Doc
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Unify.PathElement
instance GHC.Generics.Generic Cryptol.TypeCheck.Unify.PathElement
instance GHC.Show.Show Cryptol.TypeCheck.Unify.PathElement
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Unify.Path
instance GHC.Generics.Generic Cryptol.TypeCheck.Unify.Path
instance GHC.Show.Show Cryptol.TypeCheck.Unify.Path
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Unify.Path


module Cryptol.TypeCheck.TypeOf

-- | Given a typing environment and an expression, compute the type of the
--   expression as quickly as possible, assuming that the expression is
--   well formed with correct type annotations.
fastTypeOf :: Map Name Schema -> Expr -> Type
fastSchemaOf :: Map Name Schema -> Expr -> Schema


-- | Errors from typechecking foreign functions.
module Cryptol.TypeCheck.FFI.Error
data FFITypeError
FFITypeError :: Type -> FFITypeErrorReason -> FFITypeError
data FFITypeErrorReason
FFIBadWordSize :: FFITypeErrorReason
FFIBadFloatSize :: FFITypeErrorReason
FFIBadArrayType :: FFITypeErrorReason
FFIBadComponentTypes :: [FFITypeError] -> FFITypeErrorReason
FFIBadType :: FFITypeErrorReason
FFINotFunction :: FFITypeErrorReason
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.Error.FFITypeError
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.Error.FFITypeError
instance GHC.Show.Show Cryptol.TypeCheck.FFI.Error.FFITypeError
instance Control.DeepSeq.NFData Cryptol.TypeCheck.FFI.Error.FFITypeErrorReason
instance GHC.Generics.Generic Cryptol.TypeCheck.FFI.Error.FFITypeErrorReason
instance GHC.Show.Show Cryptol.TypeCheck.FFI.Error.FFITypeErrorReason
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.FFI.Error.FFITypeError
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.FFI.Error.FFITypeErrorReason
instance Cryptol.TypeCheck.Type.FVS Cryptol.TypeCheck.FFI.Error.FFITypeError
instance Cryptol.TypeCheck.Type.FVS Cryptol.TypeCheck.FFI.Error.FFITypeErrorReason
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.FFI.Error.FFITypeError)
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.FFI.Error.FFITypeErrorReason)


-- | Look for opportunity to solve goals by instantiating variables.
module Cryptol.TypeCheck.Solver.Improve

-- | Improvements from a bunch of propositions. Invariant: the substitions
--   should be already applied to the new sub-goals, if any.
improveProps :: Bool -> Ctxt -> [Prop] -> Match (Subst, [Prop])

-- | Improvements from a proposition. Invariant: the substitions should be
--   already applied to the new sub-goals, if any.
improveProp :: Bool -> Ctxt -> Prop -> Match (Subst, [Prop])
improveLit :: Bool -> Prop -> Match (Subst, [Prop])

-- | Improvements from equality constraints. Invariant: the substitions
--   should be already applied to the new sub-goals, if any.
improveEq :: Bool -> Ctxt -> Prop -> Match (Subst, [Prop])


module Cryptol.TypeCheck.Parseable
class ShowParseable t
showParseable :: ShowParseable t => t -> Doc Void
text :: String -> Doc a
int :: Int -> Doc a
($$) :: Doc a -> Doc a -> Doc a
infixl 5 $$
maybeNameDoc :: Maybe Name -> Doc Void
class ShowParseable t
showParseable :: ShowParseable t => t -> Doc Void
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.TypeCheck.AST.Expr
instance (Cryptol.TypeCheck.Parseable.ShowParseable a, Cryptol.TypeCheck.Parseable.ShowParseable b) => Cryptol.TypeCheck.Parseable.ShowParseable (a, b)
instance Cryptol.TypeCheck.Parseable.ShowParseable GHC.Types.Int
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.Utils.Ident.Ident
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.Parser.Selector.Selector
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.TypeCheck.AST.Match
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.TypeCheck.AST.Decl
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.TypeCheck.AST.DeclDef
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.TypeCheck.AST.DeclGroup
instance Cryptol.TypeCheck.Parseable.ShowParseable a => Cryptol.TypeCheck.Parseable.ShowParseable [a]
instance Cryptol.TypeCheck.Parseable.ShowParseable a => Cryptol.TypeCheck.Parseable.ShowParseable (GHC.Maybe.Maybe a)
instance Cryptol.TypeCheck.Parseable.ShowParseable a => Cryptol.TypeCheck.Parseable.ShowParseable (Cryptol.Parser.Position.Located a)
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.TypeCheck.Type.TParam
instance Cryptol.TypeCheck.Parseable.ShowParseable Cryptol.ModuleSystem.Name.Name

module Cryptol.TypeCheck.Interface

-- | Information about a declaration to be stored an in interface.
mkIfaceDecl :: Decl -> IfaceDecl

-- | Compute information about the names in a module.
genIfaceNames :: ModuleG name -> IfaceNames name

-- | Things defines by a module
genModDefines :: ModuleG name -> Set Name
genIface :: ModuleG name -> IfaceG name

-- | Generate an Iface from a typechecked module.
genIfaceWithNames :: IfaceNames name -> ModuleG ignored -> IfaceG name


-- | This module contains types used during type inference.
module Cryptol.TypeCheck.InferTypes
data SolverConfig
SolverConfig :: FilePath -> [String] -> Int -> [FilePath] -> SolverConfig

-- | The SMT solver to invoke
[solverPath] :: SolverConfig -> FilePath

-- | Additional arguments to pass to the solver
[solverArgs] :: SolverConfig -> [String]

-- | How verbose to be when type-checking
[solverVerbose] :: SolverConfig -> Int

-- | Look for the solver prelude in these locations.
[solverPreludePath] :: SolverConfig -> [FilePath]

-- | A default configuration for using Z3, where the solver prelude is
--   expected to be found in the given search path.
defaultSolverConfig :: [FilePath] -> SolverConfig

-- | The types of variables in the environment.
data VarType

-- | Known type
ExtVar :: Schema -> VarType

-- | Part of current SCC. The expression will replace the variable, after
--   we are done with the SCC. In this way a variable that gets generalized
--   is replaced with an appropriate instantiation of itself.
CurSCC :: Expr -> Type -> VarType
data Goals
Goals :: Set Goal -> Set Prop -> Map TVar LitGoal -> Map TVar LitGoal -> Goals

-- | A bunch of goals, not including the ones in <a>literalGoals</a>.
[goalSet] :: Goals -> Set Goal

-- | The set of nonliteral goals, saturated by all superclass implications
[saturatedPropSet] :: Goals -> Set Prop

-- | An entry <tt>(a,t)</tt> corresponds to <tt>Literal t a</tt>.
[literalGoals] :: Goals -> Map TVar LitGoal

-- | An entry <tt>(a,t)</tt> corresponds to <tt>LiteralLessThan t a</tt>.
[literalLessThanGoals] :: Goals -> Map TVar LitGoal

-- | This abuses the type <a>Goal</a> a bit. The <a>goal</a> field contains
--   only the numeric part of the Literal constraint. For example, <tt>(a,
--   Goal { goal = t })</tt> representats the goal for <tt>Literal t a</tt>
type LitGoal = Goal
litGoalToGoal :: (TVar, LitGoal) -> Goal
goalToLitGoal :: Goal -> Maybe (TVar, LitGoal)
litLessThanGoalToGoal :: (TVar, LitGoal) -> Goal
goalToLitLessThanGoal :: Goal -> Maybe (TVar, LitGoal)
emptyGoals :: Goals
nullGoals :: Goals -> Bool
fromGoals :: Goals -> [Goal]
goalsFromList :: [Goal] -> Goals
insertGoal :: Goal -> Goals -> Goals

-- | Something that we need to find evidence for.
data Goal
Goal :: ConstraintSource -> Range -> Prop -> Goal

-- | What it is about
[goalSource] :: Goal -> ConstraintSource

-- | Part of source code that caused goal
[goalRange] :: Goal -> Range

-- | What needs to be proved
[goal] :: Goal -> Prop
data HasGoal
HasGoal :: !Int -> Goal -> HasGoal

-- | This is the "name" of the constraint, used to find the solution for
--   ellaboration.
[hasName] :: HasGoal -> !Int
[hasGoal] :: HasGoal -> Goal

-- | A solution for a <a>HasGoal</a>
data HasGoalSln
HasGoalSln :: (Expr -> Expr) -> (Expr -> Expr -> Expr) -> HasGoalSln

-- | Select a specific field from the input expsression.
[hasDoSelect] :: HasGoalSln -> Expr -> Expr

-- | Set a field of the first expression to the second expression
[hasDoSet] :: HasGoalSln -> Expr -> Expr -> Expr

-- | Delayed implication constraints, arising from user-specified type
--   sigs.
data DelayedCt
DelayedCt :: Maybe Name -> [TParam] -> [Prop] -> [Goal] -> DelayedCt

-- | Signature that gave rise to this constraint Nothing means module
--   top-level
[dctSource] :: DelayedCt -> Maybe Name
[dctForall] :: DelayedCt -> [TParam]
[dctAsmps] :: DelayedCt -> [Prop]
[dctGoals] :: DelayedCt -> [Goal]

-- | Information about how a constraint came to be, used in error
--   reporting.
data ConstraintSource

-- | Computing shape of list comprehension
CtComprehension :: ConstraintSource

-- | Use of a split pattern
CtSplitPat :: ConstraintSource

-- | A type signature in a pattern or expression
CtTypeSig :: ConstraintSource

-- | Instantiation of this expression
CtInst :: Expr -> ConstraintSource
CtSelector :: ConstraintSource
CtExactType :: ConstraintSource
CtEnumeration :: ConstraintSource

-- | Just defaulting on the command line
CtDefaulting :: ConstraintSource

-- | Use of a partial type function.
CtPartialTypeFun :: Name -> ConstraintSource
CtImprovement :: ConstraintSource

-- | Constraints arising from type-checking patterns
CtPattern :: TypeSource -> ConstraintSource

-- | Instantiating a parametrized module
CtModuleInstance :: Range -> ConstraintSource

-- | Checking that a use of prop guards is exhastive
CtPropGuardsExhaustive :: Name -> ConstraintSource

-- | Constraints on a foreign declaration required by the FFI (e.g.
--   sequences must be finite)
CtFFI :: Name -> ConstraintSource
selSrc :: Selector -> TypeSource

-- | For use in error messages
cppKind :: Kind -> Doc
addTVarsDescsAfter :: FVS t => NameMap -> t -> Doc -> Doc
addTVarsDescsBefore :: FVS t => NameMap -> t -> Doc -> Doc
ppUse :: Expr -> Doc
instance Control.DeepSeq.NFData Cryptol.TypeCheck.InferTypes.SolverConfig
instance GHC.Generics.Generic Cryptol.TypeCheck.InferTypes.SolverConfig
instance GHC.Show.Show Cryptol.TypeCheck.InferTypes.SolverConfig
instance Control.DeepSeq.NFData Cryptol.TypeCheck.InferTypes.ConstraintSource
instance GHC.Generics.Generic Cryptol.TypeCheck.InferTypes.ConstraintSource
instance GHC.Show.Show Cryptol.TypeCheck.InferTypes.ConstraintSource
instance Control.DeepSeq.NFData Cryptol.TypeCheck.InferTypes.Goal
instance GHC.Generics.Generic Cryptol.TypeCheck.InferTypes.Goal
instance GHC.Show.Show Cryptol.TypeCheck.InferTypes.Goal
instance Control.DeepSeq.NFData Cryptol.TypeCheck.InferTypes.DelayedCt
instance GHC.Generics.Generic Cryptol.TypeCheck.InferTypes.DelayedCt
instance GHC.Show.Show Cryptol.TypeCheck.InferTypes.DelayedCt
instance GHC.Show.Show Cryptol.TypeCheck.InferTypes.HasGoal
instance GHC.Show.Show Cryptol.TypeCheck.InferTypes.Goals
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.InferTypes.Goals
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.InferTypes.HasGoal
instance Cryptol.TypeCheck.Type.FVS Cryptol.TypeCheck.InferTypes.DelayedCt
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.InferTypes.DelayedCt
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.InferTypes.DelayedCt)
instance GHC.Classes.Eq Cryptol.TypeCheck.InferTypes.Goal
instance GHC.Classes.Ord Cryptol.TypeCheck.InferTypes.Goal
instance Cryptol.TypeCheck.Type.FVS Cryptol.TypeCheck.InferTypes.Goal
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.InferTypes.Goal
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.InferTypes.Goal)
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.InferTypes.ConstraintSource
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.InferTypes.ConstraintSource


module Cryptol.TypeCheck.Solver.SMT

-- | An SMT solver packed with a logger for debugging.
data Solver
data SolverConfig

-- | Execute a computation with a fresh solver instance.
withSolver :: IO () -> SolverConfig -> (Solver -> IO a) -> IO a

-- | Start a fresh solver instance
startSolver :: IO () -> SolverConfig -> IO Solver

-- | Shut down a solver instance
stopSolver :: Solver -> IO ()

-- | Assumes no <tt>And</tt>
isNumeric :: Prop -> Bool
resetSolver :: Solver -> SolverConfig -> IO ()
debugBlock :: Solver -> String -> IO a -> IO a
debugLog :: DebugLog t => Solver -> t -> IO ()

-- | Returns goals that were not proved
proveImp :: Solver -> [Prop] -> [Goal] -> IO [Goal]

-- | Check if the given goals are known to be unsolvable.
checkUnsolvable :: Solver -> [Goal] -> IO Bool
tryGetModel :: Solver -> [TVar] -> [Prop] -> IO (Maybe [(TVar, Nat')])
shrinkModel :: Solver -> [TVar] -> [Prop] -> [(TVar, Nat')] -> IO [(TVar, Nat')]
inNewFrame :: Solver -> IO a -> IO a
type TVars = Map TVar SExpr
declareVars :: Solver -> [TVar] -> IO TVars
assume :: Solver -> TVars -> Prop -> IO ()

-- | Check if some numeric goals are known to be unsolvable.
unsolvable :: Solver -> TVars -> [Prop] -> IO Bool
instance Cryptol.TypeCheck.Solver.SMT.Mk ()
instance Cryptol.TypeCheck.Solver.SMT.Mk GHC.Num.Integer.Integer
instance Cryptol.TypeCheck.Solver.SMT.Mk Cryptol.TypeCheck.Type.TVar
instance Cryptol.TypeCheck.Solver.SMT.Mk Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.Solver.SMT.Mk (Cryptol.TypeCheck.Type.Type, Cryptol.TypeCheck.Type.Type)
instance Cryptol.TypeCheck.Solver.SMT.Mk (Cryptol.TypeCheck.Type.Type, Cryptol.TypeCheck.Type.Type, Cryptol.TypeCheck.Type.Type)
instance Cryptol.TypeCheck.Solver.SMT.DebugLog GHC.Types.Char
instance Cryptol.TypeCheck.Solver.SMT.DebugLog a => Cryptol.TypeCheck.Solver.SMT.DebugLog [a]
instance Cryptol.TypeCheck.Solver.SMT.DebugLog a => Cryptol.TypeCheck.Solver.SMT.DebugLog (GHC.Maybe.Maybe a)
instance Cryptol.TypeCheck.Solver.SMT.DebugLog Cryptol.Utils.PP.Doc
instance Cryptol.TypeCheck.Solver.SMT.DebugLog Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.Solver.SMT.DebugLog Cryptol.TypeCheck.InferTypes.Goal
instance Cryptol.TypeCheck.Solver.SMT.DebugLog Cryptol.TypeCheck.Subst.Subst

module Cryptol.TypeCheck.Error
cleanupErrors :: [(Range, Error)] -> [(Range, Error)]

-- | Should the first error suppress the next one.
subsumes :: (Range, Error) -> (Range, Error) -> Bool
data Warning
DefaultingKind :: TParam Name -> Kind -> Warning
DefaultingWildType :: Kind -> Warning
DefaultingTo :: !TVarInfo -> Type -> Warning
NonExhaustivePropGuards :: Name -> Warning

-- | Various errors that might happen during type checking/inference
data Error

-- | Expected kind, inferred kind
KindMismatch :: Maybe TypeSource -> Kind -> Kind -> Error

-- | Number of extra parameters, kind of result (which should not be of the
--   form <tt>_ -&gt; _</tt>)
TooManyTypeParams :: Int -> Kind -> Error

-- | A type variable was applied to some arguments.
TyVarWithParams :: Error

-- | Type-synonym, number of extra params
TooManyTySynParams :: Name -> Int -> Error

-- | Who is missing params, number of missing params
TooFewTyParams :: Name -> Int -> Error

-- | The type synonym declarations are recursive
RecursiveTypeDecls :: [Name] -> Error

-- | Expected type, inferred type
TypeMismatch :: TypeSource -> Path -> Type -> Type -> Error

-- | Name of module parameter, expected scehema, actual schema. This may
--   happen when instantiating modules.
SchemaMismatch :: Ident -> Schema -> Schema -> Error

-- | Unification results in a recursive type
RecursiveType :: TypeSource -> Path -> Type -> Type -> Error

-- | A constraint that we could not solve, usually because there are some
--   left-over variables that we could not infer.
UnsolvedGoals :: [Goal] -> Error

-- | A constraint that we could not solve and we know it is impossible to
--   do it.
UnsolvableGoals :: [Goal] -> Error

-- | A constraint (with context) that we could not solve
UnsolvedDelayedCt :: DelayedCt -> Error

-- | Type wild cards are not allowed in this context (e.g., definitions of
--   type synonyms).
UnexpectedTypeWildCard :: Error

-- | Unification variable depends on quantified variables that are not in
--   scope.
TypeVariableEscaped :: TypeSource -> Path -> Type -> [TParam] -> Error

-- | Quantified type variables (of kind *) need to match the given type, so
--   it does not work for all types.
NotForAll :: TypeSource -> Path -> TVar -> Type -> Error

-- | Too many positional type arguments, in an explicit type instantiation
TooManyPositionalTypeParams :: Error

-- | Kind other than <a>*</a> or <tt>#</tt> given to parameter of type
--   synonym, newtype, function signature, etc.
BadParameterKind :: TParam -> Kind -> Error
CannotMixPositionalAndNamedTypeParams :: Error
UndefinedTypeParameter :: Located Ident -> Error
RepeatedTypeParameter :: Ident -> [Range] -> Error

-- | Could not determine the value of a numeric type variable, but we know
--   it must be at least as large as the given type (or unconstrained, if
--   Nothing).
AmbiguousSize :: TVarInfo -> Maybe Type -> Error

-- | Bare expression of the form `{_}
BareTypeApp :: Error
UndefinedExistVar :: Name -> Error
TypeShadowing :: String -> Name -> String -> Error
MissingModTParam :: Located Ident -> Error
MissingModVParam :: Located Ident -> Error
MissingModParam :: Ident -> Error
FunctorInstanceMissingArgument :: Ident -> Error
FunctorInstanceBadArgument :: Ident -> Error
FunctorInstanceMissingName :: Namespace -> Ident -> Error
FunctorInstanceBadBacktick :: BadBacktickInstance -> Error

-- | Kind is not supported for FFI
UnsupportedFFIKind :: TypeSource -> TParam -> Kind -> Error

-- | Type is not supported for FFI
UnsupportedFFIType :: TypeSource -> FFITypeError -> Error

-- | Constraint guards may only apper at the top-level
NestedConstraintGuard :: Ident -> Error

-- | All declarataions in a recursive group involving constraint guards
--   should have signatures
DeclarationRequiresSignatureCtrGrd :: Ident -> Error

-- | The given constraint may not be used as a constraint guard
InvalidConstraintGuard :: Prop -> Error

-- | This is for errors that don't fit other cateogories. We should not use
--   it much, and is generally to be used for transient errors, which are
--   due to incomplete implementation.
TemporaryError :: Doc -> Error
data BadBacktickInstance
BIPolymorphicArgument :: Ident -> Ident -> BadBacktickInstance
BINested :: [(BIWhat, Name)] -> BadBacktickInstance
BIMultipleParams :: Ident -> BadBacktickInstance
data BIWhat
BIFunctor :: BIWhat
BIInterface :: BIWhat
BIPrimitive :: BIWhat
BIForeign :: BIWhat
BIAbstractType :: BIWhat

-- | When we have multiple errors on the same location, we show only the
--   ones with the has highest rating according to this function.
errorImportance :: Error -> Int
explainUnsolvable :: NameMap -> [Goal] -> Doc

-- | This picks the names to use when showing errors and warnings.
computeFreeVarNames :: [(Range, Warning)] -> [(Range, Error)] -> NameMap
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Error.Warning
instance GHC.Generics.Generic Cryptol.TypeCheck.Error.Warning
instance GHC.Show.Show Cryptol.TypeCheck.Error.Warning
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Error.BIWhat
instance GHC.Generics.Generic Cryptol.TypeCheck.Error.BIWhat
instance GHC.Show.Show Cryptol.TypeCheck.Error.BIWhat
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Error.BadBacktickInstance
instance GHC.Generics.Generic Cryptol.TypeCheck.Error.BadBacktickInstance
instance GHC.Show.Show Cryptol.TypeCheck.Error.BadBacktickInstance
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Error.Error
instance GHC.Generics.Generic Cryptol.TypeCheck.Error.Error
instance GHC.Show.Show Cryptol.TypeCheck.Error.Error
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.Error.Error
instance Cryptol.TypeCheck.Type.FVS Cryptol.TypeCheck.Error.Error
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Error.Error
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Error.Error)
instance Cryptol.TypeCheck.Subst.TVars Cryptol.TypeCheck.Error.Warning
instance Cryptol.TypeCheck.Type.FVS Cryptol.TypeCheck.Error.Warning
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Error.Warning
instance Cryptol.Utils.PP.PP (Cryptol.TypeCheck.PP.WithNames Cryptol.TypeCheck.Error.Warning)


module Cryptol.TypeCheck.Monad

-- | Information needed for type inference.
data InferInput
InferInput :: Range -> Map Name Schema -> Map Name TySyn -> Map Name Newtype -> Map Name AbstractType -> !Map Name ModParamNames -> (ModName -> Maybe (ModuleG (), IfaceG ())) -> (ModName -> Maybe ModParamNames) -> !ModParamNames -> NameSeeds -> Bool -> Bool -> [FilePath] -> !PrimMap -> !Supply -> Solver -> InferInput

-- | Location of program source
[inpRange] :: InferInput -> Range

-- | Variables that are in scope
[inpVars] :: InferInput -> Map Name Schema

-- | Type synonyms that are in scope
[inpTSyns] :: InferInput -> Map Name TySyn

-- | Newtypes in scope
[inpNewtypes] :: InferInput -> Map Name Newtype

-- | Abstract types in scope
[inpAbstractTypes] :: InferInput -> Map Name AbstractType

-- | Signatures in scope
[inpSignatures] :: InferInput -> !Map Name ModParamNames
[inpTopModules] :: InferInput -> ModName -> Maybe (ModuleG (), IfaceG ())
[inpTopSignatures] :: InferInput -> ModName -> Maybe ModParamNames
[inpParams] :: InferInput -> !ModParamNames

-- | Private state of type-checker
[inpNameSeeds] :: InferInput -> NameSeeds

-- | Should local bindings without signatures be monomorphized?
[inpMonoBinds] :: InferInput -> Bool

-- | Are we tracking call stacks?
[inpCallStacks] :: InferInput -> Bool

-- | Where to look for Cryptol theory file.
[inpSearchPath] :: InferInput -> [FilePath]

-- | This is used when the type-checker needs to refer to a predefined
--   identifier (e.g., <tt>number</tt>).
[inpPrimNames] :: InferInput -> !PrimMap

-- | The supply for fresh name generation
[inpSupply] :: InferInput -> !Supply

-- | Solver connection for typechecking
[inpSolver] :: InferInput -> Solver

-- | The results of type inference.
data InferOutput a

-- | We found some errors
InferFailed :: NameMap -> [(Range, Warning)] -> [(Range, Error)] -> InferOutput a

-- | Type inference was successful.
InferOK :: NameMap -> [(Range, Warning)] -> NameSeeds -> Supply -> a -> InferOutput a

-- | This is used for generating various names.
data NameSeeds
NameSeeds :: !Int -> !Int -> NameSeeds
[seedTVar] :: NameSeeds -> !Int
[seedGoal] :: NameSeeds -> !Int
newtype InferM a
IM :: ReaderT RO (StateT RW (ExceptionT [(Range, Error)] IO)) a -> InferM a
[unIM] :: InferM a -> ReaderT RO (StateT RW (ExceptionT [(Range, Error)] IO)) a

-- | Read-write component of the monad.
data RW
RW :: ![(Range, Error)] -> ![(Range, Warning)] -> !Subst -> [Map Name Type] -> Map Int HasGoalSln -> !NameSeeds -> !Goals -> ![[HasGoal]] -> ![ModuleG ScopeName] -> !Map Name Schema -> !Supply -> RW

-- | Collected errors
[iErrors] :: RW -> ![(Range, Error)]

-- | Collected warnings
[iWarnings] :: RW -> ![(Range, Warning)]

-- | Accumulated substitution
[iSubst] :: RW -> !Subst

-- | These keeps track of what existential type variables are available.
--   When we start checking a function, we push a new scope for its
--   arguments, and we pop it when we are done checking the function body.
--   The front element of the list is the current scope, which is the only
--   thing that will be modified, as follows. When we encounter a
--   existential type variable: 1. we look in all scopes to see if it is
--   already defined. 2. if it was not defined, we create a fresh type
--   variable, and we add it to the current scope. 3. it is an error if we
--   encounter an existential variable but we have no current scope.
[iExistTVars] :: RW -> [Map Name Type]

-- | Selector constraints that have been solved (ref. iSolvedSelectorsLazy)
[iSolvedHas] :: RW -> Map Int HasGoalSln
[iNameSeeds] :: RW -> !NameSeeds

-- | Ordinary constraints
[iCts] :: RW -> !Goals

-- | Tuple/record projection constraints. These are separate from the other
--   constraints because solving them results in actual elaboration of the
--   term, indicating how to do the projection. The modification of the
--   term is done using lazyness, by looking up a thunk ahead of time
--   (<tt>iSolvedHasLazy</tt> in RO), which is filled in when the constrait
--   is solved (<tt>iSolvedHas</tt>). See also <a>selectorScope</a>.
[iHasCts] :: RW -> ![[HasGoal]]

-- | Nested scopes we are currently checking, most nested first. These are
--   basically partially built modules.
[iScope] :: RW -> ![ModuleG ScopeName]

-- | Types of variables that we know about. We don't worry about scoping
--   here because we assume the bindings all have different names.
[iBindTypes] :: RW -> !Map Name Schema
[iSupply] :: RW -> !Supply

-- | Read-only component of the monad.
data RO
RO :: Range -> Map Name VarType -> [TParam] -> (ModName -> Maybe (ModuleG (), IfaceG ())) -> (ModName -> Maybe ModParamNames) -> ModuleG ScopeName -> Map Int HasGoalSln -> Bool -> Bool -> Solver -> !PrimMap -> !IORef Int -> RO

-- | Source code being analysed
[iRange] :: RO -> Range

-- | Type of variable that are in scope These are only parameters vars that
--   are in recursive component we are checking at the moment. If a var is
--   not there, keep looking in the <a>iScope</a>
[iVars] :: RO -> Map Name VarType

-- | Type variable that are in scope
[iTVars] :: RO -> [TParam]

-- | An exteral top-level module. We need the actual module when we
--   instantiate functors, because currently the type-checker desugars such
--   modules.
[iExtModules] :: RO -> ModName -> Maybe (ModuleG (), IfaceG ())

-- | External top-level signatures.
[iExtSignatures] :: RO -> ModName -> Maybe ModParamNames

-- | These are things we know about, but are not part of the modules we are
--   currently constructing. XXX: this sould probably be an interface NOTE:
--   External functors should be looked up in <a>iExtModules</a> and not
--   here, as they may be top-level modules.
[iExtScope] :: RO -> ModuleG ScopeName

-- | NOTE: This field is lazy in an important way! It is the final version
--   of <a>iSolvedHas</a> in <a>RW</a>, and the two are tied together
--   through recursion. The field is here so that we can look thing up
--   before they are defined, which is OK because we don't need to know the
--   results until everything is done.
[iSolvedHasLazy] :: RO -> Map Int HasGoalSln

-- | When this flag is set to true, bindings that lack signatures in
--   where-blocks will never be generalized. Bindings with type signatures,
--   and all bindings at top level are unaffected.
[iMonoBinds] :: RO -> Bool

-- | When this flag is true, retain source location information in
--   typechecked terms
[iCallStacks] :: RO -> Bool
[iSolver] :: RO -> Solver
[iPrimNames] :: RO -> !PrimMap
[iSolveCounter] :: RO -> !IORef Int
data ScopeName
ExternalScope :: ScopeName
LocalScope :: ScopeName
SubModule :: Name -> ScopeName

-- | The Text is docs
SignatureScope :: Name -> Maybe Text -> ScopeName
TopSignatureScope :: ModName -> ScopeName
MTopModule :: ModName -> ScopeName
newtype KindM a
KM :: ReaderT KRO (StateT KRW InferM) a -> KindM a
[unKM] :: KindM a -> ReaderT KRO (StateT KRW InferM) a
data KRO
KRO :: Map Name TParam -> AllowWildCards -> KRO

-- | lazy map, with tparams.
[lazyTParams] :: KRO -> Map Name TParam

-- | are type-wild cards allowed?
[allowWild] :: KRO -> AllowWildCards
data KRW
KRW :: Map Name Kind -> [(ConstraintSource, [Prop])] -> KRW

-- | kinds of (known) vars.
[typeParams] :: KRW -> Map Name Kind
[kCtrs] :: KRW -> [(ConstraintSource, [Prop])]

-- | Do we allow wild cards in the given context.
data AllowWildCards
AllowWildCards :: AllowWildCards
NoWildCards :: AllowWildCards

-- | This is what's returned when we lookup variables during kind checking.
data LkpTyVar

-- | Locally bound variable.
TLocalVar :: TParam -> Maybe Kind -> LkpTyVar

-- | An outer binding.
TOuterVar :: TParam -> LkpTyVar

-- | The monadic computation is about the given range of source code. This
--   is useful for error reporting.
inRange :: Range -> InferM a -> InferM a

-- | Generate a new free type variable.
newTVar :: TypeSource -> Kind -> InferM TVar
newName :: (NameSeeds -> (a, NameSeeds)) -> InferM a
io :: IO a -> InferM a

-- | Perform the given computation in a new scope (i.e., the subcomputation
--   may use existential type variables). This is a different kind of scope
--   from the nested modules one.
inNewScope :: InferM a -> InferM a

-- | Retrieve the mapping between identifiers and declarations in the
--   prelude.
getPrimMap :: InferM PrimMap

-- | Get information about the things defined in the module. Note that, in
--   general, the interface may contain *more* than just the definitions in
--   the module, however the <tt>ifNames</tt> should indicate which ones
--   are part of the module.
lookupModule :: ImpName Name -> InferM (IfaceG ())

-- | The initial seeds, used when checking a fresh program. XXX: why does
--   this start at 10?
nameSeeds :: NameSeeds
runInferM :: TVars a => InferInput -> InferM a -> IO (InferOutput a)

-- | Lookup the type of a variable.
lookupVar :: Name -> InferM VarType
newLocalScope :: InferM ()
endLocalScope :: InferM ([DeclGroup], Map Name TySyn)
withTParams :: [TParam] -> InferM a -> InferM a

-- | Record that the two types should be syntactically equal.
unify :: TypeWithSource -> Type -> InferM [Prop]

-- | Record some constraints that need to be solved. The string explains
--   where the constraints came from.
newGoals :: ConstraintSource -> [Prop] -> InferM ()

-- | Generate an unknown type. The doc is a note about what is this type
--   about.
newType :: TypeSource -> Kind -> InferM Type

-- | Apply the accumulated substitution to something with free type
--   variables.
applySubst :: TVars t => t -> InferM t

-- | Specify the solution (<tt>Expr -&gt; Expr</tt>) for the given
--   constraint (<a>Int</a>).
solveHasGoal :: Int -> HasGoalSln -> InferM ()

-- | Generate a fresh variable name to be used in a local binding.
newLocalName :: Namespace -> Ident -> InferM Name
getCallStacks :: InferM Bool

-- | This is the current range that we are working on.
curRange :: InferM Range

-- | Report an error.
recordError :: Error -> InferM ()
bumpCounter :: InferM ()

-- | This introduces a new "selector scope" which is currently a module. I
--   think that it might be possible to have selectors scopes be groups of
--   recursive declarations instead, as we are not going to learn anything
--   additional once we are done with the recursive group that generated
--   the selectors constraints. We do it at the module level because this
--   allows us to report more errors at once.
--   
--   A selector scope does the following: * Keep track of the Has
--   constraints generated in this scope * Keep track of the solutions for
--   discharged selector constraints: - this uses a laziness trick where we
--   build up a map containing the solutions for the Has constraints in the
--   state - the *final* value for this map (i.e., at the value the end of
--   the scope) is passed in as thunk in the reader component of the moment
--   - as we type check expressions when we need the solution for a Has
--   constraint we look it up from the reader environment; note that since
--   the map is not yet built up we just get back a thunk, so we have to be
--   carefule to not force it until *after* we've solved the goals - all of
--   this happens in the `rec` block below * At the end of a selector scope
--   we make sure that all Has constraints were discharged. If not, we
--   *abort* further type checking. The reason for aborting rather than
--   just recording an error is that the expression which produce contains
--   thunks that will lead to non-termination if forced, and some
--   type-checking operations (e.g., instantiation a functor) require us to
--   traverse the expressions.
selectorScope :: InferM a -> InferM a

-- | If there are any recoded errors than abort firther type-checking.
abortIfErrors :: InferM ()
inRangeMb :: Maybe Range -> InferM a -> InferM a

-- | Report an error.
recordErrorLoc :: Maybe Range -> Error -> InferM ()
recordWarning :: Warning -> InferM ()
getSolver :: InferM Solver
newGoal :: ConstraintSource -> Prop -> InferM Goal

-- | Add a bunch of goals that need solving.
addGoals :: [Goal] -> InferM ()

-- | The constraints are removed, and returned to the caller. The
--   substitution IS applied to them.
getGoals :: InferM [Goal]
simpGoals :: [Goal] -> InferM [Goal]

-- | Collect the goals emitted by the given sub-computation. Does not emit
--   any new goals.
collectGoals :: InferM a -> InferM (a, [Goal])
simpGoal :: Goal -> InferM [Goal]

-- | Record a constraint that when we select from the first type, we should
--   get a value of the second type. The returned function should be used
--   to wrap the expression from which we are selecting (i.e., the record
--   or tuple). Plese note that the resulting expression should not be
--   forced before the constraint is solved.
newHasGoal :: Selector -> Type -> Type -> InferM HasGoalSln

-- | Generate a new name for a goal.
newGoalName :: InferM Int

-- | Add a previously generated <tt>Has</tt> constraint
addHasGoal :: HasGoal -> InferM ()

-- | Get the <tt>Has</tt> constraints. Each of this should either be
--   solved, or added back using <a>addHasGoal</a>.
getHasGoals :: InferM [HasGoal]

-- | Generate a new free type variable that depends on these additional
--   type parameters.
newTVar' :: TypeSource -> Set TParam -> Kind -> InferM TVar

-- | Return the keys of the bound variables that are in scope.
getBoundInScope :: InferM (Set TParam)

-- | Check that the given "flavor" of parameter is allowed to have the
--   given type, and raise an error if not
checkParamKind :: TParam -> TPFlavor -> Kind -> InferM ()

-- | Generate a new free type variable.
newTParam :: TParam Name -> TPFlavor -> Kind -> InferM TParam

-- | Generate a new version of a type parameter. We use this when
--   instantiating module parameters (the "backtick" imports)
freshTParam :: (Name -> TPFlavor) -> TParam -> InferM TParam

-- | Add to the accumulated substitution, checking that the datatype
--   invariant for <a>Subst</a> is maintained.
extendSubst :: Subst -> InferM ()

-- | Get the substitution that we have accumulated so far.
getSubst :: InferM Subst
applySubstPreds :: [Prop] -> InferM [Prop]
applySubstGoals :: [Goal] -> InferM [Goal]

-- | Variables that are either mentioned in the environment or in a
--   selector constraint.
varsWithAsmps :: InferM (Set TVar)

-- | Lookup a type variable. Return <a>Nothing</a> if there is no such
--   variable in scope, in which case we must be dealing with a type
--   constant.
lookupTParam :: Name -> InferM (Maybe TParam)

-- | Lookup the definition of a type synonym.
lookupTSyn :: Name -> InferM (Maybe TySyn)

-- | Returns the type synonyms that are currently in scope.
getTSyns :: InferM (Map Name TySyn)

-- | Lookup the definition of a newtype
lookupNewtype :: Name -> InferM (Maybe Newtype)

-- | Returns the newtype declarations that are in scope.
getNewtypes :: InferM (Map Name Newtype)
lookupAbstractType :: Name -> InferM (Maybe AbstractType)

-- | Returns the abstract type declarations that are in scope.
getAbstractTypes :: InferM (Map Name AbstractType)

-- | Lookup the kind of a parameter type
lookupParamType :: Name -> InferM (Maybe ModTParam)

-- | Returns the abstract function declarations
getParamTypes :: InferM (Map Name ModTParam)
lookupSignature :: ImpName Name -> InferM ModParamNames
getSignatures :: InferM (Map Name ModParamNames)

-- | Lookup an external (i.e., previously loaded) top module.
lookupTopModule :: ModName -> InferM (Maybe (ModuleG (), IfaceG ()))
lookupFunctor :: ImpName Name -> InferM (ModuleG ())

-- | Get an environment combining all nested scopes.
getScope :: Semigroup a => (ModuleG ScopeName -> a) -> InferM a
getCurDecls :: InferM (ModuleG ())
lookupModParam :: Ident -> InferM (Maybe ModParam)

-- | Check if we already have a name for this existential type variable
--   and, if so, return the definition. If not, try to create a new
--   definition, if this is allowed. If not, returns nothing.
existVar :: Name -> Kind -> InferM Type

-- | Constraints on the module's parameters.
getParamConstraints :: InferM [Located Prop]

-- | Get the set of bound type variables that are in scope.
getTVars :: InferM (Set Name)

-- | Retrieve the value of the `mono-binds` option.
getMonoBinds :: InferM Bool

-- | We disallow shadowing between type synonyms and type variables because
--   it is confusing. As a bonus, in the implementation we don't need to
--   worry about where we lookup things (i.e., in the variable or type
--   synonym environment.
checkTShadowing :: String -> Name -> InferM ()

-- | The sub-computation is performed with the given type parameter in
--   scope.
withTParam :: TParam -> InferM a -> InferM a

-- | Execute the given computation in a new top scope. The sub-computation
--   would typically be validating a module.
newScope :: ScopeName -> InferM ()
newSignatureScope :: Name -> Maybe Text -> InferM ()

-- | Update the current scope (first in the list). Assumes there is one.
updScope :: (ModuleG ScopeName -> ModuleG ScopeName) -> InferM ()
newTopSignatureScope :: ModName -> InferM ()

-- | Start a new submodule scope. The imports and exports are just used to
--   initialize an empty module. As we type check declarations they are
--   added to this module's scope.
newSubmoduleScope :: Name -> Maybe Text -> ExportSpec Name -> InferM ()
newModuleScope :: ModName -> ExportSpec Name -> InferM ()
endSubmodule :: InferM ()
endModule :: InferM TCTopEntity
endSignature :: InferM ()
endTopSignature :: InferM TCTopEntity
addDecls :: DeclGroup -> InferM ()

-- | The sub-computation is performed with the given type-synonym in scope.
addTySyn :: TySyn -> InferM ()
addNewtype :: Newtype -> InferM ()
addPrimType :: AbstractType -> InferM ()
addParamType :: ModTParam -> InferM ()
addSignatures :: Map Name ModParamNames -> InferM ()
addSubmodules :: Map Name (IfaceNames Name) -> InferM ()
addFunctors :: Map Name (ModuleG Name) -> InferM ()

-- | The sub-computation is performed with the given abstract function in
--   scope.
addParamFun :: ModVParam -> InferM ()

-- | Add some assumptions for an entire module
addParameterConstraints :: [Located Prop] -> InferM ()
addModParam :: ModParam -> InferM ()

-- | The sub-computation is performed with the given variable in scope.
withVarType :: Name -> VarType -> InferM a -> InferM a
withVarTypes :: [(Name, VarType)] -> InferM a -> InferM a
withVar :: Name -> Schema -> InferM a -> InferM a

-- | The sub-computation is performed with the given variables in scope.
withMonoType :: (Name, Located Type) -> InferM a -> InferM a

-- | The sub-computation is performed with the given variables in scope.
withMonoTypes :: Map Name (Located Type) -> InferM a -> InferM a

-- | The arguments to this function are as follows:
--   
--   (type param. name, kind signature (opt.), type parameter)
--   
--   The type parameter is just a thunk that we should not force. The
--   reason is that the parameter depends on the kind that we are in the
--   process of computing.
--   
--   As a result we return the value of the sub-computation and the
--   computed kinds of the type parameters.
runKindM :: AllowWildCards -> [(Name, Maybe Kind, TParam)] -> KindM a -> InferM (a, Map Name Kind, [(ConstraintSource, [Prop])])

-- | Check if a name refers to a type variable.
kLookupTyVar :: Name -> KindM (Maybe LkpTyVar)

-- | Are type wild-cards OK in this context?
kWildOK :: KindM AllowWildCards

-- | Reports an error.
kRecordError :: Error -> KindM ()
kInInferM :: InferM a -> KindM a
kRecordWarning :: Warning -> KindM ()
kIO :: IO a -> KindM a

-- | Generate a fresh unification variable of the given kind. NOTE: We do
--   not simplify these, because we end up with bottom. See <a>hs</a> XXX:
--   Perhaps we can avoid the recursion?
kNewType :: TypeSource -> Kind -> KindM Type

-- | Lookup the definition of a type synonym.
kLookupTSyn :: Name -> KindM (Maybe TySyn)

-- | Lookup the definition of a newtype.
kLookupNewtype :: Name -> KindM (Maybe Newtype)
kLookupParamType :: Name -> KindM (Maybe ModTParam)
kLookupAbstractType :: Name -> KindM (Maybe AbstractType)
kExistTVar :: Name -> Kind -> KindM Type

-- | Replace the given bound variables with concrete types.
kInstantiateT :: Type -> [(TParam, Type)] -> KindM Type

-- | Record the kind for a local type variable. This assumes that we
--   already checked that there was no other valid kind for the variable
--   (if there was one, it gets over-written).
kSetKind :: Name -> Kind -> KindM ()

-- | The sub-computation is about the given range of the source code.
kInRange :: Range -> KindM a -> KindM a
kNewGoals :: ConstraintSource -> [Prop] -> KindM ()
instance Control.DeepSeq.NFData Cryptol.TypeCheck.Monad.NameSeeds
instance GHC.Generics.Generic Cryptol.TypeCheck.Monad.NameSeeds
instance GHC.Show.Show Cryptol.TypeCheck.Monad.NameSeeds
instance GHC.Show.Show a => GHC.Show.Show (Cryptol.TypeCheck.Monad.InferOutput a)
instance GHC.Base.Functor Cryptol.TypeCheck.Monad.KindM
instance GHC.Base.Applicative Cryptol.TypeCheck.Monad.KindM
instance GHC.Base.Monad Cryptol.TypeCheck.Monad.KindM
instance Control.Monad.Fail.MonadFail Cryptol.TypeCheck.Monad.KindM
instance GHC.Base.Functor Cryptol.TypeCheck.Monad.InferM
instance GHC.Base.Applicative Cryptol.TypeCheck.Monad.InferM
instance GHC.Base.Monad Cryptol.TypeCheck.Monad.InferM
instance Control.Monad.Fail.MonadFail Cryptol.TypeCheck.Monad.InferM
instance Control.Monad.Fix.MonadFix Cryptol.TypeCheck.Monad.InferM
instance Cryptol.ModuleSystem.Name.FreshM Cryptol.TypeCheck.Monad.InferM


module Cryptol.TypeCheck.Solver.Selector

-- | Solve has-constraints.
tryHasGoal :: HasGoal -> InferM (Bool, Bool)


module Cryptol.TypeCheck.Sanity
tcExpr :: InferInput -> Expr -> Either (Range, Error) (Schema, [ProofObligation])
tcDecls :: InferInput -> [DeclGroup] -> Either (Range, Error) [ProofObligation]
tcModule :: InferInput -> Module -> Either (Range, Error) [ProofObligation]
type ProofObligation = Schema
onlyNonTrivial :: [ProofObligation] -> [ProofObligation]
data Error

-- | expected, actual
TypeMismatch :: String -> Schema -> Schema -> Error

-- | expected a mono type, got this
ExpectedMono :: Schema -> Error
TupleSelectorOutOfRange :: Int -> Int -> Error
MissingField :: Ident -> [Ident] -> Error
UnexpectedTupleShape :: Int -> Int -> Error
UnexpectedRecordShape :: [Ident] -> [Ident] -> Error
UnexpectedSequenceShape :: Int -> Type -> Error
BadSelector :: Selector -> Type -> Error
BadInstantiation :: Error
Captured :: TVar -> Error
BadProofNoAbs :: Error
BadProofTyVars :: [TParam] -> Error
KindMismatch :: Kind -> Kind -> Error
NotEnoughArgumentsInKind :: Kind -> Error
BadApplication :: Type -> Type -> Error
FreeTypeVariable :: TVar -> Error
BadTypeApplication :: Kind -> [Kind] -> Error
RepeatedVariableInForall :: TParam -> Error
BadMatch :: Type -> Error
EmptyArm :: Error
UndefinedTypeVaraible :: TVar -> Error
UndefinedVariable :: Name -> Error
data AreSame
SameIf :: [Prop] -> AreSame
NotSame :: AreSame
same :: Same a => a -> a -> AreSame
instance GHC.Show.Show Cryptol.TypeCheck.Sanity.Error
instance GHC.Base.Functor Cryptol.TypeCheck.Sanity.TcM
instance GHC.Base.Applicative Cryptol.TypeCheck.Sanity.TcM
instance GHC.Base.Monad Cryptol.TypeCheck.Sanity.TcM
instance Cryptol.Utils.PP.PP Cryptol.TypeCheck.Sanity.Error
instance (GHC.Classes.Eq a, Cryptol.TypeCheck.Sanity.Same b) => Cryptol.TypeCheck.Sanity.Same (Cryptol.TypeCheck.Sanity.Field a b)
instance Cryptol.TypeCheck.Sanity.Same Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.Sanity.Same a => Cryptol.TypeCheck.Sanity.Same [a]
instance Cryptol.TypeCheck.Sanity.Same Cryptol.TypeCheck.Type.Schema
instance Cryptol.TypeCheck.Sanity.Same Cryptol.TypeCheck.Type.TParam

module Cryptol.TypeCheck.ModuleBacktickInstance
type MBQual a = (Maybe ModName, a)

-- | Rewrite declarations to add the given module parameters. Assumes the
--   renaming due to the instantiation has already happened. The module
--   being rewritten should not contain any nested functors (or module with
--   only top-level constraints) because it is not clear how to
--   parameterize the parameters.
doBacktickInstance :: Set (MBQual TParam) -> [Prop] -> Map (MBQual Name) Type -> ModuleG (Located (ImpName Name)) -> InferM (ModuleG (Located (ImpName Name)))
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewVal a => Cryptol.TypeCheck.ModuleBacktickInstance.RewVal [a]
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewVal b => Cryptol.TypeCheck.ModuleBacktickInstance.RewVal (Cryptol.Utils.RecordMap.RecordMap a b)
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewVal Cryptol.TypeCheck.AST.Expr
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewVal Cryptol.TypeCheck.AST.DeclGroup
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewVal Cryptol.TypeCheck.AST.Decl
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewVal Cryptol.TypeCheck.AST.DeclDef
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewVal Cryptol.TypeCheck.AST.Match
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewType Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewType a => Cryptol.TypeCheck.ModuleBacktickInstance.RewType [a]
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewType b => Cryptol.TypeCheck.ModuleBacktickInstance.RewType (Cryptol.Utils.RecordMap.RecordMap a b)
instance Cryptol.TypeCheck.ModuleBacktickInstance.RewType Cryptol.TypeCheck.Type.Schema
instance Cryptol.TypeCheck.ModuleBacktickInstance.AddParams Cryptol.TypeCheck.Type.Newtype
instance Cryptol.TypeCheck.ModuleBacktickInstance.AddParams Cryptol.TypeCheck.Type.TySyn
instance Cryptol.TypeCheck.ModuleBacktickInstance.AddParams Cryptol.TypeCheck.AST.Decl
instance Cryptol.TypeCheck.ModuleBacktickInstance.AddParams a => Cryptol.TypeCheck.ModuleBacktickInstance.AddParams (Data.Map.Internal.Map Cryptol.ModuleSystem.Name.Name a)
instance Cryptol.TypeCheck.ModuleBacktickInstance.AddParams a => Cryptol.TypeCheck.ModuleBacktickInstance.AddParams [a]
instance Cryptol.TypeCheck.ModuleBacktickInstance.AddParams Cryptol.TypeCheck.AST.DeclGroup

module Cryptol.TypeCheck.Default

-- | We default constraints of the form <tt>Literal t a</tt> and
--   <tt>FLiteral m n r a</tt>.
--   
--   For <tt>Literal t a</tt> we examine the context of constraints on the
--   type <tt>a</tt> to decide how to default. If <tt>Logic a</tt> is
--   required, we cannot do any defaulting. Otherwise, we default to either
--   <tt>Integer</tt> or <tt>Rational</tt>. In particular, if we need to
--   satisfy the <tt>Field a</tt>, constraint, we choose <tt>Rational</tt>
--   and otherwise we choose <tt>Integer</tt>.
--   
--   For <tt>FLiteral t a</tt> we always default to <tt>Rational</tt>.
defaultLiterals :: [TVar] -> [Goal] -> ([TVar], Subst, [Warning])
flitDefaultCandidates :: Goals -> Map TVar (Maybe ((TVar, Type), Warning))
improveByDefaultingWithPure :: [TVar] -> [Goal] -> ([TVar], [Goal], Subst, [Error])

-- | Try to pick a reasonable instantiation for an expression with the
--   given type. This is useful when we do evaluation at the REPL. The
--   resulting types should satisfy the constraints of the schema. The
--   parameters should be all of numeric kind, and the props should als be
--   numeric
defaultReplExpr' :: Solver -> [TParam] -> [Prop] -> IO (Maybe [(TParam, Type)])


module Cryptol.TypeCheck.Solve
simplifyAllConstraints :: InferM ()

-- | Prove an implication, and return any improvements that we computed.
--   Records errors, if any of the goals couldn't be solved.
proveImplication :: Bool -> Maybe Name -> [TParam] -> [Prop] -> [Goal] -> InferM Subst

-- | Tries to prove an implication. If proved, then returns `Right (m_su ::
--   InferM Subst)` where <tt>m_su</tt> is an <a>InferM</a> computation
--   that results in the solution substitution, and records any warning
--   invoked during proving. If not proved, then returns `Left (m_err ::
--   InferM ())`, which records all errors invoked during proving.
tryProveImplication :: Maybe Name -> [TParam] -> [Prop] -> [Goal] -> InferM Bool

-- | Try to clean-up any left-over constraints after we've checked
--   everything in a module. Typically these are either trivial things, or
--   constraints on the module's type parameters.
proveModuleTopLevel :: InferM ()
defaultAndSimplify :: [TVar] -> [Goal] -> ([TVar], [Goal], Subst, [Warning], [Error])
defaultReplExpr :: Solver -> Expr -> Schema -> IO (Maybe ([(TParam, Type)], Expr))


module Cryptol.TypeCheck.Kind
checkType :: Type Name -> Maybe Kind -> InferM Type

-- | Check a type signature. Returns validated schema, and any implicit
--   constraints that we inferred.
checkSchema :: AllowWildCards -> Schema Name -> InferM (Schema, [Goal])

-- | Check a newtype declaration. XXX: Do something with constraints.
checkNewtype :: Newtype Name -> Maybe Text -> InferM Newtype
checkPrimType :: PrimType Name -> Maybe Text -> InferM AbstractType

-- | Check a type-synonym declaration.
checkTySyn :: TySyn Name -> Maybe Text -> InferM TySyn

-- | Check a constraint-synonym declaration.
checkPropSyn :: PropSyn Name -> Maybe Text -> InferM TySyn

-- | Check a module parameter declarations. Nothing much to check, we just
--   translate from one syntax to another.
checkParameterType :: ParameterType Name -> InferM ModTParam
checkParameterConstraints :: [Located (Prop Name)] -> InferM [Located Prop]

-- | Validate parsed propositions that appear in the guard of a PropGuard.
--   
--   <ul>
--   <li>Note that we don't validate the well-formedness constraints
--   here---instead, they'd be validated when the signature for the auto
--   generated function corresponding guard is checked.</li>
--   <li>We also check that there are no wild-cards in the
--   constraints.</li>
--   </ul>
checkPropGuards :: [Located (Prop Name)] -> InferM [Prop]


module Cryptol.TypeCheck.Instantiate
instantiateWith :: Name -> Expr -> Schema -> [TypeArg] -> InferM (Expr, Type)
data TypeArg
TypeArg :: Maybe (Located Ident) -> MaybeCheckedType -> TypeArg
[tyArgName] :: TypeArg -> Maybe (Located Ident)
[tyArgType] :: TypeArg -> MaybeCheckedType
uncheckedTypeArg :: TypeInst Name -> TypeArg
data MaybeCheckedType
Checked :: Type -> MaybeCheckedType
Unchecked :: Type Name -> MaybeCheckedType


-- | This module implements a transformation, which tries to avoid
--   exponential slow down in some cases. What's the problem? Consider the
--   following (common) patterns:
--   
--   <pre>
--   fibs = [0,1] # [ x + y | x &lt;- fibs, y &lt;- drop`{1} fibs ]
--   </pre>
--   
--   The type of <tt>fibs</tt> is:
--   
--   <pre>
--   {a} (a &gt;= 1, fin a) =&gt; [inf][a]
--   </pre>
--   
--   Here <tt>a</tt> is the number of bits to be used in the values
--   computed by <tt>fibs</tt>. When we evaluate <tt>fibs</tt>, <tt>a</tt>
--   becomes a parameter to <tt>fibs</tt>, which works except that now
--   <tt>fibs</tt> is a function, and we don't get any of the memoization
--   we might expect! What looked like an efficient implementation has all
--   of a sudden become exponential!
--   
--   Note that this is only a problem for polymorphic values: if
--   <tt>fibs</tt> was already a function, it would not be that surprising
--   that it does not get cached.
--   
--   So, to avoid this, we try to spot recursive polymorphic values, where
--   the recursive occurrences have the exact same type parameters as the
--   definition. For example, this is the case in <tt>fibs</tt>: each
--   recursive call to <tt>fibs</tt> is instantiated with exactly the same
--   type parameter (i.e., <tt>a</tt>). The rewrite we do is as follows:
--   
--   <pre>
--   fibs : {a} (a &gt;= 1, fin a) =&gt; [inf][a]
--   fibs = \{a} (a &gt;= 1, fin a) -&gt; fibs'
--     where fibs' : [inf][a]
--           fibs' = [0,1] # [ x + y | x &lt;- fibs', y &lt;- drop`{1} fibs' ]
--   </pre>
--   
--   After the rewrite, the recursion is monomorphic (i.e., we are always
--   using the same type). As a result, <tt>fibs'</tt> is an ordinary
--   recursive value, where we get the benefit of caching.
--   
--   The rewrite is a bit more complex, when there are multiple mutually
--   recursive functions. Here is an example:
--   
--   <pre>
--   zig : {a} (a &gt;= 2, fin a) =&gt; [inf][a]
--   zig = [1] # zag
--   
--   zag : {a} (a &gt;= 2, fin a) =&gt; [inf][a]
--   zag = [2] # zig
--   </pre>
--   
--   This gets rewritten to:
--   
--   <pre>
--   newName : {a} (a &gt;= 2, fin a) =&gt; ([inf][a], [inf][a])
--   newName = \{a} (a &gt;= 2, fin a) -&gt; (zig', zag')
--     where
--     zig' : [inf][a]
--     zig' = [1] # zag'
--   
--     zag' : [inf][a]
--     zag' = [2] # zig'
--   
--   zig : {a} (a &gt;= 2, fin a) =&gt; [inf][a]
--   zig = \{a} (a &gt;= 2, fin a) -&gt; (newName a &lt;&gt; &lt;&gt; ).1
--   
--   zag : {a} (a &gt;= 2, fin a) =&gt; [inf][a]
--   zag = \{a} (a &gt;= 2, fin a) -&gt; (newName a &lt;&gt; &lt;&gt; ).2
--   </pre>
--   
--   NOTE: We are assuming that no capture would occur with binders. For
--   values, this is because we replaces things with freshly chosen
--   variables. For types, this should be because there should be no
--   shadowing in the types. XXX: Make sure that this really is the case
--   for types!!
module Cryptol.Transform.MonoValues

-- | Note that this assumes that this pass will be run only once for each
--   module, otherwise we will get name collisions.
rewModule :: Supply -> Module -> (Module, Supply)
instance Cryptol.TypeCheck.TypeMap.TrieMap Cryptol.Transform.MonoValues.RewMap' (Cryptol.ModuleSystem.Name.Name, [Cryptol.TypeCheck.Type.Type], GHC.Types.Int)


module Cryptol.ModuleSystem.NamingEnv

-- | The <a>NamingEnv</a> is used by the renamer to determine what
--   identifiers refer to.
newtype NamingEnv
NamingEnv :: Map Namespace (Map PName Names) -> NamingEnv

-- | This "joins" two naming environments by matching the text name. The
--   result maps the unique names from the first environment with the
--   matching names in the second. This is used to compute the naming for
--   an instantiated functor: * if the left environment has the defined
--   names of the functor, and * the right one has the defined names of the
--   instantiation, then * the result maps functor names to instance names.
zipByTextName :: NamingEnv -> NamingEnv -> Map Name Name

-- | Keep only the bindings in the 1st environment that are *NOT* in the
--   second.
without :: NamingEnv -> NamingEnv -> NamingEnv

-- | All names mentioned in the environment
namingEnvNames :: NamingEnv -> Set Name

-- | Get a unqualified naming environment for the given names
namingEnvFromNames :: Set Name -> NamingEnv

-- | Get the names in a given namespace
namespaceMap :: Namespace -> NamingEnv -> Map PName Names

-- | Resolve a name in the given namespace.
lookupNS :: Namespace -> PName -> NamingEnv -> Maybe Names

-- | Resolve a name in the given namespace.
lookupListNS :: Namespace -> PName -> NamingEnv -> [Name]

-- | Singleton renaming environment for the given namespace.
singletonNS :: Namespace -> PName -> Name -> NamingEnv

-- | Generate a mapping from <tt>PrimIdent</tt> to <a>Name</a> for a given
--   naming environment.
toPrimMap :: NamingEnv -> PrimMap

-- | Generate a display format based on a naming environment.
toNameDisp :: NamingEnv -> NameDisp

-- | Produce sets of visible names for types and declarations.
--   
--   NOTE: if entries in the NamingEnv would have produced a name clash,
--   they will be omitted from the resulting sets.
visibleNames :: NamingEnv -> Map Namespace (Set Name)

-- | Qualify all symbols in a <a>NamingEnv</a> with the given prefix.
qualify :: ModName -> NamingEnv -> NamingEnv
filterPNames :: (PName -> Bool) -> NamingEnv -> NamingEnv
filterUNames :: (Name -> Bool) -> NamingEnv -> NamingEnv

-- | Find the ambiguous entries in an environmet. A name is ambiguous if it
--   might refer to multiple entities.
findAmbig :: NamingEnv -> [[Name]]

-- | Get the subset of the first environment that shadows something in the
--   second one.
findShadowing :: NamingEnv -> NamingEnv -> [(PName, Name, [Name])]

-- | Do an arbitrary choice for ambiguous names. We do this to continue
--   checking afetr we've reported an ambiguity error.
forceUnambig :: NamingEnv -> NamingEnv

-- | Like mappend, but when merging, prefer values on the lhs.
shadowing :: NamingEnv -> NamingEnv -> NamingEnv
mapNamingEnv :: (Name -> Name) -> NamingEnv -> NamingEnv
travNamingEnv :: Applicative f => (Name -> f Name) -> NamingEnv -> f NamingEnv
isEmptyNamingEnv :: NamingEnv -> Bool

-- | Compute an unqualified naming environment, containing the various
--   module parameters.
modParamsNamingEnv :: ModParamNames -> NamingEnv

-- | Generate a naming environment from a declaration interface, where none
--   of the names are qualified.
unqualifiedEnv :: IfaceDecls -> NamingEnv

-- | Adapt the things exported by something to the specific import/open.
interpImportEnv :: ImportG name -> NamingEnv -> NamingEnv
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.NamingEnv.NamingEnv
instance GHC.Generics.Generic Cryptol.ModuleSystem.NamingEnv.NamingEnv
instance GHC.Show.Show Cryptol.ModuleSystem.NamingEnv.NamingEnv
instance GHC.Base.Monoid Cryptol.ModuleSystem.NamingEnv.NamingEnv
instance GHC.Base.Semigroup Cryptol.ModuleSystem.NamingEnv.NamingEnv
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.NamingEnv.NamingEnv


module Cryptol.Backend.Monad

-- | The monad for Cryptol evaluation. A computation is either "ready",
--   which means it represents only trivial computation, or is an "eval"
--   action which must be computed to get the answer, or it is a "thunk",
--   which represents a delayed, shared computation.
data Eval a
Ready :: !a -> Eval a
Eval :: !CallStack -> IO a -> Eval a
Thunk :: !TVar (ThunkState a) -> Eval a

-- | Execute the given evaluation action.
runEval :: CallStack -> Eval a -> IO a

-- | Lift an <a>IO</a> computation into the <a>Eval</a> monad.
io :: IO a -> Eval a

-- | Delay the given evaluation computation, returning a thunk which will
--   run the computation when forced. Run the <a>retry</a> computation
--   instead if the resulting thunk is forced during its own evaluation.
delayFill :: Eval a -> Maybe (Eval a) -> String -> Eval (Eval a)

-- | A computation that returns an already-evaluated value.
ready :: a -> Eval a

-- | Produce a thunk value which can be filled with its associated
--   computation after the fact. A preallocated thunk is returned, along
--   with an operation to fill the thunk with the associated computation.
--   This is used to implement recursive declaration groups.
blackhole :: String -> Eval (Eval a, Eval a -> Eval ())

-- | Begin executing the given operation in a separate thread, returning a
--   thunk which will await the completion of the computation when forced.
evalSpark :: Eval a -> Eval (Eval a)

-- | Test if a value is "ready", which means that it requires no
--   computation to return.
maybeReady :: Eval a -> Eval (Maybe a)

-- | The type of dynamic call stacks for the interpreter. New frames are
--   pushed onto the right side of the sequence.
data CallStack

-- | Get the current call stack
getCallStack :: Eval CallStack

-- | Execute the action with the given call stack
withCallStack :: CallStack -> Eval a -> Eval a

-- | Run the given action with a modify call stack
modifyCallStack :: (CallStack -> CallStack) -> Eval a -> Eval a

-- | Combine the call stack of a function value with the call stack of the
--   current calling context. This algorithm is the same one GHC uses to
--   compute profiling calling contexts.
--   
--   The algorithm is as follows.
--   
--   ccs ++&gt; ccsfn = ccs ++ dropCommonPrefix ccs ccsfn
--   
--   where
--   
--   dropCommonPrefix A B -- returns the suffix of B after removing any
--   prefix common -- to both A and B.
combineCallStacks :: CallStack -> CallStack -> CallStack

-- | Add a call frame to the top of a call stack
pushCallFrame :: Name -> Range -> CallStack -> CallStack

-- | Pretty print a call stack with each call frame on a separate line,
--   with most recent call frames at the top.
displayCallStack :: CallStack -> Doc
data Unsupported

-- | Operation cannot be supported in the symbolic simulator
UnsupportedSymbolicOp :: String -> Unsupported

-- | Data type describing errors that can occur during evaluation.
data EvalError

-- | Out-of-bounds index
InvalidIndex :: Maybe Integer -> EvalError

-- | Division or modulus by 0
DivideByZero :: EvalError

-- | Exponentiation by negative integer
NegativeExponent :: EvalError

-- | Logarithm of a negative integer
LogNegative :: EvalError

-- | Call to the Cryptol <tt>error</tt> primitive
UserError :: String -> EvalError

-- | Detectable nontermination
LoopError :: String -> EvalError

-- | Primitive with no implementation
NoPrim :: Name -> EvalError

-- | Invalid rounding mode
BadRoundingMode :: Integer -> EvalError

-- | Value outside the domain of a partial function.
BadValue :: String -> EvalError

-- | No prop guard holds for the given type variables.
NoMatchingPropGuardCase :: String -> EvalError

-- | Foreign function cannot be called
FFINotSupported :: Name -> EvalError

-- | Number passed to foreign function as a type argument is too large
FFITypeNumTooBig :: Name -> TParam -> Integer -> EvalError
data EvalErrorEx
EvalErrorEx :: CallStack -> EvalError -> EvalErrorEx

-- | Panic from an <tt>Eval</tt> context.
evalPanic :: HasCallStack => String -> [String] -> a

-- | For when we know that a word is too wide and will exceed gmp's limits
--   (though words approaching this size will probably cause the system to
--   crash anyway due to lack of memory).
wordTooWide :: Integer -> a
data WordTooWide

-- | Bitvector too large
WordTooWide :: Integer -> WordTooWide
instance GHC.Show.Show Cryptol.Backend.Monad.Unsupported
instance Cryptol.Utils.PP.PP Cryptol.Backend.Monad.WordTooWide
instance GHC.Show.Show Cryptol.Backend.Monad.WordTooWide
instance GHC.Exception.Type.Exception Cryptol.Backend.Monad.WordTooWide
instance Cryptol.Utils.PP.PP Cryptol.Backend.Monad.Unsupported
instance GHC.Exception.Type.Exception Cryptol.Backend.Monad.Unsupported
instance GHC.Base.Functor Cryptol.Backend.Monad.Eval
instance GHC.Base.Applicative Cryptol.Backend.Monad.Eval
instance GHC.Base.Monad Cryptol.Backend.Monad.Eval
instance Control.Monad.IO.Class.MonadIO Cryptol.Backend.Monad.Eval
instance Cryptol.Utils.PP.PP Cryptol.Backend.Monad.EvalErrorEx
instance GHC.Show.Show Cryptol.Backend.Monad.EvalErrorEx
instance GHC.Exception.Type.Exception Cryptol.Backend.Monad.EvalErrorEx
instance Cryptol.Utils.PP.PP Cryptol.Backend.Monad.EvalError
instance GHC.Show.Show Cryptol.Backend.Monad.EvalError
instance GHC.Base.Semigroup Cryptol.Backend.Monad.CallStack
instance GHC.Base.Monoid Cryptol.Backend.Monad.CallStack

module Cryptol.ModuleSystem.Binds

-- | Things that define exported names.
class BindsNames a
data TopDef
TopMod :: ModName -> Mod () -> TopDef
TopInst :: ModName -> ImpName PName -> ModuleInstanceArgs PName -> TopDef

-- | Things defined by a module
data Mod a
Mod :: [ImportG (ImpName PName)] -> ModKind -> Map Name (ImpName PName, ModuleInstanceArgs PName) -> Map Name (Mod a) -> NamingEnv -> !Set Name -> a -> Mod a
[modImports] :: Mod a -> [ImportG (ImpName PName)]
[modKind] :: Mod a -> ModKind
[modInstances] :: Mod a -> Map Name (ImpName PName, ModuleInstanceArgs PName)

-- | this includes signatures
[modMods] :: Mod a -> Map Name (Mod a)

-- | Things defined by this module. Note the for normal modules we really
--   just need the public names, however for things within functors we need
--   all defined names, so that we can generate fresh names in
--   instantiations
[modDefines] :: Mod a -> NamingEnv

-- | These are the exported names
[modPublic] :: Mod a -> !Set Name

-- | Used in the import loop to track the current state of processing. The
--   reason this is here, rather than just having a pair in the other
--   algorithm is because this type is recursive (for nested modules) and
--   it is conveninet to keep track for all modules at once
[modState] :: Mod a -> a
data ModKind
AFunctor :: ModKind
ASignature :: ModKind
AModule :: ModKind
modNested :: Mod a -> Set Name
modBuilder :: ModBuilder a -> Supply -> ((a, [RenamerError]), Supply)
topModuleDefs :: Module PName -> ModBuilder TopDef
topDeclsDefs :: ModPath -> [TopDecl PName] -> ModBuilder (Mod ())

-- | Given a name in a signature, make a name for the parameter
--   corresponding to the signature.
newModParam :: FreshM m => ModPath -> Ident -> Range -> Name -> m Name

-- | Do something in the context of a module. If <a>Nothing</a> than we are
--   working with a local declaration. Otherwise we are at the top-level of
--   the given module.
--   
--   By wrapping types with this, we can pass the module path to methods
--   that need the extra information.
data InModule a
InModule :: Maybe ModPath -> a -> InModule a

-- | Make a <a>Mod</a> from the public declarations in an interface. This
--   is used to handle imports.
ifaceToMod :: IfaceG name -> Mod ()
ifaceSigToMod :: ModParamNames -> Mod ()

-- | Generate a map from this module and all modules nested in it.
modToMap :: ImpName Name -> Mod () -> Map (ImpName Name) (Mod ()) -> Map (ImpName Name) (Mod ())

-- | Generate a <a>NamingEnv</a> using an explicit supply.
defsOf :: BindsNames a => a -> Supply -> (NamingEnv, Supply)
instance GHC.Show.Show a => GHC.Show.Show (Cryptol.ModuleSystem.Binds.InModule a)
instance Data.Foldable.Foldable Cryptol.ModuleSystem.Binds.InModule
instance Data.Traversable.Traversable Cryptol.ModuleSystem.Binds.InModule
instance GHC.Base.Functor Cryptol.ModuleSystem.Binds.InModule
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.Bind Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.TopDecl Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.NestedModule Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.PrimType Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.ParameterFun Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.ParameterType Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.Newtype Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.Decl Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.ModuleSystem.Binds.InModule (Cryptol.Parser.AST.SigDecl Cryptol.Parser.Name.PName))
instance Cryptol.ModuleSystem.Binds.BindsNames Cryptol.ModuleSystem.NamingEnv.NamingEnv
instance Cryptol.ModuleSystem.Binds.BindsNames a => Cryptol.ModuleSystem.Binds.BindsNames (GHC.Maybe.Maybe a)
instance Cryptol.ModuleSystem.Binds.BindsNames a => Cryptol.ModuleSystem.Binds.BindsNames [a]
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.Parser.AST.Schema Cryptol.Parser.Name.PName)
instance Cryptol.ModuleSystem.Binds.BindsNames (Cryptol.Parser.AST.TParam Cryptol.Parser.Name.PName)
instance GHC.Base.Semigroup Cryptol.ModuleSystem.Binds.BuildNamingEnv
instance GHC.Base.Monoid Cryptol.ModuleSystem.Binds.BuildNamingEnv
instance GHC.Base.Functor Cryptol.ModuleSystem.Binds.Mod


-- | This module deals with imports of nested modules (<tt>import
--   submodule</tt>). This is more complex than it might seem at first
--   because to resolve a declaration like <tt>import submodule X</tt> we
--   need to resolve what <tt>X</tt> referes to before we know what it will
--   import.
--   
--   Even triciker is the case for functor instantiations:
--   
--   module M = F { X } import M
--   
--   In this case, even if we know what <tt>M</tt> referes to, we first
--   need to resolve <tt>F</tt>, so that we can generate the instantiation
--   and generate fresh names for names defined by <tt>M</tt>.
--   
--   If we want to support applicative semantics, then before instantiation
--   <tt>M</tt> we also need to resolve <tt>X</tt> so that we know if this
--   instantiation has already been generated.
--   
--   An overall guiding principle of the design is that we assume that
--   declarations can be ordered in dependency order, and submodules can be
--   processed one at a time. In particular, this does not allow recursion
--   across modules, or functor instantiations depending on their
--   arguments.
--   
--   Thus, the following is OK:
--   
--   module A where x = 0x2
--   
--   submodule B where y = x
--   
--   z = B::y
--   
--   However, this is not OK:
--   
--   submodule A = F X submodule F where import A
module Cryptol.ModuleSystem.Renamer.Imports
resolveImports :: (ImpName Name -> Mod ()) -> TopDef -> Supply -> (Map (ImpName Name) ResolvedLocal, Supply)

-- | This represents a resolved module or signaure. The type parameter
--   helps us distinguish between two types of resolved modules:
--   
--   <ol>
--   <li>Resolved modules that are *inputs* to the algorithm (i.e., they
--   are defined outside the current module). For such modules the type
--   parameter is <tt>imps</tt> is ()</li>
--   <li>Resolved modules that are *outputs* of the algorithm (i.e., they
--   are defined within the current module). For such modules the type
--   parameter <tt>imps</tt> contains the naming environment for things
--   that came in through the import.</li>
--   </ol>
--   
--   Note that signaures are never "imported", however we do need to keep
--   them here so that signatures in a functor are properly instantiated
--   when the functor is instantiated.
data ResolvedModule imps
ResolvedModule :: NamingEnv -> !Set Name -> ModKind -> Set Name -> imps -> ResolvedModule imps

-- | Things defined by the module/signature.
[rmodDefines] :: ResolvedModule imps -> NamingEnv

-- | Exported names
[rmodPublic] :: ResolvedModule imps -> !Set Name

-- | What sort of thing are we
[rmodKind] :: ResolvedModule imps -> ModKind

-- | Modules and signatures nested in this one
[rmodNested] :: ResolvedModule imps -> Set Name

-- | Resolved imports. External modules need not specify this field, it is
--   just part of the thing we compute for local modules.
[rmodImports] :: ResolvedModule imps -> imps
data ModKind
AFunctor :: ModKind
ASignature :: ModKind
AModule :: ModKind

-- | A resolved module that's defined in (or is) the current top-level
--   module
type ResolvedLocal = ResolvedModule NamingEnv

-- | A resolved module that's not defined in the current top-level module
type ResolvedExt = ResolvedModule ()
instance Cryptol.ModuleSystem.Renamer.Imports.HasCurScope ()
instance Cryptol.ModuleSystem.Renamer.Imports.HasCurScope Cryptol.ModuleSystem.Renamer.Imports.Todo


module Cryptol.ModuleSystem.Renamer.Monad

-- | Indicates if a name is in a binding poisition or a use site
data NameType
NameBind :: NameType
NameUse :: NameType

-- | Information needed to do some renaming.
data RenamerInfo
RenamerInfo :: Supply -> ModPath -> NamingEnv -> Map ModName (Either ModParamNames Iface) -> RenamerInfo

-- | Use to make new names
[renSupply] :: RenamerInfo -> Supply

-- | We are renaming things in here
[renContext] :: RenamerInfo -> ModPath

-- | This is what's in scope
[renEnv] :: RenamerInfo -> NamingEnv

-- | External modules
[renIfaces] :: RenamerInfo -> Map ModName (Either ModParamNames Iface)
newtype RenameM a
RenameM :: ReaderT RO (StateT RW Lift) a -> RenameM a
[unRenameM] :: RenameM a -> ReaderT RO (StateT RW Lift) a
data RO
RO :: Range -> NamingEnv -> Map ModName (Maybe Iface, Map (ImpName Name) (Mod ())) -> ModPath -> Map ModPath Name -> Map (ImpName Name) ResolvedLocal -> Map Ident RenModParam -> Map Name DepName -> RO
[roLoc] :: RO -> Range
[roNames] :: RO -> NamingEnv

-- | Externally loaded modules. <a>Mod</a> is defined in <a>Binds</a>.
[roExternal] :: RO -> Map ModName (Maybe Iface, Map (ImpName Name) (Mod ()))

-- | Current module we are working on
[roCurMod] :: RO -> ModPath

-- | Maps module paths to the actual name for it. This is used for
--   dependency tracking, to find the name of a containing module. See the
--   note on <a>addDep</a>.
[roNestedMods] :: RO -> Map ModPath Name

-- | Info about locally defined modules
[roResolvedModules] :: RO -> Map (ImpName Name) ResolvedLocal

-- | Module parameters. These are used when rename the module parameters,
--   and only refer to the parameters of the current module (i.e., no outer
--   parameters as those are not needed)
[roModParams] :: RO -> Map Ident RenModParam

-- | Keeps track of which names were introduce by module parameters and
--   which one. The <a>DepName</a> is always a <a>ModParamName</a>.
[roFromModParam] :: RO -> Map Name DepName
data RW
RW :: ![RenamerWarning] -> !Set RenamerError -> !Supply -> !Map Name Int -> Set Name -> Map DepName (Set Name) -> !IfaceDecls -> RW
[rwWarnings] :: RW -> ![RenamerWarning]
[rwErrors] :: RW -> !Set RenamerError
[rwSupply] :: RW -> !Supply

-- | How many times did we refer to each name. Used to generate warnings
--   for unused definitions.
[rwNameUseCount] :: RW -> !Map Name Int

-- | keeps track of names *used* by something. see <a>depsOf</a>
[rwCurrentDeps] :: RW -> Set Name

-- | keeps track of the dependencies for things. see <a>depsOf</a>
[rwDepGraph] :: RW -> Map DepName (Set Name)

-- | Info about imported things, from external modules
[rwExternalDeps] :: RW -> !IfaceDecls
data RenModParam
RenModParam :: Ident -> Range -> ImpName Name -> Map Name Name -> RenModParam
[renModParamName] :: RenModParam -> Ident
[renModParamRange] :: RenModParam -> Range
[renModParamSig] :: RenModParam -> ImpName Name

-- | Maps names that come into scope through this parameter to the names in
--   the *module interface*. This is for functors, NOT functor
--   instantantiations.
[renModParamInstance] :: RenModParam -> Map Name Name
runRenamer :: RenamerInfo -> RenameM a -> (Either [RenamerError] (a, Supply), [RenamerWarning])
setCurMod :: ModPath -> RenameM a -> RenameM a
getCurMod :: RenameM ModPath
getNamingEnv :: RenameM NamingEnv
setResolvedLocals :: Map (ImpName Name) ResolvedLocal -> RenameM a -> RenameM a
lookupResolved :: ImpName Name -> RenameM ResolvedLocal
setModParams :: [RenModParam] -> RenameM a -> RenameM a
foldLoop :: [a] -> b -> (a -> b -> b) -> b
getModParam :: Ident -> RenameM RenModParam
getNamesFromModParams :: RenameM (Map Name DepName)
getLocalModParamDeps :: RenameM (Map Ident DepName)
setNestedModule :: Map ModPath Name -> RenameM a -> RenameM a
nestedModuleOrig :: ModPath -> RenameM (Maybe Name)

-- | Record an error.
recordError :: RenamerError -> RenameM ()
recordWarning :: RenamerWarning -> RenameM ()
collectIfaceDeps :: RenameM a -> RenameM (IfaceDecls, a)

-- | Rename something. All name uses in the sub-computation are assumed to
--   be dependenices of the thing.
depsOf :: DepName -> RenameM a -> RenameM a

-- | This is used when renaming a group of things. The result contains
--   dependencies between names defined in the group, and is intended to be
--   used to order the group members in dependency order.
depGroup :: RenameM a -> RenameM (a, Map DepName (Set Name))

-- | Get the source range for wahtever we are currently renaming.
curLoc :: RenameM Range

-- | Annotate something with the current range.
located :: a -> RenameM (Located a)

-- | Do the given computation using the source code range from <tt>loc</tt>
--   if any.
withLoc :: HasLoc loc => loc -> RenameM a -> RenameM a

-- | Shadow the current naming environment with some more names.
shadowNames :: BindsNames env => env -> RenameM a -> RenameM a
data EnvCheck

-- | Check for overlap and shadowing
CheckAll :: EnvCheck

-- | Only check for overlap
CheckOverlap :: EnvCheck

-- | Don't check the environment
CheckNone :: EnvCheck

-- | Report errors if the given naming environemnt contains multiple
--   definitions for the same symbol
checkOverlap :: NamingEnv -> RenameM NamingEnv

-- | Issue warnings if entries in the first environment would shadow
--   something in the second.
checkShadowing :: NamingEnv -> NamingEnv -> RenameM ()

-- | Shadow the current naming environment with some more names. XXX: The
--   checks are really confusing
shadowNames' :: BindsNames env => EnvCheck -> env -> RenameM a -> RenameM a
recordUse :: Name -> RenameM ()

-- | Mark something as a dependency. This is similar but different from
--   <a>recordUse</a>, in particular: * We only record use sites, not
--   bindings * We record all namespaces, not just types * We only keep
--   track of actual uses mentioned in the code. Otoh, <a>recordUse</a>
--   also considers exported entities to be used. * If we depend on a name
--   from a sibling submodule we add a dependency on the module in our
--   common ancestor. Examples: - <tt>A::B::x</tt> depends on
--   <tt>A::B::C::D::y</tt>, <tt>x</tt> depends on <tt>A::B::C</tt> -
--   <tt>A::B::x</tt> depends on <tt>A::P::Q::y</tt><tt>, </tt>x<tt>
--   depends on </tt>A::P@
addDep :: Name -> RenameM ()
warnUnused :: ModPath -> NamingEnv -> RW -> [RenamerWarning]
getExternal :: RenameM (ImpName Name -> Mod ())
getExternalMod :: ImpName Name -> RenameM (Mod ())

-- | Returns <a>Nothing</a> if the name does not refer to a module (i.e.,
--   it is a sig)
getTopModuleIface :: ImpName Name -> RenameM (Maybe Iface)

-- | Record an import: * record external dependency if the name refers to
--   an external import * record an error if the imported thing is a
--   functor
recordImport :: Range -> ImpName Name -> RenameM ()

-- | Lookup a name either in the locally resolved thing or in an external
--   module
lookupModuleThing :: ImpName Name -> RenameM (Either ResolvedLocal (Mod ()))
lookupDefines :: ImpName Name -> RenameM NamingEnv
checkIsModule :: Range -> ImpName Name -> ModKind -> RenameM ()
lookupDefinesAndSubs :: ImpName Name -> RenameM (NamingEnv, Set Name)
instance GHC.Show.Show Cryptol.ModuleSystem.Renamer.Monad.EnvCheck
instance GHC.Classes.Eq Cryptol.ModuleSystem.Renamer.Monad.EnvCheck
instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Cryptol.ModuleSystem.Renamer.Monad.RenameM a)
instance (GHC.Base.Semigroup a, GHC.Base.Monoid a) => GHC.Base.Monoid (Cryptol.ModuleSystem.Renamer.Monad.RenameM a)
instance GHC.Base.Functor Cryptol.ModuleSystem.Renamer.Monad.RenameM
instance GHC.Base.Applicative Cryptol.ModuleSystem.Renamer.Monad.RenameM
instance GHC.Base.Monad Cryptol.ModuleSystem.Renamer.Monad.RenameM
instance Cryptol.ModuleSystem.Name.FreshM Cryptol.ModuleSystem.Renamer.Monad.RenameM


module Cryptol.ModuleSystem.Renamer

-- | The <a>NamingEnv</a> is used by the renamer to determine what
--   identifiers refer to.
data NamingEnv

-- | Like mappend, but when merging, prefer values on the lhs.
shadowing :: NamingEnv -> NamingEnv -> NamingEnv

-- | Things that define exported names.
class BindsNames a

-- | Do something in the context of a module. If <a>Nothing</a> than we are
--   working with a local declaration. Otherwise we are at the top-level of
--   the given module.
--   
--   By wrapping types with this, we can pass the module path to methods
--   that need the extra information.
data InModule a
InModule :: Maybe ModPath -> a -> InModule a

-- | Shadow the current naming environment with some more names.
shadowNames :: BindsNames env => env -> RenameM a -> RenameM a
class Rename f
rename :: Rename f => f PName -> RenameM (f Name)
runRenamer :: RenamerInfo -> RenameM a -> (Either [RenamerError] (a, Supply), [RenamerWarning])
data RenameM a
data RenamerError

-- | Multiple imported symbols contain this name
MultipleSyms :: Located PName -> [Name] -> RenamerError

-- | Some name not bound to any definition
UnboundName :: Namespace -> Located PName -> RenamerError

-- | An environment has produced multiple overlapping symbols
OverlappingSyms :: [Name] -> RenamerError

-- | expected, actual. When a name is missing from the expected namespace,
--   but exists in another
WrongNamespace :: Namespace -> Namespace -> Located PName -> RenamerError

-- | When the fixity of two operators conflict
FixityError :: Located Name -> Fixity -> Located Name -> Fixity -> RenamerError

-- | When record updates overlap (e.g., <tt>{ r | x = e1, x.y = e2 }</tt>)
OverlappingRecordUpdate :: Located [Selector] -> Located [Selector] -> RenamerError

-- | Things that can't depend on each other
InvalidDependency :: [DepName] -> RenamerError

-- | Module parameters with the same name
MultipleModParams :: Ident -> [Range] -> RenamerError

-- | Can't import functors directly
InvalidFunctorImport :: ImpName Name -> RenamerError

-- | Nested modules were not supposed to appear here
UnexpectedNest :: Range -> PName -> RenamerError

-- | Exepcted one kind (first one) but found the other (second one)
ModuleKindMismatch :: Range -> ImpName Name -> ModKind -> ModKind -> RenamerError
data RenamerWarning
SymbolShadowed :: PName -> Name -> [Name] -> RenamerWarning
UnusedName :: Name -> RenamerWarning
PrefixAssocChanged :: PrefixOp -> Expr Name -> Located Name -> Fixity -> Expr Name -> RenamerWarning
renameVar :: NameType -> PName -> RenameM Name
renameType :: NameType -> PName -> RenameM Name

-- | Entry point. This is used for renaming a top-level module.
renameModule :: Module PName -> RenameM RenamedModule

-- | Entry point. Rename a list of top-level declarations. This is used for
--   declaration that don't live in a module (e.g., define on the command
--   line.)
--   
--   We assume that these declarations do not contain any nested modules.
renameTopDecls :: ModName -> [TopDecl PName] -> RenameM (NamingEnv, [TopDecl Name])

-- | Information needed to do some renaming.
data RenamerInfo
RenamerInfo :: Supply -> ModPath -> NamingEnv -> Map ModName (Either ModParamNames Iface) -> RenamerInfo

-- | Use to make new names
[renSupply] :: RenamerInfo -> Supply

-- | We are renaming things in here
[renContext] :: RenamerInfo -> ModPath

-- | This is what's in scope
[renEnv] :: RenamerInfo -> NamingEnv

-- | External modules
[renIfaces] :: RenamerInfo -> Map ModName (Either ModParamNames Iface)

-- | Indicates if a name is in a binding poisition or a use site
data NameType
NameBind :: NameType
NameUse :: NameType

-- | The result of renaming a module
data RenamedModule
RenamedModule :: Module Name -> NamingEnv -> NamingEnv -> IfaceDecls -> RenamedModule

-- | The renamed module
[rmModule] :: RenamedModule -> Module Name

-- | What this module defines
[rmDefines] :: RenamedModule -> NamingEnv

-- | What's in scope in this module
[rmInScope] :: RenamedModule -> NamingEnv

-- | Imported declarations. This provides the types for external names
--   (used by the type-checker).
[rmImported] :: RenamedModule -> IfaceDecls
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.TopDecl
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.ModParam
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.ImpName
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.ModuleInstanceArgs
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.ModuleInstanceNamedArg
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.ModuleInstanceArg
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.NestedModule
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.PrimType
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.ParameterType
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.ParameterFun
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.SigDecl
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Decl
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Newtype
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Schema
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.TParam
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Prop
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Type
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Bind
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.BindDef
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.PropGuardCase
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Pattern
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.UpdField
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.FunDesc
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Expr
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.TypeInst
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.Match
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.TySyn
instance Cryptol.ModuleSystem.Renamer.Rename Cryptol.Parser.AST.PropSyn
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Renamer.RenamedModule

module Cryptol.IR.TraverseNames
traverseNames :: (TraverseNames t, Applicative f) => (Name -> f Name) -> t -> f t
mapNames :: TraverseNames t => (Name -> Name) -> t -> t
class TraverseNames t
traverseNamesIP :: (TraverseNames t, Applicative f, ?name :: Name -> f Name) => t -> f t
instance Cryptol.IR.TraverseNames.TraverseNames a => Cryptol.IR.TraverseNames.TraverseNames [a]
instance Cryptol.IR.TraverseNames.TraverseNames a => Cryptol.IR.TraverseNames.TraverseNames (GHC.Maybe.Maybe a)
instance (GHC.Classes.Ord a, Cryptol.IR.TraverseNames.TraverseNames a) => Cryptol.IR.TraverseNames.TraverseNames (Data.Set.Internal.Set a)
instance Cryptol.IR.TraverseNames.TraverseNames a => Cryptol.IR.TraverseNames.TraverseNames (Cryptol.Parser.Position.Located a)
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.ModuleSystem.Name.Name
instance (GHC.Classes.Ord a, Cryptol.IR.TraverseNames.TraverseNames a) => Cryptol.IR.TraverseNames.TraverseNames (Cryptol.ModuleSystem.Exports.ExportSpec a)
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.AST.Expr
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.AST.Match
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.AST.DeclGroup
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.AST.Decl
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.AST.DeclDef
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.Schema
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.TParam
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.TPFlavor
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.TVarInfo
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.TypeSource
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.ArgDescr
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.Type
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.TCon.TCon
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.TCon.TC
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.TCon.UserTC
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.TVar
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.Newtype
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.ModTParam
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.ModVParam
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.FFI.FFIType.FFIFunType
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.FFI.FFIType.FFIType
instance Cryptol.IR.TraverseNames.TraverseNames Cryptol.TypeCheck.Type.TySyn

module Cryptol.TypeCheck.ModuleInstance

-- | `?tSu` should be applied to all types. `?vSu` shoudl be applied to all
--   values.
type Su = (?tSu :: Subst, ?vSu :: Map Name Name)

-- | Has value names but no types.
doVInst :: (Su, TraverseNames a) => a -> a

-- | Has types but not values.
doTInst :: (Su, TVars a) => a -> a

-- | Has both value names and types.
doTVInst :: (Su, TVars a, TraverseNames a) => a -> a
doMap :: (Su, ModuleInstance a) => Map Name a -> Map Name a
doSet :: Su => Set Name -> Set Name
class ModuleInstance t
moduleInstance :: (ModuleInstance t, Su) => t -> t
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance a => Cryptol.TypeCheck.ModuleInstance.ModuleInstance [a]
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance a => Cryptol.TypeCheck.ModuleInstance.ModuleInstance (Cryptol.Parser.Position.Located a)
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.ModuleSystem.Name.Name
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance name => Cryptol.TypeCheck.ModuleInstance.ModuleInstance (Cryptol.Parser.AST.ImpName name)
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance (Cryptol.TypeCheck.AST.ModuleG name)
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.Type
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.Schema
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.TySyn
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.Newtype
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.AbstractType
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.AST.DeclGroup
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.AST.Decl
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance name => Cryptol.TypeCheck.ModuleInstance.ModuleInstance (Cryptol.ModuleSystem.Interface.IfaceNames name)
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.ModParamNames
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.ModTParam
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.ModVParam
instance Cryptol.TypeCheck.ModuleInstance.ModuleInstance Cryptol.TypeCheck.Type.ModParam

module Cryptol.TypeCheck.Module
doFunctorInst :: Located (ImpName Name) -> Located (ImpName Name) -> ModuleInstanceArgs Name -> Map Name Name -> Maybe Text -> InferM (Maybe TCTopEntity)

module Cryptol.IR.FreeVars
class FreeVars e
freeVars :: FreeVars e => e -> Deps
data Deps
Deps :: Set Name -> Set Name -> Set TParam -> Deps

-- | Undefined value names
[valDeps] :: Deps -> Set Name

-- | Undefined type names (from newtype)
[tyDeps] :: Deps -> Set Name

-- | Undefined type params (e.d. mod params)
[tyParams] :: Deps -> Set TParam
class Defs d
defs :: Defs d => d -> Set Name

-- | Dependencies of top-level declarations in a module. These are
--   dependencies on module parameters or things defined outside the
--   module.
moduleDeps :: Module -> Map Name Deps

-- | Compute the transitive closure of the given dependencies.
transDeps :: Map Name Deps -> Map Name Deps
instance GHC.Classes.Eq Cryptol.IR.FreeVars.Deps
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.AST.DeclGroup
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.AST.Expr
instance Cryptol.IR.FreeVars.Defs a => Cryptol.IR.FreeVars.Defs [a]
instance Cryptol.IR.FreeVars.Defs Cryptol.TypeCheck.AST.DeclGroup
instance Cryptol.IR.FreeVars.Defs Cryptol.TypeCheck.AST.Decl
instance Cryptol.IR.FreeVars.Defs Cryptol.TypeCheck.AST.Match
instance Cryptol.IR.FreeVars.FreeVars e => Cryptol.IR.FreeVars.FreeVars [e]
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.AST.Decl
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.AST.DeclDef
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.AST.Match
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.Type.Schema
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.Type.Type
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.Type.TVar
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.TCon.TCon
instance Cryptol.IR.FreeVars.FreeVars Cryptol.TypeCheck.Type.Newtype
instance GHC.Base.Semigroup Cryptol.IR.FreeVars.Deps
instance GHC.Base.Monoid Cryptol.IR.FreeVars.Deps


-- | Generate C header files from foreign declarations.
module Cryptol.Eval.FFI.GenHeader

-- | Generate a C header file from the given foreign declarations.
generateForeignHeader :: [(Name, FFIFunType)] -> String
instance GHC.Classes.Ord Cryptol.Eval.FFI.GenHeader.Include
instance GHC.Classes.Eq Cryptol.Eval.FFI.GenHeader.Include


-- | Useful information about various types.
module Cryptol.Utils.Types

-- | Exponent and precision of 32-bit IEEE-754 floating point.
float32ExpPrec :: (Integer, Integer)

-- | Exponent and precision of 64-bit IEEE-754 floating point.
float64ExpPrec :: (Integer, Integer)


-- | Checking and conversion of <a>Type</a>s to <a>FFIType</a>s.
module Cryptol.TypeCheck.FFI

-- | Convert a <a>Schema</a> to a <a>FFIFunType</a>, along with any
--   <a>Prop</a>s that must be satisfied for the <a>FFIFunType</a> to be
--   valid.
toFFIFunType :: Schema -> Either FFITypeError ([Prop], FFIFunType)


-- | Assumes that the <tt>NoPat</tt> pass has been run.
module Cryptol.TypeCheck.Infer

-- | Infer the type of an expression, and translate it to a fully
--   elaborated core term.
checkE :: Expr Name -> TypeWithSource -> InferM Expr
checkSigB :: Bind Name -> (Schema, [Goal]) -> InferM Decl
inferTopModule :: Module Name -> InferM TCTopEntity

-- | <tt>inferBinds isTopLevel isRec binds</tt> performs inference for a
--   strongly-connected component of <a>Bind</a>s. If any of the members of
--   the recursive group are already marked as monomorphic, then we don't
--   do generalization. If <tt>isTopLevel</tt> is true, any bindings
--   without type signatures will be generalized. If it is false, and the
--   mono-binds flag is enabled, no bindings without type signatures will
--   be generalized, but bindings with signatures will be unaffected.
inferBinds :: Bool -> Bool -> [Bind Name] -> InferM [Decl]
checkTopDecls :: [TopDecl Name] -> InferM ()


module Cryptol.TypeCheck
tcModule :: Module Name -> InferInput -> IO (InferOutput TCTopEntity)
tcExpr :: Expr Name -> InferInput -> IO (InferOutput (Expr, Schema))
tcDecls :: [TopDecl Name] -> InferInput -> IO (InferOutput ([DeclGroup], Map Name TySyn))

-- | Information needed for type inference.
data InferInput
InferInput :: Range -> Map Name Schema -> Map Name TySyn -> Map Name Newtype -> Map Name AbstractType -> !Map Name ModParamNames -> (ModName -> Maybe (ModuleG (), IfaceG ())) -> (ModName -> Maybe ModParamNames) -> !ModParamNames -> NameSeeds -> Bool -> Bool -> [FilePath] -> !PrimMap -> !Supply -> Solver -> InferInput

-- | Location of program source
[inpRange] :: InferInput -> Range

-- | Variables that are in scope
[inpVars] :: InferInput -> Map Name Schema

-- | Type synonyms that are in scope
[inpTSyns] :: InferInput -> Map Name TySyn

-- | Newtypes in scope
[inpNewtypes] :: InferInput -> Map Name Newtype

-- | Abstract types in scope
[inpAbstractTypes] :: InferInput -> Map Name AbstractType

-- | Signatures in scope
[inpSignatures] :: InferInput -> !Map Name ModParamNames
[inpTopModules] :: InferInput -> ModName -> Maybe (ModuleG (), IfaceG ())
[inpTopSignatures] :: InferInput -> ModName -> Maybe ModParamNames
[inpParams] :: InferInput -> !ModParamNames

-- | Private state of type-checker
[inpNameSeeds] :: InferInput -> NameSeeds

-- | Should local bindings without signatures be monomorphized?
[inpMonoBinds] :: InferInput -> Bool

-- | Are we tracking call stacks?
[inpCallStacks] :: InferInput -> Bool

-- | Where to look for Cryptol theory file.
[inpSearchPath] :: InferInput -> [FilePath]

-- | This is used when the type-checker needs to refer to a predefined
--   identifier (e.g., <tt>number</tt>).
[inpPrimNames] :: InferInput -> !PrimMap

-- | The supply for fresh name generation
[inpSupply] :: InferInput -> !Supply

-- | Solver connection for typechecking
[inpSolver] :: InferInput -> Solver

-- | The results of type inference.
data InferOutput a

-- | We found some errors
InferFailed :: NameMap -> [(Range, Warning)] -> [(Range, Error)] -> InferOutput a

-- | Type inference was successful.
InferOK :: NameMap -> [(Range, Warning)] -> NameSeeds -> Supply -> a -> InferOutput a
data SolverConfig
SolverConfig :: FilePath -> [String] -> Int -> [FilePath] -> SolverConfig

-- | The SMT solver to invoke
[solverPath] :: SolverConfig -> FilePath

-- | Additional arguments to pass to the solver
[solverArgs] :: SolverConfig -> [String]

-- | How verbose to be when type-checking
[solverVerbose] :: SolverConfig -> Int

-- | Look for the solver prelude in these locations.
[solverPreludePath] :: SolverConfig -> [FilePath]

-- | A default configuration for using Z3, where the solver prelude is
--   expected to be found in the given search path.
defaultSolverConfig :: [FilePath] -> SolverConfig

-- | This is used for generating various names.
data NameSeeds

-- | The initial seeds, used when checking a fresh program. XXX: why does
--   this start at 10?
nameSeeds :: NameSeeds

-- | Various errors that might happen during type checking/inference
data Error

-- | Expected kind, inferred kind
KindMismatch :: Maybe TypeSource -> Kind -> Kind -> Error

-- | Number of extra parameters, kind of result (which should not be of the
--   form <tt>_ -&gt; _</tt>)
TooManyTypeParams :: Int -> Kind -> Error

-- | A type variable was applied to some arguments.
TyVarWithParams :: Error

-- | Type-synonym, number of extra params
TooManyTySynParams :: Name -> Int -> Error

-- | Who is missing params, number of missing params
TooFewTyParams :: Name -> Int -> Error

-- | The type synonym declarations are recursive
RecursiveTypeDecls :: [Name] -> Error

-- | Expected type, inferred type
TypeMismatch :: TypeSource -> Path -> Type -> Type -> Error

-- | Name of module parameter, expected scehema, actual schema. This may
--   happen when instantiating modules.
SchemaMismatch :: Ident -> Schema -> Schema -> Error

-- | Unification results in a recursive type
RecursiveType :: TypeSource -> Path -> Type -> Type -> Error

-- | A constraint that we could not solve, usually because there are some
--   left-over variables that we could not infer.
UnsolvedGoals :: [Goal] -> Error

-- | A constraint that we could not solve and we know it is impossible to
--   do it.
UnsolvableGoals :: [Goal] -> Error

-- | A constraint (with context) that we could not solve
UnsolvedDelayedCt :: DelayedCt -> Error

-- | Type wild cards are not allowed in this context (e.g., definitions of
--   type synonyms).
UnexpectedTypeWildCard :: Error

-- | Unification variable depends on quantified variables that are not in
--   scope.
TypeVariableEscaped :: TypeSource -> Path -> Type -> [TParam] -> Error

-- | Quantified type variables (of kind *) need to match the given type, so
--   it does not work for all types.
NotForAll :: TypeSource -> Path -> TVar -> Type -> Error

-- | Too many positional type arguments, in an explicit type instantiation
TooManyPositionalTypeParams :: Error

-- | Kind other than <a>*</a> or <tt>#</tt> given to parameter of type
--   synonym, newtype, function signature, etc.
BadParameterKind :: TParam -> Kind -> Error
CannotMixPositionalAndNamedTypeParams :: Error
UndefinedTypeParameter :: Located Ident -> Error
RepeatedTypeParameter :: Ident -> [Range] -> Error

-- | Could not determine the value of a numeric type variable, but we know
--   it must be at least as large as the given type (or unconstrained, if
--   Nothing).
AmbiguousSize :: TVarInfo -> Maybe Type -> Error

-- | Bare expression of the form `{_}
BareTypeApp :: Error
UndefinedExistVar :: Name -> Error
TypeShadowing :: String -> Name -> String -> Error
MissingModTParam :: Located Ident -> Error
MissingModVParam :: Located Ident -> Error
MissingModParam :: Ident -> Error
FunctorInstanceMissingArgument :: Ident -> Error
FunctorInstanceBadArgument :: Ident -> Error
FunctorInstanceMissingName :: Namespace -> Ident -> Error
FunctorInstanceBadBacktick :: BadBacktickInstance -> Error

-- | Kind is not supported for FFI
UnsupportedFFIKind :: TypeSource -> TParam -> Kind -> Error

-- | Type is not supported for FFI
UnsupportedFFIType :: TypeSource -> FFITypeError -> Error

-- | Constraint guards may only apper at the top-level
NestedConstraintGuard :: Ident -> Error

-- | All declarataions in a recursive group involving constraint guards
--   should have signatures
DeclarationRequiresSignatureCtrGrd :: Ident -> Error

-- | The given constraint may not be used as a constraint guard
InvalidConstraintGuard :: Prop -> Error

-- | This is for errors that don't fit other cateogories. We should not use
--   it much, and is generally to be used for transient errors, which are
--   due to incomplete implementation.
TemporaryError :: Doc -> Error
data Warning
DefaultingKind :: TParam Name -> Kind -> Warning
DefaultingWildType :: Kind -> Warning
DefaultingTo :: !TVarInfo -> Type -> Warning
NonExhaustivePropGuards :: Name -> Warning
ppWarning :: (Range, Warning) -> Doc
ppError :: (Range, Error) -> Doc

-- | This packages together a type with some names to be used to display
--   the variables. It is used for pretty printing types.
data WithNames a
WithNames :: a -> NameMap -> WithNames a
type NameMap = IntMap String
ppNamedWarning :: NameMap -> (Range, Warning) -> Doc
ppNamedError :: NameMap -> (Range, Error) -> Doc


module Cryptol.Eval.Type

-- | An evaluated type of kind *. These types do not contain type
--   variables, type synonyms, or type functions.
data TValue

-- | <pre>
--   Bit
--   </pre>
TVBit :: TValue

-- | <pre>
--   Integer
--   </pre>
TVInteger :: TValue

-- | <pre>
--   Float e p
--   </pre>
TVFloat :: Integer -> Integer -> TValue

-- | <pre>
--   Z n
--   </pre>
TVIntMod :: Integer -> TValue

-- | <pre>
--   Rational
--   </pre>
TVRational :: TValue

-- | <pre>
--   Array a b
--   </pre>
TVArray :: TValue -> TValue -> TValue

-- | <pre>
--   [n]a
--   </pre>
TVSeq :: Integer -> TValue -> TValue

-- | <pre>
--   [inf]t
--   </pre>
TVStream :: TValue -> TValue

-- | <pre>
--   (a, b, c )
--   </pre>
TVTuple :: [TValue] -> TValue

-- | <pre>
--   { x : a, y : b, z : c }
--   </pre>
TVRec :: RecordMap Ident TValue -> TValue

-- | <pre>
--   a -&gt; b
--   </pre>
TVFun :: TValue -> TValue -> TValue

-- | a named newtype
TVNewtype :: Newtype -> [Either Nat' TValue] -> RecordMap Ident TValue -> TValue

-- | an abstract type
TVAbstract :: UserTC -> [Either Nat' TValue] -> TValue

-- | Convert a type value back into a regular type
tValTy :: TValue -> Type
tNumTy :: Nat' -> Type
tNumValTy :: Either Nat' TValue -> Type

-- | True if the evaluated value is <tt>Bit</tt>
isTBit :: TValue -> Bool

-- | Produce a sequence type value
tvSeq :: Nat' -> TValue -> TValue

-- | The Cryptol <tt>Float64</tt> type.
tvFloat64 :: TValue

-- | Coerce an extended natural into an integer, for values known to be
--   finite
finNat' :: Nat' -> Integer
newtype TypeEnv
TypeEnv :: IntMap (Either Nat' TValue) -> TypeEnv
[envTypeMap] :: TypeEnv -> IntMap (Either Nat' TValue)
lookupTypeVar :: TVar -> TypeEnv -> Maybe (Either Nat' TValue)
bindTypeVar :: TVar -> Either Nat' TValue -> TypeEnv -> TypeEnv

-- | Evaluation for types (kind * or #).
evalType :: TypeEnv -> Type -> Either Nat' TValue

-- | Evaluate the body of a newtype, given evaluated arguments
evalNewtypeBody :: TypeEnv -> Newtype -> [Either Nat' TValue] -> RecordMap Ident TValue

-- | Evaluation for value types (kind *).
evalValType :: TypeEnv -> Type -> TValue

-- | Evaluation for number types (kind #).
evalNumType :: TypeEnv -> Type -> Nat'

-- | Reduce type functions, raising an exception for undefined values.
evalTF :: TFun -> [Nat'] -> Nat'
instance GHC.Classes.Eq Cryptol.Eval.Type.TValue
instance Control.DeepSeq.NFData Cryptol.Eval.Type.TValue
instance GHC.Generics.Generic Cryptol.Eval.Type.TValue
instance GHC.Show.Show Cryptol.Eval.Type.TypeEnv
instance GHC.Base.Monoid Cryptol.Eval.Type.TypeEnv
instance GHC.Base.Semigroup Cryptol.Eval.Type.TypeEnv
instance GHC.Show.Show Cryptol.Eval.Type.TValue

module Cryptol.Backend.FloatHelpers
data BF
BF :: !Integer -> !Integer -> !BigFloat -> BF
[bfExpWidth] :: BF -> !Integer
[bfPrecWidth] :: BF -> !Integer
[bfValue] :: BF -> !BigFloat

-- | Make LibBF options for the given precision and rounding mode.
fpOpts :: Integer -> Integer -> RoundMode -> BFOpts

-- | Mapping from the rounding modes defined in the <a>cry</a> to the
--   rounding modes of <tt>LibBF</tt>.
fpRound :: Integer -> Either EvalError RoundMode

-- | Check that we didn't get an unexpected status.
fpCheckStatus :: (BigFloat, Status) -> BigFloat

-- | Pretty print a float
fpPP :: PPOpts -> BF -> Doc

-- | Make a literal
fpLit :: Integer -> Integer -> Rational -> BF

-- | Make a floating point number from a rational, using the given rounding
--   mode
floatFromRational :: Integer -> Integer -> RoundMode -> Rational -> BF

-- | Convert a floating point number to a rational, if possible.
floatToRational :: String -> BF -> Either EvalError Rational

-- | Convert a floating point number to an integer, if possible.
floatToInteger :: String -> RoundMode -> BF -> Either EvalError Integer
floatFromBits :: Integer -> Integer -> Integer -> BF

-- | Turn a float into raw bits. <tt>NaN</tt> is represented as a positive
--   "quiet" <tt>NaN</tt> (most significant bit in the significand is set,
--   the rest of it is 0)
floatToBits :: Integer -> Integer -> BigFloat -> Integer

-- | Create a 64-bit IEEE-754 float.
floatFromDouble :: Double -> BF

module Cryptol.Backend

-- | This type class defines a collection of operations on bits, words and
--   integers that are necessary to define generic evaluator primitives
--   that operate on both concrete and symbolic values uniformly.
class MonadIO (SEval sym) => Backend sym where {
    type SBit sym :: Type;
    type SWord sym :: Type;
    type SInteger sym :: Type;
    type SFloat sym :: Type;
    type SEval sym :: Type -> Type;
}

-- | Check if an operation is "ready", which means its evaluation will be
--   trivial.
isReady :: Backend sym => sym -> SEval sym a -> SEval sym (Maybe a)

-- | Produce a thunk value which can be filled with its associated
--   computation after the fact. A preallocated thunk is returned, along
--   with an operation to fill the thunk with the associated computation.
--   This is used to implement recursive declaration groups.
sDeclareHole :: Backend sym => sym -> String -> SEval sym (SEval sym a, SEval sym a -> SEval sym ())

-- | Delay the given evaluation computation, returning a thunk which will
--   run the computation when forced. Run the <tt>retry</tt> computation
--   instead if the resulting thunk is forced during its own evaluation.
sDelayFill :: Backend sym => sym -> SEval sym a -> Maybe (SEval sym a) -> String -> SEval sym (SEval sym a)

-- | Begin evaluating the given computation eagerly in a separate thread
--   and return a thunk which will await the completion of the given
--   computation when forced.
sSpark :: Backend sym => sym -> SEval sym a -> SEval sym (SEval sym a)

-- | Push a call frame on to the current call stack while evaluating the
--   given action
sPushFrame :: Backend sym => sym -> Name -> Range -> SEval sym a -> SEval sym a

-- | Use the given call stack while evaluating the given action
sWithCallStack :: Backend sym => sym -> CallStack -> SEval sym a -> SEval sym a

-- | Apply the given function to the current call stack while evaluating
--   the given action
sModifyCallStack :: Backend sym => sym -> (CallStack -> CallStack) -> SEval sym a -> SEval sym a

-- | Retrieve the current evaluation call stack
sGetCallStack :: Backend sym => sym -> SEval sym CallStack

-- | Merge the two given computations according to the predicate.
mergeEval :: Backend sym => sym -> (SBit sym -> a -> a -> SEval sym a) -> SBit sym -> SEval sym a -> SEval sym a -> SEval sym a

-- | Assert that a condition must hold, and indicate what sort of error is
--   indicated if the condition fails.
assertSideCondition :: Backend sym => sym -> SBit sym -> EvalError -> SEval sym ()

-- | Indiciate that an error condition exists
raiseError :: Backend sym => sym -> EvalError -> SEval sym a

-- | Determine if this symbolic bit is a boolean literal
bitAsLit :: Backend sym => sym -> SBit sym -> Maybe Bool

-- | The number of bits in a word value.
wordLen :: Backend sym => sym -> SWord sym -> Integer

-- | Determine if this symbolic word is a literal. If so, return the bit
--   width and value.
wordAsLit :: Backend sym => sym -> SWord sym -> Maybe (Integer, Integer)

-- | Attempt to render a word value as an ASCII character. Return
--   <a>Nothing</a> if the character value is unknown (e.g., for symbolic
--   values).
wordAsChar :: Backend sym => sym -> SWord sym -> Maybe Char

-- | Determine if this symbolic integer is a literal
integerAsLit :: Backend sym => sym -> SInteger sym -> Maybe Integer

-- | Determine if this symbolic floating-point value is a literal
fpAsLit :: Backend sym => sym -> SFloat sym -> Maybe BF

-- | Construct a literal bit value from a boolean.
bitLit :: Backend sym => sym -> Bool -> SBit sym

-- | Construct a literal word value given a bit width and a value.
wordLit :: Backend sym => sym -> Integer -> Integer -> SEval sym (SWord sym)

-- | Construct a literal integer value from the given integer.
integerLit :: Backend sym => sym -> Integer -> SEval sym (SInteger sym)

-- | Construct a floating point value from the given rational.
fpLit :: Backend sym => sym -> Integer -> Integer -> Rational -> SEval sym (SFloat sym)

-- | Construct a floating point value from the given bit-precise
--   floating-point representation.
fpExactLit :: Backend sym => sym -> BF -> SEval sym (SFloat sym)
iteBit :: Backend sym => sym -> SBit sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
iteWord :: Backend sym => sym -> SBit sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)
iteInteger :: Backend sym => sym -> SBit sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)
iteFloat :: Backend sym => sym -> SBit sym -> SFloat sym -> SFloat sym -> SEval sym (SFloat sym)
bitEq :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitOr :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitAnd :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitXor :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitComplement :: Backend sym => sym -> SBit sym -> SEval sym (SBit sym)

-- | Extract the numbered bit from the word.
--   
--   NOTE: this assumes that the sequence of bits is big-endian and finite,
--   so the bit numbered 0 is the most significant bit.
wordBit :: Backend sym => sym -> SWord sym -> Integer -> SEval sym (SBit sym)

-- | Update the numbered bit in the word.
--   
--   NOTE: this assumes that the sequence of bits is big-endian and finite,
--   so the bit numbered 0 is the most significant bit.
wordUpdate :: Backend sym => sym -> SWord sym -> Integer -> SBit sym -> SEval sym (SWord sym)

-- | Construct a word value from a finite sequence of bits. NOTE: this
--   assumes that the sequence of bits is big-endian and finite, so the
--   first element of the list will be the most significant bit.
packWord :: Backend sym => sym -> [SBit sym] -> SEval sym (SWord sym)

-- | Deconstruct a packed word value in to a finite sequence of bits. NOTE:
--   this produces a list of bits that represent a big-endian word, so the
--   most significant bit is the first element of the list.
unpackWord :: Backend sym => sym -> SWord sym -> SEval sym [SBit sym]

-- | Construct a packed word of the specified width from an integer value.
wordFromInt :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SWord sym)

-- | Concatenate the two given word values. NOTE: the first argument
--   represents the more-significant bits
joinWord :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Take the most-significant bits, and return those bits and the
--   remainder. The first element of the pair is the most significant bits.
--   The two integer sizes must sum to the length of the given word value.
splitWord :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SEval sym (SWord sym, SWord sym)

-- | Extract a subsequence of bits from a packed word value. The first
--   integer argument is the number of bits in the resulting word. The
--   second integer argument is the number of less-significant digits to
--   discard. Stated another way, the operation <tt>extractWord n i w</tt>
--   is equivalent to first shifting <tt>w</tt> right by <tt>i</tt> bits,
--   and then truncating to <tt>n</tt> bits.
extractWord :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SEval sym (SWord sym)

-- | Bitwise OR
wordOr :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Bitwise AND
wordAnd :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Bitwise XOR
wordXor :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Bitwise complement
wordComplement :: Backend sym => sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement addition of packed words. The arguments must have equal
--   bit width, and the result is of the same width. Overflow is silently
--   discarded.
wordPlus :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement subtraction of packed words. The arguments must have
--   equal bit width, and the result is of the same width. Overflow is
--   silently discarded.
wordMinus :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement multiplication of packed words. The arguments must have
--   equal bit width, and the result is of the same width. The high bits of
--   the multiplication are silently discarded.
wordMult :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement unsigned division of packed words. The arguments must
--   have equal bit width, and the result is of the same width. It is
--   illegal to call with a second argument concretely equal to 0.
wordDiv :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement unsigned modulus of packed words. The arguments must
--   have equal bit width, and the result is of the same width. It is
--   illegal to call with a second argument concretely equal to 0.
wordMod :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement signed division of packed words. The arguments must
--   have equal bit width, and the result is of the same width. It is
--   illegal to call with a second argument concretely equal to 0.
wordSignedDiv :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement signed modulus of packed words. The arguments must have
--   equal bit width, and the result is of the same width. It is illegal to
--   call with a second argument concretely equal to 0.
wordSignedMod :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Shift a bitvector left by the specified amount. The shift amount is
--   considered as an unsigned value. Shifting by more than the word length
--   results in 0.
wordShiftLeft :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Shift a bitvector right by the specified amount. This is a logical
--   shift, which shifts in 0 values on the left. The shift amount is
--   considered as an unsigned value. Shifting by more than the word length
--   results in 0.
wordShiftRight :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Shift a bitvector right by the specified amount. This is an arithmetic
--   shift, which shifts in copies of the high bit on the left. The shift
--   amount is considered as an unsigned value. Shifting by more than the
--   word length results in filling the bitvector with the high bit.
wordSignedShiftRight :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)
wordRotateLeft :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)
wordRotateRight :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement negation of bitvectors
wordNegate :: Backend sym => sym -> SWord sym -> SEval sym (SWord sym)

-- | Compute rounded-up log-2 of the input
wordLg2 :: Backend sym => sym -> SWord sym -> SEval sym (SWord sym)

-- | Test if two words are equal. Arguments must have the same width.
wordEq :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SBit sym)

-- | Signed less-than comparison on words. Arguments must have the same
--   width.
wordSignedLessThan :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SBit sym)

-- | Unsigned less-than comparison on words. Arguments must have the same
--   width.
wordLessThan :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SBit sym)

-- | Unsigned greater-than comparison on words. Arguments must have the
--   same width.
wordGreaterThan :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SBit sym)

-- | Construct an integer value from the given packed word.
wordToInt :: Backend sym => sym -> SWord sym -> SEval sym (SInteger sym)

-- | Construct a signed integer value from the given packed word.
wordToSignedInt :: Backend sym => sym -> SWord sym -> SEval sym (SInteger sym)

-- | Addition of unbounded integers.
intPlus :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Negation of unbounded integers
intNegate :: Backend sym => sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Subtraction of unbounded integers.
intMinus :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Multiplication of unbounded integers.
intMult :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Integer division, rounding down. It is illegal to call with a second
--   argument concretely equal to 0. Same semantics as Haskell's
--   <tt>div</tt> operation.
intDiv :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Integer modulus, with division rounding down. It is illegal to call
--   with a second argument concretely equal to 0. Same semantics as
--   Haskell's <tt>mod</tt> operation.
intMod :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Equality comparison on integers
intEq :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SBit sym)

-- | Less-than comparison on integers
intLessThan :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SBit sym)

-- | Greater-than comparison on integers
intGreaterThan :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SBit sym)

-- | Turn an integer into a value in Z_n
intToZn :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SInteger sym)

-- | Transform a Z_n value into an integer, ensuring the value is properly
--   reduced modulo n
znToInt :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SInteger sym)

-- | Addition of integers modulo n, for a concrete positive integer n.
znPlus :: Backend sym => sym -> Integer -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Additive inverse of integers modulo n
znNegate :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SInteger sym)

-- | Subtraction of integers modulo n, for a concrete positive integer n.
znMinus :: Backend sym => sym -> Integer -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Multiplication of integers modulo n, for a concrete positive integer
--   n.
znMult :: Backend sym => sym -> Integer -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Equality test of integers modulo n
znEq :: Backend sym => sym -> Integer -> SInteger sym -> SInteger sym -> SEval sym (SBit sym)

-- | Multiplicative inverse in (Z n). PRECONDITION: the modulus is a prime
znRecip :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SInteger sym)
fpEq :: Backend sym => sym -> SFloat sym -> SFloat sym -> SEval sym (SBit sym)
fpLessThan :: Backend sym => sym -> SFloat sym -> SFloat sym -> SEval sym (SBit sym)
fpGreaterThan :: Backend sym => sym -> SFloat sym -> SFloat sym -> SEval sym (SBit sym)
fpLogicalEq :: Backend sym => sym -> SFloat sym -> SFloat sym -> SEval sym (SBit sym)
fpNaN :: Backend sym => sym -> Integer -> Integer -> SEval sym (SFloat sym)
fpPosInf :: Backend sym => sym -> Integer -> Integer -> SEval sym (SFloat sym)
fpPlus :: Backend sym => FPArith2 sym
fpMinus :: Backend sym => FPArith2 sym
fpMult :: Backend sym => FPArith2 sym
fpDiv :: Backend sym => FPArith2 sym
fpNeg :: Backend sym => sym -> SFloat sym -> SEval sym (SFloat sym)
fpAbs :: Backend sym => sym -> SFloat sym -> SEval sym (SFloat sym)
fpSqrt :: Backend sym => sym -> SWord sym -> SFloat sym -> SEval sym (SFloat sym)
fpFMA :: Backend sym => sym -> SWord sym -> SFloat sym -> SFloat sym -> SFloat sym -> SEval sym (SFloat sym)
fpIsZero :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsNeg :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsNaN :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsInf :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsNorm :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsSubnorm :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpToBits :: Backend sym => sym -> SFloat sym -> SEval sym (SWord sym)
fpFromBits :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SEval sym (SFloat sym)
fpToInteger :: Backend sym => sym -> String -> SWord sym -> SFloat sym -> SEval sym (SInteger sym)
fpFromInteger :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SInteger sym -> SEval sym (SFloat sym)
fpToRational :: Backend sym => sym -> SFloat sym -> SEval sym (SRational sym)
fpFromRational :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SRational sym -> SEval sym (SFloat sym)

-- | Delay the given evaluation computation, returning a thunk which will
--   run the computation when forced. Raise a loop error if the resulting
--   thunk is forced during its own evaluation.
sDelay :: Backend sym => sym -> SEval sym a -> SEval sym (SEval sym a)
invalidIndex :: Backend sym => sym -> Integer -> SEval sym a
cryUserError :: Backend sym => sym -> String -> SEval sym a
cryNoPrimError :: Backend sym => sym -> Name -> SEval sym a
type FPArith2 sym = sym -> SWord sym -> SFloat sym -> SFloat sym -> SEval sym (SFloat sym)
data IndexDirection
IndexForward :: IndexDirection
IndexBackward :: IndexDirection

-- | Compute the list of bits in an integer in big-endian order. Fails if
--   neither the sequence length nor the type value provide an upper bound
--   for the integer.
enumerateIntBits :: Backend sym => sym -> Nat' -> SInteger sym -> SEval sym (Integer, [SBit sym])

-- | Compute the list of bits in an integer in big-endian order. The
--   integer argument is a concrete upper bound for the symbolic integer.
enumerateIntBits' :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (Integer, [SBit sym])

-- | Representation of rational numbers. Invariant: denominator is not 0
data SRational sym
SRational :: SInteger sym -> SInteger sym -> SRational sym
[sNum] :: SRational sym -> SInteger sym
[sDenom] :: SRational sym -> SInteger sym
intToRational :: Backend sym => sym -> SInteger sym -> SEval sym (SRational sym)
ratio :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SRational sym)
rationalAdd :: Backend sym => sym -> SRational sym -> SRational sym -> SEval sym (SRational sym)
rationalSub :: Backend sym => sym -> SRational sym -> SRational sym -> SEval sym (SRational sym)
rationalNegate :: Backend sym => sym -> SRational sym -> SEval sym (SRational sym)
rationalMul :: Backend sym => sym -> SRational sym -> SRational sym -> SEval sym (SRational sym)
rationalRecip :: Backend sym => sym -> SRational sym -> SEval sym (SRational sym)
rationalDivide :: Backend sym => sym -> SRational sym -> SRational sym -> SEval sym (SRational sym)
rationalFloor :: Backend sym => sym -> SRational sym -> SEval sym (SInteger sym)
rationalCeiling :: Backend sym => sym -> SRational sym -> SEval sym (SInteger sym)
rationalTrunc :: Backend sym => sym -> SRational sym -> SEval sym (SInteger sym)
rationalRoundAway :: Backend sym => sym -> SRational sym -> SEval sym (SInteger sym)
rationalRoundToEven :: Backend sym => sym -> SRational sym -> SEval sym (SInteger sym)
rationalEq :: Backend sym => sym -> SRational sym -> SRational sym -> SEval sym (SBit sym)
rationalLessThan :: Backend sym => sym -> SRational sym -> SRational sym -> SEval sym (SBit sym)
rationalGreaterThan :: Backend sym => sym -> SRational sym -> SRational sym -> SEval sym (SBit sym)
iteRational :: Backend sym => sym -> SBit sym -> SRational sym -> SRational sym -> SEval sym (SRational sym)


-- | This module provides fast primitives for elliptic curve cryptography
--   defined on <tt>Z p</tt> for prime <tt>p &gt; 3</tt>. These are exposed
--   in cryptol by importing the built-in module <a>PrimeEC</a>. The
--   primary primitives exposed here are the doubling and addition
--   primitives in the ECC group as well as scalar multiplication and the
--   "twin" multiplication primitive, which simultaneously computes the
--   addition of two scalar multiplies.
--   
--   This module makes heavy use of some GHC internals regarding the
--   representation of the Integer type, and the underlying GMP primitives
--   in order to speed up the basic modular arithmetic operations.
module Cryptol.PrimeEC

-- | Simple newtype wrapping the <tt>BigNat</tt> value of the modulus of
--   the underlying field Z p. This modulus is required to be prime.
data PrimeModulus

-- | Inject an integer value into the <tt>PrimeModulus</tt> type. This
--   modulus is required to be prime.
primeModulus :: Integer -> PrimeModulus

-- | Points in the projective plane represented in homogenous coordinates.
data ProjectivePoint
ProjectivePoint :: !BigNat# -> !BigNat# -> !BigNat# -> ProjectivePoint
[px] :: ProjectivePoint -> !BigNat#
[py] :: ProjectivePoint -> !BigNat#
[pz] :: ProjectivePoint -> !BigNat#
toProjectivePoint :: Integer -> Integer -> Integer -> ProjectivePoint

-- | Coerce an integer value to a <tt>BigNat#</tt>. This operation only
--   really makes sense for nonnegative values, but this condition is not
--   checked.
integerToBigNat :: Integer -> BigNat#

-- | Coerce a <tt>BigNat#</tt> to an integer value.
bigNatToInteger :: BigNat# -> Integer

-- | Compute the elliptic curve group doubling operation. In other words,
--   if <tt>S</tt> is a projective point on a curve, this operation
--   computes <tt>S+S</tt> in the ECC group.
--   
--   In geometric terms, this operation computes a tangent line to the
--   curve at <tt>S</tt> and finds the (unique) intersection point of this
--   line with the curve, <tt>R</tt>; then returns the point <tt>R'</tt>,
--   which is <tt>R</tt> reflected across the x axis.
ec_double :: PrimeModulus -> ProjectivePoint -> ProjectivePoint

-- | Compute the elliptic curve group addition operation for values known
--   not to be the identity. In other words, if <tt>S</tt> and <tt>T</tt>
--   are projective points on a curve, with nonzero <tt>z</tt> coordinate
--   this operation computes <tt>S+T</tt> in the ECC group.
--   
--   In geometric terms, this operation computes a line that passes through
--   <tt>S</tt> and <tt>T</tt>, and finds the (unique) other point
--   <tt>R</tt> where the line intersects the curve; then returns the point
--   <tt>R'</tt>, which is <tt>R</tt> reflected across the x axis. In the
--   special case where <tt>S == T</tt>, we instead call the
--   <tt>ec_double</tt> operation, which instead computes a tangent line to
--   <tt>S</tt> .
ec_add_nonzero :: PrimeModulus -> ProjectivePoint -> ProjectivePoint -> ProjectivePoint

-- | Given an integer <tt>k</tt> and a projective point <tt>S</tt>, compute
--   the scalar multiplication <tt>kS</tt>, which is <tt>S</tt> added to
--   itself <tt>k</tt> times.
ec_mult :: PrimeModulus -> Integer -> ProjectivePoint -> ProjectivePoint

-- | Given an integer <tt>j</tt> and a projective point <tt>S</tt>,
--   together with another integer <tt>k</tt> and point <tt>T</tt> compute
--   the "twin" scalar the scalar multiplication <tt>jS + kT</tt>. This
--   computation can be done essentially the same number of modular
--   arithmetic operations as a single scalar multiplication by doing some
--   additional bookkeeping and setup.
ec_twin_mult :: PrimeModulus -> Integer -> ProjectivePoint -> Integer -> ProjectivePoint -> ProjectivePoint


module Cryptol.Backend.What4
data What4 sym
What4 :: sym -> MVar (Pred sym) -> MVar (What4FunCache sym) -> MVar (Set Text) -> What4 sym
[w4] :: What4 sym -> sym
[w4defs] :: What4 sym -> MVar (Pred sym)
[w4funs] :: What4 sym -> MVar (What4FunCache sym)
[w4uninterpWarns] :: What4 sym -> MVar (Set Text)
type What4FunCache sym = Map Text (SomeSymFn sym)
data SomeSymFn sym
SomeSymFn :: SymFn sym args ret -> SomeSymFn sym

-- | This is the monad used for symbolic evaluation. It adds to aspects to
--   <a>Eval</a>---<tt>WConn</tt> keeps track of the backend and collects
--   definitional predicates, and <a>W4Eval</a> adds support for partially
--   defined values
newtype W4Eval sym a
W4Eval :: W4Conn sym (W4Result sym a) -> W4Eval sym a
[evalPartial] :: W4Eval sym a -> W4Conn sym (W4Result sym a)

-- | This layer has the symbolic back-end, and can keep track of
--   definitional predicates used when working with uninterpreted constants
--   defined via a property.
newtype W4Conn sym a
W4Conn :: (sym -> Eval a) -> W4Conn sym a
[evalConn] :: W4Conn sym a -> sym -> Eval a

-- | The symbolic value we computed.
data W4Result sym a

-- | A malformed value
W4Error :: !EvalErrorEx -> W4Result sym a

-- | safety predicate and result: the result only makes sense when the
--   predicate holds.
W4Result :: !Pred sym -> !a -> W4Result sym a
w4Eval :: W4Eval sym a -> sym -> Eval (W4Result sym a)
w4Thunk :: Eval (W4Result sym a) -> W4Eval sym a

-- | A value with no context.
doEval :: IsSymExprBuilder sym => Eval a -> W4Conn sym a

-- | A total value.
total :: IsSymExprBuilder sym => W4Conn sym a -> W4Eval sym a

-- | Access the symbolic back-end
getSym :: W4Conn sym sym

-- | Record a definition. addDef :: W4.Pred sym -&gt; W4Conn sym () addDef
--   p = W4Conn _ -&gt; pure W4Defs { w4Defs = p, w4Result = () }
--   
--   Compute conjunction.
w4And :: IsSymExprBuilder sym => Pred sym -> Pred sym -> W4Conn sym (Pred sym)

-- | Compute negation.
w4Not :: IsSymExprBuilder sym => Pred sym -> W4Conn sym (Pred sym)

-- | Compute if-then-else.
w4ITE :: IsSymExprBuilder sym => Pred sym -> Pred sym -> Pred sym -> W4Conn sym (Pred sym)

-- | Add a definitional equation. This will always be asserted when we make
--   queries to the solver.
addDefEqn :: IsSymExprBuilder sym => What4 sym -> Pred sym -> W4Eval sym ()

-- | Add s safety condition.
addSafety :: IsSymExprBuilder sym => Pred sym -> W4Eval sym ()

-- | A fully undefined symbolic value
evalError :: IsSymExprBuilder sym => EvalError -> W4Eval sym a
assertBVDivisor :: IsSymExprBuilder sym => What4 sym -> SWord sym -> W4Eval sym ()
assertIntDivisor :: IsSymExprBuilder sym => What4 sym -> SymInteger sym -> W4Eval sym ()
sModAdd :: IsSymExprBuilder sym => sym -> Integer -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
sModSub :: IsSymExprBuilder sym => sym -> Integer -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
sModMult :: IsSymExprBuilder sym => sym -> Integer -> SymInteger sym -> SymInteger sym -> IO (SymInteger sym)
sModNegate :: IsSymExprBuilder sym => sym -> Integer -> SymInteger sym -> IO (SymInteger sym)

-- | Try successive powers of 2 to find the first that dominates the input.
--   We could perhaps reduce to using CLZ instead...
sLg2 :: IsSymExprBuilder sym => sym -> SWord sym -> SEval (What4 sym) (SWord sym)
evalPanic :: String -> [String] -> a
lazyIte :: (IsExpr p, Monad m) => (p BaseBoolType -> a -> a -> m a) -> p BaseBoolType -> m a -> m a -> m a
w4bvShl :: IsSymExprBuilder sym => sym -> SWord sym -> SWord sym -> W4Eval sym (SWord sym)
w4bvLshr :: IsSymExprBuilder sym => sym -> SWord sym -> SWord sym -> W4Eval sym (SWord sym)
w4bvAshr :: IsSymExprBuilder sym => sym -> SWord sym -> SWord sym -> W4Eval sym (SWord sym)
w4bvRol :: IsSymExprBuilder sym => sym -> SWord sym -> SWord sym -> W4Eval sym (SWord sym)
w4bvRor :: IsSymExprBuilder sym => sym -> SWord sym -> SWord sym -> W4Eval sym (SWord sym)
fpRoundingMode :: IsSymExprBuilder sym => What4 sym -> SWord (What4 sym) -> SEval (What4 sym) RoundingMode
fpBinArith :: IsSymExprBuilder sym => SFloatBinArith sym -> What4 sym -> SWord (What4 sym) -> SFloat (What4 sym) -> SFloat (What4 sym) -> SEval (What4 sym) (SFloat (What4 sym))
fpCvtToInteger :: (IsSymExprBuilder sy, sym ~ What4 sy) => sym -> String -> SWord sym -> SFloat sym -> SEval sym (SInteger sym)
fpCvtToRational :: (IsSymExprBuilder sy, sym ~ What4 sy) => sym -> SFloat sym -> SEval sym (SRational sym)
fpCvtFromRational :: (IsSymExprBuilder sy, sym ~ What4 sy) => sym -> Integer -> Integer -> SWord sym -> SRational sym -> SEval sym (SFloat sym)
sModRecip :: IsSymExprBuilder sym => What4 sym -> Integer -> SymInteger sym -> W4Eval sym (SymInteger sym)
instance GHC.Base.Functor (Cryptol.Backend.What4.W4Result sym)
instance What4.Interface.IsSymExprBuilder sym => GHC.Base.Functor (Cryptol.Backend.What4.W4Eval sym)
instance What4.Interface.IsSymExprBuilder sym => GHC.Base.Applicative (Cryptol.Backend.What4.W4Eval sym)
instance What4.Interface.IsSymExprBuilder sym => GHC.Base.Monad (Cryptol.Backend.What4.W4Eval sym)
instance What4.Interface.IsSymExprBuilder sym => Control.Monad.IO.Class.MonadIO (Cryptol.Backend.What4.W4Eval sym)
instance What4.Interface.IsSymExprBuilder sym => Cryptol.Backend.Backend (Cryptol.Backend.What4.What4 sym)
instance What4.Interface.IsSymExprBuilder sym => GHC.Base.Functor (Cryptol.Backend.What4.W4Conn sym)
instance What4.Interface.IsSymExprBuilder sym => GHC.Base.Applicative (Cryptol.Backend.What4.W4Conn sym)
instance What4.Interface.IsSymExprBuilder sym => GHC.Base.Monad (Cryptol.Backend.What4.W4Conn sym)
instance What4.Interface.IsSymExprBuilder sym => Control.Monad.IO.Class.MonadIO (Cryptol.Backend.What4.W4Conn sym)


module Cryptol.Backend.Concrete

-- | Concrete bitvector values: width, value Invariant: The value must be
--   within the range 0 .. 2^width-1
data BV
BV :: !Integer -> !Integer -> BV

-- | Apply an integer function to the values of bitvectors. This function
--   assumes both bitvectors are the same width.
binBV :: Applicative m => (Integer -> Integer -> Integer) -> BV -> BV -> m BV

-- | Apply an integer function to the values of a bitvector. This function
--   assumes the function will not require masking.
unaryBV :: (Integer -> Integer) -> BV -> BV
bvVal :: BV -> Integer
ppBV :: PPOpts -> BV -> Doc

-- | Smart constructor for <a>BV</a>s that checks for the width limit
mkBv :: Integer -> Integer -> BV
mask :: Integer -> Integer -> Integer
signedBV :: BV -> Integer
signedValue :: Integer -> Integer -> Integer
integerToChar :: Integer -> Char
lg2 :: Integer -> Integer
data Concrete
Concrete :: Concrete
liftBinIntMod :: Monad m => (Integer -> Integer -> Integer) -> Integer -> Integer -> Integer -> m Integer
fpBinArith :: (BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)) -> Concrete -> SWord Concrete -> SFloat Concrete -> SFloat Concrete -> SEval Concrete (SFloat Concrete)
fpRoundMode :: Concrete -> SWord Concrete -> SEval Concrete RoundMode
instance GHC.Show.Show Cryptol.Backend.Concrete.Concrete
instance GHC.Show.Show Cryptol.Backend.Concrete.BV
instance Cryptol.Backend.Backend Cryptol.Backend.Concrete.Concrete


module Cryptol.Backend.SeqMap

-- | A sequence map represents a mapping from nonnegative integer indices
--   to values. These are used to represent both finite and infinite
--   sequences.
data SeqMap sym a
indexSeqMap :: (Integer -> SEval sym a) -> SeqMap sym a
lookupSeqMap :: Backend sym => SeqMap sym a -> Integer -> SEval sym a

-- | Generate a finite sequence map from a list of values
finiteSeqMap :: Backend sym => sym -> [SEval sym a] -> SeqMap sym a

-- | Generate an infinite sequence map from a stream of values
infiniteSeqMap :: Backend sym => sym -> [SEval sym a] -> SEval sym (SeqMap sym a)

-- | Create a finite list of length <tt>n</tt> of the values from
--   <tt>[0..n-1]</tt> in the given the sequence emap.
enumerateSeqMap :: (Backend sym, Integral n) => n -> SeqMap sym a -> [SEval sym a]

-- | Create an infinite stream of all the values in a sequence map
streamSeqMap :: Backend sym => SeqMap sym a -> [SEval sym a]

-- | Reverse the order of a finite sequence map
reverseSeqMap :: Backend sym => Integer -> SeqMap sym a -> SeqMap sym a
updateSeqMap :: SeqMap sym a -> Integer -> SEval sym a -> SeqMap sym a

-- | Drop the first <tt>n</tt> elements of the given <a>SeqMap</a>.
dropSeqMap :: Backend sym => Integer -> SeqMap sym a -> SeqMap sym a

-- | Concatenate the first <tt>n</tt> values of the first sequence map onto
--   the beginning of the second sequence map.
concatSeqMap :: Backend sym => Integer -> SeqMap sym a -> SeqMap sym a -> SeqMap sym a

-- | Given a number <tt>n</tt> and a sequence map, return two new sequence
--   maps: the first containing the values from <tt>[0..n-1]</tt> and the
--   next containing the values from <tt>n</tt> onward.
splitSeqMap :: Backend sym => Integer -> SeqMap sym a -> (SeqMap sym a, SeqMap sym a)

-- | Given a sequence map, return a new sequence map that is memoized using
--   a finite map memo table.
memoMap :: Backend sym => sym -> Nat' -> SeqMap sym a -> SEval sym (SeqMap sym a)
delaySeqMap :: Backend sym => sym -> SEval sym (SeqMap sym a) -> SEval sym (SeqMap sym a)

-- | Apply the given evaluation function pointwise to the two given
--   sequence maps.
zipSeqMap :: Backend sym => sym -> (a -> a -> SEval sym a) -> Nat' -> SeqMap sym a -> SeqMap sym a -> SEval sym (SeqMap sym a)

-- | Apply the given function to each value in the given sequence map
mapSeqMap :: Backend sym => sym -> (a -> SEval sym a) -> Nat' -> SeqMap sym a -> SEval sym (SeqMap sym a)
mergeSeqMap :: Backend sym => sym -> (SBit sym -> a -> a -> SEval sym a) -> SBit sym -> SeqMap sym a -> SeqMap sym a -> SeqMap sym a
barrelShifter :: Backend sym => sym -> (SBit sym -> a -> a -> SEval sym a) -> (SeqMap sym a -> Integer -> SEval sym (SeqMap sym a)) -> Nat' -> SeqMap sym a -> Integer -> [IndexSegment sym] -> SEval sym (SeqMap sym a)
shiftSeqByInteger :: Backend sym => sym -> (SBit sym -> a -> a -> SEval sym a) -> (Integer -> Integer -> Maybe Integer) -> SEval sym a -> Nat' -> SeqMap sym a -> SInteger sym -> SEval sym (SeqMap sym a)
data IndexSegment sym
BitIndexSegment :: SBit sym -> IndexSegment sym
WordIndexSegment :: SWord sym -> IndexSegment sym
instance Cryptol.Backend.Backend sym => GHC.Base.Functor (Cryptol.Backend.SeqMap.SeqMap sym)


module Cryptol.Backend.WordValue

-- | For efficiency reasons, we handle finite sequences of bits as special
--   cases in the evaluator. In cases where we know it is safe to do so, we
--   prefer to used a "packed word" representation of bit sequences. This
--   allows us to rely directly on Integer types (in the concrete
--   evaluator) and SBV's Word types (in the symbolic simulator).
--   
--   However, if we cannot be sure all the bits of the sequence will
--   eventually be forced, we must instead rely on an explicit sequence of
--   bits representation.
data WordValue sym
wordVal :: SWord sym -> WordValue sym
bitmapWordVal :: Backend sym => sym -> Integer -> SeqMap sym (SBit sym) -> SEval sym (WordValue sym)
asWordList :: forall sym. Backend sym => sym -> [WordValue sym] -> SEval sym (Maybe [SWord sym])

-- | Force a word value into packed word form
asWordVal :: Backend sym => sym -> WordValue sym -> SEval sym (SWord sym)

-- | Force a word value into a sequence of bits
asBitsMap :: Backend sym => sym -> WordValue sym -> SeqMap sym (SBit sym)
joinWordVal :: Backend sym => sym -> WordValue sym -> WordValue sym -> SEval sym (WordValue sym)
takeWordVal :: Backend sym => sym -> Integer -> Integer -> WordValue sym -> SEval sym (WordValue sym)
dropWordVal :: Backend sym => sym -> Integer -> Integer -> WordValue sym -> SEval sym (WordValue sym)

-- | Extract a subsequence of bits from a <tt>WordValue</tt>. The first
--   integer argument is the number of bits in the resulting word. The
--   second integer argument is the number of less-significant digits to
--   discard. Stated another way, the operation `extractWordVal n i w` is
--   equivalent to first shifting <tt>w</tt> right by <tt>i</tt> bits, and
--   then truncating to <tt>n</tt> bits.
extractWordVal :: Backend sym => sym -> Integer -> Integer -> WordValue sym -> SEval sym (WordValue sym)
wordValLogicOp :: Backend sym => sym -> (SBit sym -> SBit sym -> SEval sym (SBit sym)) -> (SWord sym -> SWord sym -> SEval sym (SWord sym)) -> WordValue sym -> WordValue sym -> SEval sym (WordValue sym)
wordValUnaryOp :: Backend sym => sym -> (SBit sym -> SEval sym (SBit sym)) -> (SWord sym -> SEval sym (SWord sym)) -> WordValue sym -> SEval sym (WordValue sym)
assertWordValueInBounds :: Backend sym => sym -> Integer -> WordValue sym -> SEval sym ()

-- | Turn a word value into a sequence of bits, forcing each bit. The
--   sequence is returned in big-endian order.
enumerateWordValue :: Backend sym => sym -> WordValue sym -> SEval sym [SBit sym]

-- | Turn a word value into a sequence of bits, forcing each bit. The
--   sequence is returned in reverse of the usual order, which is
--   little-endian order.
enumerateWordValueRev :: Backend sym => sym -> WordValue sym -> SEval sym [SBit sym]
enumerateIndexSegments :: Backend sym => sym -> WordValue sym -> SEval sym [IndexSegment sym]

-- | Compute the size of a word value TODO, can we get rid of this? If
--   feels like it should be unnecessary.
wordValueSize :: Backend sym => sym -> WordValue sym -> Integer

-- | Select an individual bit from a word value
indexWordValue :: Backend sym => sym -> WordValue sym -> Integer -> SEval sym (SBit sym)

-- | Produce a new <a>WordValue</a> from the one given by updating the
--   <tt>i</tt>th bit with the given bit value.
updateWordValue :: Backend sym => sym -> WordValue sym -> Integer -> SEval sym (SBit sym) -> SEval sym (WordValue sym)
delayWordValue :: Backend sym => sym -> Integer -> SEval sym (WordValue sym) -> SEval sym (WordValue sym)
joinWords :: forall sym. Backend sym => sym -> Integer -> Integer -> SeqMap sym (WordValue sym) -> SEval sym (WordValue sym)
shiftSeqByWord :: Backend sym => sym -> (SBit sym -> a -> a -> SEval sym a) -> (Integer -> Integer -> Maybe Integer) -> SEval sym a -> Nat' -> SeqMap sym a -> WordValue sym -> SEval sym (SeqMap sym a)
shiftWordByInteger :: Backend sym => sym -> (SWord sym -> SWord sym -> SEval sym (SWord sym)) -> (Integer -> Integer -> Maybe Integer) -> WordValue sym -> SInteger sym -> SEval sym (WordValue sym)
shiftWordByWord :: Backend sym => sym -> (SWord sym -> SWord sym -> SEval sym (SWord sym)) -> (Integer -> Integer -> Maybe Integer) -> WordValue sym -> WordValue sym -> SEval sym (WordValue sym)
wordValAsLit :: Backend sym => sym -> WordValue sym -> SEval sym (Maybe Integer)
reverseWordVal :: Backend sym => sym -> WordValue sym -> SEval sym (WordValue sym)

-- | Force the evaluation of a word value
forceWordValue :: Backend sym => WordValue sym -> SEval sym ()
wordValueEqualsInteger :: forall sym. Backend sym => sym -> WordValue sym -> Integer -> SEval sym (SBit sym)
updateWordByWord :: Backend sym => sym -> IndexDirection -> WordValue sym -> WordValue sym -> SEval sym (SBit sym) -> SEval sym (WordValue sym)
mergeWord :: Backend sym => sym -> SBit sym -> WordValue sym -> WordValue sym -> SEval sym (WordValue sym)
mergeWord' :: Backend sym => sym -> SBit sym -> SEval sym (WordValue sym) -> SEval sym (WordValue sym) -> SEval sym (WordValue sym)
instance GHC.Generics.Generic (Cryptol.Backend.WordValue.WordValue sym)


module Cryptol.Eval.Value

-- | Generic value type, parameterized by bit and word types.
--   
--   NOTE: we maintain an important invariant regarding sequence types.
--   <a>VSeq</a> must never be used for finite sequences of bits. Always
--   use the <a>VWord</a> constructor instead! Infinite sequences of bits
--   are handled by the <a>VStream</a> constructor, just as for other
--   types.
data GenValue sym

-- | <pre>
--   { .. }
--   </pre>
VRecord :: !RecordMap Ident (SEval sym (GenValue sym)) -> GenValue sym

-- | <pre>
--   ( .. )
--   </pre>
VTuple :: ![SEval sym (GenValue sym)] -> GenValue sym

-- | <pre>
--   Bit
--   </pre>
VBit :: !SBit sym -> GenValue sym

-- | <tt> Integer </tt> or <tt> Z n </tt>
VInteger :: !SInteger sym -> GenValue sym

-- | <pre>
--   Rational
--   </pre>
VRational :: !SRational sym -> GenValue sym
VFloat :: !SFloat sym -> GenValue sym

-- | <tt> [n]a </tt> Invariant: VSeq is never a sequence of bits
VSeq :: !Integer -> !SeqMap sym (GenValue sym) -> GenValue sym

-- | <pre>
--   [n]Bit
--   </pre>
VWord :: !Integer -> !WordValue sym -> GenValue sym

-- | <pre>
--   [inf]a
--   </pre>
VStream :: !SeqMap sym (GenValue sym) -> GenValue sym

-- | functions
VFun :: CallStack -> (SEval sym (GenValue sym) -> SEval sym (GenValue sym)) -> GenValue sym

-- | polymorphic values (kind *)
VPoly :: CallStack -> (TValue -> SEval sym (GenValue sym)) -> GenValue sym

-- | polymorphic values (kind #)
VNumPoly :: CallStack -> (Nat' -> SEval sym (GenValue sym)) -> GenValue sym

-- | Force the evaluation of a value
forceValue :: Backend sym => GenValue sym -> SEval sym ()

-- | This type class defines a collection of operations on bits, words and
--   integers that are necessary to define generic evaluator primitives
--   that operate on both concrete and symbolic values uniformly.
class MonadIO (SEval sym) => Backend sym where {
    type SBit sym :: Type;
    type SWord sym :: Type;
    type SInteger sym :: Type;
    type SFloat sym :: Type;
    type SEval sym :: Type -> Type;
}

-- | Check if an operation is "ready", which means its evaluation will be
--   trivial.
isReady :: Backend sym => sym -> SEval sym a -> SEval sym (Maybe a)

-- | Produce a thunk value which can be filled with its associated
--   computation after the fact. A preallocated thunk is returned, along
--   with an operation to fill the thunk with the associated computation.
--   This is used to implement recursive declaration groups.
sDeclareHole :: Backend sym => sym -> String -> SEval sym (SEval sym a, SEval sym a -> SEval sym ())

-- | Delay the given evaluation computation, returning a thunk which will
--   run the computation when forced. Run the <tt>retry</tt> computation
--   instead if the resulting thunk is forced during its own evaluation.
sDelayFill :: Backend sym => sym -> SEval sym a -> Maybe (SEval sym a) -> String -> SEval sym (SEval sym a)

-- | Begin evaluating the given computation eagerly in a separate thread
--   and return a thunk which will await the completion of the given
--   computation when forced.
sSpark :: Backend sym => sym -> SEval sym a -> SEval sym (SEval sym a)

-- | Push a call frame on to the current call stack while evaluating the
--   given action
sPushFrame :: Backend sym => sym -> Name -> Range -> SEval sym a -> SEval sym a

-- | Use the given call stack while evaluating the given action
sWithCallStack :: Backend sym => sym -> CallStack -> SEval sym a -> SEval sym a

-- | Apply the given function to the current call stack while evaluating
--   the given action
sModifyCallStack :: Backend sym => sym -> (CallStack -> CallStack) -> SEval sym a -> SEval sym a

-- | Retrieve the current evaluation call stack
sGetCallStack :: Backend sym => sym -> SEval sym CallStack

-- | Merge the two given computations according to the predicate.
mergeEval :: Backend sym => sym -> (SBit sym -> a -> a -> SEval sym a) -> SBit sym -> SEval sym a -> SEval sym a -> SEval sym a

-- | Assert that a condition must hold, and indicate what sort of error is
--   indicated if the condition fails.
assertSideCondition :: Backend sym => sym -> SBit sym -> EvalError -> SEval sym ()

-- | Indiciate that an error condition exists
raiseError :: Backend sym => sym -> EvalError -> SEval sym a

-- | Determine if this symbolic bit is a boolean literal
bitAsLit :: Backend sym => sym -> SBit sym -> Maybe Bool

-- | The number of bits in a word value.
wordLen :: Backend sym => sym -> SWord sym -> Integer

-- | Determine if this symbolic word is a literal. If so, return the bit
--   width and value.
wordAsLit :: Backend sym => sym -> SWord sym -> Maybe (Integer, Integer)

-- | Attempt to render a word value as an ASCII character. Return
--   <a>Nothing</a> if the character value is unknown (e.g., for symbolic
--   values).
wordAsChar :: Backend sym => sym -> SWord sym -> Maybe Char

-- | Determine if this symbolic integer is a literal
integerAsLit :: Backend sym => sym -> SInteger sym -> Maybe Integer

-- | Determine if this symbolic floating-point value is a literal
fpAsLit :: Backend sym => sym -> SFloat sym -> Maybe BF

-- | Construct a literal bit value from a boolean.
bitLit :: Backend sym => sym -> Bool -> SBit sym

-- | Construct a literal word value given a bit width and a value.
wordLit :: Backend sym => sym -> Integer -> Integer -> SEval sym (SWord sym)

-- | Construct a literal integer value from the given integer.
integerLit :: Backend sym => sym -> Integer -> SEval sym (SInteger sym)

-- | Construct a floating point value from the given rational.
fpLit :: Backend sym => sym -> Integer -> Integer -> Rational -> SEval sym (SFloat sym)

-- | Construct a floating point value from the given bit-precise
--   floating-point representation.
fpExactLit :: Backend sym => sym -> BF -> SEval sym (SFloat sym)
iteBit :: Backend sym => sym -> SBit sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
iteWord :: Backend sym => sym -> SBit sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)
iteInteger :: Backend sym => sym -> SBit sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)
iteFloat :: Backend sym => sym -> SBit sym -> SFloat sym -> SFloat sym -> SEval sym (SFloat sym)
bitEq :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitOr :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitAnd :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitXor :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitComplement :: Backend sym => sym -> SBit sym -> SEval sym (SBit sym)

-- | Extract the numbered bit from the word.
--   
--   NOTE: this assumes that the sequence of bits is big-endian and finite,
--   so the bit numbered 0 is the most significant bit.
wordBit :: Backend sym => sym -> SWord sym -> Integer -> SEval sym (SBit sym)

-- | Update the numbered bit in the word.
--   
--   NOTE: this assumes that the sequence of bits is big-endian and finite,
--   so the bit numbered 0 is the most significant bit.
wordUpdate :: Backend sym => sym -> SWord sym -> Integer -> SBit sym -> SEval sym (SWord sym)

-- | Construct a word value from a finite sequence of bits. NOTE: this
--   assumes that the sequence of bits is big-endian and finite, so the
--   first element of the list will be the most significant bit.
packWord :: Backend sym => sym -> [SBit sym] -> SEval sym (SWord sym)

-- | Deconstruct a packed word value in to a finite sequence of bits. NOTE:
--   this produces a list of bits that represent a big-endian word, so the
--   most significant bit is the first element of the list.
unpackWord :: Backend sym => sym -> SWord sym -> SEval sym [SBit sym]

-- | Construct a packed word of the specified width from an integer value.
wordFromInt :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SWord sym)

-- | Concatenate the two given word values. NOTE: the first argument
--   represents the more-significant bits
joinWord :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Take the most-significant bits, and return those bits and the
--   remainder. The first element of the pair is the most significant bits.
--   The two integer sizes must sum to the length of the given word value.
splitWord :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SEval sym (SWord sym, SWord sym)

-- | Extract a subsequence of bits from a packed word value. The first
--   integer argument is the number of bits in the resulting word. The
--   second integer argument is the number of less-significant digits to
--   discard. Stated another way, the operation <tt>extractWord n i w</tt>
--   is equivalent to first shifting <tt>w</tt> right by <tt>i</tt> bits,
--   and then truncating to <tt>n</tt> bits.
extractWord :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SEval sym (SWord sym)

-- | Bitwise OR
wordOr :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Bitwise AND
wordAnd :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Bitwise XOR
wordXor :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Bitwise complement
wordComplement :: Backend sym => sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement addition of packed words. The arguments must have equal
--   bit width, and the result is of the same width. Overflow is silently
--   discarded.
wordPlus :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement subtraction of packed words. The arguments must have
--   equal bit width, and the result is of the same width. Overflow is
--   silently discarded.
wordMinus :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement multiplication of packed words. The arguments must have
--   equal bit width, and the result is of the same width. The high bits of
--   the multiplication are silently discarded.
wordMult :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement unsigned division of packed words. The arguments must
--   have equal bit width, and the result is of the same width. It is
--   illegal to call with a second argument concretely equal to 0.
wordDiv :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement unsigned modulus of packed words. The arguments must
--   have equal bit width, and the result is of the same width. It is
--   illegal to call with a second argument concretely equal to 0.
wordMod :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement signed division of packed words. The arguments must
--   have equal bit width, and the result is of the same width. It is
--   illegal to call with a second argument concretely equal to 0.
wordSignedDiv :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement signed modulus of packed words. The arguments must have
--   equal bit width, and the result is of the same width. It is illegal to
--   call with a second argument concretely equal to 0.
wordSignedMod :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Shift a bitvector left by the specified amount. The shift amount is
--   considered as an unsigned value. Shifting by more than the word length
--   results in 0.
wordShiftLeft :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Shift a bitvector right by the specified amount. This is a logical
--   shift, which shifts in 0 values on the left. The shift amount is
--   considered as an unsigned value. Shifting by more than the word length
--   results in 0.
wordShiftRight :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | Shift a bitvector right by the specified amount. This is an arithmetic
--   shift, which shifts in copies of the high bit on the left. The shift
--   amount is considered as an unsigned value. Shifting by more than the
--   word length results in filling the bitvector with the high bit.
wordSignedShiftRight :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)
wordRotateLeft :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)
wordRotateRight :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SWord sym)

-- | 2's complement negation of bitvectors
wordNegate :: Backend sym => sym -> SWord sym -> SEval sym (SWord sym)

-- | Compute rounded-up log-2 of the input
wordLg2 :: Backend sym => sym -> SWord sym -> SEval sym (SWord sym)

-- | Test if two words are equal. Arguments must have the same width.
wordEq :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SBit sym)

-- | Signed less-than comparison on words. Arguments must have the same
--   width.
wordSignedLessThan :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SBit sym)

-- | Unsigned less-than comparison on words. Arguments must have the same
--   width.
wordLessThan :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SBit sym)

-- | Unsigned greater-than comparison on words. Arguments must have the
--   same width.
wordGreaterThan :: Backend sym => sym -> SWord sym -> SWord sym -> SEval sym (SBit sym)

-- | Construct an integer value from the given packed word.
wordToInt :: Backend sym => sym -> SWord sym -> SEval sym (SInteger sym)

-- | Construct a signed integer value from the given packed word.
wordToSignedInt :: Backend sym => sym -> SWord sym -> SEval sym (SInteger sym)

-- | Addition of unbounded integers.
intPlus :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Negation of unbounded integers
intNegate :: Backend sym => sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Subtraction of unbounded integers.
intMinus :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Multiplication of unbounded integers.
intMult :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Integer division, rounding down. It is illegal to call with a second
--   argument concretely equal to 0. Same semantics as Haskell's
--   <tt>div</tt> operation.
intDiv :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Integer modulus, with division rounding down. It is illegal to call
--   with a second argument concretely equal to 0. Same semantics as
--   Haskell's <tt>mod</tt> operation.
intMod :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Equality comparison on integers
intEq :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SBit sym)

-- | Less-than comparison on integers
intLessThan :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SBit sym)

-- | Greater-than comparison on integers
intGreaterThan :: Backend sym => sym -> SInteger sym -> SInteger sym -> SEval sym (SBit sym)

-- | Turn an integer into a value in Z_n
intToZn :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SInteger sym)

-- | Transform a Z_n value into an integer, ensuring the value is properly
--   reduced modulo n
znToInt :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SInteger sym)

-- | Addition of integers modulo n, for a concrete positive integer n.
znPlus :: Backend sym => sym -> Integer -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Additive inverse of integers modulo n
znNegate :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SInteger sym)

-- | Subtraction of integers modulo n, for a concrete positive integer n.
znMinus :: Backend sym => sym -> Integer -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Multiplication of integers modulo n, for a concrete positive integer
--   n.
znMult :: Backend sym => sym -> Integer -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)

-- | Equality test of integers modulo n
znEq :: Backend sym => sym -> Integer -> SInteger sym -> SInteger sym -> SEval sym (SBit sym)

-- | Multiplicative inverse in (Z n). PRECONDITION: the modulus is a prime
znRecip :: Backend sym => sym -> Integer -> SInteger sym -> SEval sym (SInteger sym)
fpEq :: Backend sym => sym -> SFloat sym -> SFloat sym -> SEval sym (SBit sym)
fpLessThan :: Backend sym => sym -> SFloat sym -> SFloat sym -> SEval sym (SBit sym)
fpGreaterThan :: Backend sym => sym -> SFloat sym -> SFloat sym -> SEval sym (SBit sym)
fpLogicalEq :: Backend sym => sym -> SFloat sym -> SFloat sym -> SEval sym (SBit sym)
fpNaN :: Backend sym => sym -> Integer -> Integer -> SEval sym (SFloat sym)
fpPosInf :: Backend sym => sym -> Integer -> Integer -> SEval sym (SFloat sym)
fpPlus :: Backend sym => FPArith2 sym
fpMinus :: Backend sym => FPArith2 sym
fpMult :: Backend sym => FPArith2 sym
fpDiv :: Backend sym => FPArith2 sym
fpNeg :: Backend sym => sym -> SFloat sym -> SEval sym (SFloat sym)
fpAbs :: Backend sym => sym -> SFloat sym -> SEval sym (SFloat sym)
fpSqrt :: Backend sym => sym -> SWord sym -> SFloat sym -> SEval sym (SFloat sym)
fpFMA :: Backend sym => sym -> SWord sym -> SFloat sym -> SFloat sym -> SFloat sym -> SEval sym (SFloat sym)
fpIsZero :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsNeg :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsNaN :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsInf :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsNorm :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpIsSubnorm :: Backend sym => sym -> SFloat sym -> SEval sym (SBit sym)
fpToBits :: Backend sym => sym -> SFloat sym -> SEval sym (SWord sym)
fpFromBits :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SEval sym (SFloat sym)
fpToInteger :: Backend sym => sym -> String -> SWord sym -> SFloat sym -> SEval sym (SInteger sym)
fpFromInteger :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SInteger sym -> SEval sym (SFloat sym)
fpToRational :: Backend sym => sym -> SFloat sym -> SEval sym (SRational sym)
fpFromRational :: Backend sym => sym -> Integer -> Integer -> SWord sym -> SRational sym -> SEval sym (SFloat sym)
asciiMode :: PPOpts -> Integer -> Bool

-- | Some options for evalutaion
data EvalOpts
EvalOpts :: Logger -> PPOpts -> EvalOpts

-- | Where to print stuff (e.g., for <tt>trace</tt>)
[evalLogger] :: EvalOpts -> Logger

-- | How to pretty print things.
[evalPPOpts] :: EvalOpts -> PPOpts

-- | Create a packed word of n bits.
word :: Backend sym => sym -> Integer -> Integer -> SEval sym (GenValue sym)

-- | Construct a function value
lam :: Backend sym => sym -> (SEval sym (GenValue sym) -> SEval sym (GenValue sym)) -> SEval sym (GenValue sym)

-- | Functions that assume floating point inputs
flam :: Backend sym => sym -> (SFloat sym -> SEval sym (GenValue sym)) -> SEval sym (GenValue sym)

-- | A type lambda that expects a <tt>Type</tt>.
tlam :: Backend sym => sym -> (TValue -> SEval sym (GenValue sym)) -> SEval sym (GenValue sym)

-- | A type lambda that expects a <tt>Type</tt> of kind #.
nlam :: Backend sym => sym -> (Nat' -> SEval sym (GenValue sym)) -> SEval sym (GenValue sym)

-- | A type lambda that expects a finite numeric type.
ilam :: Backend sym => sym -> (Integer -> SEval sym (GenValue sym)) -> SEval sym (GenValue sym)

-- | Construct either a finite sequence, or a stream. In the finite case,
--   record whether or not the elements were bits, to aid pretty-printing.
mkSeq :: Backend sym => sym -> Nat' -> TValue -> SeqMap sym (GenValue sym) -> SEval sym (GenValue sym)

-- | Extract a bit value.
fromVBit :: GenValue sym -> SBit sym

-- | Extract an integer value.
fromVInteger :: GenValue sym -> SInteger sym

-- | Extract a rational value.
fromVRational :: GenValue sym -> SRational sym
fromVFloat :: GenValue sym -> SFloat sym

-- | Extract a finite sequence value.
fromVSeq :: GenValue sym -> SeqMap sym (GenValue sym)

-- | Extract a sequence.
fromSeq :: Backend sym => String -> GenValue sym -> SEval sym (SeqMap sym (GenValue sym))
fromWordVal :: Backend sym => String -> GenValue sym -> WordValue sym
asIndex :: Backend sym => sym -> String -> TValue -> GenValue sym -> Either (SInteger sym) (WordValue sym)

-- | Extract a packed word.
fromVWord :: Backend sym => sym -> String -> GenValue sym -> SEval sym (SWord sym)
vWordLen :: Backend sym => GenValue sym -> Maybe Integer

-- | If the given list of values are all fully-evaluated thunks containing
--   bits, return a packed word built from the same bits. However, if any
--   value is not a fully-evaluated bit, return <a>Nothing</a>.
tryFromBits :: Backend sym => sym -> [SEval sym (GenValue sym)] -> SEval sym (Maybe (SWord sym))

-- | Extract a function from a value.
fromVFun :: Backend sym => sym -> GenValue sym -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)

-- | Extract a polymorphic function from a value.
fromVPoly :: Backend sym => sym -> GenValue sym -> TValue -> SEval sym (GenValue sym)

-- | Extract a polymorphic function from a value.
fromVNumPoly :: Backend sym => sym -> GenValue sym -> Nat' -> SEval sym (GenValue sym)

-- | Extract a tuple from a value.
fromVTuple :: GenValue sym -> [SEval sym (GenValue sym)]

-- | Extract a record from a value.
fromVRecord :: GenValue sym -> RecordMap Ident (SEval sym (GenValue sym))

-- | Lookup a field in a record.
lookupRecord :: Ident -> GenValue sym -> SEval sym (GenValue sym)
defaultPPOpts :: PPOpts
ppValue :: forall sym. Backend sym => sym -> PPOpts -> GenValue sym -> SEval sym Doc
iteValue :: Backend sym => sym -> SBit sym -> SEval sym (GenValue sym) -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)
mergeValue :: Backend sym => sym -> SBit sym -> GenValue sym -> GenValue sym -> SEval sym (GenValue sym)
instance GHC.Generics.Generic (Cryptol.Eval.Value.GenValue sym)
instance GHC.Show.Show (Cryptol.Eval.Value.GenValue sym)


-- | This module generates random values for Cryptol types.
module Cryptol.Testing.Random
type Gen g x = Integer -> g -> (SEval x (GenValue x), g)

-- | A generator for values of the given type. This fails if we are given a
--   type that lacks a suitable random value generator.
randomValue :: (Backend sym, RandomGen g) => sym -> TValue -> Maybe (Gen g sym)

-- | Given a (function) type, compute generators for the function's
--   arguments.
dumpableType :: forall g. RandomGen g => TValue -> Maybe [Gen g Concrete]

-- | Given a (function) type, compute data necessary for random or
--   exhaustive testing.
--   
--   The first returned component is a count of the number of possible
--   input test vectors, if the input types are finite. The second
--   component is a list of all the types of the function inputs. The third
--   component is a list of all input test vectors for exhaustive testing.
--   This will be empty unless the input types are finite. The final
--   argument is a list of generators for the inputs of the function.
--   
--   This function will return <tt>Nothing</tt> if the input type does not
--   eventually return <tt>Bit</tt>, or if we cannot compute a generator
--   for one of the inputs.
testableType :: RandomGen g => TValue -> Maybe (Maybe Integer, [TValue], [[Value]], [Gen g Concrete])

-- | A test result is either a pass, a failure due to evaluating to
--   <tt>False</tt>, or a failure due to an exception raised during
--   evaluation
data TestResult
Pass :: TestResult
FailFalse :: [Value] -> TestResult
FailError :: EvalErrorEx -> [Value] -> TestResult
isPass :: TestResult -> Bool
returnTests :: RandomGen g => g -> [Gen g Concrete] -> Value -> Int -> IO [([Value], Value)]

-- | Return a collection of random tests.
returnTests' :: RandomGen g => g -> [Gen g Concrete] -> Value -> Int -> IO ([([Value], Value)], g)
exhaustiveTests :: MonadIO m => (Integer -> m ()) -> Value -> [[Value]] -> m (TestResult, Integer)
randomTests :: (MonadIO m, RandomGen g) => (Integer -> m ()) -> Integer -> Value -> [Gen g Concrete] -> g -> m (TestResult, Integer)
randomTests' :: (MonadIO m, RandomGen g) => (Integer -> m ()) -> Integer -> Value -> [Gen g Concrete] -> g -> m ((TestResult, Integer), g)

module Cryptol.Eval.Prims

-- | This type provides a lightweight syntactic framework for defining
--   Cryptol primitives. The main purpose of this type is to provide an
--   abstraction barrier that insulates the definitions of primitives from
--   possible changes in the representation of values.
data Prim sym
PFun :: (SEval sym (GenValue sym) -> Prim sym) -> Prim sym
PStrict :: (GenValue sym -> Prim sym) -> Prim sym
PWordFun :: (SWord sym -> Prim sym) -> Prim sym
PFloatFun :: (SFloat sym -> Prim sym) -> Prim sym
PTyPoly :: (TValue -> Prim sym) -> Prim sym
PNumPoly :: (Nat' -> Prim sym) -> Prim sym
PFinPoly :: (Integer -> Prim sym) -> Prim sym
PPrim :: SEval sym (GenValue sym) -> Prim sym
PVal :: GenValue sym -> Prim sym

-- | Evaluate a primitive into a value computation
evalPrim :: Backend sym => sym -> Name -> Prim sym -> SEval sym (GenValue sym)


module Cryptol.Eval.Env
data GenEvalEnv sym
EvalEnv :: !IntMap (Either (Prim sym) (SEval sym (GenValue sym))) -> !TypeEnv -> GenEvalEnv sym
[envVars] :: GenEvalEnv sym -> !IntMap (Either (Prim sym) (SEval sym (GenValue sym)))
[envTypes] :: GenEvalEnv sym -> !TypeEnv
ppEnv :: Backend sym => sym -> PPOpts -> GenEvalEnv sym -> SEval sym Doc

-- | Evaluation environment with no bindings
emptyEnv :: GenEvalEnv sym

-- | Bind a variable in the evaluation environment.
bindVar :: Backend sym => sym -> Name -> SEval sym (GenValue sym) -> GenEvalEnv sym -> SEval sym (GenEvalEnv sym)

-- | Bind a variable to a value in the evaluation environment, without
--   creating a thunk.
bindVarDirect :: Backend sym => Name -> Prim sym -> GenEvalEnv sym -> GenEvalEnv sym

-- | Lookup a variable in the environment.
lookupVar :: Name -> GenEvalEnv sym -> Maybe (Either (Prim sym) (SEval sym (GenValue sym)))

-- | Bind a type variable of kind *.
bindType :: TVar -> Either Nat' TValue -> GenEvalEnv sym -> GenEvalEnv sym

-- | Lookup a type variable.
lookupType :: TVar -> GenEvalEnv sym -> Maybe (Either Nat' TValue)
instance GHC.Generics.Generic (Cryptol.Eval.Env.GenEvalEnv sym)
instance GHC.Base.Semigroup (Cryptol.Eval.Env.GenEvalEnv sym)
instance GHC.Base.Monoid (Cryptol.Eval.Env.GenEvalEnv sym)


module Cryptol.Eval.Generic

-- | Make a numeric literal value at the given type.
mkLit :: Backend sym => sym -> TValue -> Integer -> SEval sym (GenValue sym)

-- | Make a numeric constant.
ecNumberV :: Backend sym => sym -> Prim sym
intV :: Backend sym => sym -> SInteger sym -> TValue -> SEval sym (GenValue sym)
ratioV :: Backend sym => sym -> Prim sym
ecFractionV :: Backend sym => sym -> Prim sym
fromZV :: Backend sym => sym -> Prim sym
type Binary sym = TValue -> GenValue sym -> GenValue sym -> SEval sym (GenValue sym)
binary :: Backend sym => Binary sym -> Prim sym
type Unary sym = TValue -> GenValue sym -> SEval sym (GenValue sym)
unary :: Backend sym => Unary sym -> Prim sym
type BinWord sym = Integer -> SWord sym -> SWord sym -> SEval sym (SWord sym)
ringBinary :: forall sym. Backend sym => sym -> BinWord sym -> (SInteger sym -> SInteger sym -> SEval sym (SInteger sym)) -> (Integer -> SInteger sym -> SInteger sym -> SEval sym (SInteger sym)) -> (SRational sym -> SRational sym -> SEval sym (SRational sym)) -> (SFloat sym -> SFloat sym -> SEval sym (SFloat sym)) -> Binary sym
type UnaryWord sym = Integer -> SWord sym -> SEval sym (SWord sym)
ringUnary :: forall sym. Backend sym => sym -> UnaryWord sym -> (SInteger sym -> SEval sym (SInteger sym)) -> (Integer -> SInteger sym -> SEval sym (SInteger sym)) -> (SRational sym -> SEval sym (SRational sym)) -> (SFloat sym -> SEval sym (SFloat sym)) -> Unary sym
ringNullary :: forall sym. Backend sym => sym -> (Integer -> SEval sym (SWord sym)) -> SEval sym (SInteger sym) -> (Integer -> SEval sym (SInteger sym)) -> SEval sym (SRational sym) -> (Integer -> Integer -> SEval sym (SFloat sym)) -> TValue -> SEval sym (GenValue sym)
integralBinary :: forall sym. Backend sym => sym -> BinWord sym -> (SInteger sym -> SInteger sym -> SEval sym (SInteger sym)) -> Binary sym

-- | Convert an unbounded integer to a value in Ring
fromIntegerV :: Backend sym => sym -> Prim sym
addV :: Backend sym => sym -> Binary sym
subV :: Backend sym => sym -> Binary sym
negateV :: Backend sym => sym -> Unary sym
mulV :: Backend sym => sym -> Binary sym
divV :: Backend sym => sym -> Binary sym
expV :: Backend sym => sym -> Prim sym
computeExponent :: Backend sym => sym -> TValue -> GenValue sym -> [SBit sym] -> SEval sym (GenValue sym)
modV :: Backend sym => sym -> Binary sym

-- | Convert a word to a non-negative integer.
toIntegerV :: Backend sym => sym -> Prim sym
recipV :: Backend sym => sym -> Prim sym
fieldDivideV :: Backend sym => sym -> Prim sym
roundOp :: Backend sym => sym -> String -> (SRational sym -> SEval sym (SInteger sym)) -> (SFloat sym -> SEval sym (SInteger sym)) -> Unary sym
floorV :: Backend sym => sym -> Unary sym
ceilingV :: Backend sym => sym -> Unary sym
truncV :: Backend sym => sym -> Unary sym
roundAwayV :: Backend sym => sym -> Unary sym
roundToEvenV :: Backend sym => sym -> Unary sym
andV :: Backend sym => sym -> Binary sym
orV :: Backend sym => sym -> Binary sym
xorV :: Backend sym => sym -> Binary sym
complementV :: Backend sym => sym -> Unary sym
lg2V :: Backend sym => sym -> Prim sym
sdivV :: Backend sym => sym -> Prim sym
smodV :: Backend sym => sym -> Prim sym
toSignedIntegerV :: Backend sym => sym -> Prim sym
cmpValue :: Backend sym => sym -> (SBit sym -> SBit sym -> SEval sym a -> SEval sym a) -> (SWord sym -> SWord sym -> SEval sym a -> SEval sym a) -> (SInteger sym -> SInteger sym -> SEval sym a -> SEval sym a) -> (Integer -> SInteger sym -> SInteger sym -> SEval sym a -> SEval sym a) -> (SRational sym -> SRational sym -> SEval sym a -> SEval sym a) -> (SFloat sym -> SFloat sym -> SEval sym a -> SEval sym a) -> TValue -> GenValue sym -> GenValue sym -> SEval sym a -> SEval sym a
bitLessThan :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
bitGreaterThan :: Backend sym => sym -> SBit sym -> SBit sym -> SEval sym (SBit sym)
valEq :: Backend sym => sym -> TValue -> GenValue sym -> GenValue sym -> SEval sym (SBit sym)
valLt :: Backend sym => sym -> TValue -> GenValue sym -> GenValue sym -> SBit sym -> SEval sym (SBit sym)
valGt :: Backend sym => sym -> TValue -> GenValue sym -> GenValue sym -> SBit sym -> SEval sym (SBit sym)
eqCombine :: Backend sym => sym -> SEval sym (SBit sym) -> SEval sym (SBit sym) -> SEval sym (SBit sym)
lexCombine :: Backend sym => sym -> SEval sym (SBit sym) -> SEval sym (SBit sym) -> SEval sym (SBit sym) -> SEval sym (SBit sym)
eqV :: Backend sym => sym -> Binary sym
distinctV :: Backend sym => sym -> Binary sym
lessThanV :: Backend sym => sym -> Binary sym
lessThanEqV :: Backend sym => sym -> Binary sym
greaterThanV :: Backend sym => sym -> Binary sym
greaterThanEqV :: Backend sym => sym -> Binary sym
signedLessThanV :: Backend sym => sym -> Binary sym
zeroV :: forall sym. Backend sym => sym -> TValue -> SEval sym (GenValue sym)
joinSeq :: Backend sym => sym -> Nat' -> Integer -> TValue -> SEval sym (SeqMap sym (GenValue sym)) -> SEval sym (GenValue sym)

-- | Join a sequence of sequences into a single sequence.
joinV :: Backend sym => sym -> Nat' -> Integer -> TValue -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)
takeV :: Backend sym => sym -> Nat' -> Nat' -> TValue -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)
dropV :: Backend sym => sym -> Integer -> Nat' -> TValue -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)

-- | Split implementation.
splitV :: Backend sym => sym -> Nat' -> Integer -> TValue -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)
reverseV :: forall sym. Backend sym => sym -> Integer -> TValue -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)
transposeV :: Backend sym => sym -> Nat' -> Nat' -> TValue -> GenValue sym -> SEval sym (GenValue sym)
ccatV :: Backend sym => sym -> Integer -> Nat' -> TValue -> SEval sym (GenValue sym) -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)

-- | Merge two values given a binop. This is used for and, or and xor.
logicBinary :: forall sym. Backend sym => sym -> (SBit sym -> SBit sym -> SEval sym (SBit sym)) -> (SWord sym -> SWord sym -> SEval sym (SWord sym)) -> Binary sym
logicUnary :: forall sym. Backend sym => sym -> (SBit sym -> SEval sym (SBit sym)) -> (SWord sym -> SEval sym (SWord sym)) -> Unary sym
assertIndexInBounds :: Backend sym => sym -> Nat' -> Either (SInteger sym) (WordValue sym) -> SEval sym ()

-- | Indexing operations.
indexPrim :: Backend sym => sym -> IndexDirection -> (Nat' -> TValue -> SeqMap sym (GenValue sym) -> TValue -> SInteger sym -> SEval sym (GenValue sym)) -> (Nat' -> TValue -> SeqMap sym (GenValue sym) -> TValue -> Integer -> [IndexSegment sym] -> SEval sym (GenValue sym)) -> Prim sym
updatePrim :: Backend sym => sym -> (Nat' -> TValue -> WordValue sym -> Either (SInteger sym) (WordValue sym) -> SEval sym (GenValue sym) -> SEval sym (WordValue sym)) -> (Nat' -> TValue -> SeqMap sym (GenValue sym) -> Either (SInteger sym) (WordValue sym) -> SEval sym (GenValue sym) -> SEval sym (SeqMap sym (GenValue sym))) -> Prim sym
fromToV :: Backend sym => sym -> Prim sym
fromThenToV :: Backend sym => sym -> Prim sym
fromToLessThanV :: Backend sym => sym -> Prim sym
fromToByV :: Backend sym => sym -> Prim sym
fromToByLessThanV :: Backend sym => sym -> Prim sym
fromToDownByV :: Backend sym => sym -> Prim sym
fromToDownByGreaterThanV :: Backend sym => sym -> Prim sym
infFromV :: Backend sym => sym -> Prim sym
infFromThenV :: Backend sym => sym -> Prim sym
shiftLeftReindex :: Nat' -> Integer -> Integer -> Maybe Integer
shiftRightReindex :: Nat' -> Integer -> Integer -> Maybe Integer
rotateLeftReindex :: Nat' -> Integer -> Integer -> Maybe Integer
rotateRightReindex :: Nat' -> Integer -> Integer -> Maybe Integer

-- | Generic implementation of shifting. Uses the provided word-level
--   operation to perform the shift, when possible. Otherwise falls back on
--   a barrel shifter that uses the provided reindexing operation to
--   implement the concrete shifting operations. The reindex operation is
--   given the size of the sequence, the requested index value for the new
--   output sequence, and the amount to shift. The return value is an index
--   into the original sequence if in bounds, and Nothing otherwise.
logicShift :: Backend sym => sym -> String -> (sym -> Nat' -> TValue -> SInteger sym -> SEval sym (SInteger sym)) -> (SWord sym -> SWord sym -> SEval sym (SWord sym)) -> (SWord sym -> SWord sym -> SEval sym (SWord sym)) -> (Nat' -> Integer -> Integer -> Maybe Integer) -> (Nat' -> Integer -> Integer -> Maybe Integer) -> Prim sym
intShifter :: Backend sym => sym -> String -> (SWord sym -> SWord sym -> SEval sym (SWord sym)) -> (Nat' -> Integer -> Integer -> Maybe Integer) -> Nat' -> TValue -> GenValue sym -> SInteger sym -> SEval sym (GenValue sym)
wordShifter :: Backend sym => sym -> String -> (SWord sym -> SWord sym -> SEval sym (SWord sym)) -> (Nat' -> Integer -> Integer -> Maybe Integer) -> Nat' -> TValue -> GenValue sym -> WordValue sym -> SEval sym (GenValue sym)
shiftShrink :: Backend sym => sym -> Nat' -> TValue -> SInteger sym -> SEval sym (SInteger sym)
rotateShrink :: Backend sym => sym -> Nat' -> TValue -> SInteger sym -> SEval sym (SInteger sym)
sshrV :: Backend sym => sym -> Prim sym
errorV :: forall sym. Backend sym => sym -> TValue -> String -> SEval sym (GenValue sym)

-- | Expect a word value. Mask it to an 8-bits ASCII value and return the
--   associated character, if it is concrete. Otherwise, return a
--   <tt>?</tt> character
valueToChar :: Backend sym => sym -> GenValue sym -> SEval sym Char
valueToString :: Backend sym => sym -> GenValue sym -> SEval sym String
foldlV :: Backend sym => sym -> Prim sym
foldl'V :: Backend sym => sym -> Prim sym
scanlV :: forall sym. Backend sym => sym -> Prim sym

-- | Produce a random value with the given seed. If we do not support
--   making values of the given type, return zero of that type. TODO: do
--   better than returning zero
randomV :: Backend sym => sym -> TValue -> Integer -> SEval sym (GenValue sym)
parmapV :: Backend sym => sym -> Prim sym
sparkParMap :: Backend sym => sym -> (SEval sym a -> SEval sym (GenValue sym)) -> Integer -> SeqMap sym a -> SEval sym (SeqMap sym (GenValue sym))

-- | A helper for definitng floating point constants.
fpConst :: Backend sym => (Integer -> Integer -> SEval sym (SFloat sym)) -> Prim sym

-- | Make a Cryptol value for a binary arithmetic function.
fpBinArithV :: Backend sym => sym -> FPArith2 sym -> Prim sym

-- | Rounding mode used in FP operations that do not specify it explicitly.
fpRndMode :: Backend sym => sym -> SEval sym (SWord sym)

-- | Rounding mode used in FP operations that do not specify it explicitly.
fpRndRNE :: Backend sym => sym -> SEval sym (SWord sym)

-- | Rounding mode used in FP operations that do not specify it explicitly.
fpRndRNA :: Backend sym => sym -> SEval sym (SWord sym)

-- | Rounding mode used in FP operations that do not specify it explicitly.
fpRndRTP :: Backend sym => sym -> SEval sym (SWord sym)

-- | Rounding mode used in FP operations that do not specify it explicitly.
fpRndRTN :: Backend sym => sym -> SEval sym (SWord sym)

-- | Rounding mode used in FP operations that do not specify it explicitly.
fpRndRTZ :: Backend sym => sym -> SEval sym (SWord sym)
genericFloatTable :: Backend sym => sym -> Map PrimIdent (Prim sym)
genericPrimTable :: Backend sym => sym -> IO EvalOpts -> Map PrimIdent (Prim sym)


module Cryptol.Eval.What4
type Value sym = GenValue (What4 sym)
primTable :: IsSymExprBuilder sym => What4 sym -> IO EvalOpts -> Map PrimIdent (Prim (What4 sym))


module Cryptol.Eval.Concrete
type Value = GenValue Concrete
primTable :: IO EvalOpts -> Map PrimIdent (Prim Concrete)

-- | Given an expected type, returns an expression that evaluates to this
--   value, if we can determine it.
toExpr :: PrimMap -> TValue -> Value -> Eval (Maybe Expr)


module Cryptol.Symbolic
data ProverCommand
ProverCommand :: QueryType -> String -> Bool -> Bool -> !IORef ProverStats -> [DeclGroup] -> Maybe FilePath -> Expr -> Schema -> Bool -> ProverCommand

-- | The type of query to run
[pcQueryType] :: ProverCommand -> QueryType

-- | Which prover to use (one of the strings in <tt>proverConfigs</tt>)
[pcProverName] :: ProverCommand -> String

-- | Verbosity flag passed to SBV
[pcVerbose] :: ProverCommand -> Bool

-- | Model validation flag passed to SBV
[pcValidate] :: ProverCommand -> Bool

-- | Record timing information here
[pcProverStats] :: ProverCommand -> !IORef ProverStats

-- | Extra declarations to bring into scope for symbolic simulation
[pcExtraDecls] :: ProverCommand -> [DeclGroup]

-- | Optionally output the SMTLIB query to a file
[pcSmtFile] :: ProverCommand -> Maybe FilePath

-- | The typechecked expression to evaluate
[pcExpr] :: ProverCommand -> Expr

-- | The <a>Schema</a> of <tt>pcExpr</tt>
[pcSchema] :: ProverCommand -> Schema

-- | Should we ignore safety predicates?
[pcIgnoreSafety] :: ProverCommand -> Bool
data QueryType
SatQuery :: SatNum -> QueryType
ProveQuery :: QueryType
SafetyQuery :: QueryType
data SatNum
AllSat :: SatNum
SomeSat :: Int -> SatNum

-- | A prover result is either an error message, an empty result (eg for
--   the offline prover), a counterexample or a lazy list of satisfying
--   assignments.
data ProverResult
AllSatResult :: [SatResult] -> ProverResult
ThmResult :: [TValue] -> ProverResult
CounterExample :: CounterExampleType -> SatResult -> ProverResult
EmptyResult :: ProverResult
ProverError :: String -> ProverResult
type ProverStats = NominalDiffTime

-- | A <tt>:prove</tt> command can fail either because some input causes
--   the predicate to violate a safety assertion, or because the predicate
--   returns false for some input.
data CounterExampleType
SafetyViolation :: CounterExampleType
PredicateFalsified :: CounterExampleType
data FinType
FTBit :: FinType
FTInteger :: FinType
FTIntMod :: Integer -> FinType
FTRational :: FinType
FTFloat :: Integer -> Integer -> FinType
FTSeq :: Integer -> FinType -> FinType
FTTuple :: [FinType] -> FinType
FTRecord :: RecordMap Ident FinType -> FinType
FTNewtype :: Newtype -> [Either Nat' TValue] -> RecordMap Ident FinType -> FinType
finType :: TValue -> Maybe FinType
unFinType :: FinType -> TValue
predArgTypes :: QueryType -> Schema -> Either String [FinType]
data VarShape sym
VarBit :: SBit sym -> VarShape sym
VarInteger :: SInteger sym -> VarShape sym
VarRational :: SInteger sym -> SInteger sym -> VarShape sym
VarFloat :: SFloat sym -> VarShape sym
VarWord :: SWord sym -> VarShape sym
VarFinSeq :: Integer -> [VarShape sym] -> VarShape sym
VarTuple :: [VarShape sym] -> VarShape sym
VarRecord :: RecordMap Ident (VarShape sym) -> VarShape sym
varShapeToValue :: Backend sym => sym -> VarShape sym -> GenValue sym
freshVar :: Backend sym => FreshVarFns sym -> FinType -> IO (VarShape sym)
computeModel :: PrimMap -> [FinType] -> [VarShape Concrete] -> [(TValue, Expr, Value)]
data FreshVarFns sym
FreshVarFns :: IO (SBit sym) -> (Integer -> IO (SWord sym)) -> (Maybe Integer -> Maybe Integer -> IO (SInteger sym)) -> (Integer -> Integer -> IO (SFloat sym)) -> FreshVarFns sym
[freshBitVar] :: FreshVarFns sym -> IO (SBit sym)
[freshWordVar] :: FreshVarFns sym -> Integer -> IO (SWord sym)
[freshIntegerVar] :: FreshVarFns sym -> Maybe Integer -> Maybe Integer -> IO (SInteger sym)
[freshFloatVar] :: FreshVarFns sym -> Integer -> Integer -> IO (SFloat sym)
modelPred :: Backend sym => sym -> [VarShape sym] -> [VarShape Concrete] -> SEval sym (SBit sym)
varModelPred :: Backend sym => sym -> (VarShape sym, VarShape Concrete) -> SEval sym (SBit sym)
varToExpr :: PrimMap -> FinType -> VarShape Concrete -> Expr
flattenShape :: VarShape sym -> [VarShape sym] -> [VarShape sym]

-- | Flatten structured shapes (like tuples and sequences), leaving only a
--   sequence of variable shapes of base type.
flattenShapes :: [VarShape sym] -> [VarShape sym] -> [VarShape sym]
instance GHC.Show.Show Cryptol.Symbolic.SatNum
instance GHC.Show.Show Cryptol.Symbolic.QueryType


module Cryptol.Eval

-- | Extend the given evaluation environment with all the declarations
--   contained in the given module.
moduleEnv :: EvalPrims sym => sym -> Module -> GenEvalEnv sym -> SEval sym (GenEvalEnv sym)

-- | Execute the given evaluation action.
runEval :: CallStack -> Eval a -> IO a

-- | Some options for evalutaion
data EvalOpts
EvalOpts :: Logger -> PPOpts -> EvalOpts

-- | Where to print stuff (e.g., for <tt>trace</tt>)
[evalLogger] :: EvalOpts -> Logger

-- | How to pretty print things.
[evalPPOpts] :: EvalOpts -> PPOpts

-- | How to pretty print things when evaluating
data PPOpts
PPOpts :: Bool -> Int -> Int -> Int -> PPFloatFormat -> FieldOrder -> PPOpts
[useAscii] :: PPOpts -> Bool
[useBase] :: PPOpts -> Int
[useInfLength] :: PPOpts -> Int
[useFPBase] :: PPOpts -> Int
[useFPFormat] :: PPOpts -> PPFloatFormat
[useFieldOrder] :: PPOpts -> FieldOrder
defaultPPOpts :: PPOpts

-- | The monad for Cryptol evaluation. A computation is either "ready",
--   which means it represents only trivial computation, or is an "eval"
--   action which must be computed to get the answer, or it is a "thunk",
--   which represents a delayed, shared computation.
data Eval a
type EvalEnv = GenEvalEnv Concrete

-- | Evaluation environment with no bindings
emptyEnv :: GenEvalEnv sym

-- | Evaluate a Cryptol expression to a value. This evaluator is
--   parameterized by the <a>EvalPrims</a> class, which defines the
--   behavior of bits and words, in addition to providing implementations
--   for all the primitives.
evalExpr :: (?range :: Range, EvalPrims sym) => sym -> GenEvalEnv sym -> Expr -> SEval sym (GenValue sym)

-- | Extend the given evaluation environment with the result of evaluating
--   the given collection of declaration groups.
evalDecls :: EvalPrims sym => sym -> [DeclGroup] -> GenEvalEnv sym -> SEval sym (GenEvalEnv sym)
evalNewtypeDecls :: EvalPrims sym => sym -> Map Name Newtype -> GenEvalEnv sym -> SEval sym (GenEvalEnv sym)

-- | Apply the the given "selector" form to the given value. Note that
--   selectors are expected to apply only to values of the right type, e.g.
--   tuple selectors expect only tuple values. The lifting of tuple an
--   record selectors over functions and sequences has already been
--   resolved earlier in the typechecker.
evalSel :: Backend sym => sym -> GenValue sym -> Selector -> SEval sym (GenValue sym)
evalSetSel :: forall sym. Backend sym => sym -> TValue -> GenValue sym -> Selector -> SEval sym (GenValue sym) -> SEval sym (GenValue sym)

-- | Data type describing errors that can occur during evaluation.
data EvalError

-- | Out-of-bounds index
InvalidIndex :: Maybe Integer -> EvalError

-- | Division or modulus by 0
DivideByZero :: EvalError

-- | Exponentiation by negative integer
NegativeExponent :: EvalError

-- | Logarithm of a negative integer
LogNegative :: EvalError

-- | Call to the Cryptol <tt>error</tt> primitive
UserError :: String -> EvalError

-- | Detectable nontermination
LoopError :: String -> EvalError

-- | Primitive with no implementation
NoPrim :: Name -> EvalError

-- | Invalid rounding mode
BadRoundingMode :: Integer -> EvalError

-- | Value outside the domain of a partial function.
BadValue :: String -> EvalError

-- | No prop guard holds for the given type variables.
NoMatchingPropGuardCase :: String -> EvalError

-- | Foreign function cannot be called
FFINotSupported :: Name -> EvalError

-- | Number passed to foreign function as a type argument is too large
FFITypeNumTooBig :: Name -> TParam -> Integer -> EvalError
data EvalErrorEx
EvalErrorEx :: CallStack -> EvalError -> EvalErrorEx
data Unsupported

-- | Operation cannot be supported in the symbolic simulator
UnsupportedSymbolicOp :: String -> Unsupported
data WordTooWide

-- | Bitvector too large
WordTooWide :: Integer -> WordTooWide

-- | Force the evaluation of a value
forceValue :: Backend sym => GenValue sym -> SEval sym ()

-- | Checks whether an evaluated <a>Prop</a> holds
checkProp :: Prop -> Bool
instance GHC.Base.Semigroup (Cryptol.Eval.ListEnv sym)
instance GHC.Base.Monoid (Cryptol.Eval.ListEnv sym)


module Cryptol.ModuleSystem.Env

-- | This is the current state of the interpreter.
data ModuleEnv
ModuleEnv :: LoadedModules -> NameSeeds -> EvalEnv -> CoreLint -> !Bool -> Maybe ModName -> [FilePath] -> DynamicEnv -> !Supply -> ModuleEnv

-- | Information about all loaded modules. See <a>LoadedModuleG</a>.
--   Contains information such as the file where the module was loaded
--   from, as well as the module's interface, used for type checking.
[meLoadedModules] :: ModuleEnv -> LoadedModules

-- | A source of new names for the type checker.
[meNameSeeds] :: ModuleEnv -> NameSeeds

-- | The evaluation environment. Contains the values for all loaded
--   modules, both public and private.
[meEvalEnv] :: ModuleEnv -> EvalEnv

-- | Should we run the linter to ensure sanity.
[meCoreLint] :: ModuleEnv -> CoreLint

-- | Are we assuming that local bindings are monomorphic. XXX: We should
--   probably remove this flag, and set it to <a>True</a>.
[meMonoBinds] :: ModuleEnv -> !Bool

-- | The "current" module. Used to decide how to print names, for example.
[meFocusedModule] :: ModuleEnv -> Maybe ModName

-- | Where we look for things.
[meSearchPath] :: ModuleEnv -> [FilePath]

-- | This contains additional definitions that were made at the command
--   line, and so they don't reside in any module.
[meDynEnv] :: ModuleEnv -> DynamicEnv

-- | Name source for the renamer
[meSupply] :: ModuleEnv -> !Supply

-- | Should we run the linter?
data CoreLint

-- | Don't run core lint
NoCoreLint :: CoreLint

-- | Run core lint
CoreLint :: CoreLint
resetModuleEnv :: ModuleEnv -> IO ModuleEnv
initialModuleEnv :: IO ModuleEnv

-- | Try to focus a loaded module in the module environment.
focusModule :: ModName -> ModuleEnv -> Maybe ModuleEnv

-- | Get a list of all the loaded modules. Each module in the resulting
--   list depends only on other modules that precede it. Note that this
--   includes parameterized modules.
loadedModules :: ModuleEnv -> [Module]

-- | Get a list of all the loaded non-parameterized modules. These are the
--   modules that can be used for evaluation, proving etc.
loadedNonParamModules :: ModuleEnv -> [Module]
loadedNewtypes :: ModuleEnv -> Map Name Newtype

-- | Are any parameterized modules loaded?
hasParamModules :: ModuleEnv -> Bool
allDeclGroups :: ModuleEnv -> [DeclGroup]
data ModContextParams
InterfaceParams :: ModParamNames -> ModContextParams
FunctorParams :: FunctorParams -> ModContextParams
NoParams :: ModContextParams
modContextParamNames :: ModContextParams -> ModParamNames

-- | Contains enough information to browse what's in scope, or type check
--   new expressions.
data ModContext
ModContext :: ModContextParams -> Set Name -> IfaceDecls -> NamingEnv -> NameDisp -> ModContext
[mctxParams] :: ModContext -> ModContextParams
[mctxExported] :: ModContext -> Set Name

-- | Should contain at least names in NamingEnv, but may have more
[mctxDecls] :: ModContext -> IfaceDecls

-- | What's in scope inside the module
[mctxNames] :: ModContext -> NamingEnv
[mctxNameDisp] :: ModContext -> NameDisp
modContextOf :: ModName -> ModuleEnv -> Maybe ModContext
dynModContext :: ModuleEnv -> ModContext

-- | Given the state of the environment, compute information about what's
--   in scope on the REPL. This includes what's in the focused module, plus
--   any additional definitions from the REPL (e.g., let bound names, and
--   <tt>it</tt>).
focusedEnv :: ModuleEnv -> ModContext

-- | The location of a module
data ModulePath
InFile :: FilePath -> ModulePath

-- | Label, content
InMem :: String -> ByteString -> ModulePath

-- | The name of the content---either the file path, or the provided label.
modulePathLabel :: ModulePath -> String
data LoadedModules
LoadedModules :: [LoadedModule] -> [LoadedModule] -> ![LoadedSignature] -> LoadedModules

-- | Invariants: 1) All the dependencies of any module <tt>m</tt> must
--   precede <tt>m</tt> in the list. 2) Does not contain any parameterized
--   modules.
[lmLoadedModules] :: LoadedModules -> [LoadedModule]

-- | Loaded parameterized modules.
[lmLoadedParamModules] :: LoadedModules -> [LoadedModule]
[lmLoadedSignatures] :: LoadedModules -> ![LoadedSignature]
data LoadedEntity
ALoadedModule :: LoadedModule -> LoadedEntity
ALoadedFunctor :: LoadedModule -> LoadedEntity
ALoadedInterface :: LoadedSignature -> LoadedEntity
getLoadedEntities :: LoadedModules -> Map ModName LoadedEntity
getLoadedModules :: LoadedModules -> [LoadedModule]
getLoadedNames :: LoadedModules -> Set ModName

-- | A generic type for loaded things. The things can be either modules or
--   signatures.
data LoadedModuleG a
LoadedModule :: ModName -> ModulePath -> String -> !NamingEnv -> !FileInfo -> a -> LoadedModuleG a

-- | The name of this module. Should match what's in <a>lmModule</a>
[lmName] :: LoadedModuleG a -> ModName

-- | The file path used to load this module (may not be canonical)
[lmFilePath] :: LoadedModuleG a -> ModulePath

-- | An identifier used to identify the source of the bytes for the module.
--   For files we just use the cononical path, for in memory things we use
--   their label.
[lmModuleId] :: LoadedModuleG a -> String

-- | What's in scope in this module
[lmNamingEnv] :: LoadedModuleG a -> !NamingEnv
[lmFileInfo] :: LoadedModuleG a -> !FileInfo
[lmData] :: LoadedModuleG a -> a
type LoadedModule = LoadedModuleG LoadedModuleData
lmModule :: LoadedModule -> Module
lmInterface :: LoadedModule -> Iface
data LoadedModuleData
LoadedModuleData :: Iface -> Module -> Maybe ForeignSrc -> LoadedModuleData

-- | The module's interface.
[lmdInterface] :: LoadedModuleData -> Iface

-- | The actual type-checked module
[lmdModule] :: LoadedModuleData -> Module

-- | The dynamically loaded source for any foreign functions in the module
[lmForeignSrc] :: LoadedModuleData -> Maybe ForeignSrc
type LoadedSignature = LoadedModuleG ModParamNames

-- | Has this module been loaded already.
isLoaded :: ModName -> LoadedModules -> Bool

-- | Is this a loaded parameterized module.
isLoadedParamMod :: ModName -> LoadedModules -> Bool

-- | Is this a loaded interface module.
isLoadedInterface :: ModName -> LoadedModules -> Bool
lookupTCEntity :: ModName -> ModuleEnv -> Maybe (LoadedModuleG TCTopEntity)

-- | Try to find a previously loaded module
lookupModule :: ModName -> ModuleEnv -> Maybe LoadedModule
lookupSignature :: ModName -> ModuleEnv -> Maybe LoadedSignature
addLoadedSignature :: ModulePath -> String -> FileInfo -> NamingEnv -> ModName -> ModParamNames -> LoadedModules -> LoadedModules

-- | Add a freshly loaded module. If it was previously loaded, then the new
--   version is ignored.
addLoadedModule :: ModulePath -> String -> FileInfo -> NamingEnv -> Maybe ForeignSrc -> Module -> LoadedModules -> LoadedModules

-- | Remove a previously loaded module. Note that this removes exactly the
--   modules specified by the predicate. One should be carfule to preserve
--   the invariant on <a>LoadedModules</a>.
removeLoadedModule :: (forall a. LoadedModuleG a -> Bool) -> LoadedModules -> LoadedModules
data FileInfo
FileInfo :: Fingerprint -> Set FilePath -> Set ModName -> Set FilePath -> FileInfo
[fiFingerprint] :: FileInfo -> Fingerprint
[fiIncludeDeps] :: FileInfo -> Set FilePath
[fiImportDeps] :: FileInfo -> Set ModName
[fiForeignDeps] :: FileInfo -> Set FilePath
fileInfo :: Fingerprint -> Set FilePath -> Set ModName -> Maybe ForeignSrc -> FileInfo

-- | Extra information we need to carry around to dynamically extend an
--   environment outside the context of a single module. Particularly
--   useful when dealing with interactive declarations as in <tt>let</tt>
--   or <tt>it</tt>.
data DynamicEnv
DEnv :: NamingEnv -> [DeclGroup] -> Map Name TySyn -> EvalEnv -> DynamicEnv
[deNames] :: DynamicEnv -> NamingEnv
[deDecls] :: DynamicEnv -> [DeclGroup]
[deTySyns] :: DynamicEnv -> Map Name TySyn
[deEnv] :: DynamicEnv -> EvalEnv

-- | Build <a>IfaceDecls</a> that correspond to all of the bindings in the
--   dynamic environment.
--   
--   XXX: if we add newtypes, etc. at the REPL, revisit this.
deIfaceDecls :: DynamicEnv -> IfaceDecls
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Env.CoreLint
instance GHC.Generics.Generic Cryptol.ModuleSystem.Env.CoreLint
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Env.ModulePath
instance GHC.Generics.Generic Cryptol.ModuleSystem.Env.ModulePath
instance GHC.Show.Show Cryptol.ModuleSystem.Env.ModulePath
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Env.LoadedModuleData
instance GHC.Generics.Generic Cryptol.ModuleSystem.Env.LoadedModuleData
instance GHC.Show.Show Cryptol.ModuleSystem.Env.LoadedModuleData
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Env.FileInfo
instance GHC.Generics.Generic Cryptol.ModuleSystem.Env.FileInfo
instance GHC.Show.Show Cryptol.ModuleSystem.Env.FileInfo
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Cryptol.ModuleSystem.Env.LoadedModuleG a)
instance GHC.Generics.Generic (Cryptol.ModuleSystem.Env.LoadedModuleG a)
instance GHC.Show.Show a => GHC.Show.Show (Cryptol.ModuleSystem.Env.LoadedModuleG a)
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Env.LoadedModules
instance GHC.Generics.Generic Cryptol.ModuleSystem.Env.LoadedModules
instance GHC.Show.Show Cryptol.ModuleSystem.Env.LoadedModules
instance GHC.Generics.Generic Cryptol.ModuleSystem.Env.DynamicEnv
instance GHC.Generics.Generic Cryptol.ModuleSystem.Env.ModuleEnv
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Env.ModuleEnv
instance GHC.Base.Semigroup Cryptol.ModuleSystem.Env.DynamicEnv
instance GHC.Base.Monoid Cryptol.ModuleSystem.Env.DynamicEnv
instance GHC.Base.Semigroup Cryptol.ModuleSystem.Env.LoadedModules
instance GHC.Base.Monoid Cryptol.ModuleSystem.Env.LoadedModules
instance GHC.Classes.Eq Cryptol.ModuleSystem.Env.ModulePath
instance GHC.Classes.Ord Cryptol.ModuleSystem.Env.ModulePath
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Env.ModulePath
instance GHC.Base.Semigroup Cryptol.ModuleSystem.Env.ModContext
instance GHC.Base.Monoid Cryptol.ModuleSystem.Env.ModContext

module Cryptol.REPL.Browse
data BrowseHow
BrowseExported :: BrowseHow
BrowseInScope :: BrowseHow
browseModContext :: BrowseHow -> ModContext -> Doc Void


-- | Evaluation of foreign functions.
module Cryptol.Eval.FFI

-- | Find all the foreign declarations in the module and return their names
--   and FFIFunTypes.
findForeignDecls :: ModuleG mname -> [(Name, FFIFunType)]

-- | Add the given foreign declarations to the environment, loading their
--   implementations from the given <a>ForeignSrc</a>. This is a separate
--   pass from the main evaluation functions in <a>Cryptol.Eval</a> since
--   it only works for the Concrete backend.
evalForeignDecls :: ForeignSrc -> [(Name, FFIFunType)] -> EvalEnv -> Eval (Either [FFILoadError] EvalEnv)


module Cryptol.Backend.SBV
data SBV
SBV :: MVar State -> MVar SVal -> SBV
[sbvStateVar] :: SBV -> MVar State
[sbvDefRelations] :: SBV -> MVar SVal
newtype SBVEval a
SBVEval :: Eval (SBVResult a) -> SBVEval a
[sbvEval] :: SBVEval a -> Eval (SBVResult a)
data SBVResult a
SBVError :: !EvalErrorEx -> SBVResult a
SBVResult :: !SVal -> !a -> SBVResult a
literalSWord :: Int -> Integer -> SWord SBV
freshSBool_ :: SBV -> IO (SBit SBV)
freshBV_ :: SBV -> Int -> IO (SWord SBV)
freshSInteger_ :: SBV -> IO (SInteger SBV)
addDefEqn :: SBV -> SVal -> IO ()
ashr :: SVal -> SVal -> SVal
lshr :: SVal -> SVal -> SVal
shl :: SVal -> SVal -> SVal
evalPanic :: String -> [String] -> a
svFromInteger :: Integer -> SInteger SBV -> SWord SBV
svToInteger :: SWord SBV -> SInteger SBV
instance GHC.Base.Functor Cryptol.Backend.SBV.SBVEval
instance GHC.Base.Applicative Cryptol.Backend.SBV.SBVEval
instance GHC.Base.Monad Cryptol.Backend.SBV.SBVEval
instance Control.Monad.IO.Class.MonadIO Cryptol.Backend.SBV.SBVEval
instance Cryptol.Backend.Backend Cryptol.Backend.SBV.SBV
instance GHC.Base.Functor Cryptol.Backend.SBV.SBVResult
instance GHC.Base.Applicative Cryptol.Backend.SBV.SBVResult
instance GHC.Base.Monad Cryptol.Backend.SBV.SBVResult


module Cryptol.Eval.SBV
primTable :: SBV -> IO EvalOpts -> Map PrimIdent (Prim SBV)


module Cryptol.Version
commitHash :: String
commitShortHash :: String
commitBranch :: String
commitDirty :: Bool
version :: Version
displayVersion :: Monad m => (String -> m ()) -> m ()


module Cryptol.Parser
parseModule :: Config -> Text -> Either ParseError [Module PName]
parseProgram :: Layout -> Text -> Either ParseError (Program PName)
parseProgramWith :: Config -> Text -> Either ParseError (Program PName)
parseExpr :: Text -> Either ParseError (Expr PName)
parseExprWith :: Config -> Text -> Either ParseError (Expr PName)
parseDecl :: Text -> Either ParseError (Decl PName)
parseDeclWith :: Config -> Text -> Either ParseError (Decl PName)
parseDecls :: Text -> Either ParseError [Decl PName]
parseDeclsWith :: Config -> Text -> Either ParseError [Decl PName]
parseLetDecl :: Text -> Either ParseError (Decl PName)
parseLetDeclWith :: Config -> Text -> Either ParseError (Decl PName)
parseRepl :: Text -> Either ParseError (ReplInput PName)
parseReplWith :: Config -> Text -> Either ParseError (ReplInput PName)
parseSchema :: Text -> Either ParseError (Schema PName)
parseSchemaWith :: Config -> Text -> Either ParseError (Schema PName)
parseModName :: String -> Maybe ModName
parseHelpName :: String -> Maybe PName
data ParseError
HappyError :: FilePath -> Located Token -> ParseError
HappyErrorMsg :: Range -> [String] -> ParseError
HappyUnexpected :: FilePath -> Maybe (Located Token) -> String -> ParseError
HappyOutOfTokens :: FilePath -> Position -> ParseError
ppError :: ParseError -> Doc
data Layout
Layout :: Layout
NoLayout :: Layout
data Config
Config :: !FilePath -> !Position -> !Layout -> PreProc -> [FilePath] -> Bool -> Config

-- | File that we are working on
[cfgSource] :: Config -> !FilePath

-- | Starting position for the parser
[cfgStart] :: Config -> !Position

-- | Settings for layout processing
[cfgLayout] :: Config -> !Layout

-- | Preprocessor settings
[cfgPreProc] :: Config -> PreProc

-- | Implicit includes
[cfgAutoInclude] :: Config -> [FilePath]

-- | When we do layout processing should we add a vCurly (i.e., are we
--   parsing a list of things).
[cfgModuleScope] :: Config -> Bool
defaultConfig :: Config
guessPreProc :: FilePath -> PreProc
data PreProc
None :: PreProc
Markdown :: PreProc
LaTeX :: PreProc
RST :: PreProc


module Cryptol.Parser.NoInclude
removeIncludesModule :: (FilePath -> IO ByteString) -> FilePath -> Module PName -> IO (Either [IncludeError] (Module PName, Set FilePath))
data IncludeError
IncludeFailed :: Located FilePath -> IncludeError
IncludeDecodeFailed :: Located FilePath -> UnicodeException -> IncludeError
IncludeParseError :: ParseError -> IncludeError
IncludeCycle :: [Located FilePath] -> IncludeError
ppIncludeError :: IncludeError -> Doc
instance Control.DeepSeq.NFData Cryptol.Parser.NoInclude.IncludeError
instance GHC.Generics.Generic Cryptol.Parser.NoInclude.IncludeError
instance GHC.Show.Show Cryptol.Parser.NoInclude.IncludeError
instance GHC.Base.Functor Cryptol.Parser.NoInclude.NoIncM
instance GHC.Base.Applicative Cryptol.Parser.NoInclude.NoIncM
instance GHC.Base.Monad Cryptol.Parser.NoInclude.NoIncM
instance Control.Monad.Fail.MonadFail Cryptol.Parser.NoInclude.NoIncM


module Cryptol.ModuleSystem.Monad
data ImportSource
FromModule :: ModName -> ImportSource
FromImport :: Located Import -> ImportSource
FromSigImport :: Located ModName -> ImportSource
FromModuleInstance :: Located ModName -> ImportSource
importedModule :: ImportSource -> ModName
data ModuleError

-- | Unable to find the module given, tried looking in these paths
ModuleNotFound :: ModName -> [FilePath] -> ModuleError

-- | Unable to open a file
CantFindFile :: FilePath -> ModuleError

-- | Bad UTF-8 encoding in while decoding this file
BadUtf8 :: ModulePath -> UnicodeException -> ModuleError

-- | Some other IO error occurred while reading this file
OtherIOError :: FilePath -> IOException -> ModuleError

-- | Generated this parse error when parsing the file for module m
ModuleParseError :: ModulePath -> ParseError -> ModuleError

-- | Recursive module group discovered
RecursiveModules :: [ImportSource] -> ModuleError

-- | Problems during the renaming phase
RenamerErrors :: ImportSource -> [RenamerError] -> ModuleError

-- | Problems during the NoPat phase
NoPatErrors :: ImportSource -> [Error] -> ModuleError

-- | Problems during the ExpandPropGuards phase
ExpandPropGuardsError :: ImportSource -> Error -> ModuleError

-- | Problems during the NoInclude phase
NoIncludeErrors :: ImportSource -> [IncludeError] -> ModuleError

-- | Problems during type checking
TypeCheckingFailed :: ImportSource -> NameMap -> [(Range, Error)] -> ModuleError

-- | Problems after type checking, eg. specialization
OtherFailure :: String -> ModuleError

-- | Module loaded by 'import' statement has the wrong module name
ModuleNameMismatch :: ModName -> Located ModName -> ModuleError

-- | Two modules loaded from different files have the same module name
DuplicateModuleName :: ModName -> FilePath -> FilePath -> ModuleError

-- | Errors loading foreign function implementations
FFILoadErrors :: ModName -> [FFILoadError] -> ModuleError

-- | This is just a tag on the error, indicating the file containing it. It
--   is convenient when we had to look for the module, and we'd like to
--   communicate the location of pthe problematic module to the handler.
ErrorInFile :: ModulePath -> ModuleError -> ModuleError
moduleNotFound :: ModName -> [FilePath] -> ModuleM a
cantFindFile :: FilePath -> ModuleM a
badUtf8 :: ModulePath -> UnicodeException -> ModuleM a
otherIOError :: FilePath -> IOException -> ModuleM a
moduleParseError :: ModulePath -> ParseError -> ModuleM a
recursiveModules :: [ImportSource] -> ModuleM a
renamerErrors :: [RenamerError] -> ModuleM a
noPatErrors :: [Error] -> ModuleM a
expandPropGuardsError :: Error -> ModuleM a
noIncludeErrors :: [IncludeError] -> ModuleM a
typeCheckingFailed :: NameMap -> [(Range, Error)] -> ModuleM a
moduleNameMismatch :: ModName -> Located ModName -> ModuleM a
duplicateModuleName :: ModName -> FilePath -> FilePath -> ModuleM a
ffiLoadErrors :: ModName -> [FFILoadError] -> ModuleM a

-- | Run the computation, and if it caused and error, tag the error with
--   the given file.
errorInFile :: ModulePath -> ModuleM a -> ModuleM a
data ModuleWarning
TypeCheckWarnings :: NameMap -> [(Range, Warning)] -> ModuleWarning
RenamerWarnings :: [RenamerWarning] -> ModuleWarning
warn :: [ModuleWarning] -> ModuleM ()
typeCheckWarnings :: NameMap -> [(Range, Warning)] -> ModuleM ()
renamerWarnings :: [RenamerWarning] -> ModuleM ()
data RO m
RO :: [ImportSource] -> m EvalOpts -> Bool -> (FilePath -> m ByteString) -> Solver -> RO m
[roLoading] :: RO m -> [ImportSource]
[roEvalOpts] :: RO m -> m EvalOpts
[roCallStacks] :: RO m -> Bool
[roFileReader] :: RO m -> FilePath -> m ByteString
[roTCSolver] :: RO m -> Solver
emptyRO :: ModuleInput m -> RO m
newtype ModuleT m a
ModuleT :: ReaderT (RO m) (StateT ModuleEnv (ExceptionT ModuleError (WriterT [ModuleWarning] m))) a -> ModuleT m a
[unModuleT] :: ModuleT m a -> ReaderT (RO m) (StateT ModuleEnv (ExceptionT ModuleError (WriterT [ModuleWarning] m))) a
data ModuleInput m
ModuleInput :: Bool -> m EvalOpts -> (FilePath -> m ByteString) -> ModuleEnv -> Solver -> ModuleInput m
[minpCallStacks] :: ModuleInput m -> Bool
[minpEvalOpts] :: ModuleInput m -> m EvalOpts
[minpByteReader] :: ModuleInput m -> FilePath -> m ByteString
[minpModuleEnv] :: ModuleInput m -> ModuleEnv
[minpTCSolver] :: ModuleInput m -> Solver
runModuleT :: Monad m => ModuleInput m -> ModuleT m a -> m (Either ModuleError (a, ModuleEnv), [ModuleWarning])
type ModuleM = ModuleT IO
runModuleM :: ModuleInput IO -> ModuleM a -> IO (Either ModuleError (a, ModuleEnv), [ModuleWarning])
io :: BaseM m IO => IO a -> ModuleT m a
getByteReader :: Monad m => ModuleT m (FilePath -> m ByteString)
getCallStacks :: Monad m => ModuleT m Bool
readBytes :: Monad m => FilePath -> ModuleT m ByteString
getModuleEnv :: Monad m => ModuleT m ModuleEnv
getTCSolver :: Monad m => ModuleT m Solver
setModuleEnv :: Monad m => ModuleEnv -> ModuleT m ()
modifyModuleEnv :: Monad m => (ModuleEnv -> ModuleEnv) -> ModuleT m ()
getLoadedMaybe :: ModName -> ModuleM (Maybe (LoadedModuleG TCTopEntity))

-- | This checks if the given name is loaded---it might refer to either a
--   module or a signature.
isLoaded :: ModName -> ModuleM Bool
loadingImport :: Located Import -> ModuleM a -> ModuleM a
loadingModule :: ModName -> ModuleM a -> ModuleM a
loadingModInstance :: Located ModName -> ModuleM a -> ModuleM a

-- | Push an "interactive" context onto the loading stack. A bit of a hack,
--   as it uses a faked module name
interactive :: ModuleM a -> ModuleM a
loading :: ImportSource -> ModuleM a -> ModuleM a

-- | Get the currently focused import source.
getImportSource :: ModuleM ImportSource
getIfaces :: ModuleM (Map ModName (Either ModParamNames Iface))
getLoaded :: ModName -> ModuleM Module
getAllLoaded :: ModuleM (ModName -> Maybe (ModuleG (), IfaceG ()))
getAllLoadedSignatures :: ModuleM (ModName -> Maybe ModParamNames)
getNameSeeds :: ModuleM NameSeeds
getSupply :: ModuleM Supply
getMonoBinds :: ModuleM Bool
setMonoBinds :: Bool -> ModuleM ()
setNameSeeds :: NameSeeds -> ModuleM ()
setSupply :: Supply -> ModuleM ()
unloadModule :: (forall a. LoadedModuleG a -> Bool) -> ModuleM ()
loadedModule :: ModulePath -> FileInfo -> NamingEnv -> Maybe ForeignSrc -> TCTopEntity -> ModuleM ()
modifyEvalEnvM :: Traversable t => (EvalEnv -> Eval (t EvalEnv)) -> ModuleM (t ())
modifyEvalEnv :: (EvalEnv -> Eval EvalEnv) -> ModuleM ()
getEvalEnv :: ModuleM EvalEnv
getEvalOptsAction :: ModuleM (IO EvalOpts)
getEvalOpts :: ModuleM EvalOpts
getNewtypes :: ModuleM (Map Name Newtype)
getFocusedModule :: ModuleM (Maybe ModName)
setFocusedModule :: ModName -> ModuleM ()
getSearchPath :: ModuleM [FilePath]

-- | Run a <a>ModuleM</a> action in a context with a prepended search path.
--   Useful for temporarily looking in other places while resolving
--   imports, for example.
withPrependedSearchPath :: [FilePath] -> ModuleM a -> ModuleM a
getFocusedEnv :: ModuleM ModContext
getDynEnv :: ModuleM DynamicEnv
setDynEnv :: DynamicEnv -> ModuleM ()

-- | Usefule for logging. For example: <tt>withLogger logPutStrLn
--   <a>Hello</a></tt>
withLogger :: (Logger -> a -> IO b) -> a -> ModuleM b
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Monad.ImportSource
instance GHC.Generics.Generic Cryptol.ModuleSystem.Monad.ImportSource
instance GHC.Show.Show Cryptol.ModuleSystem.Monad.ImportSource
instance GHC.Show.Show Cryptol.ModuleSystem.Monad.ModuleError
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Monad.ModuleWarning
instance GHC.Generics.Generic Cryptol.ModuleSystem.Monad.ModuleWarning
instance GHC.Show.Show Cryptol.ModuleSystem.Monad.ModuleWarning
instance GHC.Base.Monad m => GHC.Base.Functor (Cryptol.ModuleSystem.Monad.ModuleT m)
instance GHC.Base.Monad m => GHC.Base.Applicative (Cryptol.ModuleSystem.Monad.ModuleT m)
instance GHC.Base.Monad m => GHC.Base.Monad (Cryptol.ModuleSystem.Monad.ModuleT m)
instance Control.Monad.Fail.MonadFail m => Control.Monad.Fail.MonadFail (Cryptol.ModuleSystem.Monad.ModuleT m)
instance MonadLib.MonadT Cryptol.ModuleSystem.Monad.ModuleT
instance GHC.Base.Monad m => Cryptol.ModuleSystem.Name.FreshM (Cryptol.ModuleSystem.Monad.ModuleT m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Cryptol.ModuleSystem.Monad.ModuleT m)
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Monad.ModuleWarning
instance Control.DeepSeq.NFData Cryptol.ModuleSystem.Monad.ModuleError
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Monad.ModuleError
instance GHC.Classes.Eq Cryptol.ModuleSystem.Monad.ImportSource
instance Cryptol.Utils.PP.PP Cryptol.ModuleSystem.Monad.ImportSource


-- | This is the main driver---it provides entry points for the various
--   passes.
module Cryptol.ModuleSystem.Base
rename :: ModName -> NamingEnv -> RenameM a -> ModuleM a

-- | Rename a module in the context of its imported modules.
renameModule :: Module PName -> ModuleM RenamedModule

-- | Run the noPat pass.
noPat :: RemovePatterns a => a -> ModuleM a

-- | Run the expandPropGuards pass.
expandPropGuards :: Module PName -> ModuleM (Module PName)

-- | Parse a module and expand includes Returns a fingerprint of the
--   module, and a set of dependencies due to <tt>include</tt> directives.
parseModule :: ModulePath -> ModuleM (Fingerprint, Set FilePath, [Module PName])

-- | Load a module by its path.
loadModuleByPath :: Bool -> FilePath -> ModuleM TCTopEntity

-- | Load a module, unless it was previously loaded.
loadModuleFrom :: Bool -> ImportSource -> ModuleM (ModulePath, TCTopEntity)

-- | Load dependencies, typecheck, and add to the eval environment.
doLoadModule :: Bool -> Bool -> ImportSource -> ModulePath -> Fingerprint -> Set FilePath -> Module PName -> ModuleM TCTopEntity

-- | Rewrite an import declaration to be of the form:
--   
--   <pre>
--   import foo as foo [ [hiding] (a,b,c) ]
--   </pre>
fullyQualified :: Import -> Import
moduleFile :: ModName -> String -> FilePath

-- | Discover a module.
findModule :: ModName -> ModuleM ModulePath

-- | Discover a file. This is distinct from <a>findModule</a> in that we
--   assume we've already been given a particular file name.
findFile :: FilePath -> ModuleM FilePath

-- | Add the prelude to the import list if it's not already mentioned.
addPrelude :: Module PName -> Module PName

-- | Load the dependencies of a module into the environment.
loadDeps :: ModuleG mname name -> ModuleM (Set ModName)

-- | Find all imports in a module.
findDeps :: ModuleG mname name -> [ImportSource]
findDepsOfModule :: ModName -> ModuleM (ModulePath, FileInfo)
findDepsOf :: ModulePath -> ModuleM (ModulePath, FileInfo)

-- | Find the set of top-level modules imported by a module.
findModuleDeps :: ModuleG mname name -> Set ModName

-- | A helper <a>findDeps</a> and <a>findModuleDeps</a> that actually does
--   the searching.
findDeps' :: ModuleG mname name -> (Any, Endo [ImportSource])

-- | Typecheck a single expression, yielding a renamed parsed expression,
--   typechecked core expression, and a type schema.
checkExpr :: Expr PName -> ModuleM (Expr Name, Expr, Schema)

-- | Typecheck a group of declarations.
--   
--   INVARIANT: This assumes that NoPat has already been run on the
--   declarations.
checkDecls :: [TopDecl PName] -> ModuleM (NamingEnv, [DeclGroup], Map Name TySyn)

-- | Generate the primitive map. If the prelude is currently being loaded,
--   this should be generated directly from the naming environment given to
--   the renamer instead.
getPrimMap :: ModuleM PrimMap

-- | Typecheck a single module. Note: we assume that <tt>include</tt>s have
--   already been processed
checkModule :: ImportSource -> Module PName -> ModuleM (NamingEnv, TCTopEntity)
data TCLinter o
TCLinter :: (o -> InferInput -> Either (Range, Error) [ProofObligation]) -> Maybe ModName -> TCLinter o
[lintCheck] :: TCLinter o -> o -> InferInput -> Either (Range, Error) [ProofObligation]
[lintModule] :: TCLinter o -> Maybe ModName
exprLinter :: TCLinter (Expr, Schema)
declsLinter :: TCLinter ([DeclGroup], a)
moduleLinter :: ModName -> TCLinter Module
tcTopEntitytLinter :: ModName -> TCLinter TCTopEntity
type Act i o = i -> InferInput -> IO (InferOutput o)
data TCAction i o
TCAction :: Act i o -> TCLinter o -> PrimMap -> TCAction i o
[tcAction] :: TCAction i o -> Act i o
[tcLinter] :: TCAction i o -> TCLinter o
[tcPrims] :: TCAction i o -> PrimMap
typecheck :: (Show i, Show o, HasLoc i) => TCAction i o -> i -> ModContextParams -> IfaceDecls -> ModuleM o

-- | Generate input for the typechecker.
genInferInput :: Range -> PrimMap -> ModContextParams -> IfaceDecls -> ModuleM InferInput
evalExpr :: Expr -> ModuleM Value
benchmarkExpr :: Double -> Expr -> ModuleM BenchmarkStats
evalDecls :: [DeclGroup] -> ModuleM ()


module Cryptol.ModuleSystem

-- | This is the current state of the interpreter.
data ModuleEnv
ModuleEnv :: LoadedModules -> NameSeeds -> EvalEnv -> CoreLint -> !Bool -> Maybe ModName -> [FilePath] -> DynamicEnv -> !Supply -> ModuleEnv

-- | Information about all loaded modules. See <a>LoadedModuleG</a>.
--   Contains information such as the file where the module was loaded
--   from, as well as the module's interface, used for type checking.
[meLoadedModules] :: ModuleEnv -> LoadedModules

-- | A source of new names for the type checker.
[meNameSeeds] :: ModuleEnv -> NameSeeds

-- | The evaluation environment. Contains the values for all loaded
--   modules, both public and private.
[meEvalEnv] :: ModuleEnv -> EvalEnv

-- | Should we run the linter to ensure sanity.
[meCoreLint] :: ModuleEnv -> CoreLint

-- | Are we assuming that local bindings are monomorphic. XXX: We should
--   probably remove this flag, and set it to <a>True</a>.
[meMonoBinds] :: ModuleEnv -> !Bool

-- | The "current" module. Used to decide how to print names, for example.
[meFocusedModule] :: ModuleEnv -> Maybe ModName

-- | Where we look for things.
[meSearchPath] :: ModuleEnv -> [FilePath]

-- | This contains additional definitions that were made at the command
--   line, and so they don't reside in any module.
[meDynEnv] :: ModuleEnv -> DynamicEnv

-- | Name source for the renamer
[meSupply] :: ModuleEnv -> !Supply
initialModuleEnv :: IO ModuleEnv

-- | Extra information we need to carry around to dynamically extend an
--   environment outside the context of a single module. Particularly
--   useful when dealing with interactive declarations as in <tt>let</tt>
--   or <tt>it</tt>.
data DynamicEnv
DEnv :: NamingEnv -> [DeclGroup] -> Map Name TySyn -> EvalEnv -> DynamicEnv
[deNames] :: DynamicEnv -> NamingEnv
[deDecls] :: DynamicEnv -> [DeclGroup]
[deTySyns] :: DynamicEnv -> Map Name TySyn
[deEnv] :: DynamicEnv -> EvalEnv
data ModuleError

-- | Unable to find the module given, tried looking in these paths
ModuleNotFound :: ModName -> [FilePath] -> ModuleError

-- | Unable to open a file
CantFindFile :: FilePath -> ModuleError

-- | Bad UTF-8 encoding in while decoding this file
BadUtf8 :: ModulePath -> UnicodeException -> ModuleError

-- | Some other IO error occurred while reading this file
OtherIOError :: FilePath -> IOException -> ModuleError

-- | Generated this parse error when parsing the file for module m
ModuleParseError :: ModulePath -> ParseError -> ModuleError

-- | Recursive module group discovered
RecursiveModules :: [ImportSource] -> ModuleError

-- | Problems during the renaming phase
RenamerErrors :: ImportSource -> [RenamerError] -> ModuleError

-- | Problems during the NoPat phase
NoPatErrors :: ImportSource -> [Error] -> ModuleError

-- | Problems during the ExpandPropGuards phase
ExpandPropGuardsError :: ImportSource -> Error -> ModuleError

-- | Problems during the NoInclude phase
NoIncludeErrors :: ImportSource -> [IncludeError] -> ModuleError

-- | Problems during type checking
TypeCheckingFailed :: ImportSource -> NameMap -> [(Range, Error)] -> ModuleError

-- | Problems after type checking, eg. specialization
OtherFailure :: String -> ModuleError

-- | Module loaded by 'import' statement has the wrong module name
ModuleNameMismatch :: ModName -> Located ModName -> ModuleError

-- | Two modules loaded from different files have the same module name
DuplicateModuleName :: ModName -> FilePath -> FilePath -> ModuleError

-- | Errors loading foreign function implementations
FFILoadErrors :: ModName -> [FFILoadError] -> ModuleError

-- | This is just a tag on the error, indicating the file containing it. It
--   is convenient when we had to look for the module, and we'd like to
--   communicate the location of pthe problematic module to the handler.
ErrorInFile :: ModulePath -> ModuleError -> ModuleError
data ModuleWarning
TypeCheckWarnings :: NameMap -> [(Range, Warning)] -> ModuleWarning
RenamerWarnings :: [RenamerWarning] -> ModuleWarning
type ModuleCmd a = ModuleInput IO -> IO (ModuleRes a)
type ModuleRes a = (Either ModuleError (a, ModuleEnv), [ModuleWarning])
data ModuleInput m
ModuleInput :: Bool -> m EvalOpts -> (FilePath -> m ByteString) -> ModuleEnv -> Solver -> ModuleInput m
[minpCallStacks] :: ModuleInput m -> Bool
[minpEvalOpts] :: ModuleInput m -> m EvalOpts
[minpByteReader] :: ModuleInput m -> FilePath -> m ByteString
[minpModuleEnv] :: ModuleInput m -> ModuleEnv
[minpTCSolver] :: ModuleInput m -> Solver

-- | Find the file associated with a module name in the module search path.
findModule :: ModName -> ModuleCmd ModulePath

-- | Load the module contained in the given file.
loadModuleByPath :: FilePath -> ModuleCmd (ModulePath, TCTopEntity)

-- | Load the given parsed module.
loadModuleByName :: ModName -> ModuleCmd (ModulePath, TCTopEntity)

-- | Parse and typecheck a module, but don't evaluate or change the
--   environment.
checkModuleByPath :: FilePath -> ModuleCmd (ModulePath, TCTopEntity)

-- | Check the type of an expression. Give back the renamed expression, the
--   core expression, and its type schema.
checkExpr :: Expr PName -> ModuleCmd (Expr Name, Expr, Schema)

-- | Evaluate an expression.
evalExpr :: Expr -> ModuleCmd Value

-- | Benchmark an expression.
benchmarkExpr :: Double -> Expr -> ModuleCmd BenchmarkStats

-- | Typecheck top-level declarations.
checkDecls :: [TopDecl PName] -> ModuleCmd (NamingEnv, [DeclGroup], Map Name TySyn)

-- | Evaluate declarations and add them to the extended environment.
evalDecls :: [DeclGroup] -> ModuleCmd ()
noPat :: RemovePatterns a => a -> ModuleCmd a

-- | Given the state of the environment, compute information about what's
--   in scope on the REPL. This includes what's in the focused module, plus
--   any additional definitions from the REPL (e.g., let bound names, and
--   <tt>it</tt>).
focusedEnv :: ModuleEnv -> ModContext
getPrimMap :: ModuleCmd PrimMap

-- | Rename a *use* of a value name. The distinction between uses and
--   binding is used to keep track of dependencies.
renameVar :: NamingEnv -> PName -> ModuleCmd Name

-- | Rename a *use* of a type name. The distinction between uses and
--   binding is used to keep track of dependencies.
renameType :: NamingEnv -> PName -> ModuleCmd Name
type Iface = IfaceG ModName

-- | The interface repersenting a typecheck top-level module.
data IfaceG name
Iface :: IfaceNames name -> FunctorParams -> IfaceDecls -> IfaceG name

-- | Info about names in this module
[ifNames] :: IfaceG name -> IfaceNames name

-- | Module parameters, if any
[ifParams] :: IfaceG name -> FunctorParams

-- | All things defines in the module (includes nested definitions)
[ifDefines] :: IfaceG name -> IfaceDecls

-- | Declarations in a module. Note that this includes things from nested
--   modules, but not things from nested functors, which are in
--   <a>ifFunctors</a>.
data IfaceDecls
IfaceDecls :: Map Name TySyn -> Map Name Newtype -> Map Name AbstractType -> Map Name IfaceDecl -> !Map Name (IfaceNames Name) -> !Map Name ModParamNames -> !Map Name (IfaceG Name) -> IfaceDecls
[ifTySyns] :: IfaceDecls -> Map Name TySyn
[ifNewtypes] :: IfaceDecls -> Map Name Newtype
[ifAbstractTypes] :: IfaceDecls -> Map Name AbstractType
[ifDecls] :: IfaceDecls -> Map Name IfaceDecl
[ifModules] :: IfaceDecls -> !Map Name (IfaceNames Name)
[ifSignatures] :: IfaceDecls -> !Map Name ModParamNames

-- | XXX: Maybe arg info? Also, with the current implementation we aim to
--   complete remove functors by essentially inlining them. To achieve this
--   with just interfaces we'd have to store here the entire module, not
--   just its interface. At the moment we work around this by passing all
--   loaded modules to the type checker, so it looks up functors there,
--   instead of in the interfaces, but we'd need to change this if we want
--   better support for separate compilation.
[ifFunctors] :: IfaceDecls -> !Map Name (IfaceG Name)
genIface :: ModuleG name -> IfaceG name
data IfaceDecl
IfaceDecl :: !Name -> Schema -> !Bool -> [Pragma] -> Bool -> Maybe Fixity -> Maybe Text -> IfaceDecl

-- | Name of thing
[ifDeclName] :: IfaceDecl -> !Name

-- | Type
[ifDeclSig] :: IfaceDecl -> Schema
[ifDeclIsPrim] :: IfaceDecl -> !Bool

-- | Pragmas
[ifDeclPragmas] :: IfaceDecl -> [Pragma]

-- | Is this an infix thing
[ifDeclInfix] :: IfaceDecl -> Bool

-- | Fixity information
[ifDeclFixity] :: IfaceDecl -> Maybe Fixity

-- | Documentation
[ifDeclDoc] :: IfaceDecl -> Maybe Text

-- | Get information about the dependencies of a file.
getFileDependencies :: FilePath -> ModuleCmd (ModulePath, FileInfo)

-- | Get information about the dependencies of a module.
getModuleDependencies :: ModName -> ModuleCmd (ModulePath, FileInfo)


module Cryptol.Transform.Specialize

-- | A <a>Name</a> should have an entry in the <a>SpecCache</a> iff it is
--   specializable. Each <a>Name</a> starts out with an empty
--   <a>TypesMap</a>.
type SpecCache = Map Name (Decl, TypesMap (Name, Maybe Decl))

-- | The specializer monad.
type SpecT m a = StateT SpecCache (ModuleT m) a
type SpecM a = SpecT IO a
runSpecT :: SpecCache -> SpecT m a -> ModuleT m (a, SpecCache)
liftSpecT :: Monad m => ModuleT m a -> SpecT m a
getSpecCache :: Monad m => SpecT m SpecCache
setSpecCache :: Monad m => SpecCache -> SpecT m ()
modifySpecCache :: Monad m => (SpecCache -> SpecCache) -> SpecT m ()
modify :: StateM m s => (s -> s) -> m ()

-- | Add a <tt>where</tt> clause to the given expression containing
--   type-specialized versions of all functions called (transitively) by
--   the body of the expression.
specialize :: Expr -> ModuleCmd Expr
specializeExpr :: Expr -> SpecM Expr
specializeMatch :: Match -> SpecM Match

-- | Add the declarations to the SpecCache, run the given monadic action,
--   and then pull the specialized declarations back out of the SpecCache
--   state. Return the result along with the declarations and a table of
--   names of specialized bindings.
withDeclGroups :: [DeclGroup] -> SpecM a -> SpecM (a, [DeclGroup], Map Name (TypesMap Name))

-- | Compute the specialization of <tt><a>EWhere</a> e dgs</tt>. A decl
--   within <tt>dgs</tt> is replicated once for each monomorphic type
--   instance at which it is used; decls not mentioned in <tt>e</tt> (even
--   monomorphic ones) are simply dropped.
specializeEWhere :: Expr -> [DeclGroup] -> SpecM Expr

-- | Transform the given declaration groups into a set of monomorphic
--   declarations. All of the original declarations with monomorphic types
--   are kept; additionally the result set includes instantiated versions
--   of polymorphic decls that are referenced by the monomorphic bindings.
--   We also return a map relating generated names to the names from the
--   original declarations.
specializeDeclGroups :: [DeclGroup] -> SpecM ([DeclGroup], Map Name (TypesMap Name))
specializeConst :: Expr -> SpecM Expr
destEProofApps :: Expr -> (Expr, Int)
destETApps :: Expr -> (Expr, [Type])
destEProofAbs :: Expr -> ([Prop], Expr)
destETAbs :: Expr -> ([TParam], Expr)

-- | Freshen a name by giving it a new unique.
freshName :: Name -> [Type] -> SpecM Name
instantiateSchema :: [Type] -> Int -> Schema -> SpecM Schema

-- | Reduce <tt>length ts</tt> outermost type abstractions and <tt>n</tt>
--   proof abstractions.
instantiateExpr :: [Type] -> Int -> Expr -> SpecM Expr
allDeclGroups :: ModuleEnv -> [DeclGroup]
traverseSnd :: Functor f => (b -> f c) -> (a, b) -> f (a, c)


module Cryptol.Symbolic.What4
data W4ProverConfig
defaultProver :: W4ProverConfig
proverNames :: [String]
setupProver :: String -> IO (Either String ([String], W4ProverConfig))
satProve :: W4ProverConfig -> Bool -> Bool -> ProverCommand -> ModuleCmd (Maybe String, ProverResult)
satProveOffline :: Bool -> Bool -> ProverCommand -> ((Handle -> IO ()) -> IO ()) -> ModuleCmd (Maybe String)
data W4Exception
W4Ex :: SomeException -> W4Exception
W4PortfolioFailure :: [Either SomeException (Maybe String, String)] -> W4Exception
instance GHC.Base.Functor Cryptol.Symbolic.What4.MultiSat
instance GHC.Base.Applicative Cryptol.Symbolic.What4.MultiSat
instance GHC.Base.Monad Cryptol.Symbolic.What4.MultiSat
instance Control.Monad.IO.Class.MonadIO Cryptol.Symbolic.What4.MultiSat
instance GHC.Show.Show Cryptol.Symbolic.What4.W4Exception
instance GHC.Exception.Type.Exception Cryptol.Symbolic.What4.W4Exception


module Cryptol.Symbolic.SBV
data SBVProverConfig
defaultProver :: SBVProverConfig

-- | The names of all the solvers supported by SBV
proverNames :: [String]
setupProver :: String -> IO (Either String ([String], SBVProverConfig))

-- | Execute a symbolic ':prove' or ':sat' command.
--   
--   This command returns a pair: the first element is the name of the
--   solver that completes the given query (if any) along with the result
--   of executing the query.
satProve :: SBVProverConfig -> ProverCommand -> ModuleCmd (Maybe String, ProverResult)

-- | Execute a symbolic ':prove' or ':sat' command when the prover is set
--   to offline. This only prepares the SMT input file for the solver and
--   does not actually invoke the solver.
--   
--   This method returns either an error message or the text of the SMT
--   input file corresponding to the given prover command.
satProveOffline :: SBVProverConfig -> ProverCommand -> ModuleCmd (Either String String)
newtype SBVPortfolioException
SBVPortfolioException :: [Either SomeException (Maybe String, String)] -> SBVPortfolioException
instance GHC.Show.Show Cryptol.Symbolic.SBV.SBVPortfolioException
instance GHC.Exception.Type.Exception Cryptol.Symbolic.SBV.SBVPortfolioException


module Cryptol.REPL.Monad

-- | REPL_ context with InputT handling.
newtype REPL a
REPL :: (IORef RW -> IO a) -> REPL a
[unREPL] :: REPL a -> IORef RW -> IO a

-- | Run a REPL action with a fresh environment.
runREPL :: Bool -> Bool -> Logger -> REPL a -> IO a
io :: IO a -> REPL a

-- | Raise an exception.
raise :: REPLException -> REPL a
stop :: REPL ()
catch :: REPL a -> (REPLException -> REPL a) -> REPL a
finally :: REPL a -> REPL b -> REPL a

-- | Use the configured output action to print a string with a trailing
--   newline
rPutStrLn :: String -> REPL ()

-- | Use the configured output action to print a string
rPutStr :: String -> REPL ()

-- | Use the configured output action to print something using its Show
--   instance
rPrint :: Show a => a -> REPL ()

-- | REPL exceptions.
data REPLException
ParseError :: ParseError -> REPLException
FileNotFound :: FilePath -> REPLException
DirectoryNotFound :: FilePath -> REPLException
NoPatError :: [Error] -> REPLException
NoIncludeError :: [IncludeError] -> REPLException
EvalError :: EvalErrorEx -> REPLException
TooWide :: WordTooWide -> REPLException
Unsupported :: Unsupported -> REPLException
ModuleSystemError :: NameDisp -> ModuleError -> REPLException
EvalPolyError :: Schema -> REPLException
InstantiationsNotFound :: Schema -> REPLException
TypeNotTestable :: Type -> REPLException
EvalInParamModule :: [TParam] -> [Name] -> REPLException
SBVError :: String -> REPLException
SBVException :: SBVException -> REPLException
SBVPortfolioException :: SBVPortfolioException -> REPLException
W4Exception :: W4Exception -> REPLException
rethrowEvalError :: IO a -> IO a
getFocusedEnv :: REPL ModContext
getModuleEnv :: REPL ModuleEnv
setModuleEnv :: ModuleEnv -> REPL ()
getDynEnv :: REPL DynamicEnv
setDynEnv :: DynamicEnv -> REPL ()
getCallStacks :: REPL Bool
getTCSolver :: REPL Solver
resetTCSolver :: REPL ()

-- | Given an existing qualified name, prefix it with a relatively-unique
--   string. We make it unique by prefixing with a character <tt>#</tt>
--   that is not lexically valid in a module name.
uniqify :: Name -> REPL Name

-- | Generate a fresh name using the given index. The name will reside
--   within the "<a>interactive</a>" namespace.
freshName :: Ident -> NameSource -> REPL Name
whenDebug :: REPL () -> REPL ()
getEvalOptsAction :: REPL (IO EvalOpts)
getPPValOpts :: REPL PPOpts

-- | Get visible variable names. This is used for command line
--   completition.
getExprNames :: REPL [String]

-- | Get visible type signature names. This is used for command line
--   completition.
getTypeNames :: REPL [String]

-- | Return a list of property names, sorted by position in the file.
getPropertyNames :: REPL ([(Name, IfaceDecl)], NameDisp)
getModNames :: REPL [ModName]

-- | This indicates what the user would like to work on.
data LoadedModule
LoadedModule :: Maybe ModName -> ModulePath -> LoadedModule

-- | Working on this module.
[lName] :: LoadedModule -> Maybe ModName

-- | Working on this file.
[lPath] :: LoadedModule -> ModulePath
getLoadedMod :: REPL (Maybe LoadedModule)

-- | Set the name of the currently focused file, loaded via <tt>:r</tt>.
setLoadedMod :: LoadedModule -> REPL ()
clearLoadedMod :: REPL ()

-- | Set the path for the ':e' command. Note that this does not change the
--   focused module (i.e., what ":r" reloads)
setEditPath :: FilePath -> REPL ()
getEditPath :: REPL (Maybe FilePath)
clearEditPath :: REPL ()
setSearchPath :: [FilePath] -> REPL ()
prependSearchPath :: [FilePath] -> REPL ()

-- | Construct the prompt for the current environment.
getPrompt :: REPL String
shouldContinue :: REPL Bool
unlessBatch :: REPL () -> REPL ()

-- | Run a computation in batch mode, restoring the previous isBatch flag
--   afterwards
asBatch :: REPL a -> REPL a

-- | Is evaluation enabled. If the currently focused module is
--   parameterized, then we cannot evalute.
validEvalContext :: FreeVars a => a -> REPL ()

-- | Update the title
updateREPLTitle :: REPL ()

-- | Set the function that will be called when updating the title
setUpdateREPLTitle :: REPL () -> REPL ()
withRandomGen :: (TFGen -> REPL (a, TFGen)) -> REPL a
setRandomGen :: TFGen -> REPL ()
getRandomGen :: REPL TFGen
data EnvVal
EnvString :: String -> EnvVal
EnvProg :: String -> [String] -> EnvVal
EnvNum :: !Int -> EnvVal
EnvBool :: Bool -> EnvVal
data OptionDescr
OptionDescr :: String -> [String] -> EnvVal -> Checker -> String -> (EnvVal -> REPL ()) -> OptionDescr
[optName] :: OptionDescr -> String
[optAliases] :: OptionDescr -> [String]
[optDefault] :: OptionDescr -> EnvVal
[optCheck] :: OptionDescr -> Checker
[optHelp] :: OptionDescr -> String
[optEff] :: OptionDescr -> EnvVal -> REPL ()

-- | Set a user option.
setUser :: String -> String -> REPL ()

-- | Get a user option, when it's known to exist. Fail with panic when it
--   doesn't.
getUser :: String -> REPL EnvVal
getKnownUser :: IsEnvVal a => String -> REPL a

-- | Get a user option, using Maybe for failure.
tryGetUser :: String -> REPL (Maybe EnvVal)
userOptions :: OptionMap
userOptionsWithAliases :: OptionMap
getUserSatNum :: REPL SatNum
getUserShowProverStats :: REPL Bool
getUserProverValidate :: REPL Bool
parsePPFloatFormat :: String -> Maybe PPFloatFormat
parseFieldOrder :: String -> Maybe FieldOrder
getProverConfig :: REPL (Either SBVProverConfig W4ProverConfig)
parseSearchPath :: String -> [String]

-- | Get the REPL's string-printer
getPutStr :: REPL (String -> IO ())
getLogger :: REPL Logger

-- | Set the REPL's string-printer
setPutStr :: (String -> IO ()) -> REPL ()
smokeTest :: REPL [Smoke]
data Smoke
Z3NotFound :: Smoke
instance GHC.Show.Show Cryptol.REPL.Monad.REPLException
instance GHC.Show.Show Cryptol.REPL.Monad.EnvVal
instance GHC.Classes.Eq Cryptol.REPL.Monad.Smoke
instance GHC.Show.Show Cryptol.REPL.Monad.Smoke
instance Cryptol.Utils.PP.PP Cryptol.REPL.Monad.Smoke
instance Cryptol.REPL.Monad.IsEnvVal GHC.Types.Bool
instance Cryptol.REPL.Monad.IsEnvVal GHC.Types.Int
instance Cryptol.REPL.Monad.IsEnvVal (GHC.Base.String, [GHC.Base.String])
instance Cryptol.REPL.Monad.IsEnvVal GHC.Base.String
instance Cryptol.REPL.Monad.IsEnvVal Cryptol.Utils.PP.FieldOrder
instance GHC.Base.Functor Cryptol.REPL.Monad.REPL
instance GHC.Base.Applicative Cryptol.REPL.Monad.REPL
instance GHC.Base.Monad Cryptol.REPL.Monad.REPL
instance Control.Monad.IO.Class.MonadIO Cryptol.REPL.Monad.REPL
instance Control.Monad.Base.MonadBase GHC.Types.IO Cryptol.REPL.Monad.REPL
instance Control.Monad.Trans.Control.MonadBaseControl GHC.Types.IO Cryptol.REPL.Monad.REPL
instance Cryptol.ModuleSystem.Name.FreshM Cryptol.REPL.Monad.REPL
instance Control.Monad.Catch.MonadThrow Cryptol.REPL.Monad.REPL
instance Control.Monad.Catch.MonadCatch Cryptol.REPL.Monad.REPL
instance Control.Monad.Catch.MonadMask Cryptol.REPL.Monad.REPL
instance GHC.Exception.Type.Exception Cryptol.REPL.Monad.REPLException
instance Cryptol.Utils.PP.PP Cryptol.REPL.Monad.REPLException

module Cryptol.REPL.Help
helpForNamed :: PName -> REPL ()


module Cryptol.Eval.Reference

-- | Value type for the reference evaluator.
data Value

-- | <tt> Bit </tt> booleans
VBit :: !Bool -> Value

-- | <tt> Integer </tt> or <tt>Z n</tt> integers
VInteger :: !Integer -> Value

-- | <tt> Rational </tt> rationals
VRational :: !Rational -> Value

-- | Floating point numbers
VFloat :: !BF -> Value

-- | <tt> [n]a </tt> finite or infinite lists
VList :: Nat' -> [E Value] -> Value

-- | <tt> ( .. ) </tt> tuples
VTuple :: [E Value] -> Value

-- | <tt> { .. } </tt> records
VRecord :: [(Ident, E Value)] -> Value

-- | functions
VFun :: (E Value -> E Value) -> Value

-- | polymorphic values (kind *)
VPoly :: (TValue -> E Value) -> Value

-- | polymorphic values (kind #)
VNumPoly :: (Nat' -> E Value) -> Value

-- | Computation monad for the reference evaluator.
data E a
Value :: !a -> E a
Err :: EvalError -> E a
evaluate :: Expr -> ModuleCmd (E Value)
evalExpr :: Env -> Expr -> E Value
evalDeclGroup :: Env -> DeclGroup -> Env
ppValue :: PPOpts -> Value -> Doc
ppEValue :: PPOpts -> E Value -> Doc
instance GHC.Base.Semigroup Cryptol.Eval.Reference.Env
instance GHC.Base.Monoid Cryptol.Eval.Reference.Env
instance GHC.Base.Functor Cryptol.Eval.Reference.E
instance GHC.Base.Applicative Cryptol.Eval.Reference.E
instance GHC.Base.Monad Cryptol.Eval.Reference.E


module Cryptol.REPL.Command

-- | Commands.
data Command

-- | Successfully parsed command
Command :: (Int -> Maybe FilePath -> REPL ()) -> Command

-- | Ambiguous command, list of conflicting commands
Ambiguous :: String -> [String] -> Command

-- | The unknown command
Unknown :: String -> Command

-- | Command builder.
data CommandDescr
CommandDescr :: [String] -> [String] -> CommandBody -> String -> String -> CommandDescr
[cNames] :: CommandDescr -> [String]
[cArgs] :: CommandDescr -> [String]
[cBody] :: CommandDescr -> CommandBody
[cHelp] :: CommandDescr -> String
[cLongHelp] :: CommandDescr -> String
data CommandBody
ExprArg :: (String -> (Int, Int) -> Maybe FilePath -> REPL ()) -> CommandBody
FileExprArg :: (FilePath -> String -> (Int, Int) -> Maybe FilePath -> REPL ()) -> CommandBody
DeclsArg :: (String -> REPL ()) -> CommandBody
ExprTypeArg :: (String -> REPL ()) -> CommandBody
ModNameArg :: (String -> REPL ()) -> CommandBody
FilenameArg :: (FilePath -> REPL ()) -> CommandBody
OptionArg :: (String -> REPL ()) -> CommandBody
ShellArg :: (String -> REPL ()) -> CommandBody
HelpArg :: (String -> REPL ()) -> CommandBody
NoArg :: REPL () -> CommandBody
data CommandExitCode
CommandOk :: CommandExitCode
CommandError :: CommandExitCode

-- | Parse a line as a command.
parseCommand :: (String -> [CommandDescr]) -> String -> Maybe Command

-- | Run a command.
runCommand :: Int -> Maybe FilePath -> Command -> REPL CommandExitCode

-- | Split at the first word boundary.
splitCommand :: String -> Maybe (Int, String, String)

-- | Lookup a string in the command list.
findCommand :: String -> [CommandDescr]

-- | Lookup a string in the command list, returning an exact match even if
--   it's the prefix of another command.
findCommandExact :: String -> [CommandDescr]

-- | Lookup a string in the notebook-safe command list.
findNbCommand :: Bool -> String -> [CommandDescr]
commandList :: [CommandDescr]
moduleCmd :: String -> REPL ()
loadCmd :: FilePath -> REPL ()
loadPrelude :: REPL ()
setOptionCmd :: String -> REPL ()
interactiveConfig :: Config
replParseExpr :: String -> (Int, Int) -> Maybe FilePath -> REPL (Expr PName)
replEvalExpr :: Expr PName -> REPL (Value, Type)
replCheckExpr :: Expr PName -> REPL (Expr Name, Expr, Schema)
data TestReport
TestReport :: Doc -> TestResult -> Integer -> Maybe Integer -> TestReport
[reportExpr] :: TestReport -> Doc
[reportResult] :: TestReport -> TestResult
[reportTestsRun] :: TestReport -> Integer
[reportTestsPossible] :: TestReport -> Maybe Integer
qcExpr :: QCMode -> Doc -> Expr -> Schema -> REPL TestReport

-- | Randomly test a property, or exhaustively check it if the number of
--   values in the type under test is smaller than the <tt>tests</tt>
--   environment variable, or we specify exhaustive testing.
qcCmd :: QCMode -> String -> (Int, Int) -> Maybe FilePath -> REPL ()
data QCMode
QCRandom :: QCMode
QCExhaust :: QCMode
satCmd :: String -> (Int, Int) -> Maybe FilePath -> REPL ()
proveCmd :: String -> (Int, Int) -> Maybe FilePath -> REPL ()
onlineProveSat :: String -> QueryType -> Expr -> Schema -> Maybe FilePath -> REPL (Maybe String, ProverResult, ProverStats)
offlineProveSat :: String -> QueryType -> Expr -> Schema -> Maybe FilePath -> REPL ()
handleCtrlC :: a -> REPL a

-- | Strip leading space.
sanitize :: String -> String
withRWTempFile :: String -> (Handle -> IO a) -> IO a

-- | Lift a parsing action into the REPL monad.
replParse :: (String -> Either ParseError a) -> String -> REPL a
liftModuleCmd :: ModuleCmd a -> REPL a
moduleCmdResult :: ModuleRes a -> REPL a
instance GHC.Show.Show Cryptol.REPL.Command.QCMode
instance GHC.Classes.Eq Cryptol.REPL.Command.QCMode
instance GHC.Show.Show Cryptol.REPL.Command.CommandDescr
instance GHC.Classes.Eq Cryptol.REPL.Command.CommandDescr
instance GHC.Classes.Ord Cryptol.REPL.Command.CommandDescr
