Fix Trac #2587: take account of type lets
authorsimonpj@microsoft.com <unknown>
Sun, 14 Sep 2008 11:34:34 +0000 (11:34 +0000)
committersimonpj@microsoft.com <unknown>
Sun, 14 Sep 2008 11:34:34 +0000 (11:34 +0000)
GHC allows a non-recursive let for type varaibles
let a = TYPE ty in ...
But the free-variable finder had not caught up with this
fact. This patch catches up.

compiler/coreSyn/CoreFVs.lhs

index dedc4c0..d2d1383 100644 (file)
@@ -194,7 +194,7 @@ expr_fvs (Let (Rec pairs) body)
 
 ---------
 rhs_fvs :: (Id,CoreExpr) -> FV
-rhs_fvs (bndr, rhs) = expr_fvs rhs `union` someVars (idRuleVars bndr)
+rhs_fvs (bndr, rhs) = expr_fvs rhs `union` someVars (bndrRuleVars bndr)
        -- Treat any RULES as extra RHSs of the binding
 
 ---------
@@ -373,6 +373,10 @@ varTypeTyVars var
 idFreeVars :: Id -> VarSet
 idFreeVars id = ASSERT( isId id) idRuleVars id `unionVarSet` varTypeTyVars id
 
+bndrRuleVars ::Var -> VarSet
+bndrRuleVars v | isTyVar v = emptyVarSet
+              | otherwise = idRuleVars v
+
 idRuleVars ::Id -> VarSet
 idRuleVars id = ASSERT( isId id) specInfoFreeVars (idSpecialisation id)
 \end{code}
@@ -425,7 +429,7 @@ freeVars (Case scrut bndr ty alts)
                             rhs2 = freeVars rhs
 
 freeVars (Let (NonRec binder rhs) body)
-  = (freeVarsOf rhs2 `unionFVs` body_fvs `unionFVs` idRuleVars binder,
+  = (freeVarsOf rhs2 `unionFVs` body_fvs `unionFVs` bndrRuleVars binder,
                -- Remember any rules; cf rhs_fvs above
      AnnLet (AnnNonRec binder rhs2) body2)
   where