Skip to content

Commit

Permalink
Remove nothunks dependencies.
Browse files Browse the repository at this point in the history
The `nothunks` dependency is specific to the `ouroboros-consensus` use
case, so we remove the dependency here. `ouroboros-consensus` should
provide orphan instances where necessary.
  • Loading branch information
jorisdral committed Mar 21, 2023
1 parent 2a816ad commit 30b3c45
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 29 deletions.
1 change: 0 additions & 1 deletion fs-api/fs-api.cabal
Expand Up @@ -58,7 +58,6 @@ library
, directory >=1.3 && <1.4
, filepath >=1.4 && <1.5
, io-classes ^>=0.3
, nothunks >=0.1.2 && <0.2
, text >=1.2 && <1.3

if os(windows)
Expand Down
12 changes: 3 additions & 9 deletions fs-api/src/System/FS/API.hs
Expand Up @@ -32,7 +32,6 @@ import qualified Data.ByteString.Lazy as BL
import Data.Int (Int64)
import Data.Set (Set)
import Data.Word
import NoThunks.Class (NoThunks, OnlyCheckWhnfNamed (..))

import System.FS.API.Types

Expand Down Expand Up @@ -140,12 +139,11 @@ data HasFS m h = HasFS {
-- the new one.
--
-- NOTE: only works for files within the same folder.
, renameFile :: HasCallStack => FsPath -> FsPath -> m ()
, renameFile :: HasCallStack => FsPath -> FsPath -> m ()

-- | Useful for better error reporting
, mkFsErrorPath :: FsPath -> FsErrorPath
}
deriving NoThunks via OnlyCheckWhnfNamed "HasFS" (HasFS m h)

withFile :: (HasCallStack, MonadThrow m)
=> HasFS m h -> FsPath -> OpenMode -> (Handle h -> m a) -> m a
Expand Down Expand Up @@ -296,11 +294,7 @@ hPut hasFS g = hPutAll hasFS g . BS.toLazyByteString
SomeHasFS
-------------------------------------------------------------------------------}

-- | It is often inconvenient to have to parameterise over @h@. One often makes
-- it existential, losing the ability to use derive 'Generic' and 'NoThunks'.
-- This data type hides an existential @h@ parameter of a 'HasFS' and provides a
-- 'NoThunks' thunks instance.
-- | It is often inconvenient to have to parameterise over @h@. This data type
-- hides an existential @h@ parameter of a 'HasFS'.
data SomeHasFS m where
SomeHasFS :: Eq h => HasFS m h -> SomeHasFS m

deriving NoThunks via OnlyCheckWhnfNamed "SomeHasFS" (SomeHasFS m)
4 changes: 0 additions & 4 deletions fs-api/src/System/FS/API/Types.hs
Expand Up @@ -55,8 +55,6 @@ import Foreign.C.Error (Errno (..))
import qualified Foreign.C.Error as C
import GHC.Generics (Generic)
import qualified GHC.IO.Exception as GHC
import NoThunks.Class (InspectHeap (..), InspectHeapNamed (..),
NoThunks (..))
import System.FilePath
import System.IO (SeekMode (..))
import qualified System.IO.Error as IO
Expand Down Expand Up @@ -99,7 +97,6 @@ allowExisting openMode = case openMode of

newtype FsPath = UnsafeFsPath { fsPathToList :: [Strict.Text] }
deriving (Eq, Ord, Generic)
deriving NoThunks via InspectHeap FsPath

fsPathFromList :: [Strict.Text] -> FsPath
fsPathFromList = UnsafeFsPath . force
Expand Down Expand Up @@ -183,7 +180,6 @@ data Handle h = Handle {
, handlePath :: !FsPath
}
deriving (Generic)
deriving NoThunks via InspectHeapNamed "Handle" (Handle h)

instance Eq h => Eq (Handle h) where
(==) = (==) `on` handleRaw
Expand Down
4 changes: 1 addition & 3 deletions fs-api/src/System/FS/CRC.hs
Expand Up @@ -26,8 +26,6 @@ import Data.Word
import Foreign.Storable (Storable)
import GHC.Generics (Generic)
import GHC.Stack
import NoThunks.Class (NoThunks)

import System.FS.API
import System.FS.API.Types (AbsOffset (..))

Expand All @@ -36,7 +34,7 @@ import System.FS.API.Types (AbsOffset (..))
-------------------------------------------------------------------------------}

newtype CRC = CRC { getCRC :: Word32 }
deriving (Eq, Show, Generic, NoThunks, Storable)
deriving (Eq, Show, Generic, Storable)

initCRC :: CRC
initCRC = CRC $ Digest.crc32 ([] :: [Word8])
Expand Down
2 changes: 0 additions & 2 deletions fs-api/src/Util/CallStack.hs
Expand Up @@ -13,15 +13,13 @@ module Util.CallStack (

import GHC.Stack (CallStack, HasCallStack)
import qualified GHC.Stack as GHC
import NoThunks.Class (NoThunks)

{-------------------------------------------------------------------------------
Auxiliary: CallStack with different Show instance
-------------------------------------------------------------------------------}

-- | CallStack with 'Show' instance using 'prettyCallStack'
newtype PrettyCallStack = PrettyCallStack CallStack
deriving (NoThunks)

instance Show PrettyCallStack where
show (PrettyCallStack cs) = GHC.prettyCallStack cs
Expand Down
1 change: 0 additions & 1 deletion fs-sim/fs-sim.cabal
Expand Up @@ -43,7 +43,6 @@ library
, fs-api
, io-classes ^>=0.3
, mtl
, nothunks >=0.1.2 && <0.2
, QuickCheck
, strict-stm
, text >=1.2 && <1.3
Expand Down
3 changes: 1 addition & 2 deletions fs-sim/src/System/FS/Sim/FsTree.hs
Expand Up @@ -44,7 +44,6 @@ import qualified Data.Text as Text
import Data.Tree
import GHC.Generics (Generic)
import GHC.Stack
import NoThunks.Class (NoThunks)

import System.FS.API.Types

Expand All @@ -54,7 +53,7 @@ import System.FS.API.Types

-- | Simple in-memory representation of a file system
data FsTree a = File !a | Folder !(Folder a)
deriving (Show, Eq, Generic, Functor, NoThunks)
deriving (Show, Eq, Generic, Functor)

type Folder a = Map Text (FsTree a)

Expand Down
13 changes: 6 additions & 7 deletions fs-sim/src/System/FS/Sim/MockFS.hs
Expand Up @@ -71,7 +71,6 @@ import qualified Data.Set as S
import qualified Data.Text as Text
import Data.Word (Word64)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)

import System.FS.API.Types
import Util.CallStack
Expand All @@ -88,7 +87,7 @@ data MockFS = MockFS {
, mockHandles :: !(Map HandleMock HandleState)
, mockNextHandle :: !HandleMock
}
deriving (Generic, Show, NoThunks)
deriving (Generic, Show)

-- | We store the files as an 'FsTree' of the file contents
type Files = FsTree ByteString
Expand All @@ -98,7 +97,7 @@ type Files = FsTree ByteString
-- This is only meaningful when interpreted against a 'MockFS'.
newtype HandleMock = HandleMock Int
deriving stock (Show, Eq, Ord, Generic)
deriving newtype (Enum, NoThunks)
deriving newtype (Enum)

-- | Instantiate 'Handle' with the mock handle
type Handle' = Handle HandleMock
Expand All @@ -107,13 +106,13 @@ type Handle' = Handle HandleMock
data HandleState =
HandleOpen !OpenHandleState
| HandleClosed !ClosedHandleState
deriving (Show, Generic, NoThunks)
deriving (Show, Generic)

data OpenHandleState = OpenHandle {
openFilePath :: !FsPath
, openPtr :: !FilePtr
}
deriving (Show, Generic, NoThunks)
deriving (Show, Generic)

-- | Check whether the file handle is in write/append mode.
isWriteHandle :: OpenHandleState -> Bool
Expand All @@ -135,12 +134,12 @@ data FilePtr =
--
-- Offset is always the end of the file in append mode
| Append
deriving (Show, Generic, NoThunks)
deriving (Show, Generic)

data ClosedHandleState = ClosedHandle {
closedFilePath :: FsPath
}
deriving (Show, Generic, NoThunks)
deriving (Show, Generic)

-- | Monads in which we can simulate the file system
type CanSimFS m = (HasCallStack, MonadState MockFS m, MonadError FsError m)
Expand Down

0 comments on commit 30b3c45

Please sign in to comment.