Note [Module structure for zonking]
As remarked in Note [What is zonking?], there are really two different zonkers; we have GHC.Tc.Zonk.TcType for zonking within the typechecker and GHC.Tc.Zonk.Type for the final zonking pass. The code relating to zonking is thus split up across the following modules: I. Zonking within the typechecker 1. GHC.Tc.Zonk.Monad 2. GHC.Tc.Zonk.TcType II. Final zonking to Type 1. GHC.Tc.Zonk.Env 2. GHC.Tc.Zonk.Type I.1. GHC.Tc.Zonk.Monad - the ZonkM monad GHC.Tc.Zonk.Monad defines the ZonkM monad, which is a stripped down version of TcM which has just enough information to be able to zonk types. This is the monad used for zonking inside the typechecker, as used in GHC.Tc.Zonk.TcType. Crucially, it never errors. It is the monad we use when reporting errors (see ErrCtxt), and it would be quite bad if we could error in the middle of reporting an error! I.2. GHC.Tc.Zonk.TcType - zonking types in the typechecker GHC.Tc.Zonk.TcType contains code for zonking types and constraints, for use within the typechecker. It uses the ZonkM monad. For example, it defines: zonkTcType :: TcType -> ZonkM TcType zonkCt :: Ct -> ZonkM Ct II.1. GHC.Tc.Zonk.Env - the ZonkEnv and ZonkT/ZonkBndrT monad transformers GHC.Tc.Zonk.Env defines the the ZonkT and ZonkBndrT monad transformers. These are essentially "ReaderT ZonkEnv" and "StateT ZonkEnv", except that ZonkBndrT use continuation-passing style instead of an explicit state. See Note [The ZonkEnv] in GHC.Tc.Zonk.Env. These are used for the final zonking to type, in GHC.Tc.Zonk.Type. II.2. GHC.Tc.Zonk.Type - final zonking to type GHC.Tc.Zonk.Type is concerned with the "final zonking" pass, after we finish typechecking. It zonks not only types, but terms. It uses the monads type ZonkTcM = ZonkT TcM type ZonkBndrTcM = ZonkBndrTcM for example: zonkTyBndrX :: TcTyVar -> ZonkBndrTcM TyVar zonkTcTypeToTypeX :: TcType -> ZonkT TcM Type Note that ZonkTcM does a lot more things than ZonkM: - it uses a separate ZonkEnv state to accumulate zonked type (see Note [The ZonkEnv] in GHC.Tc.Zonk.Env) - it defaults type variables, (see Note [Un-unified unification variables] in GHC.Tc.Zonk.Env) - turns TcTyVars into TyVars, - ... This means that there is essentially no code shared between "GHC.Tc.Zonk.TcType" and "GHC.Tc.Zonk.Type'; they're really two different zonkers.
References 3
- The ZonkEnv GHC.Tc.Zonk.Env
- Un-unified unification variables GHC.Tc.Zonk.Env
- What is zonking? GHC.Tc.Zonk.Type
Referenced by 5
- GHC.Tc.Zonk.Type call site ×2
- GHC.Tc.Zonk.Env call site
- GHC.Tc.Zonk.Monad call site
- GHC.Tc.Zonk.TcType call site