-
Notifications
You must be signed in to change notification settings - Fork 36.6k
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
refactor: only use explicit reinterpret/const casts, not implicit #24185
refactor: only use explicit reinterpret/const casts, not implicit #24185
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
@MarcoFalke, do you have any opinions about this more stripped down PR? |
Yeah, it might be better to use spans where possible instead of changing one bloaty code to another slightly better, but still bloaty code |
@MarcoFalke
Since this PR only conflicts with two others, (one of which seems quite dead) I think this cost has been minimized. |
I don't think it makes sense to change the same LOC twice. See also #22167 (comment) where I suggested to do char->std::byte, but then decided to go char->Span. There is more cost to a pull request than conflicts. Another cost is review and the general burden that it places on the project. A burden could be any of the following:
|
I like that these named casts make smelly conversions easier to see, grep for, and more verbose/ugly, to eventually encourage refactoring them away. Given how many there are in the codebase though, it's easier to do it when the code is being touched for other things, either as a PR author or a reviewer making suggestions, and I've seen a few reinterpret casts added this way. Doing it wholesale across the codebase is a hard sell, however, for the reasons mentioned above. |
8bff802
to
73da5aa
Compare
73da5aa
to
46a9a73
Compare
3ae7791 refactor: use Span in random.* (pasta) Pull request description: ~This PR does two things~ 1. use a Span<unsigned char> for GetRandBytes and GetStrongRandBytes ~2. make GetRand a template for which any integral type can be used, where the default behavior is to return a random integral up to the max of the integral unless a max is provided. This simplifies a lot of code from `GetRand(std::numeric_limits<uint64_t>::max()` -> `GetRand<uint64_t>()`~ MarcoFalke this was inspired by your comment here: bitcoin/bitcoin#24185 (comment) about using Span, so hopefully I'll be able to get this PR done and merged 😂 ~Also, if requested I could revert the `GetRand(std::numeric_limits<uint64_t>::max()` -> `GetRand<uint64_t>()` related changes if it ends up causing too many conflicts~ ACKs for top commit: laanwj: Thank you! Code review re-ACK 3ae7791 Tree-SHA512: 12375a83b68b288916ba0de81cfcab4aac14389a66a36811ae850427435eb67dd55e47df9ac3ec47db4e214f4330139e548bec815fff8a3f571484ea558dca79
46a9a73
to
cb2d322
Compare
I had a look through a few of the casts, and I think quite a bit of them can simply be removed. E.g. all casts to |
I think the hash api might be better off taking a span of |
I just saw there are also helpers like |
cb2d322
to
96cc421
Compare
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
Closing this as it has not had any activity in a while. If you are interested in continuing work on this, please leave a comment so that it can be reopened. |
I've just rebased this PR. I'd love for this to move forward, but it seems that most maintainers here are against it due to the conflicts it'll cause with other open PRs (even though imo the conflicts will be quite easy for authors to resolve) |
@PastaPastaPasta you could remove all the |
This PR converts 149 silent reinterpret_cast's into explicit reinterpret_cast's
This PR converts 33 silent const_cast's into explicit const_cast's
This PR is broken out from #23810, as it appears there is little appetite for the scope of change as outlined in that PR.
The PR resolves the most critical step of removing implicit c-style casts that act as reinterpret_casts or const_casts, additionally, this PR should be considerably less conflicting than it's predecessor. I at least hope that it is deemed the value will exceed the cost of conflicts.
If there are any specific areas of the codebase that are heavily conflicting compared to others, I'd be happy to drop those sections of the PR for now.