Skip to content

Commit 2e2d20c

Browse files
authored
Merge pull request #5001 from IntersectMBO/aniketd/remove-heapwords
Remove heapwords from core and shelley
2 parents 855f74e + 9e504c3 commit 2e2d20c

File tree

9 files changed

+16
-42
lines changed

9 files changed

+16
-42
lines changed

eras/shelley/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.17.0.0
44

5+
* Remove `HeapWords` instances for: #5001
6+
- `ShelleyTxOut`
57
* Move `Annotator` instances, `txSeqDecoder` and `mapTraverseableDecoderA` to `testlib`
68
* Deprecate `witsFromTxWitnesses`
79
* Expose access to `ShelleyTxRaw`, `ShelleyTxAuxDataRaw`, `ShelleyTxBodyRaw`, `ShelleyTxWitsRaw`, `MkMultiSig`

eras/shelley/impl/cardano-ledger-shelley.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ library
116116
data-default,
117117
deepseq,
118118
groups,
119-
heapwords,
120119
mempack,
121120
microlens,
122121
mtl,

eras/shelley/impl/src/Cardano/Ledger/Shelley/TxOut.hs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ module Cardano.Ledger.Shelley.TxOut (
2424
valueEitherShelleyTxOutL,
2525
) where
2626

27-
import qualified Cardano.Crypto.Hash as HS
28-
import Cardano.HeapWords (HeapWords (..))
2927
import Cardano.Ledger.Address (Addr (..), CompactAddr, compactAddr, decompactAddr)
3028
import Cardano.Ledger.Binary (
3129
DecCBOR (..),
@@ -48,11 +46,8 @@ import Cardano.Ledger.Shelley.PParams ()
4846
import Cardano.Ledger.Val (Val)
4947
import Control.DeepSeq (NFData (rnf))
5048
import Data.Aeson (KeyValue, ToJSON (..), object, pairs, (.=))
51-
import qualified Data.ByteString.Short as SBS (ShortByteString, pack)
5249
import Data.Maybe (fromMaybe)
5350
import Data.MemPack
54-
import Data.Proxy (Proxy (..))
55-
import Data.Word (Word8)
5651
import GHC.Stack (HasCallStack)
5752
import Lens.Micro
5853
import NoThunks.Class (InspectHeapNamed (..), NoThunks (..))
@@ -121,11 +116,6 @@ valueEitherShelleyTxOutL =
121116
)
122117
{-# INLINE valueEitherShelleyTxOutL #-}
123118

124-
-- assume Shelley+ type address : payment addr, staking addr (same length as payment), plus 1 word overhead
125-
instance (Era era, HeapWords (CompactForm (Value era))) => HeapWords (ShelleyTxOut era) where
126-
heapWords (TxOutCompact _ vl) =
127-
3 + heapWords packedADDRHASH + heapWords vl
128-
129119
instance (Era era, Val (Value era)) => Show (ShelleyTxOut era) where
130120
show = show . viewCompactTxOut -- FIXME: showing TxOut as a tuple is just sad
131121

@@ -196,12 +186,3 @@ toTxOutPair (ShelleyTxOut !addr !amount) =
196186
[ "address" .= addr
197187
, "amount" .= amount
198188
]
199-
200-
-- a ShortByteString of the same length as the ADDRHASH
201-
-- used to calculate heapWords
202-
packedADDRHASH :: SBS.ShortByteString
203-
packedADDRHASH =
204-
SBS.pack $
205-
replicate
206-
(fromIntegral (1 + 2 * HS.sizeHash (Proxy :: Proxy ADDRHASH)))
207-
(1 :: Word8)

libs/cardano-ledger-core/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## 1.18.0.0
44

5+
* Remove `HeapWords` instances for: #5001
6+
- `Coin`
7+
- `DeltaCoin`
8+
- `CompactFormCoin`
9+
- `CompactFormDeltaCoin`
10+
- `SafeHash`
11+
- `StrictMaybe DataHash`
12+
- `TxId`
13+
- `TxIn`
514
* Add `addCompactCoin` to `Cardano.Ledger.Coin` and deprecate `Cardano.Ledger.UMap.addCompact`
615
in its favor
716
* Move `sumCompactCoin` to `Cardano.Ledger.Coin`

libs/cardano-ledger-core/cardano-ledger-core.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ library
118118
data-default >=0.8,
119119
deepseq,
120120
groups,
121-
heapwords,
122121
iproute,
123122
measures,
124123
mempack,

libs/cardano-ledger-core/src/Cardano/Ledger/Coin.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ module Cardano.Ledger.Coin (
3535
)
3636
where
3737

38-
import Cardano.HeapWords (HeapWords)
3938
import Cardano.Ledger.BaseTypes (
4039
HasZero (..),
4140
Inject (..),
@@ -83,15 +82,15 @@ newtype Coin = Coin {unCoin :: Integer}
8382
)
8483
deriving (Show) via Quiet Coin
8584
deriving (Semigroup, Monoid, Group, Abelian) via Sum Integer
86-
deriving newtype (PartialOrd, ToCBOR, EncCBOR, HeapWords)
85+
deriving newtype (PartialOrd, ToCBOR, EncCBOR)
8786

8887
instance FromCBOR Coin where
8988
fromCBOR = Coin . toInteger <$> Plain.decodeWord64
9089

9190
instance DecCBOR Coin
9291

9392
newtype DeltaCoin = DeltaCoin Integer
94-
deriving (Eq, Ord, Generic, Enum, NoThunks, HeapWords)
93+
deriving (Eq, Ord, Generic, Enum, NoThunks)
9594
deriving (Show) via Quiet DeltaCoin
9695
deriving (Semigroup, Monoid, Group, Abelian) via Sum Integer
9796
deriving newtype (PartialOrd, NFData, ToCBOR, DecCBOR, EncCBOR, ToJSON, FromJSON)
@@ -124,7 +123,7 @@ rationalToCoinViaCeiling = Coin . ceiling
124123

125124
instance Compactible Coin where
126125
newtype CompactForm Coin = CompactCoin {unCompactCoin :: Word64}
127-
deriving (Eq, Show, NoThunks, NFData, HeapWords, Prim, Ord, ToCBOR, ToJSON, FromJSON)
126+
deriving (Eq, Show, NoThunks, NFData, Prim, Ord, ToCBOR, ToJSON, FromJSON)
128127
deriving (Semigroup, Monoid, Group, Abelian) via Sum Word64
129128

130129
toCompact (Coin c) = CompactCoin <$> integerToWord64 c
@@ -145,7 +144,7 @@ instance MemPack (CompactForm Coin) where
145144

146145
instance Compactible DeltaCoin where
147146
newtype CompactForm DeltaCoin = CompactDeltaCoin Word64
148-
deriving (Eq, Show, NoThunks, NFData, HeapWords, ToJSON, Prim)
147+
deriving (Eq, Show, NoThunks, NFData, ToJSON, Prim)
149148

150149
toCompact (DeltaCoin dc) = CompactDeltaCoin <$> integerToWord64 dc
151150
fromCompact (CompactDeltaCoin cdc) = DeltaCoin (unCoin (word64ToCoin cdc))

libs/cardano-ledger-core/src/Cardano/Ledger/Hashes.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ where
8282
import qualified Cardano.Crypto.DSIGN as DSIGN
8383
import qualified Cardano.Crypto.Hash as Hash
8484
import qualified Cardano.Crypto.VRF as VRF
85-
import Cardano.HeapWords (HeapWords (..))
8685
import Cardano.Ledger.Binary (
8786
DecCBOR (..),
8887
EncCBOR (..),
@@ -332,7 +331,6 @@ newtype SafeHash i = SafeHash (Hash.Hash HASH i)
332331
, NoThunks
333332
, NFData
334333
, SafeToHash
335-
, HeapWords
336334
, ToCBOR
337335
, FromCBOR
338336
, EncCBOR

libs/cardano-ledger-core/src/Cardano/Ledger/Plutus/Data.hs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
{-# LANGUAGE TypeFamilies #-}
1717
{-# LANGUAGE UndecidableInstances #-}
1818
{-# LANGUAGE ViewPatterns #-}
19-
-- This is needed for the `HeapWords (StrictMaybe (DataHash c))` instance
20-
{-# OPTIONS_GHC -fno-warn-orphans #-}
2119

2220
module Cardano.Ledger.Plutus.Data (
2321
PlutusData (..),
@@ -39,7 +37,6 @@ module Cardano.Ledger.Plutus.Data (
3937
)
4038
where
4139

42-
import Cardano.HeapWords (HeapWords (..), heapWords0, heapWords1)
4340
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
4441
import Cardano.Ledger.Binary (
4542
DecCBOR (..),
@@ -189,10 +186,6 @@ dataHashSize :: StrictMaybe DataHash -> Integer
189186
dataHashSize SNothing = 0
190187
dataHashSize (SJust _) = 10
191188

192-
instance HeapWords (StrictMaybe DataHash) where
193-
heapWords SNothing = heapWords0
194-
heapWords (SJust a) = heapWords1 a
195-
196189
-- ============================================================================
197190
-- Datum
198191

libs/cardano-ledger-core/src/Cardano/Ledger/TxIn.hs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ module Cardano.Ledger.TxIn (
2424
where
2525

2626
import Cardano.Crypto.Hash.Class (hashToTextAsHex)
27-
import Cardano.HeapWords (HeapWords (..))
28-
import qualified Cardano.HeapWords as HW
2927
import Cardano.Ledger.BaseTypes (TxIx (..), mkTxIxPartial)
3028
import Cardano.Ledger.Binary (
3129
DecCBOR (..),
@@ -61,11 +59,7 @@ import NoThunks.Class (NoThunks (..))
6159
-- | A unique ID of a transaction, which is computable from the transaction.
6260
newtype TxId = TxId {unTxId :: SafeHash EraIndependentTxBody}
6361
deriving (Show, Eq, Ord, Generic)
64-
deriving newtype (NoThunks, ToJSON, FromJSON, HeapWords, EncCBOR, DecCBOR, NFData, MemPack)
65-
66-
instance HeapWords TxIn where
67-
heapWords (TxIn txId _) =
68-
2 + HW.heapWords txId + 1 {- txIx -}
62+
deriving newtype (NoThunks, ToJSON, FromJSON, EncCBOR, DecCBOR, NFData, MemPack)
6963

7064
instance ToJSON TxIn where
7165
toJSON = toJSON . txInToText

0 commit comments

Comments
 (0)