Skip to content

Commit

Permalink
Rename byteStringReplicate to replicateByteString
Browse files Browse the repository at this point in the history
  • Loading branch information
kozross committed May 9, 2024
1 parent 76b6fc5 commit 7b0b7f6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions plutus-core/plutus-core/src/PlutusCore/Bitwise/Logical.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module PlutusCore.Bitwise.Logical (
bitwiseLogicalComplement,
readBit,
writeBits,
byteStringReplicate,
replicateByteString
) where

import Control.Exception (Exception, throw, try)
Expand Down Expand Up @@ -267,8 +267,8 @@ writeBits bs changelist = case unsafeDupablePerformIO . try $ go of

-- | Byte replication, as per [the relevant
-- CIP](https://github.com/mlabs-haskell/CIPs/blob/koz/logic-ops/CIP-XXX/CIP-XXX.md)
byteStringReplicate :: Int -> Word8 -> BuiltinResult ByteString
byteStringReplicate len w8
replicateByteString :: Int -> Word8 -> BuiltinResult ByteString
replicateByteString len w8
| len < 0 = do
emit "byteStringReplicate: negative length requested"
evaluationFailure
Expand Down
10 changes: 5 additions & 5 deletions plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ data DefaultFun
| BitwiseLogicalComplement
| ReadBit
| WriteBits
| ByteStringReplicate
| ReplicateByteString
deriving stock (Show, Eq, Ord, Enum, Bounded, Generic, Ix)
deriving anyclass (NFData, Hashable, PrettyBy PrettyConfigPlc)

Expand Down Expand Up @@ -1880,9 +1880,9 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
writeBitsDenotation
(runCostingFunTwoArguments . unimplementedCostingFun)

toBuiltinMeaning _semvar ByteStringReplicate =
toBuiltinMeaning _semvar ReplicateByteString =
let byteStringReplicateDenotation :: Int -> Word8 -> BuiltinResult BS.ByteString
byteStringReplicateDenotation = Logical.byteStringReplicate
byteStringReplicateDenotation = Logical.replicateByteString
{-# INLINE byteStringReplicateDenotation #-}
in makeBuiltinMeaning
byteStringReplicateDenotation
Expand Down Expand Up @@ -2021,7 +2021,7 @@ instance Flat DefaultFun where
BitwiseLogicalComplement -> 78
ReadBit -> 79
WriteBits -> 80
ByteStringReplicate -> 81
ReplicateByteString -> 81

decode = go =<< decodeBuiltin
where go 0 = pure AddInteger
Expand Down Expand Up @@ -2105,7 +2105,7 @@ instance Flat DefaultFun where
go 78 = pure BitwiseLogicalComplement
go 79 = pure ReadBit
go 80 = pure WriteBits
go 81 = pure ByteStringReplicate
go 81 = pure ReplicateByteString
go t = fail $ "Failed to decode builtin tag, got: " ++ show t

size _ n = n + builtinTagWidth
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ test_Logical =
Laws.setSet,
Laws.writeBitsHomomorphismLaws
],
testGroup "byteStringReplicate" [
testGroup "replicateByteString" [
Laws.replicateHomomorphismLaws,
Laws.replicateIndex
]
Expand Down
10 changes: 5 additions & 5 deletions plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Laws.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ replicateIndex = testPropertyNamed "every byte is the same" "replicate_all_match
n <- forAll . Gen.integral . Range.linear 1 $ 1024
b <- forAll . Gen.integral . Range.constant 0 $ 255
i <- forAll . Gen.integral . Range.linear 0 $ n - 1
let lhsInner = mkIterAppNoAnn (builtin () PLC.ByteStringReplicate) [
let lhsInner = mkIterAppNoAnn (builtin () PLC.ReplicateByteString) [
mkConstant @Integer () n,
mkConstant @Integer () b
]
Expand Down Expand Up @@ -168,7 +168,7 @@ replicateHomomorphismLaws =
identityProp :: Property
identityProp = property $ do
b <- forAll . Gen.integral . Range.constant 0 $ 255
let lhs = mkIterAppNoAnn (builtin () PLC.ByteStringReplicate) [
let lhs = mkIterAppNoAnn (builtin () PLC.ReplicateByteString) [
mkConstant @Integer () 0,
mkConstant @Integer () b
]
Expand All @@ -182,19 +182,19 @@ replicateHomomorphismLaws =
b <- forAll . Gen.integral . Range.constant 0 $ 255
n1 <- forAll . Gen.integral . Range.linear 0 $ 512
n2 <- forAll . Gen.integral . Range.linear 0 $ 512
let lhsInner1 = mkIterAppNoAnn (builtin () PLC.ByteStringReplicate) [
let lhsInner1 = mkIterAppNoAnn (builtin () PLC.ReplicateByteString) [
mkConstant @Integer () n1,
mkConstant @Integer () b
]
let lhsInner2 = mkIterAppNoAnn (builtin () PLC.ByteStringReplicate) [
let lhsInner2 = mkIterAppNoAnn (builtin () PLC.ReplicateByteString) [
mkConstant @Integer () n2,
mkConstant @Integer () b
]
let lhs = mkIterAppNoAnn (builtin () PLC.AppendByteString) [
lhsInner1,
lhsInner2
]
let rhs = mkIterAppNoAnn (builtin () PLC.ByteStringReplicate) [
let rhs = mkIterAppNoAnn (builtin () PLC.ReplicateByteString) [
mkConstant @Integer () (n1 + n2),
mkConstant @Integer () b
]
Expand Down
2 changes: 1 addition & 1 deletion plutus-tx/src/PlutusTx/Builtins/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ byteStringReplicate ::
BuiltinInteger ->
BuiltinByteString
byteStringReplicate n w8 =
case Logical.byteStringReplicate (fromIntegral n) (fromIntegral w8) of
case Logical.replicateByteString (fromIntegral n) (fromIntegral w8) of
BuiltinFailure logs err -> traceAll (logs <> pure (display err)) $
Haskell.error "byteStringReplicate errored."
BuiltinSuccess bs -> BuiltinByteString bs
Expand Down

0 comments on commit 7b0b7f6

Please sign in to comment.