Wolfgang Jeltsch pushed to branch wip/jeltsch/text-read-uncovering at Glasgow Haskell Compiler / GHC

Commits:

9 changed files:

Changes:

  • libraries/base/src/Data/Data.hs
    ... ... @@ -99,3 +99,38 @@ module Data.Data (
    99 99
     
    
    100 100
     import GHC.Internal.Data.Data
    
    101 101
     import Data.Typeable
    
    102
    +
    
    103
    +import GHC.Real (toRational)
    
    104
    +import GHC.Float (Double)
    
    105
    +import Data.Eq ((==))
    
    106
    +import Data.Function ((.))
    
    107
    +import Data.Maybe (Maybe (Nothing, Just))
    
    108
    +import Data.List (filter)
    
    109
    +import Data.String (String)
    
    110
    +import Text.Read (Read, reads)
    
    111
    +
    
    112
    +-- | Lookup a constructor via a string
    
    113
    +readConstr :: DataType -> String -> Maybe Constr
    
    114
    +readConstr dt str =
    
    115
    +      case dataTypeRep dt of
    
    116
    +        AlgRep cons -> idx cons
    
    117
    +        IntRep      -> mkReadCon (\i -> (mkPrimCon dt str (IntConstr i)))
    
    118
    +        FloatRep    -> mkReadCon ffloat
    
    119
    +        CharRep     -> mkReadCon (\c -> (mkPrimCon dt str (CharConstr c)))
    
    120
    +        NoRep       -> Nothing
    
    121
    +  where
    
    122
    +
    
    123
    +    -- Read a value and build a constructor
    
    124
    +    mkReadCon :: Read t => (t -> Constr) -> Maybe Constr
    
    125
    +    mkReadCon f = case (reads str) of
    
    126
    +                    [(t,"")] -> Just (f t)
    
    127
    +                    _ -> Nothing
    
    128
    +
    
    129
    +    -- Traverse list of algebraic datatype constructors
    
    130
    +    idx :: [Constr] -> Maybe Constr
    
    131
    +    idx cons = case filter ((==) str . showConstr) cons of
    
    132
    +                [] -> Nothing
    
    133
    +                hd : _ -> Just hd
    
    134
    +
    
    135
    +    ffloat :: Double -> Constr
    
    136
    +    ffloat =  mkPrimCon dt str . FloatConstr . toRational

  • libraries/base/src/Data/Version.hs
    1 1
     {-# LANGUAGE Safe #-}
    
    2 2
     
    
    3
    +{-# LANGUAGE StandaloneDeriving #-}
    
    4
    +
    
    3 5
     -- |
    
    4 6
     -- Module      :  Data.Version
    
    5 7
     -- Copyright   :  (c) The University of Glasgow 2004
    
    ... ... @@ -33,3 +35,25 @@ module Data.Version (
    33 35
           ) where
    
    34 36
     
    
    35 37
     import GHC.Internal.Data.Version
    
    38
    +
    
    39
    +import Control.Applicative (pure, (*>))
    
    40
    +import Data.Functor (fmap)
    
    41
    +import Data.Char (isDigit, isAlphaNum)
    
    42
    +import Text.ParserCombinators.ReadP (ReadP, char, munch1, sepBy1, many)
    
    43
    +import Text.Read (Read, read)
    
    44
    +
    
    45
    +{-NOTE:
    
    46
    +    The following instance is technically an orphan, but practically it is not,
    
    47
    +    since ordinary users should not use @ghc-internal@ directly and thus get
    
    48
    +    'Version' only through this module.
    
    49
    +-}
    
    50
    +
    
    51
    +-- | @since base-2.01
    
    52
    +deriving instance Read Version
    
    53
    +
    
    54
    +-- | A parser for versions in the format produced by 'showVersion'.
    
    55
    +--
    
    56
    +parseVersion :: ReadP Version
    
    57
    +parseVersion = do branch <- sepBy1 (fmap read (munch1 isDigit)) (char '.')
    
    58
    +                  tags   <- many (char '-' *> munch1 isAlphaNum)
    
    59
    +                  pure Version{versionBranch=branch, versionTags=tags}

  • libraries/ghc-internal/src/GHC/Internal/Data/Data.hs
    ... ... @@ -61,6 +61,7 @@ module GHC.Internal.Data.Data (
    61 61
             mkIntType,
    
    62 62
             mkFloatType,
    
    63 63
             mkCharType,
    
    64
    +        mkPrimCon,
    
    64 65
             mkNoRepType,
    
    65 66
             -- ** Observers
    
    66 67
             dataTypeName,
    
    ... ... @@ -94,7 +95,6 @@ module GHC.Internal.Data.Data (
    94 95
             constrIndex,
    
    95 96
             -- ** From strings to constructors and vice versa: all data types
    
    96 97
             showConstr,
    
    97
    -        readConstr,
    
    98 98
     
    
    99 99
             -- * Convenience functions: take type constructors apart
    
    100 100
             tyconUQname,
    
    ... ... @@ -126,10 +126,8 @@ import GHC.Internal.Base (
    126 126
     import GHC.Internal.Err (errorWithoutStackTrace)
    
    127 127
     import GHC.Internal.List
    
    128 128
     import GHC.Internal.Num
    
    129
    -import GHC.Internal.Read
    
    130 129
     import GHC.Internal.Show
    
    131 130
     import GHC.Internal.Tuple (Solo (..))
    
    132
    -import GHC.Internal.Text.Read( reads )
    
    133 131
     import GHC.Internal.Types (
    
    134 132
         Bool(..), Char, Coercible, Float, Double, Type, type (~), type (~~),
    
    135 133
       )
    
    ... ... @@ -688,32 +686,6 @@ showConstr :: Constr -> String
    688 686
     showConstr = constring
    
    689 687
     
    
    690 688
     
    
    691
    --- | Lookup a constructor via a string
    
    692
    -readConstr :: DataType -> String -> Maybe Constr
    
    693
    -readConstr dt str =
    
    694
    -      case dataTypeRep dt of
    
    695
    -        AlgRep cons -> idx cons
    
    696
    -        IntRep      -> mkReadCon (\i -> (mkPrimCon dt str (IntConstr i)))
    
    697
    -        FloatRep    -> mkReadCon ffloat
    
    698
    -        CharRep     -> mkReadCon (\c -> (mkPrimCon dt str (CharConstr c)))
    
    699
    -        NoRep       -> Nothing
    
    700
    -  where
    
    701
    -
    
    702
    -    -- Read a value and build a constructor
    
    703
    -    mkReadCon :: Read t => (t -> Constr) -> Maybe Constr
    
    704
    -    mkReadCon f = case (reads str) of
    
    705
    -                    [(t,"")] -> Just (f t)
    
    706
    -                    _ -> Nothing
    
    707
    -
    
    708
    -    -- Traverse list of algebraic datatype constructors
    
    709
    -    idx :: [Constr] -> Maybe Constr
    
    710
    -    idx cons = case filter ((==) str . showConstr) cons of
    
    711
    -                [] -> Nothing
    
    712
    -                hd : _ -> Just hd
    
    713
    -
    
    714
    -    ffloat :: Double -> Constr
    
    715
    -    ffloat =  mkPrimCon dt str . FloatConstr . toRational
    
    716
    -
    
    717 689
     ------------------------------------------------------------------------------
    
    718 690
     --
    
    719 691
     --      Convenience functions: algebraic data types
    

  • libraries/ghc-internal/src/GHC/Internal/Data/Version.hs
    ... ... @@ -10,7 +10,7 @@
    10 10
     --
    
    11 11
     -- Maintainer  :  libraries@haskell.org
    
    12 12
     -- Stability   :  stable
    
    13
    --- Portability :  non-portable (local universal quantification in ReadP)
    
    13
    +-- Portability :  non-portable
    
    14 14
     --
    
    15 15
     -- A general library for representation and manipulation of versions.
    
    16 16
     --
    
    ... ... @@ -31,23 +31,18 @@ module GHC.Internal.Data.Version (
    31 31
             -- * The @Version@ type
    
    32 32
             Version(..),
    
    33 33
             -- * A concrete representation of @Version@
    
    34
    -        showVersion, parseVersion,
    
    34
    +        showVersion,
    
    35 35
             -- * Constructor function
    
    36 36
             makeVersion
    
    37 37
       ) where
    
    38 38
     
    
    39
    -import GHC.Internal.Classes          ( Eq(..), (&&) )
    
    40
    -import GHC.Internal.Data.Functor     ( Functor(..) )
    
    39
    +import GHC.Internal.Classes          ( Eq ((==)), (&&) )
    
    41 40
     import GHC.Internal.Int              ( Int )
    
    42 41
     import GHC.Internal.Data.List        ( map, sort, concat, concatMap, intersperse, (++) )
    
    43 42
     import GHC.Internal.Data.Ord
    
    44
    -import GHC.Internal.Base             ( Applicative(..), String )
    
    43
    +import GHC.Internal.Base             ( String )
    
    45 44
     import GHC.Internal.Generics
    
    46
    -import GHC.Internal.Unicode          ( isDigit, isAlphaNum )
    
    47
    -import GHC.Internal.Read
    
    48 45
     import GHC.Internal.Show
    
    49
    -import GHC.Internal.Text.ParserCombinators.ReadP
    
    50
    -import GHC.Internal.Text.Read        ( read )
    
    51 46
     
    
    52 47
     {- |
    
    53 48
     A 'Version' represents the version of a software entity.
    
    ... ... @@ -69,8 +64,8 @@ operations are the right thing for every 'Version'.
    69 64
     
    
    70 65
     Similarly, concrete representations of versions may differ.  One
    
    71 66
     possible concrete representation is provided (see 'showVersion' and
    
    72
    -'parseVersion'), but depending on the application a different concrete
    
    73
    -representation may be more appropriate.
    
    67
    +'Data.Version.parseVersion'), but depending on the application a
    
    68
    +different concrete representation may be more appropriate.
    
    74 69
     -}
    
    75 70
     data Version =
    
    76 71
       Version { versionBranch :: [Int],
    
    ... ... @@ -92,8 +87,7 @@ data Version =
    92 87
                     -- The interpretation of the list of tags is entirely dependent
    
    93 88
                     -- on the entity that this version applies to.
    
    94 89
             }
    
    95
    -  deriving ( Read    -- ^ @since base-2.01
    
    96
    -           , Show    -- ^ @since base-2.01
    
    90
    +  deriving ( Show    -- ^ @since base-2.01
    
    97 91
                , Generic -- ^ @since base-4.9.0.0
    
    98 92
                )
    
    99 93
     {-# DEPRECATED versionTags "See GHC ticket #2496" #-}
    
    ... ... @@ -121,13 +115,6 @@ showVersion (Version branch tags)
    121 115
       = concat (intersperse "." (map show branch)) ++
    
    122 116
          concatMap ('-':) tags
    
    123 117
     
    
    124
    --- | A parser for versions in the format produced by 'showVersion'.
    
    125
    ---
    
    126
    -parseVersion :: ReadP Version
    
    127
    -parseVersion = do branch <- sepBy1 (fmap read (munch1 isDigit)) (char '.')
    
    128
    -                  tags   <- many (char '-' *> munch1 isAlphaNum)
    
    129
    -                  pure Version{versionBranch=branch, versionTags=tags}
    
    130
    -
    
    131 118
     -- | Construct tag-less 'Version'
    
    132 119
     --
    
    133 120
     -- @since base-4.8.0.0
    

  • testsuite/tests/interface-stability/base-exports.stdout
    ... ... @@ -12496,7 +12496,7 @@ instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semi
    12496 12496
     instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semigroup.Min a) -- Defined in ‘Data.Semigroup’
    
    12497 12497
     instance forall m. GHC.Internal.Read.Read m => GHC.Internal.Read.Read (Data.Semigroup.WrappedMonoid m) -- Defined in ‘Data.Semigroup’
    
    12498 12498
     instance forall k (a :: k) (b :: k). Coercible a b => GHC.Internal.Read.Read (GHC.Internal.Data.Type.Coercion.Coercion a b) -- Defined in ‘GHC.Internal.Data.Type.Coercion’
    
    12499
    -instance GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘GHC.Internal.Data.Version’
    
    12499
    +instance [safe] GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘Data.Version’
    
    12500 12500
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.IntPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
    
    12501 12501
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.WordPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
    
    12502 12502
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.C.Types.CBool -- Defined in ‘GHC.Internal.Foreign.C.Types’
    

  • testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
    ... ... @@ -12525,7 +12525,7 @@ instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semi
    12525 12525
     instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semigroup.Min a) -- Defined in ‘Data.Semigroup’
    
    12526 12526
     instance forall m. GHC.Internal.Read.Read m => GHC.Internal.Read.Read (Data.Semigroup.WrappedMonoid m) -- Defined in ‘Data.Semigroup’
    
    12527 12527
     instance forall k (a :: k) (b :: k). Coercible a b => GHC.Internal.Read.Read (GHC.Internal.Data.Type.Coercion.Coercion a b) -- Defined in ‘GHC.Internal.Data.Type.Coercion’
    
    12528
    -instance GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘GHC.Internal.Data.Version’
    
    12528
    +instance [safe] GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘Data.Version’
    
    12529 12529
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.IntPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
    
    12530 12530
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.WordPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
    
    12531 12531
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.C.Types.CBool -- Defined in ‘GHC.Internal.Foreign.C.Types’
    

  • testsuite/tests/interface-stability/base-exports.stdout-mingw32
    ... ... @@ -12767,7 +12767,7 @@ instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semi
    12767 12767
     instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semigroup.Min a) -- Defined in ‘Data.Semigroup’
    
    12768 12768
     instance forall m. GHC.Internal.Read.Read m => GHC.Internal.Read.Read (Data.Semigroup.WrappedMonoid m) -- Defined in ‘Data.Semigroup’
    
    12769 12769
     instance forall k (a :: k) (b :: k). Coercible a b => GHC.Internal.Read.Read (GHC.Internal.Data.Type.Coercion.Coercion a b) -- Defined in ‘GHC.Internal.Data.Type.Coercion’
    
    12770
    -instance GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘GHC.Internal.Data.Version’
    
    12770
    +instance [safe] GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘Data.Version’
    
    12771 12771
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.IntPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
    
    12772 12772
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.WordPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
    
    12773 12773
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.C.Types.CBool -- Defined in ‘GHC.Internal.Foreign.C.Types’
    

  • testsuite/tests/interface-stability/base-exports.stdout-ws-32
    ... ... @@ -12496,7 +12496,7 @@ instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semi
    12496 12496
     instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semigroup.Min a) -- Defined in ‘Data.Semigroup’
    
    12497 12497
     instance forall m. GHC.Internal.Read.Read m => GHC.Internal.Read.Read (Data.Semigroup.WrappedMonoid m) -- Defined in ‘Data.Semigroup’
    
    12498 12498
     instance forall k (a :: k) (b :: k). Coercible a b => GHC.Internal.Read.Read (GHC.Internal.Data.Type.Coercion.Coercion a b) -- Defined in ‘GHC.Internal.Data.Type.Coercion’
    
    12499
    -instance GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘GHC.Internal.Data.Version’
    
    12499
    +instance [safe] GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘Data.Version’
    
    12500 12500
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.IntPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
    
    12501 12501
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.WordPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
    
    12502 12502
     instance GHC.Internal.Read.Read GHC.Internal.Foreign.C.Types.CBool -- Defined in ‘GHC.Internal.Foreign.C.Types’
    

  • testsuite/tests/plugins/plugins10.stdout
    ... ... @@ -2,6 +2,7 @@ parsePlugin()
    2 2
     interfacePlugin: Prelude
    
    3 3
     interfacePlugin: Language.Haskell.TH
    
    4 4
     interfacePlugin: Language.Haskell.TH.Quote
    
    5
    +interfacePlugin: Data.Version
    
    5 6
     interfacePlugin: System.IO
    
    6 7
     interfacePlugin: GHC.Internal.Base
    
    7 8
     interfacePlugin: GHC.Internal.Data.NonEmpty