cryptol-3.0.0: Cryptol: The Language of Cryptography

Copyright | (c) 2013-2016 Galois Inc.
License | BSD3
Maintainer | cryptol@galois.com
Stability | provisional
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Cryptol.ModuleSystem.Renamer.Monad

Description

Synopsis

- data NameType
  - = NameBind
  - | NameUse
- data RenamerInfo = RenamerInfo {
  - renSupply :: Supply
  - renContext :: ModPath
  - renEnv :: NamingEnv
  - renIfaces :: Map ModName (Either ModParamNames Iface)
  }
- newtype RenameM a = RenameM {
  - unRenameM :: ReaderT RO (StateT RW Lift) a
  }
- data RO = RO {
  - roLoc :: Range
  - roNames :: NamingEnv
  - roExternal :: Map ModName (Maybe Iface, Map (ImpName Name) (Mod ()))
  - roCurMod :: ModPath
  - roNestedMods :: Map ModPath Name
  - roResolvedModules :: Map (ImpName Name) ResolvedLocal
  - roModParams :: Map Ident RenModParam
  - roFromModParam :: Map Name DepName
  }
- data RW = RW {
  - rwWarnings :: ![RenamerWarning]
  - rwErrors :: !(Set RenamerError)
  - rwSupply :: !Supply
  - rwNameUseCount :: !(Map Name Int)
  - rwCurrentDeps :: Set Name
  - rwDepGraph :: Map DepName (Set Name)
  - rwExternalDeps :: !IfaceDecls
  }
- data RenModParam = RenModParam {
  - renModParamName :: Ident
  - renModParamRange :: Range
  - renModParamSig :: ImpName Name
  - renModParamInstance :: 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)
- recordError :: RenamerError -> RenameM ()
- recordWarning :: RenamerWarning -> RenameM ()
- collectIfaceDeps :: RenameM a -> RenameM (IfaceDecls, a)
- depsOf :: DepName -> RenameM a -> RenameM a
- depGroup :: RenameM a -> RenameM (a, Map DepName (Set Name))
- curLoc :: RenameM Range
- located :: a -> RenameM (Located a)
- withLoc :: HasLoc loc => loc -> RenameM a -> RenameM a
- shadowNames :: BindsNames env => env -> RenameM a -> RenameM a
- data EnvCheck
  - = CheckAll
  - | CheckOverlap
  - | CheckNone
- checkOverlap :: NamingEnv -> RenameM NamingEnv
- checkShadowing :: NamingEnv -> NamingEnv -> RenameM ()
- shadowNames' :: BindsNames env => EnvCheck -> env -> RenameM a -> RenameM a
- recordUse :: Name -> RenameM ()
- addDep :: Name -> RenameM ()
- warnUnused :: ModPath -> NamingEnv -> RW -> [RenamerWarning]
- getExternal :: RenameM (ImpName Name -> Mod ())
- getExternalMod :: ImpName Name -> RenameM (Mod ())
- getTopModuleIface :: ImpName Name -> RenameM (Maybe Iface)
- recordImport :: Range -> ImpName Name -> RenameM ()
- 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)

# Documentation

data NameType Source #

Indicates if a name is in a binding poisition or a use site

Constructors

NameBind |
NameUse |

data RenamerInfo Source #

Information needed to do some renaming.

Constructors

RenamerInfo |

Fields

- renSupply :: Supply

  Use to make new names

- renContext :: ModPath

  We are renaming things in here

- renEnv :: NamingEnv

  This is what's in scope

- renIfaces :: Map ModName (Either ModParamNames Iface)

  External modules

newtype RenameM a Source #

Constructors

RenameM |

Fields

- unRenameM :: ReaderT RO (StateT RW Lift) a

#### Instances

Instances details

