<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-im"><p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif">OK, I must be doing something wrong then. I am now looking at Tidy (not Prep) output, and I see Core like this:</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console""> 
<span style="color:black;background:silver none repeat scroll 0% 0%">showsPrec ::</span> forall a. Show a => Int -> a -> ShowS</span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">  [GblId[ClassOp],</span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">   Arity=1,</span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">   Caf=NoCafRefs,</span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">   Str=<S!P(SL,A,A)>,</span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">   RULES: Built in rule for showsPrec: "Class op showsPrec"]</span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">  showsPrec</span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">    = \ (@a_a1G3) (v_B1 :: Show a_a1G3) -></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">        case v_B1 of v_B1 { C:Show v_B2 v_B3 v_B4 -> v_B2 }</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif">so if I’m reading this right, these
</span><span style="font-family:"Lucida Console"">v</span><span style="font-size:10pt;font-family:"Arial",sans-serif">s are still shadowing.
</span></p></span></blockquote><div><br></div><div>That looks very odd.  If that gets serialised into a .hi file it won't work at all.</div><div><br></div><div>If you can repro this with GHC, can you open a ticket for it.</div><div><br></div><div>It is true (as I discovered when spelunking as a result of this thread) that Tidy does not tidy the "implicit bindings"  See this code in GHC.Iface.Tidy:<br></div><div><br></div><div>      -- See Note [Injecting implicit bindings]<br>      all_tidy_binds = implicit_binds ++ tidy_binds'<br><br></div><div>I think we must be assuming (without documenting it) that implicit_binds already satisfies the (undocumented) output invariants of Tidy.</div><div><br></div><div>See <a href="https://gitlab.haskell.org/ghc/ghc/-/issues/21333">https://gitlab.haskell.org/ghc/ghc/-/issues/21333</a>, where I suggest improving this documentation, incl this implicit_binds assumption.  Zubin may be doing this.</div><div><br></div><div>I can't account for what you are seeing though.  <br></div><div><br></div><div>Simon<br></div>

