Skip to content

Commit 07ac087

Browse files
authored
Some orphans work (#1092)
Removed `-Wno-orphans` from some modules. Un-orphan some instances from `Ouroboros.Consensus.Util.Orphans` Still draft because I need an instance in IntersectMBO/ouroboros-network#4875
2 parents 98dbae0 + 03206e1 commit 07ac087

File tree

9 files changed

+45
-42
lines changed

9 files changed

+45
-42
lines changed

cabal.project

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@ import: ./asserts.cabal
3636
if(os(windows))
3737
constraints:
3838
bitvec -simd
39+
40+
source-repository-package
41+
type: git
42+
location: https://github.com/IntersectMBO/ouroboros-network
43+
tag: 431bb599940d2947b2cb99d3ae29b7f2c4cdd36d
44+
--sha256: 1a62hqddpnc0j5r7nl54q79nrxyw77dphpsgp68hxij210dkpvca
45+
subdir:
46+
ouroboros-network-api
47+
ouroboros-network-protocols
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Non-Breaking
2+
3+
- Un-orphan instances for `Condense` and `HeaderHash (Ticked l)`.

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Ledger/Basics.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{-# LANGUAGE FlexibleContexts #-}
55
{-# LANGUAGE TypeFamilies #-}
66
{-# LANGUAGE TypeOperators #-}
7-
{-# OPTIONS_GHC -Wno-orphans #-}
87

98
-- | Definition is 'IsLedger'
109
--
@@ -48,8 +47,6 @@ class GetTip l where
4847
-- Should be 'GenesisPoint' when no blocks have been applied yet
4948
getTip :: l -> Point l
5049

51-
type instance HeaderHash (Ticked l) = HeaderHash l
52-
5350
getTipHash :: GetTip l => l -> ChainHash l
5451
getTipHash = pointHash . getTip
5552

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Protocol/PBFT.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DeriveAnyClass #-}
23
{-# LANGUAGE DeriveGeneric #-}
34
{-# LANGUAGE DerivingVia #-}
@@ -14,7 +15,12 @@
1415
{-# LANGUAGE TypeFamilyDependencies #-}
1516
{-# LANGUAGE TypeOperators #-}
1617
{-# LANGUAGE UndecidableInstances #-}
17-
{-# OPTIONS_GHC -Wno-orphans #-}
18+
19+
#if __GLASGOW_HASKELL__ >= 908
20+
-- GHC is a bit pickier for data family instances, but trying to remove this
21+
-- one forces us to reorganize the Protocol.* modules. TODO eventually.
22+
{-# OPTIONS_GHC -Wno-orphans #-}
23+
#endif
1824

1925
module Ouroboros.Consensus.Protocol.PBFT (
2026
PBft

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Protocol/PBFT/Crypto.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
{-# LANGUAGE TypeOperators #-}
1212
{-# LANGUAGE UndecidableInstances #-}
1313

14-
{-# OPTIONS_GHC -Wno-orphans #-}
1514
module Ouroboros.Consensus.Protocol.PBFT.Crypto (
1615
PBftCrypto (..)
1716
, PBftMockCrypto

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/API.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
{-# LANGUAGE TypeFamilies #-}
1616
{-# LANGUAGE UndecidableInstances #-}
1717

18-
{-# OPTIONS_GHC -Wno-orphans #-}
1918
module Ouroboros.Consensus.Storage.ChainDB.API (
2019
-- * Main ChainDB API
2120
ChainDB (..)

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Ticked.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Ouroboros.Consensus.Ticked (Ticked (..)) where
1111
import Data.Kind (Type)
1212
import Data.SOP.BasicFunctors
1313
import NoThunks.Class (NoThunks)
14+
import Ouroboros.Consensus.Block.Abstract
1415

1516
{-------------------------------------------------------------------------------
1617
Ticked state
@@ -46,6 +47,8 @@ data family Ticked st :: Type
4647
data instance Ticked () = TickedTrivial
4748
deriving (Show)
4849

50+
type instance HeaderHash (Ticked l) = HeaderHash l
51+
4952
{-------------------------------------------------------------------------------
5053
Forwarding type class instances
5154
-------------------------------------------------------------------------------}

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Util/Condense.hs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ import Cardano.Crypto.KES (MockKES, NeverKES, SigKES, SignedKES (..),
2525
pattern SigSingleKES, pattern SigSumKES,
2626
pattern SignKeyMockKES, pattern VerKeyMockKES,
2727
pattern VerKeySingleKES, pattern VerKeySumKES)
28-
import Cardano.Slotting.Block (BlockNo (..))
29-
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..),
30-
WithOrigin (..))
28+
import Cardano.Slotting.Slot (EpochNo (..), WithOrigin (..))
3129
import Control.Monad.Class.MonadTime.SI (Time (..))
3230
import qualified Data.ByteString as BS.Strict
3331
import qualified Data.ByteString.Lazy as BS.Lazy
@@ -44,7 +42,10 @@ import Data.Word
4442
import Numeric.Natural
4543
import Ouroboros.Consensus.Util.HList (All, HList (..))
4644
import qualified Ouroboros.Consensus.Util.HList as HList
47-
import Ouroboros.Network.Block (ChainHash (..), HeaderHash, Tip (..))
45+
import Ouroboros.Network.AnchoredFragment (AnchoredFragment)
46+
import qualified Ouroboros.Network.AnchoredFragment as AF
47+
import Ouroboros.Network.Block
48+
import Ouroboros.Network.Mock.Chain hiding (length)
4849
import Text.Printf (printf)
4950

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

170171
{-------------------------------------------------------------------------------
171-
Orphans for ouroboros-network
172+
Instances for ouroboros-network
172173
-------------------------------------------------------------------------------}
173174

174175
instance Condense BlockNo where
@@ -193,8 +194,21 @@ instance Condense a => Condense (WithOrigin a) where
193194
condense Origin = "origin"
194195
condense (At a) = condense a
195196

197+
instance Condense (HeaderHash block) => Condense (Point block) where
198+
condense GenesisPoint = "Origin"
199+
condense (BlockPoint s h) = "(Point " <> condense s <> ", " <> condense h <> ")"
200+
201+
instance Condense block => Condense (Chain block) where
202+
condense Genesis = "Genesis"
203+
condense (cs :> b) = condense cs <> " :> " <> condense b
204+
205+
instance (Condense block, HasHeader block, Condense (HeaderHash block))
206+
=> Condense (AnchoredFragment block) where
207+
condense (AF.Empty pt) = "EmptyAnchor " <> condense (AF.anchorToPoint pt)
208+
condense (cs AF.:> b) = condense cs <> " :> " <> condense b
209+
196210
{-------------------------------------------------------------------------------
197-
Orphans for cardano-crypto-classes
211+
Instances for cardano-crypto-classes
198212
-------------------------------------------------------------------------------}
199213

200214
instance Condense (SigDSIGN v) => Condense (SignedDSIGN v a) where

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Util/Orphans.hs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,11 @@ import Data.SOP.BasicFunctors
2727
import NoThunks.Class (InspectHeap (..), InspectHeapNamed (..),
2828
NoThunks (..), OnlyCheckWhnfNamed (..), allNoThunks,
2929
noThunksInKeysAndValues)
30-
import Ouroboros.Consensus.Block.Abstract
31-
import Ouroboros.Consensus.Util.Condense
32-
import Ouroboros.Network.AnchoredFragment (AnchoredFragment)
33-
import qualified Ouroboros.Network.AnchoredFragment as AF
34-
import Ouroboros.Network.Mock.Chain (Chain (..))
3530
import Ouroboros.Network.Util.ShowProxy
3631
import System.FS.API (SomeHasFS)
3732
import System.FS.API.Types (FsPath, Handle)
3833
import System.FS.CRC (CRC (CRC))
3934

40-
{-------------------------------------------------------------------------------
41-
Condense
42-
-------------------------------------------------------------------------------}
43-
44-
instance Condense (HeaderHash block) => Condense (Point block) where
45-
condense GenesisPoint = "Origin"
46-
condense (BlockPoint s h) = "(Point " <> condense s <> ", " <> condense h <> ")"
47-
48-
instance Condense block => Condense (Chain block) where
49-
condense Genesis = "Genesis"
50-
condense (cs :> b) = condense cs <> " :> " <> condense b
51-
52-
instance (Condense block, HasHeader block, Condense (HeaderHash block))
53-
=> Condense (AnchoredFragment block) where
54-
condense (AF.Empty pt) = "EmptyAnchor " <> condense (AF.anchorToPoint pt)
55-
condense (cs AF.:> b) = condense cs <> " :> " <> condense b
56-
5735
{-------------------------------------------------------------------------------
5836
Serialise
5937
-------------------------------------------------------------------------------}
@@ -64,12 +42,6 @@ instance Serialise (VerKeyDSIGN MockDSIGN) where
6442
encode = encodeVerKeyDSIGN
6543
decode = decodeVerKeyDSIGN
6644

67-
{-------------------------------------------------------------------------------
68-
ShowProxy
69-
-------------------------------------------------------------------------------}
70-
71-
instance ShowProxy SlotNo where
72-
7345
{-------------------------------------------------------------------------------
7446
NoThunks
7547
-------------------------------------------------------------------------------}
@@ -105,9 +77,10 @@ instance NoThunks a => NoThunks (Sum a)
10577
fs-api
10678
-------------------------------------------------------------------------------}
10779

80+
deriving via InspectHeap FsPath instance NoThunks FsPath
81+
deriving newtype instance NoThunks CRC
10882
deriving via InspectHeapNamed "Handle" (Handle h)
10983
instance NoThunks (Handle h)
110-
deriving via InspectHeap FsPath instance NoThunks FsPath
11184
deriving via OnlyCheckWhnfNamed "SomeHasFS" (SomeHasFS m)
11285
instance NoThunks (SomeHasFS m)
113-
deriving newtype instance NoThunks CRC
86+

0 commit comments

Comments
 (0)