Applicative RenameM Source # |
Instance details Defined in Cryptol.ModuleSystem.Renamer.Monad Methods pure :: a -> RenameM a Source # (<*>) :: RenameM (a -> b) -> RenameM a -> RenameM b Source # liftA2 :: (a -> b -> c) -> RenameM a -> RenameM b -> RenameM c Source # (*>) :: RenameM a -> RenameM b -> RenameM b Source # (<*) :: RenameM a -> RenameM b -> RenameM a Source #
Functor RenameM Source # |
Instance details Defined in Cryptol.ModuleSystem.Renamer.Monad Methods fmap :: (a -> b) -> RenameM a -> RenameM b Source # (<$) :: a -> RenameM b -> RenameM a Source #
Monad RenameM Source # |
Instance details Defined in Cryptol.ModuleSystem.Renamer.Monad Methods (>>=) :: RenameM a -> (a -> RenameM b) -> RenameM b Source # (>>) :: RenameM a -> RenameM b -> RenameM b Source # return :: a -> RenameM a Source #
FreshM RenameM Source # |
Instance details Defined in Cryptol.ModuleSystem.Renamer.Monad Methods liftSupply :: (Supply -> (a, Supply)) -> RenameM a Source #
(Semigroup a, Monoid a) => Monoid (RenameM a) Source # |
Instance details Defined in Cryptol.ModuleSystem.Renamer.Monad Methods mempty :: RenameM a Source # mappend :: RenameM a -> RenameM a -> RenameM a Source # mconcat :: [RenameM a] -> RenameM a Source #
Semigroup a => Semigroup (RenameM a) Source # |
Instance details Defined in Cryptol.ModuleSystem.Renamer.Monad Methods (<>) :: RenameM a -> RenameM a -> RenameM a Source # sconcat :: NonEmpty (RenameM a) -> RenameM a Source # stimes :: Integral b => b -> RenameM a -> RenameM a Source #

data RO Source #

Constructors

RO |

Fields

- roLoc :: Range
- roNames :: NamingEnv
- roExternal :: Map ModName (Maybe Iface, Map (ImpName Name) (Mod ()))

  Externally loaded modules. `Mod` is defined in `Binds`.

- roCurMod :: ModPath

  Current module we are working on

- roNestedMods :: Map ModPath Name

  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 `addDep`.

- roResolvedModules :: Map (ImpName Name) ResolvedLocal

  Info about locally defined modules

- roModParams :: Map Ident RenModParam

  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)

- roFromModParam :: Map Name DepName

  Keeps track of which names were introduce by module parameters and which one. The `DepName` is always a `ModParamName`.

data RW Source #

Constructors

RW |

Fields

- rwWarnings :: ![RenamerWarning]
- rwErrors :: !(Set RenamerError)
- rwSupply :: !Supply
- rwNameUseCount :: !(Map Name Int)

  How many times did we refer to each name. Used to generate warnings for unused definitions.

- rwCurrentDeps :: Set Name

  keeps track of names *used* by something. see `depsOf`

- rwDepGraph :: Map DepName (Set Name)

  keeps track of the dependencies for things. see `depsOf`

- rwExternalDeps :: !IfaceDecls

  Info about imported things, from external modules

data RenModParam Source #

Constructors

RenModParam |

Fields

- renModParamName :: Ident
- renModParamRange :: Range
- renModParamSig :: ImpName Name
- renModParamInstance :: Map Name Name

  Maps names that come into scope through this parameter to the names in the *module interface*. This is for functors, NOT functor instantantiations.

runRenamer :: RenamerInfo -> RenameM a -> (Either [RenamerError] (a, Supply), [RenamerWarning]) Source #

setCurMod :: ModPath -> RenameM a -> RenameM a Source #

getCurMod :: RenameM ModPath Source #

getNamingEnv :: RenameM NamingEnv Source #

setResolvedLocals :: Map (ImpName Name) ResolvedLocal -> RenameM a -> RenameM a Source #

lookupResolved :: ImpName Name -> RenameM ResolvedLocal Source #

setModParams :: [RenModParam] -> RenameM a -> RenameM a Source #

