plutus icon indicating copy to clipboard operation
plutus copied to clipboard

Cannot parse textual pir

Open phadej opened this issue 3 years ago • 9 comments

E.g. when trying to parse future.pir (in the plutus-use-cases/test/Spec), I get the following error:

  pir/future.pir: pir/future.pir:204:10:
    |
204 |         (datatypebind
    |          ^^^^^^^
unexpected "datatyp"
expecting "abs", "builtin", "con", "error", "iwrap", "lam", "let", or "unwrap"

phadej avatar Nov 06 '21 20:11 phadej

I think overall the pretty-printer and parser are not complete and production-ready as mentioned in #3445. We have a customized parser for PLC but not PIR. And I guess the recommended way, for now, is to deserialize the binary representation.

kk-hainq avatar Nov 08 '21 05:11 kk-hainq

Is there a variant of goldenPir which produces binary representation?

phadej avatar Nov 08 '21 06:11 phadej

I think setting this flag is a quick way anywhere:

{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:dump-pir #-}

kk-hainq avatar Nov 08 '21 07:11 kk-hainq

{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:dump-pir-flat #-}

That is not the same as goldenPir, won;t make tests fail.

phadej avatar Nov 08 '21 07:11 phadej

Yeah, I don't think there is any. Maybe you could break the test with the pretty-printed version, then find the corresponding binary to read the AST...

kk-hainq avatar Nov 08 '21 07:11 kk-hainq

Is there a variant of goldenPir which produces binary representation?

Unfortunately there is no a version for binary. There are functions that read or dump flat data so it should be possible to write a goldenFlat for that purposes.

I'm closing this issue because of #3445 if you don't mind. Feel free to reopen.

ak3n avatar Nov 08 '21 10:11 ak3n

I mind. The #3445 is about producing well-typed Core. This issue is about that even well-typed PIR won't be parsed. I.e. I cannot write PIR by hand and parse it in (I don't need that, but someone might).

phadej avatar Nov 08 '21 10:11 phadej

Oh, I should have linked or quoted it properly. As @michaelpj states

We should note that the pretty-printer and parser are 100% not intended for production use. You should use one of the binary formats if you care about that.

As I understand users shouldn't rely on them anyway. #3445 is open because it linked to the internal issue tracker.

@michaelpj could you please comment?

ak3n avatar Nov 08 '21 10:11 ak3n

I'm happy to leave this open. You're all right:

  • It is bad that the PIR parser and prettyprinter are not up-to-scratch. I would like us to fix this, but it's not a top priority, because...
  • The textual parsers are not in (our) production pathway and won't ever be. We use them only for testing, and we recommend you similarly don't rely on them for anything else.
  • The issue here arises from trying to do testing, which is indeed what we use the parser for, and it is indeed pretty annoying that it doesn't work.

So I think this is a legit bug that hopefully we will fix in due course.

michaelpj avatar Nov 08 '21 10:11 michaelpj

@thealmarty you implemented parsing of datatypebind and other PIR things, right? If so, please close this issue.

effectfully avatar Feb 01 '23 22:02 effectfully

After PR #4349 and a few follow up PRs more PIR things (including datatypebind) can theoretically be parsed. However no tests were added. It was not considered to be high priority at the time. I think it's best to close this after tests are added?

thealmarty avatar Feb 02 '23 15:02 thealmarty

@thealmarty thank you.

I think it's best to close this after tests are added?

Good point, let's do that.

effectfully avatar Feb 02 '23 15:02 effectfully

@thealmarty do you happen to know the status of this issue?

effectfully avatar Mar 05 '23 03:03 effectfully

There are tests that contain "datatypebind" in our codebase now. (Maybe there were before too, but I've recently added more for sure) E.g., here. This may be good to close?

thealmarty avatar Mar 13 '23 18:03 thealmarty

Seems like it then! Thanks a lot, closing as resolved.

effectfully avatar Mar 13 '23 21:03 effectfully