unison-parser-typechecker-0.0.0
Safe HaskellNone
LanguageHaskell2010

Unison.Typechecker.Context

Synopsis

Documentation

synthesizeClosed :: (BuiltinAnnotation loc, Var v, Ord loc, Show loc, Semigroup loc) => PrettyPrintEnv -> PatternMatchCoverageCheckAndKindInferenceSwitch -> Map Reference [Variance] -> [Type v loc] -> TypeLookup v loc -> Term v loc -> Result v loc (Type v loc) Source #

public interface to the typechecker

data ErrorNote v loc Source #

Constructors

ErrorNote 

Fields

Instances

Instances details
(Var v, Show loc, Ord loc) => Show (ErrorNote v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

showsPrec :: Int -> ErrorNote v loc -> ShowS #

show :: ErrorNote v loc -> String #

showList :: [ErrorNote v loc] -> ShowS #

data InfoNote v loc Source #

Constructors

SolvedBlank (Recorded loc) v (Type v loc) 
Decision v loc (Term v loc) 
TopLevelComponent [(v, Type v loc, RedundantTypeAnnotation)] 
Warning (Warn v loc) 
VarBinding v loc (Type v loc) 
VarMention v loc

The usage of a particular variable. We report the variable and its location so we can match a given source location with a specific symbol later in the LSP.

Instances

Instances details
(Var v, Show loc, Ord loc) => Show (InfoNote v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

showsPrec :: Int -> InfoNote v loc -> ShowS #

show :: InfoNote v loc -> String #

showList :: [InfoNote v loc] -> ShowS #

data Context v loc Source #

The ordered context of the typechecking algorithm.

The context is a sequence of Elements. The typechecking algorithm appends to it, retracts a suffix of it (everything after a marker), replaces one element with a few (e.g. an existential solved to an arrow, with the arrow's fresh existentials inserted before it), and asks scoping questions: is this variable declared, as an existential or a universal, and at what position? Is it solved, and to what?

The sequence only orders the elements. What is known about each variable is kept in indexes keyed by variable name, beside the sequence, and each of those maps a variable to a position in the sequence (CtxPosition): every element in the sequence has one, and vars maps each variable to its element together with that position.

So for instance, a solution proposed for an existential β may only mention variables declared before β in the context, existentials and universals alike (the universals are the rigid type variables of enclosing quantifiers). solve therefore looks up each free variable of the solution in vars, checks that it is declared as the kind of variable it occurs as, and compares its position with β's. Once β is solved, its solution is read from the same entry. anns and refinements are the same idea for term variable annotations and for the branch-local refinements of a universal.

The sequence is a finger tree whose measure includes the greatest position in a subtree (so that the element at a position can be found in logarithmic time), and a count of Inconsistent elements (so that inconsistent can tell in constant time whether the pattern-match branch being checked has been marked unreachable by contradictory GADT refinements, in which case its body is skipped).

Every change keeps the indexes describing exactly the elements in the sequence: an append or replacement records the new elements, and a retraction walks the elements it discards and forgets them. Each element is appended once and discarded at most once, so a retraction costs no more than the appends it undoes.

Segments of a context that have been retracted are plain lists (CtxSegment); the typechecker reads them whole (to generalize over their unsolved existentials, apply their solutions, or push some of them back).

Instances

Instances details
(Ord loc, Var v) => Show (Context v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context.Structure

Methods

showsPrec :: Int -> Context v loc -> ShowS #

show :: Context v loc -> String #

showList :: [Context v loc] -> ShowS #

elements :: Context v loc -> [Element v loc] Source #

The elements, in order.

data Warn v loc Source #

Constructors

AbilityConcreteSubset [Type v loc] [Type v loc] (Term v loc) (Context v loc) 

Instances

Instances details
(Var v, Ord loc) => Show (Warn v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

showsPrec :: Int -> Warn v loc -> ShowS #

show :: Warn v loc -> String #

showList :: [Warn v loc] -> ShowS #

data Element v loc Source #

Elements of an ordered algorithmic context. Every element but Refined declares its variable; a context is valid when no variable is declared twice and every type in it mentions only variables declared before it.

Constructors

Var (TypeVar v loc)

A variable declaration

Solved (Blank loc) v (Monotype v loc)

v is solved to some monotype

Ann v loc (Type v loc)

v has type a, maybe quantified loc contains the span of the name of the annotated v

Refined v (Type v loc)

The (already-declared) universal variable v is locally known to equal the given type. This is how GADT pattern matching refines a rigid type index inside a branch: matching e.g. NatLit : Expr Nat against a scrutinee of type Expr a records a ~ Nat for the duration of that branch. Like other branch-local context, these are introduced after a Marker and dropped on retraction.

Inconsistent v

Marks the context as inconsistent (the DK indexed-types paper's ⊥): the branch-local equalities are contradictory, so the current pattern-match branch is unreachable and its body is vacuously well-typed. Carries a (fresh) variable only so it scopes like any other element and is dropped on retraction. See inconsistent.

Marker v

used for scoping

Instances

Instances details
Var v => Show (Element v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context.Structure

Methods

showsPrec :: Int -> Element v loc -> ShowS #

show :: Element v loc -> String #

showList :: [Element v loc] -> ShowS #

Var v => Eq (Element v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context.Structure

Methods

(==) :: Element v loc -> Element v loc -> Bool #

(/=) :: Element v loc -> Element v loc -> Bool #

data PathElement v loc Source #

Constructors

InSynthesize (Term v loc) 
InSubtype (Type v loc) (Type v loc) 
InSubAbilities [Type v loc] [Type v loc] 
InEquate (Type v loc) (Type v loc) 
InCheck (Term v loc) (Type v loc) 
InInstantiateL v (Type v loc) 
InInstantiateR (Type v loc) v 
InSynthesizeApp (Type v loc) (Term v loc) Int 
InFunctionCall [v] (Term v loc) (Type v loc) [Term v loc] 
InAndApp 
InOrApp 
InIfCond 
InIfBody loc 
InVectorApp loc 
InMatch loc 
InMatchGuard 
InMatchBody 
InActionRestriction 
InRecordLiteral loc 
InRecordField loc Text 

Instances

Instances details
(Show v, Show loc) => Show (PathElement v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

showsPrec :: Int -> PathElement v loc -> ShowS #

show :: PathElement v loc -> String #

showList :: [PathElement v loc] -> ShowS #

type Term v loc = Term' (TypeVar v loc) v loc Source #

type Type v loc = Type (TypeVar v loc) loc Source #

type TypeVar v loc = TypeVar (Blank loc) v Source #

data Result v loc a Source #

Constructors

Success !(Seq (InfoNote v loc)) !a 
TypeError !(NESeq (ErrorNote v loc)) !(Seq (InfoNote v loc)) 
CompilerBug !(CompilerBug v loc) !(Seq (ErrorNote v loc)) !(Seq (InfoNote v loc)) 

Instances

Instances details
Applicative (Result v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

pure :: a -> Result v loc a #

(<*>) :: Result v loc (a -> b) -> Result v loc a -> Result v loc b #

liftA2 :: (a -> b -> c) -> Result v loc a -> Result v loc b -> Result v loc c #

(*>) :: Result v loc a -> Result v loc b -> Result v loc b #

(<*) :: Result v loc a -> Result v loc b -> Result v loc a #

Functor (Result v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

fmap :: (a -> b) -> Result v loc a -> Result v loc b #

(<$) :: a -> Result v loc b -> Result v loc a #

Monad (Result v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

(>>=) :: Result v loc a -> (a -> Result v loc b) -> Result v loc b #

(>>) :: Result v loc a -> Result v loc b -> Result v loc b #

return :: a -> Result v loc a #

MonadFix (Result v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

mfix :: (a -> Result v loc a) -> Result v loc a #

errorTerms :: ErrorNote v loc -> [Term v loc] Source #

lookupAnn :: Ord v => Context v loc -> v -> Maybe (Type v loc) Source #

lookupSolved :: Ord v => Context v loc -> v -> Maybe (Monotype v loc) Source #

apply :: Var v => Context v loc -> Type v loc -> Type v loc Source #

Replace any existentials with their solution in the context, and any refined universals with their refinement.

isEqual :: (Var v, Ord loc) => Type v loc -> Type v loc -> Either (CompilerBug v loc) Bool Source #

isSubtype :: (Var v, Ord loc) => Type v loc -> Type v loc -> Either (CompilerBug v loc) Bool Source #

fitsScheme :: (Var v, Ord loc) => Type v loc -> Type v loc -> Either (CompilerBug v loc) Bool Source #

isRedundant :: (Var v, Ord loc) => Type v loc -> Type v loc -> M v loc Bool Source #

data Suggestion v loc Source #

Instances

Instances details
Show v => Show (Suggestion v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

showsPrec :: Int -> Suggestion v loc -> ShowS #

show :: Suggestion v loc -> String #

showList :: [Suggestion v loc] -> ShowS #

Var v => Eq (Suggestion v loc) Source # 
Instance details

Defined in Unison.Typechecker.Context

Methods

(==) :: Suggestion v loc -> Suggestion v loc -> Bool #

(/=) :: Suggestion v loc -> Suggestion v loc -> Bool #

data Replacement v Source #

Instances

Instances details
Show v => Show (Replacement v) Source # 
Instance details

Defined in Unison.Typechecker.Context

Eq v => Eq (Replacement v) Source # 
Instance details

Defined in Unison.Typechecker.Context

Ord v => Ord (Replacement v) Source # 
Instance details

Defined in Unison.Typechecker.Context

typeErrors :: Result v loc a -> Seq (ErrorNote v loc) Source #

infoNotes :: Result v loc a -> Seq (InfoNote v loc) Source #

data Unknown Source #

Constructors

Data 
Effect 

Instances

Instances details
Show Unknown Source # 
Instance details

Defined in Unison.Typechecker.Context

relax :: (Var v, Ord loc) => Map Reference [Variance] -> Type v loc -> Type v loc Source #