<div dir="ltr">How feasible would it be to use something like <a href="https://jsonlines.org/">https://jsonlines.org/</a> ? (In short, newline-delimited json values.) This could be in addition to any future single-json-value output format, or as a stepping stone to that goal.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 10 Jul 2023 at 00:46, Ben Bellick via ghc-devs <<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-family:Arial,sans-serif;font-size:14px">Hey everyone, </div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">I am working on a summer of Haskell project to implement JSON output of GHC's diagnostics. I have begun working through some of the implementation details but have stumbled across a few road blocks and I wanted to get some feedback on. Discussion surrounding the plan can be found <a title="here" href="https://github.com/haskellfoundation/tech-proposals/pull/50" rel="noreferrer nofollow noopener" target="_blank">here</a>.</div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">In looking through the current implementation of the <code>-ddump-json</code>​ flag, I found a <a title="note" href="https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/Utils/Logger.hs#L392" rel="noreferrer nofollow noopener" target="_blank">note</a>  which seems to indicate that a sensible (albeit invasive) approach is to alter the definition of <code><a title="LogAction" href="https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/Utils/Logger.hs#L174" rel="noreferrer nofollow noopener" target="_blank">LogAction</a><span style="font-family:Arial,sans-serif">, reproduced below:</span></code></div><div style="font-family:Arial,sans-serif;font-size:14px"><pre lang="haskell"><span lang="haskell"><span><span>type</span><span> </span><span>LogAction</span><span> = </span><span>LogFlags</span></span><span></span></span>
<span lang="haskell"><span>              </span><span>-></span><span> </span><span>MessageClass</span><span></span></span>
<span lang="haskell"><span>              </span><span>-></span><span> </span><span>SrcSpan</span><span></span></span>
<span lang="haskell"><span>              </span><span>-></span><span> </span><span>SDoc</span><span></span></span>
<span lang="haskell"><span>              </span><span>-></span><span> </span><span>IO</span><span> ()</span></span>
</pre>So instead of taking in an <code>SDoc</code>​, I could alter this signature to take a set of <code>Diagnostic</code>​s, though this may introduce other complications. In the first place, it seems log action is processing all of the diagnostics one at a time, though this particular JSON output should process all of them at once in order to place them all in a single JSON object. So, I am inclined to believe that this approach may not work. </div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">Another approach could be the one originally tried and mentioned in the note linked above, which is to keep track of all diagnostics in an <code>IORef</code>​, and use this to produce a final JSON result at the end of GHC's execution. This approach seems invasive in a different way.</div><div style="font-family:Arial,sans-serif;font-size:14px"><br>Does anyone familiar with the handling of diagnostics throughout the compiler have any suggestions on how best to implement such a feature? </div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">You can find the work that I have done so far <a title="here" href="https://gitlab.haskell.org/benbellick/ghc/-/compare/master...json-diag-dump" rel="noreferrer nofollow noopener" target="_blank">here</a>. All I am really doing is checking if the new flag is set in <code><a href="https://gitlab.haskell.org/benbellick/ghc/-/compare/master...json-diag-dump#2c680115d7e70b54a18c48be02dce2d676eaf4f8_17_18" title="printMessages" target="_blank">printMessages</a></code>. If it is, then I simply invoke the <code>json</code>​ function of the <code>ToJson</code>​ typeclass and use that to print the diagnostic.</div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">It is currently a bit messy, but I wanted to just see if the path that I am taking seems fruitful or if there are any obvious hurdles that I am not seeing. Thanks so much!</div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div>
<div style="font-family:Arial,sans-serif;font-size:14px">
    <div>
        <div>Best, <br></div><div>Ben Bellick</div>
    </div>

            <div>

            </div>
</div>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div>