clash-lib-1.8.4: Clash: a functional hardware description language - As a library

Copyright | (C) 2012-2016 University of Twente 2016 Myrtle Software Ltd 2017 Google Inc. 2021-2024 QBayLogic B.V.
License | BSD2 (see the file LICENSE)
Maintainer | QBayLogic B.V. <devops@qbaylogic.com>
Safe Haskell | None
Language | Haskell2010

Clash.Core.Type

Description

Types in CoreHW

Synopsis

- data Type
  - = VarTy !TyVar
  - | ConstTy !ConstTy
  - | ForAllTy !TyVar !Type
  - | AppTy !Type !Type
  - | LitTy !LitTy
  - | AnnType [Attr Text] !Type
- data TypeView
  - = FunTy !Type !Type
  - | TyConApp !TyConName [Type]
  - | OtherType !Type
- data ConstTy
  - = TyCon !TyConName
  - | Arrow
- data LitTy
  - = NumTy !Integer
  - | SymTy !String
  - | CharTy !Char
- type Kind = Type
- type KindOrType = Type
- type KiName = Name Kind
- type TyName = Name Type
- type TyVar = Var Type
- tyView :: Type -> TypeView
- coreView :: TyConMap -> Type -> Type
- coreView1 :: TyConMap -> Type -> Maybe Type
- mkTyConTy :: TyConName -> Type
- mkFunTy :: Type -> Type -> Type
- mkPolyFunTy :: Type -> [Either TyVar Type] -> Type
- mkTyConApp :: TyConName -> [Type] -> Type
- splitFunTy :: TyConMap -> Type -> Maybe (Type, Type)
- splitFunTys :: TyConMap -> Type -> ([Type], Type)
- splitFunForallTy :: Type -> ([Either TyVar Type], Type)
- splitCoreFunForallTy :: TyConMap -> Type -> ([Either TyVar Type], Type)
- splitTyConAppM :: Type -> Maybe (TyConName, [Type])
- isPolyFunTy :: Type -> Bool
- isPolyFunCoreTy :: TyConMap -> Type -> Bool
- isPolyTy :: Type -> Bool
- isTypeFamilyApplication :: TyConMap -> Type -> Bool
- isFunTy :: TyConMap -> Type -> Bool
- isClassTy :: TyConMap -> Type -> Bool
- applyFunTy :: TyConMap -> Type -> Type -> Type
- findFunSubst :: TyConMap -> [([Type], Type)] -> [Type] -> Maybe Type
- reduceTypeFamily :: TyConMap -> Type -> Maybe Type
- isIntegerTy :: Type -> Bool
- normalizeType :: TyConMap -> Type -> Type
- varAttrs :: Var a -> [Attr Text]
- typeAttrs :: Type -> [Attr Text]

# Documentation

data Type Source #

Types in CoreHW: function and polymorphic types

Constructors

VarTy !TyVar | Type variable
ConstTy !ConstTy | Type constant
ForAllTy !TyVar !Type | Polymorphic Type
AppTy !Type !Type | Type Application
LitTy !LitTy | Type literal
AnnType [Attr Text] !Type | Annotated type, see Clash.Annotations.SynthesisAttributes

#### Instances

Instances details

Binary Type Source # |
Instance details Defined in Clash.Core.Type Methods put :: Type -> Put Source # get :: Get Type Source # putList :: [Type] -> Put Source #
HasFreeVars Type Source # |
Instance details Defined in Clash.Core.HasFreeVars Methods freeVarsOf :: Type -> VarSet Source # isClosed :: Type -> Bool Source # elemFreeVars :: Var Type -> Type -> Bool Source # notElemFreeVars :: Var Type -> Type -> Bool Source # subsetFreeVars :: VarSet -> Type -> Bool Source # disjointFreeVars :: VarSet -> Type -> Bool Source #
HasType Type Source # |
Instance details Defined in Clash.Core.HasType Methods coreTypeOf :: Type -> Type Source #
InferType Type Source # |
Instance details Defined in Clash.Core.HasType Methods inferCoreTypeOf :: TyConMap -> Type -> Type Source #
PrettyPrec Type Source # |
Instance details Defined in Clash.Core.Pretty Methods pprPrec :: Monad m => Rational -> Type -> m ClashDoc Source # pprPrec' :: Monad m => PrettyOptions -> Rational -> Type -> m ClashDoc Source #
ClashPretty Type Source # |
Instance details Defined in Clash.Core.Pretty Methods clashPretty :: Type -> Doc () Source #
NFData Type Source # |
Instance details Defined in Clash.Core.Type Methods rnf :: Type -> () Source #
Generic Type Source # |

