futhark
Safe HaskellNone
LanguageGHC2021

Language.Futhark.TypeChecker.Consumption

Contents

Description

Check that a value definition does not violate any consumption constraints, via alias analysis.

This is a very subtle part of the language. The basic idea is "the result of an expression aliases everything that goes into it", but this is in practice too restrictive when we have functions (and polymorphic and higher-order functions!) as well. However, we also do not want to make the user-facing type system too complicated.

Our solution is to infer more precise function types, that directly talk about alias information, via parametricity. These never escape into the user-facing language.

Our overall philosophy is that soundness is (of course) non-negotiable, but simplicity is better than flexibility. Futhark is not a language for very fine-grained reasoning about aliasing.

As an example of the compromise, x |> copy works and produces a fresh result, whilst id >-> copy loses freshness information.

Further, we only infer freshness for fully saturated higher-order functions, so refactoring to take advantage of partial application may not work. Likewise, we infer only the freshness of the value a function returns, not of what a returned function in turn returns: that must be declared on the returned lambda itself.

Synopsis

Documentation

checkValDef Source #

Arguments

:: (QualName VName -> Maybe BoundV)

The type scheme of any global, along with the type parameters it is polymorphic in. See Note [Parametric results].

-> (VName, [TypeParam], [Pat ParamType], Exp, ResRetType, Maybe (TypeExp Exp VName), SrcLoc) 
-> ((Exp, ResRetType), [TypeError]) 

Type-check a value definition. This also infers a new return type that may be fresher than previously.

For testing

data Alias Source #

Something a value may share memory with. Every constructor but AliasSelf denotes a Location. Its variable may be in scope, or be free: either it has gone out of scope, or it is an internal name standing for an intermediate value. A free alias behaves more like an equivalence class. See uniqueness-error18.fut for an example of why this is necessary.

Constructors

AliasBound Location 
AliasFree Location 
AliasSelf

Used to represent unknowable internal aliasing, which for example may occur for a function that returns a nonfresh abstract type. (That abstract type may internally be a pair of arrays that alias each other.)

Instances

Instances details
Show Alias Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Consumption

Methods

showsPrec :: Int -> Alias -> ShowS #

show :: Alias -> String #

showList :: [Alias] -> ShowS #

Eq Alias Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Consumption

Methods

(==) :: Alias -> Alias -> Bool #

(/=) :: Alias -> Alias -> Bool #

Ord Alias Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Consumption

Methods

compare :: Alias -> Alias -> Ordering #

(<) :: Alias -> Alias -> Bool #

(<=) :: Alias -> Alias -> Bool #

(>) :: Alias -> Alias -> Bool #

(>=) :: Alias -> Alias -> Bool #

max :: Alias -> Alias -> Alias #

min :: Alias -> Alias -> Alias #

Pretty Alias Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Consumption

Methods

pretty :: Alias -> Doc ann #

prettyList :: [Alias] -> Doc ann #

Pretty (Set Alias) Source # 
Instance details

Defined in Language.Futhark.TypeChecker.Consumption

Methods

pretty :: Set Alias -> Doc ann #

prettyList :: [Set Alias] -> Doc ann #

type Aliases = Set Alias Source #

What a value may share memory with.