forked from reflex-frp/reflex-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splices-load-save.patch
4384 lines (4222 loc) · 159 KB
/
splices-load-save.patch
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
diff --git a/compiler/basicTypes/DataCon.hs b/compiler/basicTypes/DataCon.hs
index a6d05936c1..2c8bc00af2 100644
--- a/compiler/basicTypes/DataCon.hs
+++ b/compiler/basicTypes/DataCon.hs
@@ -812,6 +812,7 @@ instance Binary SrcUnpackedness where
1 -> return SrcUnpack
_ -> return NoSrcUnpack
+
-- | Compare strictness annotations
eqHsBang :: HsImplBang -> HsImplBang -> Bool
eqHsBang HsLazy HsLazy = True
diff --git a/compiler/basicTypes/IdInfo.hs b/compiler/basicTypes/IdInfo.hs
index 07f8814767..10497fbba0 100644
--- a/compiler/basicTypes/IdInfo.hs
+++ b/compiler/basicTypes/IdInfo.hs
@@ -18,7 +18,7 @@ module IdInfo (
RecSelParent(..),
-- * The IdInfo type
- IdInfo, -- Abstract
+ IdInfo,
vanillaIdInfo, noCafIdInfo,
-- ** The OneShotInfo type
diff --git a/compiler/basicTypes/IdInfo.hs-boot b/compiler/basicTypes/IdInfo.hs-boot
index cacfe6af2e..229ff9abb0 100644
--- a/compiler/basicTypes/IdInfo.hs-boot
+++ b/compiler/basicTypes/IdInfo.hs-boot
@@ -1,6 +1,7 @@
module IdInfo where
import GhcPrelude
import Outputable
+
data IdInfo
data IdDetails
@@ -8,4 +9,3 @@ vanillaIdInfo :: IdInfo
coVarDetails :: IdDetails
isCoVarDetails :: IdDetails -> Bool
pprIdDetails :: IdDetails -> SDoc
-
diff --git a/compiler/basicTypes/OccName.hs b/compiler/basicTypes/OccName.hs
index f6a66fd635..854873011d 100644
--- a/compiler/basicTypes/OccName.hs
+++ b/compiler/basicTypes/OccName.hs
@@ -399,6 +399,10 @@ instance Uniquable OccName where
newtype OccEnv a = A (UniqFM a)
deriving Data
+instance Binary a => Binary (OccEnv a) where
+ put_ bh (A a) = put_ bh a
+ get bh = A <$> get bh
+
emptyOccEnv :: OccEnv a
unitOccEnv :: OccName -> a -> OccEnv a
extendOccEnv :: OccEnv a -> OccName -> a -> OccEnv a
diff --git a/compiler/basicTypes/PatSyn.hs b/compiler/basicTypes/PatSyn.hs
index 5a74a5b68a..fa5e475487 100644
--- a/compiler/basicTypes/PatSyn.hs
+++ b/compiler/basicTypes/PatSyn.hs
@@ -32,6 +32,7 @@ import Outputable
import Unique
import Util
import BasicTypes
+import Binary
import Var
import FieldLabel
@@ -328,6 +329,10 @@ instance Data.Data PatSyn where
gunfold _ _ = error "gunfold"
dataTypeOf _ = mkNoRepType "PatSyn"
+instance Binary PatSyn where
+ put = error "Binary PatSyn: not implemented yet"
+ get = error "Binary PatSyn: not implemented yet"
+
{-
************************************************************************
* *
diff --git a/compiler/basicTypes/RdrName.hs b/compiler/basicTypes/RdrName.hs
index 84ece4e9ff..45f2f00b13 100644
--- a/compiler/basicTypes/RdrName.hs
+++ b/compiler/basicTypes/RdrName.hs
@@ -72,6 +72,7 @@ import GhcPrelude
import Module
import Name
import Avail
+import Binary
import NameSet
import Maybes
import SrcLoc
@@ -467,6 +468,10 @@ data GlobalRdrElt
-- INVARIANT: either gre_lcl = True or gre_imp is non-empty
-- See Note [GlobalRdrElt provenance]
+instance Binary GlobalRdrElt where
+ put_ bh (GRE a b c d) = put_ bh a >> put_ bh b >> put_ bh c >> put_ bh d
+ get bh = GRE <$> get bh <*> get bh <*> get bh <*> get bh
+
-- | The children of a Name are the things that are abbreviated by the ".."
-- notation in export lists. See Note [Parents]
data Parent = NoParent
@@ -475,6 +480,18 @@ data Parent = NoParent
-- ^ See Note [Parents for record fields]
deriving (Eq, Data, Typeable)
+instance Binary Parent where
+ put_ bh p = case p of
+ NoParent -> putByte bh 0
+ ParentIs p -> putByte bh 1 >> put_ bh p
+ FldParent a b -> putByte bh 2 >> put_ bh a >> put_ bh b
+ get bh = do
+ tag <- getByte bh
+ case tag of
+ 0 -> pure NoParent
+ 1 -> ParentIs <$> get bh
+ _ -> FldParent <$> get bh <*> get bh
+
instance Outputable Parent where
ppr NoParent = empty
ppr (ParentIs n) = text "parent:" <> ppr n
@@ -1135,6 +1152,10 @@ data ImportSpec = ImpSpec { is_decl :: ImpDeclSpec,
is_item :: ImpItemSpec }
deriving( Eq, Ord, Data )
+instance Binary ImportSpec where
+ put_ bh (ImpSpec a b) = put_ bh a >> put_ bh b
+ get bh = ImpSpec <$> get bh <*> get bh
+
-- | Import Declaration Specification
--
-- Describes a particular import declaration and is
@@ -1152,6 +1173,11 @@ data ImpDeclSpec
is_dloc :: SrcSpan -- ^ The location of the entire import declaration
} deriving Data
+instance Binary ImpDeclSpec where
+ put_ bh (ImpDeclSpec a b c d) =
+ put_ bh a >> put_ bh b >> put_ bh c >> put_ bh d
+ get bh = ImpDeclSpec <$> get bh <*> get bh <*> get bh <*> get bh
+
-- | Import Item Specification
--
-- Describes import info a particular Name
@@ -1173,6 +1199,16 @@ data ImpItemSpec
-- only @T@ is named explicitly.
deriving Data
+instance Binary ImpItemSpec where
+ put_ bh s = case s of
+ ImpAll -> putByte bh 0
+ ImpSome a b -> putByte bh 1 >> put_ bh a >> put_ bh b
+ get bh = do
+ tag <- getByte bh
+ case tag of
+ 0 -> pure ImpAll
+ _ -> ImpSome <$> get bh <*> get bh
+
instance Eq ImpDeclSpec where
p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False
diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
index 9205648846..04e46f961d 100644
--- a/compiler/ghc.cabal.in
+++ b/compiler/ghc.cabal.in
@@ -210,6 +210,7 @@ Library
NameSet
OccName
RdrName
+ SeName
NameCache
SrcLoc
UniqSupply
@@ -316,6 +317,9 @@ Library
HsDecls
HsDoc
HsExpr
+ HsExprBin
+ HsExprBin_Conversions
+ HsExprBin_Instances
HsImpExp
HsLit
PlaceHolder
diff --git a/compiler/hsSyn/HsBinds.hs b/compiler/hsSyn/HsBinds.hs
index a9be2c1341..a346667b2b 100644
--- a/compiler/hsSyn/HsBinds.hs
+++ b/compiler/hsSyn/HsBinds.hs
@@ -12,6 +12,7 @@ Datatype for: @BindGroup@, @Bind@, @Sig@, @Bind@.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types]
-- in module PlaceHolder
+{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE BangPatterns #-}
@@ -324,7 +325,8 @@ data PatSynBind idL idR
-- ^ Formal parameter names
psb_def :: LPat idR, -- ^ Right-hand side
psb_dir :: HsPatSynDir idR -- ^ Directionality
- }
+ }
+
deriving instance (DataId idL, DataId idR) => Data (PatSynBind idL idR)
{-
@@ -779,7 +781,6 @@ deriving instance (DataId name) => Data (IPBind name)
instance (SourceTextX p, OutputableBndrId p) => Outputable (HsIPBinds p) where
ppr (IPBinds bs ds) = pprDeeperList vcat (map ppr bs)
- $$ whenPprDebug (ppr ds)
instance (SourceTextX p, OutputableBndrId p ) => Outputable (IPBind p) where
ppr (IPBind lr rhs) = name <+> equals <+> pprExpr (unLoc rhs)
@@ -854,7 +855,7 @@ data Sig pass
-- 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
- | IdSig Id
+ | IdSig (IdSigId pass)
-- | An ordinary fixity declaration
--
@@ -1063,7 +1064,9 @@ ppr_sig (TypeSig vars ty) = pprVarSig (map unLoc vars) (ppr ty)
ppr_sig (ClassOpSig is_deflt vars ty)
| is_deflt = text "default" <+> pprVarSig (map unLoc vars) (ppr ty)
| otherwise = pprVarSig (map unLoc vars) (ppr ty)
-ppr_sig (IdSig id) = pprVarSig [id] (ppr (varType id))
+ppr_sig (IdSig id) = case getVarType id of
+ Nothing -> ppr id
+ Just t -> pprVarSig [id] (ppr t)
ppr_sig (FixSig fix_sig) = ppr fix_sig
ppr_sig (SpecSig var ty inl@(InlinePragma { inl_inline = spec }))
= pragSrcBrackets (inl_src inl) pragmaSrc (pprSpec (unLoc var)
diff --git a/compiler/hsSyn/HsDecls.hs b/compiler/hsSyn/HsDecls.hs
index 55d43fd058..dca809f7d1 100644
--- a/compiler/hsSyn/HsDecls.hs
+++ b/compiler/hsSyn/HsDecls.hs
@@ -11,6 +11,7 @@
-- in module PlaceHolder
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE TypeFamilies #-}
-- | Abstract syntax of global declarations.
--
@@ -540,7 +541,6 @@ data TyClDecl pass
deriving instance (DataId id) => Data (TyClDecl id)
-
-- Simple classifiers for TyClDecl
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -644,7 +644,6 @@ hsDeclHasCusk (ClassDecl { tcdTyVars = tyvars }) = hsTvbAllKinded tyvars
instance (SourceTextX pass, OutputableBndrId pass)
=> Outputable (TyClDecl pass) where
-
ppr (FamDecl { tcdFam = decl }) = ppr decl
ppr (SynDecl { tcdLName = ltycon, tcdTyVars = tyvars, tcdFixity = fixity
, tcdRhs = rhs })
@@ -714,7 +713,6 @@ pprTyClDeclFlavour (FamDecl { tcdFam = FamilyDecl { fdInfo = info }})
pprTyClDeclFlavour (DataDecl { tcdDataDefn = HsDataDefn { dd_ND = nd } })
= ppr nd
-
{- Note [Complete user-supplied kind signatures]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We kind-check declarations differently if they have a complete, user-supplied
diff --git a/compiler/hsSyn/HsExpr.hs b/compiler/hsSyn/HsExpr.hs
index 333ca32d72..87a43797e6 100644
--- a/compiler/hsSyn/HsExpr.hs
+++ b/compiler/hsSyn/HsExpr.hs
@@ -10,7 +10,8 @@
-- in module PlaceHolder
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
-{-# LANGUAGE DeriveFunctor #-}
+{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-}
+{-# LANGUAGE TypeFamilies #-}
-- | Abstract Haskell syntax for expressions.
module HsExpr where
@@ -34,7 +35,7 @@ import CoreSyn
import DynFlags ( gopt, GeneralFlag(Opt_PrintExplicitCoercions) )
import Name
import NameSet
-import RdrName ( GlobalRdrEnv )
+import RdrName ( GlobalRdrEnv, RdrName )
import BasicTypes
import ConLike
import SrcLoc
@@ -434,7 +435,7 @@ data HsExpr p
-- 'ApiAnnotation.AnnClose'
-- For details on above see note [Api annotations] in ApiAnnotation
- | HsDo (HsStmtContext Name) -- The parameterisation is unimportant
+ | HsDo (HsStmtContext (DoName p)) -- The parameterisation is unimportant
-- because in this context we never use
-- the PatGuard or ParStmt variant
(Located [ExprLStmt p]) -- "do":one or more stmts
@@ -482,7 +483,6 @@ data HsExpr p
--
-- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'{'@,
-- 'ApiAnnotation.AnnDotdot','ApiAnnotation.AnnClose' @'}'@
-
-- For details on above see note [Api annotations] in ApiAnnotation
| RecordUpd
{ rupd_expr :: LHsExpr p
@@ -833,7 +833,8 @@ pprBinds b = pprDeeper (ppr b)
ppr_lexpr :: (SourceTextX p, OutputableBndrId p) => LHsExpr p -> SDoc
ppr_lexpr e = ppr_expr (unLoc e)
-ppr_expr :: forall p. (SourceTextX p, OutputableBndrId p) => HsExpr p -> SDoc
+ppr_expr :: forall p. (SourceTextX p, OutputableBndrId p)
+ => HsExpr p -> SDoc
ppr_expr (HsVar (L _ v)) = pprPrefixOcc v
ppr_expr (HsUnboundVar uv)= pprPrefixOcc (unboundVarOcc uv)
ppr_expr (HsConLikeOut c) = pprPrefixOcc c
@@ -859,6 +860,7 @@ ppr_expr (OpApp e1 op _ e2)
= pp_prefixly
where
+ should_print_infix :: HsExpr p -> Maybe SDoc
should_print_infix (HsVar (L _ v)) = Just (pprInfixOcc v)
should_print_infix (HsConLikeOut c)= Just (pprInfixOcc (conLikeName c))
should_print_infix (HsRecFld f) = Just (pprInfixOcc f)
@@ -891,6 +893,7 @@ ppr_expr (SectionL expr op)
pp_prefixly = hang (hsep [text " \\ x_ ->", ppr op])
4 (hsep [pp_expr, text "x_ )"])
+ pp_infixly :: OutputableBndr a => a -> SDoc
pp_infixly v = (sep [pp_expr, pprInfixOcc v])
ppr_expr (SectionR op expr)
@@ -905,6 +908,7 @@ ppr_expr (SectionR op expr)
pp_prefixly = hang (hsep [text "( \\ x_ ->", ppr op, text "x_"])
4 (pp_expr <> rparen)
+ pp_infixly :: OutputableBndr a => a -> SDoc
pp_infixly v = sep [pprInfixOcc v, pp_expr]
ppr_expr (ExplicitTuple exprs boxity)
@@ -1992,7 +1996,7 @@ pprStmt (RecStmt { recS_stmts = segment, recS_rec_ids = rec_ids
, whenPprDebug (vcat [ text "rec_ids=" <> ppr rec_ids
, text "later_ids=" <> ppr later_ids])]
-pprStmt (ApplicativeStmt args mb_join _)
+pprStmt (ApplicativeStmt args mb_join c)
= getPprStyle $ \style ->
if userStyle style
then pp_for_user
@@ -2010,6 +2014,7 @@ pprStmt (ApplicativeStmt args mb_join _)
flattenStmt (L _ (ApplicativeStmt args _ _)) = concatMap flattenArg args
flattenStmt stmt = [ppr stmt]
+ flattenArg :: forall a r. (a, ApplicativeArg idL r) -> [SDoc]
flattenArg (_, ApplicativeArgOne pat expr isBody)
| isBody = -- See Note [Applicative BodyStmt]
[ppr (BodyStmt expr noSyntaxExpr noSyntaxExpr (panic "pprStmt")
@@ -2421,7 +2426,7 @@ data HsMatchContext id -- Not an extensible tag
| ThPatSplice -- ^A Template Haskell pattern splice
| ThPatQuote -- ^A Template Haskell pattern quotation [p| (a,b) |]
| PatSyn -- ^A pattern synonym declaration
- deriving Functor
+ deriving (Functor, Foldable, Traversable)
deriving instance (Data id) => Data (HsMatchContext id)
instance OutputableBndr id => Outputable (HsMatchContext id) where
@@ -2437,6 +2442,7 @@ instance OutputableBndr id => Outputable (HsMatchContext id) where
ppr ThPatQuote = text "ThPatQuote"
ppr PatSyn = text "PatSyn"
+
isPatSynCtxt :: HsMatchContext id -> Bool
isPatSynCtxt ctxt =
case ctxt of
@@ -2458,7 +2464,7 @@ data HsStmtContext id
| PatGuard (HsMatchContext id) -- ^Pattern guard for specified thing
| ParStmtCtxt (HsStmtContext id) -- ^A branch of a parallel stmt
| TransStmtCtxt (HsStmtContext id) -- ^A branch of a transform stmt
- deriving Functor
+ deriving (Functor, Foldable, Traversable)
deriving instance (Data id) => Data (HsStmtContext id)
isListCompExpr :: HsStmtContext id -> Bool
diff --git a/compiler/hsSyn/HsExpr.hs-boot b/compiler/hsSyn/HsExpr.hs-boot
index bac8a5a183..2ef8dbc9a5 100644
--- a/compiler/hsSyn/HsExpr.hs-boot
+++ b/compiler/hsSyn/HsExpr.hs-boot
@@ -5,6 +5,7 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ExistentialQuantification #-}
+{-# LANGUAGE TypeFamilies #-} -- needed to use OutputableBndrId
module HsExpr where
diff --git a/compiler/hsSyn/HsExprBin.hs b/compiler/hsSyn/HsExprBin.hs
new file mode 100644
index 0000000000..1bf4b052f9
--- /dev/null
+++ b/compiler/hsSyn/HsExprBin.hs
@@ -0,0 +1,118 @@
+module HsExprBin
+ ( getModuleSplicesPath
+ , whenSet
+ , HsSpliceData(..)
+ , nonEmptyHsSpliceData
+ , emptyHsSpliceData
+ , SpliceResult(..)
+ , recordSpliceResult
+ , lookupSpliceResult
+ , exprSE2PS
+ , declSE2PS
+ , exprPS2SE
+ , declPS2SE
+ , handleUnsupported
+ ) where
+
+import Binary
+import GhcPrelude
+import HsDecls
+import HsExpr
+-- split into several modules because it was otherwise taking
+-- too long and too much memory to compile.
+import HsExprBin_Conversions
+import HsExprBin_Instances ()
+import HsExtension
+import Module
+import Outputable
+import SrcLoc
+import TcRnTypes
+
+import qualified Data.Map.Strict as Map
+import System.FilePath
+
+-- * .hs-splice file contents
+
+getModuleSplicesPath :: FilePath -> Module -> FilePath
+getModuleSplicesPath splicesDir m = splicesDir
+ </> toPath (moduleNameString (moduleName m)) <.> "hs-splice"
+
+ where toPath = map (\c -> if c == '.' then '/' else c)
+
+whenSet :: Monad m => Maybe a -> (a -> m b) -> m b -> m b
+whenSet m j n = maybe n j m
+
+newtype HsSpliceData = HsSpliceData { hsSpliceMap :: Map.Map SrcSpan SpliceResult }
+
+emptyHsSpliceData :: HsSpliceData
+emptyHsSpliceData = HsSpliceData Map.empty
+
+nonEmptyHsSpliceData :: HsSpliceData -> Bool
+nonEmptyHsSpliceData = not . Map.null . hsSpliceMap
+
+data SpliceResult
+ = SRExpr (LHsExpr GhcSe)
+ | SRDecls [LHsDecl GhcSe] -- TODO: change to HsGroup ?
+ -- TODO: add patterns and types?
+
+instance Binary SpliceResult where
+ put_ bh r = case r of
+ SRExpr e -> putByte bh 0 >> put_ bh e
+ SRDecls ds -> putByte bh 1 >> put_ bh ds
+ get bh = do
+ tag <- getByte bh
+ case tag of
+ 0 -> SRExpr <$> get bh
+ 1 -> SRDecls <$> get bh
+ _ -> panic "Binary SpliceResult: unknown tag"
+
+instance Binary HsSpliceData where
+ put_ bh (HsSpliceData m) = put_ bh (Map.toList m)
+ get bh = (\l -> HsSpliceData (Map.fromList l)) <$> get bh
+
+recordSpliceResult :: SrcSpan -> SpliceResult -> HsSpliceData -> HsSpliceData
+recordSpliceResult loc res (HsSpliceData m) = HsSpliceData (Map.insert loc res m)
+
+lookupSpliceResult :: SrcSpan -> HsSpliceData -> Maybe SpliceResult
+lookupSpliceResult loc (HsSpliceData m) = Map.lookup loc m
+
+-- * High-level conversion interface
+
+-- * Converting Se -> Ps
+
+exprSE2PS :: LHsExpr GhcSe -> RnM (ConvResult (LHsExpr GhcPs))
+exprSE2PS = runConv . cvLHsExpr
+
+declSE2PS :: LHsDecl GhcSe -> RnM (ConvResult (LHsDecl GhcPs))
+declSE2PS = runConv . cvLHsDecl
+
+-- * Converting Ps -> Se
+
+exprPS2SE :: LHsExpr GhcPs -> RnM (ConvResult (LHsExpr GhcSe))
+exprPS2SE = runConv . cvLHsExpr
+
+declPS2SE :: LHsDecl GhcPs -> RnM (ConvResult (LHsDecl GhcSe))
+declPS2SE = runConv . cvLHsDecl
+
+-- * Error reporting
+
+-- | Panics with a nice error when we encounter an unsupported
+-- construct, or returns the actual result if the conversion
+-- succeeded.
+handleUnsupported
+ :: Located SDoc -- ^ TH expression that got evaluated
+ -> Maybe SDoc -- ^ code resulting from the evaluation of the 1st arg
+ -> ConvResult a -- ^ result of the conversion
+ -> RnM a
+handleUnsupported (L loc thDoc) resDoc convRes = case convRes of
+ ConvOK a -> pure a
+ ConvError (ConvUnsupported conName tyName subexprDoc) ->
+ pprPanic "HsExprBin.handleUnsupported" . vcat $
+ [ text "GHC encountered a Haskell construct not supported by -{load, save}-splices:"
+ , nest 4 $ subexprDoc <> text (" - constructor " ++ conName ++ " of type " ++ tyName)
+ , text "while evaluating the following expression from " <> ppr loc <> text ":"
+ , nest 4 $ thDoc
+ ] ++
+ maybe [] (\d -> [text "which resulted in:" , nest 4 d]) resDoc
+
+ ConvError (ConvFailure errorStr) -> panic errorStr
diff --git a/compiler/hsSyn/HsExprBin.hs-boot b/compiler/hsSyn/HsExprBin.hs-boot
new file mode 100644
index 0000000000..964847e097
--- /dev/null
+++ b/compiler/hsSyn/HsExprBin.hs-boot
@@ -0,0 +1,4 @@
+module HsExprBin where
+
+data HsSpliceData
+emptyHsSpliceData :: HsSpliceData
\ No newline at end of file
diff --git a/compiler/hsSyn/HsExprBin_Conversions.hs b/compiler/hsSyn/HsExprBin_Conversions.hs
new file mode 100644
index 0000000000..d54bd2a7d3
--- /dev/null
+++ b/compiler/hsSyn/HsExprBin_Conversions.hs
@@ -0,0 +1,977 @@
+{-# LANGUAGE ConstraintKinds, DeriveFunctor #-}
+{-# LANGUAGE FlexibleContexts, FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeFamilies, TypeSynonymInstances #-}
+module HsExprBin_Conversions where
+
+import Control.Applicative
+import Control.Monad
+import Control.Monad.IO.Class
+import Data.Char (isDigit)
+import Data.List (intercalate)
+import Data.Maybe
+import Data.Traversable
+
+import Bag (mapBagM)
+import BasicTypes (Fixity)
+import Class
+import ConLike
+import CoreSyn ( Tickish(..) )
+import DynFlags
+import FastString
+import GhcPrelude
+import HsBinds
+import HsDecls
+import HsExpr
+import HsExtension
+import HsLit
+import HsPat
+import HsTypes
+import Module
+import Name
+import Outputable
+import PackageConfig
+import Packages
+import PlaceHolder
+import RdrName
+import SeName
+import SrcLoc
+import TcRnTypes
+import IfaceType
+import ToIface (toIfaceType)
+import TcEvidence (HsWrapper)
+import TyCoRep (Type(..), TyLit(..), Kind, Coercion)
+
+import qualified NameSet as NameSet
+
+data ConvError
+ = ConvUnsupported String String SDoc
+ -- constructor name, type name, text rendering
+ -- of the unsupported subexpression
+ | ConvFailure String
+
+data ConvResult a
+ = ConvError ConvError
+ | ConvOK a
+ deriving Functor
+-- * Conversion utilities
+
+newtype Conv a = Conv { runConv :: RnM (ConvResult a) }
+
+instance Functor Conv where
+ fmap f (Conv k) = Conv (fmap (fmap f) k)
+
+instance Applicative Conv where
+ pure = Conv . return . ConvOK
+ (<*>) = ap
+
+instance Monad Conv where
+ return = pure
+
+ Conv mx >>= f = Conv $ mx >>= \cvx -> case cvx of
+ ConvOK x -> runConv (f x)
+ ConvError e -> pure (ConvError e)
+
+unsupported :: String -- ^ constructor name
+ -> String -- ^ type name
+ -> SDoc -- ^ textual rendering of the unsupported subexpression
+ -> Conv a
+unsupported con ty subexpr = Conv $
+ pure (ConvError $ ConvUnsupported con ty subexpr)
+
+badInput :: String -> Conv a
+badInput str = Conv $ pure (ConvError $ ConvFailure str)
+
+liftRn :: RnM a -> Conv a
+liftRn = Conv . fmap ConvOK
+
+class ConvertType t u where
+ convertType :: t -> Conv u
+
+class ConvertName a b where
+ convertName :: a -> Conv b
+
+instance ConvertName a b => ConvertName [a] [b] where
+ convertName = traverse convertName
+
+instance ConvertName a b => ConvertName (Either e a) (Either e b) where
+ convertName = traverse convertName
+
+instance ConvertName a b => ConvertName (HsMatchContext a) (HsMatchContext b) where
+ convertName = traverse convertName
+
+instance ConvertName a b => ConvertName (HsStmtContext a) (HsStmtContext b) where
+ convertName = traverse convertName
+
+instance ConvertName a b => ConvertName (Maybe a) (Maybe b) where
+ convertName = traverse convertName
+
+instance ConvertType Type IfaceType where
+ convertType = pure . toIfaceType
+
+instance ConvertType IfaceType Type where
+ convertType (IfaceLitTy n) = pure $ LitTy (go n)
+ where go (IfaceNumTyLit a) = NumTyLit a
+ go (IfaceStrTyLit a) = StrTyLit a
+ convertType e@(IfaceFreeTyVar {}) = unsupported "IfaceFreeTyVar" "IfaceType" (ppr e)
+ convertType e@(IfaceTyVar {}) = unsupported "IfaceTyVar" "IfaceType" (ppr e)
+ convertType e@(IfaceAppTy {}) = unsupported "IfaceAppTy" "IfaceType" (ppr e)
+ convertType e@(IfaceFunTy {}) = unsupported "IfaceFunTy" "IfaceType" (ppr e)
+ convertType e@(IfaceDFunTy {}) = unsupported "IfaceDFunTy" "IfaceType" (ppr e)
+ convertType e@(IfaceForAllTy {}) = unsupported "IfaceForAllTy" "IfaceType" (ppr e)
+ convertType e@(IfaceTyConApp {}) = unsupported "IfaceTyConApp" "IfaceType" (ppr e)
+ convertType e@(IfaceCastTy {}) = unsupported "IfaceCastTy" "IfaceType" (ppr e)
+ convertType e@(IfaceCoercionTy {}) = unsupported "IfaceCoercion" "IfaceType" (ppr e)
+ convertType e@(IfaceTupleTy {}) = unsupported "IfaceTupleTy" "IfaceType" (ppr e)
+
+
+instance ConvertName RdrName SeName where
+ convertName = pure . mkSeName
+
+instance ConvertName SeName RdrName where
+ convertName (SeName n) = case n of
+ Orig mod occn -> do
+ -- TODO: introduce some caching here, to avoid doing the
+ -- searchPackageId dance too often.
+
+ {- liftIO . putStrLn $
+ "/!!!\\ Processing name: module=" ++ moduleNameString (moduleName mod) ++
+ ", occname = " ++ occNameString occn -}
+ currentMod <- liftRn getModule
+ {- liftIO . putStrLn $
+ "Current module (" ++ moduleNameString (moduleName currentMod) ++ ") is in: " ++
+ unitIdString (moduleUnitId currentMod) -}
+
+ if samePackages currentMod mod
+ then let newMod = mod { moduleUnitId = moduleUnitId currentMod } in
+ -- liftIO $ putStrLn ("using the current module's unit id for name coming from: " ++ moduleNameString (moduleName mod)) >>
+ pure (Orig newMod occn)
+ else do mnewmod <- liftRn (findEquivalentModule mod)
+ case mnewmod of
+ Nothing -> {- liftIO (putStrLn "keeping old name")
+ >> -} pure (Orig mod occn)
+ Just mod' -> {- liftIO (putStrLn "using new unitid!")
+ >> -} pure (Orig mod' occn)
+
+ _ -> pure n
+
+ where samePackages mod1 mod2 = fromMaybe False $ do -- maybe monad
+ let str1 = unitIdString (moduleUnitId mod1)
+ str2 = unitIdString (moduleUnitId mod2)
+ (pkg1, ver1, _mhash1) <- parseUnitId' str1
+ (pkg2, ver2, _mhash2) <- parseUnitId' str2
+ return (pkg1 == pkg2 && ver1 == ver2)
+
+instance ConvertName Name SeName where
+ convertName n = pure $ mkSeName (nameRdrName n)
+
+instance ConvertName SeName Name where
+ convertName (SeName n) = case isExact_maybe n of
+ Just a -> pure a
+ _ -> badInput "convertName :: SeName -> Name: non exact RdrName in SeName"
+
+instance ConvertName a b => ConvertName (Located a) (Located b) where
+ convertName = traverse convertName
+
+type TypeConstraints p q =
+ ( ConvertType (LitType p) (LitType q)
+ , ConvertName (IdP p) (IdP q)
+ , ConvertName (DoName p) (DoName q)
+ , ConvertName (NameOrRdrName (IdP p)) (NameOrRdrName (IdP q))
+ , ConvertName (RdrOrSeName p) (RdrOrSeName q)
+ , PostRn p NameSet.NameSet ~ PostRn q NameSet.NameSet
+ , PostRn p (Located Name) ~ PostRn q (Located Name)
+ , PostRn p [Name] ~ PostRn q [Name]
+ , PostRn p Bool ~ PostRn q Bool
+ , PostRn p (IdP p) ~ PostRn q (IdP q)
+ , PostRn q Fixity ~ PostRn p Fixity
+ , PostTc p Kind ~ PostTc q Kind
+ , PostTc p (IdP p) ~ PostTc q (IdP q)
+ , PostTc p [Type] ~ PostTc q [Type]
+ , PostTc p HsWrapper ~ PostTc q HsWrapper
+ , PostTc p ConLike ~ PostTc q ConLike
+ , PostTc p [ConLike] ~ PostTc q [ConLike]
+ , PostTc q Coercion ~ PostTc p Coercion
+ , ConvertIdX p q
+ , OutputableBndrId p
+ , SourceTextX p
+ )
+
+-- * Actual conversion implementation
+
+-- declarations
+
+cvLHsDecl :: TypeConstraints p q => LHsDecl p -> Conv (LHsDecl q)
+cvLHsDecl = traverse cvHsDecl
+
+cvHsDecl :: TypeConstraints p q => HsDecl p -> Conv (HsDecl q)
+cvHsDecl (TyClD a) = TyClD <$> cvTyClDecl a
+cvHsDecl (InstD a) = InstD <$> cvInstDecl a
+cvHsDecl (DerivD a) = DerivD <$> cvDerivDecl a
+cvHsDecl (ValD a) = ValD <$> cvHsBindLR a
+cvHsDecl (SigD a) = SigD <$> cvSig a
+cvHsDecl (DefD a) = DefD <$> cvDefaultDecl a
+cvHsDecl (ForD a) = ForD <$> cvForeignDecl a
+cvHsDecl (WarningD a) = WarningD <$> cvWarningDecls a
+cvHsDecl (RoleAnnotD a) = RoleAnnotD <$> cvRoleAnnotDecl a
+cvHsDecl (AnnD a) = AnnD <$> cvAnnDecl a
+cvHsDecl (RuleD a) = RuleD <$> cvRuleDecls a
+cvHsDecl (SpliceD a) = SpliceD <$> cvSpliceDecl a
+cvHsDecl (DocD a) = pure (DocD a)
+cvHsDecl (VectD a) = VectD <$> cvVectDecl a
+
+cvAnnDecl :: TypeConstraints p q => AnnDecl p -> Conv (AnnDecl q)
+cvAnnDecl (HsAnnotation a b c) = HsAnnotation a <$> cvAnnProvenance b <*> cvLHsExpr c
+
+cvInstDecl :: TypeConstraints p q => InstDecl p -> Conv (InstDecl q)
+cvInstDecl (ClsInstD a) = ClsInstD <$> cvClsInstDecl a
+cvInstDecl (DataFamInstD a) = DataFamInstD <$> cvDataFamInstDecl a
+cvInstDecl (TyFamInstD a) = TyFamInstD <$> cvTyFamInstDecl a
+
+cvClsInstDecl :: TypeConstraints p q => ClsInstDecl p -> Conv (ClsInstDecl q)
+cvClsInstDecl (ClsInstDecl a b c d e f ) =
+ ClsInstDecl
+ <$> cvHsImplicitBndrs (traverse cvType) a
+ <*> mapBagM (traverse cvHsBindLR) b
+ <*> traverse (traverse cvSig) c
+ <*> traverse (traverse cvTyFamInstDecl) d
+ <*> traverse (traverse cvDataFamInstDecl) e
+ <*> pure f
+
+cvDerivDecl :: TypeConstraints p q => DerivDecl p -> Conv (DerivDecl q)
+cvDerivDecl (DerivDecl a b c) =
+ DerivDecl <$> cvHsImplicitBndrs (traverse cvType) a <*> pure b <*> pure c
+
+cvTyClDecl :: TypeConstraints p q => TyClDecl p -> Conv (TyClDecl q)
+cvTyClDecl (FamDecl a) = FamDecl <$> cvFamilyDecl a
+cvTyClDecl (SynDecl a b c d e) =
+ SynDecl
+ <$> convertName a
+ <*> cvLHsQTyVars b <*> pure c
+ <*> traverse cvType d <*> pure e
+cvTyClDecl (DataDecl a b c d e f) =
+ DataDecl
+ <$> convertName a
+ <*> cvLHsQTyVars b <*> pure c
+ <*> cvHsDataDefn d <*> pure e <*> pure f
+cvTyClDecl (ClassDecl a b c d e f g h i j k) =
+ ClassDecl
+ <$> traverse (traverse (traverse cvType)) a
+ <*> convertName b
+ <*> cvLHsQTyVars c
+ <*> pure d
+ <*> traverse (traverse cvFunDep) e
+ <*> traverse (traverse cvSig) f
+ <*> mapBagM (traverse cvHsBindLR) g
+ <*> traverse (traverse cvFamilyDecl) h
+ <*> traverse (traverse $ cvFamEqn cvLHsQTyVars (traverse cvType)) i
+ <*> pure j <*> pure k
+
+cvRoleAnnotDecl
+ :: TypeConstraints p q => RoleAnnotDecl p -> Conv (RoleAnnotDecl q)
+cvRoleAnnotDecl (RoleAnnotDecl a b) = RoleAnnotDecl <$> convertName a <*> pure b
+
+cvRuleDecls :: TypeConstraints p q => RuleDecls p -> Conv (RuleDecls q)
+cvRuleDecls (HsRules a b) = HsRules a <$> traverse (traverse cvRuleDecl) b
+
+cvRuleDecl :: TypeConstraints p q => RuleDecl p -> Conv (RuleDecl q)
+cvRuleDecl (HsRule a b c d e f g) =
+ HsRule a b <$> traverse (traverse cvRuleBndr) c <*> cvLHsExpr d
+ <*> pure e <*> cvLHsExpr f <*> pure g
+
+cvSpliceDecl :: TypeConstraints p q => SpliceDecl p -> Conv (SpliceDecl q)
+cvSpliceDecl (SpliceDecl a b) = SpliceDecl <$> traverse cvHsSplice a <*> pure b
+
+cvHsSplice :: TypeConstraints p q => HsSplice p -> Conv (HsSplice q)
+cvHsSplice (HsTypedSplice a b c) = HsTypedSplice a <$> convertName b <*> cvLHsExpr c
+cvHsSplice (HsUntypedSplice a b c) = HsUntypedSplice a <$> convertName b <*> cvLHsExpr c
+cvHsSplice (HsQuasiQuote a b c d) = HsQuasiQuote <$> convertName a <*> convertName b <*> pure c <*> pure d
+cvHsSplice e@(HsSpliced {}) = unsupported "HsSpliced" "HsSplice" (ppr e)
+
+cvRuleBndr :: TypeConstraints p q => RuleBndr p -> Conv (RuleBndr q)
+cvRuleBndr (RuleBndr a) = RuleBndr <$> convertName a
+cvRuleBndr (RuleBndrSig a b) = RuleBndrSig <$> convertName a <*> cvHsSigWcType b
+
+cvFamEqn
+ :: TypeConstraints p q
+ => (a -> Conv c)
+ -> (b -> Conv d)
+ -> FamEqn p a b
+ -> Conv (FamEqn q c d)
+cvFamEqn goPats goRhs (FamEqn a b c d) =
+ FamEqn <$> convertName a <*> goPats b <*> pure c <*> goRhs d
+
+cvFamilyDecl :: TypeConstraints p q => FamilyDecl p -> Conv (FamilyDecl q)
+cvFamilyDecl (FamilyDecl a b c d e f) =
+ FamilyDecl
+ <$> cvFamilyInfo a <*> convertName b
+ <*> cvLHsQTyVars c <*> pure d
+ <*> traverse cvFamilyResultSig e
+ <*> traverse (traverse cvInjectivityAnn) f
+
+cvAnnProvenance :: ConvertName a b => AnnProvenance a -> Conv (AnnProvenance b)
+cvAnnProvenance (ValueAnnProvenance a) = ValueAnnProvenance <$> convertName a
+cvAnnProvenance (TypeAnnProvenance a) = TypeAnnProvenance <$> convertName a
+cvAnnProvenance ModuleAnnProvenance = pure ModuleAnnProvenance
+
+cvInjectivityAnn
+ :: TypeConstraints p q => InjectivityAnn p -> Conv (InjectivityAnn q)
+cvInjectivityAnn (InjectivityAnn a b) =
+ InjectivityAnn <$> convertName a <*> convertName b
+
+cvFamilyResultSig
+ :: TypeConstraints p q => FamilyResultSig p -> Conv (FamilyResultSig q)
+cvFamilyResultSig NoSig = pure NoSig
+cvFamilyResultSig (KindSig a) = KindSig <$> traverse cvType a
+cvFamilyResultSig (TyVarSig a) = TyVarSig <$> traverse cvHsTyVarBndr a
+
+cvFamilyInfo :: TypeConstraints p q => FamilyInfo p -> Conv (FamilyInfo q)
+cvFamilyInfo DataFamily = pure DataFamily
+cvFamilyInfo OpenTypeFamily = pure OpenTypeFamily
+cvFamilyInfo (ClosedTypeFamily a) =
+ ClosedTypeFamily <$> traverse (traverse (traverse (cvFamInstEqn (traverse cvType)))) a
+
+cvFamInstEqn
+ :: TypeConstraints p q
+ => (a -> Conv b)
+ -> FamInstEqn p a
+ -> Conv (FamInstEqn q b)
+cvFamInstEqn f = cvHsImplicitBndrs (cvFamEqn (traverse (traverse cvType)) f)
+
+cvFunDep :: ConvertName a b => FunDep a -> Conv (FunDep b)
+cvFunDep (xs, ys) = (,) <$> convertName xs <*> convertName ys
+
+cvLHsQTyVars :: TypeConstraints p q => LHsQTyVars p -> Conv (LHsQTyVars q)
+cvLHsQTyVars (HsQTvs a b c) = HsQTvs a <$> traverse (traverse cvHsTyVarBndr) b <*> pure c
+
+cvForeignDecl :: TypeConstraints p q => ForeignDecl p -> Conv (ForeignDecl q)
+cvForeignDecl (ForeignImport a b c d) =
+ ForeignImport
+ <$> convertName a
+ <*> cvHsImplicitBndrs (traverse cvType) b
+ <*> pure c <*> pure d
+cvForeignDecl (ForeignExport a b c d) =
+ ForeignExport
+ <$> convertName a
+ <*> cvHsImplicitBndrs (traverse cvType) b
+ <*> pure c <*> pure d
+
+cvDefaultDecl :: TypeConstraints p q => DefaultDecl p -> Conv (DefaultDecl q)
+cvDefaultDecl (DefaultDecl a) = DefaultDecl <$> traverse (traverse cvType) a
+
+cvTyFamInstDecl
+ :: TypeConstraints p q => TyFamInstDecl p -> Conv (TyFamInstDecl q)
+cvTyFamInstDecl (TyFamInstDecl d) =
+ TyFamInstDecl <$> cvFamInstEqn (traverse cvType) d
+
+cvDataFamInstDecl
+ :: TypeConstraints p q => DataFamInstDecl p -> Conv (DataFamInstDecl q)
+cvDataFamInstDecl (DataFamInstDecl d) =
+ DataFamInstDecl <$> cvFamInstEqn cvHsDataDefn d
+
+cvHsDataDefn :: TypeConstraints p q => HsDataDefn p -> Conv (HsDataDefn q)
+cvHsDataDefn (HsDataDefn a b c d e f) =
+ HsDataDefn a
+ <$> traverse (traverse (traverse cvType)) b <*> pure c
+ <*> traverse (traverse cvType) d
+ <*> traverse (traverse cvConDecl) e <*> cvHsDeriving f
+
+cvConDecl :: TypeConstraints p q => ConDecl p -> Conv (ConDecl q)
+cvConDecl (ConDeclGADT a b c) =
+ ConDeclGADT
+ <$> convertName a
+ <*> cvHsImplicitBndrs (traverse cvType) b
+ <*> pure c
+cvConDecl (ConDeclH98 a b c d e) =
+ ConDeclH98
+ <$> convertName a
+ <*> traverse cvLHsQTyVars b
+ <*> traverse (traverse (traverse (traverse cvType))) c
+ <*> cvHsConDeclDetails d
+ <*> pure e
+
+cvHsDeriving :: TypeConstraints p q => HsDeriving p -> Conv (HsDeriving q)
+cvHsDeriving = traverse (traverse (traverse cvHsDerivingClause))
+
+cvHsDerivingClause
+ :: TypeConstraints p q => HsDerivingClause p -> Conv (HsDerivingClause q)
+cvHsDerivingClause (HsDerivingClause a b) =
+ HsDerivingClause a
+ <$> traverse (traverse (cvHsImplicitBndrs (traverse cvType))) b
+
+cvHsConDeclDetails
+ :: TypeConstraints p q => HsConDeclDetails p -> Conv (HsConDeclDetails q)
+cvHsConDeclDetails =
+ cvHsConDetails (traverse cvType)
+ (traverse (traverse (traverse cvConDeclField)))
+
+cvHsConDetails
+ :: (a -> Conv c) -> (b -> Conv d) -> HsConDetails a b -> Conv (HsConDetails c d)
+cvHsConDetails f _ (PrefixCon a) = PrefixCon <$> traverse f a
+cvHsConDetails _ g (RecCon a) = RecCon <$> g a
+cvHsConDetails f _ (InfixCon a b) = InfixCon <$> f a <*> f b
+
+cvConDeclField :: TypeConstraints p q => ConDeclField p -> Conv (ConDeclField q)
+cvConDeclField (ConDeclField a b c) =
+ ConDeclField <$> traverse (traverse cvFieldOcc) a <*> traverse cvType b
+ <*> pure c
+
+cvWarningDecls :: TypeConstraints p q => WarnDecls p -> Conv (WarnDecls q)
+cvWarningDecls (Warnings a b) =
+ Warnings a <$> traverse (traverse cvWarningDecl) b
+
+cvWarningDecl :: TypeConstraints p q => WarnDecl p -> Conv (WarnDecl q)
+cvWarningDecl (Warning a b) = Warning <$> convertName a <*> pure b
+
+-- expressions
+
+cvLHsExpr
+ :: TypeConstraints p q => LHsExpr p -> Conv (LHsExpr q)
+cvLHsExpr = traverse cvHsExpr
+
+cvHsExpr
+ :: TypeConstraints p q => HsExpr p -> Conv (HsExpr q)
+cvHsExpr e = case e of
+ HsVar a -> HsVar <$> convertName a
+ HsUnboundVar a -> pure (HsUnboundVar a)
+ HsConLikeOut a -> pure (HsConLikeOut a)
+ HsRecFld a -> HsRecFld <$> cvAFieldOcc a
+ HsOverLabel a b -> HsOverLabel <$> convertName a <*> pure b
+ HsIPVar a -> pure (HsIPVar a)
+ HsOverLit a -> HsOverLit <$> cvOverLit a
+ HsLit a -> HsLit <$> cvLit a
+ HsLam a -> HsLam <$> cvMatchGroup cvLHsExpr a
+ HsLamCase a -> HsLamCase <$> cvMatchGroup cvLHsExpr a
+ HsApp a b -> HsApp <$> cvLHsExpr a <*> cvLHsExpr b
+ HsAppType a b -> HsAppType <$> cvLHsExpr a <*> cvLHsWcType b
+ OpApp a b c d -> OpApp <$> cvLHsExpr a <*> cvLHsExpr b
+ <*> pure c <*> cvLHsExpr d
+ NegApp a b -> NegApp <$> cvLHsExpr a <*> cvSyntaxExpr b
+ HsPar a -> HsPar <$> cvLHsExpr a
+ SectionL a b -> SectionL <$> cvLHsExpr a <*> cvLHsExpr b
+ SectionR a b -> SectionR <$> cvLHsExpr a <*> cvLHsExpr b
+ ExplicitTuple a b -> ExplicitTuple <$> traverse (traverse cvHsTupArg) a <*> pure b
+ ExplicitSum a b c d -> ExplicitSum a b <$> cvLHsExpr c <*> pure d
+ ExplicitList a b c -> ExplicitList a <$> traverse cvSyntaxExpr b <*> traverse cvLHsExpr c
+ HsCase a b -> HsCase <$> cvLHsExpr a <*> cvMatchGroup cvLHsExpr b
+ HsIf a b c d -> HsIf <$> traverse cvSyntaxExpr a
+ <*> cvLHsExpr b <*> cvLHsExpr c <*> cvLHsExpr d
+ HsMultiIf a b -> HsMultiIf a <$> traverse (traverse (cvGRHS cvLHsExpr)) b
+ HsLet a b -> HsLet <$> traverse cvHsLocalBinds a <*> cvLHsExpr b