Skip to content

Commit

Permalink
SCP-3673: SCP-2997: versioned builtins. fix consByteString integer wr…
Browse files Browse the repository at this point in the history
…apping

Fix for setting correct runtime in extensible-builtin test. Fix for loop

Relax Lift to be used with maxBound builtinversion

Go with Sole Reader approach

Inline with sole reader

LetFloat unrelated fixes

Letfloat solereader

Added tx-plugin changes

Switch from Bounded to Default
  • Loading branch information
bezirg committed Aug 5, 2022
1 parent 107d7e7 commit 319c55b
Show file tree
Hide file tree
Showing 57 changed files with 668 additions and 563 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ benchSliceByteString =
benchConsByteString :: Benchmark
benchConsByteString =
createTwoTermBuiltinBench ConsByteString [] [n] (smallerByteStrings150 seedA)
where n = 123456789 :: Integer
-- The precise numbers don't seem to matter here. There'll be
-- some cost coercing them to Word8, but even with very large
-- numbers that seems to be negligible.

where n = 123 :: Integer
-- The precise numbers don't seem to matter here, as long as they are in
-- the range of [0..255] (Word8). Otherwise
-- we run the risk of costing also the (fast) failures of the builtin call.

makeBenchmarks :: StdGen -> [Benchmark]
makeBenchmarks gen = [ benchTwoByteStrings AppendByteString,
Expand Down
60 changes: 32 additions & 28 deletions plutus-core/cost-model/budgeting-bench/Benchmarks/Nops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ import PlutusCore.Evaluation.Machine.ExBudgetingDefaults
import PlutusCore.Evaluation.Machine.ExMemory (ExMemoryUsage)
import PlutusCore.Evaluation.Machine.MachineParameters (CostModel (..), MachineParameters, mkMachineParameters)
import PlutusCore.Pretty
import PlutusPrelude
import UntypedPlutusCore.Evaluation.Machine.Cek

import Criterion.Main (Benchmark, bgroup)

import Control.DeepSeq (NFData)
import Data.Char (toLower)
import Data.Ix (Ix)
import GHC.Generics (Generic)
import System.Random (StdGen)

{- | A benchmark that just loads the unit constant, which is about the minimal
Expand Down Expand Up @@ -127,7 +126,7 @@ nopCostModel =

nopCostParameters :: MachineParameters CekMachineCosts CekValue DefaultUni NopFun
nopCostParameters =
mkMachineParameters defaultUnliftingMode $
mkMachineParameters def defaultUnliftingMode $
CostModel defaultCekMachineCosts nopCostModel

-- This is just to avoid some deeply nested case expressions for the NopNc
Expand Down Expand Up @@ -156,130 +155,135 @@ n >: k =
-}
instance uni ~ DefaultUni => ToBuiltinMeaning uni NopFun where
type CostingPart uni NopFun = NopCostModel

data BuiltinVersion NopFun = NopFunV1

-- Built-in Bools
toBuiltinMeaning
:: forall val . HasMeaningIn uni val
=> NopFun -> BuiltinMeaning val NopCostModel
toBuiltinMeaning Nop1b =
=> BuiltinVersion NopFun -> NopFun -> BuiltinMeaning val NopCostModel
toBuiltinMeaning _ver Nop1b =
makeBuiltinMeaning
@(Bool -> Bool)
(\_ -> True)
(runCostingFunOneArgument . paramNop1)
toBuiltinMeaning Nop2b =
toBuiltinMeaning _ver Nop2b =
makeBuiltinMeaning
@(Bool -> Bool -> Bool)
(\_ _ -> True)
(runCostingFunTwoArguments . paramNop2)
toBuiltinMeaning Nop3b =
toBuiltinMeaning _ver Nop3b =
makeBuiltinMeaning
@(Bool -> Bool -> Bool -> Bool)
(\_ _ _ -> True)
(runCostingFunThreeArguments . paramNop3)
toBuiltinMeaning Nop4b =
toBuiltinMeaning _ver Nop4b =
makeBuiltinMeaning
@(Bool -> Bool -> Bool -> Bool -> Bool)
(\_ _ _ _ -> True)
(runCostingFunFourArguments . paramNop4)
toBuiltinMeaning Nop5b =
toBuiltinMeaning _ver Nop5b =
makeBuiltinMeaning
@(Bool -> Bool -> Bool -> Bool -> Bool -> Bool)
(\_ _ _ _ _ -> True)
(runCostingFunFiveArguments . paramNop5)
toBuiltinMeaning Nop6b =
toBuiltinMeaning _ver Nop6b =
makeBuiltinMeaning
@(Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool)
(\_ _ _ _ _ _ -> True)
(runCostingFunSixArguments . paramNop6)
-- Built-in Integers
toBuiltinMeaning Nop1i =
toBuiltinMeaning _ver Nop1i =
makeBuiltinMeaning
@(Integer -> Integer)
(\_ -> 11)
(runCostingFunOneArgument . paramNop1)
toBuiltinMeaning Nop2i =
toBuiltinMeaning _ver Nop2i =
makeBuiltinMeaning
@(Integer -> Integer -> Integer)
(\_ _ -> 22)
(runCostingFunTwoArguments . paramNop2)
toBuiltinMeaning Nop3i =
toBuiltinMeaning _ver Nop3i =
makeBuiltinMeaning
@(Integer -> Integer -> Integer -> Integer)
(\_ _ _ -> 33)
(runCostingFunThreeArguments . paramNop3)
toBuiltinMeaning Nop4i =
toBuiltinMeaning _ver Nop4i =
makeBuiltinMeaning
@(Integer -> Integer -> Integer -> Integer -> Integer)
(\_ _ _ _ -> 44)
(runCostingFunFourArguments . paramNop4)
toBuiltinMeaning Nop5i =
toBuiltinMeaning _ver Nop5i =
makeBuiltinMeaning
@(Integer -> Integer -> Integer -> Integer -> Integer -> Integer)
(\_ _ _ _ _ -> 55)
(runCostingFunFiveArguments . paramNop5)
toBuiltinMeaning Nop6i =
toBuiltinMeaning _ver Nop6i =
makeBuiltinMeaning
@(Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer)
(\_ _ _ _ _ _ -> 66)
(runCostingFunSixArguments . paramNop6)
-- Integers unlifted via SomeConstant
toBuiltinMeaning Nop1c =
toBuiltinMeaning _ver Nop1c =
makeBuiltinMeaning
(\c1 -> c1 >: EvaluationSuccess 11)
(runCostingFunOneArgument . paramNop1)
toBuiltinMeaning Nop2c =
toBuiltinMeaning _ver Nop2c =
makeBuiltinMeaning
(\c1 c2 -> c1 >: c2 >: EvaluationSuccess 22)
(runCostingFunTwoArguments . paramNop2)
toBuiltinMeaning Nop3c =
toBuiltinMeaning _ver Nop3c =
makeBuiltinMeaning
(\c1 c2 c3 -> c1 >: c2 >: c3 >: EvaluationSuccess 33)
(runCostingFunThreeArguments . paramNop3)
toBuiltinMeaning Nop4c =
toBuiltinMeaning _ver Nop4c =
makeBuiltinMeaning
(\c1 c2 c3 c4 -> c1 >: c2 >: c3 >: c4 >: EvaluationSuccess 44)
(runCostingFunFourArguments . paramNop4)
toBuiltinMeaning Nop5c =
toBuiltinMeaning _ver Nop5c =
makeBuiltinMeaning
(\c1 c2 c3 c4 c5 -> c1 >: c2 >: c3 >: c4 >: c5 >: EvaluationSuccess 55)
(runCostingFunFiveArguments . paramNop5)
toBuiltinMeaning Nop6c =
toBuiltinMeaning _ver Nop6c =
makeBuiltinMeaning
(\c1 c2 c3 c4 c5 c6 -> c1 >: c2 >: c3 >: c4 >: c5 >: c6 >: EvaluationSuccess 66)
(runCostingFunSixArguments . paramNop6)
-- Opaque Integers
toBuiltinMeaning Nop1o =
toBuiltinMeaning _ver Nop1o =
makeBuiltinMeaning
@(Opaque val Integer -> Opaque val Integer)
(\_ -> fromValueOf DefaultUniInteger 11)
(runCostingFunOneArgument . paramNop1)
toBuiltinMeaning Nop2o =
toBuiltinMeaning _ver Nop2o =
makeBuiltinMeaning
@(Opaque val Integer -> Opaque val Integer-> Opaque val Integer)
(\_ _ -> fromValueOf DefaultUniInteger 22)
(runCostingFunTwoArguments . paramNop2)
toBuiltinMeaning Nop3o =
toBuiltinMeaning _ver Nop3o =
makeBuiltinMeaning
@(Opaque val Integer -> Opaque val Integer-> Opaque val Integer-> Opaque val Integer)
(\_ _ _ -> fromValueOf DefaultUniInteger 33)
(runCostingFunThreeArguments . paramNop3)
toBuiltinMeaning Nop4o =
toBuiltinMeaning _ver Nop4o =
makeBuiltinMeaning
@(Opaque val Integer -> Opaque val Integer-> Opaque val Integer-> Opaque val Integer -> Opaque val Integer)
(\_ _ _ _ -> fromValueOf DefaultUniInteger 44)
(runCostingFunFourArguments . paramNop4)
toBuiltinMeaning Nop5o =
toBuiltinMeaning _ver Nop5o =
makeBuiltinMeaning
@(Opaque val Integer -> Opaque val Integer-> Opaque val Integer
-> Opaque val Integer -> Opaque val Integer -> Opaque val Integer)
(\_ _ _ _ _ -> fromValueOf DefaultUniInteger 55)
(runCostingFunFiveArguments . paramNop5)
toBuiltinMeaning Nop6o =
toBuiltinMeaning _ver Nop6o =
makeBuiltinMeaning
@(Opaque val Integer -> Opaque val Integer-> Opaque val Integer
-> Opaque val Integer -> Opaque val Integer -> Opaque val Integer -> Opaque val Integer)
(\_ _ _ _ _ _ -> fromValueOf DefaultUniInteger 66)
(runCostingFunSixArguments . paramNop6)

instance Default (BuiltinVersion NopFun) where
def = NopFunV1

---------------- Benchmarks ----------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- editorconfig-checker-disable-file
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
Expand Down
12 changes: 5 additions & 7 deletions plutus-core/executables/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

module Common where

import PlutusPrelude (through)
import PlutusPrelude

import PlutusCore qualified as PLC
import PlutusCore.Builtin qualified as PLC
Expand All @@ -31,11 +31,10 @@ import PlutusCore.StdLib.Data.ChurchNat qualified as StdLib
import PlutusCore.StdLib.Data.Integer qualified as StdLib
import PlutusCore.StdLib.Data.Unit qualified as StdLib

import Control.DeepSeq (NFData, rnf)
import Control.DeepSeq (rnf)
import Control.Lens hiding (ix, op)
import Control.Monad.Except
import Data.Aeson qualified as Aeson
import Data.Bifunctor (second)
import Data.ByteString.Lazy qualified as BSL
import Data.Foldable (traverse_)
import Data.HashMap.Monoidal qualified as H
Expand All @@ -45,10 +44,9 @@ import Data.Maybe (fromJust)
import Data.Proxy (Proxy (..))
import Data.Text qualified as T
import Data.Text.IO qualified as T
import Data.Traversable (for)
import Flat (Flat, flat, unflat)
import GHC.TypeLits (symbolVal)
import Prettyprinter (Doc, pretty, (<+>))
import Prettyprinter ((<+>))
import UntypedPlutusCore qualified as UPLC
import UntypedPlutusCore.Check.Uniques qualified as UPLC (checkProgram)
import UntypedPlutusCore.Evaluation.Machine.Cek qualified as Cek
Expand Down Expand Up @@ -626,8 +624,8 @@ typeSchemeToSignature = toSig []

runPrintBuiltinSignatures :: IO ()
runPrintBuiltinSignatures = do
let builtins = [minBound..maxBound] :: [UPLC.DefaultFun]
let builtins = enumerate @UPLC.DefaultFun
mapM_ (\x -> putStr (printf "%-25s: %s\n" (show $ PP.pretty x) (show $ getSignature x))) builtins
where getSignature (PLC.toBuiltinMeaning @_ @_ @PlcTerm -> PLC.BuiltinMeaning sch _ _) = typeSchemeToSignature sch
where getSignature (PLC.toBuiltinMeaning @_ @_ @PlcTerm def -> PLC.BuiltinMeaning sch _ _) = typeSchemeToSignature sch


4 changes: 2 additions & 2 deletions plutus-core/executables/pir/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import PlutusIR as PIR
import PlutusIR.Analysis.RetainedSize qualified as PIR
import PlutusIR.Compiler qualified as PIR
import PlutusIR.Core.Plated
import Prettyprinter
import PlutusPrelude

data Command = Analyse AOpts
| Compile COpts
Expand Down Expand Up @@ -123,7 +123,7 @@ loadPirAndAnalyse aopts = do
nameTable = IM.fromList [(coerce $ _nameUnique n , _nameText n) | n <- names]

-- build the retentionMap
retentionMap = PIR.termRetentionMap pirT
retentionMap = PIR.termRetentionMap def pirT
-- sort the map by decreasing retained size
sortedRetained = sortOn (negate . snd) $ IM.assocs retentionMap

Expand Down
Loading

0 comments on commit 319c55b

Please sign in to comment.