futhark-0.21.12: An optimising compiler for a functional, array-oriented language.
Safe HaskellTrustworthy
LanguageHaskell2010

Futhark.IR.TypeCheck

Description

The type checker checks whether the program is type-consistent.

Synopsis

Interface

checkProg :: Checkable rep => Prog (Aliases rep) -> Either (TypeError rep) () Source #

Type check a program containing arbitrary type information, yielding either a type error or a program with complete type information.

data TypeError rep Source #

A type error.

Constructors

Error [String] (ErrorCase rep) 

Instances

Instances details
Checkable rep => Show (TypeError rep) Source # 
Instance details

Defined in Futhark.IR.TypeCheck

Methods

showsPrec :: Int -> TypeError rep -> ShowS #

show :: TypeError rep -> String #

showList :: [TypeError rep] -> ShowS #

data ErrorCase rep Source #

Information about an error during type checking. The Show instance for this type produces a human-readable description.

Instances

Instances details
Checkable rep => Show (ErrorCase rep) Source # 
Instance details

Defined in Futhark.IR.TypeCheck

Methods

showsPrec :: Int -> ErrorCase rep -> ShowS #

show :: ErrorCase rep -> String #

showList :: [ErrorCase rep] -> ShowS #

Extensionality

data TypeM rep a Source #

The type checker runs in this monad.

Instances

Instances details
Monad (TypeM rep) Source # 
Instance details

Defined in Futhark.IR.TypeCheck

Methods

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

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

return :: a -> TypeM rep a #

Functor (TypeM rep) Source # 
Instance details

Defined in Futhark.IR.TypeCheck

Methods

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

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

Applicative (TypeM rep) Source # 
Instance details

Defined in Futhark.IR.TypeCheck

Methods

pure :: a -> TypeM rep a #

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

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

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

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

Checkable rep => HasScope (Aliases rep) (TypeM rep) Source # 
Instance details

Defined in Futhark.IR.TypeCheck

Methods

lookupType :: VName -> TypeM rep Type Source #

lookupInfo :: VName -> TypeM rep (NameInfo (Aliases rep)) Source #

askScope :: TypeM rep (Scope (Aliases rep)) Source #

asksScope :: (Scope (Aliases rep) -> a) -> TypeM rep a Source #

bad :: ErrorCase rep -> TypeM rep a Source #

Signal a type error.

context :: String -> TypeM rep a -> TypeM rep a Source #

Add information about what is being type-checked to the current context. Liberal use of this combinator makes it easier to track type errors, as the strings are added to type errors signalled via bad.

class (ASTRep rep, CanBeAliased (Op rep), CheckableOp rep) => Checkable rep where Source #

The class of representations that can be type-checked.

Minimal complete definition

Nothing

Methods

checkExpDec :: ExpDec rep -> TypeM rep () Source #

default checkExpDec :: ExpDec rep ~ () => ExpDec rep -> TypeM rep () Source #

checkBodyDec :: BodyDec rep -> TypeM rep () Source #

default checkBodyDec :: BodyDec rep ~ () => BodyDec rep -> TypeM rep () Source #

checkFParamDec :: VName -> FParamInfo rep -> TypeM rep () Source #

default checkFParamDec :: FParamInfo rep ~ DeclType => VName -> FParamInfo rep -> TypeM rep () Source #

checkLParamDec :: VName -> LParamInfo rep -> TypeM rep () Source #

default checkLParamDec :: LParamInfo rep ~ Type => VName -> LParamInfo rep -> TypeM rep () Source #

checkLetBoundDec :: VName -> LetDec rep -> TypeM rep () Source #

default checkLetBoundDec :: LetDec rep ~ Type => VName -> LetDec rep -> TypeM rep () Source #

checkRetType :: [RetType rep] -> TypeM rep () Source #

default checkRetType :: RetType rep ~ DeclExtType => [RetType rep] -> TypeM rep () Source #

matchPat :: Pat (LetDec (Aliases rep)) -> Exp (Aliases rep) -> TypeM rep () Source #

default matchPat :: Pat (LetDec (Aliases rep)) -> Exp (Aliases rep) -> TypeM rep () Source #

primFParam :: VName -> PrimType -> TypeM rep (FParam (Aliases rep)) Source #

