Cabal-2.0.1.0: A framework for packaging Haskell software

Safe Haskell | None
Language | Haskell2010

Distribution.Backpack

Contents

- OpenUnitId
- DefUnitId
- OpenModule
- OpenModuleSubst
- Conversions to `UnitId`

Description

This module defines the core data types for Backpack. For more details, see:

https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst

Synopsis

- data OpenUnitId
  - = IndefFullUnitId ComponentId OpenModuleSubst
  - | DefiniteUnitId DefUnitId
- openUnitIdFreeHoles :: OpenUnitId -> Set ModuleName
- mkOpenUnitId :: UnitId -> ComponentId -> OpenModuleSubst -> OpenUnitId
- data DefUnitId
- unDefUnitId :: DefUnitId -> UnitId
- mkDefUnitId :: ComponentId -> Map ModuleName Module -> DefUnitId
- data OpenModule
  - = OpenModule OpenUnitId ModuleName
  - | OpenModuleVar ModuleName
- openModuleFreeHoles :: OpenModule -> Set ModuleName
- type OpenModuleSubst = Map ModuleName OpenModule
- dispOpenModuleSubst :: OpenModuleSubst -> Doc
- dispOpenModuleSubstEntry :: (ModuleName, OpenModule) -> Doc
- parseOpenModuleSubst :: ReadP r OpenModuleSubst
- parseOpenModuleSubstEntry :: ReadP r (ModuleName, OpenModule)
- openModuleSubstFreeHoles :: OpenModuleSubst -> Set ModuleName
- abstractUnitId :: OpenUnitId -> UnitId
- hashModuleSubst :: Map ModuleName Module -> Maybe String

# OpenUnitId

data OpenUnitId #

An `OpenUnitId` describes a (possibly partially) instantiated Backpack component, with a description of how the holes are filled in. Unlike `OpenUnitId`, the `ModuleSubst` is kept in a structured form that allows for substitution (which fills in holes.) This form of unit cannot be installed. It must first be converted to a `UnitId`.

In the absence of Backpack, there are no holes to fill, so any such component always has an empty module substitution; thus we can lossly represent it as an 'OpenUnitId uid'.

For a source component using Backpack, however, there is more structure as components may be parametrized over some signatures, and these "holes" may be partially or wholly filled.

OpenUnitId plays an important role when we are mix-in linking, and is recorded to the installed packaged database for indefinite packages; however, for compiled packages that are fully instantiated, we instantiate `OpenUnitId` into `UnitId`.

For more details see the Backpack spec https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst

Constructors

IndefFullUnitId ComponentId OpenModuleSubst | Identifies a component which may have some unfilled holes; specifying its `ComponentId` and its `OpenModuleSubst`. TODO: Invariant that `OpenModuleSubst` is non-empty? See also the Text instance.
DefiniteUnitId DefUnitId | Identifies a fully instantiated component, which has been compiled and abbreviated as a hash. The embedded `UnitId` MUST NOT be for an indefinite component; an `OpenUnitId` is guaranteed not to have any holes.

Instances

Eq OpenUnitId # |
Methods (==) :: OpenUnitId -> OpenUnitId -> Bool # (/=) :: OpenUnitId -> OpenUnitId -> Bool #
Data OpenUnitId # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> OpenUnitId -> c OpenUnitId Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c OpenUnitId Source #

toConstr :: OpenUnitId -> Constr Source #

dataTypeOf :: OpenUnitId -> DataType Source #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c OpenUnitId) Source #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OpenUnitId) Source #

gmapT :: (forall b. Data b => b -> b) -> OpenUnitId -> OpenUnitId Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OpenUnitId -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OpenUnitId -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> OpenUnitId -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> OpenUnitId -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> OpenUnitId -> m OpenUnitId Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> OpenUnitId -> m OpenUnitId Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> OpenUnitId -> m OpenUnitId Source #

