diff --git a/Cabal-syntax/src/Distribution/Utils/ShortText.hs b/Cabal-syntax/src/Distribution/Utils/ShortText.hs index f5725fcb7ba..cc172cb1af1 100644 --- a/Cabal-syntax/src/Distribution/Utils/ShortText.hs +++ b/Cabal-syntax/src/Distribution/Utils/ShortText.hs @@ -1,8 +1,5 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveDataTypeable #-} -{-# LANGUAGE DeriveGeneric #-} - --- | Compact representation of short 'Strings' +-- | This is a legacy compatibility layer, +-- new developments can use "Data.Text" directly. -- -- This module is designed to be import qualified -- @@ -25,81 +22,36 @@ module Distribution.Utils.ShortText import Distribution.Compat.Prelude hiding (length, null) import Prelude () -import Distribution.Utils.Structured (Structured (..), nominalStructure) - import qualified Data.ByteString as BS -import qualified Data.List as List import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.Text.Encoding.Error as T -import qualified Data.ByteString.Short as BS.Short - -- | Construct 'ShortText' from 'String' toShortText :: String -> ShortText +toShortText = T.pack -- | Convert 'ShortText' to 'String' fromShortText :: ShortText -> String +fromShortText = T.unpack -- | Convert from UTF-8 encoded strict 'ByteString'. -- -- @since 3.2.0.0 unsafeFromUTF8BS :: BS.ByteString -> ShortText +unsafeFromUTF8BS = T.decodeUtf8With T.lenientDecode -- | Text whether 'ShortText' is empty. -- -- @since 3.2.0.0 null :: ShortText -> Bool +null = T.null --- | Compact representation of short 'Strings' --- --- The data is stored internally as UTF8 in an --- 'BS.Short.ShortByteString'. --- --- Note: This type is for internal uses (such as e.g. 'PackageName') --- and shall not be exposed in Cabal's API --- --- @since 2.0.0.2 -newtype ShortText = ST {unST :: BS.Short.ShortByteString} - deriving (Eq, Ord, Generic, Data) - -instance Binary ShortText where - put = put . unST - get = fmap ST get - -toShortText = ST . BS.Short.toShort . T.encodeUtf8 . T.pack - -fromShortText = T.unpack . T.decodeUtf8With T.lenientDecode . BS.Short.fromShort . unST - -unsafeFromUTF8BS = ST . BS.Short.toShort +-- | @since 2.0.0.2 +type ShortText = T.Text -null = BS.Short.null . unST - -instance Structured ShortText where structure = nominalStructure - -instance NFData ShortText where - rnf = rnf . unST - -instance Show ShortText where - show = show . fromShortText - -instance Read ShortText where - readsPrec p = map (first toShortText) . readsPrec p - -instance Semigroup ShortText where - ST a <> ST b = ST (mappend a b) - -instance Monoid ShortText where - mempty = ST mempty - mappend = (<>) - -instance IsString ShortText where - fromString = toShortText - --- | /O(n)/. Length in characters. /Slow/ as converts to string. +-- | /O(n)/. Length in characters. -- -- @since 3.2.0.0 length :: ShortText -> Int -length = List.length . fromShortText - --- Note: avoid using it, we use it @cabal check@ implementation, where it's ok. +length = T.length diff --git a/Cabal-tests/tests/NoThunks.hs b/Cabal-tests/tests/NoThunks.hs index 323597eea82..b9bd1ada88c 100644 --- a/Cabal-tests/tests/NoThunks.hs +++ b/Cabal-tests/tests/NoThunks.hs @@ -26,7 +26,6 @@ import Distribution.Parsec.Source import Distribution.SPDX (License, LicenseExceptionId, LicenseExpression, LicenseId, LicenseRef, SimpleLicenseExpression) import Distribution.System (Arch, OS) import Distribution.Utils.Path (SymbolicPathX) -import Distribution.Utils.ShortText (ShortText) import Distribution.Version (Version, VersionRange) import Language.Haskell.Extension (Extension, KnownExtension, Language) import NoThunks.Class (NoThunks (..), OnlyCheckWhnf (..), noThunksInValues) @@ -118,8 +117,6 @@ instance NoThunks UnqualComponentName instance NoThunks Version instance NoThunks VersionRange -instance NoThunks ShortText where - instance NoThunks a => NoThunks (PerCompilerFlavor a) instance (Typeable allowAbs, Typeable from, Typeable to) diff --git a/Cabal-tests/tests/ParserTests/ipi/issue-2276-ghc-9885.expr b/Cabal-tests/tests/ParserTests/ipi/issue-2276-ghc-9885.expr index d5da47695e5..435c7b7b0c2 100644 --- a/Cabal-tests/tests/ParserTests/ipi/issue-2276-ghc-9885.expr +++ b/Cabal-tests/tests/ParserTests/ipi/issue-2276-ghc-9885.expr @@ -27,7 +27,7 @@ InstalledPackageInfo { synopsis = "Concrete functor and monad transformers", description = - concat + T.concat [ "A portable library of functor and monad transformers, inspired by\n", "the paper \\\"Functional Programming with Overloading and Higher-Order\n", diff --git a/Cabal-tests/tests/ParserTests/ipi/transformers.expr b/Cabal-tests/tests/ParserTests/ipi/transformers.expr index bcb40470a87..5c6ce79ae8b 100644 --- a/Cabal-tests/tests/ParserTests/ipi/transformers.expr +++ b/Cabal-tests/tests/ParserTests/ipi/transformers.expr @@ -27,7 +27,7 @@ InstalledPackageInfo { synopsis = "Concrete functor and monad transformers", description = - concat + T.concat [ "A portable library of functor and monad transformers, inspired by\n", "the paper \\\"Functional Programming with Overloading and Higher-Order\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/generics-sop.expr b/Cabal-tests/tests/ParserTests/regressions/generics-sop.expr index 7b7997d78e9..28b8e3cd3de 100644 --- a/Cabal-tests/tests/ParserTests/regressions/generics-sop.expr +++ b/Cabal-tests/tests/ParserTests/regressions/generics-sop.expr @@ -61,7 +61,7 @@ GenericPackageDescription { synopsis = "Generic Programming using True Sums of Products", description = - concat + T.concat [ "A library to support the definition of generic functions.\n", "Datatypes are viewed in a uniform, structured way:\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/indentation.expr b/Cabal-tests/tests/ParserTests/regressions/indentation.expr index 4e52f7ffa7e..11c915f6fe3 100644 --- a/Cabal-tests/tests/ParserTests/regressions/indentation.expr +++ b/Cabal-tests/tests/ParserTests/regressions/indentation.expr @@ -18,7 +18,7 @@ GenericPackageDescription { bugReports = "", sourceRepos = [], synopsis = "", - description = concat + description = T.concat [ "* foo\n", "\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/indentation2.expr b/Cabal-tests/tests/ParserTests/regressions/indentation2.expr index 28bc91409bd..72779fbf47d 100644 --- a/Cabal-tests/tests/ParserTests/regressions/indentation2.expr +++ b/Cabal-tests/tests/ParserTests/regressions/indentation2.expr @@ -18,7 +18,7 @@ GenericPackageDescription { bugReports = "", sourceRepos = [], synopsis = "", - description = concat + description = T.concat [ "foo\n", " indent2\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/indentation3.expr b/Cabal-tests/tests/ParserTests/regressions/indentation3.expr index d6cd560152e..36dc406c227 100644 --- a/Cabal-tests/tests/ParserTests/regressions/indentation3.expr +++ b/Cabal-tests/tests/ParserTests/regressions/indentation3.expr @@ -18,7 +18,7 @@ GenericPackageDescription { bugReports = "", sourceRepos = [], synopsis = "", - description = concat + description = T.concat [ "indent0\n", "\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-774.expr b/Cabal-tests/tests/ParserTests/regressions/issue-774.expr index 84baff7b936..ac84fa29c20 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-774.expr +++ b/Cabal-tests/tests/ParserTests/regressions/issue-774.expr @@ -18,7 +18,7 @@ GenericPackageDescription { sourceRepos = [], synopsis = "Package description parser interprets curly braces in the description field", - description = concat + description = T.concat [ "Here is some C code:\n", "\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/jaeger-flamegraph.expr b/Cabal-tests/tests/ParserTests/regressions/jaeger-flamegraph.expr index 96095055228..c036c2c4737 100644 --- a/Cabal-tests/tests/ParserTests/regressions/jaeger-flamegraph.expr +++ b/Cabal-tests/tests/ParserTests/regressions/jaeger-flamegraph.expr @@ -45,7 +45,7 @@ GenericPackageDescription { synopsis = "Generate flamegraphs from Jaeger .json dumps.", description = - concat + T.concat [ "This is a small tool to convert JSON dumps obtained from a Jaeger\n", "server () into a format consumable\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/libpq1.expr b/Cabal-tests/tests/ParserTests/regressions/libpq1.expr index ca27062bbbf..1211515687a 100644 --- a/Cabal-tests/tests/ParserTests/regressions/libpq1.expr +++ b/Cabal-tests/tests/ParserTests/regressions/libpq1.expr @@ -10,7 +10,7 @@ GenericPackageDescription { licenseRaw = Right BSD3, licenseFiles = [ SymbolicPath "LICENSE"], - copyright = concat + copyright = T.concat [ "(c) 2010 Grant Monroe\n", "(c) 2011 Leon P Smith"], @@ -67,7 +67,7 @@ GenericPackageDescription { sourceRepos = [], synopsis = "low-level binding to libpq", - description = concat + description = T.concat [ "This is a binding to libpq: the C application\n", "programmer's interface to PostgreSQL. libpq is a\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/libpq2.expr b/Cabal-tests/tests/ParserTests/regressions/libpq2.expr index 22622665664..968d07ea46b 100644 --- a/Cabal-tests/tests/ParserTests/regressions/libpq2.expr +++ b/Cabal-tests/tests/ParserTests/regressions/libpq2.expr @@ -14,7 +14,7 @@ GenericPackageDescription { Nothing)), licenseFiles = [ SymbolicPath "LICENSE"], - copyright = concat + copyright = T.concat [ "(c) 2010 Grant Monroe\n", "(c) 2011 Leon P Smith"], @@ -71,7 +71,7 @@ GenericPackageDescription { sourceRepos = [], synopsis = "low-level binding to libpq", - description = concat + description = T.concat [ "This is a binding to libpq: the C application\n", "programmer's interface to PostgreSQL. libpq is a\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/shake.expr b/Cabal-tests/tests/ParserTests/regressions/shake.expr index 1ba7e9a569f..089b924d0ee 100644 --- a/Cabal-tests/tests/ParserTests/regressions/shake.expr +++ b/Cabal-tests/tests/ParserTests/regressions/shake.expr @@ -56,7 +56,7 @@ GenericPackageDescription { synopsis = "Build system library, like Make, but more accurate dependencies.", description = - concat + T.concat [ "Shake is a Haskell library for writing build systems - designed as a\n", "replacement for @make@. See \"Development.Shake\" for an introduction,\n", diff --git a/Cabal-tests/tests/ParserTests/regressions/th-lift-instances.expr b/Cabal-tests/tests/ParserTests/regressions/th-lift-instances.expr index 4c9d8cc8467..a8768faed2c 100644 --- a/Cabal-tests/tests/ParserTests/regressions/th-lift-instances.expr +++ b/Cabal-tests/tests/ParserTests/regressions/th-lift-instances.expr @@ -37,7 +37,7 @@ GenericPackageDescription { synopsis = "Lift instances for template-haskell for common data types.", description = - concat + T.concat [ "Most data types in haskell platform do not have Lift instances. This package provides orphan instances\n", "for containers, text, bytestring and vector."], diff --git a/Cabal-tests/tests/ParserTests/regressions/wl-pprint-indef.expr b/Cabal-tests/tests/ParserTests/regressions/wl-pprint-indef.expr index f80e366dd84..9f87883d471 100644 --- a/Cabal-tests/tests/ParserTests/regressions/wl-pprint-indef.expr +++ b/Cabal-tests/tests/ParserTests/regressions/wl-pprint-indef.expr @@ -32,7 +32,7 @@ GenericPackageDescription { synopsis = "The Wadler/Leijen Pretty Printer", description = - concat + T.concat [ "This is a pretty printing library based on Wadler's paper \"A Prettier\n", "Printer\". See the haddocks for full info. This version allows the\n", diff --git a/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs b/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs index 93ec21c5b9f..079d522275a 100644 --- a/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs +++ b/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs @@ -29,8 +29,8 @@ md5Check proxy md5Int = structureHash proxy @?= md5FromInteger md5Int md5CheckGenericPackageDescription :: Proxy GenericPackageDescription -> Assertion md5CheckGenericPackageDescription proxy = md5Check proxy - 0x9f021aa01a9db87b4270029dc14c5966 + 0xaa065de51286b8f80733ffff51a44a20 md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion md5CheckLocalBuildInfo proxy = md5Check proxy - 0x78979713e08179ab070d6ab10cd5ef6c + 0xff2e1755aa2473b9d10c1236ef3ec80e diff --git a/Cabal-tree-diff/src/Data/TreeDiff/Instances/Cabal.hs b/Cabal-tree-diff/src/Data/TreeDiff/Instances/Cabal.hs index f8eaad4bf88..dd3dfaa028f 100644 --- a/Cabal-tree-diff/src/Data/TreeDiff/Instances/Cabal.hs +++ b/Cabal-tree-diff/src/Data/TreeDiff/Instances/Cabal.hs @@ -30,7 +30,6 @@ import Distribution.Types.PackageVersionConstraint import Distribution.Types.UnitId (DefUnitId, UnitId) import Distribution.Utils.NubList (NubList) import Distribution.Utils.Path (SymbolicPathX) -import Distribution.Utils.ShortText (ShortText, fromShortText) import Distribution.Verbosity import Distribution.Verbosity.Internal @@ -154,5 +153,3 @@ instance ToExpr UnqualComponentName instance ToExpr VerbosityFlags instance ToExpr VerbosityFlag instance ToExpr VerbosityLevel - -instance ToExpr ShortText where toExpr = toExpr . fromShortText diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs index ab056c820c9..df18f0ce0c6 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -Wno-orphans #-} diff --git a/cabal.release.project b/cabal.release.project index 8fd3d83a188..c10dd8803d0 100644 --- a/cabal.release.project +++ b/cabal.release.project @@ -3,7 +3,7 @@ import: project-cabal/pkgs/cabal.config import: project-cabal/pkgs/install.config import: project-cabal/pkgs/tests.config -index-state: hackage.haskell.org 2025-06-27T20:43:14Z +index-state: hackage.haskell.org 2026-05-22T20:43:14Z -- never include this or its TH dependency in a release! package cabal-install diff --git a/changelog.d/pr-11846.md b/changelog.d/pr-11846.md new file mode 100644 index 00000000000..0239ad9b788 --- /dev/null +++ b/changelog.d/pr-11846.md @@ -0,0 +1,10 @@ +--- +synopsis: Make ShortText a type synonym of Text +packages: [Cabal-syntax] +prs: 11846 +--- +The data type `Distribution.Utils.ShortText` is now just a type synonym for `Data.Text.Text`. +The constructor was not exported, so the change should not be noticeable by users +unless they used to define instances for `ShortText`, in which case +they might need to enable `{-# LANGUAGE TypeSynonymInstances #-}` or perhaps +drop their instances entirely, if they duplicate instances for `Text`.