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 'TestInstances'
  • Loading branch information
effectfully committed May 11, 2024
commit 669e25fcf4fc9d4c964a50cd43b57cbfef5c4cb3
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}

module PlutusCore.Builtin.Polymorphism
( Opaque (..)
Expand Down Expand Up @@ -214,7 +215,8 @@ type family AllElaboratedArgs constr x where
-- built-in type.
type AllBuiltinArgs
:: forall a. (GHC.Type -> GHC.Type) -> (GHC.Type -> GHC.Constraint) -> a -> GHC.Constraint
type AllBuiltinArgs uni constr x = AllElaboratedArgs constr (ElaborateBuiltin uni x)
class AllElaboratedArgs constr (ElaborateBuiltin uni x) => AllBuiltinArgs uni constr x
instance AllElaboratedArgs constr (ElaborateBuiltin uni x) => AllBuiltinArgs uni constr x

-- Custom type errors to guide the programmer adding a new built-in function.

Expand Down
1 change: 1 addition & 0 deletions plutus-tx/plutus-tx.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ library
PlutusTx.IsData.Instances
PlutusTx.IsData.TH
PlutusTx.Lift.Instances
PlutusTx.Lift.TestInstances
PlutusTx.Lift.TH
PlutusTx.Lift.THUtils

Expand Down
49 changes: 23 additions & 26 deletions plutus-tx/src/PlutusTx/Lift/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import PlutusCore.Data
import PlutusCore.Quote
import PlutusIR.MkPir
import PlutusTx.Builtins
import PlutusTx.Builtins.Internal (BuiltinBool, BuiltinList, BuiltinPair, BuiltinUnit)
import PlutusTx.Builtins.Internal (BuiltinBool, BuiltinInteger, BuiltinList, BuiltinPair,
BuiltinUnit)
import PlutusTx.Builtins.IsBuiltin (FromBuiltin, HasFromBuiltin)

import Language.Haskell.TH qualified as TH hiding (newName)
Expand Down Expand Up @@ -132,75 +133,71 @@ instance (TypeError ('Text "Int is not supported, use Integer instead"))
=> Lift uni Int where
lift = Haskell.error "unsupported"

instance uni `PLC.HasTypeLevel` Integer => Typeable uni Integer where
instance uni `PLC.HasTypeLevel` Integer => Typeable uni BuiltinInteger where
typeRep = typeRepBuiltin

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTermLevel` Integer => Lift uni Integer where
instance uni `PLC.HasTermLevel` Integer => Lift uni BuiltinInteger where
lift = liftBuiltin

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` BS.ByteString => Typeable uni BS.ByteString where
typeRep = typeRepBuiltin

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` Data => Typeable uni BuiltinData where
typeRep _ = typeRepBuiltin (Proxy @Data)

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTermLevel` Data => Lift uni BuiltinData where
lift = liftBuiltin . builtinDataToData

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` BS.ByteString => Typeable uni BuiltinByteString where
typeRep _proxyByteString = typeRepBuiltin (Proxy @BS.ByteString)
typeRep _ = typeRepBuiltin (Proxy @BS.ByteString)

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTermLevel` BS.ByteString => Lift uni BuiltinByteString where
lift = liftBuiltin . fromBuiltin

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` T.Text => Typeable uni BuiltinString where
typeRep _proxyByteString = typeRepBuiltin (Proxy @T.Text)
typeRep _ = typeRepBuiltin (Proxy @T.Text)

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTermLevel` T.Text => Lift uni BuiltinString where
lift = liftBuiltin . fromBuiltin

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` () => Typeable uni BuiltinUnit where
typeRep _proxyUnit = typeRepBuiltin (Proxy @())
typeRep _ = typeRepBuiltin (Proxy @())

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTermLevel` () => Lift uni BuiltinUnit where
lift = liftBuiltin . fromBuiltin

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` Bool => Typeable uni BuiltinBool where
typeRep _proxyBool = typeRepBuiltin (Proxy @Bool)
typeRep _ = typeRepBuiltin (Proxy @Bool)

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTermLevel` Bool => Lift uni BuiltinBool where
lift = liftBuiltin . fromBuiltin

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` [] => Typeable uni BuiltinList where
typeRep _proxyBuiltinList = typeRepBuiltin (Proxy @[])
typeRep _ = typeRepBuiltin (Proxy @[])

-- See Note [Lift and Typeable instances for builtins]
instance (HasFromBuiltin a, uni `PLC.HasTermLevel` [FromBuiltin a]) =>
Lift uni (BuiltinList a) where
instance (HasFromBuiltin arep, uni `PLC.HasTermLevel` [FromBuiltin arep]) =>
Lift uni (BuiltinList arep) where
lift = liftBuiltin . fromBuiltin

instance uni `PLC.HasTypeLevel` (,) => Typeable uni BuiltinPair where
typeRep _proxyBuiltinPair = typeRepBuiltin (Proxy @(,))
typeRep _ = typeRepBuiltin (Proxy @(,))

instance
( HasFromBuiltin a, HasFromBuiltin b
, uni `PLC.HasTermLevel` (FromBuiltin a, FromBuiltin b)
) => Lift uni (BuiltinPair a b) where
( HasFromBuiltin arep, HasFromBuiltin brep
, uni `PLC.HasTermLevel` (FromBuiltin arep, FromBuiltin brep)
) => Lift uni (BuiltinPair arep brep) where
lift = liftBuiltin . fromBuiltin

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` Data => Typeable uni BuiltinData where
typeRep _ = typeRepBuiltin (Proxy @Data)

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTermLevel` Data => Lift uni BuiltinData where
lift = liftBuiltin . builtinDataToData

-- See Note [Lift and Typeable instances for builtins]
instance uni `PLC.HasTypeLevel` PlutusCore.Crypto.BLS12_381.G1.Element =>
Typeable uni BuiltinBLS12_381_G1_Element where
Expand Down
39 changes: 39 additions & 0 deletions plutus-tx/src/PlutusTx/Lift/TestInstances.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}

module PlutusTx.Lift.TestInstances () where

import PlutusCore qualified as PLC
import PlutusCore.Builtin qualified as PLC
import PlutusTx.Builtins.IsBuiltin
import PlutusTx.Lift.Class

import Data.Kind qualified as GHC

type BuiltinSatisfies
:: (GHC.Type -> GHC.Constraint)
-> (GHC.Type -> GHC.Constraint)
-> GHC.Type
-> GHC.Constraint
class (pre (ToBuiltin a) => post (ToBuiltin a)) => BuiltinSatisfies pre post a
instance (pre (ToBuiltin a) => post (ToBuiltin a)) => BuiltinSatisfies pre post a

type AllBuiltinsSatisfy
:: (GHC.Type -> GHC.Constraint)
-> (GHC.Type -> GHC.Constraint)
-> GHC.Constraint
class PLC.DefaultUni `PLC.Everywhere` BuiltinSatisfies pre post => AllBuiltinsSatisfy pre post

instance AllBuiltinsSatisfy
(PLC.AllBuiltinArgs PLC.DefaultUni (Typeable PLC.DefaultUni))
(Typeable PLC.DefaultUni)
instance AllBuiltinsSatisfy
(PLC.AllBuiltinArgs PLC.DefaultUni HasFromBuiltin)
(Lift PLC.DefaultUni)
Loading