edee0dd80f7c9e27a3a2c78f96974508efc8ca34
[ghc-hetmet.git] / ghc / compiler / coreSyn / CoreSyn.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[CoreSyn]{A data type for the Haskell compiler midsection}
5
6 \begin{code}
7 module CoreSyn (
8         Expr(..), Alt, Bind(..), AltCon(..), Arg, Note(..),
9         CoreExpr, CoreAlt, CoreBind, CoreArg, CoreBndr,
10         TaggedExpr, TaggedAlt, TaggedBind, TaggedArg, TaggedBndr(..),
11
12         mkLets, mkLams, 
13         mkApps, mkTyApps, mkValApps, mkVarApps,
14         mkLit, mkIntLitInt, mkIntLit, 
15         mkConApp, 
16         varToCoreExpr,
17
18         isTyVar, isId, 
19         bindersOf, bindersOfBinds, rhssOfBind, rhssOfAlts, 
20         collectBinders, collectTyBinders, collectValBinders, collectTyAndValBinders,
21         collectArgs, 
22         coreExprCc,
23         flattenBinds, 
24
25         isValArg, isTypeArg, valArgCount, valBndrCount, isRuntimeArg, isRuntimeVar,
26
27         -- Unfoldings
28         Unfolding(..),  UnfoldingGuidance(..),  -- Both abstract everywhere but in CoreUnfold.lhs
29         noUnfolding, mkOtherCon,
30         unfoldingTemplate, maybeUnfoldingTemplate, otherCons, 
31         isValueUnfolding, isEvaldUnfolding, isCheapUnfolding, isCompulsoryUnfolding,
32         hasUnfolding, hasSomeUnfolding, neverUnfold,
33
34         -- Seq stuff
35         seqRules, seqExpr, seqExprs, seqUnfolding,
36
37         -- Annotated expressions
38         AnnExpr, AnnExpr'(..), AnnBind(..), AnnAlt, 
39         deAnnotate, deAnnotate', deAnnAlt, collectAnnBndrs,
40
41         -- Core rules
42         CoreRules(..),  -- Representation needed by friends
43         CoreRule(..),   -- CoreSubst, CoreTidy, CoreFVs, PprCore only
44         IdCoreRule,
45         RuleName,
46         emptyCoreRules, isEmptyCoreRules, rulesRhsFreeVars, rulesRules,
47         isBuiltinRule, ruleName
48     ) where
49
50 #include "HsVersions.h"
51
52 import CmdLineOpts      ( opt_RuntimeTypes )
53 import CostCentre       ( CostCentre, noCostCentre )
54 import Var              ( Var, Id, TyVar, isTyVar, isId )
55 import Type             ( Type, mkTyVarTy, seqType )
56 import Literal          ( Literal, mkMachInt )
57 import DataCon          ( DataCon, dataConWorkId )
58 import BasicTypes       ( Activation )
59 import VarSet
60 import FastString
61 import Outputable
62 \end{code}
63
64 %************************************************************************
65 %*                                                                      *
66 \subsection{The main data types}
67 %*                                                                      *
68 %************************************************************************
69
70 These data types are the heart of the compiler
71
72 \begin{code}
73 infixl 8 `App`  -- App brackets to the left
74
75 data Expr b     -- "b" for the type of binders, 
76   = Var   Id
77   | Lit   Literal
78   | App   (Expr b) (Arg b)
79   | Lam   b (Expr b)
80   | Let   (Bind b) (Expr b)
81   | Case  (Expr b) b [Alt b]    -- Binder gets bound to value of scrutinee
82                                 -- DEFAULT case must be *first*, if it occurs at all
83   | Note  Note (Expr b)
84   | Type  Type                  -- This should only show up at the top
85                                 -- level of an Arg
86
87 type Arg b = Expr b             -- Can be a Type
88
89 type Alt b = (AltCon, [b], Expr b)      -- (DEFAULT, [], rhs) is the default alternative
90
91 data AltCon = DataAlt DataCon
92             | LitAlt  Literal
93             | DEFAULT
94          deriving (Eq, Ord)
95
96 data Bind b = NonRec b (Expr b)
97               | Rec [(b, (Expr b))]
98
99 data Note
100   = SCC CostCentre
101
102   | Coerce      
103         Type            -- The to-type:   type of whole coerce expression
104         Type            -- The from-type: type of enclosed expression
105
106   | InlineCall          -- Instructs simplifier to inline
107                         -- the enclosed call
108
109   | InlineMe            -- Instructs simplifer to treat the enclosed expression
110                         -- as very small, and inline it at its call sites
111
112   | CoreNote String     -- A generic core annotation, propagated but not used by GHC
113
114 -- NOTE: we also treat expressions wrapped in InlineMe as
115 -- 'cheap' and 'dupable' (in the sense of exprIsCheap, exprIsDupable)
116 -- What this means is that we obediently inline even things that don't
117 -- look like valuse.  This is sometimes important:
118 --      {-# INLINE f #-}
119 --      f = g . h
120 -- Here, f looks like a redex, and we aren't going to inline (.) because it's
121 -- inside an INLINE, so it'll stay looking like a redex.  Nevertheless, we 
122 -- should inline f even inside lambdas.  In effect, we should trust the programmer.
123 \end{code}
124
125 INVARIANTS:
126
127 * The RHS of a letrec, and the RHSs of all top-level lets,
128   must be of LIFTED type.
129
130 * The RHS of a let, may be of UNLIFTED type, but only if the expression 
131   is ok-for-speculation.  This means that the let can be floated around 
132   without difficulty.  e.g.
133         y::Int# = x +# 1#       ok
134         y::Int# = fac 4#        not ok [use case instead]
135
136 * The argument of an App can be of any type.
137
138 * The simplifier tries to ensure that if the RHS of a let is a constructor
139   application, its arguments are trivial, so that the constructor can be
140   inlined vigorously.
141
142
143 %************************************************************************
144 %*                                                                      *
145 \subsection{Transformation rules}
146 %*                                                                      *
147 %************************************************************************
148
149 The CoreRule type and its friends are dealt with mainly in CoreRules,
150 but CoreFVs, Subst, PprCore, CoreTidy also inspect the representation.
151
152 \begin{code}
153 data CoreRules 
154   = Rules [CoreRule]
155           VarSet                -- Locally-defined free vars of RHSs
156
157 emptyCoreRules :: CoreRules
158 emptyCoreRules = Rules [] emptyVarSet
159
160 isEmptyCoreRules :: CoreRules -> Bool
161 isEmptyCoreRules (Rules rs _) = null rs
162
163 rulesRhsFreeVars :: CoreRules -> VarSet
164 rulesRhsFreeVars (Rules _ fvs) = fvs
165
166 rulesRules :: CoreRules -> [CoreRule]
167 rulesRules (Rules rules _) = rules
168 \end{code}
169
170 \begin{code}
171 type RuleName = FastString
172 type IdCoreRule = (Id,CoreRule)         -- Rules don't have their leading Id inside them
173
174 data CoreRule
175   = Rule RuleName
176          Activation     -- When the rule is active
177          [CoreBndr]     -- Forall'd variables
178          [CoreExpr]     -- LHS args
179          CoreExpr       -- RHS
180
181   | BuiltinRule         -- Built-in rules are used for constant folding
182         RuleName        -- and suchlike.  It has no free variables.
183         ([CoreExpr] -> Maybe CoreExpr)
184
185 isBuiltinRule (BuiltinRule _ _) = True
186 isBuiltinRule _                 = False
187
188 ruleName :: CoreRule -> RuleName
189 ruleName (Rule n _ _ _ _)  = n
190 ruleName (BuiltinRule n _) = n
191 \end{code}
192
193
194 %************************************************************************
195 %*                                                                      *
196 \subsection{@Unfolding@ type}
197 %*                                                                      *
198 %************************************************************************
199
200 The @Unfolding@ type is declared here to avoid numerous loops, but it
201 should be abstract everywhere except in CoreUnfold.lhs
202
203 \begin{code}
204 data Unfolding
205   = NoUnfolding
206
207   | OtherCon [AltCon]           -- It ain't one of these
208                                 -- (OtherCon xs) also indicates that something has been evaluated
209                                 -- and hence there's no point in re-evaluating it.
210                                 -- OtherCon [] is used even for non-data-type values
211                                 -- to indicated evaluated-ness.  Notably:
212                                 --      data C = C !(Int -> Int)
213                                 --      case x of { C f -> ... }
214                                 -- Here, f gets an OtherCon [] unfolding.
215
216   | CompulsoryUnfolding CoreExpr        -- There is no "original" definition,
217                                         -- so you'd better unfold.
218
219   | CoreUnfolding                       -- An unfolding with redundant cached information
220                 CoreExpr                -- Template; binder-info is correct
221                 Bool                    -- True <=> top level binding
222                 Bool                    -- exprIsValue template (cached); it is ok to discard a `seq` on
223                                         --      this variable
224                 Bool                    -- True <=> doesn't waste (much) work to expand inside an inlining
225                                         --      Basically it's exprIsCheap
226                 UnfoldingGuidance       -- Tells about the *size* of the template.
227
228
229 data UnfoldingGuidance
230   = UnfoldNever
231   | UnfoldIfGoodArgs    Int     -- and "n" value args
232
233                         [Int]   -- Discount if the argument is evaluated.
234                                 -- (i.e., a simplification will definitely
235                                 -- be possible).  One elt of the list per *value* arg.
236
237                         Int     -- The "size" of the unfolding; to be elaborated
238                                 -- later. ToDo
239
240                         Int     -- Scrutinee discount: the discount to substract if the thing is in
241                                 -- a context (case (thing args) of ...),
242                                 -- (where there are the right number of arguments.)
243
244 noUnfolding = NoUnfolding
245 mkOtherCon  = OtherCon
246
247 seqUnfolding :: Unfolding -> ()
248 seqUnfolding (CoreUnfolding e top b1 b2 g)
249   = seqExpr e `seq` top `seq` b1 `seq` b2 `seq` seqGuidance g
250 seqUnfolding other = ()
251
252 seqGuidance (UnfoldIfGoodArgs n ns a b) = n `seq` sum ns `seq` a `seq` b `seq` ()
253 seqGuidance other                       = ()
254 \end{code}
255
256 \begin{code}
257 unfoldingTemplate :: Unfolding -> CoreExpr
258 unfoldingTemplate (CoreUnfolding expr _ _ _ _) = expr
259 unfoldingTemplate (CompulsoryUnfolding expr)   = expr
260 unfoldingTemplate other = panic "getUnfoldingTemplate"
261
262 maybeUnfoldingTemplate :: Unfolding -> Maybe CoreExpr
263 maybeUnfoldingTemplate (CoreUnfolding expr _ _ _ _) = Just expr
264 maybeUnfoldingTemplate (CompulsoryUnfolding expr)   = Just expr
265 maybeUnfoldingTemplate other                        = Nothing
266
267 otherCons :: Unfolding -> [AltCon]
268 otherCons (OtherCon cons) = cons
269 otherCons other           = []
270
271 isValueUnfolding :: Unfolding -> Bool
272         -- Returns False for OtherCon
273 isValueUnfolding (CoreUnfolding _ _ is_evald _ _) = is_evald
274 isValueUnfolding other                            = False
275
276 isEvaldUnfolding :: Unfolding -> Bool
277         -- Returns True for OtherCon
278 isEvaldUnfolding (OtherCon _)                     = True
279 isEvaldUnfolding (CoreUnfolding _ _ is_evald _ _) = is_evald
280 isEvaldUnfolding other                            = False
281
282 isCheapUnfolding :: Unfolding -> Bool
283 isCheapUnfolding (CoreUnfolding _ _ _ is_cheap _) = is_cheap
284 isCheapUnfolding other                            = False
285
286 isCompulsoryUnfolding :: Unfolding -> Bool
287 isCompulsoryUnfolding (CompulsoryUnfolding _) = True
288 isCompulsoryUnfolding other                   = False
289
290 hasUnfolding :: Unfolding -> Bool
291 hasUnfolding (CoreUnfolding _ _ _ _ _) = True
292 hasUnfolding (CompulsoryUnfolding _)   = True
293 hasUnfolding other                     = False
294
295 hasSomeUnfolding :: Unfolding -> Bool
296 hasSomeUnfolding NoUnfolding = False
297 hasSomeUnfolding other       = True
298
299 neverUnfold :: Unfolding -> Bool
300 neverUnfold NoUnfolding                         = True
301 neverUnfold (OtherCon _)                        = True
302 neverUnfold (CoreUnfolding _ _ _ _ UnfoldNever) = True
303 neverUnfold other                               = False
304 \end{code}
305
306
307 %************************************************************************
308 %*                                                                      *
309 \subsection{The main data type}
310 %*                                                                      *
311 %************************************************************************
312
313 \begin{code}
314 -- The Ord is needed for the FiniteMap used in the lookForConstructor
315 -- in SimplEnv.  If you declared that lookForConstructor *ignores*
316 -- constructor-applications with LitArg args, then you could get
317 -- rid of this Ord.
318
319 instance Outputable AltCon where
320   ppr (DataAlt dc) = ppr dc
321   ppr (LitAlt lit) = ppr lit
322   ppr DEFAULT      = ptext SLIT("__DEFAULT")
323
324 instance Show AltCon where
325   showsPrec p con = showsPrecSDoc p (ppr con)
326 \end{code}
327
328
329 %************************************************************************
330 %*                                                                      *
331 \subsection{Useful synonyms}
332 %*                                                                      *
333 %************************************************************************
334
335 The common case
336
337 \begin{code}
338 type CoreBndr = Var
339 type CoreExpr = Expr CoreBndr
340 type CoreArg  = Arg  CoreBndr
341 type CoreBind = Bind CoreBndr
342 type CoreAlt  = Alt  CoreBndr
343 \end{code}
344
345 Binders are ``tagged'' with a \tr{t}:
346
347 \begin{code}
348 data TaggedBndr t = TB CoreBndr t       -- TB for "tagged binder"
349
350 type TaggedBind t = Bind (TaggedBndr t)
351 type TaggedExpr t = Expr (TaggedBndr t)
352 type TaggedArg  t = Arg  (TaggedBndr t)
353 type TaggedAlt  t = Alt  (TaggedBndr t)
354
355 instance Outputable b => Outputable (TaggedBndr b) where
356   ppr (TB b l) = char '<' <> ppr b <> comma <> ppr l <> char '>'
357
358 instance Outputable b => OutputableBndr (TaggedBndr b) where
359   pprBndr _ b = ppr b   -- Simple
360 \end{code}
361
362
363 %************************************************************************
364 %*                                                                      *
365 \subsection{Core-constructing functions with checking}
366 %*                                                                      *
367 %************************************************************************
368
369 \begin{code}
370 mkApps    :: Expr b -> [Arg b]  -> Expr b
371 mkTyApps  :: Expr b -> [Type]   -> Expr b
372 mkValApps :: Expr b -> [Expr b] -> Expr b
373 mkVarApps :: Expr b -> [Var] -> Expr b
374
375 mkApps    f args = foldl App                       f args
376 mkTyApps  f args = foldl (\ e a -> App e (Type a)) f args
377 mkValApps f args = foldl (\ e a -> App e a)        f args
378 mkVarApps f vars = foldl (\ e a -> App e (varToCoreExpr a)) f vars
379
380 mkLit         :: Literal -> Expr b
381 mkIntLit      :: Integer -> Expr b
382 mkIntLitInt   :: Int     -> Expr b
383 mkConApp      :: DataCon -> [Arg b] -> Expr b
384 mkLets        :: [Bind b] -> Expr b -> Expr b
385 mkLams        :: [b] -> Expr b -> Expr b
386
387 mkLit lit         = Lit lit
388 mkConApp con args = mkApps (Var (dataConWorkId con)) args
389
390 mkLams binders body = foldr Lam body binders
391 mkLets binds body   = foldr Let body binds
392
393 mkIntLit    n = Lit (mkMachInt n)
394 mkIntLitInt n = Lit (mkMachInt (toInteger n))
395
396 varToCoreExpr :: CoreBndr -> Expr b
397 varToCoreExpr v | isId v    = Var v
398                 | otherwise = Type (mkTyVarTy v)
399 \end{code}
400
401
402 %************************************************************************
403 %*                                                                      *
404 \subsection{Simple access functions}
405 %*                                                                      *
406 %************************************************************************
407
408 \begin{code}
409 bindersOf  :: Bind b -> [b]
410 bindersOf (NonRec binder _) = [binder]
411 bindersOf (Rec pairs)       = [binder | (binder, _) <- pairs]
412
413 bindersOfBinds :: [Bind b] -> [b]
414 bindersOfBinds binds = foldr ((++) . bindersOf) [] binds
415
416 rhssOfBind :: Bind b -> [Expr b]
417 rhssOfBind (NonRec _ rhs) = [rhs]
418 rhssOfBind (Rec pairs)    = [rhs | (_,rhs) <- pairs]
419
420 rhssOfAlts :: [Alt b] -> [Expr b]
421 rhssOfAlts alts = [e | (_,_,e) <- alts]
422
423 flattenBinds :: [Bind b] -> [(b, Expr b)]       -- Get all the lhs/rhs pairs
424 flattenBinds (NonRec b r : binds) = (b,r) : flattenBinds binds
425 flattenBinds (Rec prs1   : binds) = prs1 ++ flattenBinds binds
426 flattenBinds []                   = []
427 \end{code}
428
429 We often want to strip off leading lambdas before getting down to
430 business.  @collectBinders@ is your friend.
431
432 We expect (by convention) type-, and value- lambdas in that
433 order.
434
435 \begin{code}
436 collectBinders               :: Expr b -> ([b],         Expr b)
437 collectTyBinders             :: CoreExpr -> ([TyVar],     CoreExpr)
438 collectValBinders            :: CoreExpr -> ([Id],        CoreExpr)
439 collectTyAndValBinders       :: CoreExpr -> ([TyVar], [Id], CoreExpr)
440
441 collectBinders expr
442   = go [] expr
443   where
444     go bs (Lam b e) = go (b:bs) e
445     go bs e          = (reverse bs, e)
446
447 collectTyAndValBinders expr
448   = (tvs, ids, body)
449   where
450     (tvs, body1) = collectTyBinders expr
451     (ids, body)  = collectValBinders body1
452
453 collectTyBinders expr
454   = go [] expr
455   where
456     go tvs (Lam b e) | isTyVar b = go (b:tvs) e
457     go tvs e                     = (reverse tvs, e)
458
459 collectValBinders expr
460   = go [] expr
461   where
462     go ids (Lam b e) | isId b = go (b:ids) e
463     go ids body               = (reverse ids, body)
464 \end{code}
465
466
467 @collectArgs@ takes an application expression, returning the function
468 and the arguments to which it is applied.
469
470 \begin{code}
471 collectArgs :: Expr b -> (Expr b, [Arg b])
472 collectArgs expr
473   = go expr []
474   where
475     go (App f a) as = go f (a:as)
476     go e         as = (e, as)
477 \end{code}
478
479 coreExprCc gets the cost centre enclosing an expression, if any.
480 It looks inside lambdas because (scc "foo" \x.e) = \x.scc "foo" e
481
482 \begin{code}
483 coreExprCc :: Expr b -> CostCentre
484 coreExprCc (Note (SCC cc) e)   = cc
485 coreExprCc (Note other_note e) = coreExprCc e
486 coreExprCc (Lam _ e)           = coreExprCc e
487 coreExprCc other               = noCostCentre
488 \end{code}
489
490
491
492 %************************************************************************
493 %*                                                                      *
494 \subsection{Predicates}
495 %*                                                                      *
496 %************************************************************************
497
498 @isRuntimeVar v@ returns if (Lam v _) really becomes a lambda at runtime,
499 i.e. if type applications are actual lambdas because types are kept around
500 at runtime.  
501
502 Similarly isRuntimeArg.  
503
504 \begin{code}
505 isRuntimeVar :: Var -> Bool
506 isRuntimeVar | opt_RuntimeTypes = \v -> True
507              | otherwise        = \v -> isId v
508
509 isRuntimeArg :: CoreExpr -> Bool
510 isRuntimeArg | opt_RuntimeTypes = \e -> True
511              | otherwise        = \e -> isValArg e
512 \end{code}
513
514 \begin{code}
515 isValArg (Type _) = False
516 isValArg other    = True
517
518 isTypeArg (Type _) = True
519 isTypeArg other    = False
520
521 valBndrCount :: [CoreBndr] -> Int
522 valBndrCount []                   = 0
523 valBndrCount (b : bs) | isId b    = 1 + valBndrCount bs
524                       | otherwise = valBndrCount bs
525
526 valArgCount :: [Arg b] -> Int
527 valArgCount []              = 0
528 valArgCount (Type _ : args) = valArgCount args
529 valArgCount (other  : args) = 1 + valArgCount args
530 \end{code}
531
532
533 %************************************************************************
534 %*                                                                      *
535 \subsection{Seq stuff}
536 %*                                                                      *
537 %************************************************************************
538
539 \begin{code}
540 seqExpr :: CoreExpr -> ()
541 seqExpr (Var v)       = v `seq` ()
542 seqExpr (Lit lit)     = lit `seq` ()
543 seqExpr (App f a)     = seqExpr f `seq` seqExpr a
544 seqExpr (Lam b e)     = seqBndr b `seq` seqExpr e
545 seqExpr (Let b e)     = seqBind b `seq` seqExpr e
546 seqExpr (Case e b as) = seqExpr e `seq` seqBndr b `seq` seqAlts as
547 seqExpr (Note n e)    = seqNote n `seq` seqExpr e
548 seqExpr (Type t)      = seqType t
549
550 seqExprs [] = ()
551 seqExprs (e:es) = seqExpr e `seq` seqExprs es
552
553 seqNote (Coerce t1 t2) = seqType t1 `seq` seqType t2
554 seqNote (CoreNote s)   = s `seq` ()
555 seqNote other          = ()
556
557 seqBndr b = b `seq` ()
558
559 seqBndrs [] = ()
560 seqBndrs (b:bs) = seqBndr b `seq` seqBndrs bs
561
562 seqBind (NonRec b e) = seqBndr b `seq` seqExpr e
563 seqBind (Rec prs)    = seqPairs prs
564
565 seqPairs [] = ()
566 seqPairs ((b,e):prs) = seqBndr b `seq` seqExpr e `seq` seqPairs prs
567
568 seqAlts [] = ()
569 seqAlts ((c,bs,e):alts) = seqBndrs bs `seq` seqExpr e `seq` seqAlts alts
570
571 seqRules :: CoreRules -> ()
572 seqRules (Rules rules fvs) = seq_rules rules `seq` seqVarSet fvs
573
574 seq_rules [] = ()
575 seq_rules (Rule fs _ bs es e : rules) = seqBndrs bs `seq` seqExprs (e:es) `seq` seq_rules rules
576 seq_rules (BuiltinRule _ _   : rules) = seq_rules rules
577 \end{code}
578
579
580
581 %************************************************************************
582 %*                                                                      *
583 \subsection{Annotated core; annotation at every node in the tree}
584 %*                                                                      *
585 %************************************************************************
586
587 \begin{code}
588 type AnnExpr bndr annot = (annot, AnnExpr' bndr annot)
589
590 data AnnExpr' bndr annot
591   = AnnVar      Id
592   | AnnLit      Literal
593   | AnnLam      bndr (AnnExpr bndr annot)
594   | AnnApp      (AnnExpr bndr annot) (AnnExpr bndr annot)
595   | AnnCase     (AnnExpr bndr annot) bndr [AnnAlt bndr annot]
596   | AnnLet      (AnnBind bndr annot) (AnnExpr bndr annot)
597   | AnnNote     Note (AnnExpr bndr annot)
598   | AnnType     Type
599
600 type AnnAlt bndr annot = (AltCon, [bndr], AnnExpr bndr annot)
601
602 data AnnBind bndr annot
603   = AnnNonRec bndr (AnnExpr bndr annot)
604   | AnnRec    [(bndr, AnnExpr bndr annot)]
605 \end{code}
606
607 \begin{code}
608 deAnnotate :: AnnExpr bndr annot -> Expr bndr
609 deAnnotate (_, e) = deAnnotate' e
610
611 deAnnotate' (AnnType t)           = Type t
612 deAnnotate' (AnnVar  v)           = Var v
613 deAnnotate' (AnnLit  lit)         = Lit lit
614 deAnnotate' (AnnLam  binder body) = Lam binder (deAnnotate body)
615 deAnnotate' (AnnApp  fun arg)     = App (deAnnotate fun) (deAnnotate arg)
616 deAnnotate' (AnnNote note body)   = Note note (deAnnotate body)
617
618 deAnnotate' (AnnLet bind body)
619   = Let (deAnnBind bind) (deAnnotate body)
620   where
621     deAnnBind (AnnNonRec var rhs) = NonRec var (deAnnotate rhs)
622     deAnnBind (AnnRec pairs) = Rec [(v,deAnnotate rhs) | (v,rhs) <- pairs]
623
624 deAnnotate' (AnnCase scrut v alts)
625   = Case (deAnnotate scrut) v (map deAnnAlt alts)
626
627 deAnnAlt :: AnnAlt bndr annot -> Alt bndr
628 deAnnAlt (con,args,rhs) = (con,args,deAnnotate rhs)
629 \end{code}
630
631 \begin{code}
632 collectAnnBndrs :: AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
633 collectAnnBndrs e
634   = collect [] e
635   where
636     collect bs (_, AnnLam b body) = collect (b:bs) body
637     collect bs body               = (reverse bs, body)
638 \end{code}