398f6bee3992e0764eed8f4f97a12b5039ef1955
[ghc.git] / compiler / coreSyn / CoreFVs.hs
1 {-
2 (c) The University of Glasgow 2006
3 (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4
5 Taken quite directly from the Peyton Jones/Lester paper.
6 -}
7
8 {-# LANGUAGE CPP #-}
9
10 -- | A module concerned with finding the free variables of an expression.
11 module CoreFVs (
12 -- * Free variables of expressions and binding groups
13 exprFreeVars,
14 exprFreeVarsDSet,
15 exprFreeIds,
16 exprsFreeVars,
17 exprsFreeVarsList,
18 bindFreeVars,
19
20 -- * Selective free variables of expressions
21 InterestingVarFun,
22 exprSomeFreeVars, exprsSomeFreeVars,
23
24 -- * Free variables of Rules, Vars and Ids
25 varTypeTyVars,
26 varTypeTyVarsAcc,
27 idUnfoldingVars, idFreeVars, idRuleAndUnfoldingVars,
28 idFreeVarsAcc,
29 idRuleVars, idRuleRhsVars, stableUnfoldingVars,
30 ruleRhsFreeVars, ruleFreeVars, rulesFreeVars,
31 rulesFreeVarsDSet,
32 ruleLhsFreeIds, exprsOrphNames,
33 vectsFreeVars,
34
35 expr_fvs,
36
37 -- * Core syntax tree annotation with free variables
38 CoreExprWithFVs, -- = AnnExpr Id DVarSet
39 CoreBindWithFVs, -- = AnnBind Id DVarSet
40 freeVars, -- CoreExpr -> CoreExprWithFVs
41 freeVarsOf -- CoreExprWithFVs -> DIdSet
42 ) where
43
44 #include "HsVersions.h"
45
46 import CoreSyn
47 import Id
48 import IdInfo
49 import NameSet
50 import UniqFM
51 import Name
52 import VarSet
53 import Var
54 import TcType
55 import Coercion
56 import Maybes( orElse )
57 import Util
58 import BasicTypes( Activation )
59 import Outputable
60 import FV
61
62 {-
63 ************************************************************************
64 * *
65 \section{Finding the free variables of an expression}
66 * *
67 ************************************************************************
68
69 This function simply finds the free variables of an expression.
70 So far as type variables are concerned, it only finds tyvars that are
71
72 * free in type arguments,
73 * free in the type of a binder,
74
75 but not those that are free in the type of variable occurrence.
76 -}
77
78 -- | Find all locally-defined free Ids or type variables in an expression
79 -- returning a non-deterministic set.
80 exprFreeVars :: CoreExpr -> VarSet
81 exprFreeVars = runFVSet . exprFreeVarsAcc
82
83 -- | Find all locally-defined free Ids or type variables in an expression
84 -- returning a composable FV computation. See Note [FV naming coventions] in FV
85 -- for why export it.
86 exprFreeVarsAcc :: CoreExpr -> FV
87 exprFreeVarsAcc = filterFV isLocalVar . expr_fvs
88
89 -- | Find all locally-defined free Ids or type variables in an expression
90 -- returning a deterministic set.
91 exprFreeVarsDSet :: CoreExpr -> DVarSet
92 exprFreeVarsDSet = runFVDSet . exprFreeVarsAcc
93
94 -- | Find all locally-defined free Ids in an expression
95 exprFreeIds :: CoreExpr -> IdSet -- Find all locally-defined free Ids
96 exprFreeIds = exprSomeFreeVars isLocalId
97
98 -- | Find all locally-defined free Ids or type variables in several expressions
99 -- returning a non-deterministic set.
100 exprsFreeVars :: [CoreExpr] -> VarSet
101 exprsFreeVars = runFVSet . exprsFreeVarsAcc
102
103 -- | Find all locally-defined free Ids or type variables in several expressions
104 -- returning a composable FV computation. See Note [FV naming coventions] in FV
105 -- for why export it.
106 exprsFreeVarsAcc :: [CoreExpr] -> FV
107 exprsFreeVarsAcc exprs = mapUnionFV exprFreeVarsAcc exprs
108
109 -- | Find all locally-defined free Ids or type variables in several expressions
110 -- returning a deterministically ordered list.
111 exprsFreeVarsList :: [CoreExpr] -> [Var]
112 exprsFreeVarsList = runFVList . exprsFreeVarsAcc
113
114 -- | Find all locally defined free Ids in a binding group
115 bindFreeVars :: CoreBind -> VarSet
116 bindFreeVars (NonRec b r) = runFVSet $ filterFV isLocalVar $ rhs_fvs (b,r)
117 bindFreeVars (Rec prs) = runFVSet $ filterFV isLocalVar $
118 addBndrs (map fst prs)
119 (mapUnionFV rhs_fvs prs)
120
121 -- | Finds free variables in an expression selected by a predicate
122 exprSomeFreeVars :: InterestingVarFun -- ^ Says which 'Var's are interesting
123 -> CoreExpr
124 -> VarSet
125 exprSomeFreeVars fv_cand e = runFVSet $ filterFV fv_cand $ expr_fvs e
126
127 -- | Finds free variables in several expressions selected by a predicate
128 exprsSomeFreeVars :: InterestingVarFun -- Says which 'Var's are interesting
129 -> [CoreExpr]
130 -> VarSet
131 exprsSomeFreeVars fv_cand es =
132 runFVSet $ filterFV fv_cand $ mapUnionFV expr_fvs es
133
134 -- Comment about obselete code
135 -- We used to gather the free variables the RULES at a variable occurrence
136 -- with the following cryptic comment:
137 -- "At a variable occurrence, add in any free variables of its rule rhss
138 -- Curiously, we gather the Id's free *type* variables from its binding
139 -- site, but its free *rule-rhs* variables from its usage sites. This
140 -- is a little weird. The reason is that the former is more efficient,
141 -- but the latter is more fine grained, and a makes a difference when
142 -- a variable mentions itself one of its own rule RHSs"
143 -- Not only is this "weird", but it's also pretty bad because it can make
144 -- a function seem more recursive than it is. Suppose
145 -- f = ...g...
146 -- g = ...
147 -- RULE g x = ...f...
148 -- Then f is not mentioned in its own RHS, and needn't be a loop breaker
149 -- (though g may be). But if we collect the rule fvs from g's occurrence,
150 -- it looks as if f mentions itself. (This bites in the eftInt/eftIntFB
151 -- code in GHC.Enum.)
152 --
153 -- Anyway, it seems plain wrong. The RULE is like an extra RHS for the
154 -- function, so its free variables belong at the definition site.
155 --
156 -- Deleted code looked like
157 -- foldVarSet add_rule_var var_itself_set (idRuleVars var)
158 -- add_rule_var var set | keep_it fv_cand in_scope var = extendVarSet set var
159 -- | otherwise = set
160 -- SLPJ Feb06
161
162 addBndr :: CoreBndr -> FV -> FV
163 addBndr bndr fv fv_cand in_scope acc
164 = (varTypeTyVarsAcc bndr `unionFV`
165 -- Include type varibles in the binder's type
166 -- (not just Ids; coercion variables too!)
167 FV.delFV bndr fv) fv_cand in_scope acc
168
169 addBndrs :: [CoreBndr] -> FV -> FV
170 addBndrs bndrs fv = foldr addBndr fv bndrs
171
172 expr_fvs :: CoreExpr -> FV
173 expr_fvs (Type ty) fv_cand in_scope acc =
174 tyVarsOfTypeAcc ty fv_cand in_scope acc
175 expr_fvs (Coercion co) fv_cand in_scope acc =
176 tyCoVarsOfCoAcc co fv_cand in_scope acc
177 expr_fvs (Var var) fv_cand in_scope acc = oneVar var fv_cand in_scope acc
178 expr_fvs (Lit _) fv_cand in_scope acc = noVars fv_cand in_scope acc
179 expr_fvs (Tick t expr) fv_cand in_scope acc =
180 (tickish_fvs t `unionFV` expr_fvs expr) fv_cand in_scope acc
181 expr_fvs (App fun arg) fv_cand in_scope acc =
182 (expr_fvs fun `unionFV` expr_fvs arg) fv_cand in_scope acc
183 expr_fvs (Lam bndr body) fv_cand in_scope acc =
184 addBndr bndr (expr_fvs body) fv_cand in_scope acc
185 expr_fvs (Cast expr co) fv_cand in_scope acc =
186 (expr_fvs expr `unionFV` tyCoVarsOfCoAcc co) fv_cand in_scope acc
187
188 expr_fvs (Case scrut bndr ty alts) fv_cand in_scope acc
189 = (expr_fvs scrut `unionFV` tyVarsOfTypeAcc ty `unionFV` addBndr bndr
190 (mapUnionFV alt_fvs alts)) fv_cand in_scope acc
191 where
192 alt_fvs (_, bndrs, rhs) = addBndrs bndrs (expr_fvs rhs)
193
194 expr_fvs (Let (NonRec bndr rhs) body) fv_cand in_scope acc
195 = (rhs_fvs (bndr, rhs) `unionFV` addBndr bndr (expr_fvs body))
196 fv_cand in_scope acc
197
198 expr_fvs (Let (Rec pairs) body) fv_cand in_scope acc
199 = addBndrs (map fst pairs)
200 (mapUnionFV rhs_fvs pairs `unionFV` expr_fvs body)
201 fv_cand in_scope acc
202
203 ---------
204 rhs_fvs :: (Id, CoreExpr) -> FV
205 rhs_fvs (bndr, rhs) = expr_fvs rhs `unionFV`
206 bndrRuleAndUnfoldingVarsAcc bndr
207 -- Treat any RULES as extra RHSs of the binding
208
209 ---------
210 exprs_fvs :: [CoreExpr] -> FV
211 exprs_fvs exprs = mapUnionFV expr_fvs exprs
212
213 tickish_fvs :: Tickish Id -> FV
214 tickish_fvs (Breakpoint _ ids) = someVars ids
215 tickish_fvs _ = noVars
216
217 {-
218 ************************************************************************
219 * *
220 \section{Free names}
221 * *
222 ************************************************************************
223 -}
224
225 -- | Finds the free /external/ names of an expression, notably
226 -- including the names of type constructors (which of course do not show
227 -- up in 'exprFreeVars').
228 exprOrphNames :: CoreExpr -> NameSet
229 -- There's no need to delete local binders, because they will all
230 -- be /internal/ names.
231 exprOrphNames e
232 = go e
233 where
234 go (Var v)
235 | isExternalName n = unitNameSet n
236 | otherwise = emptyNameSet
237 where n = idName v
238 go (Lit _) = emptyNameSet
239 go (Type ty) = orphNamesOfType ty -- Don't need free tyvars
240 go (Coercion co) = orphNamesOfCo co
241 go (App e1 e2) = go e1 `unionNameSet` go e2
242 go (Lam v e) = go e `delFromNameSet` idName v
243 go (Tick _ e) = go e
244 go (Cast e co) = go e `unionNameSet` orphNamesOfCo co
245 go (Let (NonRec _ r) e) = go e `unionNameSet` go r
246 go (Let (Rec prs) e) = exprsOrphNames (map snd prs) `unionNameSet` go e
247 go (Case e _ ty as) = go e `unionNameSet` orphNamesOfType ty
248 `unionNameSet` unionNameSets (map go_alt as)
249
250 go_alt (_,_,r) = go r
251
252 -- | Finds the free /external/ names of several expressions: see 'exprOrphNames' for details
253 exprsOrphNames :: [CoreExpr] -> NameSet
254 exprsOrphNames es = foldr (unionNameSet . exprOrphNames) emptyNameSet es
255
256 {-
257 ************************************************************************
258 * *
259 \section[freevars-everywhere]{Attaching free variables to every sub-expression}
260 * *
261 ************************************************************************
262 -}
263
264 -- | Those variables free in the right hand side of a rule returned as a
265 -- non-deterministic set
266 ruleRhsFreeVars :: CoreRule -> VarSet
267 ruleRhsFreeVars (BuiltinRule {}) = noFVs
268 ruleRhsFreeVars (Rule { ru_fn = _, ru_bndrs = bndrs, ru_rhs = rhs })
269 = runFVSet $ filterFV isLocalVar $ addBndrs bndrs (expr_fvs rhs)
270 -- See Note [Rule free var hack]
271
272 -- | Those variables free in the both the left right hand sides of a rule
273 -- returned as a non-deterministic set
274 ruleFreeVars :: CoreRule -> VarSet
275 ruleFreeVars = runFVSet . ruleFreeVarsAcc
276
277 -- | Those variables free in the both the left right hand sides of a rule
278 -- returned as FV computation
279 ruleFreeVarsAcc :: CoreRule -> FV
280 ruleFreeVarsAcc (BuiltinRule {}) = noVars
281 ruleFreeVarsAcc (Rule { ru_fn = _do_not_include
282 -- See Note [Rule free var hack]
283 , ru_bndrs = bndrs
284 , ru_rhs = rhs, ru_args = args })
285 = filterFV isLocalVar $ addBndrs bndrs (exprs_fvs (rhs:args))
286
287 -- | Those variables free in the both the left right hand sides of rules
288 -- returned as FV computation
289 rulesFreeVarsAcc :: [CoreRule] -> FV
290 rulesFreeVarsAcc = mapUnionFV ruleFreeVarsAcc
291
292 -- | Those variables free in the both the left right hand sides of rules
293 -- returned as a deterministic set
294 rulesFreeVarsDSet :: [CoreRule] -> DVarSet
295 rulesFreeVarsDSet rules = runFVDSet $ rulesFreeVarsAcc rules
296
297 idRuleRhsVars :: (Activation -> Bool) -> Id -> VarSet
298 -- Just the variables free on the *rhs* of a rule
299 idRuleRhsVars is_active id
300 = mapUnionVarSet get_fvs (idCoreRules id)
301 where
302 get_fvs (Rule { ru_fn = fn, ru_bndrs = bndrs
303 , ru_rhs = rhs, ru_act = act })
304 | is_active act
305 -- See Note [Finding rule RHS free vars] in OccAnal.hs
306 = delFromUFM fvs fn -- Note [Rule free var hack]
307 where
308 fvs = runFVSet $ filterFV isLocalVar $ addBndrs bndrs (expr_fvs rhs)
309 get_fvs _ = noFVs
310
311 -- | Those variables free in the right hand side of several rules
312 rulesFreeVars :: [CoreRule] -> VarSet
313 rulesFreeVars rules = mapUnionVarSet ruleFreeVars rules
314
315 ruleLhsFreeIds :: CoreRule -> VarSet
316 -- ^ This finds all locally-defined free Ids on the left hand side of a rule
317 ruleLhsFreeIds (BuiltinRule {}) = noFVs
318 ruleLhsFreeIds (Rule { ru_bndrs = bndrs, ru_args = args })
319 = runFVSet $ filterFV isLocalId $ addBndrs bndrs (exprs_fvs args)
320
321 {-
322 Note [Rule free var hack] (Not a hack any more)
323 ~~~~~~~~~~~~~~~~~~~~~~~~~
324 We used not to include the Id in its own rhs free-var set.
325 Otherwise the occurrence analyser makes bindings recursive:
326 f x y = x+y
327 RULE: f (f x y) z ==> f x (f y z)
328 However, the occurrence analyser distinguishes "non-rule loop breakers"
329 from "rule-only loop breakers" (see BasicTypes.OccInfo). So it will
330 put this 'f' in a Rec block, but will mark the binding as a non-rule loop
331 breaker, which is perfectly inlinable.
332 -}
333
334 -- |Free variables of a vectorisation declaration
335 vectsFreeVars :: [CoreVect] -> VarSet
336 vectsFreeVars = mapUnionVarSet vectFreeVars
337 where
338 vectFreeVars (Vect _ rhs) = runFVSet $ filterFV isLocalId $ expr_fvs rhs
339 vectFreeVars (NoVect _) = noFVs
340 vectFreeVars (VectType _ _ _) = noFVs
341 vectFreeVars (VectClass _) = noFVs
342 vectFreeVars (VectInst _) = noFVs
343 -- this function is only concerned with values, not types
344
345 {-
346 ************************************************************************
347 * *
348 \section[freevars-everywhere]{Attaching free variables to every sub-expression}
349 * *
350 ************************************************************************
351
352 The free variable pass annotates every node in the expression with its
353 NON-GLOBAL free variables and type variables.
354 -}
355
356 -- | Every node in a binding group annotated with its
357 -- (non-global) free variables, both Ids and TyVars
358 type CoreBindWithFVs = AnnBind Id DVarSet
359 -- | Every node in an expression annotated with its
360 -- (non-global) free variables, both Ids and TyVars
361 type CoreExprWithFVs = AnnExpr Id DVarSet
362
363 freeVarsOf :: CoreExprWithFVs -> DIdSet
364 -- ^ Inverse function to 'freeVars'
365 freeVarsOf (free_vars, _) = free_vars
366
367 noFVs :: VarSet
368 noFVs = emptyVarSet
369
370 aFreeVar :: Var -> DVarSet
371 aFreeVar = unitDVarSet
372
373 unionFVs :: DVarSet -> DVarSet -> DVarSet
374 unionFVs = unionDVarSet
375
376 delBindersFV :: [Var] -> DVarSet -> DVarSet
377 delBindersFV bs fvs = foldr delBinderFV fvs bs
378
379 delBinderFV :: Var -> DVarSet -> DVarSet
380 -- This way round, so we can do it multiple times using foldr
381
382 -- (b `delBinderFV` s) removes the binder b from the free variable set s,
383 -- but *adds* to s
384 --
385 -- the free variables of b's type
386 --
387 -- This is really important for some lambdas:
388 -- In (\x::a -> x) the only mention of "a" is in the binder.
389 --
390 -- Also in
391 -- let x::a = b in ...
392 -- we should really note that "a" is free in this expression.
393 -- It'll be pinned inside the /\a by the binding for b, but
394 -- it seems cleaner to make sure that a is in the free-var set
395 -- when it is mentioned.
396 --
397 -- This also shows up in recursive bindings. Consider:
398 -- /\a -> letrec x::a = x in E
399 -- Now, there are no explicit free type variables in the RHS of x,
400 -- but nevertheless "a" is free in its definition. So we add in
401 -- the free tyvars of the types of the binders, and include these in the
402 -- free vars of the group, attached to the top level of each RHS.
403 --
404 -- This actually happened in the defn of errorIO in IOBase.hs:
405 -- errorIO (ST io) = case (errorIO# io) of
406 -- _ -> bottom
407 -- where
408 -- bottom = bottom -- Never evaluated
409
410 delBinderFV b s = (s `delDVarSet` b) `unionFVs` dVarTypeTyVars b
411 -- Include coercion variables too!
412
413 varTypeTyVars :: Var -> TyVarSet
414 -- Find the type/kind variables free in the type of the id/tyvar
415 varTypeTyVars var = runFVSet $ varTypeTyVarsAcc var
416
417 dVarTypeTyVars :: Var -> DTyVarSet
418 -- Find the type/kind variables free in the type of the id/tyvar
419 dVarTypeTyVars var = runFVDSet $ varTypeTyVarsAcc var
420
421 varTypeTyVarsAcc :: Var -> FV
422 varTypeTyVarsAcc var = tyVarsOfTypeAcc (varType var)
423
424 idFreeVars :: Id -> VarSet
425 idFreeVars id = ASSERT( isId id) runFVSet $ idFreeVarsAcc id
426
427 idFreeVarsAcc :: Id -> FV
428 -- Type variables, rule variables, and inline variables
429 idFreeVarsAcc id = ASSERT( isId id)
430 varTypeTyVarsAcc id `unionFV`
431 idRuleAndUnfoldingVarsAcc id
432
433 bndrRuleAndUnfoldingVarsAcc :: Var -> FV
434 bndrRuleAndUnfoldingVarsAcc v | isTyVar v = noVars
435 | otherwise = idRuleAndUnfoldingVarsAcc v
436
437 idRuleAndUnfoldingVars :: Id -> VarSet
438 idRuleAndUnfoldingVars id = runFVSet $ idRuleAndUnfoldingVarsAcc id
439
440 idRuleAndUnfoldingVarsAcc :: Id -> FV
441 idRuleAndUnfoldingVarsAcc id = ASSERT( isId id)
442 idRuleVarsAcc id `unionFV` idUnfoldingVarsAcc id
443
444
445 idRuleVars ::Id -> VarSet -- Does *not* include CoreUnfolding vars
446 idRuleVars id = runFVSet $ idRuleVarsAcc id
447
448 idRuleVarsAcc :: Id -> FV
449 idRuleVarsAcc id = ASSERT( isId id)
450 someVars (dVarSetElems $ ruleInfoFreeVars (idSpecialisation id))
451
452 idUnfoldingVars :: Id -> VarSet
453 -- Produce free vars for an unfolding, but NOT for an ordinary
454 -- (non-inline) unfolding, since it is a dup of the rhs
455 -- and we'll get exponential behaviour if we look at both unf and rhs!
456 -- But do look at the *real* unfolding, even for loop breakers, else
457 -- we might get out-of-scope variables
458 idUnfoldingVars id = runFVSet $ idUnfoldingVarsAcc id
459
460 idUnfoldingVarsAcc :: Id -> FV
461 idUnfoldingVarsAcc id = stableUnfoldingVarsAcc (realIdUnfolding id) `orElse` noVars
462
463 stableUnfoldingVars :: Unfolding -> Maybe VarSet
464 stableUnfoldingVars unf = runFVSet `fmap` stableUnfoldingVarsAcc unf
465
466 stableUnfoldingVarsAcc :: Unfolding -> Maybe FV
467 stableUnfoldingVarsAcc unf
468 = case unf of
469 CoreUnfolding { uf_tmpl = rhs, uf_src = src }
470 | isStableSource src
471 -> Just (filterFV isLocalVar $ expr_fvs rhs)
472 DFunUnfolding { df_bndrs = bndrs, df_args = args }
473 -> Just (filterFV isLocalVar $ FV.delFVs (mkVarSet bndrs) $ exprs_fvs args)
474 -- DFuns are top level, so no fvs from types of bndrs
475 _other -> Nothing
476
477
478 {-
479 ************************************************************************
480 * *
481 \subsection{Free variables (and types)}
482 * *
483 ************************************************************************
484 -}
485
486 freeVars :: CoreExpr -> CoreExprWithFVs
487 -- ^ Annotate a 'CoreExpr' with its (non-global) free type and value variables at every tree node
488 freeVars (Var v)
489 = (fvs, AnnVar v)
490 where
491 -- ToDo: insert motivating example for why we *need*
492 -- to include the idSpecVars in the FV list.
493 -- Actually [June 98] I don't think it's necessary
494 -- fvs = fvs_v `unionVarSet` idSpecVars v
495
496 fvs | isLocalVar v = aFreeVar v
497 | otherwise = emptyDVarSet
498
499 freeVars (Lit lit) = (emptyDVarSet, AnnLit lit)
500 freeVars (Lam b body)
501 = (b `delBinderFV` freeVarsOf body', AnnLam b body')
502 where
503 body' = freeVars body
504
505 freeVars (App fun arg)
506 = (freeVarsOf fun2 `unionFVs` freeVarsOf arg2, AnnApp fun2 arg2)
507 where
508 fun2 = freeVars fun
509 arg2 = freeVars arg
510
511 freeVars (Case scrut bndr ty alts)
512 = ((bndr `delBinderFV` alts_fvs) `unionFVs` freeVarsOf scrut2 `unionFVs` runFVDSet (tyVarsOfTypeAcc ty),
513 AnnCase scrut2 bndr ty alts2)
514 where
515 scrut2 = freeVars scrut
516
517 (alts_fvs_s, alts2) = mapAndUnzip fv_alt alts
518 alts_fvs = foldr unionFVs emptyDVarSet alts_fvs_s
519
520 fv_alt (con,args,rhs) = (delBindersFV args (freeVarsOf rhs2),
521 (con, args, rhs2))
522 where
523 rhs2 = freeVars rhs
524
525 freeVars (Let (NonRec binder rhs) body)
526 = (freeVarsOf rhs2
527 `unionFVs` body_fvs
528 `unionFVs` runFVDSet (bndrRuleAndUnfoldingVarsAcc binder),
529 -- Remember any rules; cf rhs_fvs above
530 AnnLet (AnnNonRec binder rhs2) body2)
531 where
532 rhs2 = freeVars rhs
533 body2 = freeVars body
534 body_fvs = binder `delBinderFV` freeVarsOf body2
535
536 freeVars (Let (Rec binds) body)
537 = (delBindersFV binders all_fvs,
538 AnnLet (AnnRec (binders `zip` rhss2)) body2)
539 where
540 (binders, rhss) = unzip binds
541
542 rhss2 = map freeVars rhss
543 rhs_body_fvs = foldr (unionFVs . freeVarsOf) body_fvs rhss2
544 binders_fvs = runFVDSet $ mapUnionFV idRuleAndUnfoldingVarsAcc binders
545 all_fvs = rhs_body_fvs `unionFVs` binders_fvs
546 -- The "delBinderFV" happens after adding the idSpecVars,
547 -- since the latter may add some of the binders as fvs
548
549 body2 = freeVars body
550 body_fvs = freeVarsOf body2
551
552 freeVars (Cast expr co)
553 = (freeVarsOf expr2 `unionFVs` cfvs, AnnCast expr2 (cfvs, co))
554 where
555 expr2 = freeVars expr
556 cfvs = runFVDSet $ tyCoVarsOfCoAcc co
557
558 freeVars (Tick tickish expr)
559 = (tickishFVs tickish `unionFVs` freeVarsOf expr2, AnnTick tickish expr2)
560 where
561 expr2 = freeVars expr
562 tickishFVs (Breakpoint _ ids) = mkDVarSet ids
563 tickishFVs _ = emptyDVarSet
564
565 freeVars (Type ty) = (runFVDSet $ tyVarsOfTypeAcc ty, AnnType ty)
566
567 freeVars (Coercion co) = (runFVDSet $ tyCoVarsOfCoAcc co, AnnCoercion co)