Note [NON-BOTTOM-DICTS invariant]

GHC/Core.hs:523 compiler

It is a global invariant (not checkable by Lint) that

     every non-newtype dictionary-typed expression is non-bottom.

These conditions are captured by GHC.Core.Type.isTerminatingType.

How are we so sure about this?  Dictionaries are built by GHC in only two ways:

* A dictionary function (DFun), arising from an instance declaration.
  DFuns do no computation: they always return a data constructor immediately.
  See DFunUnfolding in GHC.Core.  So the result of a call to a DFun is always
  non-bottom.

  Exception: newtype dictionaries.

  Plus: see the Very Nasty Wrinkle in Note [Speculative evaluation]
  in GHC.CoreToStg.Prep

* A superclass selection from some other dictionary. This is harder to guarantee:
  see Note [Recursive superclasses] and Note [Solving superclass constraints]
  in GHC.Tc.TyCl.Instance.

A bad Core-to-Core pass could invalidate this reasoning, but that's too bad.
It's still an invariant of Core programs generated by GHC from Haskell, and
Core-to-Core passes maintain it.

Why is it useful to know that dictionaries are non-bottom?

1. It justifies the use of `-XDictsStrict`;
   see `GHC.Core.Types.Demand.strictifyDictDmd`

2. It means that (eq_sel d) is ok-for-speculation and thus
     case (eq_sel d) of _ -> blah
   can be discarded by the Simplifier.  See these Notes:
   Note [exprOkForSpeculation and type classes] in GHC.Core.Utils
   Note[Speculative evaluation] in GHC.CoreToStg.Prep

References 4

Referenced by 4