| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
GHC.HsToCore.PmCheck.Types
Description
Types used through-out pattern match checking. This module is mostly there to be imported from GHC.Tc.Types. The exposed API is that of GHC.HsToCore.PmCheck.Oracle and GHC.HsToCore.PmCheck.
Synopsis
- data PmLit = PmLit {}
- data PmLitValue
- data PmAltCon
- pmLitType :: PmLit -> Type
- pmAltConType :: PmAltCon -> [Type] -> Type
- data PmEquality
- eqPmAltCon :: PmAltCon -> PmAltCon -> PmEquality
- literalToPmLit :: Type -> Literal -> Maybe PmLit
- negatePmLit :: PmLit -> Maybe PmLit
- overloadPmLit :: Type -> PmLit -> Maybe PmLit
- pmLitAsStringLit :: PmLit -> Maybe FastString
- coreExprAsPmLit :: CoreExpr -> Maybe PmLit
- type ConLikeSet = UniqDSet ConLike
- data PossibleMatches
- = PM (NonEmpty ConLikeSet)
- | NoPM
- data PmAltConSet
- emptyPmAltConSet :: PmAltConSet
- isEmptyPmAltConSet :: PmAltConSet -> Bool
- elemPmAltConSet :: PmAltCon -> PmAltConSet -> Bool
- extendPmAltConSet :: PmAltConSet -> PmAltCon -> PmAltConSet
- pmAltConSetElems :: PmAltConSet -> [PmAltCon]
- data Shared a
- newtype SharedDIdEnv a = SDIE {}
- emptySDIE :: SharedDIdEnv a
- lookupSDIE :: SharedDIdEnv a -> Id -> Maybe a
- sameRepresentativeSDIE :: SharedDIdEnv a -> Id -> Id -> Bool
- setIndirectSDIE :: SharedDIdEnv a -> Id -> Id -> SharedDIdEnv a
- setEntrySDIE :: SharedDIdEnv a -> Id -> a -> SharedDIdEnv a
- traverseSDIE :: forall a b f. Applicative f => (a -> f b) -> SharedDIdEnv a -> f (SharedDIdEnv b)
- data VarInfo = VI {
- vi_ty :: !Type
- vi_pos :: ![(PmAltCon, [TyVar], [Id])]
- vi_neg :: !PmAltConSet
- vi_cache :: !PossibleMatches
- data TmState = TmSt {}
- newtype TyState = TySt (Bag EvVar)
- data Delta = MkDelta {}
- newtype Deltas = MkDeltas (Bag Delta)
- initDeltas :: Deltas
- liftDeltasM :: Monad m => (Delta -> m (Maybe Delta)) -> Deltas -> m Deltas
Representations for Literals and AltCons
Literals (simple and overloaded ones) for pattern match checking.
See Note [Undecidable Equality for PmAltCons]
Constructors
| PmLit | |
Fields
| |
data PmLitValue #
Constructors
| PmLitInt Integer | |
| PmLitRat Rational | |
| PmLitChar Char | |
| PmLitString FastString | |
| PmLitOverInt Int Integer | |
| PmLitOverRat Int Rational | |
| PmLitOverString FastString |
Instances
| Outputable PmLitValue # | |
Defined in GHC.HsToCore.PmCheck.Types | |
Constructors
| PmAltConLike ConLike | |
| PmAltLit PmLit |
Equality on PmAltCons
data PmEquality #
Undecidable semantic equality result. See Note [Undecidable Equality for PmAltCons]
Constructors
| Equal | |
| Disjoint | |
| PossiblyOverlap |
Instances
| Show PmEquality # | |
Defined in GHC.HsToCore.PmCheck.Types | |
| Outputable PmEquality # | |
Defined in GHC.HsToCore.PmCheck.Types | |
| Eq PmEquality # | |
Defined in GHC.HsToCore.PmCheck.Types | |
eqPmAltCon :: PmAltCon -> PmAltCon -> PmEquality #
We can't in general decide whether two PmAltCons match the same set of
values. In addition to the reasons in eqPmLit and eqConLike, a
PmAltConLike might or might not represent the same value as a PmAltLit.
See Note [Undecidable Equality for PmAltCons].
Just True==> Surely equalJust False==> Surely different (non-overlapping, even!)Nothing==> Equality relation undecidable
Examples (omitting some constructor wrapping):
eqPmAltCon (LitInt 42) (LitInt 1) == Just False: Lit equality is decidableeqPmAltCon (DataCon A) (DataCon B) == Just False: DataCon equality is decidableeqPmAltCon (LitOverInt 42) (LitOverInt 1) == Nothing: OverLit equality is undecidableeqPmAltCon (PatSyn PA) (PatSyn PB) == Nothing: PatSyn equality is undecidableeqPmAltCon (DataCon I#) (LitInt 1) == Nothing: DataCon to Lit comparisons are undecidable without reasoning about the wrappedInt#eqPmAltCon (LitOverInt 1) (LitOverInt 1) == Just True: We assume reflexivity for overloaded literalseqPmAltCon (PatSyn PA) (PatSyn PA) == Just True: We assume reflexivity for Pattern Synonyms
Operations on PmLit
negatePmLit :: PmLit -> Maybe PmLit #
pmLitAsStringLit :: PmLit -> Maybe FastString #
coreExprAsPmLit :: CoreExpr -> Maybe PmLit #
Caching partially matched COMPLETE sets
type ConLikeSet = UniqDSet ConLike #
data PossibleMatches #
A data type caching the results of completeMatchConLikes with support for
deletion of constructors that were already matched on.
Constructors
| PM (NonEmpty ConLikeSet) | Each ConLikeSet is a (subset of) the constructors in a COMPLETE set
|
| NoPM | No COMPLETE set for this type (yet). Think of overloaded literals. |
Instances
| Outputable PossibleMatches # | |
Defined in GHC.HsToCore.PmCheck.Types | |
PmAltConSet
data PmAltConSet #
Instances
| Outputable PmAltConSet # | |
Defined in GHC.HsToCore.PmCheck.Types | |
isEmptyPmAltConSet :: PmAltConSet -> Bool #
elemPmAltConSet :: PmAltCon -> PmAltConSet -> Bool #
Whether there is a PmAltCon in the PmAltConSet that compares Equal to
the given PmAltCon according to eqPmAltCon.
extendPmAltConSet :: PmAltConSet -> PmAltCon -> PmAltConSet #
pmAltConSetElems :: PmAltConSet -> [PmAltCon] #
A DIdEnv where entries may be shared
Either Indirect x, meaning the value is represented by that of x, or
an Entry containing containing the actual value it represents.
Instances
newtype SharedDIdEnv a #
A DIdEnv in which entries can be shared by multiple Ids.
Merge equivalence classes of two Ids by setIndirectSDIE and set the entry
of an Id with setEntrySDIE.
Instances
emptySDIE :: SharedDIdEnv a #
lookupSDIE :: SharedDIdEnv a -> Id -> Maybe a #
sameRepresentativeSDIE :: SharedDIdEnv a -> Id -> Id -> Bool #
Check if two variables are part of the same equivalence class.
setIndirectSDIE :: SharedDIdEnv a -> Id -> Id -> SharedDIdEnv a #
setIndirectSDIE env x y sets x's Entry to Indirect y, thereby
merging x's equivalence class into y's. This will discard all info on
x!
setEntrySDIE :: SharedDIdEnv a -> Id -> a -> SharedDIdEnv a #
setEntrySDIE env x a sets the Entry x is associated with to a,
thereby modifying its whole equivalence class.
traverseSDIE :: forall a b f. Applicative f => (a -> f b) -> SharedDIdEnv a -> f (SharedDIdEnv b) #
The pattern match oracle
Information about an Id. Stores positive (vi_pos) facts, like x ~ Just 42,
and negative (vi_neg) facts, like "x is not (:)".
Also caches the type (vi_ty), the PossibleMatches of a COMPLETE set
(vi_cache).
Subject to Note [The Pos/Neg invariant] in GHC.HsToCore.PmCheck.Oracle.
Constructors
| VI | |
Fields
| |
The term oracle state. Stores VarInfo for encountered Ids. These
entries are possibly shared when we figure out that two variables must be
equal, thus represent the same set of values.
See Note [TmState invariants] in GHC.HsToCore.PmCheck.Oracle.
Constructors
| TmSt | |
Fields
| |
The type oracle state. A poor man's InsertSet: The invariant is
that all constraints in there are mutually compatible.
An inert set of canonical (i.e. mutually compatible) term and type constraints.
Constructors
| MkDelta | |
Fields
| |
A disjunctive bag of Deltas, representing a refinement type.
initDeltas :: Deltas #