Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides various simple ways to query and manipulate fundamental Futhark terms, such as types and values. The intent is to keep Futhark.Language.Syntax simple, and put whatever embellishments we need here.
Synopsis
- data Intrinsic
- intrinsics :: Map VName Intrinsic
- isBuiltin :: FilePath -> Bool
- isBuiltinLoc :: Located a => a -> Bool
- maxIntrinsicTag :: Int
- namesToPrimTypes :: Map Name PrimType
- qualName :: v -> QualName v
- qualify :: v -> QualName v -> QualName v
- valueType :: Value -> ValueType
- primValueType :: PrimValue -> PrimType
- leadingOperator :: Name -> BinOp
- progImports :: ProgBase f vn -> [(String, SrcLoc)]
- decImports :: DecBase f vn -> [(String, SrcLoc)]
- progModuleTypes :: ProgBase Info VName -> Set VName
- identifierReference :: String -> Maybe ((String, String, Maybe FilePath), String)
- prettyStacktrace :: Int -> [String] -> String
- progHoles :: ProgBase Info VName -> [(Loc, StructType)]
- defaultEntryPoint :: Name
- typeOf :: ExpBase Info VName -> PatType
- valBindTypeScheme :: ValBindBase Info VName -> ([TypeParamBase VName], StructType)
- valBindBound :: ValBindBase Info VName -> [VName]
- funType :: [PatBase Info VName] -> StructRetType -> StructType
- patIdents :: (Functor f, Ord vn) => PatBase f vn -> Set (IdentBase f vn)
- patNames :: (Functor f, Ord vn) => PatBase f vn -> Set vn
- patternMap :: Functor f => PatBase f VName -> Map VName (IdentBase f VName)
- patternType :: PatBase Info VName -> PatType
- patternStructType :: PatBase Info VName -> StructType
- patternParam :: PatBase Info VName -> (PName, StructType)
- patternOrderZero :: PatBase Info vn -> Bool
- uniqueness :: TypeBase shape as -> Uniqueness
- unique :: TypeBase shape as -> Bool
- aliases :: Monoid as => TypeBase shape as -> as
- diet :: TypeBase shape as -> Diet
- arrayRank :: TypeBase dim as -> Int
- arrayShape :: TypeBase dim as -> Shape dim
- orderZero :: TypeBase dim as -> Bool
- unfoldFunType :: TypeBase dim as -> ([TypeBase dim ()], TypeBase dim ())
- foldFunType :: Monoid as => [TypeBase dim pas] -> RetTypeBase dim as -> TypeBase dim as
- typeVars :: Monoid as => TypeBase dim as -> Set VName
- peelArray :: Int -> TypeBase dim as -> Maybe (TypeBase dim as)
- stripArray :: Int -> TypeBase dim as -> TypeBase dim as
- arrayOf :: Monoid as => Uniqueness -> Shape dim -> TypeBase dim as -> TypeBase dim as
- toStructural :: TypeBase dim as -> TypeBase () ()
- toStruct :: TypeBase dim as -> TypeBase dim ()
- fromStruct :: TypeBase dim as -> TypeBase dim Aliasing
- setAliases :: TypeBase dim asf -> ast -> TypeBase dim ast
- addAliases :: TypeBase dim asf -> (asf -> ast) -> TypeBase dim ast
- setUniqueness :: TypeBase dim as -> Uniqueness -> TypeBase dim as
- noSizes :: TypeBase Size as -> TypeBase () as
- traverseDims :: forall f fdim tdim als. Applicative f => (Set VName -> DimPos -> fdim -> f tdim) -> TypeBase fdim als -> f (TypeBase tdim als)
- data DimPos
- tupleRecord :: [TypeBase dim as] -> ScalarTypeBase dim as
- isTupleRecord :: TypeBase dim as -> Maybe [TypeBase dim as]
- areTupleFields :: Map Name a -> Maybe [a]
- tupleFields :: [a] -> Map Name a
- tupleFieldNames :: [Name]
- sortFields :: Map Name a -> [(Name, a)]
- sortConstrs :: Map Name a -> [(Name, a)]
- isTypeParam :: TypeParamBase vn -> Bool
- isSizeParam :: TypeParamBase vn -> Bool
- combineTypeShapes :: Monoid as => TypeBase Size as -> TypeBase Size as -> TypeBase Size as
- matchDims :: forall as m d1 d2. (Monoid as, Monad m) => ([VName] -> d1 -> d2 -> m d1) -> TypeBase d1 as -> TypeBase d2 as -> m (TypeBase d1 as)
- data NoInfo a = NoInfo
- type UncheckedType = TypeBase (Shape Name) ()
- type UncheckedTypeExp = TypeExp Name
- type UncheckedIdent = IdentBase NoInfo Name
- type UncheckedDimIndex = DimIndexBase NoInfo Name
- type UncheckedSlice = SliceBase NoInfo Name
- type UncheckedExp = ExpBase NoInfo Name
- type UncheckedModExp = ModExpBase NoInfo Name
- type UncheckedSigExp = SigExpBase NoInfo Name
- type UncheckedTypeParam = TypeParamBase Name
- type UncheckedPat = PatBase NoInfo Name
- type UncheckedValBind = ValBindBase NoInfo Name
- type UncheckedDec = DecBase NoInfo Name
- type UncheckedSpec = SpecBase NoInfo Name
- type UncheckedProg = ProgBase NoInfo Name
- type UncheckedCase = CaseBase NoInfo Name
Various
The nature of something predefined. For functions, these can
either be monomorphic or overloaded. An overloaded builtin is a
list valid types it can be instantiated with, to the parameter and
result type, with Nothing
representing the overloaded parameter
type.
isBuiltinLoc :: Located a => a -> Bool Source #
Is the position of this thing builtin as per isBuiltin
? Things
without location are considered not built-in.
maxIntrinsicTag :: Int Source #
The largest tag used by an intrinsic - this can be used to
determine whether a VName
refers to an intrinsic or a user-defined name.
namesToPrimTypes :: Map Name PrimType Source #
Names of primitive types to types. This is only valid if no shadowing is going on, but useful for tools.
qualify :: v -> QualName v -> QualName v Source #
Add another qualifier (at the head) to a qualified name.
primValueType :: PrimValue -> PrimType Source #
The type of a basic value.
leadingOperator :: Name -> BinOp Source #
Given an operator name, return the operator that determines its syntactical properties.
progImports :: ProgBase f vn -> [(String, SrcLoc)] Source #
The modules imported by a Futhark program.
decImports :: DecBase f vn -> [(String, SrcLoc)] Source #
The modules imported by a single declaration.
progModuleTypes :: ProgBase Info VName -> Set VName Source #
The set of module types used in any exported (non-local) declaration.
identifierReference :: String -> Maybe ((String, String, Maybe FilePath), String) Source #
Extract a leading ((name, namespace, file), remainder)
from a
documentation comment string. These are formatted as
`name`@namespace[@file]. Let us hope that this pattern does not occur
anywhere else.
prettyStacktrace :: Int -> [String] -> String Source #
Given a list of strings representing entries in the stack trace and the index of the frame to highlight, produce a final newline-terminated string for showing to the user. This string should also be preceded by a newline. The most recent stack frame must come first in the list.
progHoles :: ProgBase Info VName -> [(Loc, StructType)] Source #
Find instances of typed holes in the program.
defaultEntryPoint :: Name Source #
The name of the default program entry point (main
).
Queries on expressions
typeOf :: ExpBase Info VName -> PatType Source #
The type of an Futhark term. The aliasing will refer to itself, if the term is a non-tuple-typed variable.
valBindTypeScheme :: ValBindBase Info VName -> ([TypeParamBase VName], StructType) Source #
The type scheme of a value binding, comprising the type parameters and the actual type.
valBindBound :: ValBindBase Info VName -> [VName] Source #
The names that are brought into scope by this value binding (not including its own parameter names, but including any existential sizes).
funType :: [PatBase Info VName] -> StructRetType -> StructType Source #
The type of a function with the given parameters and return type.
Queries on patterns and params
patIdents :: (Functor f, Ord vn) => PatBase f vn -> Set (IdentBase f vn) Source #
The set of identifiers bound in a pattern.
patNames :: (Functor f, Ord vn) => PatBase f vn -> Set vn Source #
The set of names bound in a pattern.
patternMap :: Functor f => PatBase f VName -> Map VName (IdentBase f VName) Source #
A mapping from names bound in a map to their identifier.
patternStructType :: PatBase Info VName -> StructType Source #
The type matched by the pattern, including shape declarations if present.
patternParam :: PatBase Info VName -> (PName, StructType) Source #
When viewed as a function parameter, does this pattern correspond to a named parameter of some type?
patternOrderZero :: PatBase Info vn -> Bool Source #
patternOrderZero pat
is True
if all of the types in the given pattern
have order 0.
Queries on types
uniqueness :: TypeBase shape as -> Uniqueness Source #
Return the uniqueness of a type.
aliases :: Monoid as => TypeBase shape as -> as Source #
Return the set of all variables mentioned in the aliasing of a type.
diet :: TypeBase shape as -> Diet Source #
diet t
returns a description of how a function parameter of
type t
might consume its argument.
arrayRank :: TypeBase dim as -> 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 :: TypeBase dim as -> Shape dim Source #
Return the shape of a type - for non-arrays, this is mempty
.
orderZero :: TypeBase dim as -> Bool Source #
orderZero t
is True
if the argument type has order 0, i.e., it is not
a function type, does not contain a function type as a subcomponent, and may
not be instantiated with a function type.
unfoldFunType :: TypeBase dim as -> ([TypeBase dim ()], TypeBase dim ()) Source #
Extract the parameter types and return type from a type. If the type is not an arrow type, the list of parameter types is empty.
foldFunType :: Monoid as => [TypeBase dim pas] -> RetTypeBase dim as -> TypeBase dim as Source #
foldFunType ts ret
creates a function type (Arrow
) that takes
ts
as parameters and returns ret
.
Operations on types
peelArray :: Int -> TypeBase dim as -> Maybe (TypeBase dim as) 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 dim as -> TypeBase dim as 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.
arrayOf :: Monoid as => Uniqueness -> Shape dim -> TypeBase dim as -> TypeBase dim as Source #
arrayOf u s t
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
.
toStructural :: TypeBase dim as -> TypeBase () () Source #
Convert any type to one that has rank information, no alias information, and no embedded names.
fromStruct :: TypeBase dim as -> TypeBase dim Aliasing Source #
Replace no aliasing with an empty alias set.
setAliases :: TypeBase dim asf -> ast -> TypeBase dim ast Source #
t `setAliases` als
returns t
, but with als
substituted for
any already present aliasing.
addAliases :: TypeBase dim asf -> (asf -> ast) -> TypeBase dim ast Source #
t `addAliases` f
returns t
, but with any already present
aliasing replaced by f
applied to that aliasing.
setUniqueness :: TypeBase dim as -> Uniqueness -> TypeBase dim as Source #
Set the uniqueness attribute of a type. If the type is a record or sum type, the uniqueness of its components will be modified.
noSizes :: TypeBase Size as -> TypeBase () as Source #
Change the shape of a type to be just the rank.
traverseDims :: forall f fdim tdim als. Applicative f => (Set VName -> DimPos -> fdim -> f tdim) -> TypeBase fdim als -> f (TypeBase tdim als) Source #
Perform a traversal (possibly including replacement) on sizes that are parameters in a function type, but also including the type immediately passed to the function. Also passes along a set of the parameter names inside the type that have come in scope at the occurrence of the dimension.
Where does this dimension occur?
PosImmediate | Immediately in the argument to |
PosParam | In a function parameter type. |
PosReturn | In a function return type. |
tupleRecord :: [TypeBase dim as] -> ScalarTypeBase dim as Source #
Create a record type corresponding to a tuple with the given element types.
isTupleRecord :: TypeBase dim as -> Maybe [TypeBase dim as] Source #
Does this type corespond to a tuple? If so, return the elements of that tuple.
tupleFields :: [a] -> Map Name a Source #
Construct a record map corresponding to a tuple.
tupleFieldNames :: [Name] Source #
Increasing field names for a tuple (starts at 0).
sortFields :: Map Name a -> [(Name, a)] Source #
Sort fields by their name; taking care to sort numeric fields by their numeric value. This ensures that tuples and tuple-like records match.
sortConstrs :: Map Name a -> [(Name, a)] Source #
Sort the constructors of a sum type in some well-defined (but not otherwise significant) manner.
isTypeParam :: TypeParamBase vn -> Bool Source #
Is this a TypeParamType
?
isSizeParam :: TypeParamBase vn -> Bool Source #
Is this a TypeParamDim
?
combineTypeShapes :: Monoid as => TypeBase Size as -> TypeBase Size as -> TypeBase Size as Source #
Combine the shape information of types as much as possible. The first argument is the orignal type and the second is the type of the transformed expression. This is necessary since the original type may contain additional information (e.g., shape restrictions) from the user given annotation.
matchDims :: forall as m d1 d2. (Monoid as, Monad m) => ([VName] -> d1 -> d2 -> m d1) -> TypeBase d1 as -> TypeBase d2 as -> m (TypeBase d1 as) Source #
Match the dimensions of otherwise assumed-equal types. The combining function is also passed the names bound within the type (from named parameters or return types).
Values of these types are produces by the parser. They use unadorned names and have no type information, apart from that which is syntactically required.
No information functor. Usually used for placeholder type- or aliasing information.
Instances
type UncheckedType = TypeBase (Shape Name) () Source #
A type with no aliasing information but shape annotations.
type UncheckedTypeExp = TypeExp Name Source #
An expression with no type annotations.
type UncheckedDimIndex = DimIndexBase NoInfo Name Source #
An index with no type annotations.
type UncheckedModExp = ModExpBase NoInfo Name Source #
A module expression with no type annotations.
type UncheckedSigExp = SigExpBase NoInfo Name Source #
A module type expression with no type annotations.
type UncheckedTypeParam = TypeParamBase Name Source #
A type parameter with no type annotations.
type UncheckedValBind = ValBindBase NoInfo Name Source #
A function declaration with no type annotations.