Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: IntersectMBO/plutus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c891dccfd75c43c1d90c1f710704e446dcf85abc
Choose a base ref
..
head repository: IntersectMBO/plutus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7b9c8a92fdd4555ce8c0696906d5f40df4e29b9b
Choose a head ref
7 changes: 5 additions & 2 deletions plutus-core/cost-model/budgeting-bench/Benchmarks/Arrays.hs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ module Benchmarks.Arrays (makeBenchmarks) where

import Prelude

import Common (createOneTermBuiltinBench, createTwoTermBuiltinBench)
import Common (createOneTermBuiltinBench, createTwoTermBuiltinBenchElementwise)
import Control.Monad (replicateM)
import Criterion.Main (Benchmark)
import Data.Vector.Strict (Vector)
@@ -46,7 +46,10 @@ benchListToArray gen =

benchIndexArray :: StdGen -> Benchmark
benchIndexArray gen =
createTwoTermBuiltinBench IndexArray [tyArrayOfInteger] arrays idxs
createTwoTermBuiltinBenchElementwise
IndexArray
[tyArrayOfInteger]
(zip arrays idxs)
where
(arrays :: [Vector Integer], idxs :: [Integer]) =
unzip $ runStateGen_ gen \g -> replicateM 100 do
Original file line number Diff line number Diff line change
@@ -173,8 +173,8 @@ builtinMemoryModels = BuiltinCostModelBase
-- paramCaseList
-- paramCaseData
, paramDropList = Id $ ModelTwoArgumentsConstantCost 4
, paramLengthOfArray = Id $ ModelOneArgumentConstantCost 99
, paramListToArray = Id $ ModelOneArgumentConstantCost 99
, paramIndexArray = Id $ ModelTwoArgumentsConstantCost 99
, paramLengthOfArray = Id $ ModelOneArgumentConstantCost 10
, paramListToArray = Id $ ModelOneArgumentLinearInX identityFunction
, paramIndexArray = Id $ ModelTwoArgumentsConstantCost 32
}
where identityFunction = OneVariableLinearFunction 0 1
2 changes: 1 addition & 1 deletion plutus-core/cost-model/data/models.R
Original file line number Diff line number Diff line change
@@ -785,7 +785,7 @@ modelFun <- function(path) {

dropListModel <- linearInX ("DropList")

## Arrays - TEMPORARY, but probably right
## Arrays
lengthOfArrayModel <- constantModel ("LengthOfArray")
listToArrayModel <- linearInX ("ListToArray")
indexArrayModel <- constantModel ("IndexArray")
14 changes: 10 additions & 4 deletions plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@ import PlutusCore.Data (Data (..))
import PlutusCore.Default.Universe
import PlutusCore.Evaluation.Machine.BuiltinCostModel
import PlutusCore.Evaluation.Machine.ExBudgetStream (ExBudgetStream)
import PlutusCore.Evaluation.Machine.ExMemoryUsage (ExMemoryUsage, IntegerCostedLiterally (..),
import PlutusCore.Evaluation.Machine.ExMemoryUsage (ArrayCostedByLength, ExMemoryUsage,
IntegerCostedLiterally (..),
ListCostedByLength (..),
NumBytesCostedAsNumWords (..), memoryUsage,
singletonRose)
@@ -2107,7 +2108,7 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
(runCostingFunTwoArguments . paramDropList)

toBuiltinMeaning _semvar LengthOfArray =
let lengthOfArrayDenotation :: SomeConstant uni (Vector a) -> BuiltinResult Int
let lengthOfArrayDenotation :: SomeConstant uni (ArrayCostedByLength a) -> BuiltinResult Int
lengthOfArrayDenotation (SomeConstant (Some (ValueOf uni vec))) =
case uni of
DefaultUniArray _uniA -> pure $ Vector.length vec
@@ -2116,7 +2117,9 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
in makeBuiltinMeaning lengthOfArrayDenotation (runCostingFunOneArgument . paramLengthOfArray)

toBuiltinMeaning _semvar ListToArray =
let listToArrayDenotation :: SomeConstant uni [a] -> BuiltinResult (Opaque val (Vector a))
let listToArrayDenotation
:: SomeConstant uni (ListCostedByLength a)
-> BuiltinResult (Opaque val (Vector a))
listToArrayDenotation (SomeConstant (Some (ValueOf uniListA xs))) =
case uniListA of
DefaultUniList uniA -> pure $ fromValueOf (DefaultUniArray uniA) $ Vector.fromList xs
@@ -2125,7 +2128,10 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
in makeBuiltinMeaning listToArrayDenotation (runCostingFunOneArgument . paramListToArray)

toBuiltinMeaning _semvar IndexArray =
let indexArrayDenotation :: SomeConstant uni (Vector a) -> Int -> BuiltinResult (Opaque val a)
let indexArrayDenotation
:: SomeConstant uni (ArrayCostedByLength a)
-> Int
-> BuiltinResult (Opaque val a)
indexArrayDenotation (SomeConstant (Some (ValueOf uni vec))) n =
case uni of
DefaultUniArray arg -> do