[Git][ghc/ghc][master] Add missing addInScope call for letrec binders in OccurAnal

Marge Bot gitlab at gitlab.haskell.org
Sun Apr 19 07:16:55 UTC 2020



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


Commits:
eaed0a32 by Alexis King at 2020-04-19T03:16:44-04:00
Add missing addInScope call for letrec binders in OccurAnal

This fixes #18044, where a shadowed variable was incorrectly substituted
by the binder swap on the RHS of a floated-in letrec. This can only
happen when the uniques line up *just* right, so writing a regression
test would be very difficult, but at least the fix is small and
straightforward.

- - - - -


1 changed file:

- compiler/GHC/Core/Opt/OccurAnal.hs


Changes:

=====================================
compiler/GHC/Core/Opt/OccurAnal.hs
=====================================
@@ -843,7 +843,7 @@ occAnalNonRecBind env lvl imp_rule_edges bndr rhs body_usage
 occAnalRecBind :: OccEnv -> TopLevelFlag -> ImpRuleEdges -> [(Var,CoreExpr)]
                -> UsageDetails -> (UsageDetails, [CoreBind])
 occAnalRecBind env lvl imp_rule_edges pairs body_usage
-  = foldr (occAnalRec env lvl) (body_usage, []) sccs
+  = foldr (occAnalRec rhs_env lvl) (body_usage, []) sccs
         -- For a recursive group, we
         --      * occ-analyse all the RHSs
         --      * compute strongly-connected components
@@ -856,9 +856,11 @@ occAnalRecBind env lvl imp_rule_edges pairs body_usage
 
     nodes :: [LetrecNode]
     nodes = {-# SCC "occAnalBind.assoc" #-}
-            map (makeNode env imp_rule_edges bndr_set) pairs
+            map (makeNode rhs_env imp_rule_edges bndr_set) pairs
 
-    bndr_set = mkVarSet (map fst pairs)
+    bndrs    = map fst pairs
+    bndr_set = mkVarSet bndrs
+    rhs_env  = env `addInScope` bndrs
 
 {-
 Note [Unfoldings and join points]



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eaed0a3289e4c24ff1a70c6fc4b7f8bae6cd2dd3
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/20200419/52b498c6/attachment-0001.html>


More information about the ghc-commits mailing list