<div dir="ltr"><div dir="ltr">Dear GHC devs,<div><br></div><div>I'm trying to port Liquid Haskell to ghc 9.2.5. And having much difficulty using the GHC API for a specific task, so I come here to ask about it.</div><div><br></div><div>As you may know already, Liquid Haskell needs to read special comments from Haskell source code which have the form {-@ ... @-}.</div><div><br></div><div>For example</div><div><br></div><div>> module Demo.Lib where<br></div><div>><br>> {-@ type Pos = {v:Int | 0 < v} @-}<br>><br>> {-@ incr :: Pos -> Pos @-}<br>> incr :: Int -> Int<br>> incr x = h x</div><div>>   where</div><div>>      {-@ h :: Pos -> Pos @-}</div><div>>      h x = x - 1<br></div><div><br></div><div>Since Liquid Haskell runs as a GHC plugin, it has access to the GHC API. It used to be the case that one could find all of the comments together with their source spans in a field</div><div><br></div><div>pm_annotations :: ParsedModule -> ApiAnns -- [1]</div><div><br></div><div>However this field has been removed in ghc-9.2, and now the comments are all spread through the AST after parsing.</div><div><br></div><div>I managed to collect them all again with a generic traversal:</div><div><br></div><div><div>> go :: forall a. Data a => a -> [LEpaComment]</div><div>> go = gmapQr (++) [] go `extQ` (id @[LEpaComment])</div></div><div><br></div><div>but I'd expect this to be rather slow. So I'd like to ask here, is there a better way to collect all of the comments?</div><div><br></div><div>The other obvious way would be to write the traversal manually, but it would be some code to write, and it would likely need attention when porting to newer GHCs onwards.</div><div><br></div><div>Thanks!</div><div>Facundo</div><div><br></div><div>[1]: <a href="https://hackage.haskell.org/package/ghc-9.0.2/docs/GHC.html#t:ParsedModule">https://hackage.haskell.org/package/ghc-9.0.2/docs/GHC.html#t:ParsedModule</a><br></div><div><br></div><div><br></div><div><br></div></div></div>