foldLoop :: [a] -> b -> (a -> b -> b) -> b Source #

getModParam :: Ident -> RenameM RenModParam Source #

getNamesFromModParams :: RenameM (Map Name DepName) Source #

getLocalModParamDeps :: RenameM (Map Ident DepName) Source #

setNestedModule :: Map ModPath Name -> RenameM a -> RenameM a Source #

nestedModuleOrig :: ModPath -> RenameM (Maybe Name) Source #

recordError :: RenamerError -> RenameM () Source #

Record an error.

recordWarning :: RenamerWarning -> RenameM () Source #

collectIfaceDeps :: RenameM a -> RenameM (IfaceDecls, a) Source #

depsOf :: DepName -> RenameM a -> RenameM a Source #

Rename something. All name uses in the sub-computation are assumed to be dependenices of the thing.

depGroup :: RenameM a -> RenameM (a, Map DepName (Set Name)) Source #

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.

curLoc :: RenameM Range Source #

Get the source range for wahtever we are currently renaming.

located :: a -> RenameM (Located a) Source #

Annotate something with the current range.

withLoc :: HasLoc loc => loc -> RenameM a -> RenameM a Source #

Do the given computation using the source code range from `loc` if any.

shadowNames :: BindsNames env => env -> RenameM a -> RenameM a Source #

Shadow the current naming environment with some more names.

data EnvCheck Source #

Constructors

CheckAll | Check for overlap and shadowing
CheckOverlap | Only check for overlap
CheckNone | Don't check the environment

#### Instances

Instances details

Show EnvCheck Source # |
Instance details Defined in Cryptol.ModuleSystem.Renamer.Monad Methods showsPrec :: Int -> EnvCheck -> ShowS Source # show :: EnvCheck -> String Source # showList :: [EnvCheck] -> ShowS Source #
Eq EnvCheck Source # |
Instance details Defined in Cryptol.ModuleSystem.Renamer.Monad Methods (==) :: EnvCheck -> EnvCheck -> Bool Source # (/=) :: EnvCheck -> EnvCheck -> Bool Source #

checkOverlap :: NamingEnv -> RenameM NamingEnv Source #

Report errors if the given naming environemnt contains multiple definitions for the same symbol

checkShadowing :: NamingEnv -> NamingEnv -> RenameM () Source #

Issue warnings if entries in the first environment would shadow something in the second.

shadowNames' :: BindsNames env => EnvCheck -> env -> RenameM a -> RenameM a Source #

Shadow the current naming environment with some more names. XXX: The checks are really confusing

recordUse :: Name -> RenameM () Source #

addDep :: Name -> RenameM () Source #

Mark something as a dependency. This is similar but different from `recordUse`, 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, `recordUse` 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: - `A::B::x` depends on `A::B::C::D::y`, `x` depends on `A::B::C` - `A::B::x` depends on `A::P::Q::y``,` x`depends on` A::P@

warnUnused :: ModPath -> NamingEnv -> RW -> [RenamerWarning] Source #

getExternal :: RenameM (ImpName Name -> Mod ()) Source #

getExternalMod :: ImpName Name -> RenameM (Mod ()) Source #

getTopModuleIface :: ImpName Name -> RenameM (Maybe Iface) Source #

Returns `Nothing` if the name does not refer to a module (i.e., it is a sig)

recordImport :: Range -> ImpName Name -> RenameM () Source #

Record an import: * record external dependency if the name refers to an external import * record an error if the imported thing is a functor

lookupModuleThing :: ImpName Name -> RenameM (Either ResolvedLocal (Mod ())) Source #

Lookup a name either in the locally resolved thing or in an external module

lookupDefines :: ImpName Name -> RenameM NamingEnv Source #

checkIsModule :: Range -> ImpName Name -> ModKind -> RenameM () Source #

lookupDefinesAndSubs :: ImpName Name -> RenameM (NamingEnv, Set Name) Source #