Draft: component-based defaulting
With this patch, defaulting is now based on components rather than individual type variables.
The functions for collecting candidate type variables are moved from GHC.Tc.Utils.TcMType
to a new module GHC.Tc.Utils.Quantify
. Now, instead of collecting type variables in candidateQTyVarsOfType
, we collect defaultable components:
- kind components for -XNoPolyKinds,
- RuntimeRep components for representation polymorphism,
- Multiplicity components for linear types.
To default these components, we emit Concrete# constraints. Typeclass defaulting then takes care of type variable defaulting.
This approach is more robust than simply collecting type variables of specified kinds and defaulting them:
- it is more sensitive to the context in which the type variables appear,
- it is more composable,
- it handles unreduced type family applications.
This patch also significantly refactors GHC.Tc.Solver.decideQuantification
, which used to do two separate rounds of defaulting, once in defaultTyVarsAndSimplify
and once in decideQuantifiedTyVars
.