Skip to content

Commit 9280fd9

Browse files
authored
SCP-2663 Teach the Plutus Tx compiler to add profiling trace statements (IntersectMBO#3779)
* Add some golden tests and an executable for profiling. * Mark plutus-tx-plugin as unbuildable for windows.
1 parent edd3ce2 commit 9280fd9

File tree

31 files changed

+600
-27
lines changed

31 files changed

+600
-27
lines changed

nix/pkgs/haskell/haskell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ let
9191
plutus-ledger.package.buildable = false;
9292
plutus-pab.package.buildable = false;
9393
plutus-playground-server.package.buildable = false; # Would also require libpq
94+
plutus-tx-plugin.package.buildable = false;
9495
plutus-use-cases.package.buildable = false;
9596
web-ghc.package.buildable = false;
9697
# Needs agda

nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-tx-plugin.nix

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-darwin/default.nix

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-tx-plugin.nix

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-linux/default.nix

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-tx-plugin.nix

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-windows/default.nix

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plutus-core/common/PlcTestUtils.hs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ module PlcTestUtils (
2424
goldenUEval,
2525
goldenTEvalCatch,
2626
goldenUEvalCatch,
27+
goldenUEvalProfile,
2728
NoMarkRenameT(..),
2829
noMarkRename,
2930
NoRenameT(..),
3031
noRename,
3132
BrokenRenameT(..),
3233
runBrokenRenameT,
34+
runUPlcProfile,
3335
brokenRename,
3436
prop_scopingFor,
3537
test_scopingGood,
@@ -40,24 +42,27 @@ import PlutusPrelude
4042

4143
import Common
4244

43-
import qualified PlutusCore as TPLC
45+
import qualified PlutusCore as TPLC
4446
import PlutusCore.Check.Scoping
4547
import PlutusCore.DeBruijn
4648
import PlutusCore.Default.Universe
47-
import qualified PlutusCore.Evaluation.Machine.Ck as TPLC
49+
import qualified PlutusCore.Evaluation.Machine.Ck as TPLC
4850
import PlutusCore.Generators
4951
import PlutusCore.Generators.AST
5052
import PlutusCore.Pretty
51-
import qualified PlutusCore.Rename.Monad as TPLC
53+
import qualified PlutusCore.Rename.Monad as TPLC
5254

53-
import qualified UntypedPlutusCore as UPLC
54-
import qualified UntypedPlutusCore.Evaluation.Machine.Cek as UPLC
55+
import qualified UntypedPlutusCore as UPLC
56+
import qualified UntypedPlutusCore.Evaluation.Machine.Cek as UPLC
57+
import UntypedPlutusCore.Evaluation.Machine.Cek.EmitterMode (logEmitter)
5558

5659
import Control.Exception
60+
import Control.Lens.Combinators (_2)
5761
import Control.Monad.Except
5862
import Control.Monad.Reader
5963
import Control.Monad.State
60-
import qualified Data.Text.Prettyprint.Doc as PP
64+
import Data.Text (Text)
65+
import qualified Data.Text.Prettyprint.Doc as PP
6166
import Hedgehog
6267
import System.IO.Unsafe
6368
import Test.Tasty
@@ -136,6 +141,20 @@ runUPlc values = do
136141
let (UPLC.Program _ _ t) = foldl1 UPLC.applyProgram ps
137142
liftEither $ first toException $ TPLC.extractEvaluationResult $ UPLC.evaluateCekNoEmit TPLC.defaultCekParameters t
138143

144+
-- For golden tests of profiling.
145+
runUPlcProfile :: ToUPlc a DefaultUni UPLC.DefaultFun =>
146+
[a]
147+
-> ExceptT
148+
SomeException
149+
IO
150+
(UPLC.Term UPLC.Name DefaultUni UPLC.DefaultFun (), [Text])
151+
runUPlcProfile values = do
152+
ps <- traverse toUPlc values
153+
let (UPLC.Program _ _ t) = foldl1 UPLC.applyProgram ps
154+
(result, logOut) = UPLC.evaluateCek logEmitter TPLC.defaultCekParameters t
155+
res <- either (throwError . SomeException) pure result
156+
pure (res, logOut)
157+
139158
ppCatch :: PrettyPlc a => ExceptT SomeException IO a -> IO (Doc ann)
140159
ppCatch value = either (PP.pretty . show) prettyPlcClassicDebug <$> runExceptT value
141160

@@ -190,6 +209,12 @@ goldenUEvalCatch
190209
=> String -> [a] -> TestNested
191210
goldenUEvalCatch name values = nestedGoldenVsDocM name $ ppCatch $ runUPlc values
192211

212+
-- | Similar to @goldenUEval@ but with profiling turned on.
213+
goldenUEvalProfile
214+
:: ToUPlc a DefaultUni TPLC.DefaultFun
215+
=> String -> [a] -> TestNested
216+
goldenUEvalProfile name values = nestedGoldenVsDocM name $ pretty . view _2 <$> (rethrow $ runUPlcProfile values)
217+
193218
-- See Note [Marking].
194219
-- | A version of 'RenameT' that fails to take free variables into account.
195220
newtype NoMarkRenameT ren m a = NoMarkRenameT

plutus-core/plutus-core/src/PlutusCore/Constant/Typed.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ data family TyAppRep (fun :: dom -> cod) (arg :: dom) :: cod
395395
data family TyForallRep (var :: TyNameRep kind) (a :: GHC.Type) :: GHC.Type
396396

397397
-- See Note [Motivation for polymorphic built-in functions].
398-
-- See Note [Implemetation of polymorphic built-in functions].
398+
-- See Note [Implementation of polymorphic built-in functions].
399399
-- See Note [Pattern matching on built-in types].
400400
-- | The denotation of a term whose PLC type is encoded in @rep@ (for example a type variable or
401401
-- an application of a type variable). I.e. the denotation of such a term is the term itself.

plutus-core/plutus-core/src/PlutusCore/MkPlc.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ functionDefToType (FunctionDef _ _ funTy _) = functionTypeToType funTy
171171
functionDefVarDecl :: FunctionDef term tyname name uni fun ann -> VarDecl tyname name uni fun ann
172172
functionDefVarDecl (FunctionDef ann name funTy _) = VarDecl ann name $ functionTypeToType funTy
173173

174-
-- | Make a 'FunctioDef'. Return 'Nothing' if the provided type is not functional.
174+
-- | Make a 'FunctionDef'. Return 'Nothing' if the provided type is not functional.
175175
mkFunctionDef
176176
:: ann
177177
-> name

0 commit comments

Comments
 (0)