[commit: ghc] wip/spj-tc-branch3: More constraint-solver refactoring (42d5eb7)
git at git.haskell.org
git at git.haskell.org
Tue Oct 25 16:42:31 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/spj-tc-branch3
Link : http://ghc.haskell.org/trac/ghc/changeset/42d5eb7b35d330d44c79088c7bd9440c70f5766d/ghc
>---------------------------------------------------------------
commit 42d5eb7b35d330d44c79088c7bd9440c70f5766d
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Tue Oct 25 17:41:45 2016 +0100
More constraint-solver refactoring
This patch takes further my refactoring of the constraint solver.
It fixes a number of tricky bugs including
Trac #12526
Trac #12444
Trac #12538
The main changes are these
* Flatten unification variables (fmvs/fuvs) appear on the LHS
of a tvar/tyvar equality; thus
fmv ~ alpha
and not
alpha ~ fmv
See Note [Put flatten unification variables on the left]
This is implemented by TcUnify.swapOverTyVars.
* Don't reduce a "loopy" CFunEqCan where the fsk appears on
the LHS:
F t1 .. tn ~ fsk
where 'fsk' is free in t1..tn.
See Note [FunEq occurs-check principle] in TcInteract
This neatly stops some infinite loops that people reported;
and it allows us to delete some crufty code in reduce_top_fun_eq.
And it appears to be no loss whatsoever.
As well as fixing loops, ContextStack2 and T5837 both terminate
when they didn't before.
* Previously we generated "derived shadow" constraints incrementally;
a Wanted might do duty as the shadow, until it couldn't any more.
But this was jolly tricky to implement correctly; and it generated
Derived constraints even in situations where we didn't need any
because the Wanted constraints all got solved anyway.
So this patch arranges to add Derived shadows after the first
iteration of solving is complete, in TcSimplify. See the
call to mkDerivedShadows.
It's a lot simpler, and it matches the treatment of (derived)
superclasses.
See TcSMonad Note [Shadow constraints and improvement]
* Rather than have a separate inert_model in the InertCans, I've
put the derived equalities back into inert_eqs. We weren't
gaining anything from a separate field.
* Previously we had a mode for the constraint solver in which it
would more aggressively solve Derived constraints; it was used
for simplifying the context of a 'deriving' clause, or a 'default'
delcaration, for example.
But the complexity wasn't worth it; now I just make proper Wanted
constraints. See TcMType.cloneWC
* Don't generate injectivity improvement for Givens; see
Note [No FunEq improvement for Givens] in TcInteract
* Don't do reduction for Derived class constraints; see
Note [No reduction for Derived class constraints]
If we had derived CFunEqCans, we would not reduce those either.
This is a free choice really; we get less overhead, but risk
missing some eventual injectivity opportunity.
* We generate no Derived CFunEqCans at all. When flattening a Derived
constraint we generate a Watned CFunEqCan. The main reason is to
make the inert_funeqs simple; but I think this really isn't quite
right and want to come back to it.
See TcSMonad Note [No Derived CFunEqCans].
* solveSimpleWanteds leaves the insolubles in-place rather than
returning them. Simpler.
I also did lots of work on comments.
>---------------------------------------------------------------
42d5eb7b35d330d44c79088c7bd9440c70f5766d
compiler/typecheck/TcFlatten.hs | 161 ++--
compiler/typecheck/TcInteract.hs | 573 +++++++------
compiler/typecheck/TcMType.hs | 20 +-
compiler/typecheck/TcRnTypes.hs | 40 +-
compiler/typecheck/TcRules.hs | 11 +-
compiler/typecheck/TcSMonad.hs | 903 ++++++++++-----------
compiler/typecheck/TcSimplify.hs | 148 ++--
compiler/typecheck/TcUnify.hs | 40 +-
.../tests/indexed-types/should_compile/T12526.hs | 70 ++
.../tests/indexed-types/should_compile/T12538.hs | 40 +
.../indexed-types/should_compile/T12538.stderr | 11 +
.../indexed-types/should_compile/T3017.stderr | 2 +-
.../indexed-types/should_compile/T3208b.stderr | 11 +-
.../tests/indexed-types/should_compile/T4338.hs | 35 +-
testsuite/tests/indexed-types/should_compile/all.T | 2 +
.../tests/indexed-types/should_fail/T2544.stderr | 24 +-
.../tests/indexed-types/should_fail/T2627b.stderr | 4 +-
.../tests/indexed-types/should_fail/T3330c.stderr | 6 +-
.../tests/indexed-types/should_fail/T4174.stderr | 4 +-
.../tests/indexed-types/should_fail/T4179.stderr | 6 +-
.../tests/indexed-types/should_fail/T6123.stderr | 6 +-
testsuite/tests/indexed-types/should_fail/T7786.hs | 16 +-
.../tests/indexed-types/should_fail/T7786.stderr | 43 +-
.../tests/indexed-types/should_fail/T8227.stderr | 11 +-
testsuite/tests/perf/compiler/T5837.hs | 29 +-
testsuite/tests/perf/compiler/T5837.stderr | 91 ---
testsuite/tests/perf/compiler/all.T | 7 +-
testsuite/tests/polykinds/T12444.hs | 65 ++
testsuite/tests/polykinds/T12444.stderr | 16 +
testsuite/tests/polykinds/all.T | 1 +
.../tests/typecheck/should_compile/Improvement.hs | 12 +-
testsuite/tests/typecheck/should_compile/T6018.hs | 13 +
.../tests/typecheck/should_compile/T6018.stderr | 8 +-
testsuite/tests/typecheck/should_compile/all.T | 2 +-
.../tests/typecheck/should_fail/ContextStack2.hs | 2 +
.../typecheck/should_fail/ContextStack2.stderr | 13 -
testsuite/tests/typecheck/should_fail/Makefile | 5 +
testsuite/tests/typecheck/should_fail/T1899.stderr | 21 +-
testsuite/tests/typecheck/should_fail/T5691.stderr | 10 +-
testsuite/tests/typecheck/should_fail/T5853.stderr | 31 +-
.../tests/typecheck/should_fail/T7748a.stderr | 6 +-
testsuite/tests/typecheck/should_fail/T8450.stderr | 10 +-
testsuite/tests/typecheck/should_fail/T9260.stderr | 11 +-
testsuite/tests/typecheck/should_fail/all.T | 2 +-
.../tests/typecheck/should_fail/tcfail201.stderr | 8 +-
45 files changed, 1357 insertions(+), 1193 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 42d5eb7b35d330d44c79088c7bd9440c70f5766d
More information about the ghc-commits
mailing list