I’m not sure why you expect it to be so slow? When developing refactoring tasks for HLS I have never noticed big latencies, even when performing multiple generic traversals over a full module.<div><br></div><div>You might have some success by specializing or inking the definition, so that GHC can optimize the traversal generated. <br><div><br></div><div>Best</div><div><br></div><div>Santi<br><div><br>On Friday, 27 January 2023, Facundo Domínguez <<a href="mailto:facundo.dominguez@tweag.io">facundo.dominguez@tweag.io</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">https://hackage.haskell.org/<wbr>package/ghc-9.0.2/docs/GHC.<wbr>html#t:ParsedModule</a><br></div><div><br></div><div><br></div><div><br></div></div></div>
</blockquote></div></div></div>