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