Output language of typechecking pass?
Simon Peyton Jones
simonpj at microsoft.com
Mon Nov 8 13:35:24 UTC 2021
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'?
Perhaps it would be helpful to add some basic description of what comes out of the typechecker to a page like this one? (below)
https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hsc-main<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>
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.
"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
This note is now slightly out of date. We are now, very carefully, doing some desugaring before typechecking. See
* Note [Handling overloaded and rebindable constructs] in GHC.Rename.Expr
* Note [Rebindable syntax and HsExpansion] in GHC.Hs.Expr
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.
Thanks!
Simon
PS: I am leaving Microsoft at the end of November 2021, at which point simonpj at microsoft.com<mailto:simonpj at microsoft.com> will cease to work. Use simon.peytonjones at gmail.com<mailto:simon.peytonjones at gmail.com> instead. (For now, it just forwards to simonpj at microsoft.com.)
From: ghc-devs <ghc-devs-bounces at haskell.org> On Behalf Of Benjamin Redelings
Sent: 08 November 2021 13:12
To: Richard Eisenberg <lists at richarde.dev>
Cc: ghc-devs at haskell.org
Subject: Re: Output language of typechecking pass?
Hi,
Questions:
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?
I don't think so. That is, if we did it all in one pass, I still think we could get generalization right.
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?
As the wiki says:
"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
* error messages can display precisely the syntax that the user wrote; and
* desugaring is not required to preserve type-inference properties.
"
2. Does the output of type checking contain type lambdas?
Yes. See below.
3. Does the type checking pass determine where to add dictionary arguments?
Yes. See below.
4. Are there any other resources I should be looking at?
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.
I hope this helps!
Richard
Hmm... so, I think I see how this works now. I don't think '-fprint-explicit-coercions' does anything here though.
$ ghc -ddump-tc Test2.hs -fprint-typechecker-elaboration
...
AbsBinds [a_a2hp] [$dNum_a2hB]
{Exports: [g <= g_a2hz
wrap: <>]
Exported types: g :: forall a. Num a => a -> a -> a
[LclId]
Binds: g x_aYk y_aYl = (y_aYl * x_aYk) + 1
Evidence: [EvBinds{[W] $dNum_a2hs = $dNum_a2hq
[W] $dNum_a2hw = $dNum_a2hq
[W] $dNum_a2hq = $dNum_a2hB}]}
...
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.
I can see now that the type and dictionary arguments are added by annotating the AST.
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'?
Perhaps it would be helpful to add some basic description of what comes out of the typechecker to a page like this one? (below)
https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hsc-main<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>
-BenRI
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20211108/e51a9c8b/attachment.html>
More information about the ghc-devs
mailing list