[commit: ghc] master: Also show types that subsume a hole as valid substitutions for that hole. (1c92083)

git at git.haskell.org git at git.haskell.org
Thu Sep 21 18:53:54 UTC 2017


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

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

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

commit 1c9208323b5ccd6796d00763ccba9d3b4a612358
Author: Matthías Páll Gissurarson <mpg at mpg.is>
Date:   Thu Sep 21 14:14:53 2017 -0400

    Also show types that subsume a hole as valid substitutions for that hole.
    
    This builds on the previous "Valid substitutions include..." functionality,
    but add subsumption checking as well, so that the suggested valid substitutions
    show not only exact matches, but also identifiers that fit the hole by virtue of
    subsuming the type of the hole (i.e. being more general than the type of the
    hole).
    
    Building on the previous example, in the given program
    
    ```
    ps :: String -> IO ()
    ps = putStrLn
    
    ps2 :: a -> IO ()
    ps2 _ = putStrLn "hello, world"
    
    main :: IO ()
    main = _ "hello, world"
    ```
    
    The results would be something like
    
    ```
        • Found hole: _ :: [Char] -> IO ()
        • In the expression: _
          In the expression: _ "hello, world"
          In an equation for ‘main’: main = _ "hello, world"
        • Relevant bindings include main :: IO () (bound at t1.hs:8:1)
          Valid substitutions include
            ps :: String -> IO () (defined at t1.hs:2:1)
            ps2 :: forall a. a -> IO () (defined at t1.hs:5:1)
            putStrLn :: String -> IO ()
              (imported from ‘Prelude’ at t1.hs:1:1
               (and originally defined in ‘System.IO’))
            fail :: forall (m :: * -> *). Monad m => forall a. String -> m a
              (imported from ‘Prelude’ at t1.hs:1:1
               (and originally defined in ‘GHC.Base’))
            mempty :: forall a. Monoid a => a
              (imported from ‘Prelude’ at t1.hs:1:1
               (and originally defined in ‘GHC.Base’))
            print :: forall a. Show a => a -> IO ()
              (imported from ‘Prelude’ at t1.hs:1:1
               (and originally defined in ‘System.IO’))
            (Some substitutions suppressed;
             use -fmax-valid-substitutions=N or -fno-max-valid-substitutions)
    ```
    
    Signed-off-by: Matthías Páll Gissurarson <mpg at mpg.is>
    
    Modified according to suggestions from Simon PJ
    
    Accept tests that match the expectations, still a few to look better at
    
    Swithced to using tcLookup, after sit down with SPJ at ICFP. Implications are WIP.
    
    Now works with polymorphism and constraints!
    
    We still need to merge the latest master, before we can make a patch.
    
    Wrap the type of the hole, instead of implication shenanigans,
    
    As per SPJs suggestion, this is simpler and feels closer to
    what we actually want to do.
    
    Updated tests with the new implementation
    
    Remove debugging trace and update documentation
    
    Reviewers: austin, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: RyanGlScott, rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3930


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

1c9208323b5ccd6796d00763ccba9d3b4a612358
 compiler/typecheck/TcEnv.hs                        |  17 +-
 compiler/typecheck/TcErrors.hs                     | 203 +++++++++++----------
 compiler/typecheck/TcRnTypes.hs                    |  15 ++
 compiler/typecheck/TcSimplify.hs                   |  20 ++
 compiler/typecheck/TcSimplify.hs-boot              |   9 +
 testsuite/tests/gadt/T12468.stderr                 |  12 ++
 testsuite/tests/ghci/scripts/T10248.stderr         |   5 +
 testsuite/tests/ghci/scripts/T10249.stderr         |   5 +
 testsuite/tests/ghci/scripts/T8353.stderr          |  70 ++++++-
 testsuite/tests/module/mod71.stderr                |   6 +
 .../partial-sigs/should_compile/T12531.stderr      |   6 +
 testsuite/tests/th/T10267.stderr                   |  35 ++++
 .../tests/typecheck/should_compile/T13050.stderr   | 160 ++++++++++++++++
 .../tests/typecheck/should_compile/T9497a.stderr   |  12 ++
 testsuite/tests/typecheck/should_compile/all.T     |  14 +-
 .../should_compile/hole_constraints.stderr         |  41 +++++
 .../should_compile/hole_constraints_nested.stderr  |  12 ++
 .../tests/typecheck/should_compile/holes.stderr    |  40 ++++
 .../tests/typecheck/should_compile/holes2.stderr   |  16 +-
 .../tests/typecheck/should_compile/holes3.stderr   |  40 ++++
 .../should_compile/valid_substitutions.stderr      |  40 +++-
 .../tests/typecheck/should_fail/T12177.stderr      |  12 ++
 .../tests/typecheck/should_fail/T9497d.stderr      |  12 ++
 .../tests/typecheck/should_run/T9497a-run.stderr   |  24 ++-
 .../tests/typecheck/should_run/T9497b-run.stderr   |  24 ++-
 .../tests/typecheck/should_run/T9497c-run.stderr   |  24 ++-
 26 files changed, 742 insertions(+), 132 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 1c9208323b5ccd6796d00763ccba9d3b4a612358


More information about the ghc-commits mailing list