<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>I was thinking about the relationship between the wiki and the
notes in the GHC source.</p>
<p>Would it be possible to link directly to [compiler notes] in the
GHC source from the wiki, using hyperlinks? Right now, I'm seeing
references that look like: (See <code>Note [Constraint flavours]</code>.)</p>
<p>(I can see the motivation to include comments in the source, but
I also think that the wiki is more discoverable than the compiler
source code. So, in the interests of pursuing both approaches, it
would be nice to be able to link to notes FROM the wiki. I
suppose one could include a hyperlink to the file on github that
contains the note...)</p>
<p>I'm not sure how much web infrastructure would be required to
make hyperlinks for notes...<br>
</p>
<p>-BenRI<br>
</p>
<div class="moz-cite-prefix">On 11/8/21 5:35 AM, Simon Peyton Jones
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:AM9PR83MB0483BB7F13B5B4A0D5ED9E16AD919@AM9PR83MB0483.EURPRD83.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
font-size:10.0pt;
font-family:"Courier New";}p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}span.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}div.WordSection1
{page:WordSection1;}ol
{margin-bottom:0cm;}ul
{margin-bottom:0cm;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p style="margin-left:36.0pt">Is there anywhere on the GHC wiki
that explains how to interpret this output, and says that the
type and dictionary applications ARE there, just not shown by
'-ddump-tc'?<o:p></o:p></p>
<p style="margin-left:36.0pt">Perhaps it would be helpful to add
some basic description of what comes out of the typechecker to
a page like this one? (below)<o:p></o:p></p>
<p style="margin-left:36.0pt"> <a
href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2F-%2Fwikis%2Fcommentary%2Fcompiler%2Fhsc-main&data=04%7C01%7Csimonpj%40microsoft.com%7Cab59b17d2f394945ad1e08d9a2b96c81%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637719740212483767%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=WZL1VADZPUlaOACd58K1XZO5MzPOKrfLFMSuBD%2FGW44%3D&reserved=0"
moz-do-not-send="true">
https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hsc-main</a><o:p></o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Yes
it would! Would you care to start such a wiki page (a new
one; don’t just clutter up the one you point to)? You can
write down what you know. Don’t worry if you aren’t 100%
sure – we can correct it. And if you outright don’t know,
leave a “What should I say here?” note.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p style="margin-left:36.0pt">"This late desugaring is somewhat
unusual. It is much more common to desugar the program before
typechecking, or renaming, because that presents the renamer
and typechecker with a much smaller language to deal with.
However, GHC's organisation means that<o:p></o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">This
note is now slightly out of date. We are now, very
carefully, doing some desugaring
<b>before</b> typechecking. See<o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph"
style="margin-left:0cm;mso-list:l1 level1 lfo2"><span
style="mso-fareast-language:EN-US">Note [Handling
overloaded and rebindable constructs] in GHC.Rename.Expr<o:p></o:p></span></li>
<li class="MsoListParagraph"
style="margin-left:0cm;mso-list:l1 level1 lfo2"><span
style="mso-fareast-language:EN-US">Note [Rebindable syntax
and HsExpansion] in GHC.Hs.Expr<o:p></o:p></span></li>
</ul>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">You
can and should point to these and similar Notes from the
wiki page you write. Indeed there may be some part of what
you write that would be better framed as Note in GHC’s
source code.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Thanks!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Simon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:8.0pt">PS: I am
leaving Microsoft at the end of November 2021, at which
point
<a href="mailto:simonpj@microsoft.com"
moz-do-not-send="true"><span style="color:#0563C1">simonpj@microsoft.com</span></a>
will cease to work. Use
<a href="mailto:simon.peytonjones@gmail.com"
moz-do-not-send="true"><span style="color:#0563C1">simon.peytonjones@gmail.com</span></a>
instead. (For now, it just forwards to
<a class="moz-txt-link-abbreviated" href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>.)<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm
0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span
lang="EN-US"> ghc-devs
<a class="moz-txt-link-rfc2396E" href="mailto:ghc-devs-bounces@haskell.org"><ghc-devs-bounces@haskell.org></a>
<b>On Behalf Of </b>Benjamin Redelings<br>
<b>Sent:</b> 08 November 2021 13:12<br>
<b>To:</b> Richard Eisenberg
<a class="moz-txt-link-rfc2396E" href="mailto:lists@richarde.dev"><lists@richarde.dev></a><br>
<b>Cc:</b> <a class="moz-txt-link-abbreviated" href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Re: Output language of typechecking
pass?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>Hi,<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>Questions:<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>1. It seems like this separation is actually necessary, in order to apply generalization only to let arguments written by the programmer, and not to let bindings introduced during desugaring. Is that right?<o:p></o:p></pre>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>I don't think so. That is, if we did it all in one pass, I still think we could get generalization right.<o:p></o:p></pre>
</blockquote>
<p>I guess I asked this question wrong. I mean to say, if we
did the two passes in the reverse order (desugaring first,
followed by typechecking), that would not work, right?<o:p></o:p></p>
<p>As the wiki says:<o:p></o:p></p>
<p>"This late desugaring is somewhat unusual. It is much more
common to desugar the program before typechecking, or
renaming, because that presents the renamer and typechecker
with a much smaller language to deal with. However, GHC's
organisation means that<o:p></o:p></p>
<ul type="disc">
<li class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0
level1 lfo1">
error messages can display precisely the syntax that the
user wrote; and<o:p></o:p></li>
<li class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0
level1 lfo1">
desugaring is not required to preserve type-inference
properties.<o:p></o:p></li>
</ul>
<p>"<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>2. Does the output of type checking contain type lambdas?<o:p></o:p></pre>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>Yes. See below.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>3. Does the type checking pass determine where to add dictionary arguments?<o:p></o:p></pre>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>Yes. See below.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>4. Are there any other resources I should be looking at?<o:p></o:p></pre>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>Yes. You want to enable -fprint-typechecker-elaboration (and possible -fprint-explicit-coercions). With the former, you get to see all this stuff you're looking for. It's normally suppressed so that the output resembles the user's code.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>I hope this helps!<o:p></o:p></pre>
<pre>Richard<o:p></o:p></pre>
</blockquote>
<p>Hmm... so, I think I see how this works now. I don't think
'-fprint-explicit-coercions' does anything here though.<o:p></o:p></p>
<p>$ ghc -ddump-tc Test2.hs -fprint-typechecker-elaboration<o:p></o:p></p>
<p>...<o:p></o:p></p>
<p>AbsBinds [a_a2hp] [$dNum_a2hB]<br>
{Exports: [g <= g_a2hz<br>
wrap: <>]<br>
Exported types: g :: forall a. Num a => a -> a
-> a<br>
[LclId]<br>
Binds: g x_aYk y_aYl = (y_aYl * x_aYk) + 1<br>
Evidence: [EvBinds{[W] $dNum_a2hs = $dNum_a2hq<br>
[W] $dNum_a2hw = $dNum_a2hq<br>
[W] $dNum_a2hq = $dNum_a2hB}]}<o:p></o:p></p>
<p>...<o:p></o:p></p>
<p>The type and dictionary arguments are visible here (along
with the evidence bindings), but type and dictionary
applications are only visible if you use -ddump-tc-ast,
which is a lot more verbose. (I don't think there is
another flag that shows these applications?) Since I didn't
initially know what "evidence" was, and there is nothing to
say that a_a2hp is a type lambda argument, this was pretty
opaque until I managed to read the tc-ast and the light went
on.<o:p></o:p></p>
<p>I can see now that the type and dictionary arguments are
added by annotating the AST.<o:p></o:p></p>
<p>Is there anywhere on the GHC wiki that explains how to
interpret this output, and says that the type and dictionary
applications ARE there, just not shown by '-ddump-tc'?<o:p></o:p></p>
<p>Perhaps it would be helpful to add some basic description
of what comes out of the typechecker to a page like this
one? (below)<o:p></o:p></p>
<p> <a
href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2F-%2Fwikis%2Fcommentary%2Fcompiler%2Fhsc-main&data=04%7C01%7Csimonpj%40microsoft.com%7Cab59b17d2f394945ad1e08d9a2b96c81%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637719740212483767%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=WZL1VADZPUlaOACd58K1XZO5MzPOKrfLFMSuBD%2FGW44%3D&reserved=0"
moz-do-not-send="true">
https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hsc-main</a><o:p></o:p></p>
<p>-BenRI<o:p></o:p></p>
<p><o:p> </o:p></p>
</div>
</div>
</blockquote>
</body>
</html>