Skip to content

Made TxBody a data family #5005

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

Merged
merged 2 commits into from
Apr 30, 2025
Merged

Made TxBody a data family #5005

merged 2 commits into from
Apr 30, 2025

Conversation

Soupstraw
Copy link
Contributor

@Soupstraw Soupstraw commented Apr 23, 2025

Description

This PR changes TxBody from a type family to a data family.

close #4999

Checklist

  • Commits in meaningful sequence and with useful messages.
  • Tests added or updated when needed.
  • CHANGELOG.md files updated for packages with externally visible changes.
    NOTE: New section is never added with the code changes. (See RELEASING.md).
  • Versions updated in .cabal and CHANGELOG.md files when necessary, according to the
    versioning process.
  • Version bounds in .cabal files updated when necessary.
    NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
  • Code formatted (use scripts/fourmolize.sh).
  • Cabal files formatted (use scripts/cabal-format.sh).
  • CDDL files are up to date (use scripts/gen-cddl.sh)
  • hie.yaml updated (use scripts/gen-hie.sh).
  • Self-reviewed the diff.

@Soupstraw Soupstraw force-pushed the jj/txbody-data-family branch 11 times, most recently from aebaabf to 722d003 Compare April 24, 2025 09:57
@Soupstraw Soupstraw marked this pull request as ready for review April 24, 2025 09:57
@Soupstraw Soupstraw requested a review from a team as a code owner April 24, 2025 09:57
@Soupstraw Soupstraw force-pushed the jj/txbody-data-family branch 2 times, most recently from cf59cb6 to 646272e Compare April 24, 2025 14:19
@Soupstraw Soupstraw enabled auto-merge (rebase) April 25, 2025 09:59
Copy link
Contributor

@teodanciu teodanciu left a comment

Choose a reason for hiding this comment

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

Can we just remove these types ShelleyTxBody... ConwayTxBody without deprecating them?

@Soupstraw
Copy link
Contributor Author

I suppose I could add type synonyms to address that issue.

@Soupstraw Soupstraw force-pushed the jj/txbody-data-family branch 2 times, most recently from 00f26b2 to 646272e Compare April 25, 2025 13:07
@Soupstraw
Copy link
Contributor Author

It's not so easy actually, when I try to deprecate the type synonym, it deprecates the pattern with the same name instead..

@teodanciu
Copy link
Contributor

I just realized that these types are not exported in the API, so maybe it's not a big deal to remove them?

Copy link
Contributor

@neilmayhew neilmayhew left a comment

Choose a reason for hiding this comment

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

This is a welcome simplification, and the concretisation of era in many places to a specific era removes a lot of noise and complexity.

Could the same technique be applied to some of the other abstract types that we have, such as TxOut and TxCert? If not, what's special about TxBody? And if we can do it only for TxBody then perhaps it makes the code more confusing since TxBody is then handled differently to the way we handle all the other era-specific types.

I'm also concerned that removing the era parameterisation in some places will reduce the reusability of the code. OTOH, since we already know now that things from earlier eras aren't going to be reused, perhaps it's good that we remove the complexity of that unnecessary reusability.

@Soupstraw Soupstraw force-pushed the jj/txbody-data-family branch from 646272e to f2bf54f Compare April 25, 2025 15:48
Copy link
Contributor

@neilmayhew neilmayhew left a comment

Choose a reason for hiding this comment

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

Removing the era from the raw tx bodies removes a lot more constraint noise. Nice!

@Soupstraw Soupstraw force-pushed the jj/txbody-data-family branch 2 times, most recently from 18ee78c to 928fb5b Compare April 28, 2025 09:56
@Soupstraw
Copy link
Contributor Author

@neilmayhew What makes TxBody special is that so far we have defined a new TxBody for pretty much every era. By making TxBody a data family, we improve type inference and also it makes it possible to pass TxBody as a parameter with the kind Type -> Type. With a type family you had to wrap the type family in a newtype to be able to do that.

The drawback of having a data family here is that now if we want to reuse a TxBody from a previous era, we'll have to redefine the datatype and write all the instances, but if we add an entirely new TxBody, then we have to do that anyways.

@Soupstraw Soupstraw force-pushed the jj/txbody-data-family branch 2 times, most recently from 5b61a06 to 21f8a8c Compare April 29, 2025 12:49
Copy link
Contributor

@teodanciu teodanciu 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.
I think we should definitely mention in the changelog of each era the removal of <Era>TxBody type, and since the Raw types are also exposed, the fact that we removed its era parameter.

@Soupstraw Soupstraw force-pushed the jj/txbody-data-family branch from 21f8a8c to 5ce0cec Compare April 30, 2025 13:41
@Soupstraw Soupstraw force-pushed the jj/txbody-data-family branch from 5ce0cec to 9c3d7cd Compare April 30, 2025 13:46
@Soupstraw Soupstraw merged commit 39a08b0 into master Apr 30, 2025
201 of 273 checks passed
@Soupstraw Soupstraw deleted the jj/txbody-data-family branch April 30, 2025 15:45
@lehins lehins mentioned this pull request Apr 25, 2025
7 tasks
@lehins lehins mentioned this pull request Jun 16, 2025
23 tasks
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.

Switch TxBody to a data family
3 participants