Skip to content

Commit

Permalink
PLT-4265: Use a primarray for the step counter
Browse files Browse the repository at this point in the history
This is very nearly as fast as the word array version, although it is
very sensitive to exactly how it is used. Crucially, it can accommodate
more counters!
  • Loading branch information
michaelpj committed Mar 17, 2023
1 parent e8f1296 commit 924ba78
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 570 deletions.
1 change: 0 additions & 1 deletion cabal.project
Expand Up @@ -30,7 +30,6 @@ packages: doc/read-the-docs-site
plutus-tx
plutus-tx-plugin
prettyprinter-configurable
word-array
stubs/plutus-ghc-stub

-- We never, ever, want this.
Expand Down
4 changes: 1 addition & 3 deletions doc/read-the-docs-site/RELEASE.adoc
Expand Up @@ -18,14 +18,12 @@ The following packages are versioned and released:
* The main library `plutus-tx-plugin:plutus-tx-plugin`
- `prettyprinter-configurable`
* The main library `prettyprinter-configurable:prettyprinter-configurable`
- `word-array`
* The main library `word-array:word-array`

== Version Scheme

All above packages are versioned and released in sync.
That is, whenever one package releases version X, so do all other packages.
Since `prettyprinter-configurable` and `word-array` change infrequently, we only release version X if they have been changed since the previous release.
Since `prettyprinter-configurable` changes infrequently, we only release version X if they have been changed since the previous release.

We follow https://pvp.haskell.org/[the PVP version scheme] for the packages, where version numbers have a `major.major.minor.patch` pattern with the following semantics:

Expand Down
1 change: 0 additions & 1 deletion nix/cells/plutus/library/make-plutus-project.nix
Expand Up @@ -183,7 +183,6 @@ let
# upstream fix, there's nothing we can do about it other than
# disabling -Werror on it.
# prettyprinter-configurable.ghcOptions = [ "-Werror" ];
word-array.ghcOptions = [ "-Werror" ];
};
})

Expand Down
2 changes: 1 addition & 1 deletion plutus-core/executables/debugger/Event.hs
Expand Up @@ -109,7 +109,7 @@ handleDebuggerEvent _ (B.AppEvent (UpdateClientEvent budgetData cekState)) = do
EditorReturnValue
Nothing
mempty
Returning _ _ v ->
Returning _ v ->
dsReturnValueEditor .~
BE.editorText
EditorReturnValue
Expand Down
3 changes: 3 additions & 0 deletions plutus-core/executables/debugger/Main.hs
Expand Up @@ -30,6 +30,7 @@ import UntypedPlutusCore.Core.Zip
import UntypedPlutusCore.Evaluation.Machine.Cek
import UntypedPlutusCore.Evaluation.Machine.Cek.Debug.Driver qualified as D
import UntypedPlutusCore.Evaluation.Machine.Cek.Debug.Internal
import UntypedPlutusCore.Evaluation.Machine.Cek.StepCounter (newCounter)
import UntypedPlutusCore.Parser qualified as UPLC

import Draw
Expand Down Expand Up @@ -211,6 +212,7 @@ driverThread driverMailbox brickMailbox prog mbudget = do

exBudgetInfo@(ExBudgetInfo spender _ _) <- stToIO initExBudgetInfo

ctr <- newCounter 8
let ?cekRuntime = defaultRuntime
?cekEmitter = const $ pure () -- TODO: implement emitter
?cekBudgetSpender = spender
Expand All @@ -219,6 +221,7 @@ driverThread driverMailbox brickMailbox prog mbudget = do
-- get *live* accounting/budgeting that is correct/up-to-date.
-- One way to achieve this is by setting slippage to 0 (1 would also work).
?cekSlippage = 0
?cekStepCounter = ctr
in D.iterM (handle exBudgetInfo) $ D.runDriver ndterm

where
Expand Down
4 changes: 4 additions & 0 deletions plutus-core/executables/uplc/Main.hs
Expand Up @@ -29,6 +29,7 @@ import PlutusPrelude
import UntypedPlutusCore qualified as UPLC
import UntypedPlutusCore.DeBruijn
import UntypedPlutusCore.Evaluation.Machine.Cek qualified as Cek
import UntypedPlutusCore.Evaluation.Machine.Cek.StepCounter (newCounter)

import Control.DeepSeq (rnf)
import Control.Monad.Except
Expand Down Expand Up @@ -265,11 +266,14 @@ runDbg (DbgOptions inp ifmt cekModel) = do
, Repl.historyFile = Nothing
, Repl.autoAddHistory = False
}

ctr <- newCounter 8
let ?cekRuntime = runtime
?cekEmitter = const $ pure ()
?cekBudgetSpender = Cek.CekBudgetSpender $ \_ _ -> pure ()
?cekCosts = costs
?cekSlippage = D.defaultSlippage
?cekStepCounter = ctr
in Repl.runInputT replSettings $
-- MAYBE: use cutoff or partialIterT to prevent runaway
D.iterTM handleDbg $ D.runDriver nterm
Expand Down
2 changes: 1 addition & 1 deletion plutus-core/plutus-core.cabal
Expand Up @@ -164,6 +164,7 @@ library
UntypedPlutusCore.Evaluation.Machine.Cek.Debug.Driver
UntypedPlutusCore.Evaluation.Machine.Cek.Debug.Internal
UntypedPlutusCore.Evaluation.Machine.Cek.Internal
UntypedPlutusCore.Evaluation.Machine.Cek.StepCounter
UntypedPlutusCore.MkUPlc
UntypedPlutusCore.Parser
UntypedPlutusCore.Rename
Expand Down Expand Up @@ -296,7 +297,6 @@ library
, transformers
, unordered-containers
, witherable
, word-array ^>=1.1

if impl(ghc <9.0)
build-depends: integer-gmp
Expand Down

0 comments on commit 924ba78

Please sign in to comment.