Opened 14 months ago

Last modified 10 months ago

#15495 new task

Handling Source Locations via TTG

Reported by: Shayan-Najd Owned by:
Priority: normal Milestone:
Component: Compiler Version:
Keywords: Cc: alanz, simonpj, bgamari
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D5036
Wiki Page:

Description

Problem

The current implementation of TTG HsSyn AST in GHC stores source locations for terms of a datatype Exp in a separate wrapper datatype LExp which is mutually recursive with Exp such that every recursive reference to Exp is done indirectly, via a reference to the wrapper datatype LExp (see the example code below). We refer to this style of storing source locations as the ping-pong style.

Besides the indirection and the resulting complications of the ping-pong style, there are two key problems with it:

  1. It bakes-in the source locations in the base TTG AST, forcing all instances to store source locations, even if they don't need them.For example, TH AST does not carry source locations, or even within GHC, there are generated terms without source locations.
  1. It results in a form of conceptual redundancy: source locations are tree decorations and they belong in the extension points. (see https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/TreesThatGrowGuidance TTG Guidance])

Solution

We can move the source location decorations to a wrapper constructor and remove the ping-pong style. This can be done smoothly, mechanically, and gradually by using a getter/setter methods for source locations. More details can be found at the related wiki page.

Change History (6)

comment:1 Changed 13 months ago by simonpj

Branch wip/az-D5036 I believe.

comment:2 Changed 13 months ago by alanz

I am still looking for the haddock changes though.

comment:3 Changed 11 months ago by simonpj

Differential Rev(s): Phab:D5036

comment:4 Changed 11 months ago by alanz

The buildable version, with haddock changes, is at wip/az-D5036-2. It has also been rebased to master of 2 days ago.

comment:5 Changed 10 months ago by Shayan-Najd

The latest validated version is at wip/shnajd-TTG-SrcLocs in both https://github.com/shayan-najd/ghc and https://github.com/shayan-najd/haddock

comment:6 Changed 10 months ago by Alan Zimmerman <alan.zimm@…>

In 509d5be6/ghc:

[TTG: Handling Source Locations] Foundation and Pat

This patch removes the ping-pong style from HsPat (only, for now),
using the plan laid out at
https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/HandlingSourceLocations (solution
A).

- the class `HasSrcSpan`, and its functions (e.g., `cL` and `dL`), are introduced
- some instances of `HasSrcSpan` are introduced
- some constructors `L` are replaced with `cL`
- some patterns `L` are replaced with `dL->L` view pattern
- some type annotation are necessarily updated (e.g., `Pat p` --> `Pat (GhcPass p)`)

Phab diff: D5036
Trac Issues #15495

Updates haddock submodule
Note: See TracTickets for help on using tickets.