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

Make common generics more terse #573

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Jul 25, 2023

This is #375 brought back to life, I don't have perms to re-open PRs. Includes all things from the discussion thread. The individual patches are marked wip and have foramatting changes separate, this is so reviewers can more easily see how the changes effect formatting. Also this PR is hella invasive, it can sit here until its a good time to merge then I can redo the whole thing and squash it into a single patch.

I will in no way take offence if this gets nack'ed for being too invasive :)

@tcharding tcharding marked this pull request as draft July 25, 2023 08:37
@apoelstra
Copy link
Member

sgtm. See my comments in the other PR, which match my current opinions.

@tcharding
Copy link
Member Author

Awesome, thanks. How about ScriptContext to Context which I only mention in discussion on the other PR?

@apoelstra
Copy link
Member

Yep, I think ScriptContext to Context is fine.

@tcharding
Copy link
Member Author

Cool, just to make sure, would either of these be better?

  • fn foo<Pk: Key, C: Context>();
  • fn foo<Pk: Key, C: Ctx>();

@apoelstra
Copy link
Member

I think Context is better than Ctx.

@tcharding
Copy link
Member Author

Cool, I'm going to go with <Pk: Key, Ctx: Context>.

@tcharding
Copy link
Member Author

Patch one is a bit of a punish to review but it can be verified by doing the changes yourself and running the formatter

  • MiniscriptKey becomes Key
  • ScriptContext becomes Context
  • Run cargo +nightly fmt

No other manual changes in patch 1

@tcharding tcharding marked this pull request as ready for review August 7, 2023 07:39
@apoelstra
Copy link
Member

I think in the second commit we should also re-export ContextError as ScriptContextError, since that's the only other breaking change.

apoelstra
apoelstra previously approved these changes Aug 7, 2023
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 2c8ca20

@apoelstra
Copy link
Member

Will hold off on merging in case you want to add the extra re-export.

@tcharding
Copy link
Member Author

tcharding commented Aug 7, 2023

I think in the second commit we should also re-export ContextError as ScriptContextError, since that's the only other breaking change.

Oooo, to be honest I did not actually notice that change this time around when I redid this work. I'll add the re-export as suggested. Furthermore, do we want to use context::Error instead while we are touching it? (FTR I have been explicitly ignoring errors and docs in miniscript, errors because of the stuff we are doing in secp/bitcoin and docs because I'll get to them later.)

@tcharding
Copy link
Member Author

I re-ordered the patches to put the alias stuff last. Added ScriptContextError alias. As is the patch maintains backwards compatibility - I'm not convinced the current re-exports are perfectly ergonomic.

@apoelstra
Copy link
Member

Furthermore, do we want to use context::Error instead while we are touching it?

Oo, yeah, let's do that.

In an effort to make the code more terse with no loss of clarity rename
the crate's main two traits `MiniscriptKey` to `Key` and `ScriptContext`
to `Context`.

The diff is big but can be verified by simply doing a search-and-replace
on `MiniscriptKey` -> `Key` and `ScriptContext` -> `Context`. Then run
`cargo +nightly fmt`. No other manual changes.
Now we have `Key` instead of `MiniscriptKey` we can take advantage of
the shorter name to inline the where clauses when appropriate.
We just renamed the `MinscriptKey` trait to `Key` and `ScriptContext` to
`Context`.
Add an alias for each of them to the original name. This helps backwards
compatibility but also makes the library more ergonomic since the new
names are so generic they could cause naming conflicts in downstream
crates.
Add an alias to the `miniscript::context` module to maintain backwards
comparability. Also, as for `ScriptContext` this may reduce potential
naming conflicts downstream because "context" is not that unique.

Note the alias is in `miniscript::context` but in `miniscript` there is
a re-export of `Contetxt` but not one of the error.
@tcharding
Copy link
Member Author

The errors are a bit of a mess, changing to use context::Error is opening a can of worms. I'm going to leave it as ContextError for now.

@tcharding
Copy link
Member Author

Rebased, no other changes.

@sanket1729
Copy link
Member

Hey Tobin, sorry for the delayed response. I am waiting a few days to merge other PRs to see if we can #481 in first.

@tcharding
Copy link
Member Author

Oh definitely! don't make them rebase that PR. Thanks for paying attention.

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 24c11c0

@tcharding tcharding marked this pull request as draft September 25, 2023 23:45
@tcharding
Copy link
Member Author

One invasive clean up at a time is plenty, leaving this util there is an opportune moment to push it.

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