From 90fd2bc78c90147818fe0122eb372afdd5f9dfd0 Mon Sep 17 00:00:00 2001 From: sof Date: Thu, 30 Apr 1998 19:44:49 +0000 Subject: [PATCH] [project @ 1998-04-30 19:44:49 by sof] When floating in, we have to be careful not to float a specialisation of a binder past a use of that binder that may later be simplified to use the specialised version that just floated past (and out of scope.) Kludgily fix this by including the idSpecVars of a Var in its free variable set. --- ghc/compiler/coreSyn/FreeVars.lhs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ghc/compiler/coreSyn/FreeVars.lhs b/ghc/compiler/coreSyn/FreeVars.lhs index a475c3f..9619f49 100644 --- a/ghc/compiler/coreSyn/FreeVars.lhs +++ b/ghc/compiler/coreSyn/FreeVars.lhs @@ -21,8 +21,9 @@ module FreeVars ( import AnnCoreSyn -- output import CoreSyn +import CoreUtils ( idSpecVars ) import Id ( idType, getIdArity, isBottomingId, - emptyIdSet, unitIdSet, mkIdSet, + emptyIdSet, unitIdSet, mkIdSet, unionIdSets, elementOfIdSet, minusIdSet, unionManyIdSets, IdSet, Id ) @@ -36,6 +37,7 @@ import TyVar ( emptyTyVarSet, unitTyVarSet, minusTyVarSet, import BasicTypes ( Unused ) import UniqSet ( unionUniqSets, addOneToUniqSet ) import Util ( panic, assertPanic ) + \end{code} %************************************************************************ @@ -111,6 +113,7 @@ Main public interface: freeVars :: CoreExpr -> CoreExprWithFVs freeVars expr = fvExpr noIdCands noTyVarCands expr + \end{code} %************************************************************************ @@ -132,13 +135,18 @@ fvExpr :: IdCands -- In-scope Ids -> CoreExprWithFVs fvExpr id_cands tyvar_cands (Var v) - = (FVInfo (if (v `is_among` id_cands) - then aFreeId v - else noFreeIds) - noFreeTyVars - leakiness, - AnnVar v) + = (FVInfo fvs noFreeTyVars leakiness, AnnVar v) where + {- + ToDo: insert motivating example for why we *need* + to include the idSpecVars in the FV list. + -} + fvs = fvs_v `unionIdSets` mkIdSet (idSpecVars v) + + fvs_v + | v `is_among` id_cands = aFreeId v + | otherwise = noFreeIds + leakiness | isBottomingId v = lEAK_FREE_BIG -- Hack | otherwise = case getIdArity v of @@ -305,9 +313,11 @@ fvExpr id_cands tyvar_cands (Note other_note expr) -- free vars of the RHS the idSpecVars of the binder, -- since those are, in truth, free in the definition. fvRhs id_cands tyvar_cands (bndr,rhs) - = (FVInfo (fvs `unionIdSets` idSpecVars bndr) ftvs leak, rhs') + = (FVInfo fvs' ftvs leak, rhs') where (FVInfo fvs ftvs leak, rhs') = fvExpr id_cands tyvar_cands rhs + fvs' = fvs `unionIdSets` mkIdSet (idSpecVars bndr) + \end{code} \begin{code} -- 1.7.10.4