on master help sign in
Less noisy OVERLAPPABLE pragma's using some CPP
commite2b038d3f03a3e28af1f57ebdc66250158e59482 authorBas van Dijk <v.dijk.bas@gmail.com> dateMon 12 Oct 2015, 09:40 (11 years ago) parent5778d36
5 files changed+25−59
Data/Aeson/TH.hs+2−8 Data/Aeson/Types/Generic.hs+9−33 Data/Aeson/Types/Instances.hs+4−18 aeson.cabal+2 include/overlapping-compat.h+8
Data/Aeson/TH.hs+2−8
@@ -2,9 +2,7 @@
22 NoImplicitPrelude, TemplateHaskell,
33 UndecidableInstances #-}
44
5−#if __GLASGOW_HASKELL__ < 710
6−{-# LANGUAGE OverlappingInstances #-}
7−#endif
5+#include "overlapping-compat.h"
86
97{-|
108Module: Data.Aeson.TH
@@ -955,11 +953,7 @@ parseTypeMismatch tName conName expected actual =
955953class (FromJSON a) => LookupField a where
956954 lookupField :: String -> String -> Object -> T.Text -> Parser a
957955
958−instance
959−#if __GLASGOW_HASKELL__ >= 710
960− {-# OVERLAPPABLE #-}
961−#endif
962− (FromJSON a) => LookupField a where
956+instance OVERLAPPABLE_ (FromJSON a) => LookupField a where
963957 lookupField tName rec obj key =
964958 case H.lookup key obj of
965959 Nothing -> unknownFieldFail tName rec (T.unpack key)
Data/Aeson/Types/Generic.hs+9−33
@@ -5,9 +5,7 @@
55 RecordWildCards #-}
66{-# OPTIONS_GHC -fno-warn-orphans #-}
77
8−#if __GLASGOW_HASKELL__ < 710
9−{-# LANGUAGE OverlappingInstances #-}
10−#endif
8+#include "overlapping-compat.h"
119
1210-- |
1311-- Module: Data.Aeson.Types.Generic
@@ -49,11 +47,7 @@ import Data.Monoid (mempty)
4947--------------------------------------------------------------------------------
5048-- Generic toJSON
5149
52−instance
53−#if __GLASGOW_HASKELL__ >= 710
54− {-# OVERLAPPABLE #-}
55−#endif
56− (GToJSON a) => GToJSON (M1 i c a) where
50+instance OVERLAPPABLE_ (GToJSON a) => GToJSON (M1 i c a) where
5751 -- Meta-information, which is not handled elsewhere, is ignored:
5852 gToJSON opts = gToJSON opts . unM1
5953 {-# INLINE gToJSON #-}
@@ -346,11 +340,8 @@ instance (Selector s, GToJSON a) => RecordTo (S1 s a) where
346340 recordToEncoding = fieldToEncoding
347341 {-# INLINE recordToEncoding #-}
348342
349−instance
350−#if __GLASGOW_HASKELL__ >= 710
351− {-# OVERLAPPING #-}
352−#endif
353− (Selector s, ToJSON a) => RecordTo (S1 s (K1 i (Maybe a))) where
343+instance OVERLAPPING_ (Selector s, ToJSON a) =>
344+ RecordTo (S1 s (K1 i (Maybe a))) where
354345 recordToPairs opts (M1 k1) | omitNothingFields opts
355346 , K1 Nothing <- k1 = empty
356347 recordToPairs opts m1 = fieldToPair opts m1
@@ -401,11 +392,7 @@ instance ( WriteProduct a
401392 encodeProduct opts b
402393 {-# INLINE encodeProduct #-}
403394
404−instance
405−#if __GLASGOW_HASKELL__ >= 710
406− {-# OVERLAPPABLE #-}
407−#endif
408− (GToJSON a) => WriteProduct a where
395+instance OVERLAPPABLE_ (GToJSON a) => WriteProduct a where
409396 writeProduct opts mv ix _ = VM.unsafeWrite mv ix . gToJSON opts
410397 {-# INLINE writeProduct #-}
411398
@@ -451,11 +438,7 @@ gbuilder opts = fromEncoding . gToEncoding opts
451438--------------------------------------------------------------------------------
452439-- Generic parseJSON
453440
454−instance
455−#if __GLASGOW_HASKELL__ >= 710
456− {-# OVERLAPPABLE #-}
457−#endif
458− (GFromJSON a) => GFromJSON (M1 i c a) where
441+instance OVERLAPPABLE_ (GFromJSON a) => GFromJSON (M1 i c a) where
459442 -- Meta-information, which is not handled elsewhere, is just added to the
460443 -- parsed value:
461444 gParseJSON opts = fmap M1 . gParseJSON opts
@@ -680,11 +663,8 @@ instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
680663 label = fieldLabelModifier opts $ selName (undefined :: t s a p)
681664 {-# INLINE parseRecord #-}
682665
683−instance
684−#if __GLASGOW_HASKELL__ >= 710
685− {-# OVERLAPPING #-}
686−#endif
687− (Selector s, FromJSON a) => FromRecord (S1 s (K1 i (Maybe a))) where
666+instance OVERLAPPING_ (Selector s, FromJSON a) =>
667+ FromRecord (S1 s (K1 i (Maybe a))) where
688668 parseRecord _ (Just lab) obj = (M1 . K1) . join <$> obj .:? lab
689669 parseRecord opts Nothing obj = (M1 . K1) . join <$> obj .:? pack label
690670 where
@@ -753,11 +733,7 @@ class IsRecord (f :: * -> *) isRecord | f -> isRecord
753733
754734instance (IsRecord f isRecord) => IsRecord (f :*: g) isRecord
755735 where isUnary = const False
756−instance
757−#if __GLASGOW_HASKELL__ >= 710
758− {-# OVERLAPPING #-}
759−#endif
760− IsRecord (M1 S NoSelector f) False
736+instance OVERLAPPING_ IsRecord (M1 S NoSelector f) False
761737instance (IsRecord f isRecord) => IsRecord (M1 S c f) isRecord
762738instance IsRecord (K1 i c) True
763739instance IsRecord U1 False
Data/Aeson/Types/Instances.hs+4−18
@@ -4,9 +4,7 @@
44 ViewPatterns #-}
55{-# LANGUAGE DefaultSignatures #-}
66
7−#if __GLASGOW_HASKELL__ < 710
8−{-# LANGUAGE OverlappingInstances #-}
9−#endif
7+#include "overlapping-compat.h"
108
119{-# OPTIONS_GHC -fno-warn-orphans #-}
1210
@@ -453,31 +451,19 @@ instance FromJSON LT.Text where
453451 parseJSON = withText "Lazy Text" $ pure . LT.fromStrict
454452 {-# INLINE parseJSON #-}
455453
456−instance
457−#if __GLASGOW_HASKELL__ >= 710
458− {-# OVERLAPPABLE #-}
459−#endif
460− (ToJSON a) => ToJSON [a] where
454+instance OVERLAPPABLE_ (ToJSON a) => ToJSON [a] where
461455 toJSON = Array . V.fromList . map toJSON
462456 {-# INLINE toJSON #-}
463457
464458 toEncoding xs = list xs
465459 {-# INLINE toEncoding #-}
466460
467−instance
468−#if __GLASGOW_HASKELL__ >= 710
469− {-# OVERLAPPABLE #-}
470−#endif
471− (FromJSON a) => FromJSON [a] where
461+instance OVERLAPPABLE_ (FromJSON a) => FromJSON [a] where
472462 parseJSON = withArray "[a]" $ Tr.sequence .
473463 zipWith parseIndexedJSON [0..] . V.toList
474464 {-# INLINE parseJSON #-}
475465
476−instance
477−#if __GLASGOW_HASKELL__ >= 710
478− {-# OVERLAPPABLE #-}
479−#endif
480− (Foldable t, ToJSON a) => ToJSON (t a) where
466+instance OVERLAPPABLE_ (Foldable t, ToJSON a) => ToJSON (t a) where
481467 toJSON = toJSON . toList
482468 {-# INLINE toJSON #-}
483469
aeson.cabal+2
@@ -112,6 +112,8 @@ library
112112
113113 ghc-options: -O2 -Wall
114114
115+ include-dirs: include
116+
115117test-suite tests
116118 type: exitcode-stdio-1.0
117119 hs-source-dirs: tests
include/overlapping-compat.hnew file+8
@@ -0,0 +1,8 @@
1+#if __GLASGOW_HASKELL__ >= 710
2+#define OVERLAPPABLE_ {-# OVERLAPPABLE #-}
3+#define OVERLAPPING_ {-# OVERLAPPING #-}
4+#else
5+{-# LANGUAGE OverlappingInstances #-}
6+#define OVERLAPPABLE_
7+#define OVERLAPPING_
8+#endif