Note [What is zonking?]
GHC relies heavily on mutability in the typechecker for efficient operation.
For this reason, throughout much of the type checking process, meta type
variables (the MetaTv constructor of TcTyVarDetails) are represented by mutable
variables (known as TcRefs).
Zonking is the process of replacing each such mutable variable with a Type.
This involves traversing the entire type expression, but the interesting part,
replacing the mutable variables, occurs in zonkTyVarOcc.
There are two ways to zonk a Type, using one of two entirely separate zonkers,
that share essentially no code:
* GHC.Tc.Zonk.TcType.zonkTcType, which is used /during/ type checking:
* It leaves unfilled metavars untouched, so the resulting Type can contain TcTyVars
* It is only defined for Type and Coercion, not for HsExpr
* It works in a very stripped-down monad, ZonkM, make it clear that it uses
very few effects (for example, it can't throw errors).
* GHC.Tc.Zonk.Type.zonkTcTypeToType, is used /after/ typechecking is complete:
* It always returns a Type with no remaining TcTyVars; no meta-tyvars remain.
* It does defaulting, replacing an unconstrained TcTyVar with Any, or failing
(determined by the ZonkFlexi parameter used; see GHC.Tc.Zonk.Type.commitFlexi).
* It works over HsExpr and HsBinds as well as Type and Coercion. As part of this,
it also removes the mutable variables in evidence bindings.
* It works in the full TcM monad, augmented with an environment.
More precisely, it uses ZonkTcM and ZonkBndrTcM, which augment TcM with a
ZonkEnv environment using the zonking monad transformers ZonkT and ZonkBndrT
(see Note [The ZonkEnv] in GHC.Tc.Zonk.Env).
Why TcM rather than a smaller monad? See Note [Using TcM for zonking to Type]. References 2
- The ZonkEnv GHC.Tc.Zonk.Env
- Using TcM for zonking to Type GHC.Tc.Zonk.Type
Referenced by 7
- GHC.Tc.Deriv.Utils call site ×2
- GHC.Tc.Zonk.Type call site ×2
- GHC.Tc.Deriv.Generate call site
- GHC.Tc.Plugin call site
- Module structure for zonking GHC.Tc.Zonk.Type