@@ -7,16 +7,13 @@
77{-# LANGUAGE MultiParamTypeClasses #-}
88{-# LANGUAGE NoImplicitPrelude #-}
99{-# LANGUAGE OverloadedStrings #-}
10+{-# LANGUAGE PolyKinds #-}
1011{-# LANGUAGE RecordWildCards #-}
1112{-# LANGUAGE ScopedTypeVariables #-}
1213{-# LANGUAGE TypeOperators #-}
1314{-# LANGUAGE UndecidableInstances #-}
1415{-# LANGUAGE ViewPatterns #-}
1516
16−#if __GLASGOW_HASKELL__ >= 706
17−{-# LANGUAGE PolyKinds #-}
18−#endif
19−
2017#include "incoherent-compat.h"
2118#include "overlapping-compat.h"
2219
@@ -120,9 +117,9 @@ import GHC.Generics
120117import Numeric.Natural (Natural)
121118import Text.ParserCombinators.ReadP (readP_to_S)
122119import Unsafe.Coerce (unsafeCoerce)
123−import qualified Data.Aeson.Compat as Compat
124120import qualified Data.Aeson.Parser.Time as Time
125121import qualified Data.Attoparsec.ByteString.Char8 as A (endOfInput, parseOnly, scientific)
122+import qualified Data.ByteString.Lazy as L
126123import qualified Data.DList as DList
127124import qualified Data.HashMap.Strict as H
128125import qualified Data.HashSet as HashSet
@@ -157,18 +154,8 @@ import qualified Data.Primitive.UnliftedArray as PM
157154import qualified Data.Primitive.PrimArray as PM
158155#endif
159156
160−#ifndef HAS_COERCIBLE
161−#define HAS_COERCIBLE (__GLASGOW_HASKELL__ >= 707)
162−#endif
163157
164−#if HAS_COERCIBLE
165158import Data.Coerce (Coercible, coerce)
166−coerce' :: Coercible a b => a -> b
167−coerce' = coerce
168−#else
169−coerce' :: a -> b
170−coerce' = unsafeCoerce
171−#endif
172159
173160parseIndexedJSON :: (Value -> Parser a) -> Int -> Value -> Parser a
174161parseIndexedJSON p idx value = p value <?> Index idx
@@ -440,11 +427,7 @@ class FromJSONKey a where
440427-- At the moment this type is intentionally not exported. 'FromJSONKeyFunction'
441428-- can be inspected, but cannot be constructed.
442429data CoerceText a where
443−#if HAS_COERCIBLE
444430 CoerceText :: Coercible Text a => CoerceText a
445−#else
446− CoerceText :: CoerceText a
447−#endif
448431
449432-- | This type is related to 'ToJSONKeyFunction'. If 'FromJSONKeyValue' is used in the
450433-- 'FromJSONKey' instance, then 'ToJSONKeyValue' should be used in the 'ToJSONKey'
@@ -464,7 +447,7 @@ data FromJSONKeyFunction a
464447
465448-- | Only law abiding up to interpretation
466449instance Functor FromJSONKeyFunction where
467− fmap h (FromJSONKeyCoerce CoerceText) = FromJSONKeyText (h . coerce')
450+ fmap h (FromJSONKeyCoerce CoerceText) = FromJSONKeyText (h . coerce)
468451 fmap h (FromJSONKeyText f) = FromJSONKeyText (h . f)
469452 fmap h (FromJSONKeyTextParser f) = FromJSONKeyTextParser (fmap h . f)
470453 fmap h (FromJSONKeyValue f) = FromJSONKeyValue (fmap h . f)
@@ -478,9 +461,7 @@ instance Functor FromJSONKeyFunction where
478461--
479462-- On pre GHC 7.8 this is unconstrainted function.
480463fromJSONKeyCoerce ::
481−#if HAS_COERCIBLE
482464 Coercible Text a =>
483−#endif
484465 FromJSONKeyFunction a
485466fromJSONKeyCoerce = FromJSONKeyCoerce CoerceText
486467
@@ -488,29 +469,18 @@ fromJSONKeyCoerce = FromJSONKeyCoerce CoerceText
488469--
489470-- See note on 'fromJSONKeyCoerce'.
490471coerceFromJSONKeyFunction ::
491−#if HAS_COERCIBLE
492472 Coercible a b =>
493−#endif
494473 FromJSONKeyFunction a -> FromJSONKeyFunction b
495−#if HAS_COERCIBLE
496474coerceFromJSONKeyFunction = coerce
497−#else
498−coerceFromJSONKeyFunction (FromJSONKeyCoerce CoerceText) = FromJSONKeyCoerce CoerceText
499−coerceFromJSONKeyFunction (FromJSONKeyText f) = FromJSONKeyText (coerce' . f)
500−coerceFromJSONKeyFunction (FromJSONKeyTextParser f) = FromJSONKeyTextParser (fmap coerce' . f)
501−coerceFromJSONKeyFunction (FromJSONKeyValue f) = FromJSONKeyValue (fmap coerce' . f)
502−#endif
503475
504476{-# RULES
505477 "FromJSONKeyCoerce: fmap id" forall (x :: FromJSONKeyFunction a).
506478 fmap id x = x
507479 #-}
508−#if HAS_COERCIBLE
509480{-# RULES
510481 "FromJSONKeyCoerce: fmap coerce" forall x .
511482 fmap coerce x = coerceFromJSONKeyFunction x
512483 #-}
513−#endif
514484
515485-- | Same as 'fmap'. Provided for the consistency with 'ToJSONKeyFunction'.
516486mapFromJSONKeyFunction :: (a -> b) -> FromJSONKeyFunction a -> FromJSONKeyFunction b
@@ -797,13 +767,13 @@ withBoundedScientific' f v = withBoundedScientific_ id f v
797767-- | A variant of 'withBoundedScientific_' parameterized by a function to apply
798768-- to the 'Parser' in case of failure.
799769withBoundedScientific_ :: (Parser a -> Parser a) -> (Scientific -> Parser a) -> Value -> Parser a
800−withBoundedScientific_ whenFail f v@(Number scientific) =
801− if exponent > 1024
770+withBoundedScientific_ whenFail f (Number scientific) =
771+ if exp10 > 1024
802772 then whenFail (fail msg)
803773 else f scientific
804774 where
805− exponent = base10Exponent scientific
806− msg = "found a number with exponent " ++ show exponent ++ ", but it must not be greater than 1024"
775+ exp10 = base10Exponent scientific
776+ msg = "found a number with exponent " ++ show exp10 ++ ", but it must not be greater than 1024"
807777withBoundedScientific_ whenFail _ v =
808778 whenFail (typeMismatch "Number" v)
809779{-# INLINE withBoundedScientific_ #-}
@@ -823,7 +793,7 @@ withBool name _ v = prependContext name (typeMismatch "Boolean" v)
823793-- | Decode a nested JSON-encoded string.
824794withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a
825795withEmbeddedJSON _ innerParser (String txt) =
826− either fail innerParser $ eitherDecode (Compat.fromStrict $ T.encodeUtf8 txt)
796+ either fail innerParser $ eitherDecode (L.fromStrict $ T.encodeUtf8 txt)
827797 where
828798 eitherDecode = eitherFormatError . eitherDecodeWith jsonEOF ifromJSON
829799 eitherFormatError = either (Left . uncurry formatError) Right
@@ -1991,7 +1961,6 @@ instance FromJSON DotNetTime where
19911961-- primitive
19921962-------------------------------------------------------------------------------
19931963
1994−#if MIN_VERSION_base(4,7,0)
19951964instance FromJSON a => FromJSON (PM.Array a) where
19961965 -- note: we could do better than this if vector exposed the data
19971966 -- constructor in Data.Vector.
@@ -2009,7 +1978,6 @@ instance (PM.PrimUnlifted a,FromJSON a) => FromJSON (PM.UnliftedArray a) where
20091978 parseJSON = fmap Exts.fromList . parseJSON
20101979#endif
20111980#endif
2012−#endif
20131981
20141982-------------------------------------------------------------------------------
20151983-- time