Skip to content

Commit

Permalink
CAD-2907 ouroboros-consensus-shelley: prevent GHC floating the stub c…
Browse files Browse the repository at this point in the history
…losure
  • Loading branch information
deepfire committed May 28, 2021
1 parent 41666f4 commit 2b6721c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ library
, containers >=0.5 && <0.7
, deepseq
, data-default-class
, ghc-prim
, mtl >=2.2 && <2.3
, nothunks
, serialise >=0.2 && <0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
Expand Down Expand Up @@ -41,6 +42,9 @@ module Ouroboros.Consensus.Shelley.Ledger.Ledger (
, encodeShelleyLedgerState
) where

import GHC.Prim
import GHC.Types (Int(I#))

import Codec.CBOR.Decoding (Decoder)
import qualified Codec.CBOR.Decoding as CBOR
import Codec.CBOR.Encoding (Encoding)
Expand Down Expand Up @@ -290,17 +294,27 @@ instance ShelleyBasedEra era
-- - 'updateChainDepState': executes the @PRTCL@ transition
-- + 'applyLedgerBlock': executes the @BBODY@ transition
--
applyLedgerBlock =
seq (stubComputation stubComputationArg) $
applyHelper $
applyLedgerBlock x y z =
seq (stubComputation (stubComputationArg
+ I# (reallyUnsafePtrEquality# x x)
+ I# (reallyUnsafePtrEquality# y y)
+ I# (reallyUnsafePtrEquality# z z))) $
applyHelper
-- Apply the BBODY transition using the ticked state
withExcept BBodyError ..: SL.applyBlock

reapplyLedgerBlock = runIdentity ...:
seq (stubComputation stubComputationArg) $
applyHelper $
-- Reapply the BBODY transition using the ticked state
Identity ..: SL.reapplyBlock
(withExcept BBodyError ..: SL.applyBlock)
x y z

reapplyLedgerBlock x y z =
((seq (stubComputation (stubComputationArg
+ I# (reallyUnsafePtrEquality# x x)
+ I# (reallyUnsafePtrEquality# y y)
+ I# (reallyUnsafePtrEquality# z z)))
.
runIdentity) ...:
applyHelper)
-- Reapply the BBODY transition using the ticked state
(Identity ..: SL.reapplyBlock)
x y z

applyHelper ::
(ShelleyBasedEra era, Monad m)
Expand Down

0 comments on commit 2b6721c

Please sign in to comment.