Note [Using isCallStackTy in mightMentionIP]

GHC/Tc/Solver/Monad.hs:586 compiler

To implement Note [Don't add HasCallStack constraints to the solved set],
we need to check whether a constraint contains a HasCallStack or HasExceptionContext
constraint. We do this using the 'mentionsIP' function, but as per
Note [Using typesAreApart when calling mightMentionIP] we don't want to simply do:

  mightMentionIP
    (const True) -- (ignore the implicit parameter string)
    (isCallStackTy <||> isExceptionContextTy)

because this does not account for e.g. a type family that reduces to CallStack.
The predicate we want to use instead is:

    \ ty -> not (typesAreApart ty callStackTy && typesAreApart ty exceptionContextTy)

However, this is made difficult by the fact that CallStack and ExceptionContext
are not wired-in types; they are only known-key. This means we must look them
up using 'tcLookupTyCon'. However, this might fail, e.g. if we are in the middle
of typechecking ghc-internal and these data-types have not been typechecked yet!

In that case, we simply fall back to the naive 'isCallStackTy'/'isExceptionContextTy'
logic.

Note that it would be somewhat painful to wire-in ExceptionContext: at the time
of writing (March 2025), this would require wiring in the ExceptionAnnotation
class, as well as SomeExceptionAnnotation, which is a data type with existentials.

References 2

Referenced by 1