[Git][ghc/ghc][wip/int-index/term-capture] Update Note

Vladislav Zavialov (@int-index) gitlab at gitlab.haskell.org
Thu Nov 23 13:36:46 UTC 2023



Vladislav Zavialov pushed to branch wip/int-index/term-capture at Glasgow Haskell Compiler / GHC


Commits:
31a4bc49 by Vladislav Zavialov at 2023-11-23T16:36:22+03:00
Update Note

- - - - -


1 changed file:

- compiler/GHC/Rename/Env.hs


Changes:

=====================================
compiler/GHC/Rename/Env.hs
=====================================
@@ -1157,11 +1157,28 @@ that up instead. If that succeeds, use it.
   A side effect of demotion is that the renamer also allows actual
   term variables to occur at the type level:
 
-     t = True
-     x = Proxy @t     -- Not good!
-
-   GHC doesn't promote arbitrary terms to types. This is rejected in the type
-   checker via tcAddTermVarPlaceholders.
+     t = True         -- Ordinary term-level binding
+     x = Proxy @t     -- (1) Bad usage in a HsExpr
+     type T = t       -- (2) Bad usage in a TyClDecl
+     f :: t -> t      -- (3) Bad usage in a SigDecl
+
+   GHC doesn't promote arbitrary terms to types, so the type checker has to
+   reject the uses of `t` shown above. This is achieved as follows:
+
+     * In the HsExpr example (1) the type checker looks up `t` in the environment,
+       finds `ATcId`, and generates a `TermVariablePE` promotion error.
+       See the following clause in `tcTyVar`:
+          ATcId{} -> promotionErr name TermVariablePE
+
+     * In the TyClDecl example (2) and SigDecl example (3), we don't have `ATcId`
+       in the environment just yet, because type declarations and signatures are
+       type-checked /before/ term-level bindings.
+
+       To report a proper user-facing error message instead of a GHC panic,
+       we proactively populate the environment with the `TermVariablePE` promotion
+       error, one for each term variable in the current HsGroup (at the top level)
+       or in the current HsValBinds (at the level of local let/where bindings).
+       This is done with tactically placed calls to `tcAddTermVarPlaceholders`.
 
 (W2) Wrinkle 2
    Only unqualified variable names are demoted, e.g. `f` but not `M.f`.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/31a4bc49f1d27bc34af613256838ffc8e3f7e20b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/31a4bc49f1d27bc34af613256838ffc8e3f7e20b
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20231123/eb7e709e/attachment-0001.html>


More information about the ghc-commits mailing list