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