packages feed

rio 0.1.24.0 → 0.1.25.0

raw patch · 9 files changed

+53/−31 lines, 9 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- RIO.HashMap: adjust :: (Eq k, Hashable k) => (v -> v) -> k -> HashMap k v -> HashMap k v
+ RIO.HashMap: adjust :: Hashable k => (v -> v) -> k -> HashMap k v -> HashMap k v
- RIO.HashMap: alter :: (Eq k, Hashable k) => (Maybe v -> Maybe v) -> k -> HashMap k v -> HashMap k v
+ RIO.HashMap: alter :: Hashable k => (Maybe v -> Maybe v) -> k -> HashMap k v -> HashMap k v
- RIO.HashMap: delete :: (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
+ RIO.HashMap: delete :: Hashable k => k -> HashMap k v -> HashMap k v
- RIO.HashMap: difference :: (Eq k, Hashable k) => HashMap k v -> HashMap k w -> HashMap k v
+ RIO.HashMap: difference :: Hashable k => HashMap k v -> HashMap k w -> HashMap k v
- RIO.HashMap: differenceWith :: (Eq k, Hashable k) => (v -> w -> Maybe v) -> HashMap k v -> HashMap k w -> HashMap k v
+ RIO.HashMap: differenceWith :: Hashable k => (v -> w -> Maybe v) -> HashMap k v -> HashMap k w -> HashMap k v
- RIO.HashMap: fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMap k v
+ RIO.HashMap: fromList :: Hashable k => [(k, v)] -> HashMap k v
- RIO.HashMap: fromListWith :: (Eq k, Hashable k) => (v -> v -> v) -> [(k, v)] -> HashMap k v
+ RIO.HashMap: fromListWith :: Hashable k => (v -> v -> v) -> [(k, v)] -> HashMap k v
- RIO.HashMap: insert :: (Eq k, Hashable k) => k -> v -> HashMap k v -> HashMap k v
+ RIO.HashMap: insert :: Hashable k => k -> v -> HashMap k v -> HashMap k v
- RIO.HashMap: insertWith :: (Eq k, Hashable k) => (v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
+ RIO.HashMap: insertWith :: Hashable k => (v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
- RIO.HashMap: lookup :: (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
+ RIO.HashMap: lookup :: Hashable k => k -> HashMap k v -> Maybe v
- RIO.HashMap: lookupDefault :: (Eq k, Hashable k) => v -> k -> HashMap k v -> v
+ RIO.HashMap: lookupDefault :: Hashable k => v -> k -> HashMap k v -> v
- RIO.HashMap: member :: (Eq k, Hashable k) => k -> HashMap k a -> Bool
+ RIO.HashMap: member :: Hashable k => k -> HashMap k a -> Bool
- RIO.HashMap: update :: (Eq k, Hashable k) => (a -> Maybe a) -> k -> HashMap k a -> HashMap k a
+ RIO.HashMap: update :: Hashable k => (a -> Maybe a) -> k -> HashMap k a -> HashMap k a
- RIO.HashMap.Partial: (!) :: (Eq k, Hashable k, HasCallStack) => HashMap k v -> k -> v
+ RIO.HashMap.Partial: (!) :: (Hashable k, HasCallStack) => HashMap k v -> k -> v
- RIO.HashSet: delete :: (Eq a, Hashable a) => a -> HashSet a -> HashSet a
+ RIO.HashSet: delete :: Hashable a => a -> HashSet a -> HashSet a
- RIO.HashSet: difference :: (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
+ RIO.HashSet: difference :: Hashable a => HashSet a -> HashSet a -> HashSet a
- RIO.HashSet: fromList :: (Eq a, Hashable a) => [a] -> HashSet a
+ RIO.HashSet: fromList :: Hashable a => [a] -> HashSet a
- RIO.HashSet: insert :: (Eq a, Hashable a) => a -> HashSet a -> HashSet a
+ RIO.HashSet: insert :: Hashable a => a -> HashSet a -> HashSet a
- RIO.HashSet: map :: (Hashable b, Eq b) => (a -> b) -> HashSet a -> HashSet b
+ RIO.HashSet: map :: Hashable b => (a -> b) -> HashSet a -> HashSet b
- RIO.HashSet: member :: (Eq a, Hashable a) => a -> HashSet a -> Bool
+ RIO.HashSet: member :: Hashable a => a -> HashSet a -> Bool

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for rio
 
+## 0.1.25.0
+
+* Prevent warnings when compiling with newer GHC versions
+* work around GHC's [#26479](https://gitlab.haskell.org/ghc/ghc/-/issues/26479)
+
 ## 0.1.24.0
 
 * Fix a bug in the `Utf8Builder` instance of `Monoid`, introduced in `rio-0.1.23.0`
rio.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12
 --- This file has been generated from package.yaml by hpack version 0.38.2.+-- This file has been generated from package.yaml by hpack version 0.39.1. -- -- see: https://github.com/sol/hpack  name:           rio-version:        0.1.24.0+version:        0.1.25.0 synopsis:       A standard library for Haskell description:    See README and Haddocks at <https://www.stackage.org/package/rio> category:       Control@@ -120,6 +120,8 @@   else     build-depends:         unix+  if os(darwin)+    cpp-options: -DMACOS  test-suite spec   type: exitcode-stdio-1.0@@ -170,5 +172,7 @@   else     build-depends:         unix+  if os(darwin)+    cpp-options: -DMACOS   build-tool-depends:       hspec-discover:hspec-discover
src/RIO/ByteString.hs view
@@ -13,6 +13,7 @@ 
 import Data.ByteString hiding (head, last, tail, init, foldl1, foldl1', foldr1, foldr1', maximum, minimum, findSubstring, findSubstrings, packCString, packCStringLen, useAsCString, useAsCStringLen, getLine, getContents, putStr, putStrLn, interact, readFile, writeFile, appendFile, hGetLine, hGetContents, hGet, hGetSome, hGetNonBlocking, hPut, hPutNonBlocking, hPutStr, hPutStrLn, breakByte)
 import qualified Data.ByteString as B
+import qualified Data.ByteString.Char8 as B8
 import RIO
 import Foreign.C.String (CString, CStringLen)
 
@@ -34,7 +35,7 @@ 
 -- | Lifted 'B.getLine'
 getLine :: MonadIO m => m ByteString
-getLine = liftIO B.getLine
+getLine = liftIO B8.getLine
 
 -- | Lifted 'B.getContents'
 getContents :: MonadIO m => m ByteString
@@ -62,7 +63,7 @@ 
 -- | Lifted 'B.hGetLine'
 hGetLine :: MonadIO m => Handle -> m ByteString
-hGetLine = liftIO . B.hGetLine
+hGetLine = liftIO . B8.hGetLine
 
 -- | Lifted 'B.hGetContents'
 hGetContents :: MonadIO m => Handle -> m ByteString
src/RIO/List.hs view
@@ -254,7 +254,7 @@ 
 -- | @since 0.1.3.0
 headMaybe :: [a] -> Maybe a
-headMaybe = safeListCall Data.List.head
+headMaybe = fmap fst . Data.List.uncons
 
 -- | @since 0.1.3.0
 lastMaybe :: [a] -> Maybe a
@@ -262,7 +262,7 @@ 
 -- | @since 0.1.3.0
 tailMaybe :: [a] -> Maybe [a]
-tailMaybe = safeListCall Data.List.tail
+tailMaybe = fmap snd . Data.List.uncons
 
 -- | @since 0.1.3.0
 initMaybe :: [a] -> Maybe [a]
src/RIO/Prelude/Display.hs view
@@ -42,9 +42,6 @@   mempty = Utf8Builder mempty
   {-# INLINE mempty #-}
 
-  mappend = (Data.Semigroup.<>)
-  {-# INLINE mappend #-}
-
   -- Data.Foldable.fold cannot be used here because it results in a circularity:
   mconcat = foldr mappend mempty
   {-# INLINE mconcat #-}
src/RIO/Prelude/Extra.hs view
@@ -86,13 +86,6 @@ unlessM :: Monad m => m Bool -> m () -> m ()
 unlessM boolM action = boolM >>= (`unless` action)
 
-#if !MIN_VERSION_base(4, 11, 0)
-(<&>) :: Functor f => f a -> (a -> b) -> f b
-as <&> f = f <$> as
-
-infixl 1 <&>
-#endif
-
 
 -- | Helper function to force an action to run in 'IO'. Especially
 -- useful for overly general contexts, like hspec tests.
src/RIO/Prelude/Logger.hs view
@@ -144,7 +144,6 @@ -- @since 0.0.0.0
 instance Monoid LogFunc where
   mempty = mkLogFunc $ \_ _ _ _ -> return ()
-  mappend = (<>)
 
 -- | Create a 'LogFunc' from the given function.
 --
@@ -302,14 +301,17 @@ 
 canUseUtf8 :: MonadIO m => Handle -> m Bool
 canUseUtf8 h = liftIO $ do
-  isWritable <- hIsWritable h
-  unless isWritable $ ioError $ mkIOError illegalOperationErrorType
-                                          "canUseUtf8"
-                                          (Just h)
-                                          Nothing
   maybeEnc <- hGetEncoding h
   return $ fmap textEncodingName maybeEnc == Just "UTF-8"
 
+assertWritable :: MonadIO m => Handle -> m ()
+assertWritable h = liftIO $ do
+  isOpen <- hIsOpen h -- workaround for hIsWritable bug on duplex handles
+                      -- https://gitlab.haskell.org/ghc/ghc/-/issues/26479
+  isWritable <- hIsWritable h
+  unless (isOpen && isWritable) . ioError
+    $ mkIOError illegalOperationErrorType "assertWritable" (Just h) Nothing
+
 -- | Create a 'LogOptions' value which will store its data in
 -- memory. This is primarily intended for testing purposes. This will
 -- return both a 'LogOptions' value and an 'IORef' containing the
@@ -341,6 +343,7 @@ -- overridden using appropriate @set@ functions.
 -- Logging output is guaranteed to be non-interleaved only for a
 -- UTF-8 'Handle' in a multi-thread environment.
+-- If the handle is not writable, an exception is thrown immediately.
 --
 -- When Verbose Flag is @True@, the following happens:
 --
@@ -357,6 +360,7 @@   -> Bool -- ^ Verbose Flag
   -> m LogOptions
 logOptionsHandle handle' verbose = liftIO $ do
+  assertWritable handle' -- throw IOError now, if it would already throw later
   terminal <- hIsTerminalDevice handle'
   useUtf8 <- canUseUtf8 handle'
   unicode <- if useUtf8 then return True else getCanUseUnicode
@@ -933,7 +937,6 @@ -- @since 0.1.13.0
 instance Monoid (GLogFunc msg) where
   mempty = mkGLogFunc $ \_ _ -> return ()
-  mappend = (<>)
 
 -- | A vesion of 'contramapMaybeGLogFunc' which supports filering.
 --
src/RIO/Prelude/RIO.hs view
@@ -42,7 +42,6 @@   (<>) = liftA2 (<>)
 instance Monoid a => Monoid (RIO env a) where
   mempty = pure mempty
-  mappend = liftA2 mappend
 
 -- | Using the environment run in IO the action that requires that environment.
 --
test/RIO/FileSpec.hs view
@@ -1,8 +1,11 @@+{-# LANGUAGE CPP               #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE NoImplicitPrelude #-}
+
 module RIO.FileSpec where
 
 import Test.Hspec
+import System.Environment (lookupEnv)
 import System.FilePath ((</>))
 import UnliftIO.Temporary (withSystemTempDirectory)
 
@@ -43,10 +46,27 @@ 
   describe "withBinaryFileDurable" $ do
     context "happy path" $ do
-      it "works the same as withFile" $ do
-        withSystemTempDirectory "rio" $ \dir -> do
-          let fp = dir </> "with_file_durable"
-          SUT.withBinaryFileDurable fp WriteMode $ \h ->
-            BS.hPut h "Hello World"
-          contents <- BS.readFile fp
-          contents `shouldBe` "Hello World"
+      it "works the same as withFile" sameAsWithFiletest
+
+sameAsWithFiletest :: IO ()
+sameAsWithFiletest = do
+#if !MACOS
+  test
+#else
+  -- As of 2026-02-05, on GitHub macOS runners only, the file system appears to
+  -- reject durability-related open flags. So, we ignore the test if we
+  -- appear to be in that environment.
+  mGitHubActions <- lookupEnv "GITHUB_ACTIONS"
+  case mGitHubActions of
+    Just "true" -> pendingWith $
+      "On GitHub macOS runners, the file system appears to reject " <>
+      "durability-related open flags."
+    _ -> test
+#endif
+ where
+  test = withSystemTempDirectory "rio" $ \dir -> do
+    let fp = dir </> "with_file_durable"
+    SUT.withBinaryFileDurable fp WriteMode $ \h ->
+      BS.hPut h "Hello World"
+    contents <- BS.readFile fp
+    contents `shouldBe` "Hello World"