11{-# LANGUAGE PatternGuards #-}
22{-# LANGUAGE PatternSynonyms #-}
33{-# LANGUAGE RecordWildCards #-}
4+ {-# LANGUAGE MultiWayIf #-}
45
56import Control.Applicative
67import Control.Monad
@@ -227,10 +228,10 @@ extractHeader mod = extract
227228
228229-- | A crude classifier looking for lines containing options
229230
230- data Status = Deprecated | Unsafe | Safe
231- deriving (Eq )
231+ data Safety = Unsafe | Safe deriving ( Eq )
232+ data Status = Deprecated | Active deriving (Eq )
232233
233- classify :: FilePath -> [String ] -> [String ] -> Exc Status
234+ classify :: FilePath -> [String ] -> [String ] -> Exc ( Safety , Status )
234235classify fp hd ls
235236 -- We start with sanity checks
236237 | isUnsafe && safe = throwError $ fp ++ contradiction " unsafe" " safe"
@@ -239,11 +240,12 @@ classify fp hd ls
239240 | isWithK && not withK = throwError $ fp ++ missingWithK
240241 | not (isWithK || cubicalC) = throwError $ fp ++ uncategorized " as relying on K" " cubical-compatible"
241242 -- And then perform the actual classification
242- | deprecated = pure $ Deprecated
243- | isUnsafe = pure $ Unsafe
244- | safe = pure $ Safe
245- -- We know that @not (isUnsafe || safe)@, all cases are covered
246- | otherwise = error " IMPOSSIBLE"
243+ | otherwise = do
244+ let safety = if | safe -> Safe
245+ | isUnsafe -> Unsafe
246+ | otherwise -> error " IMPOSSIBLE"
247+ let status = if deprecated then Deprecated else Active
248+ pure (safety, status)
247249
248250 where
249251
@@ -280,18 +282,20 @@ classify fp hd ls
280282data LibraryFile = LibraryFile
281283 { filepath :: FilePath -- ^ FilePath of the source file
282284 , header :: [String ] -- ^ All lines in the headers are already prefixed with \"-- \".
283- , status :: Status -- ^ Safety options used by the module
285+ , safety :: Safety
286+ , status :: Status -- ^ Deprecation status options used by the module
284287 }
285288
286289analyse :: FilePath -> IO LibraryFile
287290analyse fp = do
288291 ls <- lines <$> readFileUTF8 fp
289292 hd <- runExc $ extractHeader fp ls
290- cl <- runExc $ classify fp hd ls
293+ (sf, st) <- runExc $ classify fp hd ls
291294 return $ LibraryFile
292- { filepath = fp
293- , header = hd
294- , status = cl
295+ { filepath = fp
296+ , header = hd
297+ , safety = sf
298+ , status = st
295299 }
296300
297301checkFilePaths :: String -> [FilePath ] -> IO ()
@@ -356,7 +360,7 @@ main = do
356360 unlines [ header
357361 , " {-# OPTIONS --safe --guardedness #-}\n "
358362 , mkModule safeOutputFile
359- , format $ filter ((Unsafe /= ) . status ) libraryfiles
363+ , format $ filter ((Unsafe /= ) . safety ) libraryfiles
360364 ]
361365
362366-- | Usage info.
0 commit comments