futhark-0.25.27: An optimising compiler for a functional, array-oriented language.

Safe Haskell | Safe-Inferred
Language | GHC2021

Futhark.IR.Prop.Types

Contents

- Abbreviations
- The Typed typeclass

Description

Functions for inspecting and constructing various types.

Synopsis

- rankShaped :: ArrayShape shape => TypeBase shape u -> TypeBase Rank u
- arrayRank :: ArrayShape shape => TypeBase shape u -> Int
- arrayShape :: ArrayShape shape => TypeBase shape u -> shape
- setArrayShape :: ArrayShape newshape => TypeBase oldshape u -> newshape -> TypeBase newshape u
- isEmptyArray :: Type -> Maybe (PrimType, Shape)
- existential :: ExtType -> Bool
- uniqueness :: TypeBase shape Uniqueness -> Uniqueness
- unique :: TypeBase shape Uniqueness -> Bool
- staticShapes :: [TypeBase Shape u] -> [TypeBase ExtShape u]
- staticShapes1 :: TypeBase Shape u -> TypeBase ExtShape u
- primType :: TypeBase shape u -> Bool
- isAcc :: TypeBase shape u -> Bool
- arrayOf :: ArrayShape shape => TypeBase shape u_unused -> shape -> u -> TypeBase shape u
- arrayOfRow :: ArrayShape (ShapeBase d) => TypeBase (ShapeBase d) NoUniqueness -> d -> TypeBase (ShapeBase d) NoUniqueness
- arrayOfShape :: Type -> Shape -> Type
- setOuterSize :: ArrayShape (ShapeBase d) => TypeBase (ShapeBase d) u -> d -> TypeBase (ShapeBase d) u
- setDimSize :: ArrayShape (ShapeBase d) => Int -> TypeBase (ShapeBase d) u -> d -> TypeBase (ShapeBase d) u
- setOuterDim :: ShapeBase d -> d -> ShapeBase d
- setOuterDims :: ShapeBase d -> Int -> ShapeBase d -> ShapeBase d
- setDim :: Int -> ShapeBase d -> d -> ShapeBase d
- setArrayDims :: TypeBase oldshape u -> [SubExp] -> TypeBase Shape u
- peelArray :: Int -> TypeBase Shape u -> Maybe (TypeBase Shape u)
- stripArray :: Int -> TypeBase Shape u -> TypeBase Shape u
- arrayDims :: TypeBase Shape u -> [SubExp]
- arrayExtDims :: TypeBase ExtShape u -> [ExtSize]
- shapeSize :: Int -> Shape -> SubExp
- arraySize :: Int -> TypeBase Shape u -> SubExp
- arraysSize :: Int -> [TypeBase Shape u] -> SubExp
- elemType :: TypeBase shape u -> PrimType
- rowType :: TypeBase Shape u -> TypeBase Shape u
- transposeType :: Type -> Type
- rearrangeType :: [Int] -> Type -> Type
- mapOnExtType :: Monad m => (SubExp -> m SubExp) -> TypeBase ExtShape u -> m (TypeBase ExtShape u)
- mapOnType :: Monad m => (SubExp -> m SubExp) -> TypeBase Shape u -> m (TypeBase Shape u)
- diet :: TypeBase shape Uniqueness -> Diet
- subtypeOf :: (Ord u, ArrayShape shape) => TypeBase shape u -> TypeBase shape u -> Bool
- subtypesOf :: (Ord u, ArrayShape shape) => [TypeBase shape u] -> [TypeBase shape u] -> Bool
- toDecl :: TypeBase shape NoUniqueness -> Uniqueness -> TypeBase shape Uniqueness
- fromDecl :: TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
- isExt :: Ext a -> Maybe Int
- isFree :: Ext a -> Maybe a
- extractShapeContext :: [TypeBase ExtShape u] -> [[a]] -> [a]
- shapeContext :: [TypeBase ExtShape u] -> Set Int
- hasStaticShape :: TypeBase ExtShape u -> Maybe (TypeBase Shape u)
- generaliseExtTypes :: [TypeBase ExtShape u] -> [TypeBase ExtShape u] -> [TypeBase ExtShape u]
- existentialiseExtTypes :: [VName] -> [ExtType] -> [ExtType]
- shapeExtMapping :: [TypeBase ExtShape u] -> [TypeBase Shape u1] -> Map Int SubExp
- int8 :: PrimType
- int16 :: PrimType
- int32 :: PrimType
- int64 :: PrimType
- float32 :: PrimType
- float64 :: PrimType
- class Typed t where
  - typeOf :: t -> Type
- class DeclTyped t where
  - declTypeOf :: t -> DeclType
- class FixExt t => ExtTyped t where
  - extTypeOf :: t -> ExtType
