eb56d3b24e87e261bf9d70e061b563d2a389b768
[ghc.git] / compiler / hsSyn / HsExtension.hs
1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE FlexibleContexts #-}
4 {-# LANGUAGE FlexibleInstances #-}
5 {-# LANGUAGE FunctionalDependencies #-}
6 {-# LANGUAGE MultiParamTypeClasses #-}
7 {-# LANGUAGE TypeFamilies #-}
8 {-# LANGUAGE DataKinds #-}
9 {-# LANGUAGE StandaloneDeriving #-}
10 {-# LANGUAGE PatternSynonyms #-}
11 {-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types]
12 -- in module PlaceHolder
13
14 module HsExtension where
15
16 -- This module captures the type families to precisely identify the extension
17 -- points for HsSyn
18
19 import GhcPrelude
20
21 import GHC.Exts (Constraint)
22 import Data.Data hiding ( Fixity )
23 import PlaceHolder
24 import Name
25 import RdrName
26 import Var
27 import Outputable
28 import SrcLoc (Located)
29
30 {-
31 Note [Trees that grow]
32 ~~~~~~~~~~~~~~~~~~~~~~
33
34 See https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow
35
36 The hsSyn AST is reused across multiple compiler passes. We also have the
37 Template Haskell AST, and the haskell-src-exts one (outside of GHC)
38
39 Supporting multiple passes means the AST has various warts on it to cope with
40 the specifics for the phases, such as the 'ValBindsOut', 'ConPatOut',
41 'SigPatOut' etc.
42
43 The growable AST will allow each of these variants to be captured explicitly,
44 such that they only exist in the given compiler pass AST, as selected by the
45 type parameter to the AST.
46
47 In addition it will allow tool writers to define their own extensions to capture
48 additional information for the tool, in a natural way.
49
50 A further goal is to provide a means to harmonise the Template Haskell and
51 haskell-src-exts ASTs as well.
52
53 -}
54
55 -- | used as place holder in TTG values
56 data NoExt = NoExt
57 deriving (Data,Eq,Ord)
58
59 instance Outputable NoExt where
60 ppr _ = text "NoExt"
61
62 -- | Used when constructing a term with an unused extension point.
63 noExt :: NoExt
64 noExt = NoExt
65
66 -- | Used as a data type index for the hsSyn AST
67 data GhcPass (c :: Pass)
68 deriving instance Eq (GhcPass c)
69 deriving instance Typeable c => Data (GhcPass c)
70
71 data Pass = Parsed | Renamed | Typechecked
72 deriving (Data)
73
74 -- Type synonyms as a shorthand for tagging
75 type GhcPs = GhcPass 'Parsed -- Old 'RdrName' type param
76 type GhcRn = GhcPass 'Renamed -- Old 'Name' type param
77 type GhcTc = GhcPass 'Typechecked -- Old 'Id' type para,
78 type GhcTcId = GhcTc -- Old 'TcId' type param
79
80 -- | Maps the "normal" id type for a given pass
81 type family IdP p
82 type instance IdP GhcPs = RdrName
83 type instance IdP GhcRn = Name
84 type instance IdP GhcTc = Id
85
86 type LIdP p = Located (IdP p)
87
88 -- =====================================================================
89 -- Type families for the HsBinds extension points
90
91 -- HsLocalBindsLR type families
92 type family XHsValBinds x x'
93 type family XHsIPBinds x x'
94 type family XEmptyLocalBinds x x'
95 type family XXHsLocalBindsLR x x'
96
97 type ForallXHsLocalBindsLR (c :: * -> Constraint) (x :: *) (x' :: *) =
98 ( c (XHsValBinds x x')
99 , c (XHsIPBinds x x')
100 , c (XEmptyLocalBinds x x')
101 , c (XXHsLocalBindsLR x x')
102 )
103
104 -- ValBindsLR type families
105 type family XValBinds x x'
106 type family XXValBindsLR x x'
107
108 type ForallXValBindsLR (c :: * -> Constraint) (x :: *) (x' :: *) =
109 ( c (XValBinds x x')
110 , c (XXValBindsLR x x')
111 )
112
113
114 -- HsBindsLR type families
115 type family XFunBind x x'
116 type family XPatBind x x'
117 type family XVarBind x x'
118 type family XAbsBinds x x'
119 type family XPatSynBind x x'
120 type family XXHsBindsLR x x'
121
122 type ForallXHsBindsLR (c :: * -> Constraint) (x :: *) (x' :: *) =
123 ( c (XFunBind x x')
124 , c (XPatBind x x')
125 , c (XVarBind x x')
126 , c (XAbsBinds x x')
127 , c (XPatSynBind x x')
128 , c (XXHsBindsLR x x')
129 )
130
131 -- ABExport type families
132 type family XABE x
133 type family XXABExport x
134
135 type ForallXABExport (c :: * -> Constraint) (x :: *) =
136 ( c (XABE x)
137 , c (XXABExport x)
138 )
139
140 -- PatSynBind type families
141 type family XPSB x x'
142 type family XXPatSynBind x x'
143
144 type ForallXPatSynBind (c :: * -> Constraint) (x :: *) (x' :: *) =
145 ( c (XPSB x x')
146 , c (XXPatSynBind x x')
147 )
148
149 -- HsIPBinds type families
150 type family XIPBinds x
151 type family XXHsIPBinds x
152
153 type ForallXHsIPBinds (c :: * -> Constraint) (x :: *) =
154 ( c (XIPBinds x)
155 , c (XXHsIPBinds x)
156 )
157
158 -- IPBind type families
159 type family XIPBind x
160 type family XXIPBind x
161
162 type ForallXIPBind (c :: * -> Constraint) (x :: *) =
163 ( c (XIPBind x)
164 , c (XXIPBind x)
165 )
166
167 -- Sig type families
168 type family XTypeSig x
169 type family XPatSynSig x
170 type family XClassOpSig x
171 type family XIdSig x
172 type family XFixSig x
173 type family XInlineSig x
174 type family XSpecSig x
175 type family XSpecInstSig x
176 type family XMinimalSig x
177 type family XSCCFunSig x
178 type family XCompleteMatchSig x
179 type family XXSig x
180
181 type ForallXSig (c :: * -> Constraint) (x :: *) =
182 ( c (XTypeSig x)
183 , c (XPatSynSig x)
184 , c (XClassOpSig x)
185 , c (XIdSig x)
186 , c (XFixSig x)
187 , c (XInlineSig x)
188 , c (XSpecSig x)
189 , c (XSpecInstSig x)
190 , c (XMinimalSig x)
191 , c (XSCCFunSig x)
192 , c (XCompleteMatchSig x)
193 , c (XXSig x)
194 )
195
196 -- FixitySig type families
197 type family XFixitySig x
198 type family XXFixitySig x
199
200 type ForallXFixitySig (c :: * -> Constraint) (x :: *) =
201 ( c (XFixitySig x)
202 , c (XXFixitySig x)
203 )
204
205 -- =====================================================================
206 -- Type families for the HsDecls extension points
207
208 -- HsDecl type families
209 type family XTyClD x
210 type family XInstD x
211 type family XDerivD x
212 type family XValD x
213 type family XSigD x
214 type family XDefD x
215 type family XForD x
216 type family XWarningD x
217 type family XAnnD x
218 type family XRuleD x
219 type family XSpliceD x
220 type family XDocD x
221 type family XRoleAnnotD x
222 type family XXHsDecl x
223
224 type ForallXHsDecl (c :: * -> Constraint) (x :: *) =
225 ( c (XTyClD x)
226 , c (XInstD x)
227 , c (XDerivD x)
228 , c (XValD x)
229 , c (XSigD x)
230 , c (XDefD x)
231 , c (XForD x)
232 , c (XWarningD x)
233 , c (XAnnD x)
234 , c (XRuleD x)
235 , c (XSpliceD x)
236 , c (XDocD x)
237 , c (XRoleAnnotD x)
238 , c (XXHsDecl x)
239 )
240
241 -- -------------------------------------
242 -- HsGroup type families
243 type family XCHsGroup x
244 type family XXHsGroup x
245
246 type ForallXHsGroup (c :: * -> Constraint) (x :: *) =
247 ( c (XCHsGroup x)
248 , c (XXHsGroup x)
249 )
250
251 -- -------------------------------------
252 -- SpliceDecl type families
253 type family XSpliceDecl x
254 type family XXSpliceDecl x
255
256 type ForallXSpliceDecl (c :: * -> Constraint) (x :: *) =
257 ( c (XSpliceDecl x)
258 , c (XXSpliceDecl x)
259 )
260
261 -- -------------------------------------
262 -- TyClDecl type families
263 type family XFamDecl x
264 type family XSynDecl x
265 type family XDataDecl x
266 type family XClassDecl x
267 type family XXTyClDecl x
268
269 type ForallXTyClDecl (c :: * -> Constraint) (x :: *) =
270 ( c (XFamDecl x)
271 , c (XSynDecl x)
272 , c (XDataDecl x)
273 , c (XClassDecl x)
274 , c (XXTyClDecl x)
275 )
276
277 -- -------------------------------------
278 -- TyClGroup type families
279 type family XCTyClGroup x
280 type family XXTyClGroup x
281
282 type ForallXTyClGroup (c :: * -> Constraint) (x :: *) =
283 ( c (XCTyClGroup x)
284 , c (XXTyClGroup x)
285 )
286
287 -- -------------------------------------
288 -- FamilyResultSig type families
289 type family XNoSig x
290 type family XCKindSig x -- Clashes with XKindSig above
291 type family XTyVarSig x
292 type family XXFamilyResultSig x
293
294 type ForallXFamilyResultSig (c :: * -> Constraint) (x :: *) =
295 ( c (XNoSig x)
296 , c (XCKindSig x)
297 , c (XTyVarSig x)
298 , c (XXFamilyResultSig x)
299 )
300
301 -- -------------------------------------
302 -- FamilyDecl type families
303 type family XCFamilyDecl x
304 type family XXFamilyDecl x
305
306 type ForallXFamilyDecl (c :: * -> Constraint) (x :: *) =
307 ( c (XCFamilyDecl x)
308 , c (XXFamilyDecl x)
309 )
310
311 -- -------------------------------------
312 -- HsDataDefn type families
313 type family XCHsDataDefn x
314 type family XXHsDataDefn x
315
316 type ForallXHsDataDefn (c :: * -> Constraint) (x :: *) =
317 ( c (XCHsDataDefn x)
318 , c (XXHsDataDefn x)
319 )
320
321 -- -------------------------------------
322 -- HsDerivingClause type families
323 type family XCHsDerivingClause x
324 type family XXHsDerivingClause x
325
326 type ForallXHsDerivingClause (c :: * -> Constraint) (x :: *) =
327 ( c (XCHsDerivingClause x)
328 , c (XXHsDerivingClause x)
329 )
330
331 -- -------------------------------------
332 -- ConDecl type families
333 type family XConDeclGADT x
334 type family XConDeclH98 x
335 type family XXConDecl x
336
337 type ForallXConDecl (c :: * -> Constraint) (x :: *) =
338 ( c (XConDeclGADT x)
339 , c (XConDeclH98 x)
340 , c (XXConDecl x)
341 )
342
343 -- -------------------------------------
344 -- FamEqn type families
345 type family XCFamEqn x p r
346 type family XXFamEqn x p r
347
348 type ForallXFamEqn (c :: * -> Constraint) (x :: *) (p :: *) (r :: *) =
349 ( c (XCFamEqn x p r)
350 , c (XXFamEqn x p r)
351 )
352
353 -- -------------------------------------
354 -- ClsInstDecl type families
355 type family XCClsInstDecl x
356 type family XXClsInstDecl x
357
358 type ForallXClsInstDecl (c :: * -> Constraint) (x :: *) =
359 ( c (XCClsInstDecl x)
360 , c (XXClsInstDecl x)
361 )
362
363 -- -------------------------------------
364 -- ClsInstDecl type families
365 type family XClsInstD x
366 type family XDataFamInstD x
367 type family XTyFamInstD x
368 type family XXInstDecl x
369
370 type ForallXInstDecl (c :: * -> Constraint) (x :: *) =
371 ( c (XClsInstD x)
372 , c (XDataFamInstD x)
373 , c (XTyFamInstD x)
374 , c (XXInstDecl x)
375 )
376
377 -- -------------------------------------
378 -- DerivDecl type families
379 type family XCDerivDecl x
380 type family XXDerivDecl x
381
382 type ForallXDerivDecl (c :: * -> Constraint) (x :: *) =
383 ( c (XCDerivDecl x)
384 , c (XXDerivDecl x)
385 )
386
387 -- -------------------------------------
388 -- DerivStrategy type family
389 type family XViaStrategy x
390
391 -- -------------------------------------
392 -- DefaultDecl type families
393 type family XCDefaultDecl x
394 type family XXDefaultDecl x
395
396 type ForallXDefaultDecl (c :: * -> Constraint) (x :: *) =
397 ( c (XCDefaultDecl x)
398 , c (XXDefaultDecl x)
399 )
400
401 -- -------------------------------------
402 -- DefaultDecl type families
403 type family XForeignImport x
404 type family XForeignExport x
405 type family XXForeignDecl x
406
407 type ForallXForeignDecl (c :: * -> Constraint) (x :: *) =
408 ( c (XForeignImport x)
409 , c (XForeignExport x)
410 , c (XXForeignDecl x)
411 )
412
413 -- -------------------------------------
414 -- RuleDecls type families
415 type family XCRuleDecls x
416 type family XXRuleDecls x
417
418 type ForallXRuleDecls (c :: * -> Constraint) (x :: *) =
419 ( c (XCRuleDecls x)
420 , c (XXRuleDecls x)
421 )
422
423
424 -- -------------------------------------
425 -- RuleDecl type families
426 type family XHsRule x
427 type family XXRuleDecl x
428
429 type ForallXRuleDecl (c :: * -> Constraint) (x :: *) =
430 ( c (XHsRule x)
431 , c (XXRuleDecl x)
432 )
433
434 -- -------------------------------------
435 -- RuleBndr type families
436 type family XCRuleBndr x
437 type family XRuleBndrSig x
438 type family XXRuleBndr x
439
440 type ForallXRuleBndr (c :: * -> Constraint) (x :: *) =
441 ( c (XCRuleBndr x)
442 , c (XRuleBndrSig x)
443 , c (XXRuleBndr x)
444 )
445
446 -- -------------------------------------
447 -- WarnDecls type families
448 type family XWarnings x
449 type family XXWarnDecls x
450
451 type ForallXWarnDecls (c :: * -> Constraint) (x :: *) =
452 ( c (XWarnings x)
453 , c (XXWarnDecls x)
454 )
455
456 -- -------------------------------------
457 -- AnnDecl type families
458 type family XWarning x
459 type family XXWarnDecl x
460
461 type ForallXWarnDecl (c :: * -> Constraint) (x :: *) =
462 ( c (XWarning x)
463 , c (XXWarnDecl x)
464 )
465
466 -- -------------------------------------
467 -- AnnDecl type families
468 type family XHsAnnotation x
469 type family XXAnnDecl x
470
471 type ForallXAnnDecl (c :: * -> Constraint) (x :: *) =
472 ( c (XHsAnnotation x)
473 , c (XXAnnDecl x)
474 )
475
476 -- -------------------------------------
477 -- RoleAnnotDecl type families
478 type family XCRoleAnnotDecl x
479 type family XXRoleAnnotDecl x
480
481 type ForallXRoleAnnotDecl (c :: * -> Constraint) (x :: *) =
482 ( c (XCRoleAnnotDecl x)
483 , c (XXRoleAnnotDecl x)
484 )
485
486 -- =====================================================================
487 -- Type families for the HsExpr extension points
488
489 type family XVar x
490 type family XUnboundVar x
491 type family XConLikeOut x
492 type family XRecFld x
493 type family XOverLabel x
494 type family XIPVar x
495 type family XOverLitE x
496 type family XLitE x
497 type family XLam x
498 type family XLamCase x
499 type family XApp x
500 type family XAppTypeE x
501 type family XOpApp x
502 type family XNegApp x
503 type family XPar x
504 type family XSectionL x
505 type family XSectionR x
506 type family XExplicitTuple x
507 type family XExplicitSum x
508 type family XCase x
509 type family XIf x
510 type family XMultiIf x
511 type family XLet x
512 type family XDo x
513 type family XExplicitList x
514 type family XRecordCon x
515 type family XRecordUpd x
516 type family XExprWithTySig x
517 type family XArithSeq x
518 type family XSCC x
519 type family XCoreAnn x
520 type family XBracket x
521 type family XRnBracketOut x
522 type family XTcBracketOut x
523 type family XSpliceE x
524 type family XProc x
525 type family XStatic x
526 type family XArrApp x
527 type family XArrForm x
528 type family XTick x
529 type family XBinTick x
530 type family XTickPragma x
531 type family XEWildPat x
532 type family XEAsPat x
533 type family XEViewPat x
534 type family XELazyPat x
535 type family XWrap x
536 type family XXExpr x
537
538 type ForallXExpr (c :: * -> Constraint) (x :: *) =
539 ( c (XVar x)
540 , c (XUnboundVar x)
541 , c (XConLikeOut x)
542 , c (XRecFld x)
543 , c (XOverLabel x)
544 , c (XIPVar x)
545 , c (XOverLitE x)
546 , c (XLitE x)
547 , c (XLam x)
548 , c (XLamCase x)
549 , c (XApp x)
550 , c (XAppTypeE x)
551 , c (XOpApp x)
552 , c (XNegApp x)
553 , c (XPar x)
554 , c (XSectionL x)
555 , c (XSectionR x)
556 , c (XExplicitTuple x)
557 , c (XExplicitSum x)
558 , c (XCase x)
559 , c (XIf x)
560 , c (XMultiIf x)
561 , c (XLet x)
562 , c (XDo x)
563 , c (XExplicitList x)
564 , c (XRecordCon x)
565 , c (XRecordUpd x)
566 , c (XExprWithTySig x)
567 , c (XArithSeq x)
568 , c (XSCC x)
569 , c (XCoreAnn x)
570 , c (XBracket x)
571 , c (XRnBracketOut x)
572 , c (XTcBracketOut x)
573 , c (XSpliceE x)
574 , c (XProc x)
575 , c (XStatic x)
576 , c (XArrApp x)
577 , c (XArrForm x)
578 , c (XTick x)
579 , c (XBinTick x)
580 , c (XTickPragma x)
581 , c (XEWildPat x)
582 , c (XEAsPat x)
583 , c (XEViewPat x)
584 , c (XELazyPat x)
585 , c (XWrap x)
586 , c (XXExpr x)
587 )
588 -- ---------------------------------------------------------------------
589
590 type family XUnambiguous x
591 type family XAmbiguous x
592 type family XXAmbiguousFieldOcc x
593
594 type ForallXAmbiguousFieldOcc (c :: * -> Constraint) (x :: *) =
595 ( c (XUnambiguous x)
596 , c (XAmbiguous x)
597 , c (XXAmbiguousFieldOcc x)
598 )
599
600 -- ----------------------------------------------------------------------
601
602 type family XPresent x
603 type family XMissing x
604 type family XXTupArg x
605
606 type ForallXTupArg (c :: * -> Constraint) (x :: *) =
607 ( c (XPresent x)
608 , c (XMissing x)
609 , c (XXTupArg x)
610 )
611
612 -- ---------------------------------------------------------------------
613
614 type family XTypedSplice x
615 type family XUntypedSplice x
616 type family XQuasiQuote x
617 type family XSpliced x
618 type family XXSplice x
619
620 type ForallXSplice (c :: * -> Constraint) (x :: *) =
621 ( c (XTypedSplice x)
622 , c (XUntypedSplice x)
623 , c (XQuasiQuote x)
624 , c (XSpliced x)
625 , c (XXSplice x)
626 )
627
628 -- ---------------------------------------------------------------------
629
630 type family XExpBr x
631 type family XPatBr x
632 type family XDecBrL x
633 type family XDecBrG x
634 type family XTypBr x
635 type family XVarBr x
636 type family XTExpBr x
637 type family XXBracket x
638
639 type ForallXBracket (c :: * -> Constraint) (x :: *) =
640 ( c (XExpBr x)
641 , c (XPatBr x)
642 , c (XDecBrL x)
643 , c (XDecBrG x)
644 , c (XTypBr x)
645 , c (XVarBr x)
646 , c (XTExpBr x)
647 , c (XXBracket x)
648 )
649
650 -- ---------------------------------------------------------------------
651
652 type family XCmdTop x
653 type family XXCmdTop x
654
655 type ForallXCmdTop (c :: * -> Constraint) (x :: *) =
656 ( c (XCmdTop x)
657 , c (XXCmdTop x)
658 )
659
660 -- -------------------------------------
661
662 type family XMG x b
663 type family XXMatchGroup x b
664
665 type ForallXMatchGroup (c :: * -> Constraint) (x :: *) (b :: *) =
666 ( c (XMG x b)
667 , c (XXMatchGroup x b)
668 )
669
670 -- -------------------------------------
671
672 type family XCMatch x b
673 type family XXMatch x b
674
675 type ForallXMatch (c :: * -> Constraint) (x :: *) (b :: *) =
676 ( c (XCMatch x b)
677 , c (XXMatch x b)
678 )
679
680 -- -------------------------------------
681
682 type family XCGRHSs x b
683 type family XXGRHSs x b
684
685 type ForallXGRHSs (c :: * -> Constraint) (x :: *) (b :: *) =
686 ( c (XCGRHSs x b)
687 , c (XXGRHSs x b)
688 )
689
690 -- -------------------------------------
691
692 type family XCGRHS x b
693 type family XXGRHS x b
694
695 type ForallXGRHS (c :: * -> Constraint) (x :: *) (b :: *) =
696 ( c (XCGRHS x b)
697 , c (XXGRHS x b)
698 )
699
700 -- -------------------------------------
701
702 type family XLastStmt x x' b
703 type family XBindStmt x x' b
704 type family XApplicativeStmt x x' b
705 type family XBodyStmt x x' b
706 type family XLetStmt x x' b
707 type family XParStmt x x' b
708 type family XTransStmt x x' b
709 type family XRecStmt x x' b
710 type family XXStmtLR x x' b
711
712 type ForallXStmtLR (c :: * -> Constraint) (x :: *) (x' :: *) (b :: *) =
713 ( c (XLastStmt x x' b)
714 , c (XBindStmt x x' b)
715 , c (XApplicativeStmt x x' b)
716 , c (XBodyStmt x x' b)
717 , c (XLetStmt x x' b)
718 , c (XParStmt x x' b)
719 , c (XTransStmt x x' b)
720 , c (XRecStmt x x' b)
721 , c (XXStmtLR x x' b)
722 )
723
724 -- ---------------------------------------------------------------------
725
726 type family XCmdArrApp x
727 type family XCmdArrForm x
728 type family XCmdApp x
729 type family XCmdLam x
730 type family XCmdPar x
731 type family XCmdCase x
732 type family XCmdIf x
733 type family XCmdLet x
734 type family XCmdDo x
735 type family XCmdWrap x
736 type family XXCmd x
737
738 type ForallXCmd (c :: * -> Constraint) (x :: *) =
739 ( c (XCmdArrApp x)
740 , c (XCmdArrForm x)
741 , c (XCmdApp x)
742 , c (XCmdLam x)
743 , c (XCmdPar x)
744 , c (XCmdCase x)
745 , c (XCmdIf x)
746 , c (XCmdLet x)
747 , c (XCmdDo x)
748 , c (XCmdWrap x)
749 , c (XXCmd x)
750 )
751
752 -- ---------------------------------------------------------------------
753
754 type family XParStmtBlock x x'
755 type family XXParStmtBlock x x'
756
757 type ForallXParStmtBlock (c :: * -> Constraint) (x :: *) (x' :: *) =
758 ( c (XParStmtBlock x x')
759 , c (XXParStmtBlock x x')
760 )
761
762 -- ---------------------------------------------------------------------
763
764 type family XApplicativeArgOne x
765 type family XApplicativeArgMany x
766 type family XXApplicativeArg x
767
768 type ForallXApplicativeArg (c :: * -> Constraint) (x :: *) =
769 ( c (XApplicativeArgOne x)
770 , c (XApplicativeArgMany x)
771 , c (XXApplicativeArg x)
772 )
773
774 -- =====================================================================
775 -- Type families for the HsImpExp extension points
776
777 -- TODO
778
779 -- =====================================================================
780 -- Type families for the HsLit extension points
781
782 -- We define a type family for each extension point. This is based on prepending
783 -- 'X' to the constructor name, for ease of reference.
784 type family XHsChar x
785 type family XHsCharPrim x
786 type family XHsString x
787 type family XHsStringPrim x
788 type family XHsInt x
789 type family XHsIntPrim x
790 type family XHsWordPrim x
791 type family XHsInt64Prim x
792 type family XHsWord64Prim x
793 type family XHsInteger x
794 type family XHsRat x
795 type family XHsFloatPrim x
796 type family XHsDoublePrim x
797 type family XXLit x
798
799 -- | Helper to apply a constraint to all extension points. It has one
800 -- entry per extension point type family.
801 type ForallXHsLit (c :: * -> Constraint) (x :: *) =
802 ( c (XHsChar x)
803 , c (XHsCharPrim x)
804 , c (XHsDoublePrim x)
805 , c (XHsFloatPrim x)
806 , c (XHsInt x)
807 , c (XHsInt64Prim x)
808 , c (XHsIntPrim x)
809 , c (XHsInteger x)
810 , c (XHsRat x)
811 , c (XHsString x)
812 , c (XHsStringPrim x)
813 , c (XHsWord64Prim x)
814 , c (XHsWordPrim x)
815 , c (XXLit x)
816 )
817
818 type family XOverLit x
819 type family XXOverLit x
820
821 type ForallXOverLit (c :: * -> Constraint) (x :: *) =
822 ( c (XOverLit x)
823 , c (XXOverLit x)
824 )
825
826 -- =====================================================================
827 -- Type families for the HsPat extension points
828
829 type family XWildPat x
830 type family XVarPat x
831 type family XLazyPat x
832 type family XAsPat x
833 type family XParPat x
834 type family XBangPat x
835 type family XListPat x
836 type family XTuplePat x
837 type family XSumPat x
838 type family XConPat x
839 type family XViewPat x
840 type family XSplicePat x
841 type family XLitPat x
842 type family XNPat x
843 type family XNPlusKPat x
844 type family XSigPat x
845 type family XCoPat x
846 type family XXPat x
847
848
849 type ForallXPat (c :: * -> Constraint) (x :: *) =
850 ( c (XWildPat x)
851 , c (XVarPat x)
852 , c (XLazyPat x)
853 , c (XAsPat x)
854 , c (XParPat x)
855 , c (XBangPat x)
856 , c (XListPat x)
857 , c (XTuplePat x)
858 , c (XSumPat x)
859 , c (XViewPat x)
860 , c (XSplicePat x)
861 , c (XLitPat x)
862 , c (XNPat x)
863 , c (XNPlusKPat x)
864 , c (XSigPat x)
865 , c (XCoPat x)
866 , c (XXPat x)
867 )
868
869 -- =====================================================================
870 -- Type families for the HsTypes type families
871
872 type family XHsQTvs x
873 type family XXLHsQTyVars x
874
875 type ForallXLHsQTyVars (c :: * -> Constraint) (x :: *) =
876 ( c (XHsQTvs x)
877 , c (XXLHsQTyVars x)
878 )
879
880 -- -------------------------------------
881
882 type family XHsIB x b
883 type family XXHsImplicitBndrs x b
884
885 type ForallXHsImplicitBndrs (c :: * -> Constraint) (x :: *) (b :: *) =
886 ( c (XHsIB x b)
887 , c (XXHsImplicitBndrs x b)
888 )
889
890 -- -------------------------------------
891
892 type family XHsWC x b
893 type family XXHsWildCardBndrs x b
894
895 type ForallXHsWildCardBndrs(c :: * -> Constraint) (x :: *) (b :: *) =
896 ( c (XHsWC x b)
897 , c (XXHsWildCardBndrs x b)
898 )
899
900 -- -------------------------------------
901
902 type family XForAllTy x
903 type family XQualTy x
904 type family XTyVar x
905 type family XAppsTy x
906 type family XAppTy x
907 type family XFunTy x
908 type family XListTy x
909 type family XTupleTy x
910 type family XSumTy x
911 type family XOpTy x
912 type family XParTy x
913 type family XIParamTy x
914 type family XEqTy x
915 type family XKindSig x
916 type family XSpliceTy x
917 type family XDocTy x
918 type family XBangTy x
919 type family XRecTy x
920 type family XExplicitListTy x
921 type family XExplicitTupleTy x
922 type family XTyLit x
923 type family XWildCardTy x
924 type family XXType x
925
926 -- | Helper to apply a constraint to all extension points. It has one
927 -- entry per extension point type family.
928 type ForallXType (c :: * -> Constraint) (x :: *) =
929 ( c (XForAllTy x)
930 , c (XQualTy x)
931 , c (XTyVar x)
932 , c (XAppsTy x)
933 , c (XAppTy x)
934 , c (XFunTy x)
935 , c (XListTy x)
936 , c (XTupleTy x)
937 , c (XSumTy x)
938 , c (XOpTy x)
939 , c (XParTy x)
940 , c (XIParamTy x)
941 , c (XEqTy x)
942 , c (XKindSig x)
943 , c (XSpliceTy x)
944 , c (XDocTy x)
945 , c (XBangTy x)
946 , c (XRecTy x)
947 , c (XExplicitListTy x)
948 , c (XExplicitTupleTy x)
949 , c (XTyLit x)
950 , c (XWildCardTy x)
951 , c (XXType x)
952 )
953
954 -- ---------------------------------------------------------------------
955
956 type family XUserTyVar x
957 type family XKindedTyVar x
958 type family XXTyVarBndr x
959
960 type ForallXTyVarBndr (c :: * -> Constraint) (x :: *) =
961 ( c (XUserTyVar x)
962 , c (XKindedTyVar x)
963 , c (XXTyVarBndr x)
964 )
965
966 -- ---------------------------------------------------------------------
967
968 type family XAppInfix x
969 type family XAppPrefix x
970 type family XXAppType x
971
972 type ForallXAppType (c :: * -> Constraint) (x :: *) =
973 ( c (XAppInfix x)
974 , c (XAppPrefix x)
975 , c (XXAppType x)
976 )
977
978 -- ---------------------------------------------------------------------
979
980 type family XConDeclField x
981 type family XXConDeclField x
982
983 type ForallXConDeclField (c :: * -> Constraint) (x :: *) =
984 ( c (XConDeclField x)
985 , c (XXConDeclField x)
986 )
987
988 -- ---------------------------------------------------------------------
989
990 type family XFieldOcc x
991 type family XXFieldOcc x
992
993 type ForallXFieldOcc (c :: * -> Constraint) (x :: *) =
994 ( c (XFieldOcc x)
995 , c (XXFieldOcc x)
996 )
997
998
999 -- =====================================================================
1000 -- Type families for the HsImpExp type families
1001
1002 type family XCImportDecl x
1003 type family XXImportDecl x
1004
1005 type ForallXImportDecl (c :: * -> Constraint) (x :: *) =
1006 ( c (XCImportDecl x)
1007 , c (XXImportDecl x)
1008 )
1009
1010 -- -------------------------------------
1011
1012 type family XIEVar x
1013 type family XIEThingAbs x
1014 type family XIEThingAll x
1015 type family XIEThingWith x
1016 type family XIEModuleContents x
1017 type family XIEGroup x
1018 type family XIEDoc x
1019 type family XIEDocNamed x
1020 type family XXIE x
1021
1022 type ForallXIE (c :: * -> Constraint) (x :: *) =
1023 ( c (XIEVar x)
1024 , c (XIEThingAbs x)
1025 , c (XIEThingAll x)
1026 , c (XIEThingWith x)
1027 , c (XIEModuleContents x)
1028 , c (XIEGroup x)
1029 , c (XIEDoc x)
1030 , c (XIEDocNamed x)
1031 , c (XXIE x)
1032 )
1033
1034 -- -------------------------------------
1035
1036
1037 -- =====================================================================
1038 -- End of Type family definitions
1039 -- =====================================================================
1040
1041 -- ----------------------------------------------------------------------
1042 -- | Conversion of annotations from one type index to another. This is required
1043 -- where the AST is converted from one pass to another, and the extension values
1044 -- need to be brought along if possible. So for example a 'SourceText' is
1045 -- converted via 'id', but needs a type signature to keep the type checker
1046 -- happy.
1047 class Convertable a b | a -> b where
1048 convert :: a -> b
1049
1050 instance Convertable a a where
1051 convert = id
1052
1053 -- | A constraint capturing all the extension points that can be converted via
1054 -- @instance Convertable a a@
1055 type ConvertIdX a b =
1056 (XHsDoublePrim a ~ XHsDoublePrim b,
1057 XHsFloatPrim a ~ XHsFloatPrim b,
1058 XHsRat a ~ XHsRat b,
1059 XHsInteger a ~ XHsInteger b,
1060 XHsWord64Prim a ~ XHsWord64Prim b,
1061 XHsInt64Prim a ~ XHsInt64Prim b,
1062 XHsWordPrim a ~ XHsWordPrim b,
1063 XHsIntPrim a ~ XHsIntPrim b,
1064 XHsInt a ~ XHsInt b,
1065 XHsStringPrim a ~ XHsStringPrim b,
1066 XHsString a ~ XHsString b,
1067 XHsCharPrim a ~ XHsCharPrim b,
1068 XHsChar a ~ XHsChar b,
1069 XXLit a ~ XXLit b)
1070
1071 -- ----------------------------------------------------------------------
1072
1073 -- Note [OutputableX]
1074 -- ~~~~~~~~~~~~~~~~~~
1075 --
1076 -- is required because the type family resolution
1077 -- process cannot determine that all cases are handled for a `GhcPass p`
1078 -- case where the cases are listed separately.
1079 --
1080 -- So
1081 --
1082 -- type instance XXHsIPBinds (GhcPass p) = NoExt
1083 --
1084 -- will correctly deduce Outputable for (GhcPass p), but
1085 --
1086 -- type instance XIPBinds GhcPs = NoExt
1087 -- type instance XIPBinds GhcRn = NoExt
1088 -- type instance XIPBinds GhcTc = TcEvBinds
1089 --
1090 -- will not.
1091
1092
1093 -- | Provide a summary constraint that gives all am Outputable constraint to
1094 -- extension points needing one
1095 type OutputableX p = -- See Note [OutputableX]
1096 (
1097 Outputable (XSigPat p)
1098 , Outputable (XSigPat GhcRn)
1099
1100 , Outputable (XIPBinds p)
1101
1102 , Outputable (XExprWithTySig p)
1103 , Outputable (XExprWithTySig GhcRn)
1104
1105 , Outputable (XAppTypeE p)
1106 , Outputable (XAppTypeE GhcRn)
1107
1108 , Outputable (XViaStrategy p)
1109 , Outputable (XViaStrategy GhcRn)
1110
1111 )
1112 -- TODO: Should OutputableX be included in OutputableBndrId?
1113
1114 -- ----------------------------------------------------------------------
1115
1116 -- |Constraint type to bundle up the requirement for 'OutputableBndr' on both
1117 -- the @id@ and the 'NameOrRdrName' type for it
1118 type OutputableBndrId id =
1119 ( OutputableBndr (NameOrRdrName (IdP id))
1120 , OutputableBndr (IdP id)
1121 , OutputableX id
1122 )