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

Safe Haskell | Safe-Inferred
Language | GHC2021

Language.Futhark.Traversals

Description

Functions for generic traversals across Futhark syntax trees. The motivation for this module came from dissatisfaction with rewriting the same trivial tree recursions for every module. A possible alternative would be to use normal "Scrap your boilerplate"-techniques, but these are rejected for two reasons:

- They are too slow.
- More importantly, they do not tell you whether you have missed some cases.

Instead, this module defines various traversals of the Futhark syntax tree. The implementation is rather tedious, but the interface is easy to use.

A traversal of the Futhark syntax tree is expressed as a record of functions expressing the operations to be performed on the various types of nodes.

Synopsis

- data ASTMapper m = ASTMapper {
  - mapOnExp :: ExpBase Info VName -> m (ExpBase Info VName)
  - mapOnName :: QualName VName -> m (QualName VName)
  - mapOnStructType :: StructType -> m StructType
  - mapOnParamType :: ParamType -> m ParamType
  - mapOnResRetType :: ResRetType -> m ResRetType
  }
- class ASTMappable x where
  - astMap :: Monad m => ASTMapper m -> x -> m x
- identityMapper :: Monad m => ASTMapper m
- bareExp :: ExpBase Info VName -> ExpBase NoInfo VName

# Documentation

data ASTMapper m Source #

Express a monad mapping operation on a syntax node. Each element of this structure expresses the operation to be performed on a given child.

Constructors

ASTMapper |

Fields

- mapOnExp :: ExpBase Info VName -> m (ExpBase Info VName)
- mapOnName :: QualName VName -> m (QualName VName)
- mapOnStructType :: StructType -> m StructType
- mapOnParamType :: ParamType -> m ParamType
- mapOnResRetType :: ResRetType -> m ResRetType

class ASTMappable x where Source #

The class of things that we can map an `ASTMapper` across.

Methods

astMap :: Monad m => ASTMapper m -> x -> m x Source #

Map a monadic action across the immediate children of an object. Importantly, the `astMap` action is not invoked for the object itself, and the mapping does not descend recursively into subexpressions. The mapping is done left-to-right.

#### Instances

Instances details

ASTMappable AppRes Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> AppRes -> m AppRes Source #
ASTMappable ParamType Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> ParamType -> m ParamType Source #
ASTMappable ResRetType Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> ResRetType -> m ResRetType Source #
ASTMappable StructType Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> StructType -> m StructType Source #
ASTMappable a => ASTMappable (NonEmpty a) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> NonEmpty a -> m (NonEmpty a) Source #
ASTMappable a => ASTMappable (Info a) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> Info a -> m (Info a) Source #
ASTMappable (SizeExp (ExpBase Info VName)) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> SizeExp (ExpBase Info VName) -> m (SizeExp (ExpBase Info VName)) Source #
ASTMappable a => ASTMappable [a] Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> [a] -> m [a] Source #
ASTMappable (AppExpBase Info VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> AppExpBase Info VName -> m (AppExpBase Info VName) Source #
ASTMappable (CaseBase Info VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> CaseBase Info VName -> m (CaseBase Info VName) Source #
ASTMappable (DimIndexBase Info VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> DimIndexBase Info VName -> m (DimIndexBase Info VName) Source #
ASTMappable (ExpBase Info VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> ExpBase Info VName -> m (ExpBase Info VName) Source #
ASTMappable (FieldBase Info VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> FieldBase Info VName -> m (FieldBase Info VName) Source #
ASTMappable (LoopFormBase Info VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> LoopFormBase Info VName -> m (LoopFormBase Info VName) Source #
ASTMappable (LoopInitBase Info VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> LoopInitBase Info VName -> m (LoopInitBase Info VName) Source #
ASTMappable (TypeArgExp (ExpBase Info VName) VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> TypeArgExp (ExpBase Info VName) VName -> m (TypeArgExp (ExpBase Info VName) VName) Source #
ASTMappable (TypeBase Size Uniqueness) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> TypeBase Size Uniqueness -> m (TypeBase Size Uniqueness) Source #
ASTMappable (TypeExp (ExpBase Info VName) VName) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> TypeExp (ExpBase Info VName) VName -> m (TypeExp (ExpBase Info VName) VName) Source #
(ASTMappable a, ASTMappable b) => ASTMappable (a, b) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> (a, b) -> m (a, b) Source #
ASTMappable (PatBase Info VName ParamType) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> PatBase Info VName ParamType -> m (PatBase Info VName ParamType) Source #
ASTMappable (PatBase Info VName StructType) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> PatBase Info VName StructType -> m (PatBase Info VName StructType) Source #
(ASTMappable a, ASTMappable b, ASTMappable c) => ASTMappable (a, b, c) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> (a, b, c) -> m (a, b, c) Source #
ASTMappable (IdentBase Info VName StructType) Source # |
Instance details Defined in Language.Futhark.Traversals Methods astMap :: Monad m => ASTMapper m -> IdentBase Info VName StructType -> m (IdentBase Info VName StructType) Source #

identityMapper :: Monad m => ASTMapper m Source #

An `ASTMapper` that just leaves its input unchanged.

bareExp :: ExpBase Info VName -> ExpBase NoInfo VName Source #

Remove all annotations from an expression, but retain the name/scope information.