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