Skip to content

[Evaluation] Inline everything on the evaluation path #7000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion plutus-benchmark/common/PlutusBenchmark/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Data.ByteString qualified as BS
import Data.SatInt (fromSatInt)
import Flat qualified
import GHC.IO.Encoding (setLocaleEncoding)
import GHC.Magic (inline)
import System.Directory
import System.FilePath
import System.IO
Expand Down Expand Up @@ -124,7 +125,12 @@ evaluateCekLikeInProd evalCtx term = do
let (getRes, _, _) =
let -- The validation benchmarks were all created from PlutusV1 scripts
pv = LedgerApi.ledgerLanguageIntroducedIn LedgerApi.PlutusV1
in LedgerApi.evaluateTerm UPLC.restrictingEnormous pv LedgerApi.Quiet evalCtx term
in inline LedgerApi.evaluateTerm
(inline UPLC.restrictingEnormous)
pv
LedgerApi.Quiet
evalCtx
term
getRes

-- | Evaluate a term and either throw if evaluation fails or discard the result and return '()'.
Expand Down
1 change: 1 addition & 0 deletions plutus-benchmark/plutus-benchmark.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ library plutus-benchmark-common
, directory
, filepath
, flat ^>=0.6
, ghc-prim
, plutus-core ^>=1.43
, plutus-ledger-api ^>=1.43
, plutus-tx-test-util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ import PlutusCore.Evaluation.Machine.ExMemory
-- | No emitter.
noEmitter :: EmitterMode uni fun
noEmitter = EmitterMode $ \_ -> pure $ CekEmitterInfo (\_ -> pure ()) (pure mempty)
{-# INLINABLE noEmitter #-}

-- | Emits log only.
logEmitter :: EmitterMode uni fun
logEmitter = EmitterMode $ \_ -> do
logsRef <- newSTRef DList.empty
let emitter logs = CekM $ modifySTRef logsRef (`DList.append` logs)
pure $ CekEmitterInfo emitter (DList.toList <$> readSTRef logsRef)
{-# INLINABLE logEmitter #-}

-- A wrapper around encoding a record. `cassava` insists on including a trailing newline, which is
-- annoying since we're recording the output line-by-line.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ restricting (ExRestrictingBudget initB@(ExBudget cpuInit memInit)) = ExBudgetMod
pure $ initB `minusExBudget` r
final = RestrictingSt . ExRestrictingBudget <$> remaining
pure $ ExBudgetInfo spender final cumulative
{-# INLINE restricting #-}

-- | 'restricting' instantiated at 'largeBudget'.
restrictingLarge :: ThrowableBuiltins uni fun => ExBudgetMode RestrictingSt uni fun
Expand All @@ -167,3 +168,4 @@ restrictingLarge = restricting largeBudget
-- | 'restricting' instantiated at 'enormousBudget'.
restrictingEnormous :: ThrowableBuiltins uni fun => ExBudgetMode RestrictingSt uni fun
restrictingEnormous = restricting enormousBudget
{-# INLINE restrictingEnormous #-}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import Data.Text (Text)
import Data.Vector qualified as V
import Data.Word
import GHC.Generics
import GHC.Magic (inline)
import GHC.TypeLits
import Prettyprinter
import Universe
Expand Down Expand Up @@ -459,6 +460,7 @@ throwingDischarged
-> CekValue uni fun ann
-> CekM uni fun s x
throwingDischarged l t = throwingWithCause l t . Just . dischargeCekValue
{-# INLINE throwingDischarged #-}

instance ThrowableBuiltins uni fun =>
MonadError (CekEvaluationException NamedDeBruijn uni fun) (CekM uni fun s) where
Expand Down Expand Up @@ -946,7 +948,8 @@ runCekDeBruijn
runCekDeBruijn params mode emitMode term =
runCekM params mode emitMode $ do
unCekBudgetSpender ?cekBudgetSpender BStartup $ runIdentity $ cekStartupCost ?cekCosts
enterComputeCek NoFrame Env.empty term
inline enterComputeCek NoFrame Env.empty term
{-# INLINE runCekDeBruijn #-}

{- Note [Accumulators for terms]
At a couple of points in the CEK machine (notably building the arguments to a constructor value)
Expand Down
1 change: 1 addition & 0 deletions plutus-ledger-api/plutus-ledger-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ library
, cborg
, containers
, deepseq
, ghc-prim
, lens
, mtl
, nothunks
Expand Down
5 changes: 3 additions & 2 deletions plutus-ledger-api/src/PlutusLedgerApi/Common/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Control.Monad.Writer (MonadWriter (..), runWriter)
import Data.Set as Set
import Data.Text (Text)
import Data.Tuple
import GHC.Magic (inline)
import NoThunks.Class

-- | Errors that can be thrown when evaluating a Plutus script.
Expand Down Expand Up @@ -200,10 +201,10 @@ evaluateTerm
, [Text]
)
evaluateTerm budgetMode pv verbose ectx =
UPLC.runCekDeBruijn
inline UPLC.runCekDeBruijn
(toMachineParameters pv ectx)
budgetMode
(if verbose == Verbose then UPLC.logEmitter else UPLC.noEmitter)
(if verbose == Verbose then inline UPLC.logEmitter else inline UPLC.noEmitter)
-- Just replicating the old behavior, probably doesn't matter.
{-# INLINE evaluateTerm #-}

Expand Down
Loading