[GHC] #15495: Handling Source Locations via TTG
GHC
ghc-devs at haskell.org
Thu Aug 9 12:00:53 UTC 2018
#15495: Handling Source Locations via TTG
-------------------------------------+-------------------------------------
Reporter: Shayan-Najd | Owner: (none)
Type: task | Status: new
Priority: normal | Milestone: ⊥
Component: Compiler | Version:
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
== Problem ==
The current implementation of
[https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/TreesThatGrowGuidance
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:
a. 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.
b. 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
[https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/HandlingSourceLocations
the related wiki page].
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15495>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list