[commit: ghc] master: Expose source locations via Implicit Parameters of type GHC.Location.Location (c024af1)

git at git.haskell.org git at git.haskell.org
Mon Jan 19 22:07:38 UTC 2015


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

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

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

commit c024af131b9e2538486eb605ba8af6a8d10fe76d
Author: Eric Seidel <gridaphobe at gmail.com>
Date:   Mon Jan 19 16:08:32 2015 -0600

    Expose source locations via Implicit Parameters of type GHC.Location.Location
    
    Summary:
    IPs with this type will always be solved for the current source
    location. If another IP of the same type is in scope, the two locations will be
    appended, creating a call-stack. The Location type is kept abstract so users
    cannot create them, but a Location can be turned into a list of SrcLocs, which
    correspond to individual locations in a program. Each SrcLoc contains a
    package/module/file name and start/end lines and columns.
    
    The only thing missing from the SrcLoc in my opinion is the name of the
    top-level definition it inhabits. I suspect that would also be useful, but it's
    not clear to me how to extract the current top-level binder from within the
    constraint solver. (Surely I'm just missing something here?)
    
    I made the (perhaps controversial) decision to have GHC completely ignore
    the names of Location IPs, meaning that in the following code:
    
        bar :: (?myloc :: Location) => String
        bar = foo
    
        foo :: (?loc :: Location) => String
        foo = show ?loc
    
    if I call `bar`, the resulting call-stack will include locations for
    
    1. the use of `?loc` inside `foo`,
    2. `foo`s call-site inside `bar`, and
    3. `bar`s call-site, wherever that may be.
    
    This makes Location IPs very special indeed, and I'm happy to change it if the
    dissonance is too great.
    
    I've also left out any changes to base to make use of Location IPs, since there
    were some concerns about a snowball effect. I think it would be reasonable to
    mark this as an experimental feature for now (it is!), and defer using it in
    base until we have more experience with it. It is, after all, quite easy to
    define your own version of `error`, `undefined`, etc. that use Location IPs.
    
    Test Plan: validate, new test-case is testsuite/tests/typecheck/should_run/IPLocation.hs
    
    Reviewers: austin, hvr, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: simonmar, rodlogic, carter, thomie
    
    Differential Revision: https://phabricator.haskell.org/D578
    
    GHC Trac Issues: #9049


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

c024af131b9e2538486eb605ba8af6a8d10fe76d
 compiler/deSugar/DsBinds.hs                        |  64 +++++++-
 compiler/prelude/PrelNames.hs                      |  26 +++
 compiler/typecheck/Inst.hs                         |   2 -
 compiler/typecheck/TcBinds.hs                      |   7 +-
 compiler/typecheck/TcEvidence.hs                   | 174 ++++++++++++++++++++-
 compiler/typecheck/TcExpr.hs                       |   6 +-
 compiler/typecheck/TcHsSyn.hs                      |   7 +
 compiler/typecheck/TcInteract.hs                   |  46 +++++-
 docs/users_guide/7.12.1-notes.xml                  |  43 +++++
 docs/users_guide/glasgow_exts.xml                  |  50 ++++++
 libraries/base/GHC/SrcLoc.hs                       |  33 ++++
 libraries/base/GHC/Stack.hsc                       |  57 ++++++-
 libraries/base/base.cabal                          |   1 +
 testsuite/tests/typecheck/should_run/IPLocation.hs |  44 ++++++
 .../tests/typecheck/should_run/IPLocation.stdout   |  28 ++++
 testsuite/tests/typecheck/should_run/all.T         |   1 +
 16 files changed, 568 insertions(+), 21 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 c024af131b9e2538486eb605ba8af6a8d10fe76d


More information about the ghc-commits mailing list