Cabal-syntax-3.12.1.0: A library for working with .cabal files

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
- parsecOpenModuleSubst :: CabalParsing m => m OpenModuleSubst
- parsecOpenModuleSubstEntry :: CabalParsing m => m (ModuleName, OpenModule)
- openModuleSubstFreeHoles :: OpenModuleSubst -> Set ModuleName
- abstractUnitId :: OpenUnitId -> UnitId
- hashModuleSubst :: Map ModuleName Module -> Maybe String

# OpenUnitId

data OpenUnitId Source #

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 lossily represent it as a 'DefiniteUnitId 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

Instances details

Parsec OpenUnitId Source #

    >>> eitherParsec "foobar" :: Either String OpenUnitId
    Right (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "foobar"}))

    >>> eitherParsec "foo[Str=text-1.2.3:Data.Text.Text]" :: Either String OpenUnitId
    Right (IndefFullUnitId (ComponentId "foo") (fromList [(ModuleName "Str",OpenModule (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "text-1.2.3"})) (ModuleName "Data.Text.Text"))]))

Instance details Defined in Distribution.Backpack Methods parsec :: CabalParsing m => m OpenUnitId Source #
Pretty OpenUnitId Source # |
Instance details Defined in Distribution.Backpack Methods pretty :: OpenUnitId -> Doc Source # prettyVersioned :: CabalSpecVersion -> OpenUnitId -> Doc Source #
Structured OpenUnitId Source # |
Instance details Defined in Distribution.Backpack Methods structure :: Proxy OpenUnitId -> Structure Source # structureHash' :: Tagged OpenUnitId MD5
Binary OpenUnitId Source # |
Instance details Defined in Distribution.Backpack Methods put :: OpenUnitId -> Put Source # get :: Get OpenUnitId Source # putList :: [OpenUnitId] -> Put Source #
NFData OpenUnitId Source # |
Instance details Defined in Distribution.Backpack Methods rnf :: OpenUnitId -> () Source #
Data OpenUnitId Source # |

Instance details

Defined in Distribution.Backpack

Methods

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

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

toConstr :: OpenUnitId -> Constr #

dataTypeOf :: OpenUnitId -> DataType #

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

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

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

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

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

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

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

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

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

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

Generic OpenUnitId Source # |

Instance details

Defined in Distribution.Backpack

Associated Types

type Rep OpenUnitId |

Instance details

Defined in Distribution.Backpack

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

Methods

from :: OpenUnitId -> Rep OpenUnitId x #

to :: Rep OpenUnitId x -> OpenUnitId #

Read OpenUnitId Source # |
Instance details Defined in Distribution.Backpack Methods readsPrec :: Int -> ReadS OpenUnitId # readList :: ReadS [OpenUnitId] # readPrec :: ReadPrec OpenUnitId # readListPrec :: ReadPrec [OpenUnitId] #
Show OpenUnitId Source # |
Instance details Defined in Distribution.Backpack Methods showsPrec :: Int -> OpenUnitId -> ShowS # show :: OpenUnitId -> String # showList :: [OpenUnitId] -> ShowS #
Eq OpenUnitId Source # |
Instance details Defined in Distribution.Backpack Methods (==) :: OpenUnitId -> OpenUnitId -> Bool # (/=) :: OpenUnitId -> OpenUnitId -> Bool #
Ord OpenUnitId Source # |
Instance details Defined in Distribution.Backpack 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 #
type Rep OpenUnitId Source # |

Instance details

Defined in Distribution.Backpack

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

openUnitIdFreeHoles :: OpenUnitId -> Set ModuleName Source #

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

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

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

# DefUnitId

data DefUnitId Source #

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

Instances details

Parsec DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId Methods parsec :: CabalParsing m => m DefUnitId Source #
Pretty DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId Methods pretty :: DefUnitId -> Doc Source # prettyVersioned :: CabalSpecVersion -> DefUnitId -> Doc Source #
Structured DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId Methods structure :: Proxy DefUnitId -> Structure Source # structureHash' :: Tagged DefUnitId MD5
Binary DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId Methods put :: DefUnitId -> Put Source # get :: Get DefUnitId Source # putList :: [DefUnitId] -> Put Source #
NFData DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId Methods rnf :: DefUnitId -> () Source #
Data DefUnitId Source # |

Instance details

Defined in Distribution.Types.UnitId

Methods

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

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

toConstr :: DefUnitId -> Constr #

dataTypeOf :: DefUnitId -> DataType #

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

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

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

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

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

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

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

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

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

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

Generic DefUnitId Source # |

Instance details

Defined in Distribution.Types.UnitId

Associated Types