- class FixExt t => DeclExtTyped t where
  - declExtTypeOf :: t -> DeclExtType
- class FixExt t where
  - fixExt :: Int -> SubExp -> t -> t
  - mapExt :: (Int -> Int) -> t -> t

# Documentation

rankShaped :: ArrayShape shape => TypeBase shape u -> TypeBase Rank u Source #

Remove shape information from a type.

arrayRank :: ArrayShape shape => TypeBase shape u -> Int Source #

Return the dimensionality of a type. For non-arrays, this is zero. For a one-dimensional array it is one, for a two-dimensional it is two, and so forth.

arrayShape :: ArrayShape shape => TypeBase shape u -> shape Source #

Return the shape of a type - for non-arrays, this is the `mempty`.

setArrayShape :: ArrayShape newshape => TypeBase oldshape u -> newshape -> TypeBase newshape u Source #

Set the shape of an array. If the given type is not an array, return the type unchanged.

isEmptyArray :: Type -> Maybe (PrimType, Shape) Source #

If the array is statically an empty array (meaning any dimension is a static zero), return the element type and the shape.

existential :: ExtType -> Bool Source #

True if the given type has a dimension that is existentially sized.

uniqueness :: TypeBase shape Uniqueness -> Uniqueness Source #

Return the uniqueness of a type.

unique :: TypeBase shape Uniqueness -> Bool Source #

`unique t` is `True` if the type of the argument is unique.

staticShapes :: [TypeBase Shape u] -> [TypeBase ExtShape u] Source #

Convert types with non-existential shapes to types with existential shapes. Only the representation is changed, so all the shapes will be `Free`.

staticShapes1 :: TypeBase Shape u -> TypeBase ExtShape u Source #

As `staticShapes`, but on a single type.

primType :: TypeBase shape u -> Bool Source #

A type is a primitive type if it is not an array or memory block.

isAcc :: TypeBase shape u -> Bool Source #

Is this an accumulator?

arrayOf :: ArrayShape shape => TypeBase shape u_unused -> shape -> u -> TypeBase shape u Source #

`arrayOf t s u` constructs an array type. The convenience compared to using the `Array` constructor directly is that `t` can itself be an array. If `t` is an `n`-dimensional array, and `s` is a list of length `n`, the resulting type is of an `n+m` dimensions. The uniqueness of the new array will be `u`, no matter the uniqueness of `t`. If the shape `s` has rank 0, then the `t` will be returned, although if it is an array, with the uniqueness changed to `u`.

arrayOfRow :: ArrayShape (ShapeBase d) => TypeBase (ShapeBase d) NoUniqueness -> d -> TypeBase (ShapeBase d) NoUniqueness Source #

Construct an array whose rows are the given type, and the outer size is the given dimension. This is just a convenient wrapper around `arrayOf`.

arrayOfShape :: Type -> Shape -> Type Source #

Construct an array whose rows are the given type, and the outer size is the given `Shape`. This is just a convenient wrapper around `arrayOf`.

setOuterSize :: ArrayShape (ShapeBase d) => TypeBase (ShapeBase d) u -> d -> TypeBase (ShapeBase d) u Source #

Replace the size of the outermost dimension of an array. If the given type is not an array, it is returned unchanged.

setDimSize :: ArrayShape (ShapeBase d) => Int -> TypeBase (ShapeBase d) u -> d -> TypeBase (ShapeBase d) u Source #

Replace the size of the given dimension of an array. If the given type is not an array, it is returned unchanged.

setOuterDim :: ShapeBase d -> d -> ShapeBase d Source #

Replace the outermost dimension of an array shape.

setOuterDims :: ShapeBase d -> Int -> ShapeBase d -> ShapeBase d Source #

Replace some outermost dimensions of an array shape.

setDim :: Int -> ShapeBase d -> d -> ShapeBase d Source #

Replace the specified dimension of an array shape.

setArrayDims :: TypeBase oldshape u -> [SubExp] -> TypeBase Shape u Source #

Set the dimensions of an array. If the given type is not an array, return the type unchanged.

peelArray :: Int -> TypeBase Shape u -> Maybe (TypeBase Shape u) Source #

`peelArray n t` returns the type resulting from peeling the first `n` array dimensions from `t`. Returns `Nothing` if `t` has less than `n` dimensions.

stripArray :: Int -> TypeBase Shape u -> TypeBase Shape u Source #

`stripArray n t` removes the `n` outermost layers of the array. Essentially, it is the type of indexing an array of type `t` with `n` indexes.

arrayDims :: TypeBase Shape u -> [SubExp] Source #

Return the dimensions of a type - for non-arrays, this is the empty list.

arrayExtDims :: TypeBase ExtShape u -> [ExtSize] Source #

Return the existential dimensions of a type - for non-arrays, this is the empty list.

