Expand and implement Note [The tcType invariant]

Authored by goldfire on Thu, Jul 5, 6:51 PM.

Description

Expand and implement Note [The tcType invariant]

Read that note -- it's necessary to make sure that we can
always call typeKind without panicking. As discussed on Trac #14873,
there were more checks and zonking to do, implemented here.
There are no known bugs fixed by this patch, but there are likely
unknown ones.

(cherry picked from commit cf67e59a90bcaba657a9f5db3d5defb6289c274f)