Skip to content

Do not add a 'solved dict' for quantified constraints

Simon Peyton Jones requested to merge wip/T17267 into master

GHC has a wonderful-but-delicate mechanism for building recursive dictionaries by adding a goal to the "solved dictionaries" before solving the sub-goals. See Note [Solved dictionaries] in TcSMonad

Ticket #17267 (closed) showed that if you use this mechanism for local /quantified/ constraints you can get a loop -- or even unsafe coerce. This patch fixes the bug.

Specifically

  • Make TcSMonad.addSolvedDict be conditional on using a /top level/ instance, not a quantified one.

  • Moreover, we /also/ don't want to add a solved dict for equalities (a~b).

  • Add lots more comments to Note [Solved dictionaries] to explain the above cryptic stuff.

  • Extend InstanceWhat to identify those strange built-in equality instances.

A couple of other things along the way

  • Delete the unused Type.isIPPred_maybe.

  • Stop making addSolvedDict conditional on not being an impolicit parameter. This comes from way back. But it's irrelevant now because IP dicts are never solved via an instance.

Merge request reports