[Git][ghc/ghc][master] Expand on the need to clone local binders.

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Nov 15 03:20:48 UTC 2022



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
78f7ecb0 by Andreas Klebinger at 2022-11-14T22:20:29-05:00
Expand on the need to clone local binders.

Fixes #22402.

- - - - -


2 changed files:

- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Stg/Subst.hs


Changes:

=====================================
compiler/GHC/CoreToStg/Prep.hs
=====================================
@@ -112,6 +112,17 @@ The goal of this pass is to prepare for code generation.
     and doing so would be tiresome because then we'd need
     to substitute in types and coercions.
 
+    We need to clone ids for two reasons:
+    + Things associated with labels in the final code must be truly unique in
+      order to avoid labels being shadowed in the final output.
+    + Even binders without info tables like function arguments or alternative
+      bound binders must be unique at least in their type/unique combination.
+      We only emit a single declaration for each binder when compiling to C
+      so if binders are not unique we would either get duplicate declarations
+      or misstyped variables. The later happend in #22402.
+    + We heavily use unique-keyed maps in the backend which can go wrong when
+      ids with the same unique are meant to represent the same variable.
+
 7.  Give each dynamic CCall occurrence a fresh unique; this is
     rather like the cloning step above.
 


=====================================
compiler/GHC/Stg/Subst.hs
=====================================
@@ -12,6 +12,13 @@ import GHC.Utils.Outputable
 import GHC.Utils.Misc
 import GHC.Utils.Panic
 
+-- TODO: This code might make folly of the work done in CorePrep where
+-- we clone local ids in order to ensure *all* local binders are unique.
+-- It's my understanding that here we use "the rapier"/uniqAway which makes up
+-- uniques based on the ids in scope. Which can give the same unique to different
+-- binders as long as they are in different scopes. A guarantee which isn't
+-- strong enough for code generation in general. See Note [CorePrep Overview].
+
 -- | A renaming substitution from 'Id's to 'Id's. Like 'RnEnv2', but not
 -- maintaining pairs of substitutions. Like 'GHC.Core.Subst.Subst', but
 -- with the domain being 'Id's instead of entire 'CoreExpr'.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/78f7ecb053340388236300e7e8d458a1a5a42344

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/78f7ecb053340388236300e7e8d458a1a5a42344
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/20221114/88bbad77/attachment-0001.html>


More information about the ghc-commits mailing list