</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 5 Apr 2022 at 05:08, Erdi, Gergo <<a href="mailto:Gergo.Erdi@sc.com">Gergo.Erdi@sc.com</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="overflow-wrap: break-word;" lang="EN-GB">
<div class="gmail-m_1939610184426309830WordSection1">
<p class="gmail-m_1939610184426309830msipheader7557e74b" style="margin:0in"><span style="font-size:9pt;font-family:"Arial",sans-serif;color:rgb(49,113,0)">PUBLIC</span><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif">Ah, it seems Tidy doesn’t traverse the bindings that are created for typeclass methods. I guess the idea is that I should be able to recreate them
 from the typeclass declaration? So how do I know 1. which bindings exactly should be saved to reconstruct my original full desugared module and 2. How do I fill in these missing pieces during reconstruction?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"><u></u> <u></u></span></p>
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> ghc-devs <<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>>
<b>On Behalf Of </b>Erdi, Gergo via ghc-devs<br>
<b>Sent:</b> Tuesday, April 5, 2022 11:09 AM<br>
<b>To:</b> Simon Peyton Jones <<a href="mailto:simon.peytonjones@gmail.com" target="_blank">simon.peytonjones@gmail.com</a>>; Gergo Érdi <<a href="mailto:gergo@erdi.hu" target="_blank">gergo@erdi.hu</a>><br>
<b>Cc:</b> GHC Devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>><br>
<b>Subject:</b> [External] RE: Re: Shadowing in toIface* output<u></u><u></u></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif">OK, I must be doing something wrong then. I am now looking at Tidy (not Prep) output, and I see Core like this:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console""> 
<span style="color:black;background:silver none repeat scroll 0% 0%">showsPrec ::</span> forall a. Show a => Int -> a -> ShowS<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">  [GblId[ClassOp],<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">   Arity=1,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">   Caf=NoCafRefs,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">   Str=<S!P(SL,A,A)>,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">   RULES: Built in rule for showsPrec: "Class op showsPrec"]<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">  showsPrec<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">    = \ (@a_a1G3) (v_B1 :: Show a_a1G3) -><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Lucida Console"">        case v_B1 of v_B1 { C:Show v_B2 v_B3 v_B4 -> v_B2 }<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif">so if I’m reading this right, these
</span><span style="font-family:"Lucida Console"">v</span><span style="font-size:10pt;font-family:"Arial",sans-serif">s are still shadowing.
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif">I am using
</span><span style="font-family:"Lucida Console"">tidyProgram</span><span style="font-size:10pt;font-family:"Arial",sans-serif"> on the output of
</span><span style="font-family:"Lucida Console"">hscSimplify</span><span style="font-size:10pt;font-family:"Arial",sans-serif">, and then taking the
</span><span style="font-family:"Lucida Console"">cg_binds</span><span style="font-size:10pt;font-family:"Arial",sans-serif"> of its result. What else should I do to get tidy (heh) Tidy output?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial",sans-serif"><u></u> <u></u></span></p>
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> ghc-devs <<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>>
<b>On Behalf Of </b>Simon Peyton Jones<br>
<b>Sent:</b> Monday, April 4, 2022 4:28 PM<br>
<b>To:</b> Gergő Érdi <<a href="mailto:gergo@erdi.hu" target="_blank">gergo@erdi.hu</a>><br>
<b>Cc:</b> GHC Devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>><br>
<b>Subject:</b> [External] Re: Shadowing in toIface* output<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div style="margin-left:30pt">
<p class="MsoNormal"><span style="font-family:"Tahoma",sans-serif">So does that mean Tidy produces unique `occNameFS`s, and then `Prep`<br>
breaks them? <u></u><u></u></span></p>
</div>
<div style="margin-left:30pt">
<p class="MsoNormal"><span style="font-family:"Tahoma",sans-serif"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Tahoma",sans-serif">Tidy does not produce unique OccNames.  Rather, it avoids
<i>shadowing</i>, so that if you delete all the uniques and print out the program (which is precisely what happens in an .hi file) you'll still get something sensible.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Tahoma",sans-serif"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Tahoma",sans-serif">I'm not sure whether or not Prep maintains this invariant.  There is no particular reason it should.  It might, but it is not (currently) a goal.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Tahoma",sans-serif"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Tahoma",sans-serif">Simon<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Sat, 2 Apr 2022 at 04:35, Gergő Érdi <<a href="mailto:gergo@erdi.hu" target="_blank">gergo@erdi.hu</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<p class="MsoNormal">So does that mean Tidy produces unique `occNameFS`s, and then `Prep`<br>
breaks them?<br>
<br>
On Fri, Apr 1, 2022 at 10:35 PM Josh Meredith<br>
<<a href="mailto:joshmeredith2008@gmail.com" target="_blank">joshmeredith2008@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I encountered this when we used that for Plutus. I'll have to dig up the details, but IIRC `toIfaceExpr` expects GHC to have already tidied the output, which deals with this issue of overlapping variable names.<br>
><br>
> Cheers,<br>
> Josh<br>
><br>
> On Sat, 2 Apr 2022 at 01:26, ÉRDI Gergő <<a href="mailto:gergo@erdi.hu" target="_blank">gergo@erdi.hu</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I'm trying to save (Prep'd) Core bindings right next to the serialized<br>
>> `ModIface` (so basically `put_`ing them into the same bytestream, after the<br>
>> `ModIface`), and that's exactly what the functions in `GHC.CoreToIface`<br>
>> seem to be for, so I expected it to Just Work. However, I noticed that I<br>
>> very frequently get problems with shadowing. For example, Core that looks<br>
>> like `\v{u1} v{u2} -> v{u1}` would get translated to `\v v -> v`, which is<br>
>> disastrous since these locally bound `Var`s are represented as just their<br>
>> `getOccFS` (i.e. the `FastString` `"v"`).<br>
>><br>
>> But this can't be right: if `toIfaceExpr` &c. would fail this blatently,<br>
>> then the unfoldings couldn't be saved & restored, which is something GHC<br>
>> itself does as part of normal `.hi` file handling. So clearly I must be<br>
>> doing something wrong.<br>
>><br>
>> So I guess my question could be, what could be causing `toIfaceExpr` (a<br>
>> pure function!) to behave this way for my Cores? But then, if I look at<br>
>> the implementation of `toIface*`, I can see that it really doesn't do<br>
>> anything smarter than just storing `getOccFS` in the interface (no<br>
>> uniques in sight)-- so maybe my *real* question is, what is GHC itself<br>
>> doing so that it doesn't have this same problem?<br>
>><br>
>> Thanks,<br>
>>         Gergo<br>
>> _______________________________________________<br>
>> ghc-devs mailing list<br>
>> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
>> <a href="https://clicktime.symantec.com/3BestP7qr2g6Y7xBfCxdDwr6xU?u=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs" target="_blank">
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
><br>
> _______________________________________________<br>
> ghc-devs mailing list<br>
> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
> <a href="https://clicktime.symantec.com/3BestP7qr2g6Y7xBfCxdDwr6xU?u=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs" target="_blank">
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="https://clicktime.symantec.com/3BestP7qr2g6Y7xBfCxdDwr6xU?u=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><u></u><u></u></p>
</blockquote>
</div>
</div>
<p class="MsoNormal"><br>
This email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please delete all copies and notify the sender immediately. You may wish to refer to the incorporation details of Standard Chartered PLC, Standard
 Chartered Bank and their subsidiaries at https: //<a href="http://www.sc.com/en/our-locations" target="_blank">www.sc.com/en/our-locations</a><br>
