From 5ef5609454bd69475449880453e2e723349dce93 Mon Sep 17 00:00:00 2001 From: jmcardon Date: Mon, 4 Nov 2024 15:33:43 -0500 Subject: [PATCH] Separate repl into separate project - Fix builtin gas charging for repl builtins - Move tracing flags to repl sublibrary --- gasmodel/Pact/Core/GasModel/ContractBench.hs | 14 +++++- pact-tng.cabal | 52 ++++++-------------- pact/Pact/Core/Evaluate.hs | 14 ------ profile-tx/ProfileTx.hs | 4 +- 4 files changed, 29 insertions(+), 55 deletions(-) diff --git a/gasmodel/Pact/Core/GasModel/ContractBench.hs b/gasmodel/Pact/Core/GasModel/ContractBench.hs index 63c626e0..2108c4e2 100644 --- a/gasmodel/Pact/Core/GasModel/ContractBench.hs +++ b/gasmodel/Pact/Core/GasModel/ContractBench.hs @@ -41,6 +41,8 @@ import Pact.Core.Gas import Pact.Core.Namespace import Pact.Core.Serialise import Pact.Core.Persistence.MockPersistence +import qualified Pact.Core.IR.Eval.Direct.Evaluator as Direct +import qualified Pact.Core.IR.Eval.Direct.CoreBuiltin as Direct import Pact.Core.Errors import Pact.Core.Interpreter @@ -59,7 +61,15 @@ interpretBigStep :: Interpreter ExecRuntime CoreBuiltin Info interpretBigStep = evalInterpreter interpretDirect :: Interpreter ExecRuntime CoreBuiltin Info -interpretDirect = evalDirectInterpreter +interpretDirect = + Interpreter runGuard runTerm resume evalWithCap + where + runTerm purity term = Direct.eval purity benv term + runGuard info g = Direct.interpretGuard info benv g + resume info defPact = Direct.evalResumePact info benv defPact + evalWithCap info purity ct term = + Direct.evalWithinCap info purity benv ct term + benv = Direct.coreBuiltinEnv data CoinBenchSenders @@ -179,7 +189,7 @@ setupCoinTxs pdb = do putStrLn "Setting up the coin contract and the default funds" source <- T.readFile (contractsPath "coin-v5-create.pact") ee <- setupBenchEvalEnv pdb coinInitSigners coinInitData - () <$ runPactTxFromSource ee source evalDirectInterpreter + () <$ runPactTxFromSource ee source interpretDirect _run :: IO () diff --git a/pact-tng.cabal b/pact-tng.cabal index 7eb3859e..a35d2b45 100644 --- a/pact-tng.cabal +++ b/pact-tng.cabal @@ -185,15 +185,6 @@ library import: pact-common hs-source-dirs: pact - if (flag(with-funcall-tracing)) - cpp-options: -DWITH_FUNCALL_TRACING - - if (flag(with-native-tracing)) - cpp-options: -DWITH_NATIVE_TRACING - - if (flag(with-native-tracing) || flag(with-funcall-tracing)) - cpp-options: -DWITH_TRACING - if (flag(with-crypto)) build-depends: pact-tng:pact-crypto else @@ -280,15 +271,6 @@ library Pact.Core.Trans.MPFR Pact.Core.Version - -- Repl - -- Pact.Core.Repl - -- Pact.Core.Repl.Utils - -- Pact.Core.Repl.Runtime.ReplBuiltin - -- Pact.Core.Repl.Compile - -- Pact.Core.Repl.BuiltinDocs - -- Pact.Core.Repl.BuiltinDocs.Internal - -- Pact.Core.Repl.UserDocs - -- Serialization Pact.Core.Serialise Pact.Core.Serialise.LegacyPact @@ -310,6 +292,20 @@ library pact-repl import: pact-common hs-source-dirs: pact-repl + if (flag(with-crypto)) + build-depends: pact-tng:pact-crypto + else + cpp-options: -DWITHOUT_CRYPTO + + if (flag(with-funcall-tracing)) + cpp-options: -DWITH_FUNCALL_TRACING + + if (flag(with-native-tracing)) + cpp-options: -DWITH_NATIVE_TRACING + + if (flag(with-native-tracing) || flag(with-funcall-tracing)) + cpp-options: -DWITH_TRACING + exposed-modules: Pact.Core.Repl Pact.Core.Repl.Utils @@ -354,6 +350,7 @@ executable gasmodel build-depends: , pact-tng + , pact-tng:pact-repl , criterion , terminal-progress-bar , neat-interpolation @@ -590,22 +587,3 @@ test-suite core-tests , Pact.Core.Test.ServerUtils if (flag(with-crypto)) build-depends: pact-tng:pact-crypto - - --- -- tools --- executable pact-server --- import: pact-common --- hs-source-dirs: pact-server - --- main-is: Pact/Server.hs - --- build-depends: --- , pact-tng --- , async --- , fast-logger --- , filepath --- , servant --- , servant-server --- ghc-options: -Wall -threaded -rtsopts -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints --- ghc-prof-options: -fprof-auto -fprof-auto-calls --- default-language: Haskell2010 diff --git a/pact/Pact/Core/Evaluate.hs b/pact/Pact/Core/Evaluate.hs index a4f4cb7a..e7f6fcd3 100644 --- a/pact/Pact/Core/Evaluate.hs +++ b/pact/Pact/Core/Evaluate.hs @@ -23,7 +23,6 @@ module Pact.Core.Evaluate , Eval , EvalBuiltinEnv , allModuleExports - -- , evalDirectInterpreter , evalInterpreter , EvalInput , EnableGasLogs(..) @@ -64,8 +63,6 @@ import Pact.Core.Info import Pact.Core.Signer import Pact.Core.IR.Eval.CEK.CoreBuiltin import qualified Pact.Core.IR.Eval.CEK.Evaluator as CEK --- import qualified Pact.Core.IR.Eval.Direct.Evaluator as Direct --- import qualified Pact.Core.IR.Eval.Direct.CoreBuiltin as Direct import qualified Pact.Core.Syntax.Lexer as Lisp import qualified Pact.Core.Syntax.Parser as Lisp import qualified Pact.Core.Syntax.ParseTree as Lisp @@ -118,17 +115,6 @@ evalInterpreter = cekEnv :: CEK.BuiltinEnv ExecRuntime CoreBuiltin Info cekEnv = coreBuiltinEnv @ExecRuntime --- evalDirectInterpreter :: Interpreter ExecRuntime CoreBuiltin Info --- evalDirectInterpreter = --- Interpreter runGuard runTerm resume evalWithCap --- where --- runTerm purity term = Direct.eval purity env term --- runGuard info g = Direct.interpretGuard info env g --- resume info defPact = Direct.evalResumePact info env defPact --- evalWithCap info purity ct term = --- Direct.evalWithinCap info purity env ct term --- env = Direct.coreBuiltinEnv - -- | Transaction-payload related environment data. data MsgData = MsgData { mdData :: !PactValue diff --git a/profile-tx/ProfileTx.hs b/profile-tx/ProfileTx.hs index c379a8c1..4aaa522f 100644 --- a/profile-tx/ProfileTx.hs +++ b/profile-tx/ProfileTx.hs @@ -183,7 +183,7 @@ setupCoinTxs pdb = do putStrLn "Setting up the coin contract and the default funds" source <- T.readFile (contractsPath "coin-v5-create.pact") ee <- setupBenchEvalEnv pdb coinInitSigners coinInitData - () <$ runPactTxFromSource ee source evalDirectInterpreter + () <$ runPactTxFromSource ee source evalInterpreter _run :: IO () @@ -242,7 +242,7 @@ _testCoinTransfer = withSqlitePactDb serialisePact_lineinfo (T.pack benchmarkSql t <- liftEither $ compileOnlyTermLineInfo (RawCode termText) _dsOut <$> runDesugarTerm t term <- getRightIO eterm - (out, _) <- runEvalM (ExecEnv ee) es (eval evalDirectInterpreter PImpure term) + (out, _) <- runEvalM (ExecEnv ee) es (eval evalInterpreter PImpure term) print out unsafeModuleHash :: Text -> Hash