Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlutusTx Map backed by Data #5927

Merged
merged 44 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c03986f
Add AssocList backed by Data
ana-pantilie Apr 29, 2024
0fcaac8
Fix build
ana-pantilie Apr 29, 2024
360474d
Fix AssocList union
ana-pantilie Apr 29, 2024
a730d6b
Add unionWith property test
ana-pantilie Apr 29, 2024
0d75e65
Clean-up
ana-pantilie Apr 29, 2024
ec6bccd
Fix performance bug
ana-pantilie Apr 29, 2024
634bea6
Add golden files for new tests
ana-pantilie Apr 29, 2024
857f418
Add documentation to AssocList
ana-pantilie Apr 29, 2024
8e620e5
Add docs to tests
ana-pantilie Apr 29, 2024
721d82d
Add data encoding test
ana-pantilie Apr 29, 2024
0f1d945
Address some review comments
ana-pantilie Apr 30, 2024
7dbd045
Rename AssocList to AssocMap
ana-pantilie May 7, 2024
0b51d91
Make Map newtype over BuiltinList Pair
ana-pantilie May 7, 2024
75edbf9
Fix union implementation
ana-pantilie May 8, 2024
cd2d843
Use BuiltinList internal functions
ana-pantilie May 8, 2024
4071a8a
Create internal top-level delete
ana-pantilie May 8, 2024
7d96dc4
Add union test
ana-pantilie May 8, 2024
2862dec
Add docs to integration tests
ana-pantilie May 8, 2024
1f7f634
Try naive type families
effectfully May 9, 2024
94ff0ff
Split 'Has*' into 'From*' and 'To*' again
effectfully May 10, 2024
1f0d147
Remove type families from '*Opaque'
effectfully May 10, 2024
8a02b66
Add 'ToBuiltin'
effectfully May 11, 2024
669e25f
Add 'TestInstances'
effectfully May 11, 2024
bb18d98
Make it work for GHC-8.10
effectfully May 11, 2024
0ec5c85
Polishing
effectfully May 12, 2024
173ee90
Improve docs
effectfully May 13, 2024
6e329d6
Polishing
effectfully May 13, 2024
ee05a90
Merge remote-tracking branch 'origin/master' into ana/data-assoclist
ana-pantilie May 13, 2024
29f0b1a
Address comments
effectfully May 14, 2024
f98841e
Fix compilation errors in AssocMap
ana-pantilie May 14, 2024
38270be
Add utils from bench package to plutus-tx-plugin tests
ana-pantilie May 14, 2024
a033dc0
Run first PlutusTx property test
ana-pantilie May 14, 2024
bc462b7
WIP: add makeLift to new Map type
ana-pantilie May 14, 2024
105d51c
Merge remote-tracking branch 'origin/effectfully/builtins/split-FromB…
ana-pantilie May 14, 2024
b2e34e4
Add first fully working plutus tx property test
ana-pantilie May 14, 2024
2ae4bf1
Merge remote-tracking branch 'origin/master' into ana/data-assoclist
ana-pantilie May 16, 2024
6f77819
Fix issue with insert propety test
ana-pantilie May 16, 2024
c57c9b7
Run all tests with PlutusTx
ana-pantilie May 16, 2024
678992d
Add changelog
ana-pantilie May 16, 2024
8cda32b
Fix test module warning
ana-pantilie May 21, 2024
393162c
Fix isData instance for These
ana-pantilie May 21, 2024
361cba3
Fix delete implementation
ana-pantilie May 21, 2024
72334a5
Fix redundancy
ana-pantilie May 21, 2024
c5c85ed
Address other review comments
ana-pantilie May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add union test
Signed-off-by: Ana Pantilie <ana.pantilie95@gmail.com>
  • Loading branch information
ana-pantilie committed May 8, 2024
commit 7d96dc408a07fa4c37d03b5ba733d5918fbd6e65
32 changes: 31 additions & 1 deletion plutus-tx-plugin/test/AssocMap/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import PlutusTx.Prelude qualified as PlutusTx
import PlutusTx.Show qualified as PlutusTx
import PlutusTx.Test
import PlutusTx.TH (compile)
import PlutusTx.These (These (..))
import PlutusTx.These (These (..), these)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.Hedgehog (testProperty)

Expand All @@ -48,6 +48,10 @@ goldenTests =
, goldenUPlcReadable "map2" map2
, goldenEvalCekCatch "map2" $ [map2 `unsafeApplyCode` (liftCodeDef 100)]
, goldenBudget "map2-budget" $ map2 `unsafeApplyCode` (liftCodeDef 100)
, goldenPirReadable "map3" map2
, goldenUPlcReadable "map3" map2
, goldenEvalCekCatch "map3" $ [map2 `unsafeApplyCode` (liftCodeDef 100)]
, goldenBudget "map3-budget" $ map2 `unsafeApplyCode` (liftCodeDef 100)
]

propertyTests :: TestTree
Expand Down Expand Up @@ -127,6 +131,32 @@ map2 =
||]
)

map3 :: CompiledCode (Integer -> [(Integer, PlutusTx.BuiltinString)])
map3 =
$$( compile
[||
\n ->
let m1 =
Data.AssocMap.unsafeFromList
[ (n PlutusTx.+ 1, "one")
, (n PlutusTx.+ 2, "two")
, (n PlutusTx.+ 3, "three")
, (n PlutusTx.+ 4, "four")
, (n PlutusTx.+ 5, "five")
]
m2 =
Data.AssocMap.unsafeFromList
[ (n PlutusTx.+ 3, "THREE")
, (n PlutusTx.+ 4, "FOUR")
, (n PlutusTx.+ 6, "SIX")
, (n PlutusTx.+ 7, "SEVEN")
]
m = Data.AssocMap.union m1 m2
f = these id id PlutusTx.appendByteString
in PlutusTx.fmap (\(k, v) -> (k, PlutusTx.decodeUtf8 (f v))) (Data.AssocMap.toList m)
||]
)

-- | The semantics of PlutusTx maps and their operations.
-- The 'PlutusTx' implementations maps ('Data.AssocMap.Map' and 'AssocMap.Map')
-- are checked against the semantics to ensure correctness.
Expand Down
2 changes: 2 additions & 0 deletions plutus-tx-plugin/test/Budget/9.6/map3-budget.budget.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
({cpu: 160633417
| mem: 416622})
27 changes: 27 additions & 0 deletions plutus-tx-plugin/test/Budget/9.6/map3.eval.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(constr
1
(constr 0 (con integer 105) (con string "five"))
(constr
1
(constr 0 (con integer 104) (con string "fourFOUR"))
(constr
1
(constr 0 (con integer 103) (con string "threeTHREE"))
(constr
1
(constr 0 (con integer 102) (con string "two"))
(constr
1
(constr 0 (con integer 101) (con string "one"))
(constr
1
(constr 0 (con integer 106) (con string "SIX"))
(constr
1 (constr 0 (con integer 107) (con string "SEVEN")) (constr 0)
)
)
)
)
)
)
)
Loading
Loading