Changes between Version 2 and Version 3 of ApiNameMap


Ignore:
Timestamp:
Nov 27, 2018 10:38:02 AM (9 months ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ApiNameMap

    v2 v3  
    33The `ParsedSource`, together with ApiAnnotations provide an accurate view of the source code for a module.  Together with supporting libraries such as `ghc-exactprint`, this allows tool writers to make changes to the source, by manipulating the `ParsedSource`, and then using `ghc-exactprint` to generate haskell source code reflecting the changes made, but with nothing else changed. So it preserves layout, comments and so on.
    44
     5Note: `ParsedSource` is defined, in module `GHC` thus
     6{{{
     7type ParsedSource      = Located (HsModule GhcPs)
     8}}}
     9
    510The `ParsedSource` serves as input to the renamer, generating a different AST, which has most names resolved (except the ones for overloaded record fields).  But in the process, it is changed sufficiently that it can no longer be used as an accurate reflection of the original source code, in terms of layout, comments and so on.
     11
     12''SPJ: would one possibility to ensure that it can be used as an "accurate reflection of the original source code"?   How hard would that be?  It's very close isn't it?  Parentheses are maintained.  Things like `HsWrap` and `AbsBinds` can easily be discarded.''
    613
    714So the problem a tool writer faces is that they have the `ParsedSource` which accurately represents the original source, and should be changed to modify the original source, and the ASTs from the renamer and typechecker which fully capture the `Name` information for every identifier in the module.
    815
    916Many manipulations require access to this later stage information, but as things stand now (GHC 8.6.2) there is no simple way to tie up a `RdrName` from the `ParsedSource` with a `Name` in the `RenamedSource`.
     17
     18''SPJ: I don't understand clearly enough what you mean.''  Perhaps you mean:
     19* given a particular `RdrName` occurring in the `ParsedSource`  --- perhaps at a binding site, perhaps at an occurrence site -- find the `Name` that the reamer makes for it.
     20But
     21* The `Name` alone may not be much use.  Don't you want the `Id` or `TyCon` or `Class` or whatever?
     22* Moreover, it's possible that the renamer may re-use the same `Name` more than once.  (It doesn't do this much if at all, I agree, but still.)
     23* Do you intend this for nested situations; e.g
     24{{{
     25f x = let y = x+1
     26      in y+x
     27}}}
     28  and point to the `RdrName` occurrence of `y` in `y+x`?
     29
     30Perhaps you intend this only for top-level stuff?
     31''End SPJ''
    1032
    1133=== Possible Solutions