Skip to content

Commit

Permalink
Merge pull request IntersectMBO#4822 from input-output-hk/mpj/strict-…
Browse files Browse the repository at this point in the history
…bindings-from-data

IsData: generate strict let-bindings
  • Loading branch information
michaelpj authored Aug 30, 2022
2 parents 4865bcd + 6c76067 commit 26c1ac8
Show file tree
Hide file tree
Showing 5 changed files with 837 additions and 52 deletions.
13 changes: 13 additions & 0 deletions plutus-tx-plugin/test/Budget/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Test.Tasty.Extras

import PlutusTx.Builtins qualified as PlutusTx
import PlutusTx.Code
import PlutusTx.IsData qualified as PlutusTx
import PlutusTx.Prelude qualified as PlutusTx
import PlutusTx.Show qualified as PlutusTx
import PlutusTx.TH (compile)
Expand All @@ -39,6 +40,9 @@ tests = testNested "Budget" [
, goldenBudget "elem" compiledElem
, goldenPir "elem" compiledElem

, goldenBudget "toFromData" compiledToFromData
, goldenPir "toFromData" compiledToFromData

, goldenBudget "monadicDo" monadicDo
, goldenPir "monadicDo" monadicDo
-- These should be a little cheaper than the previous one,
Expand Down Expand Up @@ -76,6 +80,15 @@ compiledElem = $$(compile [||
let ls = [1,2,3,4,5,6,7,8,9,10] :: [Integer]
in PlutusTx.elem 0 ls ||])

compiledToFromData :: CompiledCode (Either Integer (Maybe (Bool, Integer, Bool)))
compiledToFromData = $$(compile [||
let
v :: Either Integer (Maybe (Bool, Integer, Bool))
v = Right (Just (True, 1, False))
d :: PlutusTx.BuiltinData
d = PlutusTx.toBuiltinData v
in PlutusTx.unsafeFromBuiltinData d ||])

doExample :: Maybe Integer -> Maybe Integer -> Maybe Integer
doExample x y = do
x' <- x
Expand Down
3 changes: 3 additions & 0 deletions plutus-tx-plugin/test/Budget/toFromData.budget.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({ cpu: 15479457
| mem: 51292
})
Loading

0 comments on commit 26c1ac8

Please sign in to comment.