Fix TcSimplify.decideQuantification for kind variables
authorSimon Peyton Jones <simonpj@microsoft.com>
Fri, 10 Mar 2017 11:20:00 +0000 (11:20 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Fri, 10 Mar 2017 16:04:39 +0000 (16:04 +0000)
commit7e96526ac2ef5987ecb03217d3d616b6281c1441
treeed201840c894bcb71f8811e839fedc82308cfaf7
parentbc0f3abd0914808e33f84229818ab90842611bdd
Fix TcSimplify.decideQuantification for kind variables

TcSimplify.decideQuantification was doing the Wrong Thing when
"growing" the type variables to quantify over. We were trying to do
this on a tyvar set where we'd split off the dependent type varaibles;
and we just got it wrong.  A kind variable wasn't being generalised
properly, with confusing knock on consequences.

All this led to Trac #13371 and Trac #13393.

This commit tidies it all up:

* The type TcDepVars is renamed as CandidateQTvs;
  and splitDepVarsOfType to candidateQTyVarsOfType

* The code in TcSimplify.decideQuantification is simpler.
  It no longer does the tricky "grow" stuff over TcDepVars.
  Instead it use ordinary VarSets (thereby eliminating the
  nasty growThetaTyVarsDSet) and uses that to filter the
  result of candidateQTyVarsOfType.

* I documented that candidateQTyVarsOfType returns the type
  variables in a good order in which to quantify, and rewrote
  it to use an accumulator pattern, so that we would predicatably
  get left-to-right ordering.

In doing all this I also made UniqDFM behave a little more nicely:

* When inserting an element that is there already, keep the old tag,
  while still overwriting with the new value.

* This means that when doing udfmToList we get back elements in the
  order they were originally inserted, rather than in reverse order.

It's not a big deal, but in a subsequent commit I use it to improve
the order of type variables in inferred types.

All this led to a lot of error message wibbles:
 - changing the order of quantified variables
 - changing the order in which instances are listed in GHCi
 - changing the tidying of variables in typechecker erors

There's a submodule update for 'array' because one of its tests
has an error-message change.

I may not have associated all of them with the correct commit.
64 files changed:
compiler/typecheck/TcMType.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcType.hs
compiler/utils/UniqDFM.hs
libraries/array
testsuite/tests/ado/ado004.stderr
testsuite/tests/determinism/determ021/determ021.stdout
testsuite/tests/driver/werror.stderr
testsuite/tests/gadt/gadt7.stderr
testsuite/tests/ghci.debugger/scripts/break026.stdout
testsuite/tests/ghci/scripts/T11524a.stdout
testsuite/tests/ghci/scripts/T11975.stdout
testsuite/tests/ghci/scripts/T12550.stdout
testsuite/tests/ghci/scripts/T4175.stdout
testsuite/tests/ghci/scripts/T6018ghcifail.stderr
testsuite/tests/ghci/scripts/T7627.stdout
testsuite/tests/ghci/scripts/T7939.stdout
testsuite/tests/ghci/scripts/T8469.stdout
testsuite/tests/ghci/scripts/T8535.stdout
testsuite/tests/ghci/scripts/T9881.stdout
testsuite/tests/ghci/scripts/ghci011.stdout
testsuite/tests/ghci/scripts/ghci020.stdout
testsuite/tests/ghci/should_run/T10145.stdout
testsuite/tests/ghci/should_run/T12549.stdout
testsuite/tests/indexed-types/should_compile/T3017.stderr
testsuite/tests/indexed-types/should_fail/T1897b.stderr
testsuite/tests/indexed-types/should_fail/T8518.stderr
testsuite/tests/indexed-types/should_fail/T9662.stderr
testsuite/tests/module/mod72.stderr
testsuite/tests/parser/should_fail/readFail003.stderr
testsuite/tests/partial-sigs/should_compile/ExtraConstraints3.stderr
testsuite/tests/partial-sigs/should_compile/Meltdown.stderr
testsuite/tests/partial-sigs/should_compile/NamedTyVar.stderr
testsuite/tests/partial-sigs/should_compile/SkipMany.stderr
testsuite/tests/partial-sigs/should_compile/T10438.stderr
testsuite/tests/partial-sigs/should_compile/T11192.stderr
testsuite/tests/partial-sigs/should_compile/Uncurry.stderr
testsuite/tests/partial-sigs/should_compile/UncurryNamed.stderr
testsuite/tests/partial-sigs/should_compile/WarningWildcardInstantiations.stderr
testsuite/tests/partial-sigs/should_fail/NamedExtraConstraintsWildcard.stderr
testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotInMonotype.stderr
testsuite/tests/partial-sigs/should_fail/T10045.stderr
testsuite/tests/partial-sigs/should_fail/TidyClash.stderr
testsuite/tests/partial-sigs/should_fail/TidyClash2.stderr
testsuite/tests/patsyn/should_compile/T11213.stderr
testsuite/tests/polykinds/T13371.hs [new file with mode: 0644]
testsuite/tests/polykinds/T13393.hs [new file with mode: 0644]
testsuite/tests/polykinds/T13393.stderr [new file with mode: 0644]
testsuite/tests/polykinds/T7438.stderr
testsuite/tests/polykinds/T7524.stderr
testsuite/tests/polykinds/all.T
testsuite/tests/rename/should_fail/T2993.stderr
testsuite/tests/simplCore/should_compile/T3234.stderr
testsuite/tests/typecheck/should_compile/tc141.stderr
testsuite/tests/typecheck/should_compile/tc231.stderr
testsuite/tests/typecheck/should_fail/T12177.stderr
testsuite/tests/typecheck/should_fail/T6018fail.stderr
testsuite/tests/typecheck/should_fail/T6018failclosed.stderr
testsuite/tests/typecheck/should_fail/T7734.stderr
testsuite/tests/typecheck/should_fail/T8142.stderr
testsuite/tests/typecheck/should_fail/T8883.stderr
testsuite/tests/typecheck/should_fail/mc25.stderr
testsuite/tests/typecheck/should_fail/tcfail049.stderr
testsuite/tests/typecheck/should_fail/tcfail050.stderr