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

Haskell codegen: No instance for ‘LambdaBuffers.Runtime.Prelude.Json LambdaBuffers.Plutus.V1.TxOutRef’ #197

Open
bladyjoker opened this issue Feb 16, 2024 · 4 comments
Labels
bug Something isn't working codegen

Comments

@bladyjoker
Copy link
Contributor

bladyjoker commented Feb 16, 2024

Once everything is put together, everything should compile, the fact that it doesn't means this is a bug.

Some deets:

    • No instance for ‘LambdaBuffers.Runtime.Prelude.Json
                         LambdaBuffers.Plutus.V1.TxOutRef’
        arising from a use of ‘LambdaBuffers.Runtime.Prelude.toJson’

Imports printed

import qualified LambdaBuffers.Plutus.V1
import qualified LambdaBuffers.Prelude
import qualified LambdaBuffers.Runtime.Prelude
import qualified PlutusTx
import qualified PlutusTx.Eq
import qualified PlutusTx.Maybe
import qualified PlutusTx.Prelude
import qualified Prelude

Cabal printed

cabal-version:      3.0
name:               lbf-infinity-plutus-api
version:            0.1.0.0
synopsis:           A Cabal project that contains LambdaBuffers generated Haskell modules
build-type:         Simple

library
    exposed-modules: LambdaBuffers.Infinity.Validation.Plutus.Vault LambdaBuffers.Infinity.Validation.Plutus.UAsset LambdaBuffers.Infinity.Validation.Plutus.UAsset.Location LambdaBuffers.Infinity.Validation.Plutus.Minting LambdaBuffers.Infinity.Validation.Plutus.UCoin LambdaBuffers.Infinity.Validation.Plutus.Location LambdaBuffers.Infinity.Validation.Plutus.Identity LambdaBuffers.Infinity.Validation.Plutus.Main LambdaBuffers.Infinity.Validation.Plutus.Entity 
    autogen-modules: LambdaBuffers.Infinity.Validation.Plutus.Vault LambdaBuffers.Infinity.Validation.Plutus.UAsset LambdaBuffers.Infinity.Validation.Plutus.UAsset.Location LambdaBuffers.Infinity.Validation.Plutus.Minting LambdaBuffers.Infinity.Validation.Plutus.UCoin LambdaBuffers.Infinity.Validation.Plutus.Location LambdaBuffers.Infinity.Validation.Plutus.Identity LambdaBuffers.Infinity.Validation.Plutus.Main LambdaBuffers.Infinity.Validation.Plutus.Entity 
    hs-source-dirs:     autogen

    default-language: Haskell2010
    default-extensions: NoImplicitPrelude
    build-depends: lbf-plutus, lbf-prelude, base, lbr-plutus, lbr-prelude, plutus-tx

Workaround

Add this to your problematic schema which will bring in the necessary imports.

sum XY = X | Y
derive Eq XY
derive PlutusData XY
derive Json XY
@bladyjoker
Copy link
Contributor Author

The core problem is that lbr-plutus:LambdaBuffers.Runtime.Plutus import is missing where the missing instance is defined. Why is it missing?

Because during codegen, 'nothing' that requires this import was 'used'.

It's a known problem that we don't specify in our configuration a a mapping from a LB instance clause and the target module where it's implemented.

@bladyjoker
Copy link
Contributor Author

       >     • No instance for ‘PlutusTx.Eq.Eq LambdaBuffers.Prelude.Bytes’
       >         arising from a use of ‘PlutusTx.Eq.==’
       >     • In the expression: (PlutusTx.Eq.==) (x2) (x3)
       >       In the expression: let Script x3 = x1 in (PlutusTx.Eq.==) (x2) (x3)
       >       In the expression:
       >         let Script x2 = x0 in
       >         let Script x3 = x1 in (PlutusTx.Eq.==) (x2) (x3)
       >    |
       > 44 |   (==) = (\x0 -> (\x1 -> let Script x2 = x0 in let Script x3 = x1 in (PlutusTx.Eq.==) (x2) (x3) ) )
       >    |                                                                      ^^^^^^^^^^^^^^^^

This is getting annoying

@bladyjoker
Copy link
Contributor Author

Probably a duplicate of #124

@bladyjoker
Copy link
Contributor Author

To expand on this, as this is utterly my doing. Honestly, it wasn't really clear to me how to separate all this, but now the user aspect has clarified for me and I see things differently.

I'll talk about Haskell related back-ends, which I'll call native Haskell, Plutarch and PlutusTx.

And we have 2 LBF packages, namely Prelude and Plutus!

We have two Nix functions to build lbf schemas for Haskell

lbfHaskellPrelude

Nothing controversial here, this maps to native Haskell which is base and containers library and all opaque types and their instances ofc supported.

This is the codegen config https://github.com/mlabs-haskell/lambda-buffers/blob/main/lambda-buffers-codegen/data/haskell-prelude-base.json

Simple enough.

lbfHaskellPlutus

However, this is shit!!!

I collated two things that shouldn't have been collated:

  1. LBF Plutus for native Haskell (which can be used for transaction building)
  2. LBF Plutus for PlutusTx (which is used for writing scripts like Plutarch)

And now I have this shit

  1. https://github.com/mlabs-haskell/lambda-buffers/blob/main/lambda-buffers-codegen/data/haskell-prelude-plutustx.json
  2. https://github.com/mlabs-haskell/lambda-buffers/blob/main/lambda-buffers-codegen/data/haskell-plutus-plutustx.json

Solution

Treat PlutusTx as a separate language.
lbfPlutusTx codegenes PlutusTx code with configurations plutustx-prelude.json and plutustx-plutus.json, since there's some LBF Prelude types that are naturally available in PlutusTx.
The modules generated go into LB.SomeModule.PlutusTx (similar to how Plutarch backend has LB.SomeModule.Plutarch)

Have lbfHaskellPlutus map into native Haskell and not PlutusTx. It should generate code into LB.SomeModule and use pretty much native Haskell types. This can be used for transaction building for example, and the only dependency is PLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working codegen
Projects
Status: Todo
Development

No branches or pull requests

1 participant