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

Safe HaskellNone
LanguageHaskell2010

Futhark.Representation.AST.Traversals

Contents

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.

The Futhark.Transform.Rename module is a simple example of how to use this facility.

Synopsis

Mapping

data Mapper flore tlore 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

Mapper 

Fields

identityMapper :: Monad m => Mapper lore lore m Source #

A mapper that simply returns the tree verbatim.

mapExpM :: (Applicative m, Monad m) => Mapper flore tlore m -> Exp flore -> m (Exp tlore) Source #

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

mapExp :: Mapper flore tlore Identity -> Exp flore -> Exp tlore Source #

Like mapExp, but in the Identity monad.

mapOnType :: Monad m => (SubExp -> m SubExp) -> Type -> m Type Source #

mapOnLoopForm :: Monad m => Mapper flore tlore m -> LoopForm flore -> m (LoopForm tlore) Source #

mapOnExtType :: Monad m => Mapper flore tlore m -> TypeBase ExtShape u -> m (TypeBase ExtShape u) Source #

Walking

data Walker lore m Source #

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

Constructors

Walker 

Fields

identityWalker :: Monad m => Walker lore m Source #

A no-op traversal.

walkExpM :: Monad m => Walker lore m -> Exp lore -> m () Source #

As walkBodyM, but for expressions.