Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binds of a HsLet ignore the location of HsLocalBinds #56

Open
ocharles opened this issue Sep 13, 2017 · 0 comments
Open

Binds of a HsLet ignore the location of HsLocalBinds #56

ocharles opened this issue Sep 13, 2017 · 0 comments

Comments

@ocharles
Copy link

To recap our conversation on IRC:

11:47 <ocharles> alanz, mpickering: I'm looking at doing pretty printing with just ghc-exactprint - essentially just moving DPs around to get the formatting I want. It's pretty cool! But I have a q... ghc-exactprint seems to discard some locations, and I wonder why
11:47 <ocharles> for example, Annotate for HsLet in HsExpr ignores the location of the binds of the let statement, so this doesn't do anything:
11:48 <alanz> ocharles: have you looked at brittany? Does a similar thing
11:48 <ocharles> case expr of HsLet binds body -> setEntryDPT binds (DP (100000, 0))
11:48 <ocharles> alanz: yep, I know of brittany, but brittany actually does the printing itself
11:48 <alanz> ocharles: which GHC version?
11:48 <ocharles> I wanted to do nothing except move deltas around
11:49 <ocharles> 8.0.2
11:50 <ocharles> alanz: but https://github.com/alanz/ghc-exactprint/blob/master/src-ghc82/Language/Haskell/GHC/ExactPrint/Annotater.hs#L1877 seems problematic, it just discards the srcspan of the binds
11:51 <alanz> ok, you need to look in the src-ghc80 dir
11:51 <alanz> which is the same
11:51 <alanz> also discards the location
11:51 <ocharles> right
11:52 <alanz> That location was added to allow indexing the list by it, so it could move independently
11:52 <alanz> but before that the engine was set up to ignore it
11:52 <alanz> and I have not gone back to make use of it yey
11:52 <alanz> yet
11:52 <ocharles> ok, so this could be considered a bug?
11:52 <ocharles> hsmodName is similarly affected, setting the entry DP of that doesn't do anything
11:52 <alanz> There was some technical issue about managing the list in the surrounding scope, and breaking existing behaviuour
11:53 <ocharles> and I haven't tried transforming much more than that :)
11:53 <alanz> Well, it is more of a feature at the moment :(
11:53 <alanz> The thing it to look at the Annotater code and see what is used, and work from there
11:54 <alanz> You can also call showAnnData to see exactly what annotations exist
11:54 <ocharles> my use case is I want to "swing" bindings of a let statement under the let, so `let x =` becomes `let\n<space><space>x =`. Right now I'm doing that by using the first location of the binds, but that breaks if the let statement opens with a type signature
11:54 <alanz> What I normally do is run a test with the "from" source code, look at what I get, then with the manually formatted new one, and compare
11:55 <alanz> And that should be possible (it is a design goal), but you need to check what to work with
11:55 <alanz> (my brain is a bit rusty)
11:56 <alanz> iirc, I originally wanted the indent to be on the location of the binds, then each could start at zero and be freely re-arranged
11:56 <alanz> But that is not what ended up in the code, and it needs to be fixed
11:57 <alanz> The "setLayoutFlag" triggers the indentation, by the way
11:57 <alanz> no, sorry, markLocalBindsWithLayout
11:58 <ocharles> so far I haven't written my own interpreter for Annotate because I'm hoping the Print module should be sufficient
11:58 <alanz> it should be
11:59 <alanz> The problem you are seeing comes because the HsLet binds are not decls, so are split into sigs and binds
11:59 <alanz> which means you end up with this: https://github.com/alanz/ghc-exactprint/blob/master/src-ghc80/Language/Haskell/GHC/ExactPrint/Annotater.hs#L1738
11:59 <ocharles> well, that would be one explanation. my expectation was that each dp of the binds (and sigs) are relative to the dp of the whole HsLocalBinds
12:00 <alanz> that is what I want to see too.
12:00 <alanz> Unfortunately it did not happen originally, and needs to be retrofitted to be that way
12:00 <ocharles> ok, if we're in agreement there then I will at least open an issue
12:00 <alanz> please do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant