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