Exact Print Annotations : Anchor in a SrcSpan

Simon Peyton Jones simonpj at microsoft.com
Fri Oct 29 14:43:02 UTC 2021


I'm way behind with this exact-print stuff and Anchors in particular.

If you and your co-workers on it are confident you know what to do, that's great - although as ever, please document the design carefully.   (I volunteer as a reader of such a design overview.  I know that a current draft exists.)

If you want a design discussion with others less closely involved then do suggest it --  probably a synchronous meeting with a tutorial element would be helpful.

thanks for working on this in such a sustained way.


PS: I am leaving Microsoft at the end of November 2021, at which point simonpj at microsoft.com<mailto:simonpj at microsoft.com> will cease to work.  Use simon.peytonjones at gmail.com<mailto:simon.peytonjones at gmail.com> instead.  (For now, it just forwards to simonpj at microsoft.com.)

From: ghc-devs <ghc-devs-bounces at haskell.org> On Behalf Of Alan & Kim Zimmerman
Sent: 28 October 2021 22:18
To: ghc-devs <ghc-devs at haskell.org>
Subject: Exact Print Annotations : Anchor in a SrcSpan

I have been updating the ghc-exactprint library for real world use cases on the about to be released GHC 9.2.1, and realised I need to be able to put an Anchor into every SrcSpan in the ParsedSource AST.

I prepared !6854 to sort it out in master and turned to the problem of GHC 9.2.1, where I had missed the boat.

And then I discovered that we have SrcSpan defined as

    data SrcSpan =
        RealSrcSpan !RealSrcSpan !(Maybe BufSpan)
      | UnhelpfulSpan !UnhelpfulSpanReason

and the (Maybe BufSpan) is only used for attaching haddock comments after parsing.

This means there is an isomorphism between the RealSrcSpan variant and an Anchor, which I take advantage of with the code in [1], by using the Maybe to encode the AnchorOperation and the BufSpan to encode the DeltaPos.

And it struck me that perhaps we should make this a more official approach.  The only problem is the detail of the BufSpan, to be able to play both roles cleanly.


[1] https://gist.github.com/alanz/5e262599ab79138606cdfcf3792ef635<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgist.github.com%2Falanz%2F5e262599ab79138606cdfcf3792ef635&data=04%7C01%7Csimonpj%40microsoft.com%7Cd10e614607c843649c4108d99a587f99%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637710527929989318%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=4KMwfrLhB7lxKPsiSJ5UobLbEul7OEvT4CiPI8NOzu4%3D&reserved=0>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20211029/1748b7f6/attachment.html>

More information about the ghc-devs mailing list