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

Clear out psbFromBytes, quasiquoter #294

Closed
wants to merge 9 commits into from

Conversation

kozross
Copy link
Contributor

@kozross kozross commented Aug 3, 2022

This attempts to resolve #291. In particular:

  • All functions using psbFromBytes are gone.
  • IsString PinnedSizedBytes is gone.
  • Quasi-quoter psbHex has been added for compile-time construction.
  • Small tests for quasi-quoter logic.

Some refactors to enable the quasiquoter have also been added.

Currently, I'm submitting this as a draft, as I can't (quite) figure out how to stop the quasiquoter making two identical hex strings construct PinnedSizedBytes which share the same address. This is reproduced by one of the tests, which is currently failing. I attempted to address this by porting over primitive's Lift instance for ByteArray, but that doesn't seem to help any.

Upon further attempts, I'm basically giving up on this, and leaving a note about not mutating the outcomes of the quasiquoter. This is basically for two reasons:

  • No matter how we do this, GHC can work against us and let-float things, then CSE its way to victory. While there was some discussion to allow explicit blocking of this in GHC itself, we basically don't have it in any reliable way.
  • If you're using a quasiquoter, you're probably defining a constant anyway: I see no reason to want to mutate it, unless it's a bug.

@lehins - tagging you for a review.

@kozross kozross changed the title Clear out psbFromBytes, quasiquoter DRAFT: Clear out psbFromBytes, quasiquoter Aug 3, 2022
@kozross kozross changed the title DRAFT: Clear out psbFromBytes, quasiquoter Clear out psbFromBytes, quasiquoter Aug 3, 2022
@kozross kozross requested a review from tdammers August 11, 2022 19:56
Copy link
Contributor

@tdammers tdammers left a comment

Choose a reason for hiding this comment

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

Looks good to me, apart from the one remark on the previous review.

@kozross
Copy link
Contributor Author

kozross commented Aug 22, 2022

@tdammers - your comment has already been addressed a few commits ago. I can't reply to it, as it's marked 'outdated'.

Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

I don't particularly like the reimplementation of hex conversion. For performance, maintainability and correctness reasons. How can we change that?

Comment on lines +112 to +118
decodeAndCount chunk
| Text.length chunk /= 2 = do
len <- get
fail $ "Odd number of hexits (" <> show (2 * len + 1) <> ")."
| otherwise = case readMaybe ("0x" <> Text.unpack chunk) of
Nothing -> fail $ "Invalid hexit pair (" <> Text.unpack chunk <> ")."
Just w8 -> modify (+ 1) $> w8
Copy link
Collaborator

@lehins lehins Aug 25, 2022

Choose a reason for hiding this comment

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

Why are you reimplementing from hex conversion? Why not just use base16-bytestring?

@lehins
Copy link
Collaborator

lehins commented Aug 25, 2022

@kozross Thank you for doing all the work, but I'd rather implement this feature in a different way. Please review this PR if you can: #299

@lehins
Copy link
Collaborator

lehins commented Sep 6, 2022

Closing in favor of #299

@kozross Thank you on your effort on this, but quasiquoter only allows decoding into a ByteString, thus it is less powerful than the TH solution supplied in #299, which allows static check of the length as well, thus allows decoding into Hash and PinnedSizedBytes directly.

@lehins lehins closed this Sep 6, 2022
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.

Clear away psbFromBytes
3 participants