futhark-0.25.15: An optimising compiler for a functional, array-oriented language.
Safe HaskellSafe-Inferred
LanguageGHC2021

Language.Futhark.TypeChecker.Monad

Description

Main monad in which the type checker runs, as well as ancillary data definitions.

Synopsis

Documentation

data TypeM a Source #

The type checker runs in this monad.

Instances

Instances details
Applicative TypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

Methods

pure :: a -> TypeM a #

(<*>) :: TypeM (a -> b) -> TypeM a -> TypeM b #

liftA2 :: (a -> b -> c) -> TypeM a -> TypeM b -> TypeM c #

(*>) :: TypeM a -> TypeM b -> TypeM b #

(<*) :: TypeM a -> TypeM b -> TypeM a #

Functor TypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

Methods

fmap :: (a -> b) -> TypeM a -> TypeM b #

(<$) :: a -> TypeM b -> TypeM a #

Monad TypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

Methods

(>>=) :: TypeM a -> (a -> TypeM b) -> TypeM b #

(>>) :: TypeM a -> TypeM b -> TypeM b #

return :: a -> TypeM a #

MonadTypeChecker TypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

MonadError TypeError TypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

Methods

throwError :: TypeError -> TypeM a #

catchError :: TypeM a -> (TypeError -> TypeM a) -> TypeM a #

MonadState TypeState TypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

Methods

get :: TypeM TypeState #

put :: TypeState -> TypeM () #

state :: (TypeState -> (a, TypeState)) -> TypeM a #

askEnv :: TypeM Env Source #

Retrieve the current Env.

askImportName :: TypeM ImportName Source #

The name of the current file/import.

atTopLevel :: TypeM Bool Source #

Are we type-checking at the top level, or are we inside a nested module?

enteringModule :: TypeM a -> TypeM a Source #

We are now going to type-check the body of a module.

bindSpaced :: [(Namespace, Name, SrcLoc)] -> ([VName] -> TypeM a) -> TypeM a Source #

Map source-level names to fresh unique internal names, and evaluate a type checker context with the mapping active.

bindSpaced1 :: Namespace -> Name -> SrcLoc -> (VName -> TypeM a) -> TypeM a Source #

Map single source-level name to fresh unique internal names, and evaluate a type checker context with the mapping active.

bindIdents :: [IdentBase NoInfo VName t] -> TypeM a -> TypeM a Source #

Bind these identifiers in the name map and also check whether they have been used.

qualifyTypeVars :: Env -> [VName] -> [VName] -> TypeBase Size as -> TypeBase Size as Source #

Try to prepend qualifiers to the type names such that they represent how to access the type in some scope.

lookupMTy :: SrcLoc -> QualName Name -> TypeM (QualName VName, MTy) Source #

Look up a module type.

lookupImport :: SrcLoc -> FilePath -> TypeM (ImportName, Env) Source #

Look up an import.

localEnv :: Env -> TypeM a -> TypeM a Source #

Evaluate a TypeM computation within an extended (not replaced) environment.

data TypeError Source #

Information about an error during type checking.

Constructors

TypeError Loc Notes (Doc ()) 

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.

withIndexLink :: Doc a -> Doc a -> Doc a Source #

Attach a reference to documentation explaining the error in more detail.

unappliedFunctor :: MonadTypeChecker m => SrcLoc -> m a Source #

An unexpected functor appeared!

unknownVariable :: MonadTypeChecker m => Namespace -> QualName Name -> SrcLoc -> m a Source #

An unknown variable was referenced.

underscoreUse :: MonadTypeChecker m => SrcLoc -> QualName Name -> m a Source #

A name prefixed with an underscore was used.

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 #

mappend :: Notes -> Notes -> Notes #

mconcat :: [Notes] -> Notes #

Semigroup Notes Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

Methods

(<>) :: Notes -> Notes -> Notes #

sconcat :: NonEmpty Notes -> Notes #

stimes :: Integral b => b -> Notes -> Notes #

Pretty Notes Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

Methods

pretty :: Notes -> Doc ann #

prettyList :: [Notes] -> Doc ann #

aNote :: Doc () -> Notes Source #

A single note.

class Monad m => MonadTypeChecker m where Source #

Monads that support type checking. The reason we have this internal interface is because we use distinct monads for checking expressions and declarations.

Minimal complete definition

warn, warnings, newName, newTypeName, bindVal, lookupType, typeError

Methods

warn :: Located loc => loc -> Doc () -> m () Source #

warnings :: Warnings -> m () Source #

newName :: VName -> m VName Source #

newID :: Name -> m VName Source #

newTypeName :: Name -> m VName Source #

bindVal :: VName -> BoundV -> m a -> m a Source #

lookupType :: QualName VName -> m ([TypeParam], StructRetType, Liftedness) Source #

typeError :: Located loc => loc -> Notes -> Doc () -> m a Source #

data TypeState Source #

Instances

Instances details
MonadState TypeState TypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Monad

Methods

get :: TypeM TypeState #

put :: TypeState -> TypeM () #

state :: (TypeState -> (a, TypeState)) -> TypeM a #

usedName :: VName -> TypeM () Source #