Instance details

Defined in Clash.Core.Type

Associated Types

type Rep Type |

Instance details

Defined in Clash.Core.Type

type Rep Type = D1 ('MetaData "Type" "Clash.Core.Type" "clash-lib-1.8.4-CsViYhmcYd4KTpfwGN07cn" 'False) ((C1 ('MetaCons "VarTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TyVar)) :+: (C1 ('MetaCons "ConstTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ConstTy)) :+: C1 ('MetaCons "ForAllTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TyVar) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type)))) :+: (C1 ('MetaCons "AppTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type)) :+: (C1 ('MetaCons "LitTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LitTy)) :+: C1 ('MetaCons "AnnType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Attr Text]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type)))))

Methods

from :: Type -> Rep Type x Source #

to :: Rep Type x -> Type Source #

Show Type Source # |
Instance details Defined in Clash.Core.Type Methods showsPrec :: Int -> Type -> ShowS Source # show :: Type -> String Source # showList :: [Type] -> ShowS Source #
Eq Type Source # |
Instance details Defined in Clash.Core.Subst Methods (==) :: Type -> Type -> Bool Source # (/=) :: Type -> Type -> Bool Source #
Ord Type Source # |
Instance details Defined in Clash.Core.Subst Methods compare :: Type -> Type -> Ordering Source # (<) :: Type -> Type -> Bool Source # (<=) :: Type -> Type -> Bool Source # (>) :: Type -> Type -> Bool Source # (>=) :: Type -> Type -> Bool Source # max :: Type -> Type -> Type Source # min :: Type -> Type -> Type Source #
(TypeError (('Text "A broken implementation of Hashable Type has been " ':<>: 'Text "removed in Clash 1.4.7. If this is an issue for you, please submit ") ':<>: 'Text "an issue report at https://github.com/clash-lang/clash-compiler/issues.") :: Constraint) => Hashable Type Source # |
Instance details Defined in Clash.Core.Type Methods hashWithSalt :: Int -> Type -> Int Source # hash :: Type -> Int Source #
type Rep Type Source # |

Instance details

Defined in Clash.Core.Type

type Rep Type = D1 ('MetaData "Type" "Clash.Core.Type" "clash-lib-1.8.4-CsViYhmcYd4KTpfwGN07cn" 'False) ((C1 ('MetaCons "VarTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TyVar)) :+: (C1 ('MetaCons "ConstTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ConstTy)) :+: C1 ('MetaCons "ForAllTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TyVar) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type)))) :+: (C1 ('MetaCons "AppTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type)) :+: (C1 ('MetaCons "LitTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LitTy)) :+: C1 ('MetaCons "AnnType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Attr Text]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type)))))

data TypeView Source #

An easier view on types

Constructors

FunTy !Type !Type | Function type
TyConApp !TyConName [Type] | Applied TyCon
OtherType !Type | Neither of the above

#### Instances

Instances details

Show TypeView Source # |
Instance details Defined in Clash.Core.Type Methods showsPrec :: Int -> TypeView -> ShowS Source # show :: TypeView -> String Source # showList :: [TypeView] -> ShowS Source #

data ConstTy Source #

Type Constants

Constructors

TyCon !TyConName | TyCon type
Arrow | Function type

#### Instances

Instances details

Binary ConstTy Source # |
Instance details Defined in Clash.Core.Type Methods put :: ConstTy -> Put Source # get :: Get ConstTy Source # putList :: [ConstTy] -> Put Source #
NFData ConstTy Source # |
Instance details Defined in Clash.Core.Type Methods rnf :: ConstTy -> () Source #
Generic ConstTy Source # |

Instance details

Defined in Clash.Core.Type

Associated Types

