<div dir="ltr">I think another way to go about this problem is to figure out an alternative to baking in DynFlags to SDocContext (which I feel is the core problem here). The only use of those DynFlags is via sdocWithDynFlags and 94 call sites use them. <br><div><br></div><div>- In the frontend, it's used to check for the presence of the flag (like suppress module prefixes, etc.)</div><div>- In the code generator, it's used to get the word size, endianness, and other platform specific stuff for platform-specific printing.<br></div><div>- Backpack-related stuff needed to get the package state</div><div>  - Used in exactly 2 cases: Outputable instances for ComponentId and InstalledUnitId</div><div><br></div><div>From what I observed with the majority of use cases, sdocWithDynFlags is used to obviate the need for passing dflags to various ppr* functions, which is a good idea since without it, we'd probably have to pass around DynFlags to a whole lot more pure functions throughout the codebase.<br></div><div><br></div><div>So as others have said, Show instances are just not practical because printing many of the GHC types is highly dependent on the platform and what flags GHC was invoked with.<br></div><div><br></div><div>There are three solutions here:</div><div>1.) Figure out a subset of DynFlags (flags, platform details, package state) and only allow those inside of SDocContext and extend SDocContext as</div><div>     new use cases come up. This is probably not practical as it would require sweeping changes.</div><div>2.) Provide a stock set of DynFlags for the purpose of printing with Outputable. It's easy to do for flags and platform details, but tricky to do for package state. This seems to be the most reasonable solution if some sane substitute for package state can be used.</div><div> <br></div><div>Syd, can you tell us what kind of things you were trying to print out? You can try to pass in unsafeGlobalDynFlags but it may not be what you want. It gets written to on the initialisation of the GHC monad and after the command line options are parsed (so everything will be properly initialised except for package state).</div><div><br></div><div>Hope that helps,</div><div>Rahul</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 19, 2017 at 1:14 AM, Edward Z. Yang <span dir="ltr"><<a href="mailto:ezyang@mit.edu" target="_blank">ezyang@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">We can't add Show instances for these types because many types<br>below them, e.g., Type, are cyclic, and would result in infinite<br>output.<br><br>Perhaps we can add a new type class which a) faithfully represents<br>the Haskell syntax, but b) can deal with cyclic data.  I think that's<br>something people would like (extra compilation time not withstanding).<br>But it sounds annoying to do since the deriving mechanism is not going<br>to help you.<br><br>Edward<br><br>Excerpts from Tom Sydney Kerckhove's message of 2017-03-18 14:03:48 +0100:<br><span class="gmail-im gmail-HOEnZb">> Dear GHC Devs,<br>><br>> I am trying to use GHC as a library but I'm having a lot of trouble with<br>> understanding what everything means.<br>> Up to now, I have been able to figure out what to do by reading the<br>> sources, but it ocured to me that much of my struggles could have been<br>> mitigated if the relevant types had Show instances.<br>><br>> I am specifically talking about the types concerning type checking.<br>> TypecheckedModule and everything below that.<br>> I am aware that most of the types have an Outputable instance, but<br>> there are two problems with that:<br>><br>> - 'Outputting' a value requires DynFlags. (yes, I know about pprTrace)<br>> - These instances are not intended to show the internal structure of a<br>>   value, but rather a 'human readable' representation of a value.<br>><br>> My questions for you:<br>><br>> - Is there a reason that there are no derived 'Show' instances for most<br>>   types?<br>> - Would you accept a diff that adds these?<br>><br>> Thank you for your time.<br>><br></span><div class="gmail-HOEnZb"><div class="gmail-h5">______________________________<wbr>_________________<br>ghc-devs mailing list<br><a href="mailto:ghc-devs@haskell.org">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-<wbr>bin/mailman/listinfo/ghc-devs</a><br></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Rahul Muttineni</div></div><div class="gmail_extra">
</div></div>