[commit: ghc] master: Add Note [Setting the right in-scope set] (609f284)

git at git.haskell.org git at git.haskell.org
Mon Oct 30 14:57:23 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/609f2844b92d5aa474f34b989c6ec5ad9fdb2ce3/ghc

>---------------------------------------------------------------

commit 609f2844b92d5aa474f34b989c6ec5ad9fdb2ce3
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Mon Oct 30 14:56:58 2017 +0000

    Add Note [Setting the right in-scope set]


>---------------------------------------------------------------

609f2844b92d5aa474f34b989c6ec5ad9fdb2ce3
 compiler/simplCore/SimplEnv.hs | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/compiler/simplCore/SimplEnv.hs b/compiler/simplCore/SimplEnv.hs
index 0badb2a..d2cb689 100644
--- a/compiler/simplCore/SimplEnv.hs
+++ b/compiler/simplCore/SimplEnv.hs
@@ -337,7 +337,8 @@ setInScopeSet :: SimplEnv -> InScopeSet -> SimplEnv
 setInScopeSet env in_scope = env {seInScope = in_scope}
 
 setInScopeFromE :: SimplEnv -> SimplEnv -> SimplEnv
-setInScopeFromE env env' = env { seInScope = seInScope env' }
+-- See Note [Setting the right in-scope set]
+setInScopeFromE rhs_env here_env = rhs_env { seInScope = seInScope here_env }
 
 setInScopeFromF :: SimplEnv -> SimplFloats -> SimplEnv
 setInScopeFromF env floats = env { seInScope = sfInScope floats }
@@ -360,6 +361,30 @@ modifyInScope :: SimplEnv -> CoreBndr -> SimplEnv
 modifyInScope env@(SimplEnv {seInScope = in_scope}) v
   = env {seInScope = extendInScopeSet in_scope v}
 
+{- Note [Setting the right in-scope set]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Consider
+  \x. (let x = e in b) arg[x]
+where the let shadows the lambda.  Really this means something like
+  \x1. (let x2 = e in b) arg[x1]
+
+- When we capture the 'arg' in an ApplyToVal continuation, we capture
+  the environment, which says what 'x' is bound to, namely x1
+
+- Then that continuation gets pushed under the let
+
+- Finally we simplify 'arg'.  We want
+     - the static, lexical environment bindig x :-> x1
+     - the in-scopeset from "here", under the 'let' which includes
+       both x1 and x2
+
+It's important to have the right in-scope set, else we may rename a
+variable to one that is already in scope.  So we must pick up the
+in-scope set from "here", but otherwise use the environment we
+captured along with 'arg'.  This transfer of in-scope set is done by
+setInScopeFromE.
+-}
+
 ---------------------
 zapSubstEnv :: SimplEnv -> SimplEnv
 zapSubstEnv env = env {seTvSubst = emptyVarEnv, seCvSubst = emptyVarEnv, seIdSubst = emptyVarEnv}



More information about the ghc-commits mailing list