type Rep ConstTy |
Instance details Defined in Clash.Core.Type type Rep ConstTy = D1 ('MetaData "ConstTy" "Clash.Core.Type" "clash-lib-1.8.4-CsViYhmcYd4KTpfwGN07cn" 'False) (C1 ('MetaCons "TyCon" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TyConName)) :+: C1 ('MetaCons "Arrow" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: ConstTy -> Rep ConstTy x Source #

to :: Rep ConstTy x -> ConstTy Source #

Show ConstTy Source # |
Instance details Defined in Clash.Core.Type Methods showsPrec :: Int -> ConstTy -> ShowS Source # show :: ConstTy -> String Source # showList :: [ConstTy] -> ShowS Source #
Eq ConstTy Source # |
Instance details Defined in Clash.Core.Type Methods (==) :: ConstTy -> ConstTy -> Bool Source # (/=) :: ConstTy -> ConstTy -> Bool Source #
Ord ConstTy Source # |
Instance details Defined in Clash.Core.Type Methods compare :: ConstTy -> ConstTy -> Ordering Source # (<) :: ConstTy -> ConstTy -> Bool Source # (<=) :: ConstTy -> ConstTy -> Bool Source # (>) :: ConstTy -> ConstTy -> Bool Source # (>=) :: ConstTy -> ConstTy -> Bool Source # max :: ConstTy -> ConstTy -> ConstTy Source # min :: ConstTy -> ConstTy -> ConstTy Source #
Hashable ConstTy Source # |
Instance details Defined in Clash.Core.Type Methods hashWithSalt :: Int -> ConstTy -> Int Source # hash :: ConstTy -> Int Source #
type Rep ConstTy Source # |
Instance details Defined in Clash.Core.Type type Rep ConstTy = D1 ('MetaData "ConstTy" "Clash.Core.Type" "clash-lib-1.8.4-CsViYhmcYd4KTpfwGN07cn" 'False) (C1 ('MetaCons "TyCon" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TyConName)) :+: C1 ('MetaCons "Arrow" 'PrefixI 'False) (U1 :: Type -> Type))

data LitTy Source #

Literal Types

Constructors

NumTy !Integer |
SymTy !String |
CharTy !Char |

#### Instances

Instances details

Binary LitTy Source # |
Instance details Defined in Clash.Core.Type Methods put :: LitTy -> Put Source # get :: Get LitTy Source # putList :: [LitTy] -> Put Source #
PrettyPrec LitTy Source # |
Instance details Defined in Clash.Core.Pretty Methods pprPrec :: Monad m => Rational -> LitTy -> m ClashDoc Source # pprPrec' :: Monad m => PrettyOptions -> Rational -> LitTy -> m ClashDoc Source #
NFData LitTy Source # |
Instance details Defined in Clash.Core.Type Methods rnf :: LitTy -> () Source #
Generic LitTy Source # |

Instance details

Defined in Clash.Core.Type

Associated Types

type Rep LitTy |

Instance details

Defined in Clash.Core.Type

type Rep LitTy = D1 ('MetaData "LitTy" "Clash.Core.Type" "clash-lib-1.8.4-CsViYhmcYd4KTpfwGN07cn" 'False) (C1 ('MetaCons "NumTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: (C1 ('MetaCons "SymTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 String)) :+: C1 ('MetaCons "CharTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Char))))

Methods

from :: LitTy -> Rep LitTy x Source #

to :: Rep LitTy x -> LitTy Source #

Show LitTy Source # |
Instance details Defined in Clash.Core.Type Methods showsPrec :: Int -> LitTy -> ShowS Source # show :: LitTy -> String Source # showList :: [LitTy] -> ShowS Source #
Eq LitTy Source # |
Instance details Defined in Clash.Core.Type Methods (==) :: LitTy -> LitTy -> Bool Source # (/=) :: LitTy -> LitTy -> Bool Source #
Ord LitTy Source # |
Instance details Defined in Clash.Core.Type Methods compare :: LitTy -> LitTy -> Ordering Source # (<) :: LitTy -> LitTy -> Bool Source # (<=) :: LitTy -> LitTy -> Bool Source # (>) :: LitTy -> LitTy -> Bool Source # (>=) :: LitTy -> LitTy -> Bool Source # max :: LitTy -> LitTy -> LitTy Source # min :: LitTy -> LitTy -> LitTy Source #
Hashable LitTy Source # |
Instance details Defined in Clash.Core.Type Methods hashWithSalt :: Int -> LitTy -> Int Source # hash :: LitTy -> Int Source #
Pretty LitTy Source # |
Instance details Defined in Clash.Core.Pretty Methods pretty :: LitTy -> Doc ann Source # prettyList :: [LitTy] -> Doc ann Source #
type Rep LitTy Source # |