Ord OpenUnitId # |
Methods compare :: OpenUnitId -> OpenUnitId -> Ordering # (<) :: OpenUnitId -> OpenUnitId -> Bool # (<=) :: OpenUnitId -> OpenUnitId -> Bool # (>) :: OpenUnitId -> OpenUnitId -> Bool # (>=) :: OpenUnitId -> OpenUnitId -> Bool # max :: OpenUnitId -> OpenUnitId -> OpenUnitId # min :: OpenUnitId -> OpenUnitId -> OpenUnitId #
Read OpenUnitId # |
Methods readsPrec :: Int -> ReadS OpenUnitId Source # readList :: ReadS [OpenUnitId] Source # readPrec :: ReadPrec OpenUnitId Source # readListPrec :: ReadPrec [OpenUnitId] Source #
Show OpenUnitId # |
Methods showsPrec :: Int -> OpenUnitId -> ShowS Source # show :: OpenUnitId -> String Source # showList :: [OpenUnitId] -> ShowS Source #
Generic OpenUnitId # |
Associated Types type Rep OpenUnitId :: * -> * Source # Methods from :: OpenUnitId -> Rep OpenUnitId x Source # to :: Rep OpenUnitId x -> OpenUnitId Source #
NFData OpenUnitId # |
Methods rnf :: OpenUnitId -> () Source #
Binary OpenUnitId # |
Methods put :: OpenUnitId -> Put Source # get :: Get OpenUnitId Source # putList :: [OpenUnitId] -> Put Source #
Text OpenUnitId # |
Methods disp :: OpenUnitId -> Doc # parse :: ReadP r OpenUnitId #
ModSubst OpenUnitId # |
Methods modSubst :: OpenModuleSubst -> OpenUnitId -> OpenUnitId #
type Rep OpenUnitId # |

type Rep OpenUnitId = D1 * (MetaData "OpenUnitId" "Distribution.Backpack" "Cabal-2.0.1.0" False) ((:+:) * (C1 * (MetaCons "IndefFullUnitId" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * ComponentId)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * OpenModuleSubst)))) (C1 * (MetaCons "DefiniteUnitId" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * DefUnitId))))

openUnitIdFreeHoles :: OpenUnitId -> Set ModuleName #

Get the set of holes (`ModuleVar`) embedded in a `UnitId`.

mkOpenUnitId :: UnitId -> ComponentId -> OpenModuleSubst -> OpenUnitId #

Safe constructor from a UnitId. The only way to do this safely is if the instantiation is provided.

# DefUnitId

data DefUnitId #

A `UnitId` for a definite package. The `DefUnitId` invariant says that a `UnitId` identified this way is definite; i.e., it has no unfilled holes.

Instances

Eq DefUnitId # |
Methods (==) :: DefUnitId -> DefUnitId -> Bool # (/=) :: DefUnitId -> DefUnitId -> Bool #
Data DefUnitId # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> DefUnitId -> c DefUnitId Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c DefUnitId Source #

toConstr :: DefUnitId -> Constr Source #

dataTypeOf :: DefUnitId -> DataType Source #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c DefUnitId) Source #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DefUnitId) Source #

gmapT :: (forall b. Data b => b -> b) -> DefUnitId -> DefUnitId Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> DefUnitId -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> DefUnitId -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> DefUnitId -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> DefUnitId -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> DefUnitId -> m DefUnitId Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> DefUnitId -> m DefUnitId Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> DefUnitId -> m DefUnitId Source #

Ord DefUnitId # |
Methods compare :: DefUnitId -> DefUnitId -> Ordering # (<) :: DefUnitId -> DefUnitId -> Bool # (<=) :: DefUnitId -> DefUnitId -> Bool # (>) :: DefUnitId -> DefUnitId -> Bool # (>=) :: DefUnitId -> DefUnitId -> Bool # max :: DefUnitId -> DefUnitId -> DefUnitId # min :: DefUnitId -> DefUnitId -> DefUnitId #
Read DefUnitId # |
Methods readsPrec :: Int -> ReadS DefUnitId Source # readList :: ReadS [DefUnitId] Source # readPrec :: ReadPrec DefUnitId Source # readListPrec :: ReadPrec [DefUnitId] Source #
Show DefUnitId # |
Methods showsPrec :: Int -> DefUnitId -> ShowS Source # show :: DefUnitId -> String Source # showList :: [DefUnitId] -> ShowS Source #
Generic DefUnitId # |
Associated Types type Rep DefUnitId :: * -> * Source # Methods from :: DefUnitId -> Rep DefUnitId x Source # to :: Rep DefUnitId x -> DefUnitId Source #
NFData DefUnitId # |
Methods rnf :: DefUnitId -> () Source #
Binary DefUnitId # |
Methods put :: DefUnitId -> Put Source # get :: Get DefUnitId Source # putList :: [DefUnitId] -> Put Source #
Text DefUnitId # |
Methods disp :: DefUnitId -> Doc # parse :: ReadP r DefUnitId #
type Rep DefUnitId # |
type Rep DefUnitId = D1 * (MetaData "DefUnitId" "Distribution.Types.UnitId" "Cabal-2.0.1.0" True) (C1 * (MetaCons "DefUnitId" PrefixI True) (S1 * (MetaSel (Just Symbol "unDefUnitId") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * UnitId)))

unDefUnitId :: DefUnitId -> UnitId #

mkDefUnitId :: ComponentId -> Map ModuleName Module -> DefUnitId #