shapeSize :: Int -> Shape -> SubExp Source #

Return the size of the given dimension. If the dimension does not exist, the zero constant is returned.

arraySize :: Int -> TypeBase Shape u -> SubExp Source #

Return the size of the given dimension. If the dimension does not exist, the zero constant is returned.

arraysSize :: Int -> [TypeBase Shape u] -> SubExp Source #

Return the size of the given dimension in the first element of the given type list. If the dimension does not exist, or no types are given, the zero constant is returned.

elemType :: TypeBase shape u -> PrimType Source #

Returns the bottommost type of an array. For `[][]i32`, this would be `i32`. If the given type is not an array, it is returned.

rowType :: TypeBase Shape u -> TypeBase Shape u Source #

Return the immediate row-type of an array. For `[[int]]`, this would be `[int]`.

transposeType :: Type -> Type Source #

Swap the two outer dimensions of the type.

rearrangeType :: [Int] -> Type -> Type Source #

Rearrange the dimensions of the type. If the length of the permutation does not match the rank of the type, the permutation will be extended with identity.

mapOnExtType :: Monad m => (SubExp -> m SubExp) -> TypeBase ExtShape u -> m (TypeBase ExtShape u) Source #

Transform any `SubExp`s in the type.

mapOnType :: Monad m => (SubExp -> m SubExp) -> TypeBase Shape u -> m (TypeBase Shape u) Source #

Transform any `SubExp`s in the type.

diet :: TypeBase shape Uniqueness -> Diet Source #

`diet t` returns a description of how a function parameter of type `t` might consume its argument.

subtypeOf :: (Ord u, ArrayShape shape) => TypeBase shape u -> TypeBase shape u -> Bool Source #

`x `subtypeOf` y` is true if `x` is a subtype of `y` (or equal to `y`), meaning `x` is valid whenever `y` is.

subtypesOf :: (Ord u, ArrayShape shape) => [TypeBase shape u] -> [TypeBase shape u] -> Bool Source #

`xs `subtypesOf` ys` is true if `xs` is the same size as `ys`, and each element in `xs` is a subtype of the corresponding element in `ys`..

toDecl :: TypeBase shape NoUniqueness -> Uniqueness -> TypeBase shape Uniqueness Source #

Add the given uniqueness information to the types.

fromDecl :: TypeBase shape Uniqueness -> TypeBase shape NoUniqueness Source #

Remove uniqueness information from the type.

isExt :: Ext a -> Maybe Int Source #

If an existential, then return its existential index.

isFree :: Ext a -> Maybe a Source #

If a known size, then return that size.

extractShapeContext :: [TypeBase ExtShape u] -> [[a]] -> [a] Source #

Given the existential return type of a function, and the shapes of the values returned by the function, return the existential shape context. That is, those sizes that are existential in the return type.

shapeContext :: [TypeBase ExtShape u] -> Set Int Source #

The `Ext` integers used for existential sizes in the given types.

hasStaticShape :: TypeBase ExtShape u -> Maybe (TypeBase Shape u) Source #

If all dimensions of the given `ExtShape` are statically known, change to the corresponding `Shape`.

generaliseExtTypes :: [TypeBase ExtShape u] -> [TypeBase ExtShape u] -> [TypeBase ExtShape u] Source #

Given two lists of `ExtType`s of the same length, return a list of `ExtType`s that is a subtype of the two operands.

existentialiseExtTypes :: [VName] -> [ExtType] -> [ExtType] Source #

Given a list of `ExtType`s and a list of "forbidden" names, modify the dimensions of the `ExtType`s such that they are `Ext` where they were previously `Free` with a variable in the set of forbidden names.

shapeExtMapping :: [TypeBase ExtShape u] -> [TypeBase Shape u1] -> Map Int SubExp Source #

Produce a mapping for the dimensions context.

# Abbreviations

int8 :: PrimType Source #

    IntType Int8

int16 :: PrimType Source #

    IntType Int16

int32 :: PrimType Source #

    IntType Int32

int64 :: PrimType Source #

    IntType Int64

float32 :: PrimType Source #

    FloatType Float32

float64 :: PrimType Source #

    FloatType Float64

# The Typed typeclass

class Typed t where Source #

Typeclass for things that contain `Type`s.

Methods

typeOf :: t -> Type Source #

#### Instances

Instances details

