HsBinds.hs 48.1 KB
Newer Older
Austin Seipp's avatar
Austin Seipp committed
1 2 3 4
{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

5 6
\section[HsBinds]{Abstract syntax: top-level bindings and signatures}

7
Datatype for: @BindGroup@, @Bind@, @Sig@, @Bind@.
Austin Seipp's avatar
Austin Seipp committed
8
-}
9

10
{-# LANGUAGE DeriveDataTypeable #-}
11 12 13 14 15
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types]
                                      -- in module PlaceHolder
{-# LANGUAGE ConstraintKinds #-}
16
{-# LANGUAGE BangPatterns #-}
17
{-# LANGUAGE TypeFamilies #-}
18

19 20
module HsBinds where

21 22
import GhcPrelude

23
import {-# SOURCE #-} HsExpr ( pprExpr, LHsExpr,
24 25
                               MatchGroup, pprFunBind,
                               GRHSs, pprPatBind )
26
import {-# SOURCE #-} HsPat  ( LPat )
sof's avatar
sof committed
27

28
import HsExtension
29
import HsTypes
30
import PprCore ()
31
import CoreSyn
32
import TcEvidence
33 34 35
import Type
import NameSet
import BasicTypes
36
import Outputable
37 38 39
import SrcLoc
import Var
import Bag
40
import FastString
41
import BooleanFormula (LBooleanFormula)
42
import DynFlags
43 44

import Data.Data hiding ( Fixity )
45
import Data.List hiding ( foldr )
46
import Data.Ord
47

Austin Seipp's avatar
Austin Seipp committed
48 49 50
{-
************************************************************************
*                                                                      *
51
\subsection{Bindings: @BindGroup@}
Austin Seipp's avatar
Austin Seipp committed
52 53
*                                                                      *
************************************************************************
54

55
Global bindings (where clauses)
Austin Seipp's avatar
Austin Seipp committed
56
-}
57

58
-- During renaming, we need bindings where the left-hand sides
59
-- have been renamed but the right-hand sides have not.
60 61 62 63
-- the ...LR datatypes are parametrized by two id types,
-- one for the left and one for the right.
-- Other than during renaming, these will be the same.

64
-- | Haskell Local Bindings
65 66
type HsLocalBinds id = HsLocalBindsLR id id

67 68 69
-- | Located Haskell local bindings
type LHsLocalBinds id = Located (HsLocalBinds id)

70 71 72
-- | Haskell Local Bindings with separate Left and Right identifier types
--
-- Bindings in a 'let' expression
73
-- or a 'where' clause
74
data HsLocalBindsLR idL idR
75 76 77
  = HsValBinds
        (XHsValBinds idL idR)
        (HsValBindsLR idL idR)
78 79
      -- ^ Haskell Value Bindings

80 81
         -- There should be no pattern synonyms in the HsValBindsLR
         -- These are *local* (not top level) bindings
82
         -- The parser accepts them, however, leaving the
83 84
         -- renamer to report them

85 86 87
  | HsIPBinds
        (XHsIPBinds idL idR)
        (HsIPBinds idR)
88
      -- ^ Haskell Implicit Parameter Bindings
89

90
  | EmptyLocalBinds (XEmptyLocalBinds idL idR)
91
      -- ^ Empty Local Bindings
92

93 94 95
  | XHsLocalBindsLR
        (XXHsLocalBindsLR idL idR)

96 97 98 99
type instance XHsValBinds      (GhcPass pL) (GhcPass pR) = NoExt
type instance XHsIPBinds       (GhcPass pL) (GhcPass pR) = NoExt
type instance XEmptyLocalBinds (GhcPass pL) (GhcPass pR) = NoExt
type instance XXHsLocalBindsLR (GhcPass pL) (GhcPass pR) = NoExt
100

101 102
type LHsLocalBindsLR idL idR = Located (HsLocalBindsLR idL idR)

sof's avatar
sof committed
103

104
-- | Haskell Value Bindings
105 106
type HsValBinds id = HsValBindsLR id id

107 108
-- | Haskell Value bindings with separate Left and Right identifier types
-- (not implicit parameters)
109 110
-- Used for both top level and nested bindings
-- May contain pattern synonym bindings
111
data HsValBindsLR idL idR
112 113 114
  = -- | Value Bindings In
    --
    -- Before renaming RHS; idR is always RdrName
115 116
    -- Not dependency analysed
    -- Recursive by default
117 118
    ValBinds
        (XValBinds idL idR)
119
        (LHsBindsLR idL idR) [LSig idR]
120

121 122 123 124
    -- | Value Bindings Out
    --
    -- After renaming RHS; idR can be Name or Id Dependency analysed,
    -- later bindings in the list may depend on earlier ones.
125 126
  | XValBindsLR
      (XXValBindsLR idL idR)
127

128 129 130 131 132 133 134 135 136
-- ---------------------------------------------------------------------
-- Deal with ValBindsOut

-- TODO: make this the only type for ValBinds
data NHsValBindsLR idL
  = NValBinds
      [(RecFlag, LHsBinds idL)]
      [LSig GhcRn]

137
type instance XValBinds    (GhcPass pL) (GhcPass pR) = NoExt
138 139 140 141
type instance XXValBindsLR (GhcPass pL) (GhcPass pR)
            = NHsValBindsLR (GhcPass pL)

-- ---------------------------------------------------------------------
142

143
-- | Located Haskell Binding
144
type LHsBind  id = LHsBindLR  id id
145 146

-- | Located Haskell Bindings
147
type LHsBinds id = LHsBindsLR id id
148 149

-- | Haskell Binding
150
type HsBind   id = HsBindLR   id id
151

152
-- | Located Haskell Bindings with separate Left and Right identifier types
153
type LHsBindsLR idL idR = Bag (LHsBindLR idL idR)
154 155

-- | Located Haskell Binding with separate Left and Right identifier types
156
type LHsBindLR  idL idR = Located (HsBindLR idL idR)
157

158 159
{- Note [FunBind vs PatBind]
   ~~~~~~~~~~~~~~~~~~~~~~~~~
160 161 162 163 164 165 166 167 168 169
The distinction between FunBind and PatBind is a bit subtle. FunBind covers
patterns which resemble function bindings and simple variable bindings.

    f x = e
    f !x = e
    f = e
    !x = e          -- FunRhs has SrcStrict
    x `f` y = e     -- FunRhs has Infix

The actual patterns and RHSs of a FunBind are encoding in fun_matches.
170 171 172 173 174 175 176
The m_ctxt field of each Match in fun_matches will be FunRhs and carries
two bits of information about the match,

  * The mc_fixity field on each Match describes the fixity of the
    function binder in that match.  E.g. this is legal:
         f True False  = e1
         True `f` True = e2
177

178 179 180
  * The mc_strictness field is used /only/ for nullary FunBinds: ones
    with one Match, which has no pats. For these, it describes whether
    the match is decorated with a bang (e.g. `!x = e`).
181 182 183 184 185 186 187 188 189

By contrast, PatBind represents data constructor patterns, as well as a few
other interesting cases. Namely,

    Just x = e
    (x) = e
    x :: Ty = e
-}

190
-- | Haskell Binding with separate Left and Right id's
191
data HsBindLR idL idR
192
  = -- | Function-like Binding
193 194
    --
    -- FunBind is used for both functions     @f x = e@
195
    -- and variables                          @f = \x -> e@
196
    -- and strict variables                   @!x = x + 1@
197 198 199 200 201 202 203 204 205
    --
    -- Reason 1: Special case for type inference: see 'TcBinds.tcMonoBinds'.
    --
    -- Reason 2: Instance decls can only have FunBinds, which is convenient.
    --           If you change this, you'll need to change e.g. rnMethodBinds
    --
    -- But note that the form                 @f :: a->a = ...@
    -- parses as a pattern binding, just like
    --                                        @(f :: a -> a) = ... @
Alan Zimmerman's avatar
Alan Zimmerman committed
206
    --
207
    -- Strict bindings have their strictness recorded in the 'SrcStrictness' of their
208
    -- 'MatchContext'. See Note [FunBind vs PatBind] for
209 210
    -- details about the relationship between FunBind and PatBind.
    --
Alan Zimmerman's avatar
Alan Zimmerman committed
211 212 213 214 215 216
    --  'ApiAnnotation.AnnKeywordId's
    --
    --  - 'ApiAnnotation.AnnFunId', attached to each element of fun_matches
    --
    --  - 'ApiAnnotation.AnnEqual','ApiAnnotation.AnnWhere',
    --    'ApiAnnotation.AnnOpen','ApiAnnotation.AnnClose',
217 218

    -- For details on above see note [Api annotations] in ApiAnnotation
219
    FunBind {
220

221 222 223 224 225
        fun_ext :: XFunBind idL idR, -- ^ After the renamer, this contains
                                --  the locally-bound
                                -- free variables of this defn.
                                -- See Note [Bind free vars]

226
        fun_id :: Located (IdP idL), -- Note [fun_id in Match] in HsExpr
227

228
        fun_matches :: MatchGroup idR (LHsExpr idR),  -- ^ The payload
229

230 231
        fun_co_fn :: HsWrapper, -- ^ Coercion from the type of the MatchGroup to the type of
                                -- the Id.  Example:
Alan Zimmerman's avatar
Alan Zimmerman committed
232
                                --
233
                                -- @
234 235
                                --      f :: Int -> forall a. a -> a
                                --      f x y = y
236
                                -- @
Alan Zimmerman's avatar
Alan Zimmerman committed
237
                                --
238 239 240 241 242
                                -- Then the MatchGroup will have type (Int -> a' -> a')
                                -- (with a free type variable a').  The coercion will take
                                -- a CoreExpr of this type and convert it to a CoreExpr of
                                -- type         Int -> forall a'. a' -> a'
                                -- Notice that the coercion captures the free a'.
243

244
        fun_tick :: [Tickish Id] -- ^ Ticks to put on the rhs, if any
245 246
    }

247 248 249
  -- | Pattern Binding
  --
  -- The pattern is never a simple variable;
250
  -- That case is done by FunBind.
251
  -- See Note [FunBind vs PatBind] for details about the
252 253
  -- relationship between FunBind and PatBind.

Alan Zimmerman's avatar
Alan Zimmerman committed
254 255 256 257
  --
  --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnBang',
  --       'ApiAnnotation.AnnEqual','ApiAnnotation.AnnWhere',
  --       'ApiAnnotation.AnnOpen','ApiAnnotation.AnnClose',
258 259

  -- For details on above see note [Api annotations] in ApiAnnotation
260
  | PatBind {
261
        pat_ext    :: XPatBind idL idR, -- ^ See Note [Bind free vars]
262
        pat_lhs    :: LPat idL,
263
        pat_rhs    :: GRHSs idR (LHsExpr idR),
264 265
        pat_ticks  :: ([Tickish Id], [[Tickish Id]])
               -- ^ Ticks to put on the rhs, if any, and ticks to put on
266
               -- the bound variables.
267 268
    }

269 270 271
  -- | Variable Binding
  --
  -- Dictionary binding and suchlike.
272
  -- All VarBinds are introduced by the type checker
273
  | VarBind {
274
        var_ext    :: XVarBind idL idR,
275
        var_id     :: IdP idL,
276 277
        var_rhs    :: LHsExpr idR,   -- ^ Located only for consistency
        var_inline :: Bool           -- ^ True <=> inline this binding regardless
278
                                     -- (used for implication constraints only)
279 280
    }

281
  -- | Abstraction Bindings
282
  | AbsBinds {                      -- Binds abstraction; TRANSLATION
283
        abs_ext     :: XAbsBinds idL idR,
284
        abs_tvs     :: [TyVar],
285
        abs_ev_vars :: [EvVar],  -- ^ Includes equality constraints
286

287
       -- | AbsBinds only gets used when idL = idR after renaming,
288
       -- but these need to be idL's for the collect... code in HsUtil
Simon Peyton Jones's avatar
Simon Peyton Jones committed
289
       -- to have the right type
290
        abs_exports :: [ABExport idL],
291

292 293 294 295 296 297
        -- | Evidence bindings
        -- Why a list? See TcInstDcls
        -- Note [Typechecking plan for instance declarations]
        abs_ev_binds :: [TcEvBinds],

        -- | Typechecked user bindings
298
        abs_binds    :: LHsBinds idL,
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
299

300
        abs_sig :: Bool  -- See Note [The abs_sig field of AbsBinds]
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
301 302
    }

303
  -- | Patterns Synonym Binding
304 305 306
  | PatSynBind
        (XPatSynBind idL idR)
        (PatSynBind idL idR)
Alan Zimmerman's avatar
Alan Zimmerman committed
307
        -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnPattern',
Alan Zimmerman's avatar
Alan Zimmerman committed
308 309 310
        --          'ApiAnnotation.AnnLarrow','ApiAnnotation.AnnEqual',
        --          'ApiAnnotation.AnnWhere'
        --          'ApiAnnotation.AnnOpen' @'{'@,'ApiAnnotation.AnnClose' @'}'@
cactus's avatar
cactus committed
311

312 313
        -- For details on above see note [Api annotations] in ApiAnnotation

314 315 316 317 318 319 320
  | XHsBindsLR (XXHsBindsLR idL idR)

data NPatBindTc = NPatBindTc {
     pat_fvs :: NameSet, -- ^ Free variables
     pat_rhs_ty :: Type  -- ^ Type of the GRHSs
     } deriving Data

321
type instance XFunBind    (GhcPass pL) GhcPs = NoExt
322 323 324
type instance XFunBind    (GhcPass pL) GhcRn = NameSet -- Free variables
type instance XFunBind    (GhcPass pL) GhcTc = NameSet -- Free variables

325
type instance XPatBind    GhcPs (GhcPass pR) = NoExt
326 327 328
type instance XPatBind    GhcRn (GhcPass pR) = NameSet -- Free variables
type instance XPatBind    GhcTc (GhcPass pR) = NPatBindTc

329 330 331 332
type instance XVarBind    (GhcPass pL) (GhcPass pR) = NoExt
type instance XAbsBinds   (GhcPass pL) (GhcPass pR) = NoExt
type instance XPatSynBind (GhcPass pL) (GhcPass pR) = NoExt
type instance XXHsBindsLR (GhcPass pL) (GhcPass pR) = NoExt
333

334

335 336 337 338 339 340 341 342 343 344
        -- Consider (AbsBinds tvs ds [(ftvs, poly_f, mono_f) binds]
        --
        -- Creates bindings for (polymorphic, overloaded) poly_f
        -- in terms of monomorphic, non-overloaded mono_f
        --
        -- Invariants:
        --      1. 'binds' binds mono_f
        --      2. ftvs is a subset of tvs
        --      3. ftvs includes all tyvars free in ds
        --
345
        -- See Note [AbsBinds]
346

347
-- | Abtraction Bindings Export
348
data ABExport p
349 350
  = ABE { abe_ext       :: XABE p
        , abe_poly      :: IdP p -- ^ Any INLINE pragma is attached to this Id
351
        , abe_mono      :: IdP p
352 353
        , abe_wrap      :: HsWrapper    -- ^ See Note [ABExport wrapper]
             -- Shape: (forall abs_tvs. abs_ev_vars => abe_mono) ~ abe_poly
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
354
        , abe_prags     :: TcSpecPrags  -- ^ SPECIALISE pragmas
355 356 357
        }
   | XABExport (XXABExport p)

358 359
type instance XABE       (GhcPass p) = NoExt
type instance XXABExport (GhcPass p) = NoExt
360

361

Alan Zimmerman's avatar
Alan Zimmerman committed
362 363 364 365
-- | - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnPattern',
--             'ApiAnnotation.AnnEqual','ApiAnnotation.AnnLarrow'
--             'ApiAnnotation.AnnWhere','ApiAnnotation.AnnOpen' @'{'@,
--             'ApiAnnotation.AnnClose' @'}'@,
366 367

-- For details on above see note [Api annotations] in ApiAnnotation
368 369

-- | Pattern Synonym binding
370
data PatSynBind idL idR
371 372
  = PSB { psb_ext  :: XPSB idL idR,            -- ^ Post renaming, FVs.
                                               -- See Note [Bind free vars]
373
          psb_id   :: Located (IdP idL),       -- ^ Name of the pattern synonym
374 375 376 377
          psb_args :: HsPatSynDetails (Located (IdP idR)),
                                               -- ^ Formal parameter names
          psb_def  :: LPat idR,                -- ^ Right-hand side
          psb_dir  :: HsPatSynDir idR          -- ^ Directionality
378 379 380
     }
   | XPatSynBind (XXPatSynBind idL idR)

381 382 383 384 385
type instance XPSB         (GhcPass idL) GhcPs = NoExt
type instance XPSB         (GhcPass idL) GhcRn = NameSet
type instance XPSB         (GhcPass idL) GhcTc = NameSet

type instance XXPatSynBind (GhcPass idL) (GhcPass idR) = NoExt
386

Austin Seipp's avatar
Austin Seipp committed
387
{-
388 389
Note [AbsBinds]
~~~~~~~~~~~~~~~
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
The AbsBinds constructor is used in the output of the type checker, to
record *typechecked* and *generalised* bindings.  Specifically

         AbsBinds { abs_tvs      = tvs
                  , abs_ev_vars  = [d1,d2]
                  , abs_exports  = [ABE { abe_poly = fp, abe_mono = fm
                                        , abe_wrap = fwrap }
                                    ABE { slly for g } ]
                  , abs_ev_binds = DBINDS
                  , abs_binds    = BIND[fm,gm] }

where 'BIND' binds the monomorphic Ids 'fm' and 'gm', means

        fp = fwrap [/\ tvs. \d1 d2. letrec { DBINDS        ]
                   [                       ; BIND[fm,gm] } ]
                   [                 in fm                 ]

        gp = ...same again, with gm instead of fm

The 'fwrap' is an impedence-matcher that typically does nothing; see
Note [ABExport wrapper].

This is a pretty bad translation, because it duplicates all the bindings.
So the desugarer tries to do a better job:

        fp = /\ [a,b] -> \ [d1,d2] -> case tp [a,b] [d1,d2] of
                                        (fm,gm) -> fm
        ..ditto for gp..

        tp = /\ [a,b] -> \ [d1,d2] -> letrec { DBINDS; BIND }
                                      in (fm,gm)

In general:

  * abs_tvs are the type variables over which the binding group is
    generalised
  * abs_ev_var are the evidence variables (usually dictionaries)
    over which the binding group is generalised
  * abs_binds are the monomorphic bindings
  * abs_ex_binds are the evidence bindings that wrap the abs_binds
  * abs_exports connects the monomorphic Ids bound by abs_binds
    with the polymorphic Ids bound by the AbsBinds itself.

For example, consider a module M, with this top-level binding, where
there is no type signature for M.reverse,
435 436 437
    M.reverse []     = []
    M.reverse (x:xs) = M.reverse xs ++ [x]

438 439 440
In Hindley-Milner, a recursive binding is typechecked with the
*recursive* uses being *monomorphic*.  So after typechecking *and*
desugaring we will get something like this
441

442
    M.reverse :: forall a. [a] -> [a]
443
      = /\a. letrec
444 445 446 447 448 449
                reverse :: [a] -> [a] = \xs -> case xs of
                                                []     -> []
                                                (x:xs) -> reverse xs ++ [x]
             in reverse

Notice that 'M.reverse' is polymorphic as expected, but there is a local
Simon Peyton Jones's avatar
Simon Peyton Jones committed
450
definition for plain 'reverse' which is *monomorphic*.  The type variable
451 452
'a' scopes over the entire letrec.

453 454
That's after desugaring.  What about after type checking but before
desugaring?  That's where AbsBinds comes in.  It looks like this:
455 456

   AbsBinds { abs_tvs     = [a]
457
            , abs_ev_vars = []
458
            , abs_exports = [ABE { abe_poly = M.reverse :: forall a. [a] -> [a],
dfordivam's avatar
dfordivam committed
459
                                 , abe_mono = reverse :: [a] -> [a]}]
460
            , abs_ev_binds = {}
461
            , abs_binds = { reverse :: [a] -> [a]
462 463 464 465 466
                               = \xs -> case xs of
                                            []     -> []
                                            (x:xs) -> reverse xs ++ [x] } }

Here,
467 468 469

  * abs_tvs says what type variables are abstracted over the binding
    group, just 'a' in this case.
470
  * abs_binds is the *monomorphic* bindings of the group
471 472
  * abs_exports describes how to get the polymorphic Id 'M.reverse'
    from the monomorphic one 'reverse'
473 474 475 476 477 478

Notice that the *original* function (the polymorphic one you thought
you were defining) appears in the abe_poly field of the
abs_exports. The bindings in abs_binds are for fresh, local, Ids with
a *monomorphic* Id.

Gabor Greif's avatar
Gabor Greif committed
479
If there is a group of mutually recursive (see Note [Polymorphic
480 481 482 483
recursion]) functions without type signatures, we get one AbsBinds
with the monomorphic versions of the bindings in abs_binds, and one
element of abe_exports for each variable bound in the mutually
recursive group.  This is true even for pattern bindings.  Example:
484 485 486 487 488 489 490 491 492
        (f,g) = (\x -> x, f)
After type checking we get
   AbsBinds { abs_tvs     = [a]
            , abs_exports = [ ABE { abe_poly = M.f :: forall a. a -> a
                                  , abe_mono = f :: a -> a }
                            , ABE { abe_poly = M.g :: forall a. a -> a
                                  , abe_mono = g :: a -> a }]
            , abs_binds = { (f,g) = (\x -> x, f) }

Gabor Greif's avatar
Gabor Greif committed
493
Note [Polymorphic recursion]
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
   Rec { f x = ...(g ef)...

       ; g :: forall a. [a] -> [a]
       ; g y = ...(f eg)...  }

These bindings /are/ mutually recursive (f calls g, and g calls f).
But we can use the type signature for g to break the recursion,
like this:

  1. Add g :: forall a. [a] -> [a] to the type environment

  2. Typecheck the definition of f, all by itself,
     including generalising it to find its most general
     type, say f :: forall b. b -> b -> [b]

  3. Extend the type environment with that type for f

  4. Typecheck the definition of g, all by itself,
     checking that it has the type claimed by its signature

Steps 2 and 4 each generate a separate AbsBinds, so we end
up with
   Rec { AbsBinds { ...for f ... }
       ; AbsBinds { ...for g ... } }

This approach allows both f and to call each other
Gabor Greif's avatar
Gabor Greif committed
522
polymorphically, even though only g has a signature.
523 524 525 526 527 528 529

We get an AbsBinds that encompasses multiple source-program
bindings only when
 * Each binding in the group has at least one binder that
   lacks a user type signature
 * The group forms a strongly connected component

530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576

Note [The abs_sig field of AbsBinds]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The abs_sig field supports a couple of special cases for bindings.
Consider

  x :: Num a => (# a, a #)
  x = (# 3, 4 #)

The general desugaring for AbsBinds would give

  x = /\a. \ ($dNum :: Num a) ->
      letrec xm = (# fromInteger $dNum 3, fromInteger $dNum 4 #) in
      xm

But that has an illegal let-binding for an unboxed tuple.  In this
case we'd prefer to generate the (more direct)

  x = /\ a. \ ($dNum :: Num a) ->
     (# fromInteger $dNum 3, fromInteger $dNum 4 #)

A similar thing happens with representation-polymorphic defns
(Trac #11405):

  undef :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => a
  undef = error "undef"

Again, the vanilla desugaring gives a local let-binding for a
representation-polymorphic (undefm :: a), which is illegal.  But
again we can desugar without a let:

  undef = /\ a. \ (d:HasCallStack) -> error a d "undef"

The abs_sig field supports this direct desugaring, with no local
let-bining.  When abs_sig = True

 * the abs_binds is single FunBind

 * the abs_exports is a singleton

 * we have a complete type sig for binder
   and hence the abs_binds is non-recursive
   (it binds the mono_id but refers to the poly_id

These properties are exploited in DsBinds.dsAbsBinds to
generate code without a let-binding.

577 578
Note [ABExport wrapper]
~~~~~~~~~~~~~~~~~~~~~~~
Simon Peyton Jones's avatar
Simon Peyton Jones committed
579
Consider
580 581 582 583 584
   (f,g) = (\x.x, \y.y)
This ultimately desugars to something like this:
   tup :: forall a b. (a->a, b->b)
   tup = /\a b. (\x:a.x, \y:b.y)
   f :: forall a. a -> a
585
   f = /\a. case tup a Any of
586 587 588
               (fm::a->a,gm:Any->Any) -> fm
   ...similarly for g...

Gabor Greif's avatar
Gabor Greif committed
589
The abe_wrap field deals with impedance-matching between
590 591 592 593 594 595 596
    (/\a b. case tup a b of { (f,g) -> f })
and the thing we really want, which may have fewer type
variables.  The action happens in TcBinds.mkExport.

Note [Bind free vars]
~~~~~~~~~~~~~~~~~~~~~
The bind_fvs field of FunBind and PatBind records the free variables
597
of the definition.  It is used for the following purposes
598 599 600

a) Dependency analysis prior to type checking
    (see TcBinds.tc_group)
601

602 603 604
b) Deciding whether we can do generalisation of the binding
    (see TcBinds.decideGeneralisationPlan)

605 606 607 608
c) Deciding whether the binding can be used in static forms
    (see TcExpr.checkClosedInStaticForm for the HsStatic case and
     TcBinds.isClosedBndrGroup).

609
Specifically,
610 611 612 613 614 615 616 617

  * bind_fvs includes all free vars that are defined in this module
    (including top-level things and lexically scoped type variables)

  * bind_fvs excludes imported vars; this is just to keep the set smaller

  * Before renaming, and after typechecking, the field is unused;
    it's just an error thunk
Austin Seipp's avatar
Austin Seipp committed
618
-}
619

620
instance (idL ~ GhcPass pl, idR ~ GhcPass pr,
Ben Gamari's avatar
Ben Gamari committed
621 622
          OutputableBndrId idL, OutputableBndrId idR)
        => Outputable (HsLocalBindsLR idL idR) where
623 624 625 626
  ppr (HsValBinds _ bs)   = ppr bs
  ppr (HsIPBinds _ bs)    = ppr bs
  ppr (EmptyLocalBinds _) = empty
  ppr (XHsLocalBindsLR x) = ppr x
627

628
instance (idL ~ GhcPass pl, idR ~ GhcPass pr,
Ben Gamari's avatar
Ben Gamari committed
629 630
          OutputableBndrId idL, OutputableBndrId idR)
        => Outputable (HsValBindsLR idL idR) where
631
  ppr (ValBinds _ binds sigs)
632
   = pprDeclList (pprLHsBindsForUser binds sigs)
633

634
  ppr (XValBindsLR (NValBinds sccs sigs))
635
    = getPprStyle $ \ sty ->
636 637
      if debugStyle sty then    -- Print with sccs showing
        vcat (map ppr sigs) $$ vcat (map ppr_scc sccs)
638
     else
639
        pprDeclList (pprLHsBindsForUser (unionManyBags (map snd sccs)) sigs)
640 641
   where
     ppr_scc (rec_flag, binds) = pp_rec rec_flag <+> pprLHsBinds binds
642 643
     pp_rec Recursive    = text "rec"
     pp_rec NonRecursive = text "nonrec"
644

645 646
pprLHsBinds :: (OutputableBndrId (GhcPass idL), OutputableBndrId (GhcPass idR))
            => LHsBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
647
pprLHsBinds binds
648
  | isEmptyLHsBinds binds = empty
649
  | otherwise = pprDeclList (map ppr (bagToList binds))
650

651 652 653 654
pprLHsBindsForUser :: (OutputableBndrId (GhcPass idL),
                       OutputableBndrId (GhcPass idR),
                       OutputableBndrId (GhcPass id2))
     => LHsBindsLR (GhcPass idL) (GhcPass idR) -> [LSig (GhcPass id2)] -> [SDoc]
655
--  pprLHsBindsForUser is different to pprLHsBinds because
656
--  a) No braces: 'let' and 'where' include a list of HsBindGroups
657
--     and we don't want several groups of bindings each
658 659 660 661
--     with braces around
--  b) Sort by location before printing
--  c) Include signatures
pprLHsBindsForUser binds sigs
662
  = map snd (sort_by_loc decls)
663 664 665 666
  where

    decls :: [(SrcSpan, SDoc)]
    decls = [(loc, ppr sig)  | L loc sig <- sigs] ++
667
            [(loc, ppr bind) | L loc bind <- bagToList binds]
668

669
    sort_by_loc decls = sortBy (comparing fst) decls
670

671 672 673 674 675
pprDeclList :: [SDoc] -> SDoc   -- Braces with a space
-- Print a bunch of declarations
-- One could choose  { d1; d2; ... }, using 'sep'
-- or      d1
--         d2
676
--         ..
677 678 679 680 681
--    using vcat
-- At the moment we chose the latter
-- Also we do the 'pprDeeperList' thing.
pprDeclList ds = pprDeeperList vcat ds

682
------------
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
emptyLocalBinds :: HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds = EmptyLocalBinds noExt

-- AZ:These functions do not seem to be used at all?
isEmptyLocalBindsTc :: HsLocalBindsLR (GhcPass a) GhcTc -> Bool
isEmptyLocalBindsTc (HsValBinds _ ds)   = isEmptyValBinds ds
isEmptyLocalBindsTc (HsIPBinds _ ds)    = isEmptyIPBindsTc ds
isEmptyLocalBindsTc (EmptyLocalBinds _) = True
isEmptyLocalBindsTc (XHsLocalBindsLR _) = True

isEmptyLocalBindsPR :: HsLocalBindsLR (GhcPass a) (GhcPass b) -> Bool
isEmptyLocalBindsPR (HsValBinds _ ds)   = isEmptyValBinds ds
isEmptyLocalBindsPR (HsIPBinds _ ds)    = isEmptyIPBindsPR ds
isEmptyLocalBindsPR (EmptyLocalBinds _) = True
isEmptyLocalBindsPR (XHsLocalBindsLR _) = True
698

699
eqEmptyLocalBinds :: HsLocalBindsLR a b -> Bool
700 701
eqEmptyLocalBinds (EmptyLocalBinds _) = True
eqEmptyLocalBinds _                   = False
702

703 704 705
isEmptyValBinds :: HsValBindsLR (GhcPass a) (GhcPass b) -> Bool
isEmptyValBinds (ValBinds _ ds sigs)  = isEmptyLHsBinds ds && null sigs
isEmptyValBinds (XValBindsLR (NValBinds ds sigs)) = null ds && null sigs
706

707 708 709
emptyValBindsIn, emptyValBindsOut :: HsValBindsLR (GhcPass a) (GhcPass b)
emptyValBindsIn  = ValBinds noExt emptyBag []
emptyValBindsOut = XValBindsLR (NValBinds [] [])
710

711
emptyLHsBinds :: LHsBindsLR idL idR
712 713
emptyLHsBinds = emptyBag

714
isEmptyLHsBinds :: LHsBindsLR idL idR -> Bool
715 716 717
isEmptyLHsBinds = isEmptyBag

------------
718 719 720 721 722 723 724
plusHsValBinds :: HsValBinds (GhcPass a) -> HsValBinds (GhcPass a)
               -> HsValBinds(GhcPass a)
plusHsValBinds (ValBinds _ ds1 sigs1) (ValBinds _ ds2 sigs2)
  = ValBinds noExt (ds1 `unionBags` ds2) (sigs1 ++ sigs2)
plusHsValBinds (XValBindsLR (NValBinds ds1 sigs1))
               (XValBindsLR (NValBinds ds2 sigs2))
  = XValBindsLR (NValBinds (ds1 ++ ds2) (sigs1 ++ sigs2))
725 726
plusHsValBinds _ _
  = panic "HsBinds.plusHsValBinds"
727

728
instance (idL ~ GhcPass pl, idR ~ GhcPass pr,
Ben Gamari's avatar
Ben Gamari committed
729 730
          OutputableBndrId idL, OutputableBndrId idR)
         => Outputable (HsBindLR idL idR) where
731
    ppr mbind = ppr_monobind mbind
sof's avatar
sof committed
732

733 734
ppr_monobind :: (OutputableBndrId (GhcPass idL), OutputableBndrId (GhcPass idR))
             => HsBindLR (GhcPass idL) (GhcPass idR) -> SDoc
735

736 737
ppr_monobind (PatBind { pat_lhs = pat, pat_rhs = grhss })
  = pprPatBind pat grhss
738
ppr_monobind (VarBind { var_id = var, var_rhs = rhs })
739
  = sep [pprBndr CasePatBind var, nest 2 $ equals <+> pprExpr (unLoc rhs)]
740
ppr_monobind (FunBind { fun_id = fun,
741 742
                        fun_co_fn = wrap,
                        fun_matches = matches,
743 744 745
                        fun_tick = ticks })
  = pprTicks empty (if null ticks then empty
                    else text "-- ticks = " <> ppr ticks)
Simon Peyton Jones's avatar
Simon Peyton Jones committed
746
    $$  whenPprDebug (pprBndr LetBind (unLoc fun))
747
    $$  pprFunBind  matches
Simon Peyton Jones's avatar
Simon Peyton Jones committed
748
    $$  whenPprDebug (ppr wrap)
749
ppr_monobind (PatSynBind _ psb) = ppr psb
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
750 751
ppr_monobind (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dictvars
                       , abs_exports = exports, abs_binds = val_binds
752
                       , abs_ev_binds = ev_binds })
753
  = sdocWithDynFlags $ \ dflags ->
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
754
    if gopt Opt_PrintTypecheckerElaboration dflags then
755
      -- Show extra information (bug number: #10662)
756
      hang (text "AbsBinds" <+> brackets (interpp'SP tyvars)
757 758
                                    <+> brackets (interpp'SP dictvars))
         2 $ braces $ vcat
759
      [ text "Exports:" <+>
760
          brackets (sep (punctuate comma (map ppr exports)))
761
      , text "Exported types:" <+>
762
          vcat [pprBndr LetBind (abe_poly ex) | ex <- exports]
763 764
      , text "Binds:" <+> pprLHsBinds val_binds
      , text "Evidence:" <+> ppr ev_binds ]
765 766
    else
      pprLHsBinds val_binds
767
ppr_monobind (XHsBindsLR x) = ppr x
768

769
instance (p ~ GhcPass pass, OutputableBndrId p) => Outputable (ABExport p) where
770
  ppr (ABE { abe_wrap = wrap, abe_poly = gbl, abe_mono = lcl, abe_prags = prags })
771
    = vcat [ ppr gbl <+> text "<=" <+> ppr lcl
772
           , nest 2 (pprTcSpecPrags prags)
773
           , nest 2 (text "wrap:" <+> ppr wrap)]
774
  ppr (XABExport x) = ppr x
775

776 777
instance (idR ~ GhcPass pr,OutputableBndrId idL, OutputableBndrId idR,
         Outputable (XXPatSynBind idL idR))
Ben Gamari's avatar
Ben Gamari committed
778
          => Outputable (PatSynBind idL idR) where
779 780
  ppr (PSB{ psb_id = (L _ psyn), psb_args = details, psb_def = pat,
            psb_dir = dir })
781 782
      = ppr_lhs <+> ppr_rhs
    where
783
      ppr_lhs = text "pattern" <+> ppr_details
784 785
      ppr_simple syntax = syntax <+> ppr pat

786
      ppr_details = case details of
787 788 789 790
          InfixCon v1 v2 -> hsep [ppr v1, pprInfixOcc psyn, ppr v2]
          PrefixCon vs   -> hsep (pprPrefixOcc psyn : map ppr vs)
          RecCon vs      -> pprPrefixOcc psyn
                            <> braces (sep (punctuate comma (map ppr vs)))
791 792

      ppr_rhs = case dir of
793
          Unidirectional           -> ppr_simple (text "<-")
794
          ImplicitBidirectional    -> ppr_simple equals
795
          ExplicitBidirectional mg -> ppr_simple (text "<-") <+> ptext (sLit "where") $$
796
                                      (nest 2 $ pprFunBind mg)
797
  ppr (XPatSynBind x) = ppr x
798

799 800 801
pprTicks :: SDoc -> SDoc -> SDoc
-- Print stuff about ticks only when -dppr-debug is on, to avoid
-- them appearing in error messages (from the desugarer); see Trac # 3263
802 803
-- Also print ticks in dumpStyle, so that -ddump-hpc actually does
-- something useful.
804
pprTicks pp_no_debug pp_when_debug
805 806 807
  = getPprStyle (\ sty -> if debugStyle sty || dumpStyle sty
                             then pp_when_debug
                             else pp_no_debug)
808

Austin Seipp's avatar
Austin Seipp committed
809 810 811
{-
************************************************************************
*                                                                      *
812
                Implicit parameter bindings
Austin Seipp's avatar
Austin Seipp committed
813 814 815
*                                                                      *
************************************************************************
-}
816

817
-- | Haskell Implicit Parameter Bindings
818
data HsIPBinds id
819
  = IPBinds
820
        (XIPBinds id)
821
        [LIPBind id]
822 823 824
        -- TcEvBinds       -- Only in typechecker output; binds
        --                 -- uses of the implicit parameters
  | XHsIPBinds (XXHsIPBinds id)
825

826 827
type instance XIPBinds       GhcPs = NoExt
type instance XIPBinds       GhcRn = NoExt
828 829 830 831
type instance XIPBinds       GhcTc = TcEvBinds -- binds uses of the
                                               -- implicit parameters


832
type instance XXHsIPBinds    (GhcPass p) = NoExt
833 834 835 836 837 838 839 840

isEmptyIPBindsPR :: HsIPBinds (GhcPass p) -> Bool
isEmptyIPBindsPR (IPBinds _ is) = null is
isEmptyIPBindsPR (XHsIPBinds _) = True

isEmptyIPBindsTc :: HsIPBinds GhcTc -> Bool
isEmptyIPBindsTc (IPBinds ds is) = null is && isEmptyTcEvBinds ds
isEmptyIPBindsTc (XHsIPBinds _) = True
841

842
-- | Located Implicit Parameter Binding
843
type LIPBind id = Located (IPBind id)
Alan Zimmerman's avatar
Alan Zimmerman committed
844 845
-- ^ May have 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnSemi' when in a
--   list
846

847 848
-- For details on above see note [Api annotations] in ApiAnnotation

849
-- | Implicit parameter bindings.
Alan Zimmerman's avatar
Alan Zimmerman committed
850
--
Alan Zimmerman's avatar
Alan Zimmerman committed
851 852 853 854 855
-- These bindings start off as (Left "x") in the parser and stay
-- that way until after type-checking when they are replaced with
-- (Right d), where "d" is the name of the dictionary holding the
-- evidence for the implicit parameter.
--
Alan Zimmerman's avatar
Alan Zimmerman committed
856
-- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnEqual'
857 858

-- For details on above see note [Api annotations] in ApiAnnotation
859
data IPBind id
860
  = IPBind
861
        (XCIPBind id)
862 863
        (Either (Located HsIPName) (IdP id))
        (LHsExpr id)
864
  | XIPBind (XXIPBind id)
865

866
type instance XCIPBind    (GhcPass p) = NoExt
867
type instance XXIPBind    (GhcPass p) = NoExt
868

869 870
instance (p ~ GhcPass pass, OutputableBndrId p)
       => Outputable (HsIPBinds p) where
871
  ppr (IPBinds ds bs) = pprDeeperList vcat (map ppr bs)
Simon Peyton Jones's avatar
Simon Peyton Jones committed
872
                        $$ whenPprDebug (ppr ds)
873
  ppr (XHsIPBinds x) = ppr x
874

875
instance (p ~ GhcPass pass, OutputableBndrId p) => Outputable (IPBind p) where
876
  ppr (IPBind _ lr rhs) = name <+> equals <+> pprExpr (unLoc rhs)
877
    where name = case lr of
Alan Zimmerman's avatar
Alan Zimmerman committed
878 879
                   Left (L _ ip) -> pprBndr LetBind ip
                   Right     id  -> pprBndr LetBind id
880
  ppr (XIPBind x) = ppr x
881

Austin Seipp's avatar
Austin Seipp committed
882 883 884
{-
************************************************************************
*                                                                      *
885
\subsection{@Sig@: type signatures and value-modifying user pragmas}
Austin Seipp's avatar
Austin Seipp committed
886 887
*                                                                      *
************************************************************************
888 889 890 891 892

It is convenient to lump ``value-modifying'' user-pragmas (e.g.,
``specialise this function to these four types...'') in with type
signatures.  Then all the machinery to move them into place, etc.,
serves for both.
Austin Seipp's avatar
Austin Seipp committed
893
-}
894

895
-- | Located Signature
896
type LSig pass = Located (Sig pass)
897

898
-- | Signatures and pragmas
899
data Sig pass
900
  =   -- | An ordinary type signature
901 902 903
      --
      -- > f :: Num a => a -> a
      --
thomasw's avatar
thomasw committed
904 905 906 907 908 909 910
      -- After renaming, this list of Names contains the named and unnamed
      -- wildcards brought into scope by this signature. For a signature
      -- @_ -> _a -> Bool@, the renamer will give the unnamed wildcard @_@
      -- a freshly generated name, e.g. @_w@. @_w@ and the named wildcard @_a@
      -- are then both replaced with fresh meta vars in the type. Their names
      -- are stored in the type signature that brought them into scope, in
      -- this third field to be more specific.
Alan Zimmerman's avatar
Alan Zimmerman committed
911 912 913
      --
      --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnDcolon',
      --          'ApiAnnotation.AnnComma'
914 915

      -- For details on above see note [Api annotations] in ApiAnnotation
Matthew Pickering's avatar
Matthew Pickering committed
916
    TypeSig
917
       (XTypeSig pass)
918 919
       [Located (IdP pass)]  -- LHS of the signature; e.g.  f,g,h :: blah
       (LHsSigWcType pass)   -- RHS of the signature; can have wildcards
920

cactus's avatar
cactus committed
921
      -- | A pattern synonym type signature
922 923 924 925 926 927
      --
      -- > pattern Single :: () => (Show a) => a -> [a]
      --
      --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnPattern',
      --           'ApiAnnotation.AnnDcolon','ApiAnnotation.AnnForall'
      --           'ApiAnnotation.AnnDot','ApiAnnotation.AnnDarrow'
928 929

      -- For details on above see note [Api annotations] in ApiAnnotation
930
  | PatSynSig (XPatSynSig pass) [Located (IdP pass)] (LHsSigType pass)
Rik Steenkamp's avatar
Rik Steenkamp committed
931
      -- P :: forall a b. Req => Prov => ty
932 933

      -- | A signature for a class method
Rik Steenkamp's avatar
Rik Steenkamp committed
934
      --   False: ordinary class-method signature
935
      --   True:  generic-default class method signature
936 937 938 939 940 941 942
      -- e.g.   class C a where
      --          op :: a -> a                   -- Ordinary
      --          default op :: Eq a => a -> a   -- Generic default
      -- No wildcards allowed here
      --
      --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnDefault',
      --           'ApiAnnotation.AnnDcolon'
943
  | ClassOpSig (XClassOpSig pass) Bool [Located (IdP pass)] (LHsSigType pass)
944

945
        -- | A type signature in generated code, notably the code
946 947 948 949
        -- generated for record selectors.  We simply record
        -- the desired Id itself, replete with its name, type
        -- and IdDetails.  Otherwise it's just like a type
        -- signature: there should be an accompanying binding
950
  | IdSig (XIdSig pass) Id
951

952 953
        -- | An ordinary fixity declaration
        --
Alan Zimmerman's avatar
Alan Zimmerman committed
954
        -- >     infixl 8 ***
955
        --
956 957 958
        --
        --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnInfix',
        --           'ApiAnnotation.AnnVal'
959 960

        -- For details on above see note [Api annotations] in ApiAnnotation
961
  | FixSig (XFixSig pass) (FixitySig pass)
962

963 964 965 966
        -- | An inline pragma
        --
        -- > {#- INLINE f #-}
        --
Alan Zimmerman's avatar
Alan Zimmerman committed
967 968
        --  - 'ApiAnnotation.AnnKeywordId' :
        --       'ApiAnnotation.AnnOpen' @'{-\# INLINE'@ and @'['@,
Alan Zimmerman's avatar
Alan Zimmerman committed
969 970 971
        --       'ApiAnnotation.AnnClose','ApiAnnotation.AnnOpen',
        --       'ApiAnnotation.AnnVal','ApiAnnotation.AnnTilde',
        --       'ApiAnnotation.AnnClose'
972 973

        -- For details on above see note [Api annotations] in ApiAnnotation
974 975
  | InlineSig   (XInlineSig pass)
                (Located (IdP pass)) -- Function name
976
                InlinePragma         -- Never defaultInlinePragma
977

978 979 980 981
        -- | A specialisation pragma
        --
        -- > {-# SPECIALISE f :: Int -> Int #-}
        --
Alan Zimmerman's avatar
Alan Zimmerman committed
982
        --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen',
Alan Zimmerman's avatar
Alan Zimmerman committed
983 984 985 986 987
        --      'ApiAnnotation.AnnOpen' @'{-\# SPECIALISE'@ and @'['@,
        --      'ApiAnnotation.AnnTilde',
        --      'ApiAnnotation.AnnVal',
        --      'ApiAnnotation.AnnClose' @']'@ and @'\#-}'@,
        --      'ApiAnnotation.AnnDcolon'
988 989

        -- For details on above see note [Api annotations] in ApiAnnotation
990 991
  | SpecSig     (XSpecSig pass)
                (Located (IdP pass)) -- Specialise a function or datatype  ...
992
                [LHsSigType pass]  -- ... to these types
993 994 995
                InlinePragma       -- The pragma on SPECIALISE_INLINE form.
                                   -- If it's just defaultInlinePragma, then we said
                                   --    SPECIALISE, not SPECIALISE_INLINE
996

997 998 999 1000 1001 1002
        -- | A specialisation pragma for instance declarations only
        --
        -- > {-# SPECIALISE instance Eq [Int] #-}
        --
        -- (Class tys); should be a specialisation of the
        -- current instance declaration
Alan Zimmerman's avatar
Alan Zimmerman committed
1003 1004 1005
        --
        --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen',
        --      'ApiAnnotation.AnnInstance','ApiAnnotation.AnnClose'
1006 1007

        -- For details on above see note [Api annotations] in ApiAnnotation
1008
  | SpecInstSig (XSpecInstSig pass) SourceText (LHsSigType pass)
Alan Zimmerman's avatar
Alan Zimmerman committed
1009
                  -- Note [Pragma source text] in BasicTypes
1010 1011 1012 1013

        -- | A minimal complete definition pragma
        --
        -- > {-# MINIMAL a | (b, c | (d | e)) #-}
Alan Zimmerman's avatar
Alan Zimmerman committed
1014 1015 1016 1017
        --
        --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen',
        --      'ApiAnnotation.AnnVbar','ApiAnnotation.AnnComma',
        --      'ApiAnnotation.AnnClose'
1018 1019

        -- For details on above see note [Api annotations] in ApiAnnotation
1020 1021
  | MinimalSig (XMinimalSig pass)
               SourceText (LBooleanFormula (Located (IdP pass)))
Alan Zimmerman's avatar
Alan Zimmerman committed
1022
               -- Note [Pragma source text] in BasicTypes
1023

1024 1025 1026 1027 1028 1029 1030 1031
        -- | A "set cost centre" pragma for declarations
        --
        -- > {-# SCC funName #-}
        --
        -- or
        --
        -- > {-# SCC funName "cost_centre_name" #-}

1032 1033
  | SCCFunSig  (XSCCFunSig pass)
               SourceText      -- Note [Pragma source text] in BasicTypes
1034
               (Located (IdP pass))  -- Function name
1035
               (Maybe (Located StringLiteral))
1036 1037 1038 1039 1040 1041 1042
       -- | A complete match pragma
       --
       -- > {-# COMPLETE C, D [:: T] #-}
       --
       -- Used to inform the pattern match checker about additional
       -- complete matchings which, for example, arise from pattern