Create a `DefUnitId` from a `ComponentId` and an instantiation with no holes.

# OpenModule

data OpenModule #

Unlike a `Module`, an `OpenModule` is either an ordinary module from some unit, OR an `OpenModuleVar`, representing a hole that needs to be filled in. Substitutions are over module variables.

Constructors

OpenModule OpenUnitId ModuleName |
OpenModuleVar ModuleName |

Instances

Eq OpenModule # |
Methods (==) :: OpenModule -> OpenModule -> Bool # (/=) :: OpenModule -> OpenModule -> Bool #
Data OpenModule # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> OpenModule -> c OpenModule Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c OpenModule Source #

toConstr :: OpenModule -> Constr Source #

dataTypeOf :: OpenModule -> DataType Source #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c OpenModule) Source #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OpenModule) Source #

gmapT :: (forall b. Data b => b -> b) -> OpenModule -> OpenModule Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OpenModule -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OpenModule -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> OpenModule -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> OpenModule -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> OpenModule -> m OpenModule Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> OpenModule -> m OpenModule Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> OpenModule -> m OpenModule Source #

Ord OpenModule # |
Methods compare :: OpenModule -> OpenModule -> Ordering # (<) :: OpenModule -> OpenModule -> Bool # (<=) :: OpenModule -> OpenModule -> Bool # (>) :: OpenModule -> OpenModule -> Bool # (>=) :: OpenModule -> OpenModule -> Bool # max :: OpenModule -> OpenModule -> OpenModule # min :: OpenModule -> OpenModule -> OpenModule #
Read OpenModule # |
Methods readsPrec :: Int -> ReadS OpenModule Source # readList :: ReadS [OpenModule] Source # readPrec :: ReadPrec OpenModule Source # readListPrec :: ReadPrec [OpenModule] Source #
Show OpenModule # |
Methods showsPrec :: Int -> OpenModule -> ShowS Source # show :: OpenModule -> String Source # showList :: [OpenModule] -> ShowS Source #
Generic OpenModule # |
Associated Types type Rep OpenModule :: * -> * Source # Methods from :: OpenModule -> Rep OpenModule x Source # to :: Rep OpenModule x -> OpenModule Source #
NFData OpenModule # |
Methods rnf :: OpenModule -> () Source #
Binary OpenModule # |
Methods put :: OpenModule -> Put Source # get :: Get OpenModule Source # putList :: [OpenModule] -> Put Source #
Text OpenModule # |
Methods disp :: OpenModule -> Doc # parse :: ReadP r OpenModule #
ModSubst OpenModule # |
Methods modSubst :: OpenModuleSubst -> OpenModule -> OpenModule #
type Rep OpenModule # |

type Rep OpenModule = D1 * (MetaData "OpenModule" "Distribution.Backpack" "Cabal-2.0.1.0" False) ((:+:) * (C1 * (MetaCons "OpenModule" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * OpenUnitId)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * ModuleName)))) (C1 * (MetaCons "OpenModuleVar" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * ModuleName))))

openModuleFreeHoles :: OpenModule -> Set ModuleName #

Get the set of holes (`ModuleVar`) embedded in a `Module`.

# OpenModuleSubst

type OpenModuleSubst = Map ModuleName OpenModule #

An explicit substitution on modules.

NB: These substitutions are NOT idempotent, for example, a valid substitution is (A -> B, B -> A).

dispOpenModuleSubst :: OpenModuleSubst -> Doc #

Pretty-print the entries of a module substitution, suitable for embedding into a `OpenUnitId` or passing to GHC via `--instantiate-with`.

dispOpenModuleSubstEntry :: (ModuleName, OpenModule) -> Doc #

Pretty-print a single entry of a module substitution.

parseOpenModuleSubst :: ReadP r OpenModuleSubst #

Inverse to `dispModSubst`.

parseOpenModuleSubstEntry :: ReadP r (ModuleName, OpenModule) #

Inverse to `dispModSubstEntry`.

openModuleSubstFreeHoles :: OpenModuleSubst -> Set ModuleName #

Get the set of holes (`ModuleVar`) embedded in a `OpenModuleSubst`. This is NOT the domain of the substitution.

# Conversions to `UnitId`

abstractUnitId :: OpenUnitId -> UnitId #

When typechecking, we don't demand that a freshly instantiated `IndefFullUnitId` be compiled; instead, we just depend on the installed indefinite unit installed at the `ComponentId`.

hashModuleSubst :: Map ModuleName Module -> Maybe String #

Take a module substitution and hash it into a string suitable for `UnitId`. Note that since this takes `Module`, not `OpenModule`, you are responsible for recursively converting `OpenModule` into `Module`. See also Distribution.Backpack.ReadyComponent.