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
)
import BasicTypes ( Unused )
import UniqSet ( unionUniqSets, addOneToUniqSet )
import Util ( panic, assertPanic )
+
\end{code}
%************************************************************************
freeVars :: CoreExpr -> CoreExprWithFVs
freeVars expr = fvExpr noIdCands noTyVarCands expr
+
\end{code}
%************************************************************************
-> 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
-- 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}