Skip to content

Commit

Permalink
Removes a smattering of, apparent, dead code.
Browse files Browse the repository at this point in the history
Using weeder to find unused definitions. There are a great many more,
but this was an attempt to be relatively conservative in the removal.
  • Loading branch information
telser committed Jun 10, 2024
1 parent dda541c commit f009c2e
Show file tree
Hide file tree
Showing 51 changed files with 20 additions and 1,185 deletions.
1 change: 0 additions & 1 deletion Cabal-described/src/Distribution/Described.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module Distribution.Described (
reMunch1CS,
-- * Variables
reVar0,
reVar1,
-- * Special expressions
reDot,
reComma,
Expand Down
29 changes: 2 additions & 27 deletions Cabal-described/src/Distribution/Utils/CharSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module Distribution.Utils.CharSet (
-- * Conversions
fromList,
toList,
fromIntervalList,
toIntervalList,
-- * Special lists
alpha,
Expand All @@ -31,12 +30,12 @@ module Distribution.Utils.CharSet (
) where

import Data.Char (chr, isAlpha, isAlphaNum, isUpper, ord)
import Data.List (foldl', sortBy)
import Data.List (foldl')
import Data.Monoid (Monoid (..))
import Data.String (IsString (..))
import Distribution.Compat.Semigroup (Semigroup (..))
import Prelude
(Bool (..), Bounded (..), Char, Enum (..), Eq (..), Int, Maybe (..), Num (..), Ord (..), Show (..), String, concatMap, flip, fst, otherwise, showParen,
(Bool (..), Bounded (..), Char, Enum (..), Eq (..), Int, Maybe (..), Num (..), Ord (..), Show (..), String, concatMap, flip, otherwise, showParen,
showString, uncurry, ($), (.))

#if MIN_VERSION_containers(0,5,0)
Expand Down Expand Up @@ -84,12 +83,6 @@ null (CS cs) = IM.null cs

-- | Size of 'CharSet'
--
-- >>> size $ fromIntervalList [('a','f'), ('0','9')]
-- 16
--
-- >>> length $ toList $ fromIntervalList [('a','f'), ('0','9')]
-- 16
--
size :: CharSet -> Int
size (CS m) = foldl' (\ !acc (lo, hi) -> acc + (hi - lo) + 1) 0 (IM.toList m)

Expand Down Expand Up @@ -179,24 +172,6 @@ toList = concatMap (uncurry enumFromTo) . toIntervalList
toIntervalList :: CharSet -> [(Char, Char)]
toIntervalList (CS m) = [ (chr lo, chr hi) | (lo, hi) <- IM.toList m ]

-- | Convert from interval pairs.
--
-- >>> fromIntervalList []
-- ""
--
-- >>> fromIntervalList [('a','f'), ('0','9')]
-- "0123456789abcdef"
--
-- >>> fromIntervalList [('Z','A')]
-- ""
--
fromIntervalList :: [(Char,Char)] -> CharSet
fromIntervalList xs = normalise' $ sortBy (\a b -> compare (fst a) (fst b))
[ (ord lo, ord hi)
| (lo, hi) <- xs
, lo <= hi
]

-------------------------------------------------------------------------------
-- Normalisation
-------------------------------------------------------------------------------
Expand Down
54 changes: 0 additions & 54 deletions Cabal-syntax/src/Distribution/Compat/CharParsing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,10 @@
module Distribution.Compat.CharParsing
( -- * Combinators
oneOf -- :: CharParsing m => [Char] -> m Char
, noneOf -- :: CharParsing m => [Char] -> m Char
, spaces -- :: CharParsing m => m ()
, space -- :: CharParsing m => m Char
, newline -- :: CharParsing m => m Char
, tab -- :: CharParsing m => m Char
, upper -- :: CharParsing m => m Char
, lower -- :: CharParsing m => m Char
, alphaNum -- :: CharParsing m => m Char
, letter -- :: CharParsing m => m Char
, digit -- :: CharParsing m => m Char
, hexDigit -- :: CharParsing m => m Char
, octDigit -- :: CharParsing m => m Char
, satisfyRange -- :: CharParsing m => Char -> Char -> m Char

-- * Class
Expand Down Expand Up @@ -76,15 +68,6 @@ oneOf :: CharParsing m => [Char] -> m Char
oneOf xs = satisfy (\c -> c `elem` xs)
{-# INLINE oneOf #-}

-- | As the dual of 'oneOf', @noneOf cs@ succeeds if the current
-- character is /not/ in the supplied list of characters @cs@. Returns the
-- parsed character.
--
-- > consonant = noneOf "aeiou"
noneOf :: CharParsing m => [Char] -> m Char
noneOf xs = satisfy (\c -> c `notElem` xs)
{-# INLINE noneOf #-}

-- | Skips /zero/ or more white space characters. See also 'skipMany'.
spaces :: CharParsing m => m ()
spaces = skipMany space <?> "white space"
Expand All @@ -96,54 +79,17 @@ space :: CharParsing m => m Char
space = satisfy isSpace <?> "space"
{-# INLINE space #-}

-- | Parses a newline character (\'\\n\'). Returns a newline character.
newline :: CharParsing m => m Char
newline = char '\n' <?> "new-line"
{-# INLINE newline #-}

-- | Parses a tab character (\'\\t\'). Returns a tab character.
tab :: CharParsing m => m Char
tab = char '\t' <?> "tab"
{-# INLINE tab #-}

-- | Parses an upper case letter. Returns the parsed character.
upper :: CharParsing m => m Char
upper = satisfy isUpper <?> "uppercase letter"
{-# INLINE upper #-}

-- | Parses a lower case character. Returns the parsed character.
lower :: CharParsing m => m Char
lower = satisfy isLower <?> "lowercase letter"
{-# INLINE lower #-}

-- | Parses a letter or digit. Returns the parsed character.
alphaNum :: CharParsing m => m Char
alphaNum = satisfy isAlphaNum <?> "letter or digit"
{-# INLINE alphaNum #-}

-- | Parses a letter (an upper case or lower case character). Returns the
-- parsed character.
letter :: CharParsing m => m Char
letter = satisfy isAlpha <?> "letter"
{-# INLINE letter #-}

-- | Parses a digit. Returns the parsed character.
digit :: CharParsing m => m Char
digit = satisfy isDigit <?> "digit"
{-# INLINE digit #-}

-- | Parses a hexadecimal digit (a digit or a letter between \'a\' and
-- \'f\' or \'A\' and \'F\'). Returns the parsed character.
hexDigit :: CharParsing m => m Char
hexDigit = satisfy isHexDigit <?> "hexadecimal digit"
{-# INLINE hexDigit #-}

-- | Parses an octal digit (a character between \'0\' and \'7\'). Returns
-- the parsed character.
octDigit :: CharParsing m => m Char
octDigit = satisfy isOctDigit <?> "octal digit"
{-# INLINE octDigit #-}

satisfyRange :: CharParsing m => Char -> Char -> m Char
satisfyRange a z = satisfy (\c -> c >= a && c <= z)
{-# INLINE satisfyRange #-}
Expand Down
35 changes: 0 additions & 35 deletions Cabal-syntax/src/Distribution/Compat/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,14 @@ module Distribution.Compat.Graph

-- * Query
, null
, size
, member
, lookup

-- * Construction
, empty
, insert
, deleteKey
, deleteLookup

-- * Combine
, unionLeft
, unionRight

-- * Graph algorithms
Expand All @@ -72,7 +68,6 @@ module Distribution.Compat.Graph
, revNeighbors
, closure
, revClosure
, topSort
, revTopSort

-- * Conversions
Expand All @@ -93,7 +88,6 @@ module Distribution.Compat.Graph

-- * Node type
, Node (..)
, nodeValue
) where

import Distribution.Compat.Prelude hiding (empty, lookup, null, toList)
Expand Down Expand Up @@ -200,10 +194,6 @@ instance (IsNode a, IsNode b, Key a ~ Key b) => IsNode (Either a b) where
data Node k a = N a k [k]
deriving (Show, Eq)

-- | Get the value from a 'Node'.
nodeValue :: Node k a -> a
nodeValue (N a _ _) = a

instance Functor (Node k) where
fmap f (N a k ks) = N (f a) k ks

Expand All @@ -222,10 +212,6 @@ instance Ord k => IsNode (Node k a) where
null :: Graph a -> Bool
null = Map.null . toMap

-- | /O(1)/. The number of nodes in the graph.
size :: Graph a -> Int
size = Map.size . toMap

-- | /O(log V)/. Check if the key is in the graph.
member :: IsNode a => Key a -> Graph a -> Bool
member k g = Map.member k (toMap g)
Expand All @@ -244,17 +230,6 @@ empty = fromMap Map.empty
insert :: IsNode a => a -> Graph a -> Graph a
insert !n g = fromMap (Map.insert (nodeKey n) n (toMap g))

-- | /O(log V)/. Delete the node at a key from the graph.
deleteKey :: IsNode a => Key a -> Graph a -> Graph a
deleteKey k g = fromMap (Map.delete k (toMap g))

-- | /O(log V)/. Lookup and delete. This function returns the deleted
-- value if it existed.
deleteLookup :: IsNode a => Key a -> Graph a -> (Maybe a, Graph a)
deleteLookup k g =
let (r, m') = Map.updateLookupWithKey (\_ _ -> Nothing) k (toMap g)
in (r, fromMap m')

-- Combining

-- | /O(V + V')/. Right-biased union, preferring entries
Expand All @@ -263,11 +238,6 @@ deleteLookup k g =
unionRight :: IsNode a => Graph a -> Graph a -> Graph a
unionRight g g' = fromMap (Map.union (toMap g') (toMap g))

-- | /O(V + V')/. Left-biased union, preferring entries from
-- the first map when conflicts occur.
unionLeft :: IsNode a => Graph a -> Graph a -> Graph a
unionLeft = flip unionRight

-- Graph-like operations

-- | /Ω(V + E)/. Compute the strongly connected components of a graph.
Expand Down Expand Up @@ -336,11 +306,6 @@ flattenForest = concatMap Tree.flatten
decodeVertexForest :: Graph a -> Tree.Forest G.Vertex -> [a]
decodeVertexForest g = map (graphVertexToNode g) . flattenForest

-- | Topologically sort the nodes of a graph.
-- Requires amortized construction of graph.
topSort :: Graph a -> [a]
topSort g = map (graphVertexToNode g) $ G.topSort (graphForward g)

-- | Reverse topologically sort the nodes of a graph.
-- Requires amortized construction of graph.
revTopSort :: Graph a -> [a]
Expand Down
13 changes: 1 addition & 12 deletions Cabal-syntax/src/Distribution/Compat/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module Distribution.Compat.Lens

-- ** rank-1 types
, Getting
, AGetter
, ASetter
, ALens
, ALens'
Expand Down Expand Up @@ -55,7 +54,6 @@ module Distribution.Compat.Lens
, (%=)
, (^#)
, (#~)
, (#%~)

-- * Internal Comonads
, Pretext (..)
Expand Down Expand Up @@ -87,7 +85,6 @@ type Traversal' s a = Traversal s s a a

type Getting r s a = LensLike (Const r) s s a a

type AGetter s a = LensLike (Const a) s s a a -- this doesn't exist in 'lens'
type ASetter s t a b = LensLike Identity s t a b
type ALens s t a b = LensLike (Pretext a b) s t a b

Expand Down Expand Up @@ -172,7 +169,7 @@ infixl 1 &

infixl 8 ^., ^#
infixr 4 .~, %~, ?~
infixr 4 #~, #%~
infixr 4 #~
infixr 4 .=, %=, ?=

(^.) :: s -> Getting a s a -> a
Expand Down Expand Up @@ -210,18 +207,10 @@ s ^# l = aview l s
(#~) l b s = pretextPeek b (l pretextSell s)
{-# INLINE (#~) #-}

(#%~) :: ALens s t a b -> (a -> b) -> s -> t
(#%~) l f s = pretextPeeks f (l pretextSell s)
{-# INLINE (#%~) #-}

pretextSell :: a -> Pretext a b b
pretextSell a = Pretext (\afb -> afb a)
{-# INLINE pretextSell #-}

pretextPeeks :: (a -> b) -> Pretext a b t -> t
pretextPeeks f (Pretext m) = runIdentity $ m (\x -> Identity (f x))
{-# INLINE pretextPeeks #-}

pretextPeek :: b -> Pretext a b t -> t
pretextPeek b (Pretext m) = runIdentity $ m (\_ -> Identity b)
{-# INLINE pretextPeek #-}
Expand Down
26 changes: 1 addition & 25 deletions Cabal-syntax/src/Distribution/Compat/Newtype.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
{-# LANGUAGE FunctionalDependencies #-}

-- | Per Conor McBride, the 'Newtype' typeclass represents the packing and
-- unpacking of a newtype, and allows you to operate under that newtype with
-- functions such as 'ala'.
-- unpacking of a newtype.
module Distribution.Compat.Newtype
( Newtype (..)
, ala
, alaf
, pack'
, unpack'
) where
Expand Down Expand Up @@ -63,27 +60,6 @@ instance Newtype a (Sum a)
instance Newtype a (Product a)
instance Newtype (a -> a) (Endo a)

-- |
--
-- >>> ala Sum foldMap [1, 2, 3, 4 :: Int]
-- 10
--
-- /Note:/ the user supplied function for the newtype is /ignored/.
--
-- >>> ala (Sum . (+1)) foldMap [1, 2, 3, 4 :: Int]
-- 10
ala :: (Newtype o n, Newtype o' n') => (o -> n) -> ((o -> n) -> b -> n') -> (b -> o')
ala pa hof = alaf pa hof id

-- |
--
-- >>> alaf Sum foldMap length ["cabal", "install"]
-- 12
--
-- /Note:/ as with 'ala', the user supplied function for the newtype is /ignored/.
alaf :: (Newtype o n, Newtype o' n') => (o -> n) -> ((a -> n) -> b -> n') -> (a -> o) -> (b -> o')
alaf _ hof f = unpack . hof (pack . f)

-- | Variant of 'pack', which takes a phantom type.
pack' :: Newtype o n => (o -> n) -> o -> n
pack' _ = pack
Expand Down
Loading

0 comments on commit f009c2e

Please sign in to comment.