text-show 3.10.3 → 3.10.4
raw patch · 8 files changed
+179/−32 lines, 8 filesdep ~basedep ~containersdep ~deriving-compat
Dependency ranges changed: base, containers, deriving-compat, ghc-boot-th, template-haskell, text, th-abstraction
Files
- CHANGELOG.md +14/−0
- README.md +15/−2
- shared/TextShow/TH/Names.hs +3/−1
- src/TextShow/Data/Typeable.hs +47/−2
- src/TextShow/TH/Internal.hs +60/−4
- tests/Derived/TypeSynonyms.hs +2/−0
- tests/Spec/Data/TypeableSpec.hs +6/−0
- text-show.cabal +32/−23
CHANGELOG.md view
@@ -1,3 +1,17 @@+### 3.10.4 [2023.08.06]+* Support building with GHC 9.8.+* Ensure that the `TextShow` instance for `TypeRep` properly displays+ `TypeRep []` as `"[]"`.+* Ensure that the `TextShow` instance for `TypeRep` properly handles partial+ applications of tuple constructors (e.g., `(,) Int`).+* Support deriving `TextShow(1)(2)` instances for data types with fields+ of type `Int64#` or `Word64#` on GHC 9.8 or later.+* When generating `TextShow(1)(2)` instances with `TextShow.TH` using GHC 9.8 or+ later, data types that have fields of type `Int{8,16,32,64}#` or+ `Word{8,16,32,64}#` will be printed using extended literal syntax, mirroring+ corresponding changes introduced in GHC 9.8 (see+ https://github.com/ghc-proposals/ghc-proposals/pull/596).+ ### 3.10.3 [2023.06.03] * Support building with `QuickCheck-2.14.3` in the test suite.
README.md view
@@ -18,8 +18,6 @@ `text-show` offers a replacement for the `Show` typeclass intended for use with `Text` instead of `String`s. This package was created in the spirit of [`bytestring-show`](http://hackage.haskell.org/package/bytestring-show). -At the moment, `text-show` provides instances for most data types in the [`array`](http://hackage.haskell.org/package/array), [`base`](http://hackage.haskell.org/package/base), [`bytestring`](http://hackage.haskell.org/package/bytestring), and [`text`](http://hackage.haskell.org/package/text) packages. Therefore, much of the source code for `text-show` consists of borrowed code from those packages in order to ensure that the behaviors of `Show` and `TextShow` coincide.- For most uses, simply importing `TextShow` will suffice: ```haskell@@ -34,3 +32,18 @@ See also the [naming conventions](https://github.com/RyanGlScott/text-show/wiki/Naming-conventions) page. Support for automatically deriving `TextShow` instances can be found in the `TextShow.TH` and `TextShow.Generic` modules.++## Scope of the library++`text-show` only provides instances for data types in the following packages:++* [`array`](http://hackage.haskell.org/package/array)+* [`base`](http://hackage.haskell.org/package/base)+* [`bytestring`](http://hackage.haskell.org/package/bytestring)+* [`text`](http://hackage.haskell.org/package/text)++This policy is in place to keep `text-show`'s dependencies reasonably light. If+you need a `TextShow` instance for a library that is not in this list, it may+be covered by the+[`text-show-instances`](https://github.com/RyanGlScott/text-show-instances)+library.
@@ -59,7 +59,9 @@ -- | The 'Name' of 'asInt64' (or, 'asInt' on @base-4.10.0.0@ or later). asInt64ValName :: Name-#if MIN_VERSION_base(4,10,0)+#if MIN_VERSION_base(4,19,0)+asInt64ValName = mkNameG_fld "base" "GHC.Event.Unique" "Unique" "asInt"+#elif MIN_VERSION_base(4,10,0) asInt64ValName = mkNameG_v "base" "GHC.Event.Unique" "asInt" #else asInt64ValName = mkNameG_v "base" "GHC.Event.Unique" "asInt64"
src/TextShow/Data/Typeable.hs view
@@ -39,7 +39,6 @@ import TextShow.Classes (TextShow(..), TextShow1(..), showbParen, showbSpace) import TextShow.Data.Typeable.Utils (showbArgs, showbTuple)-import TextShow.Utils (isTupleString) import Type.Reflection (pattern App, pattern Con, pattern Con', pattern Fun, SomeTypeRep(..), TypeRep,@@ -70,6 +69,16 @@ import TextShow.Classes (TextShow(..), showbParen, showbSpace) import TextShow.Data.List () import TextShow.Data.Typeable.Utils (showbArgs, showbTuple)+#endif++#if MIN_VERSION_base(4,13,0)+import Type.Reflection (typeRepKind)+#endif++#if MIN_VERSION_base(4,19,0)+import Data.Char (isDigit, ord)+import Type.Reflection (tyConModule, tyConPackage)+#else import TextShow.Utils (isTupleString) #endif @@ -104,9 +113,31 @@ #endif -- | Does the 'TyCon' represent a tuple type constructor?+#if MIN_VERSION_base(4,19,0)+isTupleTyCon :: TyCon -> Maybe Int+isTupleTyCon tc+ | tyConPackage tc == "ghc-prim"+ , tyConModule tc == "GHC.Tuple.Prim"+ = case tyConName tc of+ "Unit" -> Just 0+ 'T' : 'u' : 'p' : 'l' : 'e' : arity -> readTwoDigits arity+ _ -> Nothing+ | otherwise = Nothing++readTwoDigits :: String -> Maybe Int+readTwoDigits s = case s of+ [c] | isDigit c -> Just (digit_to_int c)+ [c1, c2] | isDigit c1, isDigit c2+ -> Just (digit_to_int c1 * 10 + digit_to_int c2)+ _ -> Nothing+ where+ digit_to_int :: Char -> Int+ digit_to_int c = ord c - ord '0'+#else isTupleTyCon :: TyCon -> Bool isTupleTyCon = isTupleString . tyConName {-# INLINE isTupleTyCon #-}+#endif #if MIN_VERSION_base(4,10,0) -- | Only available with @base-4.10.0.0@ or later.@@ -131,10 +162,24 @@ showbTypeable _ rep | Just HRefl <- rep `eqTypeRep` (typeRep :: TypeRep Type) = singleton '*'+ | isListTyCon tc, [] <- tys =+ fromString "[]" | isListTyCon tc, [ty] <- tys = singleton '[' <> showb ty <> singleton ']'- | isTupleTyCon tc =+# if MIN_VERSION_base(4,19,0)+ | Just _ <- isTupleTyCon tc,+ Just _ <- typeRep @Type `eqTypeRep` typeRepKind rep = showbTuple tys+ -- Print (,,,) instead of Tuple4+ | Just n <- isTupleTyCon tc, [] <- tys =+ singleton '(' <> fromString (replicate (n-1) ',') <> singleton ')'+# else+ | isTupleTyCon tc+# if MIN_VERSION_base(4,13,0)+ , Just _ <- typeRep @Type `eqTypeRep` typeRepKind rep+# endif+ = showbTuple tys+# endif where (tc, tys) = splitApps rep showbTypeable p (Con' tycon []) = showbPrec p tycon
src/TextShow/TH/Internal.hs view
@@ -80,10 +80,14 @@ , Int8#, Int16#, Word8#, Word16# # if MIN_VERSION_base(4,16,0) , Int32#, Word32#+# if MIN_VERSION_base(4,19,0)+ , Int64#, Word64#+# else , int8ToInt#, int16ToInt#, int32ToInt# , intToInt8#, intToInt16#, intToInt32# , word8ToWord#, word16ToWord#, word32ToWord# , wordToWord8#, wordToWord16#, wordToWord32#+# endif # else , extendInt8#, extendInt16#, extendWord8#, extendWord16# , narrowInt8#, narrowInt16#, narrowWord8#, narrowWord16#@@ -91,6 +95,10 @@ #endif ) import GHC.Show (appPrec, appPrec1)+#if MIN_VERSION_base(4,19,0)+import GHC.Int (Int8(..), Int16(..), Int32(..), Int64(..))+import GHC.Word (Word8(..), Word16(..), Word32(..), Word64(..))+#endif import Language.Haskell.TH.Datatype as Datatype import Language.Haskell.TH.Lib@@ -1263,8 +1271,50 @@ , primShowPostfixMod = twoHashE , primShowConv = \_ x -> x })-#if MIN_VERSION_base(4,13,0)+#if MIN_VERSION_base(4,19,0) , (''Int8#, PrimShow+ { primShowBoxer = appE (conE 'I8#)+ , primShowPostfixMod = extendedLitE "Int8"+ , primShowConv = \_ x -> x+ })+ , (''Int16#, PrimShow+ { primShowBoxer = appE (conE 'I16#)+ , primShowPostfixMod = extendedLitE "Int16"+ , primShowConv = \_ x -> x+ })+ , (''Int32#, PrimShow+ { primShowBoxer = appE (conE 'I32#)+ , primShowPostfixMod = extendedLitE "Int32"+ , primShowConv = \_ x -> x+ })+ , (''Int64#, PrimShow+ { primShowBoxer = appE (conE 'I64#)+ , primShowPostfixMod = extendedLitE "Int64"+ , primShowConv = \_ x -> x+ })+ , (''Word8#, PrimShow+ { primShowBoxer = appE (conE 'W8#)+ , primShowPostfixMod = extendedLitE "Word8"+ , primShowConv = \_ x -> x+ })+ , (''Word16#, PrimShow+ { primShowBoxer = appE (conE 'W16#)+ , primShowPostfixMod = extendedLitE "Word16"+ , primShowConv = \_ x -> x+ })+ , (''Word32#, PrimShow+ { primShowBoxer = appE (conE 'W32#)+ , primShowPostfixMod = extendedLitE "Word32"+ , primShowConv = \_ x -> x+ })+ , (''Word64#, PrimShow+ { primShowBoxer = appE (conE 'W64#)+ , primShowPostfixMod = extendedLitE "Word64"+ , primShowConv = \_ x -> x+ })+#else+# if MIN_VERSION_base(4,13,0)+ , (''Int8#, PrimShow { primShowBoxer = appE (conE 'I#) . appE (varE int8ToIntHashValName) , primShowPostfixMod = oneHashE , primShowConv = mkNarrowE intToInt8HashValName@@ -1284,8 +1334,8 @@ , primShowPostfixMod = twoHashE , primShowConv = mkNarrowE wordToWord16HashValName })-#endif-#if MIN_VERSION_base(4,16,0)+# endif+# if MIN_VERSION_base(4,16,0) , (''Int32#, PrimShow { primShowBoxer = appE (conE 'I#) . appE (varE 'int32ToInt#) , primShowPostfixMod = oneHashE@@ -1296,10 +1346,11 @@ , primShowPostfixMod = twoHashE , primShowConv = mkNarrowE 'wordToWord32# })+# endif #endif ] -#if MIN_VERSION_base(4,13,0)+#if MIN_VERSION_base(4,13,0) && !(MIN_VERSION_base(4,19,0)) mkNarrowE :: Name -> TextShowFun -> Q Exp -> Q Exp mkNarrowE narrowName tsFun e = foldr (`infixApp` [| (<>) |])@@ -1376,6 +1427,11 @@ oneHashE, twoHashE :: TextShowFun -> Q Exp oneHashE tsFun = varE (singletonName tsFun) `appE` charE '#' twoHashE tsFun = varE (fromStringName tsFun) `appE` stringE "##"++#if MIN_VERSION_base(4,19,0)+extendedLitE :: String -> TextShowFun -> Q Exp+extendedLitE suffix tsFun = varE (fromStringName tsFun) `appE` stringE ("#" ++ suffix)+#endif ------------------------------------------------------------------------------- -- Assorted utilities
tests/Derived/TypeSynonyms.hs view
@@ -18,6 +18,8 @@ -} module Derived.TypeSynonyms (TyCon(..), TyFamily(..)) where +import Control.Monad.Trans.Instances ()+ import Data.Orphans () import qualified Generics.Deriving.TH as Generics
tests/Spec/Data/TypeableSpec.hs view
@@ -52,6 +52,8 @@ describe "TypeRep" $ do describe "TypeRep Type" $ matchesTextShowSpec (Proxy :: Proxy (TypeRep Type))+ describe "TypeRep []" $+ matchesTextShowSpec (Proxy :: Proxy (TypeRep [])) describe "TypeRep [Int]" $ matchesTextShowSpec (Proxy :: Proxy (TypeRep [Int])) describe "TypeRep '[Int]" $@@ -62,6 +64,10 @@ matchesTextShowSpec (Proxy :: Proxy (TypeRep '(Int, Int))) describe "TypeRep (Int -> Int)" $ matchesTextShowSpec (Proxy :: Proxy (TypeRep (Int -> Int)))+ describe "TypeRep ((,) Int)" $+ matchesTextShowSpec (Proxy :: Proxy (TypeRep ((,) Int)))+ describe "TypeRep ('(,) Int)" $+ matchesTextShowSpec (Proxy :: Proxy (TypeRep ('(,) Int))) describe "TypeRep (Either Int)" $ matchesTextShowSpec (Proxy :: Proxy (TypeRep (Either Int))) #else
text-show.cabal view
@@ -1,20 +1,11 @@ name: text-show-version: 3.10.3+version: 3.10.4 synopsis: Efficient conversion of values into Text description: @text-show@ offers a replacement for the @Show@ typeclass intended for use with @Text@ instead of @String@s. This package was created in the spirit of @<http://hackage.haskell.org/package/bytestring-show bytestring-show>@. .- At the moment, @text-show@ provides instances for most data- types in the @<http://hackage.haskell.org/package/array array>@,- @<http://hackage.haskell.org/package/base base>@,- @<http://hackage.haskell.org/package/bytestring bytestring>@, and- @<http://hackage.haskell.org/package/text text>@ packages.- Therefore, much of the source code for @text-show@ consists of- borrowed code from those packages in order to ensure that the- behaviors of @Show@ and @TextShow@ coincide.- . For most uses, simply importing "TextShow" will suffice: .@@ -33,6 +24,24 @@ . Support for automatically deriving @TextShow@ instances can be found in the "TextShow.TH" and "TextShow.Generic" modules.+ .+ @text-show@ only provides instances for data types in the+ following packages:+ .+ * @<http://hackage.haskell.org/package/array array>@+ .+ * @<http://hackage.haskell.org/package/base base>@+ .+ * @<http://hackage.haskell.org/package/bytestring bytestring>@+ .+ * @<http://hackage.haskell.org/package/text text>@+ .+ This policy is in place to keep @text-show@'s dependencies+ reasonably light. If you need a @TextShow@ instance for a+ library that is not in this list, it may be covered by the+ @<http://hackage.haskell.org/package/text-show-instances text-show-instances>@+ library.+ homepage: https://github.com/RyanGlScott/text-show bug-reports: https://github.com/RyanGlScott/text-show/issues license: BSD3@@ -52,9 +61,9 @@ , GHC == 8.8.4 , GHC == 8.10.7 , GHC == 9.0.2- , GHC == 9.2.7- , GHC == 9.4.4- , GHC == 9.6.1+ , GHC == 9.2.8+ , GHC == 9.4.5+ , GHC == 9.6.2 extra-source-files: CHANGELOG.md, README.md, include/*.h cabal-version: >=1.10 @@ -167,24 +176,24 @@ build-depends: array >= 0.3 && < 0.6 , base-compat-batteries >= 0.11 && < 0.14 , bifunctors >= 5.1 && < 6- , bytestring >= 0.9 && < 0.12+ , bytestring >= 0.9 && < 0.13 , bytestring-builder , containers >= 0.1 && < 0.7 , generic-deriving >= 1.14.1 && < 2 , ghc-prim , text >= 0.11.1 && < 2.1- , th-abstraction >= 0.4 && < 0.6+ , th-abstraction >= 0.4 && < 0.7 , th-lift >= 0.7.6 && < 1 if flag(base-4-9)- build-depends: base >= 4.9 && < 4.19+ build-depends: base >= 4.9 && < 4.20 cpp-options: "-DNEW_FUNCTOR_CLASSES" else build-depends: base >= 4.7 && < 4.9 if flag(template-haskell-2-11)- build-depends: template-haskell >= 2.11 && < 2.21- , ghc-boot-th >= 8.0 && < 9.7+ build-depends: template-haskell >= 2.11 && < 2.22+ , ghc-boot-th >= 8.0 && < 9.9 else build-depends: template-haskell >= 2.9 && < 2.11 @@ -358,22 +367,22 @@ build-depends: array >= 0.3 && < 0.6 , base-compat-batteries >= 0.11 && < 0.14 , base-orphans >= 0.8.5 && < 0.10- , bytestring >= 0.9 && < 0.12+ , bytestring >= 0.9 && < 0.13 , bytestring-builder- , deriving-compat >= 0.6 && < 1+ , deriving-compat >= 0.6.5 && < 1 , generic-deriving >= 1.14.1 && < 2 , ghc-prim , hspec >= 2 && < 3 , QuickCheck >= 2.14.3 && < 2.15 , quickcheck-instances >= 0.3.28 && < 0.4- , template-haskell >= 2.9 && < 2.21+ , template-haskell >= 2.9 && < 2.22 , text >= 0.11.1 && < 2.1 , text-show , transformers-compat >= 0.5 && < 1 build-tool-depends: hspec-discover:hspec-discover if flag(base-4-9)- build-depends: base >= 4.9 && < 4.19+ build-depends: base >= 4.9 && < 4.20 cpp-options: "-DNEW_FUNCTOR_CLASSES" else build-depends: base >= 4.7 && < 4.9@@ -398,7 +407,7 @@ benchmark bench type: exitcode-stdio-1.0 main-is: Bench.hs- build-depends: base >= 4.5 && < 4.19+ build-depends: base >= 4.5 && < 4.20 , criterion >= 1.1.4 && < 2 , deepseq >= 1.3 && < 2 , ghc-prim