type Rep DefUnitId |
Instance details Defined in Distribution.Types.UnitId type Rep DefUnitId = D1 ('MetaData "DefUnitId" "Distribution.Types.UnitId" "Cabal-syntax-3.12.1.0-5c0e" 'True) (C1 ('MetaCons "DefUnitId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unDefUnitId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UnitId)))

Methods

from :: DefUnitId -> Rep DefUnitId x #

to :: Rep DefUnitId x -> DefUnitId #

Read DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId Methods readsPrec :: Int -> ReadS DefUnitId # readList :: ReadS [DefUnitId] # readPrec :: ReadPrec DefUnitId # readListPrec :: ReadPrec [DefUnitId] #
Show DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId Methods showsPrec :: Int -> DefUnitId -> ShowS # show :: DefUnitId -> String # showList :: [DefUnitId] -> ShowS #
Eq DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId Methods (==) :: DefUnitId -> DefUnitId -> Bool # (/=) :: DefUnitId -> DefUnitId -> Bool #
Ord DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId 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 #
type Rep DefUnitId Source # |
Instance details Defined in Distribution.Types.UnitId type Rep DefUnitId = D1 ('MetaData "DefUnitId" "Distribution.Types.UnitId" "Cabal-syntax-3.12.1.0-5c0e" 'True) (C1 ('MetaCons "DefUnitId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unDefUnitId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UnitId)))

unDefUnitId :: DefUnitId -> UnitId Source #

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

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

# OpenModule

data OpenModule Source #

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

Instances details

Parsec OpenModule Source #

    >>> eitherParsec "Includes2-0.1.0.0-inplace-mysql:Database.MySQL" :: Either String OpenModule
    Right (OpenModule (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "Includes2-0.1.0.0-inplace-mysql"})) (ModuleName "Database.MySQL"))

Instance details Defined in Distribution.Backpack Methods parsec :: CabalParsing m => m OpenModule Source #
Pretty OpenModule Source # |
Instance details Defined in Distribution.Backpack Methods pretty :: OpenModule -> Doc Source # prettyVersioned :: CabalSpecVersion -> OpenModule -> Doc Source #
Structured OpenModule Source # |
Instance details Defined in Distribution.Backpack Methods structure :: Proxy OpenModule -> Structure Source # structureHash' :: Tagged OpenModule MD5
Binary OpenModule Source # |
Instance details Defined in Distribution.Backpack Methods put :: OpenModule -> Put Source # get :: Get OpenModule Source # putList :: [OpenModule] -> Put Source #
NFData OpenModule Source # |
Instance details Defined in Distribution.Backpack Methods rnf :: OpenModule -> () Source #
Data OpenModule Source # |

Instance details

Defined in Distribution.Backpack

Methods

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

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

toConstr :: OpenModule -> Constr #

dataTypeOf :: OpenModule -> DataType #

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

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

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

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

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

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

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

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

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

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

Generic OpenModule Source # |

Instance details

Defined in Distribution.Backpack

Associated Types

type Rep OpenModule |

Instance details

Defined in Distribution.Backpack

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

Methods

from :: OpenModule -> Rep OpenModule x #

to :: Rep OpenModule x -> OpenModule #

Read OpenModule Source # |
Instance details Defined in Distribution.Backpack Methods readsPrec :: Int -> ReadS OpenModule # readList :: ReadS [OpenModule] # readPrec :: ReadPrec OpenModule # readListPrec :: ReadPrec [OpenModule] #
Show OpenModule Source # |
Instance details Defined in Distribution.Backpack Methods showsPrec :: Int -> OpenModule -> ShowS # show :: OpenModule -> String # showList :: [OpenModule] -> ShowS #
Eq OpenModule Source # |
Instance details Defined in Distribution.Backpack Methods (==) :: OpenModule -> OpenModule -> Bool # (/=) :: OpenModule -> OpenModule -> Bool #
Ord OpenModule Source # |
Instance details Defined in Distribution.Backpack 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 #
type Rep OpenModule Source # |

Instance details

Defined in Distribution.Backpack

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

openModuleFreeHoles :: OpenModule -> Set ModuleName Source #

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

# OpenModuleSubst

type OpenModuleSubst = Map ModuleName OpenModule Source #

An explicit substitution on modules.

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

dispOpenModuleSubst :: OpenModuleSubst -> Doc Source #

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 Source #

Pretty-print a single entry of a module substitution.

parsecOpenModuleSubst :: CabalParsing m => m OpenModuleSubst Source #

Inverse to `dispModSubst`.

Since: Cabal-syntax-2.2

parsecOpenModuleSubstEntry :: CabalParsing m => m (ModuleName, OpenModule) Source #

Inverse to `dispModSubstEntry`.

Since: Cabal-syntax-2.2

openModuleSubstFreeHoles :: OpenModuleSubst -> Set ModuleName Source #

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

# Conversions to `UnitId`

abstractUnitId :: OpenUnitId -> UnitId Source #

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 Source #

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.