... | ... | @@ -25,7 +25,7 @@ This will allow the core `ghc-exacprint` functionality to also move into GHC, me |
|
|
The existing API Annotations are only kept if requested, as they impose a space penalty which need not be paid under all circumstances, especially when simply compiling code to generate a library / exe.
|
|
|
|
|
|
|
|
|
A way to avoid this penalty, and to allow the additional information stored to grow relatively freely without having to worry too much about optimising the straight compilation process, is to have two variants of the AST, one for the straight (batch) compilation, and one for the interactive one.
|
|
|
A way to avoid this penalty, and to allow the additional information stored to grow relatively freely without having to worry too much about optimising the straight compilation process, is to have two variants of the AST, one for compiling with Api Annotations, one for without, as selected by using the `Opt_KeepRawTokenStream` dynamic flag, as used at present.
|
|
|
|
|
|
|
|
|
This can be achieved by making use of the mechanics listed below. If it turns out that the penalty is moderate, and the additional complexity of having two variants is not worth it, this step need not be taken.
|
... | ... | @@ -38,17 +38,20 @@ This can be achieved by making use of the mechanics listed below. If it turns ou |
|
|
`hsSyn/HsExtension.hs` would be extended to
|
|
|
|
|
|
```
|
|
|
-- | Used as a data type index for the hsSyn ASTdataGhcPass(c ::Pass)dataPass=ParsedProcess|Renamed|TypecheckeddataProcess=Batch|InteractivetypeGhcPs=GhcPass('Parsed'Batch)typeGhcPsI=GhcPass('Parsed'Interactive)
|
|
|
-- | Used as a data type index for the hsSyn ASTdataGhcPass(c ::Pass)dataPass=ParsedProcess|Renamed|TypecheckeddataProcess=WithApiAnnotations|WithoutApiAnnotationstypeGhcPs=GhcPass('Parsed'WithoutApiAnnotations)typeGhcPsI=GhcPass('Parsed'WithApiAnnotations)
|
|
|
```
|
|
|
|
|
|
|
|
|
So the current `GhcPs` synonym would still indicate the (normal) batch compilation process, and the new one `GhcPsI` reflects the compiler invoked in interactive mode.
|
|
|
So the current `GhcPs` synonym would still indicate the (normal) batch compilation process without Api Annotations, and the new one `GhcPsI` reflects the compiler invoked to generate the Api Annotations.
|
|
|
|
|
|
|
|
|
Since the key feature of Trees that Grow is that different extensions to the AST can be defined based on the index type used, it means that a set of extension types capturing the requirements for the `ghc-exactprint` capable Api Annotations can be defined.
|
|
|
|
|
|
|
|
|
This means the relevant information is stored directly in the AST, making modification of the AST while preserving layout and comments by tooling much simpler.
|
|
|
This means the relevant information is stored directly in the AST, making modification of the AST while preserving layout and comments by tooling much simpler.
|
|
|
|
|
|
|
|
|
There would still be a single parser definition in `Parser.y`, which would make use of functions to add the additional info to the generated source tree, which would be NOPs if the information was not being kept. This is similar to what happens at present with the Api Annotations.
|
|
|
|
|
|
## Phasing
|
|
|
|
... | ... | |