[commit: ghc] master: Improved Valid Hole Fits (e0b44e2)

git at git.haskell.org git at git.haskell.org
Wed May 30 20:31:20 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/e0b44e2eccd4053852b6c4c3de75a714301ec080/ghc

>---------------------------------------------------------------

commit e0b44e2eccd4053852b6c4c3de75a714301ec080
Author: Matthías Páll Gissurarson <mpg at mpg.is>
Date:   Sun May 27 11:50:49 2018 -0400

    Improved Valid Hole Fits
    
    I've changed the name from `Valid substitutions` to `Valid hole fits`,
    since "substitution" already has a well defined meaning within the
    theory. As part of this change, the flags and output is reanamed, with
    substitution turning into hole-fit in most cases. "hole fit" was already
    used internally in the code, it's clear and shouldn't cause any
    confusion.
    
    In this update, I've also reworked how we manage side-effects in the
    hole we are considering.
    
    This allows us to consider local bindings such as where clauses and
    arguments to functions, suggesting e.g. `a` for `head (x:xs) where head
    :: [a] -> a`.
    
    It also allows us to find suggestions such as `maximum` for holes of
    type `Ord a => a -> [a]`, and `max` when looking for a match for the
    hole in `g = foldl1 _`, where `g :: Ord a => [a] -> a`.
    
    We also show much improved output for refinement hole fits, and
    fixes #14990. We now show the correct type of the function, but we also
    now show what the arguments to the function should be e.g. `foldl1 (_ ::
    Integer -> Integer -> Integer)` when looking for `[Integer] -> Integer`.
    
    I've moved the bulk of the code from `TcErrors.hs` to a new file,
    `TcHoleErrors.hs`, since it was getting too big to not live on it's own.
    
    This addresses the considerations raised in #14969, and takes proper
    care to set the `tcLevel` of the variables to the right level before
    passing it to the simplifier.
    
    We now also zonk the suggestions properly, which improves the output of
    the refinement hole fits considerably.
    
    This also filters out suggestions from the `GHC.Err` module, since even
    though `error` and `undefined` are indeed valid hole fits, they are
    "trivial", and almost never useful to the user.
    
    We now find the hole fits using the proper manner, namely by solving
    nested implications. This entails that the givens are passed along using
    the implications the hole was nested in, which in turn should mean that
    there will be fewer weird bugs in the typed holes.
    
    I've also added a new sorting method (as suggested by SPJ) and sort by
    the size of the types needed to turn the hole fits into the type of the
    hole. This gives a reasonable approximation to relevance, and is much
    faster than the subsumption check. I've also added a flag to toggle
    whether to use this new sorting algorithm (as is done by default) or the
    subsumption algorithm. This fixes #14969
    
    I've also added documentation for these new flags and update the
    documentation according to the new output.
    
    Reviewers: bgamari, goldfire
    
    Reviewed By: bgamari
    
    Subscribers: simonpj, rwbarton, thomie, carter
    
    GHC Trac Issues: #14969, #14990, #10946
    
    Differential Revision: https://phabricator.haskell.org/D4444


>---------------------------------------------------------------

