[commit: ghc] ghc-8.4: Fix two pernicious bugs in DeriveAnyClass (d8dbe29)
git at git.haskell.org
git at git.haskell.org
Wed Mar 28 17:43:06 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-8.4
Link : http://ghc.haskell.org/trac/ghc/changeset/d8dbe2936c923471a13e214113b0e43222e95592/ghc
>---------------------------------------------------------------
commit d8dbe2936c923471a13e214113b0e43222e95592
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date: Sun Mar 25 14:00:39 2018 -0400
Fix two pernicious bugs in DeriveAnyClass
The way GHC was handling `DeriveAnyClass` was subtly wrong
in two notable ways:
* In `inferConstraintsDAC`, we were //always// bumping the `TcLevel`
of newly created unification variables, under the assumption that
we would always place those unification variables inside an
implication constraint. But #14932 showed precisely the scenario
where we had `DeriveAnyClass` //without// any of the generated
constraints being used inside an implication, which made GHC
incorrectly believe the unification variables were untouchable.
* Even worse, we were using the generated unification variables from
`inferConstraintsDAC` in every single iteration of `simplifyDeriv`.
In #14933, however, we have a scenario where we fill in a
unification variable with a skolem in one iteration, discard it,
proceed on to another iteration, use the same unification variable
(still filled in with the old skolem), and try to unify it with
a //new// skolem! This results in an utter disaster.
The root of both these problems is `inferConstraintsDAC`. This patch
fixes the issue by no longer generating unification variables
directly in `inferConstraintsDAC`. Instead, we store the original
variables from a generic default type signature in `to_metas`, a new
field of `ThetaOrigin`, and in each iteration of `simplifyDeriv`, we
generate fresh meta tyvars (avoiding the second issue). Moreover,
this allows us to more carefully fine-tune the `TcLevel` under which
we create these meta tyvars, fixing the first issue.
Test Plan: make test TEST="T14932 T14933"
Reviewers: simonpj, bgamari
Reviewed By: simonpj
Subscribers: rwbarton, thomie, carter
GHC Trac Issues: #14932, #14933
Differential Revision: https://phabricator.haskell.org/D4507
(cherry picked from commit 9893042604cda5260cb0f7b674ed5c34b419e403)
>---------------------------------------------------------------
d8dbe2936c923471a13e214113b0e43222e95592
compiler/typecheck/TcDerivInfer.hs | 103 ++++++++++++----------
compiler/typecheck/TcDerivUtils.hs | 97 +++++++++++++-------
testsuite/tests/deriving/should_compile/T14932.hs | 23 +++++
testsuite/tests/deriving/should_compile/T14933.hs | 22 +++++
testsuite/tests/deriving/should_compile/all.T | 2 +
5 files changed, 170 insertions(+), 77 deletions(-)
Diff suppressed because of size. To see it, use:
git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc d8dbe2936c923471a13e214113b0e43222e95592
More information about the ghc-commits
mailing list