Completely new treatment of INLINE pragmas (big patch)
[ghc-hetmet.git] / compiler / hsSyn / HsBinds.lhs
1 %
2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 %
5 \section[HsBinds]{Abstract syntax: top-level bindings and signatures}
6
7 Datatype for: @BindGroup@, @Bind@, @Sig@, @Bind@.
8
9 \begin{code}
10 {-# OPTIONS -fno-warn-incomplete-patterns #-}
11 -- The above warning supression flag is a temporary kludge.
12 -- While working on this module you are encouraged to remove it and fix
13 -- any warnings in the module. See
14 --     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
15 -- for details
16
17 module HsBinds where
18
19 import {-# SOURCE #-} HsExpr ( HsExpr, pprExpr, LHsExpr,
20                                MatchGroup, pprFunBind,
21                                GRHSs, pprPatBind )
22 import {-# SOURCE #-} HsPat  ( LPat )
23
24 import HsTypes
25 import PprCore ()
26 import Coercion
27 import Type
28 import Name
29 import NameSet
30 import BasicTypes
31 import Outputable       
32 import SrcLoc
33 import Util
34 import Var
35 import Bag
36 import FastString
37 \end{code}
38
39 %************************************************************************
40 %*                                                                      *
41 \subsection{Bindings: @BindGroup@}
42 %*                                                                      *
43 %************************************************************************
44
45 Global bindings (where clauses)
46
47 \begin{code}
48 -- During renaming, we need bindings where the left-hand sides
49 -- have been renamed but the the right-hand sides have not.
50 -- the ...LR datatypes are parametrized by two id types,
51 -- one for the left and one for the right.
52 -- Other than during renaming, these will be the same.
53
54 type HsLocalBinds id = HsLocalBindsLR id id
55
56 data HsLocalBindsLR idL idR     -- Bindings in a 'let' expression
57                                -- or a 'where' clause
58   = HsValBinds (HsValBindsLR idL idR)
59   | HsIPBinds  (HsIPBinds idR)
60   | EmptyLocalBinds
61
62 type HsValBinds id = HsValBindsLR id id
63
64 data HsValBindsLR idL idR  -- Value bindings (not implicit parameters)
65   = ValBindsIn             -- Before typechecking
66         (LHsBindsLR idL idR) [LSig idR] -- Not dependency analysed
67                                         -- Recursive by default
68
69   | ValBindsOut                -- After renaming
70         [(RecFlag, LHsBinds idL)]       -- Dependency analysed, later bindings 
71                                         -- in the list may depend on earlier
72                                         -- ones.
73         [LSig Name]
74
75 type LHsBinds id  = Bag (LHsBind id)
76 type DictBinds id = LHsBinds id         -- Used for dictionary or method bindings
77 type LHsBind  id  = Located (HsBind id)
78 type HsBind id = HsBindLR id id
79
80 type LHsBindLR idL idR = Located (HsBindLR idL idR)
81 type LHsBindsLR idL idR = Bag (LHsBindLR idL idR)
82
83 data HsBindLR idL idR
84   = -- | FunBind is used for both functions   @f x = e@
85     -- and variables                          @f = \x -> e@
86     --
87     -- Reason 1: Special case for type inference: see 'TcBinds.tcMonoBinds'.
88     --
89     -- Reason 2: Instance decls can only have FunBinds, which is convenient.
90     --           If you change this, you'll need to change e.g. rnMethodBinds
91     --
92     -- But note that the form                 @f :: a->a = ...@
93     -- parses as a pattern binding, just like
94     --                                        @(f :: a -> a) = ... @
95     FunBind {
96
97         fun_id :: Located idL,
98
99         fun_infix :: Bool,      -- ^ True => infix declaration
100
101         fun_matches :: MatchGroup idR,  -- ^ The payload
102
103         fun_co_fn :: HsWrapper, -- ^ Coercion from the type of the MatchGroup to the type of
104                                 -- the Id.  Example:
105                                 -- @
106                                 --      f :: Int -> forall a. a -> a
107                                 --      f x y = y
108                                 -- @
109                                 -- Then the MatchGroup will have type (Int -> a' -> a')
110                                 -- (with a free type variable a').  The coercion will take
111                                 -- a CoreExpr of this type and convert it to a CoreExpr of
112                                 -- type         Int -> forall a'. a' -> a'
113                                 -- Notice that the coercion captures the free a'.
114
115         bind_fvs :: NameSet,    -- ^ After the renamer, this contains a superset of the
116                                 -- Names of the other binders in this binding group that 
117                                 -- are free in the RHS of the defn
118                                 -- Before renaming, and after typechecking, 
119                                 -- the field is unused; it's just an error thunk
120
121         fun_tick :: Maybe (Int,[idR])   -- ^ This is the (optional) module-local tick number.
122     }
123
124   | PatBind {   -- The pattern is never a simple variable;
125                 -- That case is done by FunBind
126         pat_lhs    :: LPat idL,
127         pat_rhs    :: GRHSs idR,
128         pat_rhs_ty :: PostTcType,       -- Type of the GRHSs
129         bind_fvs   :: NameSet           -- Same as for FunBind
130     }
131
132   | VarBind {   -- Dictionary binding and suchlike 
133         var_id :: idL,          -- All VarBinds are introduced by the type checker
134         var_rhs :: LHsExpr idR, -- Located only for consistency
135         var_inline :: Bool      -- True <=> inline this binding regardless
136                                 --      (used for implication constraints)
137     }
138
139   | AbsBinds {                                  -- Binds abstraction; TRANSLATION
140         abs_tvs     :: [TyVar],  
141         abs_dicts   :: [DictId],                -- Includes equality constraints
142
143        -- AbsBinds only gets used when idL = idR after renaming,
144        -- but these need to be idL's for the collect... code in HsUtil to have
145        -- the right type
146         abs_exports :: [([TyVar], idL, idL, [LPrag])],  -- (tvs, poly_id, mono_id, prags)
147         abs_binds   :: LHsBinds idL             -- The dictionary bindings and typechecked user bindings
148                                                 -- mixed up together; you can tell the dict bindings because
149                                                 -- they are all VarBinds
150     }
151         -- Consider (AbsBinds tvs ds [(ftvs, poly_f, mono_f) binds]
152         -- 
153         -- Creates bindings for (polymorphic, overloaded) poly_f
154         -- in terms of monomorphic, non-overloaded mono_f
155         --
156         -- Invariants: 
157         --      1. 'binds' binds mono_f
158         --      2. ftvs is a subset of tvs
159         --      3. ftvs includes all tyvars free in ds
160         --
161         -- See section 9 of static semantics paper for more details.
162         -- (You can get a PhD for explaining the True Meaning
163         --  of this last construct.)
164
165 placeHolderNames :: NameSet
166 -- Used for the NameSet in FunBind and PatBind prior to the renamer
167 placeHolderNames = panic "placeHolderNames"
168
169 ------------
170 instance (OutputableBndr idL, OutputableBndr idR) => Outputable (HsLocalBindsLR idL idR) where
171   ppr (HsValBinds bs) = ppr bs
172   ppr (HsIPBinds bs)  = ppr bs
173   ppr EmptyLocalBinds = empty
174
175 instance (OutputableBndr idL, OutputableBndr idR) => Outputable (HsValBindsLR idL idR) where
176   ppr (ValBindsIn binds sigs)
177    = pprValBindsForUser binds sigs
178
179   ppr (ValBindsOut sccs sigs) 
180     = getPprStyle $ \ sty ->
181       if debugStyle sty then    -- Print with sccs showing
182         vcat (map ppr sigs) $$ vcat (map ppr_scc sccs)
183      else
184         pprValBindsForUser (unionManyBags (map snd sccs)) sigs
185    where
186      ppr_scc (rec_flag, binds) = pp_rec rec_flag <+> pprLHsBinds binds
187      pp_rec Recursive    = ptext (sLit "rec")
188      pp_rec NonRecursive = ptext (sLit "nonrec")
189
190 --  *not* pprLHsBinds because we don't want braces; 'let' and
191 -- 'where' include a list of HsBindGroups and we don't want
192 -- several groups of bindings each with braces around.
193 -- Sort by location before printing
194 pprValBindsForUser :: (OutputableBndr idL, OutputableBndr idR, OutputableBndr id2)
195                    => LHsBindsLR idL idR -> [LSig id2] -> SDoc
196 pprValBindsForUser binds sigs
197   = pprDeeperList vcat (map snd (sort_by_loc decls))
198   where
199
200     decls :: [(SrcSpan, SDoc)]
201     decls = [(loc, ppr sig)  | L loc sig <- sigs] ++
202              [(loc, ppr bind) | L loc bind <- bagToList binds]
203
204     sort_by_loc decls = sortLe (\(l1,_) (l2,_) -> l1 <= l2) decls
205
206 pprLHsBinds :: (OutputableBndr idL, OutputableBndr idR) => LHsBindsLR idL idR -> SDoc
207 pprLHsBinds binds 
208   | isEmptyLHsBinds binds = empty
209   | otherwise = lbrace <+> pprDeeperList vcat (map ppr (bagToList binds)) <+> rbrace
210
211 ------------
212 emptyLocalBinds :: HsLocalBindsLR a b
213 emptyLocalBinds = EmptyLocalBinds
214
215 isEmptyLocalBinds :: HsLocalBindsLR a b -> Bool
216 isEmptyLocalBinds (HsValBinds ds) = isEmptyValBinds ds
217 isEmptyLocalBinds (HsIPBinds ds)  = isEmptyIPBinds ds
218 isEmptyLocalBinds EmptyLocalBinds = True
219
220 isEmptyValBinds :: HsValBindsLR a b -> Bool
221 isEmptyValBinds (ValBindsIn ds sigs)  = isEmptyLHsBinds ds && null sigs
222 isEmptyValBinds (ValBindsOut ds sigs) = null ds && null sigs
223
224 emptyValBindsIn, emptyValBindsOut :: HsValBindsLR a b
225 emptyValBindsIn  = ValBindsIn emptyBag []
226 emptyValBindsOut = ValBindsOut []      []
227
228 emptyLHsBinds :: LHsBindsLR idL idR
229 emptyLHsBinds = emptyBag
230
231 isEmptyLHsBinds :: LHsBindsLR idL idR -> Bool
232 isEmptyLHsBinds = isEmptyBag
233
234 ------------
235 plusHsValBinds :: HsValBinds a -> HsValBinds a -> HsValBinds a
236 plusHsValBinds (ValBindsIn ds1 sigs1) (ValBindsIn ds2 sigs2)
237   = ValBindsIn (ds1 `unionBags` ds2) (sigs1 ++ sigs2)
238 plusHsValBinds (ValBindsOut ds1 sigs1) (ValBindsOut ds2 sigs2)
239   = ValBindsOut (ds1 ++ ds2) (sigs1 ++ sigs2)
240 \end{code}
241
242 What AbsBinds means
243 ~~~~~~~~~~~~~~~~~~~
244          AbsBinds tvs
245                   [d1,d2]
246                   [(tvs1, f1p, f1m), 
247                    (tvs2, f2p, f2m)]
248                   BIND
249 means
250
251         f1p = /\ tvs -> \ [d1,d2] -> letrec DBINDS and BIND 
252                                       in fm
253
254         gp = ...same again, with gm instead of fm
255
256 This is a pretty bad translation, because it duplicates all the bindings.
257 So the desugarer tries to do a better job:
258
259         fp = /\ [a,b] -> \ [d1,d2] -> case tp [a,b] [d1,d2] of
260                                         (fm,gm) -> fm
261         ..ditto for gp..
262
263         tp = /\ [a,b] -> \ [d1,d2] -> letrec DBINDS and BIND 
264                                        in (fm,gm)
265
266 \begin{code}
267 instance (OutputableBndr idL, OutputableBndr idR) => Outputable (HsBindLR idL idR) where
268     ppr mbind = ppr_monobind mbind
269
270 ppr_monobind :: (OutputableBndr idL, OutputableBndr idR) => HsBindLR idL idR -> SDoc
271
272 ppr_monobind (PatBind { pat_lhs = pat, pat_rhs = grhss })      = pprPatBind pat grhss
273 ppr_monobind (VarBind { var_id = var, var_rhs = rhs })         = pprBndr CaseBind var <+> equals <+> pprExpr (unLoc rhs)
274 ppr_monobind (FunBind { fun_id = fun, fun_infix = inf,
275                         fun_matches = matches,
276                         fun_tick = tick }) = 
277                            (case tick of 
278                               Nothing -> empty
279                               Just t  -> text "-- tick id = " <> ppr t
280                            ) $$ pprFunBind (unLoc fun) inf matches
281
282 ppr_monobind (AbsBinds { abs_tvs = tyvars, abs_dicts = dictvars, 
283                          abs_exports = exports, abs_binds = val_binds })
284      = sep [ptext (sLit "AbsBinds"),
285             brackets (interpp'SP tyvars),
286             brackets (interpp'SP dictvars),
287             brackets (sep (punctuate comma (map ppr_exp exports)))]
288        $$
289        nest 2 ( vcat [pprBndr LetBind x | (_,x,_,_) <- exports]
290                         -- Print type signatures
291                 $$ pprLHsBinds val_binds )
292   where
293     ppr_exp (tvs, gbl, lcl, prags)
294         = vcat [ppr gbl <+> ptext (sLit "<=") <+> ppr tvs <+> ppr lcl,
295                 nest 2 (vcat (map (pprPrag gbl) prags))]
296 \end{code}
297
298 %************************************************************************
299 %*                                                                      *
300                 Implicit parameter bindings
301 %*                                                                      *
302 %************************************************************************
303
304 \begin{code}
305 data HsIPBinds id
306   = IPBinds 
307         [LIPBind id] 
308         (DictBinds id)  -- Only in typechecker output; binds 
309                         -- uses of the implicit parameters
310
311 isEmptyIPBinds :: HsIPBinds id -> Bool
312 isEmptyIPBinds (IPBinds is ds) = null is && isEmptyBag ds
313
314 type LIPBind id = Located (IPBind id)
315
316 -- | Implicit parameter bindings.
317 data IPBind id
318   = IPBind
319         (IPName id)
320         (LHsExpr id)
321
322 instance (OutputableBndr id) => Outputable (HsIPBinds id) where
323   ppr (IPBinds bs ds) = pprDeeperList vcat (map ppr bs) 
324                         $$ pprLHsBinds ds
325
326 instance (OutputableBndr id) => Outputable (IPBind id) where
327   ppr (IPBind id rhs) = pprBndr LetBind id <+> equals <+> pprExpr (unLoc rhs)
328 \end{code}
329
330
331 %************************************************************************
332 %*                                                                      *
333 \subsection{Coercion functions}
334 %*                                                                      *
335 %************************************************************************
336
337 \begin{code}
338 -- A HsWrapper is an expression with a hole in it
339 -- We need coercions to have concrete form so that we can zonk them
340
341 data HsWrapper
342   = WpHole                      -- The identity coercion
343
344   | WpCompose HsWrapper HsWrapper       -- (\a1..an. []) `WpCompose` (\x1..xn. [])
345                                 --      = (\a1..an \x1..xn. [])
346
347   | WpCast Coercion             -- A cast:  [] `cast` co
348                                 -- Guaranteed not the identity coercion
349
350   | WpApp Var                   -- [] d         the 'd' is a type-class dictionary or coercion variable
351
352   | WpTyApp Type                -- [] t         the 't' is a type or corecion
353                                 --      ToDo: it'd be tidier if 't' was always a type (not coercion),
354                                 --            but that is inconvenient in Inst.instCallDicts
355
356   | WpLam Var                   -- \d. []       the 'd' is a type-class dictionary or coercion variable
357   | WpTyLam TyVar               -- \a. []       the 'a' is a type variable (not coercion var)
358
359         -- Non-empty bindings, so that the identity coercion
360         -- is always exactly WpHole
361   | WpLet (LHsBinds Id)         -- let binds in []
362                                 -- (would be nicer to be core bindings)
363
364 instance Outputable HsWrapper where 
365   ppr co_fn = pprHsWrapper (ptext (sLit "<>")) co_fn
366
367 pprHsWrapper :: SDoc -> HsWrapper -> SDoc
368 pprHsWrapper it wrap = 
369     let 
370         help it WpHole            = it
371         help it (WpCompose f1 f2) = help (help it f2) f1
372         help it (WpCast co)   = sep [it, nest 2 (ptext (sLit "`cast`") <+> pprParendType co)]
373         help it (WpApp id)    = sep [it, nest 2 (ppr id)]
374         help it (WpTyApp ty)  = sep [it, ptext (sLit "@") <+> pprParendType ty]
375         help it (WpLam id)    = sep [ptext (sLit "\\") <> pprBndr LambdaBind id <> dot, it]
376         help it (WpTyLam tv)  = sep [ptext (sLit "/\\") <> pprBndr LambdaBind tv <> dot, it]
377         help it (WpLet binds) = sep [ptext (sLit "let") <+> braces (ppr binds), it]
378     in
379       -- in debug mode, print the wrapper
380       -- otherwise just print what's inside
381       getPprStyle (\ s -> if debugStyle s then (help it wrap) else it)
382
383 (<.>) :: HsWrapper -> HsWrapper -> HsWrapper
384 WpHole <.> c = c
385 c <.> WpHole = c
386 c1 <.> c2    = c1 `WpCompose` c2
387
388 mkWpTyApps :: [Type] -> HsWrapper
389 mkWpTyApps tys = mk_co_fn WpTyApp (reverse tys)
390
391 mkWpApps :: [Var] -> HsWrapper
392 mkWpApps ids = mk_co_fn WpApp (reverse ids)
393
394 mkWpTyLams :: [TyVar] -> HsWrapper
395 mkWpTyLams ids = mk_co_fn WpTyLam ids
396
397 mkWpLams :: [Var] -> HsWrapper
398 mkWpLams ids = mk_co_fn WpLam ids
399
400 mk_co_fn :: (a -> HsWrapper) -> [a] -> HsWrapper
401 mk_co_fn f as = foldr (WpCompose . f) WpHole as
402
403 idHsWrapper :: HsWrapper
404 idHsWrapper = WpHole
405
406 isIdHsWrapper :: HsWrapper -> Bool
407 isIdHsWrapper WpHole = True
408 isIdHsWrapper _      = False
409 \end{code}
410
411
412 %************************************************************************
413 %*                                                                      *
414 \subsection{@Sig@: type signatures and value-modifying user pragmas}
415 %*                                                                      *
416 %************************************************************************
417
418 It is convenient to lump ``value-modifying'' user-pragmas (e.g.,
419 ``specialise this function to these four types...'') in with type
420 signatures.  Then all the machinery to move them into place, etc.,
421 serves for both.
422
423 \begin{code}
424 type LSig name = Located (Sig name)
425
426 data Sig name   -- Signatures and pragmas
427   =     -- An ordinary type signature
428         -- f :: Num a => a -> a
429     TypeSig     (Located name)  -- A bog-std type signature
430                 (LHsType name)
431
432         -- An ordinary fixity declaration
433         --      infixl *** 8
434   | FixSig      (FixitySig name)        -- Fixity declaration
435
436         -- An inline pragma
437         -- {#- INLINE f #-}
438   | InlineSig   (Located name)  -- Function name
439                 InlineSpec
440
441         -- A specialisation pragma
442         -- {-# SPECIALISE f :: Int -> Int #-}
443   | SpecSig     (Located name)  -- Specialise a function or datatype ...
444                 (LHsType name)  -- ... to these types
445                 InlineSpec
446
447         -- A specialisation pragma for instance declarations only
448         -- {-# SPECIALISE instance Eq [Int] #-}
449   | SpecInstSig (LHsType name)  -- (Class tys); should be a specialisation of the 
450                                 -- current instance decl
451
452
453 type LFixitySig name = Located (FixitySig name)
454 data FixitySig name = FixitySig (Located name) Fixity 
455
456 -- A Prag conveys pragmas from the type checker to the desugarer
457 type LPrag = Located Prag
458 data Prag 
459   = InlinePrag 
460         InlineSpec
461
462   | SpecPrag   
463         (HsExpr Id)     -- An expression, of the given specialised type, which
464         PostTcType      -- specialises the polymorphic function
465         InlineSpec      -- Inlining spec for the specialised function
466
467 isInlinePrag :: Prag -> Bool
468 isInlinePrag (InlinePrag _) = True
469 isInlinePrag _              = False
470
471 isSpecPrag :: Prag -> Bool
472 isSpecPrag (SpecPrag {}) = True
473 isSpecPrag _             = False
474 \end{code}
475
476 \begin{code}
477 okBindSig :: Sig a -> Bool
478 okBindSig _ = True
479
480 okHsBootSig :: Sig a -> Bool
481 okHsBootSig (TypeSig  _ _) = True
482 okHsBootSig (FixSig _)     = True
483 okHsBootSig _              = False
484
485 okClsDclSig :: Sig a -> Bool
486 okClsDclSig (SpecInstSig _) = False
487 okClsDclSig _               = True        -- All others OK
488
489 okInstDclSig :: Sig a -> Bool
490 okInstDclSig (TypeSig _ _)   = False
491 okInstDclSig (FixSig _)      = False
492 okInstDclSig _               = True
493
494 sigForThisGroup :: NameSet -> LSig Name -> Bool
495 sigForThisGroup ns sig
496   = case sigName sig of
497         Nothing -> False
498         Just n  -> n `elemNameSet` ns
499
500 sigName :: LSig name -> Maybe name
501 sigName (L _ sig) = sigNameNoLoc sig
502
503 sigNameNoLoc :: Sig name -> Maybe name    
504 sigNameNoLoc (TypeSig   n _)          = Just (unLoc n)
505 sigNameNoLoc (SpecSig   n _ _)        = Just (unLoc n)
506 sigNameNoLoc (InlineSig n _)          = Just (unLoc n)
507 sigNameNoLoc (FixSig (FixitySig n _)) = Just (unLoc n)
508 sigNameNoLoc _                        = Nothing
509
510 isFixityLSig :: LSig name -> Bool
511 isFixityLSig (L _ (FixSig {})) = True
512 isFixityLSig _                 = False
513
514 isVanillaLSig :: LSig name -> Bool
515 isVanillaLSig (L _(TypeSig {})) = True
516 isVanillaLSig _                 = False
517
518 isSpecLSig :: LSig name -> Bool
519 isSpecLSig (L _(SpecSig {})) = True
520 isSpecLSig _                 = False
521
522 isSpecInstLSig :: LSig name -> Bool
523 isSpecInstLSig (L _ (SpecInstSig {})) = True
524 isSpecInstLSig _                      = False
525
526 isPragLSig :: LSig name -> Bool
527         -- Identifies pragmas 
528 isPragLSig (L _ (SpecSig {}))   = True
529 isPragLSig (L _ (InlineSig {})) = True
530 isPragLSig _                    = False
531
532 isInlineLSig :: LSig name -> Bool
533         -- Identifies inline pragmas 
534 isInlineLSig (L _ (InlineSig {})) = True
535 isInlineLSig _                    = False
536
537 hsSigDoc :: Sig name -> SDoc
538 hsSigDoc (TypeSig {})           = ptext (sLit "type signature")
539 hsSigDoc (SpecSig {})           = ptext (sLit "SPECIALISE pragma")
540 hsSigDoc (InlineSig {})         = ptext (sLit "INLINE pragma")
541 hsSigDoc (SpecInstSig {})       = ptext (sLit "SPECIALISE instance pragma")
542 hsSigDoc (FixSig {})            = ptext (sLit "fixity declaration")
543 \end{code}
544
545 Signature equality is used when checking for duplicate signatures
546
547 \begin{code}
548 eqHsSig :: Eq a => LSig a -> LSig a -> Bool
549 eqHsSig (L _ (FixSig (FixitySig n1 _))) (L _ (FixSig (FixitySig n2 _))) = unLoc n1 == unLoc n2
550 eqHsSig (L _ (TypeSig n1 _))            (L _ (TypeSig n2 _))            = unLoc n1 == unLoc n2
551 eqHsSig (L _ (InlineSig n1 _))          (L _ (InlineSig n2 _))          = unLoc n1 == unLoc n2
552         -- For specialisations, we don't have equality over
553         -- HsType, so it's not convenient to spot duplicate 
554         -- specialisations here.  Check for this later, when we're in Type land
555 eqHsSig _other1 _other2 = False
556 \end{code}
557
558 \begin{code}
559 instance (OutputableBndr name) => Outputable (Sig name) where
560     ppr sig = ppr_sig sig
561
562 ppr_sig :: OutputableBndr name => Sig name -> SDoc
563 ppr_sig (TypeSig var ty)          = pprVarSig (unLoc var) ty
564 ppr_sig (FixSig fix_sig)          = ppr fix_sig
565 ppr_sig (SpecSig var ty inl)      = pragBrackets (pprSpec var ty inl)
566 ppr_sig (InlineSig var inl)       = pragBrackets (ppr inl <+> ppr var)
567 ppr_sig (SpecInstSig ty)          = pragBrackets (ptext (sLit "SPECIALIZE instance") <+> ppr ty)
568
569 instance Outputable name => Outputable (FixitySig name) where
570   ppr (FixitySig name fixity) = sep [ppr fixity, ppr name]
571
572 pragBrackets :: SDoc -> SDoc
573 pragBrackets doc = ptext (sLit "{-#") <+> doc <+> ptext (sLit "#-}") 
574
575 pprVarSig :: (Outputable id, Outputable ty) => id -> ty -> SDoc
576 pprVarSig var ty = sep [ppr var <+> dcolon, nest 2 (ppr ty)]
577
578 pprSpec :: (Outputable id, Outputable ty) => id -> ty -> InlineSpec -> SDoc
579 pprSpec var ty inl = sep [ptext (sLit "SPECIALIZE") <+> ppr inl <+> pprVarSig var ty]
580
581 pprPrag :: Outputable id => id -> LPrag -> SDoc
582 pprPrag var (L _ (InlinePrag inl))        = ppr inl <+> ppr var
583 pprPrag var (L _ (SpecPrag _expr ty inl)) = pprSpec var ty inl
584 \end{code}
585