Note [Solve by unification]
If we solve
alpha[n] ~ ty
by unification, there are two cases to consider
* TouchableSameLevel: if the ambient level is 'n', then
we can simply update alpha := ty, and do nothing else
* TouchableOuterLevel free_metas n: if the ambient level is greater than
'n' (the level of alpha), in addition to setting alpha := ty we must
do two other things:
1. Promote all the free meta-vars of 'ty' to level n. After all,
alpha[n] is at level n, and so if we set, say,
alpha[n] := Maybe beta[m],
we must ensure that when unifying beta we do skolem-escape checks
etc relevant to level n. Simple way to do that: promote beta to
level n.
2. Set the Unification Level Flag to record that a level-n unification has
taken place. See Note [The Unification Level Flag] in GHC.Tc.Solver.Monad
NB: TouchableSameLevel is just an optimisation for TouchableOuterLevel. Promotion
would be a no-op, and setting the unification flag unnecessarily would just
make the solver iterate more often. (We don't need to iterate when unifying
at the ambient level because of the kick-out mechanism.) References 1
- The Unification Level Flag GHC.Tc.Solver.Monad
Referenced by 1
- GHC.Tc.Utils.Unify call site