Skip to content

Handling Source Locations via TTG

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:

  • 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.

  • It results in a form of conceptual redundancy: source locations are tree decorations and they belong in the extension points.

These issues are discussed in

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.

Trac metadata
Trac field Value
Version
Type Task
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC alanz, bgamari, simonpj
Operating system
Architecture
Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information