Instance details

Defined in Clash.Core.Type

type Rep LitTy = D1 ('MetaData "LitTy" "Clash.Core.Type" "clash-lib-1.8.4-CsViYhmcYd4KTpfwGN07cn" 'False) (C1 ('MetaCons "NumTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: (C1 ('MetaCons "SymTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 String)) :+: C1 ('MetaCons "CharTy" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Char))))

type Kind = Type Source #

The level above types

type KindOrType = Type Source #

Either a Kind or a Type

type KiName = Name Kind Source #

Reference to a Kind

type TyName = Name Type Source #

Reference to a Type

type TyVar = Var Type Source #

Type variable

tyView :: Type -> TypeView Source #

An easier view on types

Note [Arrow arguments]

Clash' Arrow type can either have 2 or 4 arguments, depending on who created it. By default it has two arguments: the argument type of a function, and the result type of a function.

So when do we have 4 arguments? When in Haskell/GHC land the arrow was unsaturated. This can happen in instance heads, or in the eta-reduced representation of newtypes. So what are those additional 2 arguments compared to the "normal" function type? They're the kinds of argument and result type.

coreView :: TyConMap -> Type -> Type Source #

A view on types in which newtypes are transparent, the Signal type is transparent, and type functions are evaluated to WHNF (when possible).

Strips away ALL layers. If no layers are found it returns the given type.

coreView1 :: TyConMap -> Type -> Maybe Type Source #

A view on types in which newtypes are transparent, the Signal type is transparent, and type functions are evaluated to WHNF (when possible).

Only strips away one "layer".

mkTyConTy :: TyConName -> Type Source #

Make a Type out of a TyCon

mkFunTy :: Type -> Type -> Type Source #

Make a function type of an argument and result type

mkPolyFunTy Source #

Arguments

:: Type | Result type
-> [Either TyVar Type] | List of quantifiers and function argument types
-> Type |

Make a polymorphic function type out of a result type and a list of quantifiers and function argument types

mkTyConApp :: TyConName -> [Type] -> Type Source #

Make a TyCon Application out of a TyCon and a list of argument types

splitFunTy :: TyConMap -> Type -> Maybe (Type, Type) Source #

Split a function type in an argument and result type

splitFunTys :: TyConMap -> Type -> ([Type], Type) Source #

splitFunForallTy :: Type -> ([Either TyVar Type], Type) Source #

Split a poly-function type in a: list of type-binders and argument types, and the result type

splitCoreFunForallTy :: TyConMap -> Type -> ([Either TyVar Type], Type) Source #

Split a poly-function type in a: list of type-binders and argument types, and the result type. Looks through `Signal` and type functions.

splitTyConAppM :: Type -> Maybe (TyConName, [Type]) Source #

Split a TyCon Application in a TyCon and its arguments

isPolyFunTy :: Type -> Bool Source #

Is a type a polymorphic or function type?

isPolyFunCoreTy :: TyConMap -> Type -> Bool Source #

Is a type a polymorphic or function type under `coreView1`?

isPolyTy :: Type -> Bool Source #

Is a type polymorphic?

isTypeFamilyApplication :: TyConMap -> Type -> Bool Source #

isFunTy :: TyConMap -> Type -> Bool Source #

Is a type a function type?

isClassTy :: TyConMap -> Type -> Bool Source #

applyFunTy :: TyConMap -> Type -> Type -> Type Source #

Apply a function type to an argument type and get the result type

findFunSubst :: TyConMap -> [([Type], Type)] -> [Type] -> Maybe Type Source #

reduceTypeFamily :: TyConMap -> Type -> Maybe Type Source #

isIntegerTy :: Type -> Bool Source #

normalizeType :: TyConMap -> Type -> Type Source #

Normalize a type, looking through Signals and newtypes

For example: `Signal a (Vec (6-1) (Unsigned (3+1)))` normalizes to `Vec 5 (Unsigned 4)`

varAttrs :: Var a -> [Attr Text] Source #

typeAttrs :: Type -> [Attr Text] Source #

Extract attributes from type. Will return an empty list if this is an AnnType with an empty list AND if this is not an AnnType at all.