Skip to content

miniscript: non-recursive Clone #724

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 1 commit into from
Aug 19, 2024

Conversation

apoelstra
Copy link
Member

This is mostly just annoying/mechanical code. But it needs to be written because the derive(Clone) logic, I think, was only doing a "shallow clone" by cloning the Arcs in the Miniscript.

In my view this is undesirable behavior. If users want to do a shallow clone, they can hold an Arc and call Arc::clone on that. But there are some cases where they might want to do a deep clone, and currently there isn't really any way to do so (you can do it with the translator API and an "identity" translator, but this is awkward to do and will be slow because it redoes typechecking and rechecks for duplicate keys).

This is mostly just annoying/mechanical code. But it needs to be written
because the derive(Clone) logic, I think, was only doing a "shallow
clone" by cloning the Arcs in the Miniscript.

In my view this is undesirable behavior. If users want to do a shallow
clone, they can hold an Arc<Miniscript> and call Arc::clone on that. But
there are some cases where they might want to do a deep clone, and
currently there isn't really any way to do so (you can do it with the
translator API and an "identity" translator, but this is awkward to do
and will be slow because it redoes typechecking and rechecks for
duplicate keys).
Copy link
Member Author

@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.

Successfully ran local tests on 0d1a59a.

Copy link
Member

@sanket1729 sanket1729 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. Will ACK in a min after testing compiler benchmarks. I don't know how much they rely on cheap clones.

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK 0d1a59a.

No difference in compiler performance. We are using Arc there, and not Arc

@apoelstra apoelstra merged commit cab7762 into rust-bitcoin:master Aug 19, 2024
30 checks passed
@apoelstra apoelstra deleted the 2024-08--clone branch August 19, 2024 12:19
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