| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Language.Futhark.Prop
Description
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
- intrinsicVar :: Name -> VName
- maxIntrinsicTag :: Int
- isIntrinsic :: VName -> Bool
- namesToPrimTypes :: Map Name PrimType
- qualName :: v -> QualName v
- qualify :: v -> QualName v -> QualName v
- primValueType :: PrimValue -> PrimType
- leadingOperator :: Name -> BinOp
- progImports :: forall (f :: Type -> Type) vn. ProgBase f vn -> [(String, Loc)]
- decImports :: forall (f :: Type -> Type) vn. DecBase f vn -> [(String, Loc)]
- progModuleTypes :: ProgBase Info VName -> Set VName
- identifierReference :: String -> Maybe ((String, String, Maybe FilePath), String)
- prettyStacktrace :: Int -> [Text] -> Text
- progHoles :: ProgBase Info VName -> [(Loc, StructType)]
- defaultEntryPoint :: Name
- paramName :: PName -> Maybe VName
- anySize :: Int -> Size
- isAnySize :: Size -> Maybe Int
- setApplyLoc :: SrcLoc -> Exp -> Exp
- typeOf :: ExpBase Info VName -> StructType
- valBindTypeScheme :: ValBindBase Info VName -> ([TypeParamBase VName], StructType)
- valBindBound :: ValBindBase Info VName -> [VName]
- funType :: [Pat (TypeBase d Diet)] -> RetTypeBase d Freshness -> TypeBase d NoMode
- stripExp :: Exp -> Maybe Exp
- subExps :: Exp -> [Exp]
- similarExps :: Exp -> Exp -> Maybe [(Exp, Exp)]
- sameExp :: Exp -> Exp -> Bool
- patIdents :: forall (f :: Type -> Type) vn t. PatBase f vn t -> [IdentBase f vn t]
- patNames :: Pat t -> [VName]
- patternMap :: Pat t -> [(VName, t)]
- patternType :: Pat (TypeBase d o) -> TypeBase d o
- patternStructType :: Pat (TypeBase Size o) -> StructType
- patternParam :: Pat (TypeBase d Diet) -> (PName, Diet, TypeBase d NoMode)
- patternOrderZero :: Pat (TypeBase d o) -> Bool
- freshness :: TypeBase shape Freshness -> Freshness
- fresh :: TypeBase shape Freshness -> Bool
- diet :: TypeBase shape Diet -> Diet
- arrayRank :: TypeBase d o -> Int
- arrayShape :: TypeBase dim o -> Shape dim
- orderZero :: TypeBase dim o -> Bool
- unfoldFunType :: TypeBase dim o -> ([(PName, TypeBase dim Diet)], TypeBase dim NoMode)
- foldFunType :: [TypeBase d Diet] -> RetTypeBase d Freshness -> TypeBase d NoMode
- typeQualVars :: TypeBase dim o -> [QualName VName]
- typeVars :: TypeBase dim o -> Set VName
- isAccType :: TypeBase d o -> Maybe (TypeBase d NoMode)
- peelArray :: Int -> TypeBase dim o -> Maybe (TypeBase dim o)
- stripArray :: Int -> TypeBase dim o -> TypeBase dim o
- arrayOf :: Shape dim -> TypeBase dim NoMode -> TypeBase dim NoMode
- arrayOfWithAliases :: o -> Shape dim -> TypeBase dim o' -> TypeBase dim o
- toStructural :: TypeBase dim o -> TypeBase () NoMode
- toStruct :: TypeBase dim o -> TypeBase dim NoMode
- toRes :: Freshness -> TypeBase Size o -> ResType
- toParam :: Diet -> TypeBase Size o -> ParamType
- resToParam :: ResType -> ParamType
- paramToRes :: ParamType -> ResType
- toResRet :: Freshness -> RetTypeBase Size o -> ResRetType
- setMode :: TypeBase dim o1 -> o2 -> TypeBase dim o2
- noSizes :: TypeBase Size o -> TypeBase () o
- traverseDims :: Applicative f => (Set VName -> DimPos -> fdim -> f tdim) -> TypeBase fdim o -> f (TypeBase tdim o)
- data DimPos
- tupleRecord :: [TypeBase dim o] -> ScalarTypeBase dim o
- isTupleRecord :: TypeBase dim o -> Maybe [TypeBase dim o]
- 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
- matchDims :: (Monoid o, Monad m) => ([VName] -> d1 -> d2 -> m d1) -> TypeBase d1 o -> TypeBase d2 o -> m (TypeBase d1 o)
- type UncheckedType = TypeBase (Shape Name) ()
- type UncheckedTypeExp = TypeExp UncheckedExp Name
- type UncheckedIdent = IdentBase (NoInfo :: k -> Type) Name
- type UncheckedDimIndex = DimIndexBase (NoInfo :: Type -> Type) Name
- type UncheckedSlice = SliceBase (NoInfo :: Type -> Type) Name
- type UncheckedExp = ExpBase (NoInfo :: Type -> Type) Name
- type UncheckedModExp = ModExpBase (NoInfo :: Type -> Type) Name
- type UncheckedModTypeExp = ModTypeExpBase (NoInfo :: Type -> Type) Name
- type UncheckedTypeParam = TypeParamBase Name
- type UncheckedPat = PatBase (NoInfo :: Type -> Type) Name
- type UncheckedValBind = ValBindBase (NoInfo :: Type -> Type) Name
- type UncheckedTypeBind = TypeBindBase (NoInfo :: Type -> Type) Name
- type UncheckedModTypeBind = ModTypeBindBase (NoInfo :: Type -> Type) Name
- type UncheckedModBind = ModBindBase (NoInfo :: Type -> Type) Name
- type UncheckedDec = DecBase (NoInfo :: Type -> Type) Name
- type UncheckedSpec = SpecBase (NoInfo :: Type -> Type) Name
- type UncheckedProg = ProgBase (NoInfo :: Type -> Type) Name
- type UncheckedCase = CaseBase (NoInfo :: Type -> Type) Name
- type Ident = IdentBase Info VName
- type DimIndex = DimIndexBase Info VName
- type Slice = SliceBase Info VName
- type AppExp = AppExpBase Info VName
- type Exp = ExpBase Info VName
- type Pat = PatBase Info VName
- type ModExp = ModExpBase Info VName
- type ModParam = ModParamBase Info VName
- type ModTypeExp = ModTypeExpBase Info VName
- type ModBind = ModBindBase Info VName
- type ModTypeBind = ModTypeBindBase Info VName
- type ValBind = ValBindBase Info VName
- type Dec = DecBase Info VName
- type Spec = SpecBase Info VName
- type Prog = ProgBase Info VName
- type TypeBind = TypeBindBase Info VName
- type StructTypeArg = TypeArg Size
- type ScalarType = ScalarTypeBase ()
- type TypeParam = TypeParamBase VName
- type Case = CaseBase Info VName
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.
intrinsicVar :: Name -> VName Source #
Find the VName corresponding to a builtin. Crashes if that
name cannot be found.
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.
isIntrinsic :: VName -> Bool Source #
Is this the name of an intrinsic?
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 :: forall (f :: Type -> Type) vn. ProgBase f vn -> [(String, Loc)] Source #
The modules imported by a Futhark program.
decImports :: forall (f :: Type -> Type) vn. DecBase f vn -> [(String, Loc)] 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 -> [Text] -> Text 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).
anySize :: Int -> Size Source #
A special expression representing no known size, but encoding an equivalence class (represented by the integer) that can be used to detect unknown-but-equal sizes. This is important so that we do not throw away size equalities just because the names become unknown to us (e.g. see #2326). The type checker should _never_ produce anySizes - they are a (hopefully temporary) thing introduced by defunctorisation and monomorphisation. They represent a flaw in our implementation. When they occur in a return type, they can be replaced with freshly created existential sizes. When they occur in parameter types, they can be replaced with size parameters.
isAnySize :: Size -> Maybe Int Source #
If this is any size, retrieve the key for the equivalence class.
setApplyLoc :: SrcLoc -> Exp -> Exp Source #
Override the location of an Apply expression.
This is useful because mkApply sets the location to be the span of the
function and all arguments, but during many frontend transformations we
insert additional arguments for which we do not care about the original
source location. Our goal is to maintain a correspondence between the
original source code and the generated code.
Queries on expressions
typeOf :: ExpBase Info VName -> StructType 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 :: [Pat (TypeBase d Diet)] -> RetTypeBase d Freshness -> TypeBase d NoMode Source #
The type of a function with the given parameters and return type.
stripExp :: Exp -> Maybe Exp Source #
Strip semantically irrelevant stuff from the top level of expression. This is used to provide a slightly fuzzy notion of expression equality.
Ideally we'd implement unification on a simpler representation that simply didn't allow us.
subExps :: Exp -> [Exp] Source #
All non-trivial subexpressions (as by stripExp) of some expression, not including the expression itself.
similarExps :: Exp -> Exp -> Maybe [(Exp, Exp)] Source #
If these two expressions are structurally similar at top level as sizes, produce their subexpressions (which are not necessarily similar, but you can check for that!). This is the machinery underlying expresssion unification. We assume that the expressions have the same type.
sameExp :: Exp -> Exp -> Bool Source #
Are these the same expression as per recursively invoking
similarExps?
Queries on patterns and params
patIdents :: forall (f :: Type -> Type) vn t. PatBase f vn t -> [IdentBase f vn t] Source #
The set of identifiers bound in a pattern.
patternMap :: Pat t -> [(VName, t)] Source #
Each name bound in a pattern alongside its type.
patternStructType :: Pat (TypeBase Size o) -> StructType Source #
The type matched by the pattern, including shape declarations if present.
patternParam :: Pat (TypeBase d Diet) -> (PName, Diet, TypeBase d NoMode) Source #
When viewed as a function parameter, does this pattern correspond to a named parameter of some type?
patternOrderZero :: Pat (TypeBase d o) -> Bool Source #
patternOrderZero pat is True if all of the types in the given pattern
have order 0.
Queries on types
freshness :: TypeBase shape Freshness -> Freshness Source #
Return the freshness of a type. A composite type is fresh if any of its components are.
fresh :: TypeBase shape Freshness -> Bool Source #
fresh t is True if the type of the argument is fresh.
diet :: TypeBase shape Diet -> Diet Source #
diet t returns a description of how a function parameter of
type t consumes its argument.
arrayRank :: TypeBase d o -> 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 o -> Shape dim Source #
Return the shape of a type - for non-arrays, this is mempty.
orderZero :: TypeBase dim o -> 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 o -> ([(PName, TypeBase dim Diet)], TypeBase dim NoMode) 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 :: [TypeBase d Diet] -> RetTypeBase d Freshness -> TypeBase d NoMode Source #
foldFunType ts ret creates a function type (Arrow) that takes
ts as parameters and returns ret.
typeQualVars :: TypeBase dim o -> [QualName VName] Source #
The qualified type names mentioned in a type.
isAccType :: TypeBase d o -> Maybe (TypeBase d NoMode) Source #
If this type corresponds to the builtin "acc" type, return the type of the underlying array.
Operations on types
peelArray :: Int -> TypeBase dim o -> Maybe (TypeBase dim o) 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 o -> TypeBase dim o 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 :: Shape dim -> TypeBase dim NoMode -> TypeBase dim NoMode Source #
arrayOf o 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.
arrayOfWithAliases :: o -> Shape dim -> TypeBase dim o' -> TypeBase dim o Source #
Like arrayOf, but you can pass in the annotation of the
resulting array.
toStructural :: TypeBase dim o -> TypeBase () NoMode Source #
Convert any type to one that has rank information, no alias information, and no embedded names.
toResRet :: Freshness -> RetTypeBase Size o -> ResRetType Source #
Convert to ResRetType
traverseDims :: Applicative f => (Set VName -> DimPos -> fdim -> f tdim) -> TypeBase fdim o -> f (TypeBase tdim o) 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?
Constructors
| PosImmediate | Immediately in the argument to |
| PosParam | In a function parameter type. |
| PosReturn | In a function return type. |
tupleRecord :: [TypeBase dim o] -> ScalarTypeBase dim o Source #
Create a record type corresponding to a tuple with the given element types.
isTupleRecord :: TypeBase dim o -> Maybe [TypeBase dim o] 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?
matchDims :: (Monoid o, Monad m) => ([VName] -> d1 -> d2 -> m d1) -> TypeBase d1 o -> TypeBase d2 o -> m (TypeBase d1 o) 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).
Un-typechecked ASTs
type UncheckedType = TypeBase (Shape Name) () Source #
A type with no aliasing information but shape annotations.
type UncheckedTypeExp = TypeExp UncheckedExp Name Source #
An unchecked type expression.
type UncheckedIdent = IdentBase (NoInfo :: k -> Type) Name Source #
An identifier with no type annotations.
type UncheckedDimIndex = DimIndexBase (NoInfo :: Type -> Type) Name Source #
An index with no type annotations.
type UncheckedSlice = SliceBase (NoInfo :: Type -> Type) Name Source #
A slice with no type annotations.
type UncheckedExp = ExpBase (NoInfo :: Type -> Type) Name Source #
An expression with no type annotations.
type UncheckedModExp = ModExpBase (NoInfo :: Type -> Type) Name Source #
A module expression with no type annotations.
type UncheckedModTypeExp = ModTypeExpBase (NoInfo :: Type -> Type) Name Source #
A module type expression with no type annotations.
type UncheckedTypeParam = TypeParamBase Name Source #
A type parameter with no type annotations.
type UncheckedPat = PatBase (NoInfo :: Type -> Type) Name Source #
A pattern with no type annotations.
type UncheckedValBind = ValBindBase (NoInfo :: Type -> Type) Name Source #
A function declaration with no type annotations.
type UncheckedTypeBind = TypeBindBase (NoInfo :: Type -> Type) Name Source #
A type binding with no type annotations.
type UncheckedModTypeBind = ModTypeBindBase (NoInfo :: Type -> Type) Name Source #
A module type binding with no type annotations.
type UncheckedModBind = ModBindBase (NoInfo :: Type -> Type) Name Source #
A module binding with no type annotations.
type UncheckedDec = DecBase (NoInfo :: Type -> Type) Name Source #
A declaration with no type annotations.
type UncheckedSpec = SpecBase (NoInfo :: Type -> Type) Name Source #
A spec with no type annotations.
type UncheckedProg = ProgBase (NoInfo :: Type -> Type) Name Source #
A Futhark program with no type annotations.
type UncheckedCase = CaseBase (NoInfo :: Type -> Type) Name Source #
A case (of a match expression) with no type annotations.
Type-checked ASTs
type ModTypeExp = ModTypeExpBase Info VName Source #
A type-checked module type expression.
type ModTypeBind = ModTypeBindBase Info VName Source #
A type-checked module type binding.
type StructTypeArg = TypeArg Size Source #
A known type arg with shape annotations.
type ScalarType = ScalarTypeBase () Source #
A known scalar type with no shape annotations.
type TypeParam = TypeParamBase VName Source #
A type-checked type parameter.