Indicate that this name has been used. This is usually done implicitly by other operations, but sometimes we want to make a "fake" use to avoid things like top level functions being considered unused.

checkName :: Namespace -> Name -> SrcLoc -> TypeM VName Source #

Elaborate the given name in the given namespace at the given location, producing the corresponding unique VName.

checkAttr :: MonadTypeChecker m => AttrInfo VName -> m (AttrInfo VName) Source #

Type-check an attribute.

checkQualName :: Namespace -> QualName Name -> SrcLoc -> TypeM (QualName VName) Source #

Elaborate the given qualified name in the given namespace at the given location, producing the corresponding unique QualName.

checkValName :: QualName Name -> SrcLoc -> TypeM (QualName VName) Source #

Elaborate the given qualified name in the given namespace at the given location, producing the corresponding unique QualName. Fails if the name is a module.

badOnLeft :: Either TypeError a -> TypeM a Source #

Turn a Left TypeError into an actual error.

isKnownType :: QualName VName -> TypeM Bool Source #

Does a type with this name already exist? This is used for warnings, so it is OK it's a little unprincipled.

data Env Source #

Modules produces environment with this representation.

Instances

Instances details
Monoid Env Source # 
Instance details

Defined in Language.Futhark.Semantic

Methods

mempty :: Env #

mappend :: Env -> Env -> Env #

mconcat :: [Env] -> Env #

Semigroup Env Source # 
Instance details

Defined in Language.Futhark.Semantic

Methods

(<>) :: Env -> Env -> Env #

sconcat :: NonEmpty Env -> Env #

stimes :: Integral b => b -> Env -> Env #

Show Env Source # 
Instance details

Defined in Language.Futhark.Semantic

Methods

showsPrec :: Int -> Env -> ShowS #

show :: Env -> String #

showList :: [Env] -> ShowS #

Pretty Env Source # 
Instance details

Defined in Language.Futhark.Semantic

Methods

pretty :: Env -> Doc ann #

prettyList :: [Env] -> Doc ann #

type TySet = Map (QualName VName) Liftedness Source #

A mapping of abstract types to their liftedness.

data FunModType Source #

A parametric functor consists of a set of abstract types, the environment of its parameter, and the resulting module type.

Instances

Instances details
Show FunModType Source # 
Instance details

Defined in Language.Futhark.Semantic

type ImportTable = Map ImportName Env Source #

A mapping from import import names to Envs. This is used to resolve import declarations.

type NameMap = Map (Namespace, Name) (QualName VName) Source #

A mapping from names (which always exist in some namespace) to a unique (tagged) name.

data BoundV Source #

Type parameters, list of parameter types (optinally named), and return type. The type parameters are in scope in both parameter types and the return type. Non-functional values have only a return type.

Constructors

BoundV [TypeParam] StructType 

Instances

Instances details
Show BoundV Source # 
Instance details

Defined in Language.Futhark.Semantic

data Mod Source #

Representation of a module, which is either a plain environment, or a parametric module ("functor" in SML).

Constructors

ModEnv Env 
ModFun FunModType 

Instances

Instances details
Show Mod Source # 
Instance details

Defined in Language.Futhark.Semantic

Methods

showsPrec :: Int -> Mod -> ShowS #

show :: Mod -> String #

showList :: [Mod] -> ShowS #

Pretty Mod Source # 
Instance details

Defined in Language.Futhark.Semantic

Methods

pretty :: Mod -> Doc ann #

prettyList :: [Mod] -> Doc ann #

data TypeBinding Source #

A binding from a name to its definition as a type. We allow a return type here to support type abbreviations that hide some inner sizes (these must necessarily be Lifted or SizeLifted).

Instances

Instances details
Show TypeBinding Source # 
Instance details

Defined in Language.Futhark.Semantic

Eq TypeBinding Source # 
Instance details

Defined in Language.Futhark.Semantic

data MTy Source #

Representation of a module type.

Constructors

MTy 

Fields

Instances

Instances details
Show MTy Source # 
Instance details

Defined in Language.Futhark.Semantic

Methods

showsPrec :: Int -> MTy -> ShowS #

show :: MTy -> String #

showList :: [MTy] -> ShowS #

Pretty MTy Source # 
Instance details

Defined in Language.Futhark.Semantic

Methods

pretty :: MTy -> Doc ann #

prettyList :: [MTy] -> Doc ann #

anySignedType :: [PrimType] Source #

All signed integer types.

anyUnsignedType :: [PrimType] Source #

All unsigned integer types.

anyIntType :: [PrimType] Source #

All integer types.

anyFloatType :: [PrimType] Source #

All floating-point types.

anyNumberType :: [PrimType] Source #

All number types.

anyPrimType :: [PrimType] Source #

All primitive types.

data Namespace Source #

The space inhabited by a name.

Constructors

Term

Functions and values.

Type 
Signature 

intrinsicsNameMap :: NameMap Source #

The NameMap corresponding to the intrinsics module.

topLevelNameMap :: NameMap Source #

The names that are available in the initial environment.

mkTypeVarName :: Name -> Int -> Name Source #

Construct the name of a new type variable given a base description and a tag number (note that this is distinct from actually constructing a VName; the tag here is intended for human consumption but the machine does not care).