Skip to content

Clean up miniscript/mod.rs #583

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 11 commits into from
Jul 28, 2023

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Jul 27, 2023

Make an effort to clean up the miniscript/mod.rs file. I could not see a reason for all the separate impl blocks, is there one? Please note this PR does not fix all the docs, just does ones that should not be too hard to review.

@@ -59,7 +59,7 @@ pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> {
pub ty: types::Type,
///Additional information helpful for extra analysis.
pub ext: types::extra_props::ExtData,
/// Context PhantomData. Only accessible inside this crate
/// Needed because not all terminals are paramatized by script context.
Copy link
Member

Choose a reason for hiding this comment

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

In c874074

This is actually just used to simulate #[non_exhaustive] which we did not have in 1.29. We can just drop it and add #[non_exhaustive].

Copy link
Member Author

Choose a reason for hiding this comment

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

Did you think this was an enum? I think the comment is correct IIUC, if we remove the phantom we get build error

error[E0392]: parameter `Ctx` is never used
  --> src/miniscript/mod.rs:55:42
   |
55 | pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> {
   |                                          ^^^ unused parameter
   |
   = help: consider removing `Ctx`, referring to it in a field, or using a marker such as `PhantomData`

Copy link
Member

Choose a reason for hiding this comment

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

Oh, no, I think actually I'm just wrong. But I don't understand your comment. Ctx is clearly used in the node field, this error is just a bug in rustc (which I think has been well-known for many years). We should change the comment to clarify this.

And it is doing double-duty as a #[non_exhaustive] tag, which is fine. It prevents users from directly constructing this type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I thought it was being caused by the fact that not all variants of Terminal have Ctx. Not sure what to write there now, the original is definitely just noise though.

/// The type information and extra_properties can be deterministically determined
/// by the ast.
///
/// The type information and extra_properties can be deterministically determined by the AST.
Copy link
Member

Choose a reason for hiding this comment

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

In 33c04e2:

While we're touching this, let's replace "can be deterministically determined" with "are implied" :P.

@apoelstra
Copy link
Member

5182529 looks good otherwise

@tcharding tcharding force-pushed the 07-27-miniscript-mod-cleanup branch 2 times, most recently from 6775430 to 3150427 Compare July 27, 2023 19:54
@tcharding
Copy link
Member Author

Changes in force push:

  • Fixed docs as suggested
  • Added a couple of lines of whitespace that were missing from the original refactorings
  • Fixed formatting in the last patch

@tcharding tcharding force-pushed the 07-27-miniscript-mod-cleanup branch from 3150427 to 447412a Compare July 27, 2023 19:56
@tcharding
Copy link
Member Author

... and fixed the rebase

@tcharding tcharding force-pushed the 07-27-miniscript-mod-cleanup branch from 447412a to 55e65f3 Compare July 27, 2023 19:57
@tcharding
Copy link
Member Author

And rebased on master to pick up the pinning fix.

@apoelstra
Copy link
Member

55e65f3 is good except I'd like to change the comment on the phantom.

tcharding added 11 commits July 28, 2023 07:04
The `Hash` trait is related to PartialEq, Eq, PartialOrd, Ord - as such
put it next to them.
Improve and make the docs all the same.
Move the `Miniscript` impl block (with the constructors in in) to be
underneath the struct.

Refactor only, no logic changes.
Combine the two impl blocks that contain constructors and conversion
functions.

Refactor only, no logic changes.
Move the `encode` and `script_size` functions to the main impl block.

Refactor only, no logic changes.
Move the two `max_satisfaction*` functions to the main impl block.

Refactor only, no logic changes.
Move the two `satisfy*` functions to the main impl block.

Refactor only, no logic changes.
There are now two impl blocks for `Miniscript` with different generics,
put one directly under the other.

To match the diff this should be said "move trait impls below the second
Miniscript impl block".
Compress match arms using `|`, this makes the code more terse and easier
to quickly see if terminal variants return the expected length (for the
trivial ones at least).
Reduce duplicate code by factoring out a helper function.

Refactor only, no logic changes.
@tcharding tcharding force-pushed the 07-27-miniscript-mod-cleanup branch from 55e65f3 to a60c642 Compare July 27, 2023 21:05
@tcharding
Copy link
Member Author

I just dropped the phantom doc change altogether.

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 a60c642

@apoelstra apoelstra merged commit d1051cb into rust-bitcoin:master Jul 28, 2023
@tcharding tcharding deleted the 07-27-miniscript-mod-cleanup branch August 7, 2023 07:24
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