futhark
Safe HaskellNone
LanguageGHC2021

Language.Futhark.TypeChecker.Terms.Monad

Description

Facilities for type-checking terms. Factored out of Language.Futhark.TypeChecker.Terms to prevent the module from being gigantic.

Incidentally also a nice place to put Haddock comments to make the internal API of the type checker easier to browse.

Synopsis

Documentation

data TermTypeM a Source #

Instances

Instances details
MonadTypeChecker TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

MonadUnify TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

Applicative TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

Methods

pure :: a -> TermTypeM a #

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

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

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

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

Functor TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

Methods

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

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

Monad TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

Methods

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

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

return :: a -> TermTypeM a #

MonadError TypeError TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

MonadReader TermEnv TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

Methods

ask :: TermTypeM TermEnv #

local :: (TermEnv -> TermEnv) -> TermTypeM a -> TermTypeM a #

reader :: (TermEnv -> a) -> TermTypeM a #

MonadState TermTypeState TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

data ValBinding dim Source #

What a bound value stands for. Note that although modules are in the same name space, they are not value bindings.

Constructors

BoundV [TypeParam] (TypeBase dim NoMode) 
OverloadedF [PrimType] [Maybe PrimType] (Maybe PrimType) 
EqualityF 
RecursiveV

A recursive function with no declared return type, currently being checked and in scope of its own body. Each occurrence adopts the type recorded for it by the unsized type checker, with fresh (unrelated) sizes. See Note [Checking recursive functions] in Language.Futhark.TypeChecker.Terms.

Instances

Instances details
Show dim => Show (ValBinding dim) Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Scope

Methods

showsPrec :: Int -> ValBinding dim -> ShowS #

show :: ValBinding dim -> String #

showList :: [ValBinding dim] -> ShowS #

data SizeSource Source #

What was the source of some existential size? This is used for using the same existential variable if the same source is encountered in multiple locations.

data Inferred t Source #

During type checking a pattern, we might find an explicit ascription. These contain complete type information (although they must of course still be checked against what remains of the pattern).

Constructors

NoneInferred 
Ascribed t 

Instances

Instances details
Functor Inferred Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Scope

Methods

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

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

Show t => Show (Inferred t) Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Scope

Methods

showsPrec :: Int -> Inferred t -> ShowS #

show :: Inferred t -> String #

showList :: [Inferred t] -> ShowS #

data TermEnv Source #

Type checking happens with access to this environment. The TermScope will be extended during type-checking as bindings come into scope.

Instances

Instances details
MonadReader TermEnv TermTypeM Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Monad

Methods

ask :: TermTypeM TermEnv #

local :: (TermEnv -> TermEnv) -> TermTypeM a -> TermTypeM a #

reader :: (TermEnv -> a) -> TermTypeM a #

data TermScope dim Source #

The lexical scope information.

Instances

Instances details
Semigroup (TermScope dim) Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Scope

Methods

(<>) :: TermScope dim -> TermScope dim -> TermScope dim #

sconcat :: NonEmpty (TermScope dim) -> TermScope dim #

stimes :: Integral b => b -> TermScope dim -> TermScope dim #

Show dim => Show (TermScope dim) Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Terms.Scope

Methods

showsPrec :: Int -> TermScope dim -> ShowS #

show :: TermScope dim -> String #

showList :: [TermScope dim] -> ShowS #

data TermTypeState Source #

The state is a set of constraints and a counter for generating type names. This is distinct from the usual counter we use for generating unique names, as these will be user-visible.

expType :: Exp -> TermTypeM StructType Source #

Get the type of an expression. Currently no different from typeOf, but kept as the counterpart of expTypeFully.

expTypeFully :: Exp -> TermTypeM StructType Source #

Get the type of an expression, with all type variables substituted. Slower than expType, but sometimes necessary. Never call typeOf directly (except in a few carefully inspected locations)!

instTyVars Source #

Arguments

:: Substitutable (TypeBase Size o) 
=> SrcLoc 
-> Map VName Liftedness

The type parameters being instantiated, along with their liftedness.

-> TypeBase () o 
-> TypeBase Size o 
-> TermTypeM (TypeBase Size o) 

Instantiate the type parameters of a type scheme with the types inferred by the unsized type checker, creating fresh variables for their sizes. See Note [Size Inference] in Language.Futhark.TypeChecker.Terms.

replaceTyVars :: SrcLoc -> TypeBase Size o -> TermTypeM (TypeBase Size o) Source #

Replace type variables inferred by the unsized type checker with their solutions, instantiating their sizes with fresh (non-absorbable) size variables. See Note [Size Inference] in Language.Futhark.TypeChecker.Terms.

replaceTyVarsAbsorbable :: SrcLoc -> TypeBase Size o -> TermTypeM (TypeBase Size o) Source #

Like replaceTyVars, but the fresh sizes may be determined to be existential by unification, like instantiated sizes. This is used for holes, which adopt whatever type the context provides. See Note [Size Inference] in Language.Futhark.TypeChecker.Terms.

updateTypes :: ASTMappable e => e -> TermTypeM e Source #

Replace all type variables with their concrete types.

Primitive checking

typeSchemes :: TermTypeM (QualName VName -> Maybe BoundV) Source #

A pure function for looking up the type scheme of a global name. Used by consumption checking to exploit parametricity; see Note [Parametric results] in Language.Futhark.TypeChecker.Consumption.

lookupAbsTy :: QualName VName -> TermTypeM Liftedness Source #

Look up the liftedness of an abstract type.

Sizes

Control flow

Errors