Skip to content
Snippets Groups Projects
Commit e3dc2804 authored by Eric Seidel's avatar Eric Seidel Committed by Ben Gamari
Browse files

Expose source locations via Implicit Parameters of type GHC.Location.Location

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

Cherry-Picked-From: c024af13
Cherry-Picked-By: default avatarNiklas Hambüchen <niklas@fpcomplete.com>

Changes for the cherry-pick:

* Commit d2b6e767 "Make the location in TcLclEnv and CtLoc into a RealSrcSpan"
  was cherry-picked before to ensure that
    EvCsPushCall, EvCsTop :: EvCallStack
  can indeed carry `RealSrcSpan`s instead of `SrcSpan`s.
* The use of `setWantedEvBind` was replaced by `setEvBind`, as
  `setWantedEvBind` is not yet present in 7.10.1; it was added to
  the 7.12 series in commit 32973bf3.
* docs/users_guide/7.10.1-notes.xml was adjusted to contain the
  documentation about CallStack, copied from the 7.12 notes.
parent 00cd6173
No related branches found
No related tags found
No related merge requests found
Showing
with 567 additions and 18 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment