Skip to content

Commit

Permalink
Some orphans work
Browse files Browse the repository at this point in the history
Removed `-Wno-orphans` from some modules.
Un-orphan some instances from `Ouroboros.Consensus.Util.Orphans`
  • Loading branch information
jasagredo committed May 8, 2024
1 parent 98dbae0 commit d4b636d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | Definition is 'IsLedger'
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Ouroboros.Consensus.Protocol.PBFT (
PBft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Consensus.Protocol.PBFT.Crypto (
PBftCrypto (..)
, PBftMockCrypto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Consensus.Storage.ChainDB.API (
-- * Main ChainDB API
ChainDB (..)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import Cardano.Crypto.KES (MockKES, NeverKES, SigKES, SignedKES (..),
pattern SigSingleKES, pattern SigSumKES,
pattern SignKeyMockKES, pattern VerKeyMockKES,
pattern VerKeySingleKES, pattern VerKeySumKES)
import Cardano.Slotting.Block (BlockNo (..))
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..),
WithOrigin (..))
import Cardano.Slotting.Slot (EpochNo (..), WithOrigin (..))
import Control.Monad.Class.MonadTime.SI (Time (..))
import qualified Data.ByteString as BS.Strict
import qualified Data.ByteString.Lazy as BS.Lazy
Expand All @@ -44,7 +42,10 @@ import Data.Word
import Numeric.Natural
import Ouroboros.Consensus.Util.HList (All, HList (..))
import qualified Ouroboros.Consensus.Util.HList as HList
import Ouroboros.Network.Block (ChainHash (..), HeaderHash, Tip (..))
import Ouroboros.Network.AnchoredFragment (AnchoredFragment)
import qualified Ouroboros.Network.AnchoredFragment as AF
import Ouroboros.Network.Block
import Ouroboros.Network.Mock.Chain hiding (length)
import Text.Printf (printf)

{-------------------------------------------------------------------------------
Expand Down Expand Up @@ -168,7 +169,7 @@ instance All Condense as => Condense (HList as) where
condense as = "(" ++ intercalate "," (HList.collapse (Proxy @Condense) condense as) ++ ")"

{-------------------------------------------------------------------------------
Orphans for ouroboros-network
Instances for ouroboros-network
-------------------------------------------------------------------------------}

instance Condense BlockNo where
Expand All @@ -193,8 +194,21 @@ instance Condense a => Condense (WithOrigin a) where
condense Origin = "origin"
condense (At a) = condense a

instance Condense (HeaderHash block) => Condense (Point block) where
condense GenesisPoint = "Origin"
condense (BlockPoint s h) = "(Point " <> condense s <> ", " <> condense h <> ")"

instance Condense block => Condense (Chain block) where
condense Genesis = "Genesis"
condense (cs :> b) = condense cs <> " :> " <> condense b

instance (Condense block, HasHeader block, Condense (HeaderHash block))
=> Condense (AnchoredFragment block) where
condense (AF.Empty pt) = "EmptyAnchor " <> condense (AF.anchorToPoint pt)
condense (cs AF.:> b) = condense cs <> " :> " <> condense b

{-------------------------------------------------------------------------------
Orphans for cardano-crypto-classes
Instances for cardano-crypto-classes
-------------------------------------------------------------------------------}

instance Condense (SigDSIGN v) => Condense (SignedDSIGN v a) where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,11 @@ import Data.SOP.BasicFunctors
import NoThunks.Class (InspectHeap (..), InspectHeapNamed (..),
NoThunks (..), OnlyCheckWhnfNamed (..), allNoThunks,
noThunksInKeysAndValues)
import Ouroboros.Consensus.Block.Abstract
import Ouroboros.Consensus.Util.Condense
import Ouroboros.Network.AnchoredFragment (AnchoredFragment)
import qualified Ouroboros.Network.AnchoredFragment as AF
import Ouroboros.Network.Mock.Chain (Chain (..))
import Ouroboros.Network.Util.ShowProxy
import System.FS.API (SomeHasFS)
import System.FS.API.Types (FsPath, Handle)
import System.FS.CRC (CRC (CRC))

{-------------------------------------------------------------------------------
Condense
-------------------------------------------------------------------------------}

instance Condense (HeaderHash block) => Condense (Point block) where
condense GenesisPoint = "Origin"
condense (BlockPoint s h) = "(Point " <> condense s <> ", " <> condense h <> ")"

instance Condense block => Condense (Chain block) where
condense Genesis = "Genesis"
condense (cs :> b) = condense cs <> " :> " <> condense b

instance (Condense block, HasHeader block, Condense (HeaderHash block))
=> Condense (AnchoredFragment block) where
condense (AF.Empty pt) = "EmptyAnchor " <> condense (AF.anchorToPoint pt)
condense (cs AF.:> b) = condense cs <> " :> " <> condense b

{-------------------------------------------------------------------------------
Serialise
-------------------------------------------------------------------------------}
Expand All @@ -64,12 +42,6 @@ instance Serialise (VerKeyDSIGN MockDSIGN) where
encode = encodeVerKeyDSIGN
decode = decodeVerKeyDSIGN

{-------------------------------------------------------------------------------
ShowProxy
-------------------------------------------------------------------------------}

instance ShowProxy SlotNo where

{-------------------------------------------------------------------------------
NoThunks
-------------------------------------------------------------------------------}
Expand Down Expand Up @@ -105,9 +77,10 @@ instance NoThunks a => NoThunks (Sum a)
fs-api
-------------------------------------------------------------------------------}

deriving via InspectHeap FsPath instance NoThunks FsPath
deriving newtype instance NoThunks CRC
deriving via InspectHeapNamed "Handle" (Handle h)
instance NoThunks (Handle h)
deriving via InspectHeap FsPath instance NoThunks FsPath
deriving via OnlyCheckWhnfNamed "SomeHasFS" (SomeHasFS m)
instance NoThunks (SomeHasFS m)
deriving newtype instance NoThunks CRC

0 comments on commit d4b636d

Please sign in to comment.