e0b44e2eccd4053852b6c4c3de75a714301ec080
 compiler/ghc.cabal.in                              |   1 +
 compiler/main/DynFlags.hs                          | 120 ++-
 compiler/typecheck/TcErrors.hs                     | 489 +----------
 compiler/typecheck/TcHoleErrors.hs                 | 917 +++++++++++++++++++++
 compiler/typecheck/TcHoleErrors.hs-boot            |  12 +
 compiler/typecheck/TcMType.hs                      |   9 +-
 compiler/typecheck/TcRnTypes.hs                    |  28 +-
 compiler/typecheck/TcSimplify.hs                   |  37 +-
 compiler/typecheck/TcSimplify.hs-boot              |  11 -
 docs/users_guide/8.6.1-notes.rst                   |   4 +
 docs/users_guide/glasgow_exts.rst                  | 461 ++++++-----
 testsuite/tests/gadt/T12468.stderr                 |   8 +-
 testsuite/tests/ghci/scripts/T10248.stderr         |   4 +-
 testsuite/tests/ghci/scripts/T10249.stderr         |   3 -
 testsuite/tests/ghci/scripts/T8353.stderr          |  45 +-
 testsuite/tests/module/mod71.stderr                |   5 +-
 .../partial-sigs/should_compile/T12531.stderr      |   5 +-
 testsuite/tests/th/T10267.stderr                   |  58 +-
 testsuite/tests/th/all.T                           |   2 +-
 .../tests/typecheck/should_compile/T13050.stderr   | 225 +++--
 .../tests/typecheck/should_compile/T14273.stderr   |  27 +-
 .../tests/typecheck/should_compile/T14590.stderr   | 304 ++++---
 .../tests/typecheck/should_compile/T9497a.stderr   |   9 +-
 .../typecheck/should_compile/ValidHoleFits.hs      |   4 +
 .../tests/typecheck/should_compile/ValidSubs.hs    |   4 -
 ...tutions.hs => abstract_refinement_hole_fits.hs} |   0
 .../abstract_refinement_hole_fits.stderr           | 277 +++++++
 .../abstract_refinement_substitutions.stderr       | 410 ---------
 testsuite/tests/typecheck/should_compile/all.T     |  31 +-
 .../should_compile/constraint_hole_fits.hs         |   4 +
 .../should_compile/constraint_hole_fits.stderr     |  65 ++
 .../should_compile/free_monad_hole_fits.hs         |  25 +
 .../should_compile/free_monad_hole_fits.stderr     |  81 ++
 .../should_compile/hole_constraints.stderr         |  44 +-
 .../should_compile/hole_constraints_nested.stderr  |   9 +-
 .../tests/typecheck/should_compile/holes.stderr    | 574 +++----------
 .../tests/typecheck/should_compile/holes2.stderr   |  24 +-
 .../tests/typecheck/should_compile/holes3.stderr   | 574 +++----------
 .../typecheck/should_compile/local_hole_fits.hs    |  11 +
 .../should_compile/local_hole_fits.stderr          |  28 +
 ...nt_substitutions.hs => refinement_hole_fits.hs} |   0
 .../should_compile/refinement_hole_fits.stderr     | 236 ++++++
 .../should_compile/refinement_substitutions.stderr | 330 --------
 .../should_compile/subsumption_sort_hole_fits.hs   |   5 +
 .../subsumption_sort_hole_fits.stderr              |  39 +
 .../should_compile/type_in_type_hole_fits.hs       |  88 ++
 .../should_compile/type_in_type_hole_fits.stderr   |  78 ++
 .../{valid_substitutions.hs => valid_hole_fits.hs} |   4 +-
 .../should_compile/valid_hole_fits.stderr          | 255 ++++++
 ...ractions.hs => valid_hole_fits_interactions.hs} |   0
 .../valid_hole_fits_interactions.stderr            |  11 +
 .../should_compile/valid_substitutions.stderr      | 258 ------
 .../valid_substitutions_interactions.stderr        |  16 -
 .../tests/typecheck/should_fail/T12177.stderr      |   8 -
 .../tests/typecheck/should_fail/T14884.stderr      |  17 +-
 .../tests/typecheck/should_fail/T9497d.stderr      |   9 +-
 .../tests/typecheck/should_run/T9497a-run.stderr   |   9 +-
 .../tests/typecheck/should_run/T9497b-run.stderr   |   9 +-
 .../tests/typecheck/should_run/T9497c-run.stderr   |   9 +-
 59 files changed, 3284 insertions(+), 3046 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 e0b44e2eccd4053852b6c4c3de75a714301ec080


More information about the ghc-commits mailing list