Skip to content

Commit

Permalink
Remove Proof from CertState pretty printer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucsanszky committed Feb 15, 2025
1 parent 0633416 commit dc553dd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ data CertStateF era where
unCertStateF :: CertStateF era -> CertState era
unCertStateF (CertStateF _ x) = x

instance PrettyA (CertStateF era) where
prettyA (CertStateF p x) = unReflect pcCertState p x
instance Reflect era => PrettyA (CertStateF era) where
prettyA (CertStateF _ x) = pcCertState x

instance Eq (CertStateF era) where
(CertStateF Shelley x) == (CertStateF Shelley y) = x == y
Expand Down Expand Up @@ -882,14 +882,14 @@ genProposedPPUpdates p = case p of
Babbage -> ProposedPPUpdatesF p . PP.ProposedPPUpdates <$> arbitrary
Conway -> ProposedPPUpdatesF p . PP.ProposedPPUpdates <$> arbitrary

genCertState :: Proof era -> Gen (CertStateF era)
genCertState p = case p of
Shelley -> CertStateF p <$> arbitrary
Allegra -> CertStateF p <$> arbitrary
Mary -> CertStateF p <$> arbitrary
Alonzo -> CertStateF p <$> arbitrary
Babbage -> CertStateF p <$> arbitrary
Conway -> CertStateF p <$> arbitrary
genCertState :: forall era. Reflect era => Gen (CertStateF era)
genCertState = case reify @era of
p@Shelley -> CertStateF p <$> arbitrary
p@Allegra -> CertStateF p <$> arbitrary
p@Mary -> CertStateF p <$> arbitrary
p@Alonzo -> CertStateF p <$> arbitrary
p@Babbage -> CertStateF p <$> arbitrary
p@Conway -> CertStateF p <$> arbitrary

genGovState :: Proof era -> Gen (GovState era)
genGovState p = case p of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ demoC mode = do
>>= (\subst -> monadTyped $ substToEnv subst emptyEnv)
)
certState <- monadTyped . runTarget env $ certStateT
when (mode == Interactive) $ putStrLn (show (pcCertState proof (unCertStateF certState)))
when (mode == Interactive) $ putStrLn (show (pcCertState (unCertStateF certState)))
modeRepl mode proof env ""

