Do not add a 'solved dict' for quantified constraints
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 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.
Showing
- compiler/typecheck/ClsInst.hs 20 additions, 9 deletionscompiler/typecheck/ClsInst.hs
- compiler/typecheck/TcInteract.hs 2 additions, 3 deletionscompiler/typecheck/TcInteract.hs
- compiler/typecheck/TcSMonad.hs 72 additions, 13 deletionscompiler/typecheck/TcSMonad.hs
- compiler/typecheck/TcValidity.hs 1 addition, 9 deletionscompiler/typecheck/TcValidity.hs
- compiler/types/Type.hs 1 addition, 8 deletionscompiler/types/Type.hs
- testsuite/tests/quantified-constraints/T17267.hs 54 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267.hs
- testsuite/tests/quantified-constraints/T17267.stderr 16 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267.stderr
- testsuite/tests/quantified-constraints/T17267a.hs 18 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267a.hs
- testsuite/tests/quantified-constraints/T17267a.stderr 16 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267a.stderr
- testsuite/tests/quantified-constraints/T17267b.hs 16 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267b.hs
- testsuite/tests/quantified-constraints/T17267b.stderr 16 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267b.stderr
- testsuite/tests/quantified-constraints/T17267c.hs 23 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267c.hs
- testsuite/tests/quantified-constraints/T17267c.stderr 16 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267c.stderr
- testsuite/tests/quantified-constraints/T17267d.hs 28 additions, 0 deletionstestsuite/tests/quantified-constraints/T17267d.hs
- testsuite/tests/quantified-constraints/T17267d.stdout 1 addition, 0 deletionstestsuite/tests/quantified-constraints/T17267d.stdout
- testsuite/tests/quantified-constraints/all.T 5 additions, 0 deletionstestsuite/tests/quantified-constraints/all.T
Loading
Please register or sign in to comment