ghc-lib-parser-9.12.2.20250421: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Types.Cpr

Description

Types for the Constructed Product Result lattice. GHC.Core.Opt.CprAnal and GHC.Core.Opt.WorkWrap.Utils are its primary customers via `idCprSig`.

Synopsis

- data Cpr where
  - pattern ConCpr :: ConTag -> [Cpr] -> Cpr
- topCpr :: Cpr
- botCpr :: Cpr
- flatConCpr :: ConTag -> Cpr
- asConCpr :: Cpr -> Maybe (ConTag, [Cpr])
- data CprType = CprType {
  - ct_arty :: !Arity
  - ct_cpr :: !Cpr
  }
- topCprType :: CprType
- botCprType :: CprType
- flatConCprType :: ConTag -> CprType
- lubCprType :: CprType -> CprType -> CprType
- applyCprTy :: CprType -> Arity -> CprType
- abstractCprTy :: CprType -> CprType
- trimCprTy :: CprType -> CprType
- data UnpackConFieldsResult
  - = AllFieldsSame !Cpr
  - | ForeachField ![Cpr]
- unpackConFieldsCpr :: DataCon -> Cpr -> UnpackConFieldsResult
- newtype CprSig = CprSig {
  - getCprSig :: CprType
  }
- topCprSig :: CprSig
- isTopCprSig :: CprSig -> Bool
- mkCprSigForArity :: Arity -> CprType -> CprSig
- mkCprSig :: Arity -> Cpr -> CprSig
- seqCprSig :: CprSig -> ()
- prependArgsCprSig :: Arity -> CprSig -> CprSig

# Documentation

data Cpr where Source #

Bundled Patterns

pattern ConCpr :: ConTag -> [Cpr] -> Cpr |

#### Instances

Instances details

Binary Cpr Source # |
Instance details Defined in GHC.Types.Cpr Methods put_ :: WriteBinHandle -> Cpr -> IO () Source # put :: WriteBinHandle -> Cpr -> IO (Bin Cpr) Source # get :: ReadBinHandle -> IO Cpr Source #

Outputable Cpr Source #

BNF:

    cpr ::= ''                               -- TopCpr
         |  n                                -- FlatConCpr n
         |  n '(' cpr1 ',' cpr2 ',' ... ')'  -- ConCpr n [cpr1,cpr2,...]
         |  'b'                              -- BotCpr

Examples: * `f x = f x` has result CPR `b` * `1(1,)` is a valid (nested) `Cpr` denotation for `(I# 42#, f 42)`.

Instance details Defined in GHC.Types.Cpr Methods ppr :: Cpr -> SDoc Source #
Eq Cpr Source # |
Instance details Defined in GHC.Types.Cpr Methods (==) :: Cpr -> Cpr -> Bool Source # (/=) :: Cpr -> Cpr -> Bool Source #

topCpr :: Cpr Source #

botCpr :: Cpr Source #

flatConCpr :: ConTag -> Cpr Source #

asConCpr :: Cpr -> Maybe (ConTag, [Cpr]) Source #

data CprType Source #

The abstract domain \(A_t\) from the original 'CPR for Haskell' paper.

Constructors

CprType |

Fields

- ct_arty :: !Arity

  Number of value arguments the denoted expression eats before returning the `ct_cpr`

- ct_cpr :: !Cpr

  `Cpr` eventually unleashed when applied to `ct_arty` arguments

#### Instances

Instances details

Binary CprType Source # |
Instance details Defined in GHC.Types.Cpr Methods put_ :: WriteBinHandle -> CprType -> IO () Source # put :: WriteBinHandle -> CprType -> IO (Bin CprType) Source # get :: ReadBinHandle -> IO CprType Source #

Outputable CprType Source #

BNF:

    cpr_ty ::= cpr               -- short form if arty == 0
            |  '\' arty '.' cpr  -- if arty > 0

Examples: * `f x y z = f x y z` has denotation `3.b` * `g !x = (x+1, x+2)` has denotation `1.1(1,1)`.

Instance details Defined in GHC.Types.Cpr Methods ppr :: CprType -> SDoc Source #
Eq CprType Source # |
Instance details Defined in GHC.Types.Cpr Methods (==) :: CprType -> CprType -> Bool Source # (/=) :: CprType -> CprType -> Bool Source #

topCprType :: CprType Source #

botCprType :: CprType Source #

flatConCprType :: ConTag -> CprType Source #

lubCprType :: CprType -> CprType -> CprType Source #

applyCprTy :: CprType -> Arity -> CprType Source #

abstractCprTy :: CprType -> CprType Source #

trimCprTy :: CprType -> CprType Source #

data UnpackConFieldsResult Source #

The result of `unpackConFieldsCpr`.

Constructors

AllFieldsSame !Cpr |
ForeachField ![Cpr] |

unpackConFieldsCpr :: DataCon -> Cpr -> UnpackConFieldsResult Source #

Unpacks a `ConCpr`-shaped `Cpr` and returns the field `Cpr`s wrapped in a `ForeachField`. Otherwise, it returns `AllFieldsSame` with the appropriate `Cpr` to assume for each field.

The use of `UnpackConFieldsResult` allows O(1) space for the common, non-`ConCpr` case.

newtype CprSig Source #

The arity of the wrapped `CprType` is the arity at which it is safe to unleash. See Note [Understanding DmdType and DmdSig] in GHC.Types.Demand

Constructors

CprSig |

Fields

- getCprSig :: CprType

#### Instances

Instances details

Binary CprSig Source # |
Instance details Defined in GHC.Types.Cpr Methods put_ :: WriteBinHandle -> CprSig -> IO () Source # put :: WriteBinHandle -> CprSig -> IO (Bin CprSig) Source # get :: ReadBinHandle -> IO CprSig Source #
Outputable CprSig Source # | Only print the CPR result
Instance details Defined in GHC.Types.Cpr Methods ppr :: CprSig -> SDoc Source #
Eq CprSig Source # |
Instance details Defined in GHC.Types.Cpr Methods (==) :: CprSig -> CprSig -> Bool Source # (/=) :: CprSig -> CprSig -> Bool Source #

topCprSig :: CprSig Source #

isTopCprSig :: CprSig -> Bool Source #

mkCprSigForArity :: Arity -> CprType -> CprSig Source #

Turns a `CprType` computed for the particular `Arity` into a `CprSig` unleashable at that arity. See Note [Understanding DmdType and DmdSig] in GHC.Types.Demand

mkCprSig :: Arity -> Cpr -> CprSig Source #

seqCprSig :: CprSig -> () Source #

prependArgsCprSig :: Arity -> CprSig -> CprSig Source #

Add extra value args to CprSig