<br>
Where you have a Financial Markets relationship with Standard Chartered PLC, Standard Chartered Bank and their subsidiaries (the "Group"), information on the regulatory standards we adhere to and how it may affect you can be found in our Regulatory Compliance
 Statement at https: //<a href="http://www.sc.com/rcs/" target="_blank">www.sc.com/rcs/</a> and Regulatory Compliance Disclosures at http: //<a href="http://www.sc.com/rcs/fm" target="_blank">www.sc.com/rcs/fm</a><br>
<br>
Insofar as this communication is not sent by the Global Research team and contains any market commentary, the market commentary has been prepared by the sales and/or trading desk of Standard Chartered Bank or its affiliate. It is not and does not constitute
 research material, independent research, recommendation or financial advice. Any market commentary is for information purpose only and shall not be relied on for any other purpose and is subject to the relevant disclaimers available at https: //<a href="http://www.sc.com/en/regulatory-disclosures/#market-disclaimer" target="_blank">www.sc.com/en/regulatory-disclosures/#market-disclaimer</a>.<br>
<br>
Insofar as this communication is sent by the Global Research team and contains any research materials prepared by members of the team, the research material is for information purpose only and shall not be relied on for any other purpose, and is subject to
 the relevant disclaimers available at https: //<a href="http://research.sc.com/research/api/application/static/terms-and-conditions" target="_blank">research.sc.com/research/api/application/static/terms-and-conditions</a>.
<br>
<br>
Insofar as this e-mail contains the term sheet for a proposed transaction, by responding affirmatively to this e-mail, you agree that you have understood the terms and conditions in the attached term sheet and evaluated the merits and risks of the transaction.
 We may at times also request you to sign the term sheet to acknowledge the same.<br>
<br>
Please visit https: //<a href="http://www.sc.com/en/regulatory-disclosures/dodd-frank/" target="_blank">www.sc.com/en/regulatory-disclosures/dodd-frank/</a> for important information with respect to derivative products.<u></u><u></u></p>
</div>
</div>
<br clear="all">
This email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please delete all copies and notify the sender immediately. You may wish to refer to the incorporation details of Standard Chartered PLC, Standard Chartered Bank and their subsidiaries at https: //<a href="http://www.sc.com/en/our-locations" target="_blank">www.sc.com/en/our-locations</a><br>
<br>
Where you have a Financial Markets relationship with Standard Chartered PLC, Standard Chartered Bank and their subsidiaries (the "Group"), information on the regulatory standards we adhere to and how it may affect you can be found in our Regulatory Compliance Statement at https: //<a href="http://www.sc.com/rcs/" target="_blank">www.sc.com/rcs/</a> and Regulatory Compliance Disclosures at http: //<a href="http://www.sc.com/rcs/fm" target="_blank">www.sc.com/rcs/fm</a><br>
<br>
Insofar as this communication is not sent by the Global Research team and contains any market commentary, the market commentary has been prepared by the sales and/or trading desk of Standard Chartered Bank or its affiliate. It is not and does not constitute research material, independent research, recommendation or financial advice. Any market commentary is for information purpose only and shall not be relied on for any other purpose and is subject to the relevant disclaimers available at https: //<a href="http://www.sc.com/en/regulatory-disclosures/#market-disclaimer" target="_blank">www.sc.com/en/regulatory-disclosures/#market-disclaimer</a>.<br>
<br>
Insofar as this communication is sent by the Global Research team and contains any research materials prepared by members of the team, the research material is for information purpose only and shall not be relied on for any other purpose, and is subject to the relevant disclaimers available at https: //<a href="http://research.sc.com/research/api/application/static/terms-and-conditions" target="_blank">research.sc.com/research/api/application/static/terms-and-conditions</a>. <br>
<br>
Insofar as this e-mail contains the term sheet for a proposed transaction, by responding affirmatively to this e-mail, you agree that you have understood the terms and conditions in the attached term sheet and evaluated the merits and risks of the transaction. We may at times also request you to sign the term sheet to acknowledge the same.<br>
<br>
Please visit https: //<a href="http://www.sc.com/en/regulatory-disclosures/dodd-frank/" target="_blank">www.sc.com/en/regulatory-disclosures/dodd-frank/</a> for important information with respect to derivative products.<br>
</div>

</blockquote></div>