diff options
author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2022-11-09 19:16:09 +0100 |
---|---|---|
committer | Andreas Klebinger <klebinger.andreas@gmx.at> | 2022-11-09 19:16:19 +0100 |
commit | 9b9c89c7bdaf22b75f6295c3b9230c88bbd1b4c5 (patch) | |
tree | a5cd37b52b9bf227f41a59b40a4b350f3cb2f235 | |
parent | 90c5abd4581b404f715e72ad55303e18d0c31d68 (diff) | |
download | haskell-9b9c89c7bdaf22b75f6295c3b9230c88bbd1b4c5.tar.gz |
Expand on the need to clone local binders.wip/andreask/cmm_invariants
Fixes #22402.
-rw-r--r-- | compiler/GHC/CoreToStg/Prep.hs | 11 | ||||
-rw-r--r-- | compiler/GHC/Stg/Subst.hs | 7 |
2 files changed, 18 insertions, 0 deletions
diff --git a/compiler/GHC/CoreToStg/Prep.hs b/compiler/GHC/CoreToStg/Prep.hs index 9ca8bff0c9..2be595e8d4 100644 --- a/compiler/GHC/CoreToStg/Prep.hs +++ b/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. diff --git a/compiler/GHC/Stg/Subst.hs b/compiler/GHC/Stg/Subst.hs index 0983abf7a1..e98f445b2f 100644 --- a/compiler/GHC/Stg/Subst.hs +++ b/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'. |