demoTestC :: TestTree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ data Rep era t where
PParamsR :: Era era => Proof era -> Rep era (PParamsF era)
FuturePParamsR :: Era era => Proof era -> Rep era (FuturePParams era)
PParamsUpdateR :: Era era => Proof era -> Rep era (PParamsUpdateF era)
CertStateR :: Era era => Proof era -> Rep era (CertStateF era)
CertStateR :: Reflect era => Rep era (CertStateF era)
--
DeltaCoinR :: Rep era DeltaCoin
GenDelegPairR :: Era era => Rep era GenDelegPair
Expand Down Expand Up @@ -613,7 +613,7 @@ synopsis (UTxOR p) (UTxO mp) = "UTxO( " ++ synopsis (MapR TxInR (TxOutR p)) (Map
synopsis (PParamsR _) (PParamsF p x) = show $ pcPParams p x
synopsis (FuturePParamsR p) x = show $ pcFuturePParams p x
synopsis (PParamsUpdateR _) _ = "PParamsUpdate ..."
synopsis (CertStateR _) (CertStateF p x) = show $ pcCertState p x
synopsis CertStateR (CertStateF _ x) = show $ pcCertState x
synopsis DeltaCoinR (DeltaCoin n) = show (hsep [ppString "▵₳", ppInteger n])
synopsis GenDelegPairR x = show (pcGenDelegPair x)
synopsis FutureGenDelegR x = show (pcFutureGenDeleg x)
Expand Down Expand Up @@ -773,7 +773,7 @@ genSizedRep _n (UTxOR p) = genUTxO p
genSizedRep _ (PParamsR p) = genPParams p
genSizedRep _ (FuturePParamsR p) = genFuturePParams p
genSizedRep _ (PParamsUpdateR p) = genPParamsUpdate p
genSizedRep _ (CertStateR p) = genCertState p
genSizedRep _ CertStateR = genCertState
genSizedRep _ DeltaCoinR = DeltaCoin <$> choose (-1000, 1000)
genSizedRep _ GenDelegPairR = arbitrary
genSizedRep _ FutureGenDelegR = arbitrary
Expand Down Expand Up @@ -1041,7 +1041,7 @@ shrinkRep (UTxOR _) _ = []
shrinkRep (PParamsR _) _ = []
shrinkRep (FuturePParamsR _) _ = []
shrinkRep (PParamsUpdateR _) _ = []
shrinkRep (CertStateR _) _ = []
shrinkRep CertStateR _ = []
shrinkRep CharR t = shrink t
shrinkRep DeltaCoinR t = shrink t
shrinkRep GenDelegPairR t = shrink t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3167,12 +3167,12 @@ instance PrettyA FutureGenDeleg where
instance PrettyA GenDelegPair where
prettyA = pcGenDelegPair

pcCertState :: Proof era -> CertState era -> PDoc
pcCertState p certState = case whichCertState p of
CertStateShelleyToBabbage -> pcShelleyCertState p certState
pcCertState :: forall era. Reflect era => CertState era -> PDoc
pcCertState certState = case whichCertState (reify @era) of
CertStateShelleyToBabbage -> pcShelleyCertState certState

pcShelleyCertState :: Proof era -> ShelleyCertState era -> PDoc
pcShelleyCertState _p (ShelleyCertState {..}) =
pcShelleyCertState :: ShelleyCertState era -> PDoc
pcShelleyCertState (ShelleyCertState {..}) =
ppRecord
"ShelleyCertState"
[ ("pstate", pcPState shelleyCertPState)
Expand Down Expand Up @@ -3374,12 +3374,12 @@ psUTxOState proof (UTxOState (UTxO u) dep fs gs (IStake m _) don) =
, ("donation", pcCoin don)
]

pcLedgerState :: Proof era -> LedgerState era -> PDoc
pcLedgerState :: Reflect era => Proof era -> LedgerState era -> PDoc
pcLedgerState proof ls =
ppRecord
"LedgerState"
[ ("utxoState", pcUTxOState proof (lsUTxOState ls))
, ("certState", pcCertState proof (lsCertState ls))
, ("certState", pcCertState (lsCertState ls))
]

instance Reflect era => PrettyA (LedgerState era) where
Expand All @@ -3391,7 +3391,7 @@ psLedgerState proof ls =
ppRecord
"LedgerState"
[ ("utxoState", psUTxOState proof (lsUTxOState ls))
, ("certState", pcCertState proof (lsCertState ls))
, ("certState", pcCertState (lsCertState ls))
]

pcPState :: PState era -> PDoc
Expand Down Expand Up @@ -3667,7 +3667,7 @@ instance Reflect era => PrettyA (CertEnv era) where
]

instance Reflect era => PrettyA (ShelleyCertState era) where
prettyA = pcShelleyCertState reify
prettyA = pcShelleyCertState

instance PrettyA x => PrettyA (Seq x) where
prettyA x = prettyA (toList x)
Expand Down
19 changes: 10 additions & 9 deletions libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Same.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ instance Reflect era => Same era (LedgerState era) where
++ certState
where
prettyShelley :: [(String, Maybe PDoc)]
prettyShelley = [("ShelleyCertState", (sameCertState proof (lsCertState x1) (lsCertState x2)))]
prettyShelley = [("ShelleyCertState", (sameCertState (lsCertState x1) (lsCertState x2)))]
prettyConway :: [(String, Maybe PDoc)]
prettyConway = [("ConwayCertState", (sameCertState proof (lsCertState x1) (lsCertState x2)))]
prettyConway = [("ConwayCertState", (sameCertState (lsCertState x1) (lsCertState x2)))]
certState = case reify @era of
Shelley -> prettyShelley
Mary -> prettyShelley
Expand Down Expand Up @@ -350,13 +350,14 @@ sameTransCtx Babbage x y = eqByShow x y
sameTransCtx Conway x y = eqByShow x y
{-# NOINLINE sameTransCtx #-}

sameCertState :: Proof era -> CertState era -> CertState era -> Maybe PDoc
sameCertState Shelley x y = eqByShow x y
sameCertState Allegra x y = eqByShow x y
sameCertState Mary x y = eqByShow x y
sameCertState Alonzo x y = eqByShow x y
sameCertState Babbage x y = eqByShow x y
sameCertState Conway x y = eqByShow x y
sameCertState :: forall era. Reflect era => CertState era -> CertState era -> Maybe PDoc
sameCertState x y = case reify @era of
Shelley -> eqByShow x y
Allegra -> eqByShow x y
Mary -> eqByShow x y
Alonzo -> eqByShow x y
Babbage -> eqByShow x y
Conway -> eqByShow x y
{-# NOINLINE sameCertState #-}

-- ==========================
Expand Down

0 comments on commit dc553dd

Please sign in to comment.