Typed DeclType Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods typeOf :: DeclType -> Type Source #
Typed Ident Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods typeOf :: Ident -> Type Source #
Typed Type Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods typeOf :: Type -> Type Source #
ASTRep rep => Typed (Entry rep) Source # |
Instance details Defined in Futhark.Analysis.SymbolTable Methods typeOf :: Entry rep -> Type Source #
RepTypes rep => Typed (NameInfo rep) Source # |
Instance details Defined in Futhark.IR.Prop.Scope Methods typeOf :: NameInfo rep -> Type Source #
Typed dec => Typed (Param dec) Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods typeOf :: Param dec -> Type Source #
Typed dec => Typed (PatElem dec) Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods typeOf :: PatElem dec -> Type Source #
Typed b => Typed (a, b) Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods typeOf :: (a, b) -> Type Source #
Typed (MemInfo SubExp NoUniqueness ret) Source # |
Instance details Defined in Futhark.IR.Mem Methods typeOf :: MemInfo SubExp NoUniqueness ret -> Type Source #
Typed (MemInfo SubExp Uniqueness ret) Source # |
Instance details Defined in Futhark.IR.Mem Methods typeOf :: MemInfo SubExp Uniqueness ret -> Type Source #

class DeclTyped t where Source #

Typeclass for things that contain `DeclType`s.

Methods

declTypeOf :: t -> DeclType Source #

#### Instances

Instances details

DeclTyped DeclType Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods declTypeOf :: DeclType -> DeclType Source #
DeclTyped dec => DeclTyped (Param dec) Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods declTypeOf :: Param dec -> DeclType Source #
DeclTyped (MemInfo SubExp Uniqueness ret) Source # |
Instance details Defined in Futhark.IR.Mem Methods declTypeOf :: MemInfo SubExp Uniqueness ret -> DeclType Source #

class FixExt t => ExtTyped t where Source #

Typeclass for things that contain `ExtType`s.

Methods

extTypeOf :: t -> ExtType Source #

#### Instances

Instances details

ExtTyped DeclExtType Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods extTypeOf :: DeclExtType -> ExtType Source #
ExtTyped ExtType Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods extTypeOf :: ExtType -> ExtType Source #
FixExt ret => ExtTyped (MemInfo ExtSize NoUniqueness ret) Source # |
Instance details Defined in Futhark.IR.Mem Methods extTypeOf :: MemInfo ExtSize NoUniqueness ret -> ExtType Source #
FixExt ret => ExtTyped (MemInfo ExtSize Uniqueness ret) Source # |
Instance details Defined in Futhark.IR.Mem Methods extTypeOf :: MemInfo ExtSize Uniqueness ret -> ExtType Source #

class FixExt t => DeclExtTyped t where Source #

Typeclass for things that contain `DeclExtType`s.

Methods

declExtTypeOf :: t -> DeclExtType Source #

#### Instances

Instances details

DeclExtTyped DeclExtType Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods declExtTypeOf :: DeclExtType -> DeclExtType Source #
FixExt ret => DeclExtTyped (MemInfo ExtSize Uniqueness ret) Source # |
Instance details Defined in Futhark.IR.Mem Methods declExtTypeOf :: MemInfo ExtSize Uniqueness ret -> DeclExtType Source #

class FixExt t where Source #

Something with an existential context that can be (partially) fixed.

Methods

fixExt :: Int -> SubExp -> t -> t Source #

Fix the given existentional variable to the indicated free value.

mapExt :: (Int -> Int) -> t -> t Source #

Map a function onto any existential.

#### Instances

Instances details

FixExt MemReturn Source # |
Instance details Defined in Futhark.IR.Mem Methods fixExt :: Int -> SubExp -> MemReturn -> MemReturn Source # mapExt :: (Int -> Int) -> MemReturn -> MemReturn Source #
FixExt ExtSize Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods fixExt :: Int -> SubExp -> ExtSize -> ExtSize Source # mapExt :: (Int -> Int) -> ExtSize -> ExtSize Source #
FixExt () Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods fixExt :: Int -> SubExp -> () -> () Source # mapExt :: (Int -> Int) -> () -> () Source #
FixExt d => FixExt (ShapeBase d) Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods fixExt :: Int -> SubExp -> ShapeBase d -> ShapeBase d Source # mapExt :: (Int -> Int) -> ShapeBase d -> ShapeBase d Source #
FixExt a => FixExt [a] Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods fixExt :: Int -> SubExp -> [a] -> [a] Source # mapExt :: (Int -> Int) -> [a] -> [a] Source #
(FixExt shape, ArrayShape shape) => FixExt (TypeBase shape u) Source # |
Instance details Defined in Futhark.IR.Prop.Types Methods fixExt :: Int -> SubExp -> TypeBase shape u -> TypeBase shape u Source # mapExt :: (Int -> Int) -> TypeBase shape u -> TypeBase shape u Source #
FixExt ret => FixExt (MemInfo ExtSize u ret) Source # |
Instance details Defined in Futhark.IR.Mem Methods fixExt :: Int -> SubExp -> MemInfo ExtSize u ret -> MemInfo ExtSize u ret Source # mapExt :: (Int -> Int) -> MemInfo ExtSize u ret -> MemInfo ExtSize u ret Source #