Make a smart mkAppTyM
This patch finally delivers on Trac Trac #15952. Specifically
- Completely remove Note [The tcType invariant], along with its complicated consequences (IT1-IT6).
- Replace Note [The well-kinded type invariant] with:
Note [The Purely Kinded Type Invariant (PKTI)]
- Instead, establish the (PKTI) in TcHsType.tcInferApps, by using a new function mkAppTyM when building a type application. See Note [mkAppTyM].
- As a result we can remove the delicate mkNakedXX functions entirely. Specifically, mkNakedCastTy retained lots of extremly delicate Refl coercions which just cluttered everything up, and(worse) were very vulnerable to being silently eliminated by (say) substTy. This led to a succession of bug reports.
The result is noticeably simpler to explain, simpler
to code, and Richard and I are much more confident that
it is correct.
I also did a raft of other minor refactorings:
- Use tcTypeKind consistently in the type checker
- Rename tcInstTyBinders to tcInvisibleTyBinders, and refactor it a bit
- Refactor tcEqType, pickyEqType, tcEqTypeVis Simpler, probably more efficient.
- Make zonkTcType zonk TcTyCons, at least if they have any free unification variables -- see zonk_tc_tycon in TcMType.zonkTcTypeMapper.
Not zonking these TcTyCons was actually a bug before.
- Simplify try_to_reduce_no_cache in TcFlatten (a lot)
- Combine checkExpectedKind and checkExpectedKindX. And then combine the invisible-binder instantation code Much simpler now.
- Fix a little bug in TcMType.skolemiseQuantifiedTyVar. I'm not sure how I came across this originally.
- Fix a little bug in TyCoRep.isUnliftedRuntimeRep (the ASSERT was over-zealous). Again I'm not certain how I encountered this.
- Add a missing solveLocalEqualities in TcHsType.tcHsPartialSigType. I came across this when trying to get level numbers right.