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 encodeUtf8/decodeUtf8 for bytestrings and strings. #3288

Merged
merged 3 commits into from
Jun 3, 2021

Conversation

ghost
Copy link

@ghost ghost commented May 31, 2021

This PR fills the gap in strings/bytestrings functionality and will help for further literal bytestrings support.


Pre-submit checklist:

  • Branch
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Relevant tickets are mentioned in commit messages
    • Formatting, materialized Nix files, PNG optimization, etc. are updated
  • PR
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

Pre-merge checklist:

  • Someone approved it
  • Commits have useful messages
  • Review clarifications made it into the code
  • History is moderately tidy; or going to squash-merge

@ghost ghost requested review from michaelpj, j-mueller, kwxm and effectfully May 31, 2021 09:11
Comment on lines 69 to 70
, test_applyBuiltinFunction EncodeUtf8
, test_applyBuiltinFunction DecodeUtf8
Copy link
Contributor

Choose a reason for hiding this comment

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

Please drop these changes, that module is going to be gone once #3208 is merged.

Copy link
Author

Choose a reason for hiding this comment

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

Done 👌

Comment on lines 83 to 84
, test_applyBuiltinFunction EncodeUtf8
, test_applyBuiltinFunction DecodeUtf8
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Author

Choose a reason for hiding this comment

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

Done 👌

Comment on lines +112 to +115
pretty EncodeUtf8 = "encodeUtf8"
pretty DecodeUtf8 = "decodeUtf8"
Copy link
Contributor

Choose a reason for hiding this comment

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

Tangential: @michaelpj I'm so annoyed that we don't derive Pretty in terms of Show for DefaultFun, because of stuff like

pretty GreaterThanEqInteger = "greaterThanEqualsInteger"

Adding that pretty EncodeUtf8 = "encodeUtf8" line (and the other one) manually is stupid redundant work. Should we rename the constructors of DefaultFun to match with the Pretty instance or should we change the Pretty instance to be derived in terms of Show (with the first letter lowered) even if that breaks backwards compatibility?

Copy link
Contributor

Choose a reason for hiding this comment

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

Backwards compatibility for whom? Nobody uses the parser. I say change it. Not in this PR, though.

@ghost
Copy link
Author

ghost commented May 31, 2021

CI fails with

 serialization round-trip (CBOR):                               FAIL (4.39s)
      ✗ serialization round-trip (CBOR) failed at plutus-core/test/Spec.hs:99:5
        after 15 tests and 12 shrinks.
      
           ┏━━ generators/PlutusCore/Generators/Internal/Utils.hs ━━━
        57 ┃ forAllPretty :: (Monad m, Pretty a) => Gen a -> PropertyT m a
        58 ┃ forAllPretty = forAllWith display
           ┃ │ (program 0.0.1
           ┃ │   (lam a a { (lam a a (builtin encodeUtf8)) a })
           ┃ │ )
        
           ┏━━ plutus-core/test/Spec.hs ━━━
        96 ┃ propCBOR :: Property
        97 ┃ propCBOR = property $ do
        98 ┃     prog <- forAllPretty $ runAstGen genProgram
        99 ┃     Hedgehog.tripping prog serialise deserialiseOrFail
           ┃     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           ┃     │ ━━━ Intermediate ━━━
           ┃     │ "\246\246\NUL\NUL\SOH\STX\246aa\NUL\NUL\246aa\NUL\ENQ\246\STX\246aa\NUL\NUL\246aa\NUL\t\246\CAN\GS\NUL\246aa\NUL"
           ┃     │ ━━━ - Original) (+ Roundtrip ━━━
           ┃     │ - Right
           ┃     │ -   (Program
           ┃     │ -      ()
           ┃     │ -      (Version () 0 0 1)
           ┃     │ -      (LamAbs
           ┃     │ -         ()
           ┃     │ -         Name { nameString = "a" , nameUnique = Unique { unUnique = 0 } }
           ┃     │ -         (TyVar
           ┃     │ -            ()
           ┃     │ -            TyName
           ┃     │ -              { unTyName =
           ┃     │ -                  Name { nameString = "a" , nameUnique = Unique { unUnique = 0 } }
           ┃     │ -              })
           ┃     │ -         (TyInst
           ┃     │ -            ()
           ┃     │ -            (LamAbs
           ┃     │ -               ()
           ┃     │ -               Name { nameString = "a" , nameUnique = Unique { unUnique = 0 } }
           ┃     │ -               (TyVar
           ┃     │ -                  ()
           ┃     │ -                  TyName
           ┃     │ -                    { unTyName =
           ┃     │ -                        Name { nameString = "a" , nameUnique = Unique { unUnique = 0 } }
           ┃     │ -                    })
           ┃     │ -               (Builtin () EncodeUtf8))
           ┃     │ -            (TyVar
           ┃     │ -               ()
           ┃     │ -               TyName
           ┃     │ -                 { unTyName =
           ┃     │ -                     Name { nameString = "a" , nameUnique = Unique { unUnique = 0 } }
           ┃     │ -                 }))))
           ┃     │ + Left (DeserialiseFailure 31 "Failed to decode BuiltinName")
      
        This failure can be reproduced by running:
        > recheck (Size 14) (Seed 2224849573486902166 16519328201700872397) serialization round-trip (CBOR)

🤔

@effectfully
Copy link
Contributor

Looking at Builtin.hs I think you simply forgot to update the decode part of the Serialize instance?

@ghost
Copy link
Author

ghost commented May 31, 2021

@effectfully yeah, right, thanks! Missed the warnings from the compiler somehow.

Is there a reason why -Werror is not enabled by default? Or it's too irritating for the development process? Maybe should be enabled on CI?

@effectfully
Copy link
Contributor

Missed the warnings from the compiler somehow.

I think there were no warnings? It's decoding that is problematic and it has a bunch of clauses for particular integers and a final catch-all clause, hence we don't get any warnings when we forget to update the decoding function. We need a cocoverage checker! Or do the two "co"s cancel each other and it's verage checker in fact?

Anyway, as long as tests catch such errors, we're fine.

@effectfully
Copy link
Contributor

Is there a reason why -Werror is not enabled by default? Or it's too irritating for the development process? Maybe should be enabled on CI?

It is enabled in CI form what I know (@michaelpj, right?). We used to have it enabled for development as well, but people were annoyed and so we switched (I personally don't care either way).

@ghost
Copy link
Author

ghost commented Jun 1, 2021

It's decoding that is problematic and it has a bunch of clauses for particular integers and a final catch-all clause

Oh, right, my bad, should not write things in the late evening.

@@ -112,6 +114,10 @@ lessThanByteString = (<)
greaterThanByteString :: ByteString -> ByteString -> Bool
greaterThanByteString = (>)

{-# NOINLINE decodeUtf8 #-}
decodeUtf8 :: ByteString -> String
Copy link
Contributor

Choose a reason for hiding this comment

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

haddock for these. Yes, it's somewhat obvious, but it never hurts.

@michaelpj
Copy link
Contributor

And yes, we run with -Werror in CI.

Has conflicts now.

@michaelpj
Copy link
Contributor

Rebase went wrong, it seems?

@ghost ghost force-pushed the add-encode-decode-string-bytestring branch from b484433 to f88a107 Compare June 3, 2021 05:35
@ghost
Copy link
Author

ghost commented Jun 3, 2021

I think it was the consequence of yesterday's GitHub issues. Updated.

@michaelpj michaelpj merged commit 9658f16 into master Jun 3, 2021
@ghost ghost deleted the add-encode-decode-string-bytestring branch June 3, 2021 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants