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

Safe Haskell | None
Language | GHC2021

Language.Futhark.TypeChecker

Description

The type checker checks whether the program is type-consistent and adds type annotations and various other elaborations. The program does not need to have any particular properties for the type checker to function; in particular it does not need unique names.

Synopsis

- checkProg :: Imports -> VNameSource -> ImportName -> UncheckedProg -> (Warnings, Either TypeError (FileModule, VNameSource))
- checkExp :: Imports -> VNameSource -> Env -> UncheckedExp -> (Warnings, Either TypeError ([TypeParam], Exp))
- checkDec :: Imports -> VNameSource -> Env -> ImportName -> UncheckedDec -> (Warnings, Either TypeError (Env, Dec, VNameSource))
- checkModExp :: Imports -> VNameSource -> Env -> ModExpBase (NoInfo :: Type -> Type) Name -> (Warnings, Either TypeError (MTy, ModExpBase Info VName))
- data Notes
- data TypeError = TypeError Loc Notes (Doc ())
- prettyTypeError :: TypeError -> Doc AnsiStyle
- prettyTypeErrorNoLoc :: TypeError -> Doc AnsiStyle
- data Warnings
- initialEnv :: Env
- envWithImports :: Imports -> Env -> Env

# Documentation

checkProg :: Imports -> VNameSource -> ImportName -> UncheckedProg -> (Warnings, Either TypeError (FileModule, VNameSource)) Source #

Type check a program containing no type information, yielding either a type error or a program with complete type information. Accepts a mapping from file names (excluding extension) to previously type checked results. The `ImportName` is used to resolve relative `import`s.

checkExp :: Imports -> VNameSource -> Env -> UncheckedExp -> (Warnings, Either TypeError ([TypeParam], Exp)) Source #

Type check a single expression containing no type information, yielding either a type error or the same expression annotated with type information. Also returns a list of type parameters, which will be nonempty if the expression is polymorphic. See also `checkProg`.

checkDec :: Imports -> VNameSource -> Env -> ImportName -> UncheckedDec -> (Warnings, Either TypeError (Env, Dec, VNameSource)) Source #

Type check a single declaration containing no type information, yielding either a type error or the same declaration annotated with type information along the Env produced by that declaration. See also `checkProg`.

checkModExp :: Imports -> VNameSource -> Env -> ModExpBase (NoInfo :: Type -> Type) Name -> (Warnings, Either TypeError (MTy, ModExpBase Info VName)) Source #

Type check a single module expression containing no type information, yielding either a type error or the same expression annotated with type information along the Env produced by that declaration. See also `checkProg`.

data Notes Source #

A collection of extra information regarding a type error.

#### Instances

Instances details

Monoid Notes Source # |
Instance details Defined in Language.Futhark.TypeChecker.Monad Methods mempty :: Notes Source # mappend :: Notes -> Notes -> Notes Source # mconcat :: [Notes] -> Notes Source #
Semigroup Notes Source # |
Instance details Defined in Language.Futhark.TypeChecker.Monad Methods (<>) :: Notes -> Notes -> Notes Source # sconcat :: NonEmpty Notes -> Notes Source # stimes :: Integral b => b -> Notes -> Notes Source #
Pretty Notes Source # |
Instance details Defined in Language.Futhark.TypeChecker.Monad Methods pretty :: Notes -> Doc ann Source # prettyList :: [Notes] -> Doc ann Source #

data TypeError Source #

Information about an error during type checking.

Constructors

TypeError Loc Notes (Doc ()) |

#### Instances

Instances details

MonadError TypeError TypeM Source # |
Instance details Defined in Language.Futhark.TypeChecker.Monad Methods throwError :: TypeError -> TypeM a Source # catchError :: TypeM a -> (TypeError -> TypeM a) -> TypeM a Source #
MonadError TypeError TermTypeM Source # |
Instance details Defined in Language.Futhark.TypeChecker.Terms.Monad Methods throwError :: TypeError -> TermTypeM a Source # catchError :: TermTypeM a -> (TypeError -> TermTypeM a) -> TermTypeM a Source #

prettyTypeError :: TypeError -> Doc AnsiStyle Source #

Prettyprint type error.

prettyTypeErrorNoLoc :: TypeError -> Doc AnsiStyle Source #

Prettyprint type error, without location information. This can be used for cases where the location is printed in some other way.

data Warnings Source #

The warnings produced by the compiler. The `Show` instance produces a human-readable description.

#### Instances

Instances details

Monoid Warnings Source # |
Instance details Defined in Language.Futhark.Warnings Methods mempty :: Warnings Source # mappend :: Warnings -> Warnings -> Warnings Source # mconcat :: [Warnings] -> Warnings Source #
Semigroup Warnings Source # |
Instance details Defined in Language.Futhark.Warnings Methods (<>) :: Warnings -> Warnings -> Warnings Source # sconcat :: NonEmpty Warnings -> Warnings Source # stimes :: Integral b => b -> Warnings -> Warnings Source #

initialEnv :: Env Source #

An initial environment for the type checker, containing intrinsics and such.

envWithImports :: Imports -> Env -> Env Source #

Produce an environment, based on the one passed in, where all of the provided imports have been `open`ened in order. This could in principle also be done with `checkDec`, but this is more precise.