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

weaken FromCBOR for TxOut to Annotator TxOut #2593

Merged
merged 4 commits into from
Jan 4, 2022

Conversation

goolord
Copy link
Contributor

@goolord goolord commented Dec 22, 2021

required for #2560

babbage's TxOut will only be an instance of FromCBOR (Annotator TxOut), so this pr adds instances for FromCBOR (Annotator.. as it bubbles up from TxOut and FromCBOR constraints where necessary in code that's reused in babbage

@goolord goolord mentioned this pull request Dec 22, 2021
@goolord goolord force-pushed the zc/babbage-weaken-FromCBOR branch from 9147c3d to 6095478 Compare December 22, 2021 16:30
@goolord goolord force-pushed the zc/babbage-weaken-FromCBOR branch from 6095478 to 086baff Compare December 22, 2021 16:34
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 highly recommend avoiding all the copy pasting. Most of the code added in this PR can be avoided. For example:

instance ... => FromCBOR (Annotator (EpochState era)) where
  fromCBOR = do
    es@EpochState {eslState} <- fromCBOR
    pure $ Annotator $ \fbs -> es {esLState = runAnnotator esLState fbs}

It is especially dangerous to copy serialization/deserialziation code like that, because it s possible that someone in the future will change one fromCBOR, but not the other other one.

Also it is very bad practice to copy paste code in general, it is almost always better to create an abstraction. A professor of mine said once: "If you are finding yourself copying a piece of code, it is most likely that you are doing something wrong."

So please, keep your code as DRY as possible.

@goolord
Copy link
Contributor Author

goolord commented Dec 25, 2021

I don't think the code in your example would typecheck. since the constraints are different the instances have to be duplicated, or we can remove the non-Annotator FromCBOR instances, but not both

@goolord
Copy link
Contributor Author

goolord commented Dec 26, 2021

actually, I just realized that if Ann and ApplyAnn are generalized to any Applicative, all of these instances can share the same decoding function, so i'm going to do that ☃️

@goolord goolord requested a review from lehins December 27, 2021 21:51
Copy link
Contributor

@JaredCorduan JaredCorduan left a comment

Choose a reason for hiding this comment

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

Adding those annotators do tend to infect a lot of code, thanks for plowing through this! LGTM

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.

This looks great. @goolord thank you for reducing duplication!

There are just a couple of minor suggestions that I have in this review.

co-authored-by: Alexey Kuleshevich <[email protected]>
@goolord goolord force-pushed the zc/babbage-weaken-FromCBOR branch from 8b680a7 to 4f3d300 Compare January 3, 2022 21:38
@goolord goolord merged commit 5527a51 into master Jan 4, 2022
@iohk-bors iohk-bors bot deleted the zc/babbage-weaken-FromCBOR branch January 4, 2022 00:02
goolord added a commit that referenced this pull request Jan 11, 2022
goolord added a commit that referenced this pull request Jan 11, 2022
goolord added a commit that referenced this pull request Jan 11, 2022
goolord added a commit that referenced this pull request Jan 11, 2022
goolord added a commit that referenced this pull request Jan 12, 2022
goolord added a commit that referenced this pull request Jan 12, 2022
lehins pushed a commit to lehins/cardano-ledger that referenced this pull request Apr 11, 2022
```
Case                             Max          MaxOS           Live        Allocated     GCs  Wall Time
EpochState (FromCBOR)  1,739,105,216  5,082,447,872  1,724,424,656  103,862,408,816  93,015    99.967s
Benchmark memory: FINISH
```
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.

3 participants