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

[PlutusTx] [Builtins] Split 'FromBuiltin' and 'ToBuiltin' #5971

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no reason to make it a class synonym before, but now it's convenient, since we partially apply it in the TestAllBuiltinsSatisfy instances below.


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

Expand Down
2 changes: 1 addition & 1 deletion plutus-ledger-api/test-plugin/Spec/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ valueToLists = ListTx.map (fmap AssocMap.toList) . AssocMap.toList . getValue
eqValueCode :: CompiledCode Value -> CompiledCode Value -> (Bool, PLC.CountingSt)
eqValueCode valueCode1 valueCode2 = (res, cost) where
prog =
$$(compile [|| \value1 value2 -> toBuiltin ((value1 :: Value) == value2) ||])
$$(compile [|| \value1 value2 -> toOpaque ((value1 :: Value) == value2) ||])
`unsafeApplyCode` valueCode1 `unsafeApplyCode` valueCode2
(errOrRes, cost)
= PLC.runCekNoEmit PLC.defaultCekParameters PLC.counting
Expand Down
2 changes: 1 addition & 1 deletion plutus-tx-plugin/src/PlutusTx/Compiler/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module PlutusTx.Compiler.Builtins (
, lookupBuiltinType
, errorFunc) where

import PlutusTx.Builtins.Class qualified as Builtins
import PlutusTx.Builtins.HasOpaque qualified as Builtins
import PlutusTx.Builtins.Internal qualified as Builtins

import PlutusTx.Compiler.Error
Expand Down
2 changes: 1 addition & 1 deletion plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import PlutusTx.PIRTypes
import PlutusTx.PLCTypes (PLCType, PLCVar)

-- I feel like we shouldn't need this, we only need it to spot the special String type, which is annoying
import PlutusTx.Builtins.Class qualified as Builtins
import PlutusTx.Builtins.HasOpaque qualified as Builtins
import PlutusTx.Trace

import PlutusIR qualified as PIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@
)
)
)
(termbind
(nonstrict)
(vardecl
`$fHasFromOpaqueBuiltinDataBuiltinData_$cfromOpaque`
(fun (con data) (con data))
)
(lam eta (con data) eta)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the id removed from the below.

)
(termbind
(strict)
(vardecl
Expand All @@ -271,7 +279,7 @@
(termbind
(nonstrict)
(vardecl
`$fFromBuiltinBuiltinListList_$cfromBuiltin`
`$fHasFromOpaqueBuiltinListList_$cfromOpaque`
(all
arep
(type)
Expand All @@ -292,7 +300,7 @@
a
(type)
(lam
`$dFromBuiltin`
`$dHasFromOpaque`
[ [ (lam arep (type) (lam a (type) (fun arep a))) arep ] a ]
(let
(rec)
Expand Down Expand Up @@ -323,7 +331,7 @@
[
[
{ Cons a }
[ `$dFromBuiltin` [ { head arep } l ] ]
[ `$dHasFromOpaque` [ { head arep } l ] ]
]
[ go [ { tail arep } l ] ]
]
Expand All @@ -347,11 +355,6 @@
)
(builtin fstPair)
)
(termbind
(nonstrict)
(vardecl id (all a (type) (fun a a)))
(abs a (type) (lam x a x))
)
(termbind
(strict)
(vardecl
Expand Down Expand Up @@ -405,12 +408,12 @@
[
{
{
`$fFromBuiltinBuiltinListList_$cfromBuiltin`
`$fHasFromOpaqueBuiltinListList_$cfromOpaque`
(con data)
}
(con data)
}
{ id (con data) }
`$fHasFromOpaqueBuiltinDataBuiltinData_$cfromOpaque`
]
a
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Changed

- Split `PlutusTx.Builtins.Class` into `PlutusTx.Builtins.HasBuiltin` and `PlutusTx.Builtins.HasOpaque` in #5971:
+ Split 'FromBuiltin' into 'HasFromBuiltin' and 'HasFromOpaque'
+ Split 'ToBuiltin' into 'HasToBuiltin' and 'HasToOpaque'
4 changes: 3 additions & 1 deletion plutus-tx/plutus-tx.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ library
PlutusTx.Blueprint.Write
PlutusTx.Bool
PlutusTx.Builtins
PlutusTx.Builtins.Class
PlutusTx.Builtins.HasBuiltin
PlutusTx.Builtins.HasOpaque
PlutusTx.Builtins.Internal
PlutusTx.Code
PlutusTx.Coverage
Expand Down Expand Up @@ -108,6 +109,7 @@ library
PlutusTx.IsData.Instances
PlutusTx.IsData.TH
PlutusTx.Lift.Instances
PlutusTx.Lift.TestInstances
PlutusTx.Lift.TH
PlutusTx.Lift.THUtils

Expand Down
Loading