This is the first step towards implementation of the linear types proposal (https://github.com/ghc-proposals/ghc-proposals/pull/111, #15981 (closed)).
It features
There are several issues which are not yet completed and need to be fixed before this PR is merged. However, they shouldn't block review, and they will be local changes to the commit.
The following items are not supported.
a # m -> b
syntax (only prefix FUN
is supported for now)The important changes, which guide the implementation and can be read first are:
Multiplicity
, which defines type Mult = Type
, the Scaled
type and functions unrestricted
, linear
, pattern synonyms One
and Omega
, quick submultiplicity test submult
FunTy
and new mkFunTy
in TyCoRep
, where the multiplicity argument is addedfunTyCon
in TysPrim
unrestrictedFunTyCon
and multiplicityTy
in TysWiredIn
Var
has now a new field varMult
; functions such as updateVarTypeAndMult
can be used to update multiplicity (e.g. when zonking). In Core, the multiplicity of a lambda is indicated by its varMult
; multiplicity of a case expression is indicated by varMult
of the case binder.UsageEnv
defines a map from a variable to its multiplicity, used when typecheckingsubmult
and tcSubMult
, which guide multiplicity checking in the type checkerensureSubMult
and its calls, which guide multiplicity checking in LintA high-level description can be found at https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation Following the link above you will find a description of the changes made to Core.
This commit has been authored by
With contributions from: