summaryrefslogtreecommitdiff
path: root/docs/users_guide
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2017-05-19 14:56:09 +0200
committerAlan Zimmerman <alan.zimm@gmail.com>2017-06-04 21:54:14 +0200
commit46af88c257d4aab8912690a0b1d3ab038f160e1d (patch)
treea098b338c0c9afefe271519330dc8c0b217e62ed /docs/users_guide
parentff363bd74c8b2505b92b39d5fedcf95b8ab7365a (diff)
downloadhaskell-wip/new-tree-one-param-2.tar.gz
Udate hsSyn AST to use Trees that Growwip/new-tree-one-param-2
Summary: See https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow This commit prepares the ground for a full extensible AST, by replacing the type parameter for the hsSyn data types with a set of indices into type families, data GhcPs -- ^ Index for GHC parser output data GhcRn -- ^ Index for GHC renamer output data GhcTc -- ^ Index for GHC typechecker output These are now used instead of `RdrName`, `Name` and `Id`/`TcId`/`Var` Where the original name type is required in a polymorphic context, this is accessible via the IdP type family, defined as type family IdP p type instance IdP GhcPs = RdrName type instance IdP GhcRn = Name type instance IdP GhcTc = Id These types are declared in the new 'hsSyn/HsExtension.hs' module. To gain a better understanding of the extension mechanism, it has been applied to `HsLit` only, also replacing the `SourceText` fields in them with extension types. To preserve extension generality, a type class is introduced to capture the `SourceText` interface, which must be honoured by all of the extension points which originally had a `SourceText`. The class is defined as class HasSourceText a where -- Provide setters to mimic existing constructors noSourceText :: a sourceText :: String -> a setSourceText :: SourceText -> a getSourceText :: a -> SourceText And the constraint is captured in `SourceTextX`, which is a constraint type listing all the extension points that make use of the class. Updating Haddock submodule to match. Test Plan: ./validate Reviewers: simonpj, shayan-najd, goldfire, austin, bgamari Subscribers: rwbarton, thomie, mpickering Differential Revision: https://phabricator.haskell.org/D3609
Diffstat (limited to 'docs/users_guide')
-rw-r--r--docs/users_guide/8.4.1-notes.rst34
1 files changed, 34 insertions, 0 deletions
diff --git a/docs/users_guide/8.4.1-notes.rst b/docs/users_guide/8.4.1-notes.rst
index 72d6901d18..5929998e95 100644
--- a/docs/users_guide/8.4.1-notes.rst
+++ b/docs/users_guide/8.4.1-notes.rst
@@ -94,3 +94,37 @@ Template Haskell
``ghc`` library
~~~~~~~~~~~~~~~
+
+- hsSyn Abstract Syntax Tree (AST) is now extensible via the mechanism described in `Trees that Grow <http://www.jucs.org/jucs_23_1/trees_that_grow/jucs_23_01_0042_0062_najd.pdf>`_
+
+ The main change for users of the GHC API is that the AST is no longer indexed
+ by the type used as the identifier, but by a specific index type, ::
+
+ type GhcPs = GhcPass 'Parsed -- Old 'RdrName' type param
+ type GhcRn = GhcPass 'Renamed -- Old 'Name' type param
+ type GhcTc = GhcPass 'Typechecked -- Old 'Id' type para,
+ type GhcTcId = GhcTc -- Old 'TcId' type param
+
+ The simplest way to support the current GHC as well as earlier ones is to define ::
+
+ #if MIN_VERSION_ghc(8,3,0)
+ type ParseI = GhcPs
+ type RenameI = GhcRn
+ type TypecheckI = GhcTc
+ #else
+ type ParseI = RdrName
+ type RenameI = Name
+ type TypecheckI = Var
+ #endif
+
+ and then replace all hardcoded index types accordingly. For polymorphic types,
+ the constraint ::
+
+ #if MIN_VERSION_ghc(8,3,0)
+ -- |bundle up the constraints required for a trees that grow pass
+ type IsPass pass = (DataId pass, OutputableBndrId pass, SourceTextX pass)
+ else
+ type IsPass pass = (DataId pass, OutputableBndrId pass)
+ #endif
+
+ can be used.