default primFParam :: FParamInfo rep ~ DeclType => VName -> PrimType -> TypeM rep (FParam (Aliases rep)) Source #

matchReturnType :: [RetType rep] -> Result -> TypeM rep () Source #

default matchReturnType :: RetType rep ~ DeclExtType => [RetType rep] -> Result -> TypeM rep () Source #

matchBranchType :: [BranchType rep] -> Body (Aliases rep) -> TypeM rep () Source #

default matchBranchType :: BranchType rep ~ ExtType => [BranchType rep] -> Body (Aliases rep) -> TypeM rep () Source #

matchLoopResult :: [FParam (Aliases rep)] -> Result -> TypeM rep () Source #

default matchLoopResult :: FParamInfo rep ~ DeclType => [FParam (Aliases rep)] -> Result -> TypeM rep () Source #

Instances

Instances details
Checkable Seq Source # 
Instance details

Defined in Futhark.IR.Seq

Checkable SOACS Source # 
Instance details

Defined in Futhark.IR.SOACS

Checkable SeqMem Source # 
Instance details

Defined in Futhark.IR.SeqMem

Checkable MCMem Source # 
Instance details

Defined in Futhark.IR.MCMem

Checkable MC Source # 
Instance details

Defined in Futhark.IR.MC

Checkable GPU Source # 
Instance details

Defined in Futhark.IR.GPU

Checkable GPUMem Source # 
Instance details

Defined in Futhark.IR.GPUMem

class ASTRep rep => CheckableOp rep where Source #

Methods

checkOp :: OpWithAliases (Op rep) -> TypeM rep () Source #

Used at top level; can be locally changed with checkOpWith.

Instances

Instances details
CheckableOp Seq Source # 
Instance details

Defined in Futhark.IR.Seq

CheckableOp SOACS Source # 
Instance details

Defined in Futhark.IR.SOACS

CheckableOp SeqMem Source # 
Instance details

Defined in Futhark.IR.SeqMem

CheckableOp MCMem Source # 
Instance details

Defined in Futhark.IR.MCMem

CheckableOp MC Source # 
Instance details

Defined in Futhark.IR.MC

CheckableOp GPU Source # 
Instance details

Defined in Futhark.IR.GPU

CheckableOp GPUMem Source # 
Instance details

Defined in Futhark.IR.GPUMem

checkOpWith :: (OpWithAliases (Op rep) -> TypeM rep ()) -> TypeM rep a -> TypeM rep a Source #

Checkers

require :: Checkable rep => [Type] -> SubExp -> TypeM rep () Source #

require ts se causes a '(TypeError vn)' if the type of se is not a subtype of one of the types in ts.

requireI :: Checkable rep => [Type] -> VName -> TypeM rep () Source #

Variant of require working on variable names.

checkCerts :: Checkable rep => Certs -> TypeM rep () Source #

checkExp :: Checkable rep => Exp (Aliases rep) -> TypeM rep () Source #

checkStms :: Checkable rep => Stms (Aliases rep) -> TypeM rep a -> TypeM rep a Source #

checkStm :: Checkable rep => Stm (Aliases rep) -> TypeM rep a -> TypeM rep a Source #

matchExtPat :: Checkable rep => Pat (LetDec (Aliases rep)) -> [ExtType] -> TypeM rep () Source #

matchExtBranchType :: Checkable rep => [ExtType] -> Body (Aliases rep) -> TypeM rep () Source #

argType :: Arg -> Type Source #

noArgAliases :: Arg -> Arg Source #

checkArg :: Checkable rep => SubExp -> TypeM rep Arg Source #

checkSOACArrayArgs :: Checkable rep => SubExp -> [VName] -> TypeM rep [Arg] Source #

checkLambda :: Checkable rep => Lambda (Aliases rep) -> [Arg] -> TypeM rep () Source #

checkBody :: Checkable rep => Body (Aliases rep) -> TypeM rep [Names] Source #

consume :: Checkable rep => Names -> TypeM rep () Source #

Proclaim that we have written to the given variables.

binding :: Checkable rep => Scope (Aliases rep) -> TypeM rep a -> TypeM rep a Source #

alternative :: TypeM rep a -> TypeM rep b -> TypeM rep (a, b) Source #

Type check two mutually control flow branches. Think if. This interacts with consumption checking, as it is OK for an array to be consumed in both branches.